CIS441 Controller

Dependencies:   TextLCD mbed-rtos mbed

Fork of PacemakerController by Chad Nachiappan

Revision:
33:b68c1648206e
Parent:
32:c58b6651336c
Child:
34:b4b50ca26e8c
Child:
36:03704a3ec2e3
--- a/PacemakerController.cpp	Wed Dec 02 02:23:26 2015 +0000
+++ b/PacemakerController.cpp	Wed Dec 02 03:40:48 2015 +0000
@@ -39,8 +39,8 @@
 // alarms
 DigitalOut led_apace(LED1);
 DigitalOut led_vpace(LED2);
-DigitalOut Asense(LED3);
-DigitalOut Vsense(LED4);
+DigitalOut led_asense(LED3);
+DigitalOut led_vsense(LED4);
 
 DigitalIn  agetSignal(p24);
 DigitalIn  vgetSignal(p23);
@@ -53,16 +53,20 @@
 void asense()
 {
     a_sense = 1;
+    led_asense = 1;
     lcd.printf("asense fired\n");
     Thread::wait(10);
+    led_asense = 0;
     a_sense = 0;
 }
 
 void vsense()
 {
     v_sense = 1;
+    led_vsense = 1;
     lcd.printf("vssense fired\n");
     Thread::wait(10);
+    led_vsense = 0;
     v_sense = 0;
 }
 
@@ -73,6 +77,7 @@
     apaceSignal = 1;
     led_apace = 1;
     Thread::wait(10);
+    led_apace = 0;
     apaceSignal = 0;
 
 }
@@ -83,20 +88,21 @@
     vpaceSignal = 1;
     led_vpace = 1;
     Thread::wait(10);
+    led_vpace = 0;
     vpaceSignal = 0;
 
 }
 
 // hardware interrupt handler, adapted from code in piazza post by Dagaen
-extern "C" void TIMER0_IRQHandler (void)
+/*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
     }
 }
-
-// init the hardware interrupt (timer0), adapted same as above
+*/
+/*// init the hardware interrupt (timer0), adapted same as above
 void timer0_init(void)
 {
     LPC_SC->PCONP |=1<1;            //timer0 power on
@@ -105,7 +111,7 @@
     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 PM_ALARM(void const *args)
@@ -137,44 +143,58 @@
         //lcd.locate(0,1);
         //lcd.printf("in pmsense\n");
         
-        t_count.stop();
+        /*if (agetSignal == 0) {
+            pc.printf("Aget:LO\n"); 
+        }
+        
+        if (vgetSignal == 0) {
+            pc.printf("Vget:LO\n"); 
+        }
+        if (agetSignal == 1) {
+            pc.printf("Aget:HI\n"); 
+        }
+        
+        if (vgetSignal == 1) {
+            pc.printf("Vget:HI\n"); 
+        }*/
+        
 
-        if (t_count.read() >= VRP && vgetSignal == 1) {
+        if (t_count.read_ms() >= VRP && vgetSignal == 1) {
             lcd.printf("valid v state\n");
             pc.printf("valid v state\n");
             //Thread::wait(2);
             // Valid_V state
 
             t_count.reset();
-            t_count.start();
+            //t_count.start();
             vsense();
             // do something with Vsense!
 
-        } else if (t_count.read() < VRP  && vgetSignal == 1) {
+        } else if (t_count.read_ms() < VRP  && vgetSignal == 1) {
             lcd.printf("invalid v state\n");
             pc.printf("invalid v state\n");
-                        pc.printf("%d\n",t_count.read());
+                        //pc.printf("%d\n",t_count.read());
                         
-            t_count.start();
+            //t_count.start();
 
             //Thread::wait(2);
             // Invalid_V state
         }
 
-        if (t_count.read() < PVARP && agetSignal == 1) {
+        if (t_count.read_ms() < PVARP && agetSignal == 1) {
             // Invalid_A state
             lcd.printf("invalid a state\n");
             pc.printf("invalid a state\n");
-                                    pc.printf("%d\n",t_count.read());
-            t_count.start();
+                                   // pc.printf("%d\n",t_count.read());
+            //t_count.start();
 
             //Thread::wait(2);
-        } else if (t_count.read() >= PVARP && agetSignal == 1) {
+        } else if (t_count.read_ms() >= PVARP && agetSignal == 1) {
             // Valid_A state
             lcd.printf("valid a state\n");
             pc.printf("valid a state\n");
             //Thread::wait(2);
-            t_count.start();
+            //t_count.start();
             asense();
             // do something with Asense!
         }
@@ -186,13 +206,16 @@
 {
     while(1) {
         //lcd.cls();
-        //lcd.printf("in response\n");
+        lcd.printf("in response\n");
+        pc.printf("in response %d\n", t_count.read());
         bool goInitalState = 1;
-        if (t_count.read() >= LRI-AVI) {
+        if (t_count.read_ms() >= LRI - AVI) {
+            
             //lcd.cls();
             //lcd.printf("t_count.reasd() >= LRI-AVI\n");
             goInitalState = 0;
             // PM_A! sets the LED high
+            pc.printf("in pmresponse");
             led_apace = 1;
 
             // avi_clk = 0
@@ -200,7 +223,7 @@
 
             apace();
             // At Atrial Event State
-            while (avi_clk.read() < AVI) {
+            while (avi_clk.read_ms() < AVI) {
                 //lcd.cls();
                 //lcd.printf("avi_clk.read() < AVI\n");
                 if (v_sense == 1) {
@@ -216,9 +239,10 @@
                 led_vpace = 1;
 
                 t_count.reset();
+                pc.printf("in pmresponse 2");
                 vpace();
             }
-        } else if (t_count.read() < LRI - AVI) {
+        } else if (t_count.read_ms() < LRI - AVI) {
             //lcd.cls();
             //lcd.printf("t_count.read() < LRI - AVI\n");
             // if Asense, move on to atrial event
@@ -262,14 +286,21 @@
 
     // Start the avi_clock
     avi_clk.start();
-    t_count.start();
+    avi_clk.reset();
 
     Thread t1(pm_sense, (void *)"");
     Thread t2(pm_response, (void *)"");
     Thread t3(PM_ALARM, (void *)"");
+    t_count.start();
+    t_count.reset();
+    //pc.printf("PM CLOCK time isss %d\n",t_count.read_ms());
+      //                                  pc.printf("AVI CLK %d\n",avi_clk.read_ms());
 
     char a = 'Z';
     while(1) {
+                    
+
+
     if (pc.readable()) {
 
         a = pc.getc();