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

Files at this revision

API Documentation at this revision

Comitter:
JimCarver
Date:
Wed Apr 23 17:12:15 2014 +0000
Parent:
4:be6abf9f2d59
Child:
6:cdc362f08339
Commit message:
experiment

Changed in this revision

FXOS8700Q.cpp Show annotated file Show diff for this revision Revisions of this file
FXOS8700Q.h Show annotated file Show diff for this revision Revisions of this file
MotionSensor.lib Show annotated file Show diff for this revision Revisions of this file
--- a/FXOS8700Q.cpp	Sat Apr 19 00:16:49 2014 +0000
+++ b/FXOS8700Q.cpp	Wed Apr 23 17:12:15 2014 +0000
@@ -20,7 +20,7 @@
 #define UINT14_MAX        16383
 
 
-FXOS8700Q::FXOS8700Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
+FXOS8700Q_acc::FXOS8700Q_acc(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
     // activate the peripheral
     uint8_t data[2] = {FXOS8700Q_CTRL_REG1, 0x00};
     m_i2c.frequency(400000);
@@ -40,34 +40,34 @@
 }
 
 
-FXOS8700Q::~FXOS8700Q() { }
+FXOS8700Q_acc::~FXOS8700Q_acc() { }
 
-uint8_t FXOS8700Q::getWhoAmI() {
+uint8_t FXOS8700Q_acc::getWhoAmI() {
     uint8_t who_am_i = 0;
     readRegs(FXOS8700Q_WHOAMI, &who_am_i, 1);
     return who_am_i;
 }
 
-float FXOS8700Q::getAccX() {
+float FXOS8700Q_acc::getAccX() {
     return (float(getAccAxis(FXOS8700Q_OUT_X_MSB))/4096.0);
 }
 
-float FXOS8700Q::getAccY() {
+float FXOS8700Q_acc::getAccY() {
     return (float(getAccAxis(FXOS8700Q_OUT_Y_MSB))/4096.0);
 }
 
-float FXOS8700Q::getAccZ() {
+float FXOS8700Q_acc::getAccZ() {
     return (float(getAccAxis(FXOS8700Q_OUT_Z_MSB))/4096.0);
 }
 
 
-void FXOS8700Q::getAccAllAxis(float * res) {
-    res[0] = getAccX();
-    res[1] = getAccY();
-    res[2] = getAccZ();
+void FXOS8700Q_acc::getAxis(MotionSensorDataUnits * data) {
+    data->x = getAccX();
+    data->y = getAccY();
+    data->z = getAccZ();
 }
 
-void FXOS8700Q::AccXYZraw(int16_t * d) {
+void FXOS8700Q_acc::getAxis(MotionSensorDataCounts * data {
     int16_t acc;
     uint8_t res[6];
     readRegs(FXOS8700Q_OUT_X_MSB, res, 6);
@@ -75,18 +75,18 @@
     acc = (res[0] << 6) | (res[1] >> 2);
     if (acc > UINT14_MAX/2)
         acc -= UINT14_MAX;
-    d[0] = acc;
+    data->x = acc;
     acc = (res[2] << 6) | (res[3] >> 2);
     if (acc > UINT14_MAX/2)
         acc -= UINT14_MAX;
-    d[1] = acc;
+    data->y = acc;
     acc = (res[4] << 6) | (res[5] >> 2);
     if (acc > UINT14_MAX/2)
         acc -= UINT14_MAX;
-    d[2] = acc;
+    data->z = acc;
 }
 
-void FXOS8700Q::MagXYZraw(int16_t * d) {
+void FXOS8700Q_acc::MagXYZraw(int16_t * d) {
     int16_t acc;
     uint8_t res[6];
     readRegs(FXOS8700Q_M_OUT_X_MSB, res, 6);
@@ -96,7 +96,7 @@
     d[2] = (res[4] << 8) | res[5];
 }
 
-void FXOS8700Q::getMagAllAxis(float * res) {
+void FXOS8700Q_acc::getMagAllAxis(float * res) {
     int16_t raw[3];
     MagXYZraw( raw);
     res[0] = (float) raw[0] * 0.1f;
@@ -104,7 +104,7 @@
     res[2] = (float) raw[2] * 0.1f;
 }        
     
-int16_t FXOS8700Q::getAccAxis(uint8_t addr) {
+int16_t FXOS8700Q_acc::getAccAxis(uint8_t addr) {
     int16_t acc;
     uint8_t res[2];
     readRegs(addr, res, 2);
@@ -116,13 +116,13 @@
     return acc;
 }
 
-void FXOS8700Q::readRegs(int addr, uint8_t * data, int len) {
+void FXOS8700Q_acc::readRegs(int addr, uint8_t * data, int len) {
     char t[1] = {addr};
     m_i2c.write(m_addr, t, 1, true);
     m_i2c.read(m_addr, (char *)data, len);
 }
 
-void FXOS8700Q::writeRegs(uint8_t * data, int len) {
+void FXOS8700Q_acc::writeRegs(uint8_t * data, int len) {
     m_i2c.write(m_addr, (char *)data, len);
 }
 
--- a/FXOS8700Q.h	Sat Apr 19 00:16:49 2014 +0000
+++ b/FXOS8700Q.h	Wed Apr 23 17:12:15 2014 +0000
@@ -20,6 +20,7 @@
 #define FXOS8700Q_H
 
 #include "mbed.h"
+#include "MotionSensor.h"
 // FXOS8700CQ I2C address
 #define FXOS8700CQ_SLAVE_ADDR0 (0x1E<<1) // with pins SA0=0, SA1=0
 #define FXOS8700CQ_SLAVE_ADDR1 (0x1D<<1) // with pins SA0=1, SA1=0
@@ -66,7 +67,7 @@
 * @endcode
 */
 
-class FXOS8700Q
+class FXOS8700Q : public MotionSensor
 {
 public:
   /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MotionSensor.lib	Wed Apr 23 17:12:15 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/components/code/MotionSensor/#821b100de6e1