1 #ifndef LIBPROPELLER_LSM303DLHC_H_ 2 #define LIBPROPELLER_LSM303DLHC_H_ 5 #include "libpropeller/i2c/i2c.h" 7 #include "libpropeller/i2c/i2cMOCK.h" 69 status_ = bus_->
Ping(kDeviceMagnAddress);
70 if (status_ ==
false) {
74 status_ = bus_->
Ping(kDeviceAcclAddress);
75 if (status_ ==
false) {
81 bus_->
Put(kDeviceMagnAddress, kCRA_REG_M, 0b10011100);
82 bus_->
Put(kDeviceMagnAddress, kCRB_REG_M, kGain_1_3);
83 bus_->
Put(kDeviceMagnAddress, kMR_REG_M, 0b00000000);
86 bus_->
Put(kDeviceAcclAddress, kCTRL_REG1_A, 0b10010111);
87 bus_->
Put(kDeviceAcclAddress, kCTRL_REG4_A, 0b00111000);
104 if (status_ ==
false) {
109 if (bus_->
Get(kDeviceAcclAddress, kOUT_X_L_A, data, 6) ==
false) {
118 x = ((data[0] | (data[1] << 8)) << 16) >> 16;
119 y = ((data[2] | (data[3] << 8)) << 16) >> 16;
120 z = ((data[4] | (data[5] << 8)) << 16) >> 16;
137 if (status_ ==
false) {
142 if (bus_->
Get(kDeviceMagnAddress, kOUT_X_H_M, data, 6) ==
false) {
150 x = ((data[1] | (data[0] << 8)) << 16) >> 16;
151 z = ((data[3] | (data[2] << 8)) << 16) >> 16;
152 y = ((data[5] | (data[4] << 8)) << 16) >> 16;
162 const static unsigned char kDeviceAcclAddress = 0b00110010;
163 const static unsigned char kDeviceMagnAddress = 0b00111100;
166 const static unsigned char kCTRL_REG1_A = 0x20;
167 const static unsigned char kCTRL_REG4_A = 0x23;
168 const static unsigned char kOUT_X_L_A = 0x28 | 0x80;
171 const static unsigned char kCRA_REG_M = 0x00;
172 const static unsigned char kCRB_REG_M = 0x01;
173 const static unsigned char kMR_REG_M = 0x02;
174 const static unsigned char kOUT_X_H_M = 0x03 | 0x80;
176 const static unsigned char kGain_1_9 = 0b01000000;
177 const static unsigned char kGain_1_3 = 0b00100000;
182 #endif // LIBPROPELLER_LSM303DLHC_H_ bool Put(const unsigned char device, const unsigned char address, const char byte)
bool Ping(const unsigned char device)
bool Init(libpropeller::I2C *i2c_bus)
unsigned char Get(const unsigned char device, const unsigned char address)
bool ReadAccl(int &x, int &y, int &z)
bool ReadMagn(int &x, int &y, int &z)