CIS441 Controller
Dependencies: TextLCD mbed-rtos mbed
Fork of PacemakerController by
Diff: PacemakerController.cpp
- Revision:
- 41:d806d68f7969
- Parent:
- 35:b5e8650a7669
- Child:
- 42:2e4ed3a53c64
--- a/PacemakerController.cpp Wed Dec 02 04:54:53 2015 +0000 +++ b/PacemakerController.cpp Wed Dec 02 05:19:41 2015 +0000 @@ -10,6 +10,8 @@ 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; @@ -28,7 +30,7 @@ enum mode {NORMAL, SLEEP, EXERCISE, MANUAL}; // counters -int beats = 0; +volatile int beats = 0; // state variables int upper_bound = 100; @@ -66,6 +68,7 @@ Thread::wait(10); led_vsense = 0; v_sense = 0; + beats++; } void apace() @@ -85,7 +88,6 @@ Thread::wait(10); led_vpace = 0; vpaceSignal = 0; - } // hardware interrupt handler, adapted from code in piazza post by Dagaen @@ -238,6 +240,18 @@ } } +/* 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/ @@ -254,6 +268,10 @@ 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(); @@ -268,6 +286,8 @@ // 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"); }