Example program for FXOS8700Q sensor

Dependencies:   FXOS8700Q mbed

Fork of Hello_FXOS8700Q by Freescale

Files at this revision

API Documentation at this revision

Comitter:
sam_grove
Date:
Thu Jun 18 22:54:17 2015 +0000
Parent:
6:02bfeec82bc1
Commit message:
Update example program

Changed in this revision

FXOS8700Q.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 02bfeec82bc1 -r 518e61df67d7 FXOS8700Q.lib
--- a/FXOS8700Q.lib	Fri Apr 25 16:47:00 2014 +0000
+++ b/FXOS8700Q.lib	Thu Jun 18 22:54:17 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/JimCarver/code/FXOS8700Q/#c53dda05b8cf
+http://developer.mbed.org/teams/Freescale/code/FXOS8700Q/#834488c11340
diff -r 02bfeec82bc1 -r 518e61df67d7 main.cpp
--- a/main.cpp	Fri Apr 25 16:47:00 2014 +0000
+++ b/main.cpp	Thu Jun 18 22:54:17 2015 +0000
@@ -1,53 +1,68 @@
+/* FXOS8700Q Example Program
+ * Copyright (c) 2014-2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #include "mbed.h"
 #include "FXOS8700Q.h"
 
-
-//FXOS8700Q acc( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield
-//FXOS8700Q mag( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield
-FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
-FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
-
 Serial pc(USBTX, USBRX);
-
-MotionSensorDataUnits mag_data;
-MotionSensorDataUnits acc_data;
-
-MotionSensorDataCounts mag_raw;
-MotionSensorDataCounts acc_raw;
+I2C i2c(PTE25, PTE24);
+//FXOS8700Q fxos(i2c, FXOS8700CQ_SLAVE_ADDR1);
+FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1);    // Configured for the FRDM-K64F with onboard sensors
+FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1);
+//FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR0);    // Configured for use with the FRDM-MULTI shield
+//FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR0);
 
 
-int main() {
-float faX, faY, faZ;
-float fmX, fmY, fmZ;
-int16_t raX, raY, raZ;
-int16_t rmX, rmY, rmZ;
-acc.enable();
-printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI());
+int main(void)
+{
+    motion_data_units_t acc_data, mag_data;
+    motion_data_counts_t acc_raw, mag_raw;
+    float faX, faY, faZ, fmX, fmY, fmZ, tmp_float;
+    int16_t raX, raY, raZ, rmX, rmY, rmZ, tmp_int;
+
+    acc.enable();
+    mag.enable();
+    printf("FXOS8700QAccelerometer Who Am I= %X\r\n", acc.whoAmI());
+    printf("FXOS8700QMagnetometer Who Am I= %X\r\n", acc.whoAmI());
     while (true) {
+        // counts based results
+        acc.getAxis(acc_raw);
+        mag.getAxis(mag_raw);
+        printf("ACC: X=%06dd Y=%06dd Z=%06dd \t MAG: X=%06dd Y=%06dd Z=%06dd\r\n", acc_raw.x, acc_raw.y, acc_raw.z, mag_raw.x, mag_raw.y, mag_raw.z);
+        acc.getX(raX);
+        acc.getY(raY);
+        acc.getZ(raZ);
+        mag.getX(rmX);
+        mag.getY(rmY);
+        mag.getZ(rmZ);
+        printf("ACC: X=%06dd Y=%06dd Z=%06dd \t MAG: X=%06dd Y=%06dd Z=%06dd\r\n", raX, raY, raZ, rmX, rmY, rmZ);
+        printf("ACC: X=%06dd Y=%06dd Z=%06dd \t MAG: X=%06dd Y=%06dd Z=%06dd\r\n", acc.getX(tmp_int), acc.getY(tmp_int), acc.getZ(tmp_int), mag.getX(tmp_int), mag.getY(tmp_int), mag.getZ(tmp_int));
+        // unit based results
         acc.getAxis(acc_data);
         mag.getAxis(mag_data);
-        printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f  ", acc_data.x, acc_data.y, acc_data.z);
-        printf("    MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data.x, mag_data.y, mag_data.z);
-        acc.getX(&faX);
-        acc.getY(&faY);
-        acc.getZ(&faZ);
-        mag.getX(&fmX);
-        mag.getY(&fmY);
-        mag.getZ(&fmZ);
-        printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f  ", faX, faY, faZ);
-        printf("    MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", fmX, fmY, fmZ);
-        acc.getAxis(acc_raw);
-        mag.getAxis(mag_raw);
-        printf("FXOS8700Q ACC: X=%d Y=%d Z=%d  ", acc_raw.x, acc_raw.y, acc_raw.z);
-        printf("    MAG: X=%d Y=%d Z=%d\r\n", mag_raw.x, mag_raw.y, mag_raw.z);
-        acc.getX(&raX);
-        acc.getY(&raY);
-        acc.getZ(&raZ);
-        mag.getX(&rmX);
-        mag.getY(&rmY);
-        mag.getZ(&rmZ);                
-        printf("FXOS8700Q ACC: X=%d Y=%d Z=%d  ", raX, raY, raZ);
-        printf("    MAG: X=%d Y=%d Z=%d\r\n\n", rmX, rmY, rmZ);    
-        wait(1.0);
+        printf("ACC: X=%1.4ff Y=%1.4ff Z=%1.4ff \t MAG: X=%4.1ff Y=%4.1ff Z=%4.1ff\r\n", acc_data.x, acc_data.y, acc_data.z, mag_data.x, mag_data.y, mag_data.z);
+        acc.getX(faX);
+        acc.getY(faY);
+        acc.getZ(faZ);
+        mag.getX(fmX);
+        mag.getY(fmY);
+        mag.getZ(fmZ);
+        printf("ACC: X=%1.4ff Y=%1.4ff Z=%1.4ff \t MAG: X=%4.1ff Y=%4.1ff Z=%4.1ff\r\n", faX, faY, faZ, fmX, fmY, fmZ);
+        printf("ACC: X=%1.4ff Y=%1.4ff Z=%1.4ff \t MAG: X=%4.1ff Y=%4.1ff Z=%4.1ff\r\n", acc.getX(tmp_float), acc.getY(tmp_float), acc.getZ(tmp_float), mag.getX(tmp_float), mag.getY(tmp_float), mag.getZ(tmp_float));
+        puts("");
+        wait(5.0f);
     }
 }
\ No newline at end of file
diff -r 02bfeec82bc1 -r 518e61df67d7 mbed.bld
--- a/mbed.bld	Fri Apr 25 16:47:00 2014 +0000
+++ b/mbed.bld	Thu Jun 18 22:54:17 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file