df

Dependencies:   mbed

Fork of APP1 by Team APP

Revision:
6:3facf0329142
Parent:
5:f59b51ac4b40
Child:
7:1e00dfecc92d
--- a/Accelerometer.cpp	Sun Jan 15 01:34:25 2017 +0000
+++ b/Accelerometer.cpp	Sun Jan 15 02:04:23 2017 +0000
@@ -1,4 +1,5 @@
 #include "Accelerometer.hpp"
+#include "Utility.hpp"
 
 //Compute inverse two's complement to obtain a signed value
 //See page 21: https://www.gel.usherbrooke.ca/s5info/h17/doc/app1/file/MMA8452Q.pdf
@@ -21,30 +22,12 @@
         default: return AXIS_INVALID;
     }
 }
-
-bool is_almost_equal(double a, double b, double tolerance)
-{
-    double difference = std::abs(a-b);
-    return (difference <= tolerance);
-}
-
-//Return angle between 0 and 360 degree
-double wrap_angle(double angle)
-{
-    return angle - 360 * floor( angle / 360 );
-} 
     
 double g_force_from_int_axis_data(const int axis_data)
 {
     return (double)axis_data / 64.0;
 }
 
-double degree_from_radian(const double angle_radian)
-{
-    const double angle_degree = angle_radian * 180.0 / PI;
-    return wrap_angle(angle_degree);
-}
-
 //Z axis is perpendicular to the horizontal plane, towards the floor when the accelerometer is flat
 //Therefore, 
 // - if the Z force is +1g, the accelerometer is flat
@@ -55,7 +38,7 @@
 {
     const double z_g_force = g_force_from_int_axis_data(axis_data);
     const double angle_radian = acos(fabs(z_g_force));
-    return degree_from_radian(angle_radian);
+    return utility::degree_from_radian(angle_radian);
 }
 
 Accelerometer::Accelerometer(