51 52 with same code
Dependencies: MtSense07
Fork of MtConnect04S_MtSense07 by
Revision 4:4ca64a863fbf, committed 2018-04-27
- Comitter:
- johnathanlyu
- Date:
- Fri Apr 27 10:00:21 2018 +0000
- Parent:
- 3:bca765439d71
- Commit message:
- 51 52 with same code
Changed in this revision
img/uvision.png | 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 |
diff -r bca765439d71 -r 4ca64a863fbf img/uvision.png
diff -r bca765439d71 -r 4ca64a863fbf main.cpp --- a/main.cpp Thu Mar 23 08:55:23 2017 +0000 +++ b/main.cpp Fri Apr 27 10:00:21 2018 +0000 @@ -21,21 +21,68 @@ #include "AK09970.h" #include "config.h" +I2C i2c(p3, p2); + +#ifdef NRF52 +Serial pc(p18, p16); +DigitalOut reset_sensor(p24, 1); // Reset pin for AK09970 (Low active) +AK9750 ak9750(i2c, p5); +#else Serial pc(p15, p16); - DigitalOut reset_sensor(p4, 1); // Reset pin for AK09970 (Low active) -I2C i2c(p3, p2); AK9750 ak9750(i2c, p0); +#endif + AK09912 ak09912(i2c); AK09970 ak09970(i2c); volatile bool isIntEvent = false; +static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE); +int32_t count = 0; //============================================================================== static void IntEventCallback() { isIntEvent = true; } +void readSensorCallback() { +#if (CONFIG_RUN_MODE == RUN_ALL_SENSOR_COM) + AK9750::Data ak9750_data; + AK09912::Data ak09912_data; + AK09970::Data ak09970_data; + int32_t triggered_area; + ak9750.GetData(&ak9750_data); + triggered_area = ak9750.GetTriggeredAreaNum(&ak9750_data); + pc.printf("AK9750(%5.1fpA, %5.1fpA, %5.1fpA, %5.1fpA, %2.1f'C, Area%d)\n", + ak9750_data.ir1, ak9750_data.ir2, ak9750_data.ir3, ak9750_data.ir4, ak9750_data.tmp, triggered_area); + ak09912.GetData(&ak09912_data); + pc.printf("AK09912(%5.1fuT/LSB, %5.1fuT/LSB, %5.1fuT/LSB, %2.1f'C)\n", + ak09912_data.x, ak09912_data.y, ak09912_data.z, ak09912_data.t); + + ak09970.GetData(&ak09970_data); + pc.printf("AK09970(%6.1fuT/LSB, %6.1fuT/LSB, %6.1fuT/LSB)\n", + ak09970_data.x, ak09970_data.y, ak09970_data.z); + + pc.printf("\n"); +#elif (CONFIG_RUN_MODE == RUN_IR_AK9750_APP) + AK9750::Data ak9750_data; + ak9750.GetData(&ak9750_data); + pc.printf(" 3:%d,%d,%d,%d,%d,\r", count, (int32_t)ak9750_data.ir1, (int32_t)ak9750_data.ir2, (int32_t)ak9750_data.ir3, (int32_t)ak9750_data.ir4); + count++; + +#elif (CONFIG_RUN_MODE == RUN_COMPASS_AK09912_APP) + AK09912::Data ak09912_data; + ak09912.GetData(&ak09912_data); + pc.printf("C:%d,%d,%d,%d\r", count, (int32_t)ak09912_data.x, (int32_t)ak09912_data.y, (int32_t)ak09912_data.z); + count++; + +#elif (CONFIG_RUN_MODE == RUN_MAGNETIC_AK09970_APP) + AK09970::Data ak09970_data; + ak09970.GetData(&ak09970_data); + pc.printf("C:%d,%d,%d,%d\r", count, (int32_t)ak09970_data.x, (int32_t)ak09970_data.y, (int32_t)ak09970_data.z); + count++; +#endif +} //============================================================================== int main() { /* Disable the hardware flow control of Serial, then show the mbed version */ @@ -83,54 +130,21 @@ /* Main loop */ #if (CONFIG_RUN_MODE == RUN_ALL_SENSOR_COM) - AK9750::Data ak9750_data; - AK09912::Data ak09912_data; - AK09970::Data ak09970_data; - int32_t triggered_area; - while (1) { - ak9750.GetData(&ak9750_data); - triggered_area = ak9750.GetTriggeredAreaNum(&ak9750_data); - pc.printf("AK9750(%5.1fpA, %5.1fpA, %5.1fpA, %5.1fpA, %2.1f'C, Area%d)\n", - ak9750_data.ir1, ak9750_data.ir2, ak9750_data.ir3, ak9750_data.ir4, ak9750_data.tmp, triggered_area); - - ak09912.GetData(&ak09912_data); - pc.printf("AK09912(%5.1fuT/LSB, %5.1fuT/LSB, %5.1fuT/LSB, %2.1f'C)\n", - ak09912_data.x, ak09912_data.y, ak09912_data.z, ak09912_data.t); - - ak09970.GetData(&ak09970_data); - pc.printf("AK09970(%6.1fuT/LSB, %6.1fuT/LSB, %6.1fuT/LSB)\n", - ak09970_data.x, ak09970_data.y, ak09970_data.z); - - pc.printf("\n"); - wait(1); - } + eventQueue.call_every(200, readSensorCallback); + eventQueue.dispatch_forever(); + #elif (CONFIG_RUN_MODE == RUN_IR_AK9750_APP) - AK9750::Data ak9750_data; - int32_t count = 0; - while (1) { - ak9750.GetData(&ak9750_data); - pc.printf(" 3:%d,%d,%d,%d,%d,\r", count, (int32_t)ak9750_data.ir1, (int32_t)ak9750_data.ir2, (int32_t)ak9750_data.ir3, (int32_t)ak9750_data.ir4); - count++; - wait(1); - } + eventQueue.call_every(200, readASensorCallback); + eventQueue.dispatch_forever(); + #elif (CONFIG_RUN_MODE == RUN_COMPASS_AK09912_APP) - AK09912::Data ak09912_data; - int32_t count = 0; - while (1) { - ak09912.GetData(&ak09912_data); - pc.printf("C:%d,%d,%d,%d\r", count, (int32_t)ak09912_data.x, (int32_t)ak09912_data.y, (int32_t)ak09912_data.z); - count++; - wait(1); - } + eventQueue.call_every(200, readASensorCallback); + eventQueue.dispatch_forever(); + #elif (CONFIG_RUN_MODE == RUN_MAGNETIC_AK09970_APP) - AK09970::Data ak09970_data; - int32_t count = 0; - while (1) { - ak09970.GetData(&ak09970_data); - pc.printf("C:%d,%d,%d,%d\r", count, (int32_t)ak09970_data.x, (int32_t)ak09970_data.y, (int32_t)ak09970_data.z); - count++; - wait(1); - } + eventQueue.call_every(200, readASensorCallback); + eventQueue.dispatch_forever(); + #elif (CONFIG_RUN_MODE == RUN_IR_AK9750_INT_COM) // Enable interrupt sources and set callback function ak9750.SetIntEvent(AK9750::INT_DR, &IntEventCallback);