-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
I may just not understand how to do it correctly, but I can't figure out how to write 4 bytes on i2c. I am trying to port this to WiringPi. I got most of the functions working, but color for RGB LEDs is [register + (index*3), r, g, b]
. I think this would work, if I had access to i2c_smbus_access
:
void wiringpi_8encoder_set_led_color_rgb(uint8_t fd, uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
uint8_t c[3] = {r, g, b};
i2c_smbus_access(fd, I2C_SMBUS_WRITE, (index * 3) + RGB_LED_REG, 3, &c);
}
Here is the working python equivalent (self.i2c
is from blinka):
def set_led_color_rgb(self, index, red, green, blue):
self.i2c.writeto(self.address, bytes([index * 3 + RGB_LED_REG, red, green, blue]))
Is there a better way to do this? I tried writing 4 bytes, 1 at a time, and it did not work (I think because it's adding termination and stuff.)
Would there be interest in a PR to expose i2c_smbus_access
as wiringPiI2CWriteRegBytes
(so it matches API a bit better) that lets us set the raw bytes/count?
int wiringPiI2CWriteRegBytes (int fd, uint8_t reg, int size, uint_8_t *data);
Would we also need a corresponding wiringPiI2CReadRegBytes
?
int wiringPiI2CReadRegBytes (int fd, uint8_t reg, int size, uint_8_t *data);
// usage
uint_8_t *data[8] = {0};
wiringPiI2CReadRegBytes(fd, SOME_REGISTER, 8, data);
Is this basically what is in #130 ?