df

Dependencies:   mbed

Fork of APP1 by Team APP

Revision:
3:1a9d0f0a50bf
Parent:
1:7becb0e903e3
Child:
4:303fb83498fd
--- a/Accelerometer.hpp	Sat Jan 14 18:53:39 2017 +0000
+++ b/Accelerometer.hpp	Sat Jan 14 22:37:34 2017 +0000
@@ -1,4 +1,5 @@
-#include <memory>
+#ifndef ACCELEROMETER_HPP
+#define ACCELEROMETER_HPP
 
 #include "mbed.h"
 
@@ -13,23 +14,46 @@
 const char WHO_AM_I_REGISTER = 0x0D;
 const char CTRL_REG1_REGISTER_ADDRESS = 0x2A;
 
+const int I2C_ACCELEROMETER_ADDRESS = 0x1D;
+
+enum Axis
+{
+    AXIS_X,
+    AXIS_Y,
+    AXIS_Z,
+    AXIS_INVALID
+};
+
+int raw_axis_data_to_int(signed char raw_axis_data);
+void test_raw_axis_data_to_int();
+char get_axis_register(Axis axis);
+
 class Accelerometer
 {
-    public:
-        Accelerometer(I2C& device, const int slave_address);
+    public:        
+        Accelerometer(
+            PinName sda_pin, 
+            PinName scl_pin, 
+            const int slave_address = I2C_ACCELEROMETER_ADDRESS
+            );
         
         void write_register(const char register_address, const char new_value);
         char read_register(const char register_address);
         
-        //axis_data must be an array of 6 bytes
-        void read_all_axis(char* axis_data);
+        //axis_data must be an array of length 6
+        void read_all_axis(signed char* axis_data);
         void print_all_axis_data();
         
         void set_standby();
         void set_active();
         void init();
+        
+        //Read data from the 8 most significant bits (MSB) of a given axis
+        int read_axis_data_8_bits(Axis axis);
     
     private:
-        I2C& device;
+        I2C device;
         const int slave_address;
-};
\ No newline at end of file
+};
+
+#endif
\ No newline at end of file