CIS441 Controller

Dependencies:   TextLCD mbed-rtos mbed

Fork of PacemakerController by Chad Nachiappan

Revision:
35:b5e8650a7669
Parent:
34:b4b50ca26e8c
Child:
38:ceabf8f1dfa0
Child:
39:51c4ec84f6fd
Child:
41:d806d68f7969
--- a/PacemakerController.cpp	Wed Dec 02 04:43:10 2015 +0000
+++ b/PacemakerController.cpp	Wed Dec 02 04:54:53 2015 +0000
@@ -257,61 +257,59 @@
     t_count.start();
     t_count.reset();
 
-    char a = 'Z';
     while(1) {
-                    
-    if (pc.readable()) {
-
-        a = pc.getc();
-
-        // Handle different keyboard inputs
-
-        if (a >= '0' && a <= '9') {
-            // update observation interval
-            obs_int = (a - '0' + 1) * 5;
-        } else {
-            pc.printf("Expected numeric key\n");
+        if (pc.readable()) {
+    
+            char a = pc.getc();
+    
+            // Handle different keyboard inputs
+            if (keyboard_needs_numeric) {
+                if (a >= '0' && a <= '9') {
+                    // update observation interval
+                    obs_int = (a - '0' + 1) * 5;
+                    keyboard_needs_numeric = 0;
+                } else {
+                    pc.printf("Expected numeric key\n");
+                }
+            } else if(a == 'N') {
+                // if the char is N, update bounds to normal mode
+                curr_mode = NORMAL;
+                upper_bound = 100;
+                lower_bound = 40;
+                pc.printf("MODE IS N\n");
+                // if the char is S, set bounds to sleep
+            } else if (a == 'S') {
+                curr_mode = SLEEP;
+                upper_bound = 60;
+                lower_bound = 30;
+                pc.printf("MODE IS S\n");
+                // if the char is E, set bounds to exercise
+            } else if (a == 'E') {
+                curr_mode = EXERCISE;
+                upper_bound = 175;
+                lower_bound = 100;
+                pc.printf("MODE IS E\n");
+                // if the char is M, set to manual
+            } else if (a == 'M') {
+                curr_mode = MANUAL;
+                upper_bound = 175;
+                lower_bound = 30;
+                pc.printf("MODE IS MANUAL\n");
+                // check for A if mode is manual
+            } else if (a == 'A') {
+                if(curr_mode == MANUAL) {
+                    pc.printf("MODE IS MANUAL GOT APACE\n");
+                }
+                // check for V is mode is manual
+            } else if (a == 'V') {
+                if(curr_mode == MANUAL) {
+                    pc.printf("MODE IS MANUAL GOT VPACE\n");
+                }
+            } else if (a == 'O') {
+                keyboard_needs_numeric = 1;
+            } else {
+                // do nothing for invalid char
+            }
         }
-    } else if(a == 'N') {
-        // if the char is N, update bounds to normal mode
-        curr_mode = NORMAL;
-        upper_bound = 100;
-        lower_bound = 40;
-        pc.printf("MODE IS N\n");
-        // if the char is S, set bounds to sleep
-    } else if (a == 'S') {
-        curr_mode = SLEEP;
-        upper_bound = 60;
-        lower_bound = 30;
-        pc.printf("MODE IS S\n");
-        // if the char is E, set bounds to exercise
-    } else if (a == 'E') {
-        curr_mode = EXERCISE;
-        upper_bound = 175;
-        lower_bound = 100;
-        pc.printf("MODE IS E\n");
-        beats = 2;
-        // if the char is M, set to manual
-    } else if (a == 'M') {
-        curr_mode = MANUAL;
-        upper_bound = 175;
-        lower_bound = 30;
-        beats = 300;
-        pc.printf("MODE IS MANUAL\n");
-        // check for A if mode is manual
-    } else if (a == 'A') {
-        if(curr_mode == MANUAL) {
-            pc.printf("MODE IS MANUAL GOT APACE\n");
-        }
-        // check for V is mode is manual
-    } else if (a == 'V') {
-        if(curr_mode == MANUAL) {
-            pc.printf("MODE IS MANUAL GOT VPACE\n");
-        }
-    } else if (a == 'O') {
-        keyboard_needs_numeric = 1;
-    } else {
-        // do nothing for invalid char
-    }
     }
 }