reeeeeeeeeeeeeee

Dependencies:   MotionSensor mbed

Fork of Assignment2_ver3 by weeb grammers

Files at this revision

API Documentation at this revision

Comitter:
weebgrammers
Date:
Tue Nov 29 22:06:14 2016 +0000
Parent:
8:45befd2bb1e5
Commit message:
r

Changed in this revision

Hardware.cpp 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
motion.cpp Show annotated file Show diff for this revision Revisions of this file
motion.h Show annotated file Show diff for this revision Revisions of this file
--- a/Hardware.cpp	Tue Nov 29 20:32:27 2016 +0000
+++ b/Hardware.cpp	Tue Nov 29 22:06:14 2016 +0000
@@ -4,18 +4,18 @@
 #define LOW  0
 #define HIGH 1
 
-#include "pinmap.h"
-#include "FXOS8700Q.h"
+//#include "pinmap.h"
+//#include "FXOS8700Q.h"
 
 ////////////////////////////////////////////////////////
-FXOS8700Q_acc acc(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
+//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
+//int numCount;
+//int const MAX_NUM_COUNTS = 3;
+//int const TIMING_PERIOD = 20; // Sensor polling interval
 
-uint8_t motion_exceeded_threshold = 0;
+//uint8_t motion_exceeded_threshold = 0;
 ///////////////////////////////////////////
 DigitalOut output_pin_A(LED3);
 DigitalOut output_pin_V(LED2);
@@ -210,7 +210,7 @@
 }
 ///////////////////////////////////////////////////////////////////////////////////////////////
 
-void initialize_motion () {
+/*void initialize_motion () {
     acc.enable();
 }
 
@@ -229,8 +229,8 @@
  * 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 */
+/*void a_count(void) {
+    /* step 1 increment the counter 
     numCount++;
     
 
@@ -256,4 +256,4 @@
         }
 
     }   
-}
\ No newline at end of file
+}*/
\ No newline at end of file
--- a/main.cpp	Tue Nov 29 20:32:27 2016 +0000
+++ b/main.cpp	Tue Nov 29 22:06:14 2016 +0000
@@ -1,9 +1,11 @@
 #include "mbed.h"
 #include "PaceHeart.h"
 #include "Hardware.h"
+#include "motion.h"
 //DigitalOut output_pin_A(LED1);
 
 PaceHeart* Pacer = new PaceHeart;
+
 DigitalOut led(LED1);
 Serial pc(USBTX, USBRX);
 void setup() {
@@ -13,8 +15,12 @@
 
 int main() {
     setup();
+    initialize_motion ();
     while(1){
-    Output_V(1.0,0.4);
+        
+    Pacer->pace_V();
+    //motionThread.start(motion_thread);
+    motion_thread(*Pacer);
     //Check_serial(pc,*Pacer);
     }
     //Pacer-> pace_A();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motion.cpp	Tue Nov 29 22:06:14 2016 +0000
@@ -0,0 +1,68 @@
+//#include "rtos.h"
+#include "Hardware.h"
+#include "FXOS8700Q.h"
+#include "PaceHeart.h"
+
+FXOS8700Q_acc acc(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
+
+//PaceHeart* Pacing = new PaceHeart;
+
+/* 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;
+
+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 (PaceHeart &Pacing) {
+    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 > 1.0f) { // Greater than (1.5G of Accel.)^2
+            a_count();      // increment acceleration event counter
+            Pacing.set_dir(1);
+            Pacing.set_p_vPaceWidth(Pacing.get_p_vPaceWidth()+0.1);
+            Pacing.set_p_vPaceAmp(Pacing.get_p_vPaceAmp()+500);
+            
+        }
+
+        wait(TIMING_PERIOD); 
+    }   
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motion.h	Tue Nov 29 22:06:14 2016 +0000
@@ -0,0 +1,11 @@
+#ifndef MOTION_H
+#define MOTION_H
+
+bool isMotionThresholdExceeded ();
+void resetMotionDetection ();
+void initialize_motion ();
+void motion_thread (PaceHeart &Pacer);
+
+
+
+#endif
\ No newline at end of file