diff --git a/drivers/i2c/i2c.go b/drivers/i2c/i2c.go index 7a1521c1..aa5184f1 100644 --- a/drivers/i2c/i2c.go +++ b/drivers/i2c/i2c.go @@ -58,7 +58,7 @@ func NewConnection(bus sysfs.I2cDevice, address int) (connection *i2cConnection) // Read data from an i2c device. func (c *i2cConnection) Read(data []byte) (read int, err error) { - if err := c.bus.SetAddress(c.address); err != nil { + if err = c.bus.SetAddress(c.address); err != nil { return 0, err } read, err = c.bus.Read(data) @@ -67,7 +67,7 @@ func (c *i2cConnection) Read(data []byte) (read int, err error) { // Write data to an i2c device. func (c *i2cConnection) Write(data []byte) (written int, err error) { - if err := c.bus.SetAddress(c.address); err != nil { + if err = c.bus.SetAddress(c.address); err != nil { return 0, err } written, err = c.bus.Write(data) diff --git a/drivers/i2c/i2c_test.go b/drivers/i2c/i2c_test.go index a6bb2243..d5a051af 100644 --- a/drivers/i2c/i2c_test.go +++ b/drivers/i2c/i2c_test.go @@ -3,10 +3,11 @@ package i2c import ( "testing" - "gobot.io/x/gobot/gobottest" - "gobot.io/x/gobot/sysfs" "syscall" "unsafe" + + "gobot.io/x/gobot/gobottest" + "gobot.io/x/gobot/sysfs" ) func syscallImpl(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { @@ -39,6 +40,11 @@ func TestI2CAddress(t *testing.T) { gobottest.Assert(t, c.address, 0x66) } +func TestI2CClose(t *testing.T) { + c := NewConnection(initI2CDevice(), 0x06) + gobottest.Assert(t, c.Close(), nil) +} + func TestI2CRead(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) i, _ := c.Read([]byte{})