i2c: ensure bmp180 returns Temperature() error, if any
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
a772e835d9
commit
56a67a6626
|
@ -127,6 +127,7 @@ func (d *BMP180Driver) initialization() (err error) {
|
||||||
binary.Read(buf, binary.BigEndian, &d.calibrationCoefficients.mb)
|
binary.Read(buf, binary.BigEndian, &d.calibrationCoefficients.mb)
|
||||||
binary.Read(buf, binary.BigEndian, &d.calibrationCoefficients.mc)
|
binary.Read(buf, binary.BigEndian, &d.calibrationCoefficients.mc)
|
||||||
binary.Read(buf, binary.BigEndian, &d.calibrationCoefficients.md)
|
binary.Read(buf, binary.BigEndian, &d.calibrationCoefficients.md)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +140,7 @@ func (d *BMP180Driver) Halt() (err error) {
|
||||||
func (d *BMP180Driver) Temperature() (temp float32, err error) {
|
func (d *BMP180Driver) Temperature() (temp float32, err error) {
|
||||||
var rawTemp int16
|
var rawTemp int16
|
||||||
if rawTemp, err = d.rawTemp(); err != nil {
|
if rawTemp, err = d.rawTemp(); err != nil {
|
||||||
return 0, nil
|
return 0, err
|
||||||
}
|
}
|
||||||
return d.calculateTemp(rawTemp), nil
|
return d.calculateTemp(rawTemp), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
// +build example
|
||||||
|
//
|
||||||
|
// Do not build by default.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gobot.io/x/gobot"
|
||||||
|
"gobot.io/x/gobot/drivers/i2c"
|
||||||
|
"gobot.io/x/gobot/platforms/firmata"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
|
||||||
|
bmp180 := i2c.NewBMP180Driver(firmataAdaptor)
|
||||||
|
|
||||||
|
work := func() {
|
||||||
|
gobot.Every(1*time.Second, func() {
|
||||||
|
//fmt.Println("Pressure", mpl115a2.Pressure())
|
||||||
|
t, _ := bmp180.Temperature()
|
||||||
|
fmt.Println("Temperature", t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
robot := gobot.NewRobot("bmp180bot",
|
||||||
|
[]gobot.Connection{firmataAdaptor},
|
||||||
|
[]gobot.Device{bmp180},
|
||||||
|
work,
|
||||||
|
)
|
||||||
|
|
||||||
|
robot.Start()
|
||||||
|
}
|
Loading…
Reference in New Issue