Skip to content

Instantly share code, notes, and snippets.

@owenwaller
Created February 24, 2017 17:16
Show Gist options
  • Save owenwaller/593cfb0193e41acecbce153845edf588 to your computer and use it in GitHub Desktop.
Save owenwaller/593cfb0193e41acecbce153845edf588 to your computer and use it in GitHub Desktop.
GoBot i2cDevice.WriteBlockData - ref: Gobot issue 372
func (d *i2cDevice) WriteBlockData(reg uint8, data []byte) (err error) {
if d.funcs&I2C_FUNC_SMBUS_WRITE_BLOCK_DATA == 0 {
return fmt.Errorf("SMBus block data writing not supported")
}
if len(data) > 32 {
return fmt.Errorf("SMBus block data write length od data slice to large (max: 32, passed: %d)", len(data))
}
buf := make([]byte, len(data)+1)
n := copy(buf[1:], data) // <- fix
if n != len(data) {
return fmt.Errorf("SMBus block data write failed to all of the bytes from data (expected:%d, copied%d)", len(data), n)
}
fmt.Printf("Number of bytes copied: %d\n", n)
buf[0] = uint8(len(data))
fmt.Printf("len(data)=%d\n", len(data))
fmt.Printf("data:%#v\n", data)
fmt.Printf("len(buf)=%d\n", len(buf))
fmt.Printf("buf:%#v\n", buf)
err = d.smbusAccess(I2C_SMBUS_WRITE, reg, I2C_SMBUS_BLOCK_DATA, uintptr(unsafe.Pointer(&buf[0]))) // <- Broken?
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment