i2c: fix I2c::read() call
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -120,9 +120,9 @@ class I2c {
|
|||||||
* @param length Size of read in bytes to make
|
* @param length Size of read in bytes to make
|
||||||
* @return pointer to std::string
|
* @return pointer to std::string
|
||||||
*/
|
*/
|
||||||
std::string read(int length, uint8_t command) {
|
std::string read(int length) {
|
||||||
uint8_t* data = (uint8_t*) malloc(sizeof(uint8_t) * length);
|
uint8_t* data = (uint8_t*) malloc(sizeof(uint8_t) * length);
|
||||||
mraa_i2c_read(m_i2c, data, command, length);
|
mraa_i2c_read(m_i2c, data, length);
|
||||||
std::string str((char*)data, length);
|
std::string str((char*)data, length);
|
||||||
free(data);
|
free(data);
|
||||||
return str;
|
return str;
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ main(int argc, char **argv)
|
|||||||
// chosen register
|
// chosen register
|
||||||
mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
|
mraa_i2c_address(i2c, HMC5883L_I2C_ADDR);
|
||||||
// this call behaves very similarly to the Wire receive() call
|
// this call behaves very similarly to the Wire receive() call
|
||||||
mraa_i2c_read(i2c, rx_tx_buf, HMC5883L_DATA_REG, DATA_REG_SIZE);
|
mraa_i2c_read(i2c, rx_tx_buf, DATA_REG_SIZE);
|
||||||
|
|
||||||
x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_X_LSB_REG] ;
|
x = (rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_X_LSB_REG] ;
|
||||||
z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Z_LSB_REG] ;
|
z = (rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | rx_tx_buf[HMC5883L_Z_LSB_REG] ;
|
||||||
|
|||||||
Reference in New Issue
Block a user