mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-29 13:49:14 +08:00
Fixed incorrect error condition check when reading the 'ctrl_hum' register.
Expanded the BME280 unit test for TestBME280DriverStart() to support reading from the 'ctrl_hum' register. Signed-off-by: Graeme Cross <graeme@ceriumdesigns.com>
This commit is contained in:
parent
95b0fe880f
commit
2ebbc97e49
@ -117,9 +117,10 @@ func (d *BME280Driver) initHumidity() (err error) {
|
||||
// The 'ctrl_hum' register sets the humidity data acquisition options of
|
||||
// the device. Changes to this register only become effective after a write
|
||||
// operation to 'ctrl_meas'. Read the current value in, then write it back
|
||||
cmr, err := d.connection.ReadByteData(bmp280RegisterControl)
|
||||
if err != nil {
|
||||
d.connection.WriteByteData(bmp280RegisterControl, cmr)
|
||||
var cmr uint8
|
||||
cmr, err = d.connection.ReadByteData(bmp280RegisterControl)
|
||||
if err == nil {
|
||||
err = d.connection.WriteByteData(bmp280RegisterControl, cmr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -39,7 +39,12 @@ func TestBME280Driver(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBME280DriverStart(t *testing.T) {
|
||||
bme280, _ := initTestBME280DriverWithStubbedAdaptor()
|
||||
bme280, adaptor := initTestBME280DriverWithStubbedAdaptor()
|
||||
adaptor.i2cReadImpl = func(b []byte) (int, error) {
|
||||
// Simulate returning a single byte for the
|
||||
// ReadByteData(bmp280RegisterControl) call in Start()
|
||||
return 1, nil
|
||||
}
|
||||
gobottest.Assert(t, bme280.Start(), nil)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user