CIS441 Controller
Dependencies: TextLCD mbed-rtos mbed
Fork of PacemakerController by
Diff: PacemakerController.cpp
- Revision:
- 32:c58b6651336c
- Parent:
- 31:7f0e865e3d4b
- Child:
- 33:b68c1648206e
diff -r 7f0e865e3d4b -r c58b6651336c PacemakerController.cpp --- a/PacemakerController.cpp Wed Dec 02 01:50:22 2015 +0000 +++ b/PacemakerController.cpp Wed Dec 02 02:23:26 2015 +0000 @@ -15,6 +15,7 @@ int h_clock; int pm_clock; Timer avi_clk; +Timer t_count; int LRI = 1000; int AVI = 150; @@ -128,67 +129,6 @@ } // hw interrupt callback, deal with the keyboard input from PC -/*void keyboard_handler() -{ - - // get the char, put it on the PC command line - char a = pc.getc(); - - if (keyboard_needs_numeric) { - 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 - } - -}*/ void pm_sense(void const *args) { @@ -196,22 +136,45 @@ while(1) { //lcd.locate(0,1); //lcd.printf("in pmsense\n"); + + t_count.stop(); - if (timer_count >= VRP && vgetSignal == 1) { + if (t_count.read() >= VRP && vgetSignal == 1) { + lcd.printf("valid v state\n"); + pc.printf("valid v state\n"); + //Thread::wait(2); // Valid_V state - timer_count = 0; + t_count.reset(); + t_count.start(); vsense(); // do something with Vsense! - } else if (timer_count < VRP && vgetSignal == 1) { + } else if (t_count.read() < VRP && vgetSignal == 1) { + lcd.printf("invalid v state\n"); + pc.printf("invalid v state\n"); + pc.printf("%d\n",t_count.read()); + + t_count.start(); + + //Thread::wait(2); // Invalid_V state } - if (timer_count < PVARP && agetSignal == 1) { + if (t_count.read() < PVARP && agetSignal == 1) { // Invalid_A state - } else if (timer_count >= PVARP && agetSignal == 1) { + lcd.printf("invalid a state\n"); + pc.printf("invalid a state\n"); + pc.printf("%d\n",t_count.read()); + t_count.start(); + + //Thread::wait(2); + } else if (t_count.read() >= PVARP && agetSignal == 1) { // Valid_A state + lcd.printf("valid a state\n"); + pc.printf("valid a state\n"); + //Thread::wait(2); + t_count.start(); asense(); // do something with Asense! } @@ -225,9 +188,9 @@ //lcd.cls(); //lcd.printf("in response\n"); bool goInitalState = 1; - if (timer_count >= LRI-AVI) { + if (t_count.read() >= LRI-AVI) { //lcd.cls(); - //lcd.printf("timer_count >= LRI-AVI\n"); + //lcd.printf("t_count.reasd() >= LRI-AVI\n"); goInitalState = 0; // PM_A! sets the LED high led_apace = 1; @@ -247,17 +210,17 @@ } if (!goInitalState) { // Ventricular Event - timer_count = 0; + t_count.reset(); // PM_V! sets the LED high led_vpace = 1; - timer_count = 0; + t_count.reset(); vpace(); } - } else if (timer_count < LRI - AVI) { + } else if (t_count.read() < LRI - AVI) { //lcd.cls(); - //lcd.printf("timer_count < LRI - AVI\n"); + //lcd.printf("t_count.read() < LRI - AVI\n"); // if Asense, move on to atrial event if (a_sense == 1) { goInitalState = 0; @@ -274,12 +237,12 @@ } // Ventricular Event - timer_count = 0; + t_count.reset(); // PM_V! sets the LED high led_vpace = 1; - timer_count = 0; + t_count.reset(); vpace(); } } @@ -299,6 +262,7 @@ // Start the avi_clock avi_clk.start(); + t_count.start(); Thread t1(pm_sense, (void *)""); Thread t2(pm_response, (void *)"");