the emg filtering part of the program

Dependencies:   HIDScope biquadFilter mbed MODSERIAL

Fork of EMG by Tom Tom

Revision:
29:ac08c1a32c54
Parent:
28:3b1b29193851
Child:
30:7cc564d38bc4
--- a/main.cpp	Mon Oct 24 08:47:19 2016 +0000
+++ b/main.cpp	Mon Oct 24 22:28:43 2016 +0000
@@ -2,7 +2,6 @@
 #include "HIDScope.h"
 #include "BiQuad.h"
 #include "MODSERIAL.h"
-#include <string.h>
 
 //Define objects
 
@@ -21,6 +20,7 @@
 volatile bool buttonflag = false;
 volatile bool newcase = false;
 volatile bool newcaseprint = false;
+volatile bool change_ref_timer = false;
 
 double threshold = 0.04;
 double samplefreq=0.002;
@@ -77,6 +77,7 @@
 void sampleflag()
 {
     sampletimer=true;
+    change_ref_timer=true;
 }
 
 void buttonflag_go()
@@ -169,10 +170,7 @@
     } else {
         newcase=true;
         newcaseprint=true;
-
     }
-
-    sampletimer = false;
 }
 
 void sample(states &mystate)
@@ -192,6 +190,7 @@
     scope.set(4, emg3.read());    //original signal
     emg22=bqc33.step(fabs(bqc31.step(emg3.read())));
     scope.set(5, emg22);
+
     //pc.printf("Hello World!\n");
     /*   Ensure that enough channels are available (HIDScope scope( 2 ))
      *   Finally, send all channels to the PC at once */
@@ -234,8 +233,6 @@
         newcaseprint=true;
         newcase=true;
     }
-
-    sampletimer = false;
 }
 
 void change_x(int direction)
@@ -246,13 +243,13 @@
 
 void change_y(int direction)
 {
-    ref_y=ref_y+0.1*direction;
+    ref_y=ref_y+0.0002*direction;
 
 }
 void change_xy(int direction)
 {
-    ref_x=ref_x+0.1*direction;
-    ref_y=ref_y+0.1*direction;
+    ref_x=ref_x+0.0002*direction;
+    ref_y=ref_y+0.0002*direction;
 }
 
 void my_pos()
@@ -261,7 +258,7 @@
 
 }
 
-void print_state(states mystate)
+void print_state()
 {
     // switch, case
     if (newcaseprint==true) {
@@ -271,33 +268,55 @@
                 break;
             }
             case STATE_X : // run
-                    pc.printf("X\n\r");
+                pc.printf("X\n\r");
                 break;
             case STATE_X_NEG : // run
-                    pc.printf("Xneg\n\r");
+                pc.printf("Xneg\n\r");
                 break;
             case STATE_Y : // execute mode 1
-                    pc.printf("Y\n\r");
+                pc.printf("Y\n\r");
                 break;
             case STATE_Y_NEG : // execute mode 1
-                    pc.printf("Yneg\n\r");
+                pc.printf("Yneg\n\r");
                 break;
             case STATE_XY : // execute mode 2
-                    pc.printf("XY\n\r");
+                pc.printf("XY\n\r");
                 break;
             case STATE_XY_NEG : // execute mode 2
-                    pc.printf("XYneg\n\r");
+                pc.printf("XYneg\n\r");
                 break;
             case STATE_PAUZE : // default
-                    pc.printf("PAUZE\n\r");
+                pc.printf("PAUZE\n\r");
                 break;
         }
     }
 
 }
 
+void change_ref()
+{
+    if (change_ref_timer==true) {
+        if (mystate == STATE_X) {
+            change_x(1);
+        } else if (mystate == STATE_X_NEG) {
+            change_x(-1);
+        } else if (mystate == STATE_Y) {
+            change_y(1);
+        } else if (mystate == STATE_Y_NEG) {
+            change_y(-1);
+        } else if (mystate == STATE_XY) {
+            change_xy(1);
+        } else if (mystate == STATE_XY_NEG) {
+            change_xy(-1);
+        }
+        change_ref_timer=false;
+    }
+}
+
+
 int main()
 {
+    pc.printf("RESET\n\r");
     pc.baud(115200);
 
     //de biquad chains instellen
@@ -318,8 +337,12 @@
     while(1) {
         if (sampletimer==true) {
             //sample(mystate);
-            sample_button(mystate);
-            print_state(mystate);
+            sample(mystate);
+            print_state();
+            change_ref();
+            sampletimer = false;
+
+
         }
     }
 }
\ No newline at end of file