An eCompass library only for use on FPU enabled platforms like the K64F
Dependents: K64F_eCompass_LCD rtos_compass K64F_eCompass GPS_6Axis_DataLogger_SD_UDP ... more
Fork of eCompass_Lib by
Revision 6:37bc03c3b1f9, committed 2014-05-05
- Comitter:
- JimCarver
- Date:
- Mon May 05 17:38:37 2014 +0000
- Parent:
- 5:aeaceeb90d58
- Commit message:
- Updated eCompass which conforms to the virtual MotionSensor class
Changed in this revision
eCompass_Lib.cpp | Show annotated file Show diff for this revision Revisions of this file |
eCompass_Lib.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r aeaceeb90d58 -r 37bc03c3b1f9 eCompass_Lib.cpp --- a/eCompass_Lib.cpp Mon Apr 14 17:13:59 2014 +0000 +++ b/eCompass_Lib.cpp Mon May 05 17:38:37 2014 +0000 @@ -5,13 +5,21 @@ extern void init_eCompass(void); extern void calibrate_eCompass(void); -extern void hal_map(int16_t * acc_raw, int16_t * mag_raw); +extern void hal_map(MotionSensorDataCounts * acc_raw, MotionSensorDataCounts * mag_raw); axis6_t axis6; uint32_t seconds; uint32_t compass_type; int32_t tcount; uint8_t cdebug; + +/* +typedef struct MotionSensorDataCounts +{ + int16_t x, y, z; +} MotionSensorDataCounts; +*/ + eCompass::eCompass() { init_eCompass(); @@ -26,36 +34,36 @@ //eCompass::~eCompass() { } -void eCompass::run(int16_t * acc_raw, int16_t * mag_raw) +void eCompass::run(MotionSensorDataCounts &acc_raw, MotionSensorDataCounts &mag_raw) { axis6.timestamp = tcount; - hal_map(acc_raw, mag_raw); + hal_map(&acc_raw, &mag_raw); // // raw data - axis6.acc_x = acc_raw[0]; - axis6.acc_y = acc_raw[1]; - axis6.acc_z = acc_raw[2]; - axis6.mag_x = mag_raw[0]; - axis6.mag_y = mag_raw[1]; - axis6.mag_z = mag_raw[2]; + axis6.acc_x = acc_raw.x; + axis6.acc_y = acc_raw.y; + axis6.acc_z = acc_raw.z; + axis6.mag_x = mag_raw.x; + axis6.mag_y = mag_raw.y; + axis6.mag_z = mag_raw.z; // // raw data converted to floating ouing - axis6.fax = (float) acc_raw[0]; - axis6.fay = (float) acc_raw[1]; - axis6.faz = (float) acc_raw[2]; - axis6.fmx = (float) mag_raw[0]; - axis6.fmy = (float) mag_raw[1]; - axis6.fmz = (float) mag_raw[2]; + axis6.fax = (float) acc_raw.x; + axis6.fay = (float) acc_raw.y; + axis6.faz = (float) acc_raw.z; + axis6.fmx = (float) mag_raw.x; + axis6.fmy = (float) mag_raw.y; + axis6.fmz = (float) mag_raw.z; // // Accelerometer data converted to Gs - axis6.fGax = ((float) acc_raw[0]) / 4096.0f; - axis6.fGay = ((float) acc_raw[1]) / 4096.0f; - axis6.fGaz = ((float) acc_raw[2]) / 4096.0f; + axis6.fGax = ((float) acc_raw.x) / 4096.0f; + axis6.fGay = ((float) acc_raw.y) / 4096.0f; + axis6.fGaz = ((float) acc_raw.z) / 4096.0f; // // Magnetometer data converted to microteslas - axis6.fUTmx = ((float) mag_raw[0]) / 10.0f; - axis6.fUTmy = ((float) mag_raw[1]) / 10.0f; - axis6.fUTmz = ((float) mag_raw[2]) / 10.0f; + axis6.fUTmx = ((float) mag_raw.x) / 10.0f; + axis6.fUTmy = ((float) mag_raw.y) / 10.0f; + axis6.fUTmz = ((float) mag_raw.z) / 10.0f; //printf("r"); if(!cdebug) run_eCompass(); }
diff -r aeaceeb90d58 -r 37bc03c3b1f9 eCompass_Lib.h --- a/eCompass_Lib.h Mon Apr 14 17:13:59 2014 +0000 +++ b/eCompass_Lib.h Mon May 05 17:38:37 2014 +0000 @@ -13,7 +13,8 @@ #define ECOMPASS_H__ #include "mbed.h" -//#include "Wi-Go_eCompass_Lib_V3.ar" +#include "MotionSensor.h" + #ifdef __cplusplus extern "C" { @@ -44,6 +45,8 @@ #define FCOUNTSPERUT 10.0F // sensor specific: MAG3110 provide 10 counts / uT #define FCOUNTSPERG 4096.0F // sensor specific: MMA8451 provide 4096 counts / g in 2g mode + + typedef struct { // Always 1 uint16 packet_id; @@ -75,7 +78,7 @@ { public: eCompass(); - void run(int16_t * acc, int16_t * mag); + void run(MotionSensorDataCounts &acc_raw, MotionSensorDataCounts &mag_raw); void calibrate(void); void init(void);