#ifndef LSM303DLM_H #define LSM303DLM_H #include class LSM303DLM_A { private: I2C& i2c; public: int16_t x, y, z; LSM303DLM_A(I2C& i2c_bus) : i2c(i2c_bus) {} void init() { i2c.write_reg(0x19, 0x20, 0x27); // Normal mode, 50 Hz. } void update() { uint8_t buf[6]; i2c.read_reg(0x19, 0xa8, 6, buf); x = (buf[1] << 8 | buf[0]) - 0; y = (buf[3] << 8 | buf[2]) - 0; z = (buf[5] << 8 | buf[4]) - 0; } }; class LSM303DLM_M { private: I2C& i2c; public: int16_t x, y, z; LSM303DLM_M(I2C& i2c_bus) : i2c(i2c_bus) {} void init() { i2c.write_reg(0x1e, 0x02, 0x00); // Continous operation mode. } void update() { uint8_t buf[6]; i2c.read_reg(0x1e, 0x03, 6, buf); x = (buf[0] << 8 | buf[1]) - 0; y = (buf[2] << 8 | buf[3]) - 0; z = (buf[4] << 8 | buf[5]) - 0; } }; #endif