reeeeeeeeeeeeeee
Dependencies: MotionSensor mbed
Fork of Assignment2_ver3 by
Diff: Hardware.cpp
- Revision:
- 8:45befd2bb1e5
- Parent:
- 7:6dc42e1a2a81
- Child:
- 9:751e39d24c39
--- a/Hardware.cpp Tue Nov 29 20:21:45 2016 +0000 +++ b/Hardware.cpp Tue Nov 29 20:32:27 2016 +0000 @@ -3,6 +3,20 @@ #define LOW 0 #define HIGH 1 + +#include "pinmap.h" +#include "FXOS8700Q.h" + +//////////////////////////////////////////////////////// +FXOS8700Q_acc acc(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); + +/* Constants and Declares */ +int numCount; +int const MAX_NUM_COUNTS = 3; +int const TIMING_PERIOD = 20; // Sensor polling interval + +uint8_t motion_exceeded_threshold = 0; +/////////////////////////////////////////// DigitalOut output_pin_A(LED3); DigitalOut output_pin_V(LED2); /*=== Analog In ===*/ @@ -193,4 +207,53 @@ aout = 0.5; wait(1); aout = 0;*/ +} +/////////////////////////////////////////////////////////////////////////////////////////////// + +void initialize_motion () { + acc.enable(); +} + +bool isMotionThresholdExceeded () { + return motion_exceeded_threshold; +} + +void resetMotionDetection () { + motion_exceeded_threshold = 0; +} + +/**** Function: a_count + * return: void + * parameters: none + * A function called if motion detection interrupt flag is set. Maintains + * a global counter and sets a timer to keep track of number of flags within + * timing limit. + */ +void a_count(void) { + /* step 1 increment the counter */ + numCount++; + + + if (numCount >= MAX_NUM_COUNTS) { + rled = !rled; // toggle LEDs to show acceleration threshold reached + gled = !gled; // toggle LEDS to show acceleration threshold reached + + motion_exceeded_threshold = 1; + } +} + +void motion_thread () { + while(true) { + + float xAcc, yAcc, zAcc; + acc.getX(&xAcc); + acc.getY(&yAcc); + acc.getZ(&zAcc); + float magtd = xAcc*xAcc + yAcc*yAcc + zAcc*zAcc; + + if (magtd > 3.0f) { // Greater than (1.5G of Accel.)^2 + a_count(); // increment acceleration event counter + } + + } } \ No newline at end of file