diff --git a/drivers/i2c/l3gd20h_driver.go b/drivers/i2c/l3gd20h_driver.go index 1b242cce..0735b7e7 100644 --- a/drivers/i2c/l3gd20h_driver.go +++ b/drivers/i2c/l3gd20h_driver.go @@ -133,7 +133,7 @@ func (d *L3GD20HDriver) Halt() (err error) { // XYZ returns the current change in degrees per second, for the 3 axis. func (d *L3GD20HDriver) XYZ() (x float32, y float32, z float32, err error) { if _, err = d.connection.Write([]byte{l3gd20hRegisterOutXLSB}); err != nil { - return 0, 0, 0, nil + return 0, 0, 0, err } measurements := make([]byte, 6) if _, err = d.connection.Read(measurements); err != nil { diff --git a/drivers/i2c/l3gd20h_driver_test.go b/drivers/i2c/l3gd20h_driver_test.go index 3b4a3e00..e552b703 100644 --- a/drivers/i2c/l3gd20h_driver_test.go +++ b/drivers/i2c/l3gd20h_driver_test.go @@ -102,6 +102,17 @@ func TestL3GD20HDriverMeasurementError(t *testing.T) { gobottest.Assert(t, err, errors.New("read error")) } +func TestL3GD20HDriverMeasurementWriteError(t *testing.T) { + d, adaptor := initTestL3GD20HDriverWithStubbedAdaptor() + d.Start() + adaptor.i2cWriteImpl = func(b []byte) (int, error) { + return 0, errors.New("write error") + } + + _, _, _, err := d.XYZ() + gobottest.Assert(t, err, errors.New("write error")) +} + func TestL3GD20HDriverSetName(t *testing.T) { d := initTestL3GD20HDriver() d.SetName("TESTME")