1
0
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:
Graeme Cross 2017-06-05 21:28:09 +10:00 committed by deadprogram
parent 95b0fe880f
commit 2ebbc97e49
2 changed files with 10 additions and 4 deletions

View File

@ -117,9 +117,10 @@ func (d *BME280Driver) initHumidity() (err error) {
// The 'ctrl_hum' register sets the humidity data acquisition options of // The 'ctrl_hum' register sets the humidity data acquisition options of
// the device. Changes to this register only become effective after a write // 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 // operation to 'ctrl_meas'. Read the current value in, then write it back
cmr, err := d.connection.ReadByteData(bmp280RegisterControl) var cmr uint8
if err != nil { cmr, err = d.connection.ReadByteData(bmp280RegisterControl)
d.connection.WriteByteData(bmp280RegisterControl, cmr) if err == nil {
err = d.connection.WriteByteData(bmp280RegisterControl, cmr)
} }
return err return err
} }

View File

@ -39,7 +39,12 @@ func TestBME280Driver(t *testing.T) {
} }
func TestBME280DriverStart(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) gobottest.Assert(t, bme280.Start(), nil)
} }