CIS541 / Mbed 2 deprecated CIS541PM

Dependencies:   mbed mbed-rtos TextLCD

Revision:
1:e3a5388e46ab
Parent:
0:2d6b43fc4625
Child:
2:b178e27d9f22
--- a/main.cpp	Mon Nov 23 00:30:38 2015 +0000
+++ b/main.cpp	Thu Nov 26 23:54:30 2015 +0000
@@ -1,12 +1,135 @@
 #include "mbed.h"
+#include "rtos.h"
+
+Serial pc(USBTX, USBRX);
+
+
+void PacemakerKeyboardInput(void const *args);
+void PacemakerModes(void const *args);
 
-DigitalOut myled(LED1);
+int modeSwitchTimeInterval = 5000;
+int flag=0;
+const int sleepModeURI = 1000;
+const int sleepModeLRI = 2000;
+const int normalModeURI = 600;
+const int normalModeLRI = 1500;
+const int sportsModeURI = 343;
+const int sportsModeLRI = 600;
+const int manualModeURI = 343;
+const int manualModeLRI = 2000;
+
+int LRI = normalModeLRI;
+int URI = normalModeURI;
+Timer k;
+char mode;
+char manualPace;
+Thread Pmki(PacemakerKeyboardInput,(void *) 0); 
+Thread Pmm(PacemakerModes,(void *) 0); 
 
-int main() {
-    while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+void PacemakerKeyboardInput(void const *args){
+    k.start();
+    char input;
+    while(true){
+        input=pc.getc();
+        if (k.read()>=modeSwitchTimeInterval && flag==0){
+            if (input=='F'){
+                mode='F';
+                Pmm.signal_set(0x1);
+                Thread::signal_wait(0x1);
+                }
+            else if (input=='S'){
+                mode='S';
+                Pmm.signal_set(0x1);
+                Thread::signal_wait(0x1);
+                }
+            else if (input=='N'){
+                mode='N';
+                Pmm.signal_set(0x1);
+                Thread::signal_wait(0x1);
+                }
+            else if (input=='O'){
+                mode='O';
+                Pmm.signal_set(0x1);
+                Thread::signal_wait(0x1);
+                }
+            else if (input=='M'){
+                mode='M';
+                Pmm.signal_set(0x1);
+                Thread::signal_wait(0x1);
+                }
+            else if (input=='A'){
+                if (mode=='M')
+                    manualPace='A';
+                    Pmm.signal_set(0x1);
+                    Thread::signal_wait(0x1);
+                    }
+                }
+            else if (input=='V'){
+                if (mode=='M'){
+                    manualControl.lock();
+                    manualPace='V';
+                    Pmm.signal_set(0x1);
+                    Thread::signal_wait(0x1);
+                    }
+                }
+            }
+        }
     }
+    
+    
+void PacemakerModes(void const *args){
+    while(1){
+        Thread::signal_wait(0x1);
+        if (mode=='F'){
+            LRI=sportsModeLRI;
+            URI=sportsModeURI;
+            pmki.signal_set(0x1);
+            }
+        else if (mode=='S'){
+            LRI=sleepModeLRI;
+            URI=sleepModeURI;
+            pmki.signal_set(0x1);
+            }
+        else if (mode=='N'){
+            LRI=normalModeLRI;
+            URI=normalModeURI;
+            pmki.signal_set(0x1);
+            }
+        else if (mode=='O'){
+            //not sure what to do here
+            pmki.signal_set(0x1);
+            }
+        else if (mode=='M'){
+            LRI=manualModeLRI;
+            URI=manualModeURI;
+            pmki.signal_set(0x1);
+            while(1){
+                Thread::signal_wait(0x1);
+                if (mode=='M'){
+                    if (manualPace=='A'){
+                        // do stuff
+                        manualPace='';
+                        }
+                    else if (manualPace=='V'){
+                        //do stuff
+                        manualPace='';
+                        }
+                    }
+                else {
+                    pmm.signal_set(0x1);
+                    pmki.signal_wait(0x1);
+                    break;
+                    }
+                pmki.signal_wait(0x1);
+                }
+            }
+            
+        
+        
+        }
+    } 
+
+int main(){
+    
+    while(1);
 }