heart modes, send, receive
Dependencies: Terminal TextLCD mbed-rtos mbed
Fork of Heartnew by
heart.cpp@5:8e3b9032ddfc, 2015-12-02 (annotated)
- Committer:
- sanjeet25
- Date:
- Wed Dec 02 02:09:34 2015 +0000
- Revision:
- 5:8e3b9032ddfc
- Parent:
- 4:a64a0fea5266
- Child:
- 6:cc4fcc38b9f0
heartnewer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sanjeet25 | 0:a307f0abfd4d | 1 | #include "mbed.h" |
sanjeet25 | 0:a307f0abfd4d | 2 | #include "TextLCD.h" |
sanjeet25 | 0:a307f0abfd4d | 3 | #include "rtos.h" |
sanjeet25 | 0:a307f0abfd4d | 4 | |
sanjeet25 | 0:a307f0abfd4d | 5 | TextLCD lcd(p15, p16, p17, p18, p19, p20); |
sanjeet25 | 0:a307f0abfd4d | 6 | Serial pc(USBTX, USBRX); |
sanjeet25 | 0:a307f0abfd4d | 7 | |
sanjeet25 | 1:c340c31174a5 | 8 | InterruptIn APace(p23); |
sanjeet25 | 1:c340c31174a5 | 9 | InterruptIn VPace(p24); |
sanjeet25 | 0:a307f0abfd4d | 10 | |
sanjeet25 | 1:c340c31174a5 | 11 | DigitalOut ASignal(p25); |
sanjeet25 | 1:c340c31174a5 | 12 | DigitalOut VSignal(p26); |
sanjeet25 | 1:c340c31174a5 | 13 | |
sanjeet25 | 2:fc2f41386ee4 | 14 | DigitalOut APaceReceive(LED1); |
sanjeet25 | 2:fc2f41386ee4 | 15 | DigitalOut VPaceReceive(LED2); |
sanjeet25 | 2:fc2f41386ee4 | 16 | |
sanjeet25 | 2:fc2f41386ee4 | 17 | DigitalOut ASignal1(LED3); |
sanjeet25 | 2:fc2f41386ee4 | 18 | DigitalOut VSignal1(LED4); |
sanjeet25 | 0:a307f0abfd4d | 19 | |
sanjeet25 | 0:a307f0abfd4d | 20 | const int minwait_A=50; |
sanjeet25 | 0:a307f0abfd4d | 21 | const int minwait_V=50; |
sanjeet25 | 0:a307f0abfd4d | 22 | |
sanjeet25 | 3:b702a21b2990 | 23 | volatile int t=0; |
sanjeet25 | 3:b702a21b2990 | 24 | volatile int k=0; |
sanjeet25 | 0:a307f0abfd4d | 25 | int m=0; |
sanjeet25 | 0:a307f0abfd4d | 26 | int s=0; |
sanjeet25 | 0:a307f0abfd4d | 27 | int ms=0; |
sanjeet25 | 2:fc2f41386ee4 | 28 | int heartInterval; |
sanjeet25 | 0:a307f0abfd4d | 29 | char key_input; |
sanjeet25 | 3:b702a21b2990 | 30 | int testNumber; |
sanjeet25 | 4:a64a0fea5266 | 31 | bool test_result; |
sanjeet25 | 4:a64a0fea5266 | 32 | const int prop_delay=15; |
sanjeet25 | 4:a64a0fea5266 | 33 | int flag_key=0; |
sanjeet25 | 0:a307f0abfd4d | 34 | |
sanjeet25 | 0:a307f0abfd4d | 35 | int LRI=1500; |
sanjeet25 | 0:a307f0abfd4d | 36 | int URI=600; |
sanjeet25 | 2:fc2f41386ee4 | 37 | int heartRate; |
sanjeet25 | 0:a307f0abfd4d | 38 | volatile bool Areceived=false; |
sanjeet25 | 0:a307f0abfd4d | 39 | volatile bool Vreceived=false; |
sanjeet25 | 3:b702a21b2990 | 40 | bool test=false; |
sanjeet25 | 2:fc2f41386ee4 | 41 | int low[4] = {30,40,100,30}; |
sanjeet25 | 2:fc2f41386ee4 | 42 | int high[4] = {60,100,175,175}; |
sanjeet25 | 2:fc2f41386ee4 | 43 | int modeset; |
sanjeet25 | 3:b702a21b2990 | 44 | int pulses; |
sanjeet25 | 4:a64a0fea5266 | 45 | //int test; |
sanjeet25 | 4:a64a0fea5266 | 46 | int flag; |
sanjeet25 | 4:a64a0fea5266 | 47 | int delta=15; |
sanjeet25 | 4:a64a0fea5266 | 48 | int observationInterval=10000; |
sanjeet25 | 4:a64a0fea5266 | 49 | const int vrp=100; |
sanjeet25 | 4:a64a0fea5266 | 50 | const int pvarp=150; |
sanjeet25 | 4:a64a0fea5266 | 51 | const int avi=65; |
sanjeet25 | 4:a64a0fea5266 | 52 | const int pvab=10; |
sanjeet25 | 0:a307f0abfd4d | 53 | |
sanjeet25 | 0:a307f0abfd4d | 54 | const int sleepModeURI = 1000; |
sanjeet25 | 0:a307f0abfd4d | 55 | const int sleepModeLRI = 2000; |
sanjeet25 | 0:a307f0abfd4d | 56 | |
sanjeet25 | 0:a307f0abfd4d | 57 | const int normalModeURI = 600; |
sanjeet25 | 0:a307f0abfd4d | 58 | const int normalModeLRI = 1500; |
sanjeet25 | 0:a307f0abfd4d | 59 | |
sanjeet25 | 0:a307f0abfd4d | 60 | const int sportsModeURI = 343; |
sanjeet25 | 0:a307f0abfd4d | 61 | const int sportsModeLRI = 600; |
sanjeet25 | 0:a307f0abfd4d | 62 | |
sanjeet25 | 0:a307f0abfd4d | 63 | const int manualModeURI = 343; |
sanjeet25 | 0:a307f0abfd4d | 64 | const int manualModeLRI = 2000; |
sanjeet25 | 0:a307f0abfd4d | 65 | |
sanjeet25 | 4:a64a0fea5266 | 66 | int lri=normalModeLRI; |
sanjeet25 | 4:a64a0fea5266 | 67 | int uri=normalModeURI; |
sanjeet25 | 4:a64a0fea5266 | 68 | |
sanjeet25 | 0:a307f0abfd4d | 69 | typedef enum Modes { |
sanjeet25 | 0:a307f0abfd4d | 70 | Test, |
sanjeet25 | 0:a307f0abfd4d | 71 | Normal, |
sanjeet25 | 0:a307f0abfd4d | 72 | Sleep, |
sanjeet25 | 0:a307f0abfd4d | 73 | Random, |
sanjeet25 | 0:a307f0abfd4d | 74 | Sports, |
sanjeet25 | 0:a307f0abfd4d | 75 | Manual, |
sanjeet25 | 2:fc2f41386ee4 | 76 | Observer |
sanjeet25 | 0:a307f0abfd4d | 77 | }; |
sanjeet25 | 0:a307f0abfd4d | 78 | Modes mode; |
sanjeet25 | 0:a307f0abfd4d | 79 | |
sanjeet25 | 0:a307f0abfd4d | 80 | Mutex HeartMutex; |
sanjeet25 | 0:a307f0abfd4d | 81 | |
sanjeet25 | 2:fc2f41386ee4 | 82 | Thread *heartreceive; |
sanjeet25 | 2:fc2f41386ee4 | 83 | Thread *heartsend; |
sanjeet25 | 2:fc2f41386ee4 | 84 | Thread *heartkeyboard; |
sanjeet25 | 4:a64a0fea5266 | 85 | Thread *testmode; |
sanjeet25 | 4:a64a0fea5266 | 86 | Thread *hmode; |
sanjeet25 | 2:fc2f41386ee4 | 87 | |
sanjeet25 | 2:fc2f41386ee4 | 88 | |
sanjeet25 | 3:b702a21b2990 | 89 | void resett(); |
sanjeet25 | 3:b702a21b2990 | 90 | void resetk(); |
sanjeet25 | 2:fc2f41386ee4 | 91 | void VPacereceived(); |
sanjeet25 | 2:fc2f41386ee4 | 92 | void APacereceived(); |
sanjeet25 | 0:a307f0abfd4d | 93 | void ASignalsend(); |
sanjeet25 | 0:a307f0abfd4d | 94 | void VSignalsend(); |
sanjeet25 | 0:a307f0abfd4d | 95 | void HeartReceive(); |
sanjeet25 | 0:a307f0abfd4d | 96 | void HeartSend(); |
sanjeet25 | 1:c340c31174a5 | 97 | void HeartKeyBoardModeSwitch(); |
sanjeet25 | 3:b702a21b2990 | 98 | void sound_lowAlarm(); |
sanjeet25 | 3:b702a21b2990 | 99 | void sound_highAlarm(); |
sanjeet25 | 4:a64a0fea5266 | 100 | void Testmode(); |
sanjeet25 | 0:a307f0abfd4d | 101 | |
sanjeet25 | 0:a307f0abfd4d | 102 | |
sanjeet25 | 0:a307f0abfd4d | 103 | extern "C" void TIMER0_IRQHandler (void) |
sanjeet25 | 0:a307f0abfd4d | 104 | { |
sanjeet25 | 3:b702a21b2990 | 105 | if((LPC_TIM0->IR & 0x01) == 0x01) { // if MR0 interrupt, proceed |
sanjeet25 | 0:a307f0abfd4d | 106 | LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag |
sanjeet25 | 3:b702a21b2990 | 107 | t++; |
sanjeet25 | 3:b702a21b2990 | 108 | k++; |
sanjeet25 | 0:a307f0abfd4d | 109 | } |
sanjeet25 | 0:a307f0abfd4d | 110 | } |
sanjeet25 | 0:a307f0abfd4d | 111 | |
sanjeet25 | 3:b702a21b2990 | 112 | //Initializing the timer 0 |
sanjeet25 | 3:b702a21b2990 | 113 | void timer0_init(void) |
sanjeet25 | 0:a307f0abfd4d | 114 | { |
sanjeet25 | 0:a307f0abfd4d | 115 | |
sanjeet25 | 3:b702a21b2990 | 116 | LPC_SC->PCONP |=1<1; //Timer0 Power On |
sanjeet25 | 3:b702a21b2990 | 117 | LPC_TIM0->MR0 = 23990; //1 msec |
sanjeet25 | 3:b702a21b2990 | 118 | LPC_TIM0->MCR = 3; //interrupt and reset control |
sanjeet25 | 3:b702a21b2990 | 119 | NVIC_EnableIRQ(TIMER1_IRQn); //Enable timer0 interrupt |
sanjeet25 | 3:b702a21b2990 | 120 | LPC_TIM0->TCR = 1; //enable Timer0 |
sanjeet25 | 3:b702a21b2990 | 121 | t = 0; |
sanjeet25 | 3:b702a21b2990 | 122 | k = 0; |
sanjeet25 | 3:b702a21b2990 | 123 | } |
sanjeet25 | 3:b702a21b2990 | 124 | |
sanjeet25 | 3:b702a21b2990 | 125 | void resett() |
sanjeet25 | 3:b702a21b2990 | 126 | { |
sanjeet25 | 3:b702a21b2990 | 127 | t=0; |
sanjeet25 | 3:b702a21b2990 | 128 | } |
sanjeet25 | 3:b702a21b2990 | 129 | |
sanjeet25 | 3:b702a21b2990 | 130 | void resetk() |
sanjeet25 | 3:b702a21b2990 | 131 | { |
sanjeet25 | 3:b702a21b2990 | 132 | k=0; |
sanjeet25 | 0:a307f0abfd4d | 133 | } |
sanjeet25 | 0:a307f0abfd4d | 134 | |
sanjeet25 | 4:a64a0fea5266 | 135 | void sound_lowAlarm() |
sanjeet25 | 4:a64a0fea5266 | 136 | { |
sanjeet25 | 4:a64a0fea5266 | 137 | pc.printf("lowalarm"); |
sanjeet25 | 4:a64a0fea5266 | 138 | } |
sanjeet25 | 4:a64a0fea5266 | 139 | void sound_highAlarm() |
sanjeet25 | 4:a64a0fea5266 | 140 | { |
sanjeet25 | 4:a64a0fea5266 | 141 | pc.printf("highalarm"); |
sanjeet25 | 4:a64a0fea5266 | 142 | } |
sanjeet25 | 3:b702a21b2990 | 143 | void VPacereceived() |
sanjeet25 | 0:a307f0abfd4d | 144 | { |
sanjeet25 | 3:b702a21b2990 | 145 | pc.printf("VPace received"); |
sanjeet25 | 3:b702a21b2990 | 146 | VPaceReceive=1; |
sanjeet25 | 3:b702a21b2990 | 147 | wait(0.002); |
sanjeet25 | 3:b702a21b2990 | 148 | APaceReceive=0; |
sanjeet25 | 3:b702a21b2990 | 149 | pulses++; |
sanjeet25 | 0:a307f0abfd4d | 150 | Vreceived=true; |
sanjeet25 | 3:b702a21b2990 | 151 | Areceived=false; |
sanjeet25 | 4:a64a0fea5266 | 152 | if(mode == Test && flag==0) { |
sanjeet25 | 4:a64a0fea5266 | 153 | (*testmode).signal_set(0x04); |
sanjeet25 | 3:b702a21b2990 | 154 | } |
sanjeet25 | 3:b702a21b2990 | 155 | if(mode == Test && test) { |
sanjeet25 | 3:b702a21b2990 | 156 | if(testNumber == 2 || testNumber == 0 || testNumber == 3 || testNumber == 1) { |
sanjeet25 | 4:a64a0fea5266 | 157 | test_result = false; |
sanjeet25 | 3:b702a21b2990 | 158 | } else if(testNumber == 6 || testNumber == 4) { |
sanjeet25 | 4:a64a0fea5266 | 159 | test_result = true; |
sanjeet25 | 3:b702a21b2990 | 160 | } |
sanjeet25 | 3:b702a21b2990 | 161 | } |
sanjeet25 | 0:a307f0abfd4d | 162 | } |
sanjeet25 | 0:a307f0abfd4d | 163 | |
sanjeet25 | 2:fc2f41386ee4 | 164 | void APacereceived() |
sanjeet25 | 3:b702a21b2990 | 165 | { |
sanjeet25 | 3:b702a21b2990 | 166 | pc.printf("APace received"); |
sanjeet25 | 3:b702a21b2990 | 167 | APaceReceive=1; |
sanjeet25 | 3:b702a21b2990 | 168 | wait(0.002); |
sanjeet25 | 3:b702a21b2990 | 169 | APaceReceive=0; |
sanjeet25 | 0:a307f0abfd4d | 170 | Areceived=true; |
sanjeet25 | 3:b702a21b2990 | 171 | if(mode == Test && test) { |
sanjeet25 | 3:b702a21b2990 | 172 | if(testNumber == 0) { |
sanjeet25 | 4:a64a0fea5266 | 173 | test_result = false; |
sanjeet25 | 3:b702a21b2990 | 174 | } else if(testNumber == 4 || testNumber == 7 || testNumber == 3 || testNumber == 1) { |
sanjeet25 | 4:a64a0fea5266 | 175 | test_result = true; |
sanjeet25 | 3:b702a21b2990 | 176 | } |
sanjeet25 | 3:b702a21b2990 | 177 | } |
sanjeet25 | 0:a307f0abfd4d | 178 | } |
sanjeet25 | 0:a307f0abfd4d | 179 | |
sanjeet25 | 0:a307f0abfd4d | 180 | void ASignalsend() |
sanjeet25 | 0:a307f0abfd4d | 181 | { |
sanjeet25 | 0:a307f0abfd4d | 182 | ASignal=1; |
sanjeet25 | 1:c340c31174a5 | 183 | ASignal1=1; |
sanjeet25 | 3:b702a21b2990 | 184 | wait(0.02); |
sanjeet25 | 3:b702a21b2990 | 185 | Thread::wait(1); |
sanjeet25 | 3:b702a21b2990 | 186 | ASignal1=0; |
sanjeet25 | 3:b702a21b2990 | 187 | ASignal=0; |
sanjeet25 | 0:a307f0abfd4d | 188 | } |
sanjeet25 | 0:a307f0abfd4d | 189 | |
sanjeet25 | 0:a307f0abfd4d | 190 | void VSignalsend() |
sanjeet25 | 0:a307f0abfd4d | 191 | { |
sanjeet25 | 0:a307f0abfd4d | 192 | VSignal=1; |
sanjeet25 | 1:c340c31174a5 | 193 | VSignal1=1; |
sanjeet25 | 3:b702a21b2990 | 194 | wait(0.02); |
sanjeet25 | 3:b702a21b2990 | 195 | Thread::wait(1); |
sanjeet25 | 3:b702a21b2990 | 196 | VSignal1=0; |
sanjeet25 | 3:b702a21b2990 | 197 | VSignal==0; |
sanjeet25 | 0:a307f0abfd4d | 198 | } |
sanjeet25 | 2:fc2f41386ee4 | 199 | |
sanjeet25 | 2:fc2f41386ee4 | 200 | void updateHeart() |
sanjeet25 | 2:fc2f41386ee4 | 201 | { |
sanjeet25 | 2:fc2f41386ee4 | 202 | int temp = 60/heartInterval; |
sanjeet25 | 2:fc2f41386ee4 | 203 | heartRate = heartRate + temp; |
sanjeet25 | 2:fc2f41386ee4 | 204 | } |
sanjeet25 | 0:a307f0abfd4d | 205 | void HeartReceive(void const* args) |
sanjeet25 | 0:a307f0abfd4d | 206 | { |
sanjeet25 | 0:a307f0abfd4d | 207 | while(1) { |
sanjeet25 | 0:a307f0abfd4d | 208 | pc.printf("HR"); |
sanjeet25 | 1:c340c31174a5 | 209 | while(Areceived==false||Vreceived==false); |
sanjeet25 | 0:a307f0abfd4d | 210 | if(Vreceived==true) { |
sanjeet25 | 3:b702a21b2990 | 211 | resett(); |
sanjeet25 | 3:b702a21b2990 | 212 | |
sanjeet25 | 0:a307f0abfd4d | 213 | } else if(Areceived==true) { |
sanjeet25 | 3:b702a21b2990 | 214 | resett(); |
sanjeet25 | 0:a307f0abfd4d | 215 | } |
sanjeet25 | 0:a307f0abfd4d | 216 | } |
sanjeet25 | 0:a307f0abfd4d | 217 | } |
sanjeet25 | 0:a307f0abfd4d | 218 | |
sanjeet25 | 0:a307f0abfd4d | 219 | void HeartSend(void const* args) |
sanjeet25 | 0:a307f0abfd4d | 220 | { |
sanjeet25 | 1:c340c31174a5 | 221 | while(!pc.readable()) { |
sanjeet25 | 1:c340c31174a5 | 222 | int r = rand() % 2; |
sanjeet25 | 0:a307f0abfd4d | 223 | pc.printf("HS"); |
sanjeet25 | 3:b702a21b2990 | 224 | while(t<minwait_V && mode!=Random && (mode==Test || mode==Manual)); |
sanjeet25 | 3:b702a21b2990 | 225 | pc.printf("%u",t); |
sanjeet25 | 4:a64a0fea5266 | 226 | if(r==0 && mode!=Test) { |
sanjeet25 | 0:a307f0abfd4d | 227 | VSignalsend(); |
sanjeet25 | 1:c340c31174a5 | 228 | pc.printf("Vsignal"); |
sanjeet25 | 3:b702a21b2990 | 229 | resett(); |
sanjeet25 | 4:a64a0fea5266 | 230 | } else if(r==1&&mode!=Test) { |
sanjeet25 | 0:a307f0abfd4d | 231 | ASignalsend(); |
sanjeet25 | 1:c340c31174a5 | 232 | pc.printf("ASignal"); |
sanjeet25 | 3:b702a21b2990 | 233 | resett(); |
sanjeet25 | 0:a307f0abfd4d | 234 | } |
sanjeet25 | 0:a307f0abfd4d | 235 | } |
sanjeet25 | 0:a307f0abfd4d | 236 | } |
sanjeet25 | 0:a307f0abfd4d | 237 | void HeartKeyBoardModeSwitch(void const* args) |
sanjeet25 | 0:a307f0abfd4d | 238 | { |
sanjeet25 | 1:c340c31174a5 | 239 | while(1) { |
sanjeet25 | 5:8e3b9032ddfc | 240 | // Thread::wait(0x02); |
sanjeet25 | 5:8e3b9032ddfc | 241 | if((key_input=='r'||key_input=='R')&&flag_key==1) { |
sanjeet25 | 5:8e3b9032ddfc | 242 | mode=Random; |
sanjeet25 | 5:8e3b9032ddfc | 243 | pc.printf("Random"); |
sanjeet25 | 5:8e3b9032ddfc | 244 | HeartSend("s"); |
sanjeet25 | 5:8e3b9032ddfc | 245 | flag_key=0; |
sanjeet25 | 5:8e3b9032ddfc | 246 | } else if((key_input=='m'||key_input=='M')&&flag_key) { |
sanjeet25 | 5:8e3b9032ddfc | 247 | mode=Manual; |
sanjeet25 | 5:8e3b9032ddfc | 248 | pc.printf("Manual"); |
sanjeet25 | 5:8e3b9032ddfc | 249 | flag_key=0; |
sanjeet25 | 5:8e3b9032ddfc | 250 | } else if(mode==Manual&&(key_input=='v'||key_input=='V')&&flag_key==1) { |
sanjeet25 | 5:8e3b9032ddfc | 251 | mode=Manual; |
sanjeet25 | 5:8e3b9032ddfc | 252 | VSignalsend(); |
sanjeet25 | 5:8e3b9032ddfc | 253 | pc.printf("Ventricular"); |
sanjeet25 | 5:8e3b9032ddfc | 254 | flag_key=0; |
sanjeet25 | 5:8e3b9032ddfc | 255 | } else if(mode==Manual&&flag_key==1&&(key_input=='a'||key_input=='A')) { |
sanjeet25 | 5:8e3b9032ddfc | 256 | mode=Manual; |
sanjeet25 | 5:8e3b9032ddfc | 257 | ASignalsend(); |
sanjeet25 | 5:8e3b9032ddfc | 258 | pc.printf("Atrial"); |
sanjeet25 | 5:8e3b9032ddfc | 259 | flag_key=0; |
sanjeet25 | 5:8e3b9032ddfc | 260 | } else if((key_input=='o'||key_input=='O')&&flag_key==1) { |
sanjeet25 | 5:8e3b9032ddfc | 261 | int a = 10 + rand() % 80; |
sanjeet25 | 5:8e3b9032ddfc | 262 | mode=Observer; |
sanjeet25 | 5:8e3b9032ddfc | 263 | pc.printf("Observer and %u",a); |
sanjeet25 | 5:8e3b9032ddfc | 264 | heartInterval =a; |
sanjeet25 | 5:8e3b9032ddfc | 265 | HeartSend("s"); |
sanjeet25 | 5:8e3b9032ddfc | 266 | flag_key=0; |
sanjeet25 | 0:a307f0abfd4d | 267 | |
sanjeet25 | 5:8e3b9032ddfc | 268 | } else if(flag_key==1&&(key_input=='t'||key_input=='T')) { |
sanjeet25 | 5:8e3b9032ddfc | 269 | mode=Test; |
sanjeet25 | 5:8e3b9032ddfc | 270 | (*testmode).signal_set(0x03); |
sanjeet25 | 5:8e3b9032ddfc | 271 | pc.printf("Test"); |
sanjeet25 | 5:8e3b9032ddfc | 272 | flag_key=0; |
sanjeet25 | 0:a307f0abfd4d | 273 | } |
sanjeet25 | 0:a307f0abfd4d | 274 | } |
sanjeet25 | 5:8e3b9032ddfc | 275 | } |
sanjeet25 | 4:a64a0fea5266 | 276 | |
sanjeet25 | 2:fc2f41386ee4 | 277 | |
sanjeet25 | 3:b702a21b2990 | 278 | void display(void const* args) |
sanjeet25 | 3:b702a21b2990 | 279 | { |
sanjeet25 | 3:b702a21b2990 | 280 | while(1) { |
sanjeet25 | 3:b702a21b2990 | 281 | Thread::wait(observationInterval/1000); |
sanjeet25 | 3:b702a21b2990 | 282 | // if(mode!=Test) { |
sanjeet25 | 3:b702a21b2990 | 283 | // if(mode!= changeobservationinterval) { |
sanjeet25 | 3:b702a21b2990 | 284 | // avgHeartRate=pulseCount*60000/(obsInterval); |
sanjeet25 | 3:b702a21b2990 | 285 | // pulseCount = 0; |
sanjeet25 | 3:b702a21b2990 | 286 | // updateDisplay(); |
sanjeet25 | 3:b702a21b2990 | 287 | // |
sanjeet25 | 3:b702a21b2990 | 288 | // } |
sanjeet25 | 3:b702a21b2990 | 289 | // } |
sanjeet25 | 3:b702a21b2990 | 290 | if(!Test) { |
sanjeet25 | 3:b702a21b2990 | 291 | pc.printf("Avg Heart Rate: %02d bpm", heartRate); |
sanjeet25 | 3:b702a21b2990 | 292 | while(!Vreceived||!VSignal==0) { |
sanjeet25 | 3:b702a21b2990 | 293 | updateHeart(); |
sanjeet25 | 3:b702a21b2990 | 294 | } |
sanjeet25 | 3:b702a21b2990 | 295 | while(k<=heartInterval*1000); |
sanjeet25 | 3:b702a21b2990 | 296 | if(heartRate>high[mode]) { |
sanjeet25 | 3:b702a21b2990 | 297 | sound_highAlarm(); |
sanjeet25 | 3:b702a21b2990 | 298 | heartRate=0; |
sanjeet25 | 3:b702a21b2990 | 299 | resetk(); |
sanjeet25 | 3:b702a21b2990 | 300 | } else if(heartRate<low[mode]) { |
sanjeet25 | 3:b702a21b2990 | 301 | sound_lowAlarm(); |
sanjeet25 | 3:b702a21b2990 | 302 | heartRate=0; |
sanjeet25 | 3:b702a21b2990 | 303 | resetk(); |
sanjeet25 | 3:b702a21b2990 | 304 | } else if(heartRate >= low[mode] && heartRate <= high[mode]) { |
sanjeet25 | 3:b702a21b2990 | 305 | heartRate=0; |
sanjeet25 | 3:b702a21b2990 | 306 | resetk(); |
sanjeet25 | 3:b702a21b2990 | 307 | } |
sanjeet25 | 3:b702a21b2990 | 308 | |
sanjeet25 | 3:b702a21b2990 | 309 | |
sanjeet25 | 3:b702a21b2990 | 310 | } |
sanjeet25 | 3:b702a21b2990 | 311 | } |
sanjeet25 | 3:b702a21b2990 | 312 | } |
sanjeet25 | 3:b702a21b2990 | 313 | |
sanjeet25 | 2:fc2f41386ee4 | 314 | |
sanjeet25 | 4:a64a0fea5266 | 315 | void Testmode(void const* args) |
sanjeet25 | 4:a64a0fea5266 | 316 | { |
sanjeet25 | 4:a64a0fea5266 | 317 | Thread::wait(0x03); |
sanjeet25 | 4:a64a0fea5266 | 318 | test = true; |
sanjeet25 | 4:a64a0fea5266 | 319 | switch(test) { |
sanjeet25 | 4:a64a0fea5266 | 320 | case 1: |
sanjeet25 | 5:8e3b9032ddfc | 321 | flag=0; |
sanjeet25 | 5:8e3b9032ddfc | 322 | Thread::signal_wait(0x04); |
sanjeet25 | 4:a64a0fea5266 | 323 | flag=1; |
sanjeet25 | 4:a64a0fea5266 | 324 | t = 0; |
sanjeet25 | 4:a64a0fea5266 | 325 | Thread::wait(vrp); |
sanjeet25 | 4:a64a0fea5266 | 326 | ASignalsend(); |
sanjeet25 | 4:a64a0fea5266 | 327 | test = true; |
sanjeet25 | 4:a64a0fea5266 | 328 | Thread::wait(lri-avi-vrp); |
sanjeet25 | 4:a64a0fea5266 | 329 | test_result=false; |
sanjeet25 | 4:a64a0fea5266 | 330 | if(test_result) { |
sanjeet25 | 4:a64a0fea5266 | 331 | pc.printf("Test %u passed",test); |
sanjeet25 | 4:a64a0fea5266 | 332 | test=2; |
sanjeet25 | 4:a64a0fea5266 | 333 | } else { |
sanjeet25 | 4:a64a0fea5266 | 334 | pc.printf("Test %u failed",test); |
sanjeet25 | 4:a64a0fea5266 | 335 | test=2; |
sanjeet25 | 4:a64a0fea5266 | 336 | } |
sanjeet25 | 4:a64a0fea5266 | 337 | break; |
sanjeet25 | 5:8e3b9032ddfc | 338 | |
sanjeet25 | 5:8e3b9032ddfc | 339 | case 2: |
sanjeet25 | 4:a64a0fea5266 | 340 | flag=0; |
sanjeet25 | 4:a64a0fea5266 | 341 | Thread::signal_wait(0x04); //Send A after PVARP |
sanjeet25 | 4:a64a0fea5266 | 342 | flag=1; |
sanjeet25 | 4:a64a0fea5266 | 343 | t = 0; |
sanjeet25 | 4:a64a0fea5266 | 344 | Thread::wait(pvarp); |
sanjeet25 | 4:a64a0fea5266 | 345 | ASignalsend(); |
sanjeet25 | 5:8e3b9032ddfc | 346 | |
sanjeet25 | 4:a64a0fea5266 | 347 | Thread::wait(uri-pvarp-delta); |
sanjeet25 | 5:8e3b9032ddfc | 348 | |
sanjeet25 | 4:a64a0fea5266 | 349 | if(test_result) { |
sanjeet25 | 4:a64a0fea5266 | 350 | pc.printf("Test %u passed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 351 | test=3; |
sanjeet25 | 4:a64a0fea5266 | 352 | } else { |
sanjeet25 | 4:a64a0fea5266 | 353 | pc.printf("Test %u failed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 354 | test=3; |
sanjeet25 | 4:a64a0fea5266 | 355 | } |
sanjeet25 | 4:a64a0fea5266 | 356 | break; |
sanjeet25 | 4:a64a0fea5266 | 357 | |
sanjeet25 | 4:a64a0fea5266 | 358 | case 3: |
sanjeet25 | 4:a64a0fea5266 | 359 | flag=0; |
sanjeet25 | 4:a64a0fea5266 | 360 | Thread::signal_wait(0x04); |
sanjeet25 | 4:a64a0fea5266 | 361 | flag=1; |
sanjeet25 | 4:a64a0fea5266 | 362 | t = 0; |
sanjeet25 | 4:a64a0fea5266 | 363 | Thread::wait(uri); |
sanjeet25 | 4:a64a0fea5266 | 364 | for(int i = 0; i<7; i++) { |
sanjeet25 | 4:a64a0fea5266 | 365 | ASignalsend(); |
sanjeet25 | 4:a64a0fea5266 | 366 | Thread::wait(avi-delta); |
sanjeet25 | 4:a64a0fea5266 | 367 | VSignalsend(); |
sanjeet25 | 4:a64a0fea5266 | 368 | Thread::wait(lri-avi-delta); |
sanjeet25 | 4:a64a0fea5266 | 369 | } |
sanjeet25 | 4:a64a0fea5266 | 370 | if(test_result) { |
sanjeet25 | 4:a64a0fea5266 | 371 | pc.printf("Test %u passed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 372 | test=4; |
sanjeet25 | 4:a64a0fea5266 | 373 | } else { |
sanjeet25 | 4:a64a0fea5266 | 374 | pc.printf("Test %u failed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 375 | test=4; |
sanjeet25 | 4:a64a0fea5266 | 376 | } |
sanjeet25 | 4:a64a0fea5266 | 377 | break; |
sanjeet25 | 4:a64a0fea5266 | 378 | case 4: |
sanjeet25 | 4:a64a0fea5266 | 379 | flag=0; |
sanjeet25 | 4:a64a0fea5266 | 380 | Thread::signal_wait(0x04); //Send A after PVARP |
sanjeet25 | 4:a64a0fea5266 | 381 | flag=1; |
sanjeet25 | 4:a64a0fea5266 | 382 | t = 0; |
sanjeet25 | 4:a64a0fea5266 | 383 | Thread::wait(pvarp); |
sanjeet25 | 4:a64a0fea5266 | 384 | ASignalsend(); |
sanjeet25 | 5:8e3b9032ddfc | 385 | |
sanjeet25 | 4:a64a0fea5266 | 386 | Thread::wait(uri-pvarp-delta); |
sanjeet25 | 5:8e3b9032ddfc | 387 | |
sanjeet25 | 4:a64a0fea5266 | 388 | if(test_result) { |
sanjeet25 | 4:a64a0fea5266 | 389 | pc.printf("Test %u passed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 390 | test=5; |
sanjeet25 | 4:a64a0fea5266 | 391 | } else { |
sanjeet25 | 4:a64a0fea5266 | 392 | pc.printf("Test %u failed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 393 | test=5; |
sanjeet25 | 4:a64a0fea5266 | 394 | } |
sanjeet25 | 4:a64a0fea5266 | 395 | break; |
sanjeet25 | 5:8e3b9032ddfc | 396 | case 5: |
sanjeet25 | 4:a64a0fea5266 | 397 | flag=0; |
sanjeet25 | 4:a64a0fea5266 | 398 | Thread::signal_wait(0x04); //Heart is dead |
sanjeet25 | 4:a64a0fea5266 | 399 | flag=1; |
sanjeet25 | 4:a64a0fea5266 | 400 | t = 0; |
sanjeet25 | 5:8e3b9032ddfc | 401 | |
sanjeet25 | 4:a64a0fea5266 | 402 | Thread::wait(lri); |
sanjeet25 | 4:a64a0fea5266 | 403 | Thread::wait(lri); |
sanjeet25 | 4:a64a0fea5266 | 404 | test = false; |
sanjeet25 | 4:a64a0fea5266 | 405 | if(test_result) { |
sanjeet25 | 4:a64a0fea5266 | 406 | pc.printf("Test %u passed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 407 | test=6; |
sanjeet25 | 4:a64a0fea5266 | 408 | } else { |
sanjeet25 | 4:a64a0fea5266 | 409 | pc.printf("Test %u failed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 410 | test=6; |
sanjeet25 | 4:a64a0fea5266 | 411 | } |
sanjeet25 | 4:a64a0fea5266 | 412 | break; |
sanjeet25 | 5:8e3b9032ddfc | 413 | |
sanjeet25 | 5:8e3b9032ddfc | 414 | case 6: |
sanjeet25 | 4:a64a0fea5266 | 415 | flag=0; |
sanjeet25 | 4:a64a0fea5266 | 416 | Thread::signal_wait(0x04); //Heart beating very fast. ASig, VSig |
sanjeet25 | 4:a64a0fea5266 | 417 | flag=1; |
sanjeet25 | 4:a64a0fea5266 | 418 | t = 0; |
sanjeet25 | 4:a64a0fea5266 | 419 | for(int i = 0; i<50; i++) { |
sanjeet25 | 4:a64a0fea5266 | 420 | ASignalsend(); |
sanjeet25 | 4:a64a0fea5266 | 421 | VSignalsend(); |
sanjeet25 | 4:a64a0fea5266 | 422 | } |
sanjeet25 | 4:a64a0fea5266 | 423 | if(test_result) { |
sanjeet25 | 4:a64a0fea5266 | 424 | pc.printf("Test %u passed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 425 | test=7; |
sanjeet25 | 4:a64a0fea5266 | 426 | } else { |
sanjeet25 | 4:a64a0fea5266 | 427 | pc.printf("Test %u failed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 428 | test=7; |
sanjeet25 | 5:8e3b9032ddfc | 429 | } |
sanjeet25 | 4:a64a0fea5266 | 430 | break; |
sanjeet25 | 5:8e3b9032ddfc | 431 | |
sanjeet25 | 5:8e3b9032ddfc | 432 | case 7: |
sanjeet25 | 4:a64a0fea5266 | 433 | flag=0; |
sanjeet25 | 4:a64a0fea5266 | 434 | Thread::signal_wait(0x04); //Wait for VPace to be received |
sanjeet25 | 4:a64a0fea5266 | 435 | flag=1; |
sanjeet25 | 4:a64a0fea5266 | 436 | t= 0; |
sanjeet25 | 4:a64a0fea5266 | 437 | Thread::wait(uri); |
sanjeet25 | 4:a64a0fea5266 | 438 | ASignalsend(); |
sanjeet25 | 4:a64a0fea5266 | 439 | Thread::wait(avi+delta); |
sanjeet25 | 4:a64a0fea5266 | 440 | if(test_result) { |
sanjeet25 | 4:a64a0fea5266 | 441 | pc.printf("Test %u passed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 442 | test=8; |
sanjeet25 | 4:a64a0fea5266 | 443 | } else { |
sanjeet25 | 4:a64a0fea5266 | 444 | pc.printf("Test %u failed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 445 | test=8; |
sanjeet25 | 5:8e3b9032ddfc | 446 | } |
sanjeet25 | 5:8e3b9032ddfc | 447 | |
sanjeet25 | 5:8e3b9032ddfc | 448 | break; |
sanjeet25 | 5:8e3b9032ddfc | 449 | |
sanjeet25 | 5:8e3b9032ddfc | 450 | case 8: |
sanjeet25 | 4:a64a0fea5266 | 451 | flag=0; |
sanjeet25 | 4:a64a0fea5266 | 452 | Thread::signal_wait(0x04); //Send an extra V to see if LRI starts then |
sanjeet25 | 4:a64a0fea5266 | 453 | flag=1; |
sanjeet25 | 4:a64a0fea5266 | 454 | t = 0; |
sanjeet25 | 4:a64a0fea5266 | 455 | Thread::wait(pvarp); |
sanjeet25 | 4:a64a0fea5266 | 456 | VSignalsend(); |
sanjeet25 | 4:a64a0fea5266 | 457 | Thread::wait(lri-avi-delta); |
sanjeet25 | 4:a64a0fea5266 | 458 | if(test_result) { |
sanjeet25 | 4:a64a0fea5266 | 459 | pc.printf("Test %u passed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 460 | test=0; |
sanjeet25 | 4:a64a0fea5266 | 461 | } else { |
sanjeet25 | 4:a64a0fea5266 | 462 | pc.printf("Test %u failed", &test_result); |
sanjeet25 | 4:a64a0fea5266 | 463 | test=0; |
sanjeet25 | 5:8e3b9032ddfc | 464 | } |
sanjeet25 | 4:a64a0fea5266 | 465 | break; |
sanjeet25 | 4:a64a0fea5266 | 466 | |
sanjeet25 | 3:b702a21b2990 | 467 | } |
sanjeet25 | 4:a64a0fea5266 | 468 | } |
sanjeet25 | 4:a64a0fea5266 | 469 | |
sanjeet25 | 3:b702a21b2990 | 470 | |
sanjeet25 | 3:b702a21b2990 | 471 | |
sanjeet25 | 3:b702a21b2990 | 472 | int main() |
sanjeet25 | 5:8e3b9032ddfc | 473 | { |
sanjeet25 | 1:c340c31174a5 | 474 | pc.baud(9600); |
sanjeet25 | 2:fc2f41386ee4 | 475 | VPace.rise(&VPacereceived); |
sanjeet25 | 2:fc2f41386ee4 | 476 | APace.rise(&APacereceived); |
sanjeet25 | 0:a307f0abfd4d | 477 | timer0_init(); |
sanjeet25 | 3:b702a21b2990 | 478 | Thread heartreceive(HeartReceive); |
sanjeet25 | 3:b702a21b2990 | 479 | Thread heartsend(HeartSend); |
sanjeet25 | 3:b702a21b2990 | 480 | Thread heartkeyboard(HeartKeyBoardModeSwitch); |
sanjeet25 | 4:a64a0fea5266 | 481 | hmode = &heartkeyboard; |
sanjeet25 | 3:b702a21b2990 | 482 | Thread disPlay(display); |
sanjeet25 | 4:a64a0fea5266 | 483 | Thread tmode(Testmode); |
sanjeet25 | 4:a64a0fea5266 | 484 | testmode = &tmode; |
sanjeet25 | 0:a307f0abfd4d | 485 | |
sanjeet25 | 5:8e3b9032ddfc | 486 | while(1){ |
sanjeet25 | 5:8e3b9032ddfc | 487 | if(pc.readable()) { |
sanjeet25 | 5:8e3b9032ddfc | 488 | key_input=pc.getc(); //read uart buffer data and clear the interrupt flag |
sanjeet25 | 5:8e3b9032ddfc | 489 | //initiate the serial thread to change the state of the timer |
sanjeet25 | 5:8e3b9032ddfc | 490 | pc.printf("setting"); |
sanjeet25 | 5:8e3b9032ddfc | 491 | //(*testmode).signal_set(0x02); |
sanjeet25 | 5:8e3b9032ddfc | 492 | flag_key=1; |
sanjeet25 | 5:8e3b9032ddfc | 493 | pc.printf("set"); |
sanjeet25 | 5:8e3b9032ddfc | 494 | }} |
sanjeet25 | 0:a307f0abfd4d | 495 | } |