hmc5883l: use int16_t as coordinate type throughout

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll 2014-11-19 11:57:35 +00:00
parent ea7b7a23fa
commit 9ab215b6fd
3 changed files with 7 additions and 7 deletions

View File

@ -31,7 +31,7 @@ main(int argc, char **argv)
{
//! [Interesting]
upm::Hmc5883l* compass = new upm::Hmc5883l(0);
int *pos;
int16_t *pos;
compass->set_declination(0.2749); // Set your declination from true north in radians

View File

@ -105,11 +105,11 @@ Hmc5883l::update(void)
mraa_i2c_read(m_i2c, m_rx_tx_buf, DATA_REG_SIZE);
// x
m_coor[0] = (int16_t)((m_rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_X_LSB_REG]);
m_coor[0] = (m_rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_X_LSB_REG];
// z
m_coor[2] = (int16_t)((m_rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Z_LSB_REG]);
m_coor[2] = (m_rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Z_LSB_REG];
// y
m_coor[1] = (int16_t)((m_rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Y_LSB_REG]);
m_coor[1] = (m_rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Y_LSB_REG];
return MRAA_SUCCESS;
}
@ -130,7 +130,7 @@ Hmc5883l::heading(void)
return dir;
}
int*
int16_t*
Hmc5883l::coordinates(void)
{
return &m_coor[0];

View File

@ -72,7 +72,7 @@ public:
*
* @return *int to an int[3]
*/
int* coordinates();
int16_t* coordinates();
/**
* Updates the values by reading from i2c
@ -93,7 +93,7 @@ public:
*/
float get_declination();
private:
int m_coor[3];
int16_t m_coor[3];
float m_declination;
uint8_t m_rx_tx_buf[MAX_BUFFER_LENGTH];
mraa_i2c_context m_i2c;