Implemented first Hangar-Service

Dependencies:   CalibrateMagneto QuaternionMath

Fork of SML2 by TobyRich GmbH

Revision:
12:1632d7391453
Parent:
11:d21275e60ebb
Child:
15:4488660e1a3b
--- a/Accelerometer.cpp	Thu Mar 12 10:16:01 2015 +0000
+++ b/Accelerometer.cpp	Fri Mar 13 09:12:56 2015 +0000
@@ -42,25 +42,16 @@
 Vector3 Accelerometer::read()
 {
     // Check comments in the read() function of the Gyroscope for more info why we read bytes one by one.
-    union {
-        uint8_t bytes[6];
-        struct {
-            int16_t z;
-            int16_t y;
-            int16_t x;
-        } val;
-    } buffer;
-    
-    size_t i = 6;
-    while (i --> 0) {
-        buffer.bytes[i] = read_reg(0x02 + i);
-    };
-    
-    const int16_t x = buffer.val.x / 16;
-    const int16_t y = buffer.val.y / 16;
-    const int16_t z = buffer.val.z / 16;
-    
+    uint8_t buffer[6];
+
+    for (size_t i = 0; i < 6; i++)
+        buffer[i] = read_reg(0x02 + i);
+
+    const int16_t x = *(reinterpret_cast<const int16_t*>(buffer + 0)) / 16;
+    const int16_t y = *(reinterpret_cast<const int16_t*>(buffer + 2)) / 16;
+    const int16_t z = *(reinterpret_cast<const int16_t*>(buffer + 4)) / 16;
+
     const float accel_resolution = 0.0009765625;
-    
-    return Vector3(x, y, z) * accel_resolution;
+
+    return Vector3(-x, -y, z) * accel_resolution;
 }