Skip to content

Commit

Permalink
Fixed incorrect error condition check when reading the 'ctrl_hum' reg…
Browse files Browse the repository at this point in the history
…ister.

Expanded the BME280 unit test for TestBME280DriverStart() to support reading
from the 'ctrl_hum' register.

Signed-off-by: Graeme Cross <graeme@ceriumdesigns.com>
  • Loading branch information
ssorc committed Jun 5, 2017
1 parent b6e207d commit c09f9c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions drivers/i2c/bme280_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion drivers/i2c/bme280_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit c09f9c1

Please sign in to comment.