used with BBC microbit

Dependencies:   MotionSensor

Fork of MAG3110 by Jim Carver

Revision:
6:1da3fe7b3510
Parent:
5:f3abe901c33a
Child:
7:f246f14f8bd2
--- a/MAG3110.h	Mon Apr 07 21:02:57 2014 +0000
+++ b/MAG3110.h	Fri May 16 18:19:17 2014 +0000
@@ -7,6 +7,7 @@
 #define MAG3110_H
 
 #include "mbed.h"
+#include "MotionSensor.h"
 
 #define PI 3.14159265359
 
@@ -20,7 +21,7 @@
 #define MAG_OUT_Y_LSB 0x04
 #define MAG_OUT_Z_MSB 0x05
 #define MAG_OUT_Z_LSB 0x06
-#define MAG_WHO_AM_I  0x07
+#define MAG_WHOAMI  0x07
 #define MAG_SYSMOD    0x08
 #define MAG_OFF_X_MSB 0x09
 #define MAG_OFF_X_LSB 0x0A
@@ -77,7 +78,7 @@
  * MAG3110 Class to read X/Y/Z data from the magentometer
  *
  */
-class MAG3110
+class MAG3110 : public MotionSensor
 {
 public:
     /**
@@ -87,72 +88,27 @@
      * @param addr addr of the I2C peripheral
      */
     MAG3110(PinName sda, PinName scl);
-    /**
-     * Debug version of constructor
-     * @param sda SDA pin
-     * @param sdl SCL pin
-     * @param addr Address of the I2C peripheral
-     * @param pc Serial object to output debug messages
-     */
-    MAG3110(PinName sda, PinName scl, Serial *pc); //pass serial for debug
-    /**
-     * Setup the Magnetometer
-     *
-     */
-    void begin();
-    /**
-     * Read a register, return its value as int
-     * @param regAddr The address to read
-     * @return value in register
-     */
-    int readReg(char regAddr);
-    /**
-     * Read a value from a pair of registers, return as int
-     * @param regAddr The address to read
-     * @return Value from 2 consecutive registers
-     */
-    int readVal(char regAddr);
-    /**
-     * Calculate the heading
-     * @return heading in degrees
-     */
-    float getHeading();
-    
-    /**
-     * Perform a read on the X, Y and Z values, converted to microteslas.
-     * @paran mag Pointer to the 3 element array whare the results will be placed
-     */
-    void ReadXYZ(float * mag);
-    
-    /**
-     * Perform a read on the raw X, Y and Z values.
-     * @paran mag Pointer to the 3 element array whare the results will be placed
-     */
-    void ReadXYZraw(int16_t * mag_raw);
-    
-    /**
-     * Perform a read on the X, Y and Z values.
-     * @param xVal Pointer to X value
-     * @param yVal Pointer to Y value
-     * @param zVal Pointer to Z value
-     */
-    void getValues(int *xVal, int *yVal, int *zVal);
-    /**
-     * Set the calibration parameters if required.
-     * @param minX Minimum value for X range
-     * @param maxX Maximum value for X range
-     * @param minY Minimum value for Y range
-     * @param maxY maximum value for Y range
-     */
-    void setCalibration(int minX, int maxX, int minY, int maxY);
 
+    void enable(void);
+    void disable(void);
+    uint32_t sampleRate(uint32_t fequency);
+    uint32_t whoAmI(void);
+    uint32_t dataReady(void);
+    void getX(int16_t * x);
+    void getY(int16_t * y);
+    void getZ(int16_t * z);
+    void getX(float * x);
+    void getY(float * y);
+    void getZ(float * z);
+    void getAxis(MotionSensorDataCounts &data);
+    void getAxis(MotionSensorDataUnits &data);
+    void readRegs(int addr, uint8_t * data, int len);
+  
 private:
-    I2C _i2c;
-    int _i2c_address;
-    Serial *_pc;
-    bool _debug;
-    int _avgX, _avgY;
-    int x, y, z;
+  I2C m_i2c;
+  char m_addr;
+  int16_t getMagAxis(uint8_t addr);
+  void writeRegs(uint8_t * data, int len);
 
 };
 #endif