Selaa lähdekoodia

hmc5883l: use int16_t as coordinate type throughout

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
Brendan Le Foll 10 vuotta sitten
vanhempi
commit
9ab215b6fd
3 muutettua tiedostoa jossa 7 lisäystä ja 7 poistoa
  1. 1
    1
      examples/hmc5883l.cxx
  2. 4
    4
      src/hmc5883l/hmc5883l.cxx
  3. 2
    2
      src/hmc5883l/hmc5883l.h

+ 1
- 1
examples/hmc5883l.cxx Näytä tiedosto

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

+ 4
- 4
src/hmc5883l/hmc5883l.cxx Näytä tiedosto

@@ -105,11 +105,11 @@ Hmc5883l::update(void)
105 105
     mraa_i2c_read(m_i2c, m_rx_tx_buf, DATA_REG_SIZE);
106 106
 
107 107
     // x
108
-    m_coor[0] = (int16_t)((m_rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_X_LSB_REG]);
108
+    m_coor[0] = (m_rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_X_LSB_REG];
109 109
     // z
110
-    m_coor[2] = (int16_t)((m_rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Z_LSB_REG]);
110
+    m_coor[2] = (m_rx_tx_buf[HMC5883L_Z_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Z_LSB_REG];
111 111
     // y
112
-    m_coor[1] = (int16_t)((m_rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Y_LSB_REG]);
112
+    m_coor[1] = (m_rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Y_LSB_REG];
113 113
 
114 114
     return MRAA_SUCCESS;
115 115
 }
@@ -130,7 +130,7 @@ Hmc5883l::heading(void)
130 130
     return dir;
131 131
 }
132 132
 
133
-int*
133
+int16_t*
134 134
 Hmc5883l::coordinates(void)
135 135
 {
136 136
     return &m_coor[0];

+ 2
- 2
src/hmc5883l/hmc5883l.h Näytä tiedosto

@@ -72,7 +72,7 @@ public:
72 72
      *
73 73
      * @return *int to an int[3]
74 74
      */
75
-    int* coordinates();
75
+    int16_t* coordinates();
76 76
 
77 77
     /**
78 78
      * Updates the values by reading from i2c
@@ -93,7 +93,7 @@ public:
93 93
      */
94 94
     float get_declination();
95 95
 private:
96
-    int m_coor[3];
96
+    int16_t m_coor[3];
97 97
     float m_declination;
98 98
     uint8_t m_rx_tx_buf[MAX_BUFFER_LENGTH];
99 99
     mraa_i2c_context m_i2c;