heart modes, send, receive
Dependencies: Terminal TextLCD mbed-rtos mbed
Fork of Heartnew by
Diff: heart.cpp
- Revision:
- 2:fc2f41386ee4
- Parent:
- 1:c340c31174a5
- Child:
- 3:b702a21b2990
diff -r c340c31174a5 -r fc2f41386ee4 heart.cpp --- a/heart.cpp Sun Nov 29 01:17:40 2015 +0000 +++ b/heart.cpp Mon Nov 30 21:00:10 2015 +0000 @@ -11,8 +11,11 @@ DigitalOut ASignal(p25); DigitalOut VSignal(p26); -DigitalOut ASignal1(LED2); -DigitalOut VSignal1(LED3); +DigitalOut APaceReceive(LED1); +DigitalOut VPaceReceive(LED2); + +DigitalOut ASignal1(LED3); +DigitalOut VSignal1(LED4); const int minwait_A=50; const int minwait_V=50; @@ -22,14 +25,17 @@ int m=0; int s=0; int ms=0; - +int heartInterval; char key_input; int LRI=1500; int URI=600; - +int heartRate; volatile bool Areceived=false; volatile bool Vreceived=false; +int low[4] = {30,40,100,30}; +int high[4] = {60,100,175,175}; +int modeset; const int sleepModeURI = 1000; const int sleepModeLRI = 2000; @@ -50,17 +56,21 @@ Random, Sports, Manual, - AtrialMode, - VentricularMode + Observer }; Modes mode; Mutex HeartMutex; +Thread *heartreceive; +Thread *heartsend; +Thread *heartkeyboard; + + void resetTimer0(); void resetTimer1(); -void VCheck(); -void ACheck(); +void VPacereceived(); +void APacereceived(); void ASignalsend(); void VSignalsend(); void HeartReceive(); @@ -113,6 +123,7 @@ m=0; s=0; ms=0; + time_count=0; LPC_TIM0->TCR = 0; lcd.locate(0,0); lcd.printf("%02d:%02d:%02d", m,s,ms); @@ -125,17 +136,22 @@ ms=0; LPC_TIM1->TCR = 0; lcd.locate(0,0); - time_count=0; + time1_count=0; + } -void VCheck() -{ +void VPacereceived() +{ pc.printf("VPace aaya"); Vreceived=true; + VPaceReceive=1; + APaceReceive=0; } -void ACheck() -{ +void APacereceived() +{ pc.printf("APace aaya"); Areceived=true; + VPaceReceive=0; + APaceReceive=1; } void ASignalsend() @@ -151,6 +167,12 @@ VSignal1=1; ASignal1=0; } + +void updateHeart() +{ + int temp = 60/heartInterval; + heartRate = heartRate + temp; +} void HeartReceive(void const* args) { while(1) { @@ -158,10 +180,9 @@ while(Areceived==false||Vreceived==false); if(Vreceived==true) { resetTimer0(); - pc.printf("VPace aaya"); + } else if(Areceived==true) { resetTimer0(); - pc.printf("APace aaya"); } } } @@ -173,7 +194,7 @@ pc.printf("HS"); while(time_count<minwait_V && mode!=Random && (mode==Test || mode==Manual)); pc.printf("%u",time_count); - if(r==0) { //(time_count<minwait_V && mode!=Random && mode==Test && mode==Manual && r==0) { + if(r==0) { VSignalsend(); pc.printf("Vsignal"); resetTimer0(); @@ -201,29 +222,34 @@ } else if(key_input=='m'||key_input=='M') { mode=Manual; pc.printf("Manual"); - key_input = pc.getc(); } else if(mode==Manual&&(key_input=='v'||key_input=='V')) { mode=Manual; pc.printf("Ventricular"); } else if(mode==Manual&&(key_input=='a'||key_input=='A')) { mode=Manual; pc.printf("Atrial"); - - + } else if(key_input=='o'||key_input=='O') { + int a = 10 + rand() % 80; + mode=Observer; + pc.printf("Observer and %u",a); + heartInterval =a; + HeartSend("s"); } } } } -int main() + + + int main() { pc.baud(9600); - VPace.rise(&VCheck); - APace.rise(&ACheck); + VPace.rise(&VPacereceived); + APace.rise(&APacereceived); timer0_init(); timer1_init(); - Thread heartreceive(HeartReceive); - Thread heartsend(HeartSend); - Thread heartkeyboard(HeartKeyBoardModeSwitch); + heartreceive=new Thread(HeartReceive); + heartsend=new Thread(HeartSend); + heartkeyboard=new Thread(HeartKeyBoardModeSwitch); while(1) { }