Michael Ernst Peter / Mbed OS Test_GPS

Dependencies:   Eigen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers QMC5883L.h Source File

QMC5883L.h

00001 #ifndef QMC5883L_
00002 #define QMC5883L_
00003  
00004 #include <mbed.h>
00005 #include <math.h>
00006  
00007 /**
00008  * notes:
00009  * - do not readout faster than the set ODR (currently 200 Hz)
00010  * - the actual signal magnitude (norm) is sensitive to temperature,
00011  *   give the unit some time after startup
00012  * - readMag needs approx 2450 mus
00013  */
00014  
00015 #define QMC5883L_ADDRESS 0x1A
00016  
00017 #define OUT_X_LSB    0x00
00018 #define OUT_X_MSB    0x01
00019 #define OUT_Y_LSB    0x02
00020 #define OUT_Y_MSB    0x03
00021 #define OUT_Z_LSB    0x04
00022 #define OUT_Z_MSB    0x05
00023 #define CONTROL_A    0x09
00024 #define SET_RESET    0x0B
00025   
00026 class QMC5883L
00027 {
00028     public:
00029         QMC5883L(I2C& i2c);
00030         void readMag();
00031         float magX();
00032         float magY();
00033         float magZ();
00034  
00035     private:
00036         I2C& i2c;
00037         int16_t m_mag_val[3] = {0, 0, 0};
00038         float m_scale;
00039         void init();
00040         void getMagValue(const uint8_t& OUT_LSB, const uint8_t& OUT_MSB, int16_t& retval);
00041         bool ReadByte(const uint8_t& reg, uint8_t& data);
00042         bool WriteByte(const uint8_t& reg, const uint8_t& data);
00043 };
00044  
00045 #endif /* QMC5883L_ */