Part of the Pacemaker Project; this models the Pacemaker.

Dependencies:   mbed TextLCD mbed-rtos

Revision:
22:365d51eb3783
Parent:
8:5924b2048a27
--- a/PMTest.cpp	Mon Nov 30 21:08:26 2015 +0000
+++ b/PMTest.cpp	Mon Nov 30 21:36:01 2015 +0000
@@ -11,28 +11,75 @@
 
 int timer_count;
 int curr_test;
+int obs_int;
+
+Timer t;
+
+struct mode{RANDOM,MANUAL,TEST};
+
+// state variables
+mode current_mode = RANDOM;
 
 int[][] testfunc;
 
-// hardware interrupt handler, adapted from code in piazza post by Dagaen
-extern "C" void TIMER0_IRQHandler (void)
-{
-if((LPC_TIM0->IR & 0x01) == 0x01)   // if MR0 interrupt, proceed
-    {
-    LPC_TIM0->IR |= 1 << 0;         // Clear MR0 interrupt flag
-    timer_count++;                  //increment timer_count
+void random_heart(){
+    t.reset();
+    t.start();
+    
+    while(curr_mode == NORMAL){
+        if(rand()% 2 == 1){
+            if(t.read() < minwaitA){
+                asense = 1;
+                Thread::wait(10);
+                asense = 0;
+            }
+        }else{
+            if(t.read() < minwaitV){
+                vsense = 1;
+                Thread::wait(10);
+                vsense = 0;
+            }
+            
+        } 
     }
 }
- 
-// init the hardware interrupt (timer0), adapted same as above
-void timer0_init(int n)
-{
-    LPC_SC->PCONP |=1<1;            //timer0 power on
-    LPC_SC-> PCLKSEL0 |= 1 << 2;    // set timer clock to CCLCK nondivided (1 clock cycle = 1 increment)
-    LPC_TIM0->MR0 = n;          //100mhz clock cycle, 1 cycle = 10ns, 10ms = 10 000 000 ns = 1M cycles
-    LPC_TIM0->MCR = 3;              //interrupt and reset control
-                                    //3 = Interrupt & reset timer0 on match (111) sets all three bits
-    NVIC_EnableIRQ(TIMER0_IRQn);    //enable timer0 interrupt
+
+
+void man_interrupt(){
+    char a = pc.getc();
+    
+    if (keyboard_needs_numeric) {
+        if (a >= '0' && a <= '9') {
+            // update observation interval
+            obs_int = (a - '0' + 1) * 5;
+        } else {
+            pc.printf("Expected numeric key\n");    
+        }
+        keyboard_needs_numeric = 0;
+    }else if(a == 'N'){
+        curr_mode = NORMAL;
+    }else if (a == 'M'){
+        curr_mode = MANUAL;
+    }else if (a == 'T'){
+        curr_mode = TEST;
+    }else if (a == 'O'){
+        keyboard_needs_number = 1;
+    }
+    
+    if(curr_mode == MANUAL){
+           if(a == 'A'){
+               asense = 1;
+               Thread::wait(10);
+               asense = 0;
+            }else if(a == "V"){
+               vsense = 1;
+               Thread::wait(10);
+               vsense = 0;
+            }    
+    }
+    
+    keyboard_needs_number = 0;   
+    
 }
 
 // interrupt function