Skip to content

Commit

Permalink
Merge pull request #425 from ssorc/dev
Browse files Browse the repository at this point in the history
Issue #424: Enables humidity readings in the BME280 driver by enforci…
  • Loading branch information
deadprogram authored Jun 5, 2017
2 parents 0d2f85c + c09f9c1 commit 48b704b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion drivers/i2c/bme280_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,15 @@ func (d *BME280Driver) initHumidity() (err error) {

d.connection.WriteByteData(bme280RegisterControlHumidity, 0x3F)

return nil
// 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
var cmr uint8
cmr, err = d.connection.ReadByteData(bmp280RegisterControl)
if err == nil {
err = d.connection.WriteByteData(bmp280RegisterControl, cmr)
}
return err
}

func (d *BME280Driver) rawHumidity() (uint32, error) {
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 48b704b

Please sign in to comment.