![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Part of the Pacemaker Project; this models the Pacemaker.
Dependencies: mbed TextLCD mbed-rtos
Diff: PacemakerController.cpp
- Revision:
- 43:f28bc869321e
- Parent:
- 42:2e4ed3a53c64
- Child:
- 44:dfa38e4b3146
--- a/PacemakerController.cpp Wed Dec 02 05:31:09 2015 +0000 +++ b/PacemakerController.cpp Wed Dec 02 06:41:57 2015 +0000 @@ -10,8 +10,6 @@ Serial pc(USBTX, USBRX); TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7 -Ticker rate_monitor; - int keyboard_needs_numeric = 0; // boolean - is in middle of interval input? int h_clock; @@ -19,8 +17,8 @@ Timer avi_clk; Timer t_count; -int LRI = 100; -int AVI = 30; +int LRI = 1000; +int AVI = 300; int PVARP = 150; int VRP = 100; @@ -30,7 +28,7 @@ enum mode {NORMAL, SLEEP, EXERCISE, MANUAL}; // counters -volatile int beats = 0; +int beats = 0; // state variables int upper_bound = 100; @@ -68,7 +66,6 @@ Thread::wait(10); led_vsense = 0; v_sense = 0; - beats++; } void apace() @@ -88,6 +85,7 @@ Thread::wait(10); led_vpace = 0; vpaceSignal = 0; + } // hardware interrupt handler, adapted from code in piazza post by Dagaen @@ -160,15 +158,12 @@ vsense(); } else if (t_count.read_ms() < VRP && vgetSignal == 1) { - //pc.printf("invalid v state\n"); - // Invalid_V state } if (t_count.read_ms() < PVARP && agetSignal == 1) { // Invalid_A state - //pc.printf("invalid a state\n"); } else if (t_count.read_ms() >= PVARP && agetSignal == 1) { // Valid_A state asense(); @@ -208,6 +203,7 @@ led_vpace = 1; t_count.reset(); + pc.printf("in pmresponse 2"); vpace(); } } else if (t_count.read_ms() < LRI - AVI) { @@ -239,18 +235,6 @@ } } -/* Every observation interval, calculate beats per minute and display - * - */ -void update_display() { - double rate = beats / (double) obs_int / 60; - //reset count - beats = 0; - lcd.cls(); - lcd.locate(0,0); - lcd.printf("BPM: %.1f "); -} - int main() { // https://developer.mbed.org/users/chadnach1/code/PacemakerController/ @@ -267,10 +251,6 @@ Thread t1(pm_sense, (void *)""); Thread t2(pm_response, (void *)""); Thread t3(PM_ALARM, (void *)""); - - //update_display - rate_monitor.attach(&update_display, obs_int); - t_count.start(); t_count.reset(); @@ -285,8 +265,6 @@ // update observation interval obs_int = (a - '0' + 1) * 5; keyboard_needs_numeric = 0; - rate_monitor.attach(&update_display, obs_int); - pc.printf("Set observation interval to %d seconds\n", obs_int); } else { pc.printf("Expected numeric key\n"); } @@ -294,41 +272,41 @@ // if the char is N, update bounds to normal mode curr_mode = NORMAL; upper_bound = 100; - LRI = 100; + LRI = 1000; lower_bound = 40; 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; - LRI = 60; + LRI = 600; lower_bound = 30; 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; - LRI = 175; + LRI = 1750; lower_bound = 100; pc.printf("MODE IS E\n"); // if the char is M, set to manual } else if (a == 'M') { curr_mode = MANUAL; upper_bound = 175; - LRI = 175; + LRI = 1750; lower_bound = 30; 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 SENT APACE\n"); apace(); - pc.printf("MODE IS MANUAL SENT APACE\n"); } // check for V is mode is manual } else if (a == 'V') { if(curr_mode == MANUAL) { + pc.printf("MODE IS MANUAL SENT VPACE\n"); vpace(); - pc.printf("MODE IS MANUAL SENT VPACE\n"); } } else if (a == 'O') { keyboard_needs_numeric = 1;