CIS441 Controller

Dependencies:   TextLCD mbed-rtos mbed

Fork of PacemakerController by Chad Nachiappan

Revision:
23:08456978fb78
Parent:
20:dc272bfaa276
Child:
25:18923916215b
--- a/PMTest.cpp	Mon Nov 30 21:38:54 2015 +0000
+++ b/PMTest.cpp	Mon Nov 30 21:47:20 2015 +0000
@@ -11,30 +11,67 @@
 
 int timer_count;
 int curr_test;
+int minwaitV;
+int minwaitA;
+
+int needs_num_input = 0;
+
+struct mode{RANDOM,MANUAL,TEST};
+mode curr_mode = RANDOM;
+Timer t;
 
 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 == RANDOM){
+        int r = rand();
+
+        if(r%2 == 0){
+            if(t.read() > minwaitA){
+                asense = 1;
+                Thread::wait(10);
+                asense = 0;
+            }
+        }else{
+            if(t.read() > minwaitV){
+                vsense = 1;
+                Thread::wait(10);
+                vsense = 0;
+            }
+        }
+
+
+        t.reset();
+
     }
 }
- 
-// 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 kbd_intrp(){
+    char a = pc.getc();
+
+    if(needs_num_input){
+        // DO O handling
+        needs_num_input = 0;
+        return;
+    }
+
+    if(a = 'R'){
+        curr_mode = RANDOM;
+    }
+
+
+
 }
 
+
+
 // interrupt function
 void interrupt_and_run_test(){
     // zero timer, set for 1ms interrupt