summaryrefslogtreecommitdiff
path: root/ak8975.h
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-04-11 05:44:51 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-04-11 05:44:51 +0200
commitc6ac90fc731d8411380f582be3b91ce4e93f61fc (patch)
treee5fc2017a6e27e3669a81f595df551cc91af7549 /ak8975.h
parent14f24f2a98a63a5c5525fd196df46100b4ef626d (diff)
Create I2CSensor class and subclasses for each sensor.
Diffstat (limited to 'ak8975.h')
-rw-r--r--ak8975.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/ak8975.h b/ak8975.h
new file mode 100644
index 0000000..beb9940
--- /dev/null
+++ b/ak8975.h
@@ -0,0 +1,24 @@
+#ifndef AK8975_H
+#define AK8975_H
+
+#include "i2csensor.h"
+
+class AK8975 : public I2CSensor {
+ public:
+ int16_t x, y, z;
+
+ void init() {
+ i2c_address = 0x0c;
+ write(0x0a, 0x01); // Start first measurement.
+ }
+
+ void update() {
+ read(0x03, 6);
+ x = (rxdata[0] | rxdata[1] << 8);
+ y = (rxdata[2] | rxdata[3] << 8);
+ z = (rxdata[4] | rxdata[5] << 8);
+ write(0x0a, 0x01); // Start a new measurement.
+ }
+};
+
+#endif