reeeeeeeeeeeeeee

Dependencies:   MotionSensor mbed

Fork of Assignment2_ver3 by weeb grammers

Committer:
weebgrammers
Date:
Tue Nov 29 22:06:14 2016 +0000
Revision:
9:751e39d24c39
r

Who changed what in which revision?

UserRevisionLine numberNew contents of line
weebgrammers 9:751e39d24c39 1 //#include "rtos.h"
weebgrammers 9:751e39d24c39 2 #include "Hardware.h"
weebgrammers 9:751e39d24c39 3 #include "FXOS8700Q.h"
weebgrammers 9:751e39d24c39 4 #include "PaceHeart.h"
weebgrammers 9:751e39d24c39 5
weebgrammers 9:751e39d24c39 6 FXOS8700Q_acc acc(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
weebgrammers 9:751e39d24c39 7
weebgrammers 9:751e39d24c39 8 //PaceHeart* Pacing = new PaceHeart;
weebgrammers 9:751e39d24c39 9
weebgrammers 9:751e39d24c39 10 /* Constants and Declares */
weebgrammers 9:751e39d24c39 11 int numCount;
weebgrammers 9:751e39d24c39 12 int const MAX_NUM_COUNTS = 3;
weebgrammers 9:751e39d24c39 13 int const TIMING_PERIOD = 20; // Sensor polling interval
weebgrammers 9:751e39d24c39 14
weebgrammers 9:751e39d24c39 15 uint8_t motion_exceeded_threshold = 0;
weebgrammers 9:751e39d24c39 16
weebgrammers 9:751e39d24c39 17 void initialize_motion () {
weebgrammers 9:751e39d24c39 18 acc.enable();
weebgrammers 9:751e39d24c39 19 }
weebgrammers 9:751e39d24c39 20
weebgrammers 9:751e39d24c39 21 bool isMotionThresholdExceeded () {
weebgrammers 9:751e39d24c39 22 return motion_exceeded_threshold;
weebgrammers 9:751e39d24c39 23 }
weebgrammers 9:751e39d24c39 24
weebgrammers 9:751e39d24c39 25 void resetMotionDetection () {
weebgrammers 9:751e39d24c39 26 motion_exceeded_threshold = 0;
weebgrammers 9:751e39d24c39 27 }
weebgrammers 9:751e39d24c39 28
weebgrammers 9:751e39d24c39 29 /**** Function: a_count
weebgrammers 9:751e39d24c39 30 * return: void
weebgrammers 9:751e39d24c39 31 * parameters: none
weebgrammers 9:751e39d24c39 32 * A function called if motion detection interrupt flag is set. Maintains
weebgrammers 9:751e39d24c39 33 * a global counter and sets a timer to keep track of number of flags within
weebgrammers 9:751e39d24c39 34 * timing limit.
weebgrammers 9:751e39d24c39 35 */
weebgrammers 9:751e39d24c39 36 void a_count(void) {
weebgrammers 9:751e39d24c39 37 /* step 1 increment the counter */
weebgrammers 9:751e39d24c39 38 numCount++;
weebgrammers 9:751e39d24c39 39
weebgrammers 9:751e39d24c39 40
weebgrammers 9:751e39d24c39 41 if (numCount >= MAX_NUM_COUNTS) {
weebgrammers 9:751e39d24c39 42 //rled = !rled; // toggle LEDs to show acceleration threshold reached
weebgrammers 9:751e39d24c39 43 //gled = !gled; // toggle LEDS to show acceleration threshold reached
weebgrammers 9:751e39d24c39 44
weebgrammers 9:751e39d24c39 45 motion_exceeded_threshold = 1;
weebgrammers 9:751e39d24c39 46 }
weebgrammers 9:751e39d24c39 47 }
weebgrammers 9:751e39d24c39 48
weebgrammers 9:751e39d24c39 49 void motion_thread (PaceHeart &Pacing) {
weebgrammers 9:751e39d24c39 50 while(true) {
weebgrammers 9:751e39d24c39 51
weebgrammers 9:751e39d24c39 52 float xAcc, yAcc, zAcc;
weebgrammers 9:751e39d24c39 53 acc.getX(&xAcc);
weebgrammers 9:751e39d24c39 54 acc.getY(&yAcc);
weebgrammers 9:751e39d24c39 55 acc.getZ(&zAcc);
weebgrammers 9:751e39d24c39 56 float magtd = xAcc*xAcc + yAcc*yAcc + zAcc*zAcc;
weebgrammers 9:751e39d24c39 57
weebgrammers 9:751e39d24c39 58 if (magtd > 1.0f) { // Greater than (1.5G of Accel.)^2
weebgrammers 9:751e39d24c39 59 a_count(); // increment acceleration event counter
weebgrammers 9:751e39d24c39 60 Pacing.set_dir(1);
weebgrammers 9:751e39d24c39 61 Pacing.set_p_vPaceWidth(Pacing.get_p_vPaceWidth()+0.1);
weebgrammers 9:751e39d24c39 62 Pacing.set_p_vPaceAmp(Pacing.get_p_vPaceAmp()+500);
weebgrammers 9:751e39d24c39 63
weebgrammers 9:751e39d24c39 64 }
weebgrammers 9:751e39d24c39 65
weebgrammers 9:751e39d24c39 66 wait(TIMING_PERIOD);
weebgrammers 9:751e39d24c39 67 }
weebgrammers 9:751e39d24c39 68 }