diff --git a/drivers/i2c/bme280_driver.go b/drivers/i2c/bme280_driver.go index 212437d3..2649338e 100644 --- a/drivers/i2c/bme280_driver.go +++ b/drivers/i2c/bme280_driver.go @@ -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 } diff --git a/drivers/i2c/bme280_driver_test.go b/drivers/i2c/bme280_driver_test.go index 083fc708..c5f9b2e0 100644 --- a/drivers/i2c/bme280_driver_test.go +++ b/drivers/i2c/bme280_driver_test.go @@ -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) }