CIS441 Controller

Dependencies:   TextLCD mbed-rtos mbed

Fork of PacemakerController by Chad Nachiappan

Revision:
31:7f0e865e3d4b
Parent:
30:97db5a684eaa
Child:
32:c58b6651336c
--- a/PacemakerController.cpp	Wed Dec 02 01:26:27 2015 +0000
+++ b/PacemakerController.cpp	Wed Dec 02 01:50:22 2015 +0000
@@ -116,7 +116,7 @@
             lcd.locate(0,1);
             lcd.printf("!<\n");
         }
-    
+
         // max hr alarm
         if(beats > MAX_PM_RT) {
             lcd.cls();
@@ -128,7 +128,7 @@
 }
 
 // hw interrupt callback, deal with the keyboard input from PC
-void keyboard_handler()
+/*void keyboard_handler()
 {
 
     // get the char, put it on the PC command line
@@ -139,6 +139,7 @@
             // update observation interval
             obs_int = (a - '0' + 1) * 5;
         } else {
+            lcd.printf("MODE IS N\n");
             pc.printf("Expected numeric key\n");
         }
     } else if(a == 'N') {
@@ -146,18 +147,21 @@
         curr_mode = NORMAL;
         upper_bound = 100;
         lower_bound = 40;
+        lcd.printf("MODE IS N\n");
         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;
+        lcd.printf("MODE IS S\n");
         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;
+        lcd.printf("MODE IS E\n");
         pc.printf("MODE IS E\n");
         beats = 2;
         // if the char is M, set to manual
@@ -166,6 +170,7 @@
         upper_bound = 175;
         lower_bound = 30;
         beats = 300;
+        lcd.printf("MODE IS MANUAL\n");
         pc.printf("MODE IS MANUAL\n");
         // check for A if mode is manual
     } else if (a == 'A') {
@@ -183,7 +188,7 @@
         // do nothing for invalid char
     }
 
-}
+}*/
 
 void pm_sense(void const *args)
 {
@@ -251,12 +256,12 @@
                 vpace();
             }
         } else if (timer_count < LRI - AVI) {
-             //lcd.cls();
-             //lcd.printf("timer_count < LRI - AVI\n");
+            //lcd.cls();
+            //lcd.printf("timer_count < LRI - AVI\n");
             // if Asense, move on to atrial event
             if (a_sense == 1) {
                 goInitalState = 0;
-                
+
                 // avi_clk = 0
                 avi_clk.reset();
 
@@ -285,7 +290,7 @@
 {
     // https://developer.mbed.org/users/chadnach1/code/PacemakerController/
     // connect the serial device (PC keybd) to the interrupt
-    pc.attach(&keyboard_handler);
+    //pc.attach(&keyboard_handler);
     lcd.printf("in main\n");
 
     // Start LED's Off
@@ -297,6 +302,67 @@
 
     Thread t1(pm_sense, (void *)"");
     Thread t2(pm_response, (void *)"");
-    
-    PM_ALARM((void *)"");
-}
\ No newline at end of file
+    Thread t3(PM_ALARM, (void *)"");
+
+    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 {
+            lcd.printf("MODE IS N\n");
+            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;
+        lcd.printf("MODE IS N\n");
+        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;
+        lcd.printf("MODE IS S\n");
+        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;
+        lcd.printf("MODE IS E\n");
+        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;
+        lcd.printf("MODE IS MANUAL\n");
+        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
+    }
+    }
+}