Firmata: I2C read bytes data array size mismatch fix
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
17b147ba82
commit
3bd590c18c
@@ -231,9 +231,16 @@ mraa_firmata_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
|
|||||||
static int
|
static int
|
||||||
mraa_firmata_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
|
mraa_firmata_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
|
||||||
{
|
{
|
||||||
|
uint32_t *local_storage = (uint32_t*) calloc(length, sizeof(int));
|
||||||
if (mraa_firmata_send_i2c_read_reg_req(dev, command, length) == MRAA_SUCCESS) {
|
if (mraa_firmata_send_i2c_read_reg_req(dev, command, length) == MRAA_SUCCESS) {
|
||||||
if (mraa_firmata_i2c_wait(dev->addr, command) == MRAA_SUCCESS) {
|
if (mraa_firmata_i2c_wait(dev->addr, command) == MRAA_SUCCESS) {
|
||||||
memcpy(data, &firmata_dev->i2cmsg[dev->addr][command], sizeof(int)*length);
|
memcpy(local_storage, &firmata_dev->i2cmsg[dev->addr][command], sizeof(int)*length);
|
||||||
|
int x = 0;
|
||||||
|
for(; x<length; x++){
|
||||||
|
data[x] = (uint8_t) local_storage[x];
|
||||||
|
}
|
||||||
|
free(local_storage);
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user