mbed heart
Dependencies: TextLCD mbed-rtos mbed
PMTest.cpp
- Committer:
- lucastai
- Date:
- 2015-12-02
- Revision:
- 4:6d3ddf74b49a
- Parent:
- 3:189e64d01258
- Child:
- 5:8d9bcf25accb
File content as of revision 4:6d3ddf74b49a:
#include "mbed.h" #include "LPC17xx.h" #include "TextLCD.h" #include "rtos.h" #include "Thread.h" DigitalOut vsense(p23); DigitalOut asense(p24); DigitalIn apace(p22); DigitalIn vpace(p21); DigitalOut led_apace(LED1); DigitalOut led_vpace(LED2); DigitalOut led_asense(LED3); DigitalOut led_vsense(LED4); Serial serial_in(USBTX, USBRX); int test_time_count; int curr_test; int minwaitV = 100000; int minwaitA = 200000; int needs_num_input = 0; enum mode {RANDOM,MANUAL,TEST}; mode test_curr_mode = RANDOM; Timer t; void random_heart(void const *args) { t.reset(); t.start(); while(1){ while(test_curr_mode == RANDOM) { int r = rand(); if(r%2 == 0) { serial_in.printf("timer was %i",t.read()); if(1) { led_asense = 1; asense = 1; serial_in.printf("asense "); Thread::wait(10); asense = 0; led_asense = 0; t.reset(); } } else { if(1) { led_vsense = 1; vsense = 1; serial_in.printf("vsense "); Thread::wait(10); vsense = 0; led_vsense = 0; t.reset(); } } Thread::wait(500); } } } void kbd_intrp() { char a = serial_in.getc(); serial_in.printf("char was " + a); if(needs_num_input) { // DO O handling needs_num_input = 0; return; } if(a == 'R') { test_curr_mode = RANDOM; } else if(a == 'T') { test_curr_mode = TEST; } else if(a == 'M') { test_curr_mode = MANUAL; } if(a == 'A' && test_curr_mode == MANUAL) { asense = 1; Thread::wait(10); asense = 0; } if(a == 'V' && test_curr_mode == MANUAL) { vsense = 1; Thread::wait(10); vsense = 0; } } void rec_apace(){ led_apace = 1; serial_in.printf("vssense fired\n"); Thread::wait(10); led_apace = 0; } void rec_vpace(){ led_vpace = 1; serial_in.printf("vssense fired\n"); Thread::wait(10); led_vpace = 0; } void heart_response(void const *args){ while(1){ if(apace == 1){ rec_apace(); } if(vpace == 1){ rec_vpace(); } } } // interrupt function void interrupt_and_run_test() { // zero timer, set for 1ms interrupt // wait for atrial pulse // check if timer was within event // send vsense // send asense // check if timer was in event // wait for vpace // wait for atrial pulse // check if timer was within event } int main(void) { Thread t3(random_heart, (void *)""); Thread t2(heart_response, (void *)""); char a = 'Z'; while(1) { if(serial_in.readable()) { a = serial_in.getc(); serial_in.printf("char was " + a); if(needs_num_input) { // DO O handling needs_num_input = 0; } if(a == 'R') { test_curr_mode = RANDOM; } else if(a == 'T') { test_curr_mode = TEST; } else if(a == 'M') { test_curr_mode = MANUAL; } if(a == 'A' && test_curr_mode == MANUAL) { asense = 1; Thread::wait(10); asense = 0; } if(a == 'V' && test_curr_mode == MANUAL) { vsense = 1; Thread::wait(10); vsense = 0; } } } }