CIS541 / Mbed 2 deprecated CIS541PM

Dependencies:   mbed mbed-rtos TextLCD

Committer:
shibulal
Date:
Mon Nov 30 17:59:05 2015 +0000
Revision:
3:ac2e5aceb324
Parent:
2:b178e27d9f22
Child:
4:242a71a6efed
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shibulal 0:2d6b43fc4625 1 #include "mbed.h"
shibulal 1:e3a5388e46ab 2 #include "rtos.h"
shibulal 3:ac2e5aceb324 3 #include "TextLCD.h"
shibulal 2:b178e27d9f22 4 InterruptIn A(p8);
shibulal 2:b178e27d9f22 5 InterruptIn V(p9);
shibulal 3:ac2e5aceb324 6 int pacemakerrate;
shibulal 3:ac2e5aceb324 7 DigitalOut Apace(p10);
shibulal 3:ac2e5aceb324 8 DigitalOut Vpace(p11);
shibulal 3:ac2e5aceb324 9 DigitalOut ApaceLED(LED1);
shibulal 3:ac2e5aceb324 10 DigitalOut VpaceLED(LED2);
shibulal 3:ac2e5aceb324 11 DigitalOut AsigLED(LED3);
shibulal 3:ac2e5aceb324 12 DigitalOut VsigLED(LED4);
shibulal 3:ac2e5aceb324 13 TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2);
shibulal 1:e3a5388e46ab 14 Serial pc(USBTX, USBRX);
shibulal 3:ac2e5aceb324 15 Queue<char, 16> AVsigpmv;
shibulal 3:ac2e5aceb324 16 Queue<char, 16> AVsensepmv;
shibulal 3:ac2e5aceb324 17 Queue<char, 16> AVpacepmv;
shibulal 3:ac2e5aceb324 18 Queue<char, 16> AVsigpms;
shibulal 3:ac2e5aceb324 19 Queue<char, 16> AVsensepms;
shibulal 3:ac2e5aceb324 20 Queue<char, 16> AVpacepms;
shibulal 3:ac2e5aceb324 21 Queue<char, 16> AVsigpma;
shibulal 3:ac2e5aceb324 22 Queue<char, 16> AVsensepma;
shibulal 3:ac2e5aceb324 23 Queue<char, 16> AVpacepma;
shibulal 3:ac2e5aceb324 24 Queue<char, 16> AVsigpmm;
shibulal 3:ac2e5aceb324 25 Queue<char, 16> AVsensepmm;
shibulal 3:ac2e5aceb324 26 Queue<char, 16> AVpacepmm;
shibulal 3:ac2e5aceb324 27 Queue<char, 16> AVsigpmd;
shibulal 3:ac2e5aceb324 28 Queue<char, 16> AVsensepmd;
shibulal 3:ac2e5aceb324 29 Queue<char, 16> AVpacepmd;
shibulal 1:e3a5388e46ab 30 void PacemakerKeyboardInput(void const *args);
shibulal 1:e3a5388e46ab 31 void PacemakerModes(void const *args);
shibulal 3:ac2e5aceb324 32
shibulal 2:b178e27d9f22 33 void PacemakerSend(void const *args);
shibulal 3:ac2e5aceb324 34 void PaceMakerAtrialInterval(void const *args);
shibulal 3:ac2e5aceb324 35 void PaceMakerVentricalInterval(void const *args);
shibulal 3:ac2e5aceb324 36 int pacemakerMode;
shibulal 1:e3a5388e46ab 37 int modeSwitchTimeInterval = 5000;
shibulal 1:e3a5388e46ab 38 int flag=0;
shibulal 3:ac2e5aceb324 39 int PVAB;
shibulal 1:e3a5388e46ab 40 const int sleepModeURI = 1000;
shibulal 1:e3a5388e46ab 41 const int sleepModeLRI = 2000;
shibulal 1:e3a5388e46ab 42 const int normalModeURI = 600;
shibulal 1:e3a5388e46ab 43 const int normalModeLRI = 1500;
shibulal 1:e3a5388e46ab 44 const int sportsModeURI = 343;
shibulal 1:e3a5388e46ab 45 const int sportsModeLRI = 600;
shibulal 1:e3a5388e46ab 46 const int manualModeURI = 343;
shibulal 1:e3a5388e46ab 47 const int manualModeLRI = 2000;
shibulal 3:ac2e5aceb324 48 int pulses = 0;
shibulal 3:ac2e5aceb324 49 int pacemakerInterval = 10;
shibulal 3:ac2e5aceb324 50 int heartInterval = 10;
shibulal 3:ac2e5aceb324 51 int pacemakerRate = 0;
shibulal 3:ac2e5aceb324 52 int heartRate = 0;
shibulal 1:e3a5388e46ab 53 int LRI = normalModeLRI;
shibulal 1:e3a5388e46ab 54 int URI = normalModeURI;
shibulal 1:e3a5388e46ab 55 Timer k;
shibulal 3:ac2e5aceb324 56 Timer r;
shibulal 2:b178e27d9f22 57 Timer p;
shibulal 3:ac2e5aceb324 58 Timer t_loc;
shibulal 3:ac2e5aceb324 59 Timer t;
shibulal 2:b178e27d9f22 60 const int PVARP = 150;
shibulal 2:b178e27d9f22 61 const int VRP = PVARP;
shibulal 2:b178e27d9f22 62 const int AVI = 65;
shibulal 1:e3a5388e46ab 63 char mode;
shibulal 1:e3a5388e46ab 64 char manualPace;
shibulal 2:b178e27d9f22 65 char AorV;
shibulal 2:b178e27d9f22 66 char AorVsense;
shibulal 1:e3a5388e46ab 67 Thread Pmki(PacemakerKeyboardInput,(void *) 0);
shibulal 2:b178e27d9f22 68 Thread Pmm(PacemakerModes,(void *) 0);
shibulal 3:ac2e5aceb324 69 Thread Pms (PacemakerSend, (void *) 0);
shibulal 3:ac2e5aceb324 70 Thread PmA (PaceMakerAtrialInterval, (void *) 0);
shibulal 3:ac2e5aceb324 71 Thread PmV (PaceMakerVentricalInterval, (void *) 0);
shibulal 1:e3a5388e46ab 72 void PacemakerKeyboardInput(void const *args){
shibulal 1:e3a5388e46ab 73 k.start();
shibulal 1:e3a5388e46ab 74 char input;
shibulal 1:e3a5388e46ab 75 while(true){
shibulal 1:e3a5388e46ab 76 input=pc.getc();
shibulal 1:e3a5388e46ab 77 if (k.read()>=modeSwitchTimeInterval && flag==0){
shibulal 1:e3a5388e46ab 78 if (input=='F'){
shibulal 1:e3a5388e46ab 79 mode='F';
shibulal 1:e3a5388e46ab 80 Pmm.signal_set(0x1);
shibulal 1:e3a5388e46ab 81 Thread::signal_wait(0x1);
shibulal 1:e3a5388e46ab 82 }
shibulal 1:e3a5388e46ab 83 else if (input=='S'){
shibulal 1:e3a5388e46ab 84 mode='S';
shibulal 1:e3a5388e46ab 85 Pmm.signal_set(0x1);
shibulal 1:e3a5388e46ab 86 Thread::signal_wait(0x1);
shibulal 1:e3a5388e46ab 87 }
shibulal 1:e3a5388e46ab 88 else if (input=='N'){
shibulal 1:e3a5388e46ab 89 mode='N';
shibulal 1:e3a5388e46ab 90 Pmm.signal_set(0x1);
shibulal 1:e3a5388e46ab 91 Thread::signal_wait(0x1);
shibulal 1:e3a5388e46ab 92 }
shibulal 1:e3a5388e46ab 93 else if (input=='O'){
shibulal 1:e3a5388e46ab 94 mode='O';
shibulal 1:e3a5388e46ab 95 Pmm.signal_set(0x1);
shibulal 1:e3a5388e46ab 96 Thread::signal_wait(0x1);
shibulal 1:e3a5388e46ab 97 }
shibulal 1:e3a5388e46ab 98 else if (input=='M'){
shibulal 1:e3a5388e46ab 99 mode='M';
shibulal 1:e3a5388e46ab 100 Pmm.signal_set(0x1);
shibulal 1:e3a5388e46ab 101 Thread::signal_wait(0x1);
shibulal 1:e3a5388e46ab 102 }
shibulal 1:e3a5388e46ab 103 else if (input=='A'){
shibulal 1:e3a5388e46ab 104 if (mode=='M')
shibulal 1:e3a5388e46ab 105 manualPace='A';
shibulal 1:e3a5388e46ab 106 Pmm.signal_set(0x1);
shibulal 1:e3a5388e46ab 107 Thread::signal_wait(0x1);
shibulal 1:e3a5388e46ab 108 }
shibulal 1:e3a5388e46ab 109 }
shibulal 1:e3a5388e46ab 110 else if (input=='V'){
shibulal 1:e3a5388e46ab 111 if (mode=='M'){
shibulal 2:b178e27d9f22 112
shibulal 1:e3a5388e46ab 113 manualPace='V';
shibulal 1:e3a5388e46ab 114 Pmm.signal_set(0x1);
shibulal 1:e3a5388e46ab 115 Thread::signal_wait(0x1);
shibulal 1:e3a5388e46ab 116 }
shibulal 1:e3a5388e46ab 117 }
shibulal 1:e3a5388e46ab 118 }
shibulal 1:e3a5388e46ab 119 }
shibulal 2:b178e27d9f22 120
shibulal 1:e3a5388e46ab 121
shibulal 1:e3a5388e46ab 122
shibulal 1:e3a5388e46ab 123 void PacemakerModes(void const *args){
shibulal 1:e3a5388e46ab 124 while(1){
shibulal 1:e3a5388e46ab 125 Thread::signal_wait(0x1);
shibulal 1:e3a5388e46ab 126 if (mode=='F'){
shibulal 1:e3a5388e46ab 127 LRI=sportsModeLRI;
shibulal 1:e3a5388e46ab 128 URI=sportsModeURI;
shibulal 2:b178e27d9f22 129 Pmki.signal_set(0x1);
shibulal 1:e3a5388e46ab 130 }
shibulal 1:e3a5388e46ab 131 else if (mode=='S'){
shibulal 1:e3a5388e46ab 132 LRI=sleepModeLRI;
shibulal 1:e3a5388e46ab 133 URI=sleepModeURI;
shibulal 2:b178e27d9f22 134 Pmki.signal_set(0x1);
shibulal 1:e3a5388e46ab 135 }
shibulal 1:e3a5388e46ab 136 else if (mode=='N'){
shibulal 1:e3a5388e46ab 137 LRI=normalModeLRI;
shibulal 1:e3a5388e46ab 138 URI=normalModeURI;
shibulal 2:b178e27d9f22 139 Pmki.signal_set(0x1);
shibulal 1:e3a5388e46ab 140 }
shibulal 1:e3a5388e46ab 141 else if (mode=='O'){
shibulal 1:e3a5388e46ab 142 //not sure what to do here
shibulal 2:b178e27d9f22 143 Pmki.signal_set(0x1);
shibulal 1:e3a5388e46ab 144 }
shibulal 1:e3a5388e46ab 145 else if (mode=='M'){
shibulal 1:e3a5388e46ab 146 LRI=manualModeLRI;
shibulal 1:e3a5388e46ab 147 URI=manualModeURI;
shibulal 2:b178e27d9f22 148 Pmki.signal_set(0x1);
shibulal 1:e3a5388e46ab 149 while(1){
shibulal 1:e3a5388e46ab 150 Thread::signal_wait(0x1);
shibulal 1:e3a5388e46ab 151 if (mode=='M'){
shibulal 1:e3a5388e46ab 152 if (manualPace=='A'){
shibulal 3:ac2e5aceb324 153 char* element;
shibulal 3:ac2e5aceb324 154 *element='A';
shibulal 3:ac2e5aceb324 155 AVpacepms.put(element);
shibulal 3:ac2e5aceb324 156 AVpacepma.put(element);
shibulal 3:ac2e5aceb324 157 AVpacepmv.put(element);
shibulal 3:ac2e5aceb324 158 AVpacepmm.put(element);
shibulal 3:ac2e5aceb324 159 AVpacepmd.put(element);
shibulal 1:e3a5388e46ab 160 }
shibulal 1:e3a5388e46ab 161 else if (manualPace=='V'){
shibulal 3:ac2e5aceb324 162 char* element;
shibulal 3:ac2e5aceb324 163 *element='V';
shibulal 3:ac2e5aceb324 164 AVpacepms.put(element);
shibulal 3:ac2e5aceb324 165 AVpacepma.put(element);
shibulal 3:ac2e5aceb324 166 AVpacepmv.put(element);
shibulal 3:ac2e5aceb324 167 AVpacepmm.put(element);
shibulal 3:ac2e5aceb324 168 AVpacepmd.put(element);
shibulal 1:e3a5388e46ab 169 }
shibulal 1:e3a5388e46ab 170 }
shibulal 1:e3a5388e46ab 171 else {
shibulal 2:b178e27d9f22 172 Pmm.signal_set(0x1);
shibulal 2:b178e27d9f22 173 Pmki.signal_set(0x1);
shibulal 2:b178e27d9f22 174 break;
shibulal 2:b178e27d9f22 175 }
shibulal 2:b178e27d9f22 176 Pmki.signal_set(0x1);
shibulal 2:b178e27d9f22 177 }
shibulal 2:b178e27d9f22 178 }
shibulal 2:b178e27d9f22 179 }
shibulal 2:b178e27d9f22 180 }
shibulal 3:ac2e5aceb324 181
shibulal 3:ac2e5aceb324 182 void PaceMakerAtrialInterval(void const *args){
shibulal 3:ac2e5aceb324 183 char *AorVsig;
shibulal 3:ac2e5aceb324 184 char *AorVpace;
shibulal 3:ac2e5aceb324 185 char *AorVsense;
shibulal 3:ac2e5aceb324 186 osEvent evt;
shibulal 3:ac2e5aceb324 187 while (1){
shibulal 3:ac2e5aceb324 188 evt = AVsigpma.get(1);
shibulal 3:ac2e5aceb324 189 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 190 AorVsig = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 191 }
shibulal 3:ac2e5aceb324 192 if (*AorVsig=='A'){
shibulal 3:ac2e5aceb324 193 AorVsig=0;
shibulal 3:ac2e5aceb324 194 char* element;
shibulal 3:ac2e5aceb324 195 *element='A';
shibulal 3:ac2e5aceb324 196 AVsensepms.put(element);
shibulal 3:ac2e5aceb324 197 AVsensepma.put(element);
shibulal 3:ac2e5aceb324 198 AVsensepmv.put(element);
shibulal 3:ac2e5aceb324 199 AVsensepmm.put(element);
shibulal 3:ac2e5aceb324 200 AVsensepmd.put(element);
shibulal 3:ac2e5aceb324 201 break;
shibulal 3:ac2e5aceb324 202 }
shibulal 3:ac2e5aceb324 203 evt = AVpacepma.get(1);
shibulal 3:ac2e5aceb324 204 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 205 AorVpace = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 206 }
shibulal 3:ac2e5aceb324 207 if (*AorVpace=='A'){
shibulal 3:ac2e5aceb324 208 AorVpace=0;
shibulal 3:ac2e5aceb324 209 break;
shibulal 3:ac2e5aceb324 210 }
shibulal 3:ac2e5aceb324 211 }
shibulal 3:ac2e5aceb324 212 t.reset();
shibulal 2:b178e27d9f22 213 while(1){
shibulal 3:ac2e5aceb324 214 osEvent evt = AVsensepma.get(1);
shibulal 3:ac2e5aceb324 215 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 216 AorVsense = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 217 }
shibulal 3:ac2e5aceb324 218 if (*AorVsense=='V'){
shibulal 3:ac2e5aceb324 219 AorVsense=0;
shibulal 3:ac2e5aceb324 220 break;
shibulal 3:ac2e5aceb324 221 }
shibulal 3:ac2e5aceb324 222 evt = AVsensepma.get(1);
shibulal 3:ac2e5aceb324 223 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 224 AorVpace = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 225 }
shibulal 3:ac2e5aceb324 226 if (*AorVpace=='V'){
shibulal 3:ac2e5aceb324 227 *AorVpace='V';
shibulal 3:ac2e5aceb324 228 break;
shibulal 3:ac2e5aceb324 229 }
shibulal 3:ac2e5aceb324 230 }
shibulal 3:ac2e5aceb324 231 k.reset();
shibulal 3:ac2e5aceb324 232 while(!(k>=PVARP));
shibulal 3:ac2e5aceb324 233 while(!(t>=URI));
shibulal 3:ac2e5aceb324 234 }
shibulal 3:ac2e5aceb324 235 void updatePacemaker(){
shibulal 3:ac2e5aceb324 236 int temp = 60/pacemakerInterval;
shibulal 3:ac2e5aceb324 237 pacemakerRate = pacemakerRate + temp;
shibulal 3:ac2e5aceb324 238 }
shibulal 3:ac2e5aceb324 239 void PaceMakerDisplay(void const *args){
shibulal 3:ac2e5aceb324 240 osEvent evt;
shibulal 3:ac2e5aceb324 241 char* AorVsense;
shibulal 3:ac2e5aceb324 242 char* AorVpace;
shibulal 3:ac2e5aceb324 243 while(1){
shibulal 3:ac2e5aceb324 244
shibulal 3:ac2e5aceb324 245 while(1){
shibulal 3:ac2e5aceb324 246 evt = AVsensepmd.get(1);
shibulal 3:ac2e5aceb324 247 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 248 AorVsense = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 249 }
shibulal 3:ac2e5aceb324 250 if (*AorVsense=='V'){
shibulal 3:ac2e5aceb324 251 break;
shibulal 3:ac2e5aceb324 252 }
shibulal 3:ac2e5aceb324 253 evt = AVpacepmd.get(1);
shibulal 3:ac2e5aceb324 254 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 255 AorVpace = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 256 }
shibulal 3:ac2e5aceb324 257 if (*AorVpace=='V'){
shibulal 3:ac2e5aceb324 258 break;
shibulal 3:ac2e5aceb324 259 }
shibulal 3:ac2e5aceb324 260 }
shibulal 3:ac2e5aceb324 261 if (r<=pacemakerInterval*1000){
shibulal 3:ac2e5aceb324 262 updatePacemaker();
shibulal 3:ac2e5aceb324 263 }
shibulal 3:ac2e5aceb324 264 else {
shibulal 3:ac2e5aceb324 265 if (pacemakerRate < low[mode]){
shibulal 3:ac2e5aceb324 266 r.reset();
shibulal 3:ac2e5aceb324 267 paceMakerRate=0;
shibulal 3:ac2e5aceb324 268 }
shibulal 3:ac2e5aceb324 269 else if (pacemakerRate >= low[mode] && pacemakerRate <= high[mode]){
shibulal 3:ac2e5aceb324 270 //high alarm
shibulal 3:ac2e5aceb324 271 r.reset();
shibulal 3:ac2e5aceb324 272 paceMakerRate=0;
shibulal 3:ac2e5aceb324 273 }
shibulal 3:ac2e5aceb324 274 else if (pacemakerRate > high[mode]){
shibulal 3:ac2e5aceb324 275 //low alarm
shibulal 3:ac2e5aceb324 276 r.reset();
shibulal 3:ac2e5aceb324 277 paceMakerRate=0;
shibulal 3:ac2e5aceb324 278 }
shibulal 3:ac2e5aceb324 279 }
shibulal 3:ac2e5aceb324 280
shibulal 3:ac2e5aceb324 281
shibulal 3:ac2e5aceb324 282 }
shibulal 3:ac2e5aceb324 283 }
shibulal 3:ac2e5aceb324 284 void PaceMakerVentricalInterval(void const *args){
shibulal 3:ac2e5aceb324 285 char *AorVsig;
shibulal 3:ac2e5aceb324 286 char *AorVsense;
shibulal 3:ac2e5aceb324 287 char *AorVpace;
shibulal 3:ac2e5aceb324 288 osEvent evt;
shibulal 3:ac2e5aceb324 289 while(1){
shibulal 3:ac2e5aceb324 290 while(1){
shibulal 3:ac2e5aceb324 291 evt = AVsigpmv.get(1);
shibulal 3:ac2e5aceb324 292 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 293 AorVsig = (char*)evt.value.p;
shibulal 2:b178e27d9f22 294 }
shibulal 3:ac2e5aceb324 295 if (*AorVsig=='V'){
shibulal 3:ac2e5aceb324 296 AorVsig=0;
shibulal 3:ac2e5aceb324 297 char* element;
shibulal 3:ac2e5aceb324 298 *element='V';
shibulal 3:ac2e5aceb324 299 AVsensepms.put(element);
shibulal 3:ac2e5aceb324 300 AVsensepma.put(element);
shibulal 3:ac2e5aceb324 301 AVsensepmv.put(element);
shibulal 3:ac2e5aceb324 302 AVsensepmm.put(element);
shibulal 3:ac2e5aceb324 303 AVsensepmd.put(element);
shibulal 3:ac2e5aceb324 304 break;
shibulal 3:ac2e5aceb324 305 }
shibulal 3:ac2e5aceb324 306 evt = AVsensepmv.get(1);
shibulal 3:ac2e5aceb324 307 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 308 AorVsense = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 309 }
shibulal 3:ac2e5aceb324 310 if (*AorVsense=='A'){
shibulal 3:ac2e5aceb324 311 AorVsense=0;
shibulal 3:ac2e5aceb324 312 p.reset();
shibulal 3:ac2e5aceb324 313 while(!(p>=PVAB));
shibulal 3:ac2e5aceb324 314 while(1){
shibulal 3:ac2e5aceb324 315 osEvent evt = AVsigpmv.get(1);
shibulal 3:ac2e5aceb324 316 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 317 AorVsig = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 318 }
shibulal 3:ac2e5aceb324 319 if (*AorVsig=='V'){
shibulal 3:ac2e5aceb324 320 AorVsig=0;
shibulal 3:ac2e5aceb324 321 break;
shibulal 3:ac2e5aceb324 322 }
shibulal 3:ac2e5aceb324 323 evt = AVpacepmv.get(1);
shibulal 3:ac2e5aceb324 324 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 325 AorVpace = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 326 }
shibulal 3:ac2e5aceb324 327 if (*AorVpace=='V'){
shibulal 3:ac2e5aceb324 328 char* element;
shibulal 3:ac2e5aceb324 329 *element='V';
shibulal 3:ac2e5aceb324 330 AVsensepmv.put(element);
shibulal 3:ac2e5aceb324 331 break;
shibulal 3:ac2e5aceb324 332 }
shibulal 3:ac2e5aceb324 333 p.reset();
shibulal 3:ac2e5aceb324 334 while(!(p>=VRP));
shibulal 2:b178e27d9f22 335 }
shibulal 3:ac2e5aceb324 336 break;
shibulal 3:ac2e5aceb324 337 }
shibulal 3:ac2e5aceb324 338 evt = AVpacepmv.get(1);
shibulal 3:ac2e5aceb324 339 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 340 AorVpace = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 341 }
shibulal 3:ac2e5aceb324 342 if (*AorVpace=='A'){
shibulal 3:ac2e5aceb324 343 AorVpace=0;
shibulal 3:ac2e5aceb324 344 p.reset();
shibulal 3:ac2e5aceb324 345 while(!(p>=PVAB));
shibulal 3:ac2e5aceb324 346 while(1){
shibulal 3:ac2e5aceb324 347 osEvent evt = AVsigpmv.get(1);
shibulal 3:ac2e5aceb324 348 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 349 AorVsig = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 350 }
shibulal 3:ac2e5aceb324 351 if (*AorVsig=='V'){
shibulal 3:ac2e5aceb324 352 AorVsig=0;
shibulal 3:ac2e5aceb324 353 break;
shibulal 3:ac2e5aceb324 354 }
shibulal 3:ac2e5aceb324 355 evt = AVpacepmv.get(1);
shibulal 3:ac2e5aceb324 356 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 357 AorVpace = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 358 }
shibulal 3:ac2e5aceb324 359 if (*AorVpace=='V'){
shibulal 3:ac2e5aceb324 360 char* element;
shibulal 3:ac2e5aceb324 361 *element='V';
shibulal 3:ac2e5aceb324 362 AVsensepms.put(element);
shibulal 3:ac2e5aceb324 363 AVsensepma.put(element);
shibulal 3:ac2e5aceb324 364 AVsensepmv.put(element);
shibulal 3:ac2e5aceb324 365 AVsensepmm.put(element);
shibulal 3:ac2e5aceb324 366 AVsensepmd.put(element);
shibulal 3:ac2e5aceb324 367 break;
shibulal 3:ac2e5aceb324 368 }
shibulal 3:ac2e5aceb324 369 p.reset();
shibulal 3:ac2e5aceb324 370 while(!(p.read()>=VRP));
shibulal 3:ac2e5aceb324 371 }
shibulal 3:ac2e5aceb324 372 break;
shibulal 2:b178e27d9f22 373 }
shibulal 3:ac2e5aceb324 374 }
shibulal 3:ac2e5aceb324 375 }
shibulal 3:ac2e5aceb324 376
shibulal 3:ac2e5aceb324 377 }
shibulal 3:ac2e5aceb324 378 void PacemakerSend(void const *args){
shibulal 3:ac2e5aceb324 379 char *AorV;
shibulal 3:ac2e5aceb324 380 while(1){
shibulal 3:ac2e5aceb324 381 while(1){
shibulal 3:ac2e5aceb324 382 osEvent evt = AVsensepms.get(1);
shibulal 3:ac2e5aceb324 383 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 384 AorV = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 385 }
shibulal 3:ac2e5aceb324 386 if (*AorV=='A'){
shibulal 3:ac2e5aceb324 387 AorV=0;
shibulal 3:ac2e5aceb324 388 break;
shibulal 3:ac2e5aceb324 389 }
shibulal 3:ac2e5aceb324 390 else if (t.read()>=AVI){
shibulal 3:ac2e5aceb324 391 char* element;
shibulal 3:ac2e5aceb324 392 *element='V';
shibulal 3:ac2e5aceb324 393 AVpacepms.put(element);
shibulal 3:ac2e5aceb324 394 AVpacepmv.put(element);
shibulal 3:ac2e5aceb324 395 AVpacepma.put(element);
shibulal 3:ac2e5aceb324 396 Vpace=1;
shibulal 3:ac2e5aceb324 397 wait(.1);
shibulal 3:ac2e5aceb324 398 Vpace=0;
shibulal 3:ac2e5aceb324 399 break;
shibulal 3:ac2e5aceb324 400 }
shibulal 3:ac2e5aceb324 401 else if (pacemakerMode==1){
shibulal 3:ac2e5aceb324 402 while(pacemakerMode!=0);
shibulal 3:ac2e5aceb324 403 break;
shibulal 3:ac2e5aceb324 404 }
shibulal 3:ac2e5aceb324 405 }
shibulal 3:ac2e5aceb324 406 while(1){
shibulal 3:ac2e5aceb324 407 osEvent evt = AVsensepms.get(1);
shibulal 3:ac2e5aceb324 408 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 409 AorV = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 410 }
shibulal 3:ac2e5aceb324 411 if (*AorV=='A'){
shibulal 3:ac2e5aceb324 412 AorV=0;
shibulal 3:ac2e5aceb324 413 if (pacemakerMode==1){
shibulal 3:ac2e5aceb324 414 while(pacemakerMode!=0);
shibulal 2:b178e27d9f22 415 break;
shibulal 2:b178e27d9f22 416 }
shibulal 3:ac2e5aceb324 417 else{
shibulal 3:ac2e5aceb324 418 t.reset();
shibulal 1:e3a5388e46ab 419 break;
shibulal 1:e3a5388e46ab 420 }
shibulal 2:b178e27d9f22 421 }
shibulal 3:ac2e5aceb324 422 else if (*AorV=='V'){
shibulal 3:ac2e5aceb324 423 AorV=0;
shibulal 3:ac2e5aceb324 424 t.reset();
shibulal 3:ac2e5aceb324 425 while(1){
shibulal 3:ac2e5aceb324 426 osEvent evt = AVsensepms.get(1);
shibulal 3:ac2e5aceb324 427 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 428 AorV = (char*)evt.value.p;
shibulal 2:b178e27d9f22 429 }
shibulal 3:ac2e5aceb324 430 if (*AorV=='A'){
shibulal 3:ac2e5aceb324 431 AorV=0;
shibulal 3:ac2e5aceb324 432 if (pacemakerMode==1){
shibulal 3:ac2e5aceb324 433 while(pacemakerMode!=0);
shibulal 3:ac2e5aceb324 434 break;
shibulal 3:ac2e5aceb324 435 }
shibulal 3:ac2e5aceb324 436 else{
shibulal 3:ac2e5aceb324 437 t.reset();
shibulal 3:ac2e5aceb324 438 break;
shibulal 3:ac2e5aceb324 439 }
shibulal 3:ac2e5aceb324 440 }
shibulal 3:ac2e5aceb324 441 else if (pacemakerMode==1){
shibulal 3:ac2e5aceb324 442 while(pacemakerMode!=0);
shibulal 3:ac2e5aceb324 443 break;
shibulal 3:ac2e5aceb324 444 }
shibulal 3:ac2e5aceb324 445 else if (t>= LRI-AVI){
shibulal 3:ac2e5aceb324 446 char* element;
shibulal 3:ac2e5aceb324 447 *element='A';
shibulal 3:ac2e5aceb324 448 AVpacepms.put(element);
shibulal 3:ac2e5aceb324 449 AVpacepma.put(element);
shibulal 3:ac2e5aceb324 450 AVpacepmv.put(element);
shibulal 3:ac2e5aceb324 451 AVpacepmm.put(element);
shibulal 3:ac2e5aceb324 452 AVpacepmd.put(element);
shibulal 3:ac2e5aceb324 453 Apace=1;
shibulal 3:ac2e5aceb324 454 wait(.1);
shibulal 3:ac2e5aceb324 455 Apace=0;
shibulal 3:ac2e5aceb324 456 if (pacemakerMode==1){
shibulal 3:ac2e5aceb324 457 while(pacemakerMode!=0);
shibulal 3:ac2e5aceb324 458 break;
shibulal 3:ac2e5aceb324 459 }
shibulal 3:ac2e5aceb324 460 else{
shibulal 3:ac2e5aceb324 461 t.reset();
shibulal 3:ac2e5aceb324 462 break;
shibulal 3:ac2e5aceb324 463 }
shibulal 3:ac2e5aceb324 464 }
shibulal 2:b178e27d9f22 465 }
shibulal 2:b178e27d9f22 466 }
shibulal 3:ac2e5aceb324 467 else if (t.read()>=LRI){
shibulal 3:ac2e5aceb324 468 char* element;
shibulal 3:ac2e5aceb324 469 *element='A';
shibulal 3:ac2e5aceb324 470 AVpacepms.put(element);
shibulal 3:ac2e5aceb324 471 AVpacepma.put(element);
shibulal 3:ac2e5aceb324 472 AVpacepmv.put(element);
shibulal 3:ac2e5aceb324 473 AVpacepmm.put(element);
shibulal 3:ac2e5aceb324 474 AVpacepmd.put(element);
shibulal 3:ac2e5aceb324 475 Apace=1;
shibulal 3:ac2e5aceb324 476 wait(.1);
shibulal 3:ac2e5aceb324 477 Apace=0;
shibulal 3:ac2e5aceb324 478 if (pacemakerMode==1){
shibulal 3:ac2e5aceb324 479 while(pacemakerMode!=0);
shibulal 3:ac2e5aceb324 480 break;
shibulal 3:ac2e5aceb324 481 }
shibulal 3:ac2e5aceb324 482 else{
shibulal 3:ac2e5aceb324 483 t.reset();
shibulal 3:ac2e5aceb324 484 break;
shibulal 3:ac2e5aceb324 485 }
shibulal 2:b178e27d9f22 486 }
shibulal 3:ac2e5aceb324 487 else if (pacemakerMode==1){
shibulal 3:ac2e5aceb324 488 while(pacemakerMode!=0);
shibulal 2:b178e27d9f22 489 break;
shibulal 2:b178e27d9f22 490 }
shibulal 1:e3a5388e46ab 491
shibulal 2:b178e27d9f22 492
shibulal 3:ac2e5aceb324 493 }
shibulal 2:b178e27d9f22 494 }
shibulal 3:ac2e5aceb324 495 }
shibulal 3:ac2e5aceb324 496 void Asig();
shibulal 3:ac2e5aceb324 497 void Vsig();
shibulal 1:e3a5388e46ab 498 int main(){
shibulal 3:ac2e5aceb324 499 osEvent evt;
shibulal 3:ac2e5aceb324 500 A.mode(PullDown);
shibulal 3:ac2e5aceb324 501 char* AorVpace;
shibulal 3:ac2e5aceb324 502 char* AorVsig;
shibulal 2:b178e27d9f22 503 A.rise(Asig);
shibulal 2:b178e27d9f22 504 V.mode(PullDown);
shibulal 2:b178e27d9f22 505 V.rise(Vsig);
shibulal 1:e3a5388e46ab 506
shibulal 3:ac2e5aceb324 507 while(1){
shibulal 3:ac2e5aceb324 508 evt = AVpacepmm.get(1);
shibulal 3:ac2e5aceb324 509 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 510 AorVpace = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 511 }
shibulal 3:ac2e5aceb324 512 if (*AorVpace=='A'){
shibulal 3:ac2e5aceb324 513 AorVpace=0;
shibulal 3:ac2e5aceb324 514 ApaceLED=1;
shibulal 3:ac2e5aceb324 515 wait(.1);
shibulal 3:ac2e5aceb324 516 ApaceLED=(0);
shibulal 3:ac2e5aceb324 517 }
shibulal 3:ac2e5aceb324 518 else if (*AorVpace=='V'){
shibulal 3:ac2e5aceb324 519 AorVpace=0;
shibulal 3:ac2e5aceb324 520 VpaceLED=1;
shibulal 3:ac2e5aceb324 521 wait(.1);
shibulal 3:ac2e5aceb324 522 VpaceLED=0;
shibulal 3:ac2e5aceb324 523 }
shibulal 3:ac2e5aceb324 524 evt = AVsigpmm.get(1);
shibulal 3:ac2e5aceb324 525 if (evt.status == osEventMessage) {
shibulal 3:ac2e5aceb324 526 AorVsig = (char*)evt.value.p;
shibulal 3:ac2e5aceb324 527 }
shibulal 3:ac2e5aceb324 528 if (*AorVsig=='A'){
shibulal 3:ac2e5aceb324 529 AorVsig=0;
shibulal 3:ac2e5aceb324 530 AsigLED=1;
shibulal 3:ac2e5aceb324 531 wait(.1);
shibulal 3:ac2e5aceb324 532 ApaceLED=(0);
shibulal 3:ac2e5aceb324 533 }
shibulal 3:ac2e5aceb324 534 else if (*AorVsig=='V'){
shibulal 3:ac2e5aceb324 535 AorVsig=0;
shibulal 3:ac2e5aceb324 536 VsigLED=1;
shibulal 3:ac2e5aceb324 537 wait(.1);
shibulal 3:ac2e5aceb324 538 VpaceLED=0;
shibulal 3:ac2e5aceb324 539 }
shibulal 3:ac2e5aceb324 540 lcd.cls();
shibulal 3:ac2e5aceb324 541 lcd.printf("%d", pacemakerRate);
shibulal 3:ac2e5aceb324 542 Thread::wait(15);
shibulal 3:ac2e5aceb324 543 };
shibulal 0:2d6b43fc4625 544 }
shibulal 2:b178e27d9f22 545
shibulal 2:b178e27d9f22 546
shibulal 2:b178e27d9f22 547 void Asig() {
shibulal 3:ac2e5aceb324 548 char* element;
shibulal 3:ac2e5aceb324 549 *element='A';
shibulal 3:ac2e5aceb324 550 AVsigpms.put(element);
shibulal 3:ac2e5aceb324 551 AVsigpma.put(element);
shibulal 3:ac2e5aceb324 552 AVsigpmv.put(element);
shibulal 3:ac2e5aceb324 553 AVsigpmm.put(element);
shibulal 3:ac2e5aceb324 554 AVsigpmd.put(element);
shibulal 2:b178e27d9f22 555
shibulal 2:b178e27d9f22 556 }
shibulal 2:b178e27d9f22 557 void Vsig() {
shibulal 3:ac2e5aceb324 558 char* element;
shibulal 3:ac2e5aceb324 559 *element='V';
shibulal 3:ac2e5aceb324 560 AVsigpms.put(element);
shibulal 3:ac2e5aceb324 561 AVsigpma.put(element);
shibulal 3:ac2e5aceb324 562 AVsigpmv.put(element);
shibulal 3:ac2e5aceb324 563 AVsigpmm.put(element);
shibulal 3:ac2e5aceb324 564 AVsigpmd.put(element);
shibulal 2:b178e27d9f22 565
shibulal 2:b178e27d9f22 566 }