From 24d7aff6b23fae05fe859096d4a8e5ffa46f9833 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 9 Jul 2011 18:52:55 +0200 Subject: Added ITG3200 wrapper. --- itg3200.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 itg3200.h (limited to 'itg3200.h') diff --git a/itg3200.h b/itg3200.h new file mode 100644 index 0000000..2e90f62 --- /dev/null +++ b/itg3200.h @@ -0,0 +1,32 @@ +#ifndef ITG3200_H +#define ITG3200_H + +#include "i2c.h" + +class ITG3200 { + private: + I2C& i2c; + + public: + int16_t x, y, z; + + ITG3200(I2C& i2c_bus) : i2c(i2c_bus) { + + } + + void init() { + i2c.write_reg(0x68, 0x3e, 0x03); // Select clock reference. + i2c.write_reg(0x68, 0x16, 0x18 | 0x02); // 2000 deg/sec range, 98 Hz bandwidth. + } + + void update() { + uint8_t buf[6]; + i2c.read_reg(0x68, 0x1d, 6, buf); + + x = (buf[0] << 8 | buf[1]) - 0; + y = (buf[2] << 8 | buf[3]) - 0; + z = (buf[4] << 8 | buf[5]) - 0; + } +}; + +#endif -- cgit v1.2.3