A basic library for the FXOS8700Q combination accelerometer / magnetometer

Dependencies:   MotionSensor

Dependents:   K64F_eCompass_LCD Hello_FXOS8700Q rtos_compass K64F_eCompass ... more

This library supports the 6 axis combination Accelerometer / Magnetometer. Functions are provided to retrieve data in raw 16 bit signed integers or unit converted G's and micro-teslas

Revision:
2:ab84f99086e5
Parent:
1:8b53edef272f
diff -r 8b53edef272f -r ab84f99086e5 FXOS8700Q.cpp
--- a/FXOS8700Q.cpp	Sun Apr 13 21:22:58 2014 +0000
+++ b/FXOS8700Q.cpp	Mon Apr 14 17:13:15 2014 +0000
@@ -3,8 +3,16 @@
 
 
 FXOS8700Q::FXOS8700Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
+
+}
+
+
+FXOS8700Q::~FXOS8700Q() { }
+
+void FXOS8700Q::enable(void) {
     // activate the peripheral
     uint8_t data[2] = {FXOS8700Q_CTRL_REG1, 0x00};
+    m_i2c.frequency(400000);
     writeRegs(data, 2);
     data[0] = FXOS8700Q_M_CTRL_REG1;
     data[1] = 0x1F;
@@ -18,11 +26,8 @@
     data[0] = FXOS8700Q_CTRL_REG1;
     data[1] = 0x19;//0x1D;
     writeRegs(data, 2);
-}
-
-
-FXOS8700Q::~FXOS8700Q() { }
-
+    }
+    
 uint8_t FXOS8700Q::getWhoAmI() {
     uint8_t who_am_i = 0;
     readRegs(FXOS8700Q_WHOAMI, &who_am_i, 1);
@@ -30,15 +35,15 @@
 }
 
 float FXOS8700Q::getAccX() {
-    return (float(getAccAxis(FXOS8700Q_OUT_X_MSB))/4096.0);
+    return (float(getAccAxis(FXOS8700Q_OUT_X_MSB))/4096.0f);
 }
 
 float FXOS8700Q::getAccY() {
-    return (float(getAccAxis(FXOS8700Q_OUT_Y_MSB))/4096.0);
+    return (float(getAccAxis(FXOS8700Q_OUT_Y_MSB))/4096.0f);
 }
 
 float FXOS8700Q::getAccZ() {
-    return (float(getAccAxis(FXOS8700Q_OUT_Z_MSB))/4096.0);
+    return (float(getAccAxis(FXOS8700Q_OUT_Z_MSB))/4096.0f);
 }
 
 
@@ -96,7 +101,7 @@
 }
 
 void FXOS8700Q::writeRegs(uint8_t * data, int len) {
-    m_i2c.write(m_addr, (char *)data, len);
+    if(m_i2c.write(m_addr, (char *)data, len)) printf("WRite Error\r\n");
 }
 
     
\ No newline at end of file