From c6ac90fc731d8411380f582be3b91ce4e93f61fc Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 11 Apr 2011 05:44:51 +0200 Subject: Create I2CSensor class and subclasses for each sensor. --- bma150.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 bma150.h (limited to 'bma150.h') diff --git a/bma150.h b/bma150.h new file mode 100644 index 0000000..0cd6b27 --- /dev/null +++ b/bma150.h @@ -0,0 +1,24 @@ +#ifndef BMA150_H +#define BMA150_H + +#include "i2csensor.h" + +class BMA150 : public I2CSensor { + public: + int16_t x, y, z; + + void init() { + i2c_address = 0x38; + read(0x14, 1); + write(0x14, (rxdata[0] & 0xe0) | 0x00 | 0x00); // 2g range, 25 Hz bandwidth + } + + void update() { + read(0x02, 6); + x = ((rxdata[0] & 0xc0) | rxdata[1] << 8); + y = ((rxdata[2] & 0xc0) | rxdata[3] << 8); + z = ((rxdata[4] & 0xc0) | rxdata[5] << 8); + } +}; + +#endif -- cgit v1.2.3