CIS441 Controller
Dependencies: TextLCD mbed-rtos mbed
Fork of PacemakerController by
Diff: PacemakerController.cpp
- Revision:
- 27:2c5aefcf3000
- Parent:
- 24:81cd9ef5c4f6
- Child:
- 29:5cec671cb80d
--- a/PacemakerController.cpp Wed Dec 02 00:21:13 2015 +0000 +++ b/PacemakerController.cpp Wed Dec 02 00:37:37 2015 +0000 @@ -15,7 +15,7 @@ int h_clock; int pm_clock; -Timer avi_clock; +Timer avi_clk; int LRI = 1000; int AVI = 150; @@ -42,13 +42,47 @@ DigitalOut Asense(LED3); DigitalOut Vsense(LED4); -DigitalIn aget(p24); -DigitalIn vget(p23); -DigitalOut apace(p22); -DigitalOut vpace(p21); +DigitalIn agetSignal(p24); +DigitalIn vgetSignal(p23); +DigitalOut apaceSignal(p22); +DigitalOut vpaceSignal(p21); + +bool v_sense; +bool a_sense; + +void asense() +{ + a_sense = 1; + Thread::wait(10); + a_sense = 0; +} -bool vsense; -bool asense; +void vsense() +{ + v_sense = 1; + Thread::wait(10); + v_sense = 0; +} + +void apace() +{ + + apaceSignal = 1; + led_apace = 1; + Thread::wait(10); + apaceSignal = 0; + +} + +void vpace() +{ + + vpaceSignal = 1; + led_vpace = 1; + Thread::wait(10); + vpaceSignal = 0; + +} // hardware interrupt handler, adapted from code in piazza post by Dagaen extern "C" void TIMER0_IRQHandler (void) @@ -71,7 +105,7 @@ } -void PM_ALARM(void const *argument) +void PM_ALARM(void const *args) { // min hr alarm @@ -146,25 +180,25 @@ } -void pm_sense() +void pm_sense(void const *args) { while(1) { - if (timer_count >= VRP && vget == 1) { + if (timer_count >= VRP && vgetSignal == 1) { // Valid_V state timer_count = 0; vsense(); // do something with Vsense! - } else if (timer_count < VRP && vget == 1) { + } else if (timer_count < VRP && vgetSignal == 1) { // Invalid_V state } - if (timer_count < PVARP && aget == 1) { + if (timer_count < PVARP && agetSignal == 1) { // Invalid_A state - } else if (timer_count >= PVARP && aget == 1) { + } else if (timer_count >= PVARP && agetSignal == 1) { // Valid_A state asense(); // do something with Asense! @@ -173,12 +207,12 @@ } } -void pm_response() +void pm_response(void const *args) { while(1) { - bool goInitalState = true; + bool goInitalState = 1; if (timer_count >= LRI-AVI) { - goInitialState = false; + goInitalState = 0; // PM_A! sets the LED high led_apace = 1; @@ -188,12 +222,12 @@ apace(); // At Atrial Event State while (avi_clk.read() < AVI) { - if (vsense == 1) { - goInitialState = true; + if (v_sense == 1) { + goInitalState = 1; break; } } - if (!goInitialState) { + if (!goInitalState) { // Ventricular Event timer_count = 0; @@ -205,16 +239,16 @@ } } else if (timer_count < LRI - AVI) { // if Asense, move on to atrial event - if (asense == 1) { - goInitialState = false; + if (a_sense == 1) { + goInitalState = 0; + // avi_clk = 0 - avi_clk.reset(); // At Atrial Event State while (avi_clk.read() < AVI) { - if (vsense == 1) { - goInitialState = true; + if (v_sense == 1) { + goInitalState = 1; break; } } @@ -232,41 +266,6 @@ } } -void asense() -{ - asense = 1; - Thread::wait(10); - asense = 0; -} - -void vpace() -{ - vsense = 1; - Thread::wait(10); - vsense = 0; -} - -void apace() -{ - - apace = 1; - led_apace = 1; - Thread::wait(10); - apace = 0; - -} - -void vpace() -{ - - vpace = 1; - led_vpace = 1; - Thread::wait(10); - vpace = 0; - -} - - int main() { // https://developer.mbed.org/users/chadnach1/code/PacemakerController/ @@ -280,10 +279,7 @@ // Start the avi_clock avi_clk.start(); + Thread t2(PM_ALARM); Thread t3(pm_sense); Thread t4(pm_response); - - Thread t2(PM_ALARM); - Thread t5(); - } \ No newline at end of file