HAHAHAHHA

Dependencies:   TextLCD mbed-rtos mbed

Fork of 541-pacemaker-heart by Terry Fang

Committer:
terryfan
Date:
Mon Dec 05 03:11:53 2016 +0000
Revision:
2:18b496a20413
Parent:
1:57cd3ae5f44a
Child:
3:1498846197ee
need to implement heart_beats count in code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terryfan 0:da581483b90d 1 #include "mbed.h"
terryfan 0:da581483b90d 2 #include "rtos.h"
terryfan 0:da581483b90d 3 #include "TextLCD.h"
terryfan 0:da581483b90d 4
terryfan 2:18b496a20413 5
terryfan 0:da581483b90d 6 LocalFileSystem local("local");
terryfan 0:da581483b90d 7
terryfan 2:18b496a20413 8
terryfan 0:da581483b90d 9 InterruptIn vpace(p5);
terryfan 0:da581483b90d 10 InterruptIn apace(p6);
terryfan 0:da581483b90d 11 DigitalOut vsignal(p7);
terryfan 0:da581483b90d 12 DigitalOut asignal(p8);
terryfan 0:da581483b90d 13
terryfan 2:18b496a20413 14
terryfan 0:da581483b90d 15 DigitalOut asignal_led(LED1);
terryfan 0:da581483b90d 16 DigitalOut vsignal_led(LED2);
terryfan 0:da581483b90d 17 DigitalOut apace_led(LED3);
terryfan 0:da581483b90d 18 DigitalOut vpace_led(LED4);
terryfan 0:da581483b90d 19
terryfan 2:18b496a20413 20
terryfan 0:da581483b90d 21 Thread *heartmodeThread;
terryfan 0:da581483b90d 22 osThreadId heartmodeTid;
terryfan 0:da581483b90d 23
terryfan 2:18b496a20413 24
terryfan 1:57cd3ae5f44a 25 Queue<char,256> mode_q;
terryfan 1:57cd3ae5f44a 26 Queue<char,256> signal_q;
terryfan 1:57cd3ae5f44a 27
terryfan 1:57cd3ae5f44a 28
terryfan 2:18b496a20413 29 Queue<char,256> obsint_q;
terryfan 2:18b496a20413 30
terryfan 1:57cd3ae5f44a 31 FILE * testresults;
terryfan 1:57cd3ae5f44a 32
terryfan 2:18b496a20413 33
terryfan 0:da581483b90d 34 /////////////////
terryfan 0:da581483b90d 35 TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2);
terryfan 0:da581483b90d 36 RawSerial pc(USBTX, USBRX);
terryfan 0:da581483b90d 37 char key = 'n';
terryfan 0:da581483b90d 38 int manual_mode;
terryfan 2:18b496a20413 39
terryfan 2:18b496a20413 40
terryfan 2:18b496a20413 41 int observation_interval = 10;
terryfan 0:da581483b90d 42 /////////////////
terryfan 1:57cd3ae5f44a 43 volatile char c;
terryfan 1:57cd3ae5f44a 44 volatile int mm = 0;
terryfan 0:da581483b90d 45
terryfan 2:18b496a20413 46 volatile int om = 0;
terryfan 0:da581483b90d 47 int lri = 1000;
terryfan 0:da581483b90d 48 int uri = 700;
terryfan 0:da581483b90d 49 int avi = 150;
terryfan 0:da581483b90d 50 int pvarp = 300;
terryfan 0:da581483b90d 51 int vrp = 200;
terryfan 0:da581483b90d 52 int arp = 50;
terryfan 0:da581483b90d 53
terryfan 2:18b496a20413 54
terryfan 0:da581483b90d 55 int twait = 10;
terryfan 0:da581483b90d 56 int thrsh = 1000;
terryfan 0:da581483b90d 57 int heartmode = 0;
terryfan 1:57cd3ae5f44a 58
terryfan 2:18b496a20413 59 int heart_beats = 0; // Heart-Beats (sensed or paced) since the last observation interval
terryfan 2:18b496a20413 60 Mutex hr_mutex; //hr_mutex.lock()/unlock()
terryfan 1:57cd3ae5f44a 61
terryfan 2:18b496a20413 62
terryfan 2:18b496a20413 63
terryfan 0:da581483b90d 64 void vpace_irq()
terryfan 0:da581483b90d 65 {
terryfan 0:da581483b90d 66 //heartmodeThread->signal_set(0x1);
terryfan 0:da581483b90d 67 osSignalSet(heartmodeTid, 0x1);
terryfan 0:da581483b90d 68 }
terryfan 0:da581483b90d 69
terryfan 2:18b496a20413 70
terryfan 0:da581483b90d 71 void apace_irq()
terryfan 0:da581483b90d 72 {
terryfan 0:da581483b90d 73 //heartmodeThread->signal_set(0x10);
terryfan 0:da581483b90d 74 osSignalSet(heartmodeTid, 0x10);
terryfan 0:da581483b90d 75 }
terryfan 0:da581483b90d 76
terryfan 2:18b496a20413 77
terryfan 1:57cd3ae5f44a 78 void Rx_interrupt()
terryfan 1:57cd3ae5f44a 79 {
terryfan 1:57cd3ae5f44a 80 while(pc.readable()) {
terryfan 1:57cd3ae5f44a 81 c = pc.getc();
terryfan 2:18b496a20413 82 if(c == 'm' && om != 1) {
terryfan 1:57cd3ae5f44a 83 mode_q.put((char*)c);
terryfan 1:57cd3ae5f44a 84 mm = 1;
terryfan 2:18b496a20413 85 } else if((c == 'r' || c == 't') && om != 1) {
terryfan 1:57cd3ae5f44a 86 mode_q.put((char*)c);
terryfan 1:57cd3ae5f44a 87 mm = 0;
terryfan 1:57cd3ae5f44a 88 } else if((c == 'a' || c == 'v') && mm) {
terryfan 1:57cd3ae5f44a 89 signal_q.put((char*)c);
terryfan 2:18b496a20413 90 } else if(c == 'o' && om != 1) {
terryfan 2:18b496a20413 91 mode_q.put((char*)c);
terryfan 2:18b496a20413 92 om = 1;
terryfan 2:18b496a20413 93 } else if (c == '\r' && om) {
terryfan 2:18b496a20413 94 obsint_q.put((char*)c);
terryfan 2:18b496a20413 95 om = 0;
terryfan 2:18b496a20413 96 } else if ((int)c > 47 && (int)c < 58 && om) {
terryfan 2:18b496a20413 97 obsint_q.put((char*)c);
terryfan 1:57cd3ae5f44a 98 }
terryfan 1:57cd3ae5f44a 99 }
terryfan 1:57cd3ae5f44a 100 }
terryfan 1:57cd3ae5f44a 101
terryfan 2:18b496a20413 102 void displayThread(void const *args)
terryfan 2:18b496a20413 103 {
terryfan 2:18b496a20413 104 ///////////////////////////////////////////////////////////////////////////
terryfan 2:18b496a20413 105 ///////////////////////////////////////////////////////////////////////////
terryfan 2:18b496a20413 106 //////////////////////////////need to implement heart_beats counts in code
terryfan 2:18b496a20413 107 ///////////////////////////////////////////////////////////////////////////
terryfan 2:18b496a20413 108 ///////////////////////////////////////////////////////////////////////////
terryfan 2:18b496a20413 109 while (1) {
terryfan 2:18b496a20413 110 Thread::wait(observation_interval);
terryfan 2:18b496a20413 111 lcd.cls();
terryfan 2:18b496a20413 112
terryfan 2:18b496a20413 113 hr_mutex.lock();
terryfan 2:18b496a20413 114 int hr = (heart_beats*60) / (observation_interval / 1000);
terryfan 2:18b496a20413 115 heart_beats = 0;
terryfan 2:18b496a20413 116 hr_mutex.unlock();
terryfan 2:18b496a20413 117
terryfan 2:18b496a20413 118 lcd.printf("%s%d%s","HR: ", hr, " bpm");
terryfan 2:18b496a20413 119 }
terryfan 2:18b496a20413 120 }
terryfan 2:18b496a20413 121
terryfan 0:da581483b90d 122 void test_vrp_vv(FILE * results, Timer * ti)
terryfan 0:da581483b90d 123 {
terryfan 0:da581483b90d 124 int vrpwait = vrp/2;
terryfan 0:da581483b90d 125 int adifu,vdifu,difl = 0;
terryfan 0:da581483b90d 126 fprintf(results, " Test VRP VV\n\n Time Action\n");
terryfan 0:da581483b90d 127 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 128 apace_led = 1;
terryfan 0:da581483b90d 129 Thread::wait(twait);
terryfan 0:da581483b90d 130 apace_led = 0;
terryfan 0:da581483b90d 131 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 132 ti->reset();
terryfan 0:da581483b90d 133 vpace_led = 1;
terryfan 0:da581483b90d 134 Thread::wait(twait);
terryfan 0:da581483b90d 135 vpace_led = 0;
terryfan 0:da581483b90d 136
terryfan 2:18b496a20413 137
terryfan 0:da581483b90d 138 Thread::wait(vrpwait);
terryfan 0:da581483b90d 139 vsignal = 1;
terryfan 0:da581483b90d 140 vsignal_led = 1;
terryfan 0:da581483b90d 141 fprintf(results, "%6d%8s\n", ti->read_ms(), "VS");
terryfan 0:da581483b90d 142 Thread::wait(twait);
terryfan 0:da581483b90d 143 vsignal_led = 0;
terryfan 0:da581483b90d 144 vsignal = 0;
terryfan 0:da581483b90d 145
terryfan 2:18b496a20413 146
terryfan 0:da581483b90d 147 Thread::wait(vrpwait);
terryfan 0:da581483b90d 148 vsignal = 1;
terryfan 0:da581483b90d 149 difl = ti->read_us();
terryfan 0:da581483b90d 150 vsignal_led = 1;
terryfan 0:da581483b90d 151 fprintf(results, "%6d%8s\n", ti->read_ms(), "VS");
terryfan 0:da581483b90d 152 Thread::wait(twait);
terryfan 0:da581483b90d 153 vsignal = 0;
terryfan 0:da581483b90d 154 vsignal_led = 0;
terryfan 0:da581483b90d 155
terryfan 2:18b496a20413 156
terryfan 0:da581483b90d 157 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 158 adifu = ti->read_us();
terryfan 0:da581483b90d 159 apace_led = 1;
terryfan 0:da581483b90d 160 fprintf(results, "%6d%8s\n", ti->read_ms(), "AP");
terryfan 0:da581483b90d 161 Thread::wait(twait);
terryfan 0:da581483b90d 162 apace_led = 0;
terryfan 0:da581483b90d 163
terryfan 2:18b496a20413 164
terryfan 0:da581483b90d 165 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 166 vdifu = ti->read_us();
terryfan 0:da581483b90d 167 vpace_led = 1;
terryfan 0:da581483b90d 168 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 169 Thread::wait(twait);
terryfan 0:da581483b90d 170 vpace_led = 0;
terryfan 0:da581483b90d 171
terryfan 2:18b496a20413 172
terryfan 0:da581483b90d 173 int adif = adifu-difl;
terryfan 0:da581483b90d 174 int vdif = vdifu-difl;
terryfan 0:da581483b90d 175 const char * res = ((adif >= ((lri-avi)*1000 - thrsh)) &&
terryfan 0:da581483b90d 176 (adif < ((lri-avi)*1000 + thrsh)) &&
terryfan 0:da581483b90d 177 (vdif >= (lri*1000 - thrsh)) &&
terryfan 0:da581483b90d 178 (vdif < (lri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 179
terryfan 2:18b496a20413 180
terryfan 0:da581483b90d 181 fprintf(results, "\nResult: %s %d %d\n\n", res, adif, vdif);
terryfan 0:da581483b90d 182
terryfan 2:18b496a20413 183
terryfan 0:da581483b90d 184 }
terryfan 0:da581483b90d 185 void test_pvarp_aa(FILE * results, Timer * ti)
terryfan 0:da581483b90d 186 {
terryfan 0:da581483b90d 187 int pvarpwait = pvarp/2;
terryfan 0:da581483b90d 188 int vdifu = 0;
terryfan 0:da581483b90d 189 fprintf(results, " Test PVARP AA\n\n Time Action\n");
terryfan 0:da581483b90d 190 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 191 apace_led = 1;
terryfan 0:da581483b90d 192 Thread::wait(twait);
terryfan 0:da581483b90d 193 apace_led = 0;
terryfan 0:da581483b90d 194 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 195 ti->reset();
terryfan 0:da581483b90d 196 vpace_led = 1;
terryfan 0:da581483b90d 197 Thread::wait(twait);
terryfan 0:da581483b90d 198 vpace_led = 0;
terryfan 0:da581483b90d 199
terryfan 2:18b496a20413 200
terryfan 0:da581483b90d 201 Thread::wait(pvarpwait);
terryfan 0:da581483b90d 202 asignal = 1;
terryfan 0:da581483b90d 203 asignal_led = 1;
terryfan 0:da581483b90d 204 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 205 Thread::wait(twait);
terryfan 0:da581483b90d 206 asignal_led = 0;
terryfan 0:da581483b90d 207 asignal = 0;
terryfan 0:da581483b90d 208
terryfan 2:18b496a20413 209
terryfan 0:da581483b90d 210 Thread::wait(pvarpwait);
terryfan 0:da581483b90d 211 asignal = 1;
terryfan 0:da581483b90d 212 //difl = ti->read_us();
terryfan 0:da581483b90d 213 asignal_led = 1;
terryfan 0:da581483b90d 214 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 215 Thread::wait(twait);
terryfan 0:da581483b90d 216 asignal_led = 0;
terryfan 0:da581483b90d 217 asignal = 0;
terryfan 0:da581483b90d 218
terryfan 2:18b496a20413 219
terryfan 0:da581483b90d 220 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 221 vdifu = ti->read_us();
terryfan 0:da581483b90d 222 vpace_led = 1;
terryfan 0:da581483b90d 223 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 224 Thread::wait(twait);
terryfan 0:da581483b90d 225 vpace_led = 0;
terryfan 0:da581483b90d 226
terryfan 2:18b496a20413 227
terryfan 0:da581483b90d 228 int vdif = vdifu;
terryfan 0:da581483b90d 229 const char * res = ((vdif >= (uri*1000 - thrsh)) &&
terryfan 0:da581483b90d 230 (vdif < (uri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 231
terryfan 2:18b496a20413 232
terryfan 0:da581483b90d 233 fprintf(results, "\nResult: %s %d\n\n", res, vdif);
terryfan 0:da581483b90d 234 }
terryfan 0:da581483b90d 235
terryfan 2:18b496a20413 236
terryfan 0:da581483b90d 237 void test_pvarp_arp_aaa(FILE * results, Timer * ti)
terryfan 0:da581483b90d 238 {
terryfan 0:da581483b90d 239 int arpwait = arp/2;
terryfan 0:da581483b90d 240 int vdifu = 0;
terryfan 0:da581483b90d 241 fprintf(results, "Test PVARP ARP AAA\n\n Time Action\n");
terryfan 0:da581483b90d 242 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 243 apace_led = 1;
terryfan 0:da581483b90d 244 Thread::wait(twait);
terryfan 0:da581483b90d 245 apace_led = 0;
terryfan 0:da581483b90d 246 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 247 ti->reset();
terryfan 0:da581483b90d 248 vpace_led = 1;
terryfan 0:da581483b90d 249 Thread::wait(twait);
terryfan 0:da581483b90d 250 vpace_led = 0;
terryfan 0:da581483b90d 251
terryfan 2:18b496a20413 252
terryfan 0:da581483b90d 253 Thread::wait(pvarp);
terryfan 0:da581483b90d 254 asignal = 1;
terryfan 0:da581483b90d 255 asignal_led = 1;
terryfan 0:da581483b90d 256 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 257 Thread::wait(twait);
terryfan 0:da581483b90d 258 asignal_led = 0;
terryfan 0:da581483b90d 259 asignal = 0;
terryfan 0:da581483b90d 260
terryfan 2:18b496a20413 261
terryfan 0:da581483b90d 262 Thread::wait(arpwait);
terryfan 0:da581483b90d 263 asignal = 1;
terryfan 0:da581483b90d 264 asignal_led = 1;
terryfan 0:da581483b90d 265 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 266 Thread::wait(twait);
terryfan 0:da581483b90d 267 asignal_led = 0;
terryfan 0:da581483b90d 268 asignal = 0;
terryfan 0:da581483b90d 269
terryfan 2:18b496a20413 270
terryfan 0:da581483b90d 271 Thread::wait(arpwait);
terryfan 0:da581483b90d 272 asignal = 1;
terryfan 0:da581483b90d 273 asignal_led = 1;
terryfan 0:da581483b90d 274 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 275 Thread::wait(twait);
terryfan 0:da581483b90d 276 asignal_led = 0;
terryfan 0:da581483b90d 277 asignal = 0;
terryfan 0:da581483b90d 278
terryfan 2:18b496a20413 279
terryfan 0:da581483b90d 280 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 281 vdifu = ti->read_us();
terryfan 0:da581483b90d 282 vpace_led = 1;
terryfan 0:da581483b90d 283 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 284 Thread::wait(twait);
terryfan 0:da581483b90d 285 vpace_led = 0;
terryfan 0:da581483b90d 286
terryfan 2:18b496a20413 287
terryfan 0:da581483b90d 288 int vdif = vdifu;
terryfan 0:da581483b90d 289 const char * res = ((vdif >= (uri*1000 - thrsh)) &&
terryfan 0:da581483b90d 290 (vdif < (uri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 291
terryfan 2:18b496a20413 292
terryfan 0:da581483b90d 293 fprintf(results, "\nResult: %s %d\n\n", res, vdif);
terryfan 0:da581483b90d 294 }
terryfan 0:da581483b90d 295
terryfan 2:18b496a20413 296
terryfan 0:da581483b90d 297 void test_pvarp_arp_aav(FILE * results, Timer * ti)
terryfan 0:da581483b90d 298 {
terryfan 0:da581483b90d 299 int adifu,vdifu,difl = 0;
terryfan 0:da581483b90d 300 fprintf(results, "Test PVARP ARP AAV\n\n Time Action\n");
terryfan 0:da581483b90d 301 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 302 apace_led = 1;
terryfan 0:da581483b90d 303 Thread::wait(twait);
terryfan 0:da581483b90d 304 apace_led = 0;
terryfan 0:da581483b90d 305 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 306 ti->reset();
terryfan 0:da581483b90d 307 vpace_led = 1;
terryfan 0:da581483b90d 308 Thread::wait(twait);
terryfan 0:da581483b90d 309 vpace_led = 0;
terryfan 0:da581483b90d 310
terryfan 2:18b496a20413 311
terryfan 0:da581483b90d 312 Thread::wait(pvarp);
terryfan 0:da581483b90d 313 asignal = 1;
terryfan 0:da581483b90d 314 asignal_led = 1;
terryfan 0:da581483b90d 315 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 316 Thread::wait(twait);
terryfan 0:da581483b90d 317 asignal_led = 0;
terryfan 0:da581483b90d 318 asignal = 0;
terryfan 0:da581483b90d 319
terryfan 2:18b496a20413 320
terryfan 0:da581483b90d 321 Thread::wait(arp);
terryfan 0:da581483b90d 322 asignal = 1;
terryfan 0:da581483b90d 323 asignal_led = 1;
terryfan 0:da581483b90d 324 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 325 Thread::wait(twait);
terryfan 0:da581483b90d 326 asignal_led = 0;
terryfan 0:da581483b90d 327 asignal = 0;
terryfan 0:da581483b90d 328
terryfan 2:18b496a20413 329
terryfan 0:da581483b90d 330 Thread::wait(20);
terryfan 0:da581483b90d 331 vsignal = 1;
terryfan 0:da581483b90d 332 difl = ti->read_us();
terryfan 0:da581483b90d 333 vsignal_led = 1;
terryfan 0:da581483b90d 334 fprintf(results, "%6d%8s\n", ti->read_ms(), "VS");
terryfan 0:da581483b90d 335 Thread::wait(twait);
terryfan 0:da581483b90d 336 vsignal = 0;
terryfan 0:da581483b90d 337 vsignal_led = 0;
terryfan 0:da581483b90d 338
terryfan 2:18b496a20413 339
terryfan 0:da581483b90d 340 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 341 adifu = ti->read_us();
terryfan 0:da581483b90d 342 apace_led = 1;
terryfan 0:da581483b90d 343 fprintf(results, "%6d%8s\n", ti->read_ms(), "AP");
terryfan 0:da581483b90d 344 Thread::wait(twait);
terryfan 0:da581483b90d 345 apace_led = 0;
terryfan 0:da581483b90d 346
terryfan 2:18b496a20413 347
terryfan 0:da581483b90d 348 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 349 vdifu = ti->read_us();
terryfan 0:da581483b90d 350 vpace_led = 1;
terryfan 0:da581483b90d 351 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 352 Thread::wait(twait);
terryfan 0:da581483b90d 353 vpace_led = 0;
terryfan 0:da581483b90d 354
terryfan 2:18b496a20413 355
terryfan 0:da581483b90d 356 int adif = adifu-difl;
terryfan 0:da581483b90d 357 int vdif = vdifu-difl;
terryfan 0:da581483b90d 358 const char * res = ((adif >= ((lri-avi)*1000 - thrsh)) &&
terryfan 0:da581483b90d 359 (adif < ((lri-avi)*1000 + thrsh)) &&
terryfan 0:da581483b90d 360 (vdif >= (lri*1000 - thrsh)) &&
terryfan 0:da581483b90d 361 (vdif < (lri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 362
terryfan 2:18b496a20413 363
terryfan 0:da581483b90d 364 fprintf(results, "\nResult: %s %d %d\n\n", res, adif, vdif);
terryfan 0:da581483b90d 365
terryfan 2:18b496a20413 366
terryfan 0:da581483b90d 367 }
terryfan 0:da581483b90d 368
terryfan 2:18b496a20413 369
terryfan 0:da581483b90d 370 void test_vpace_after_a(FILE * results, Timer * ti)
terryfan 0:da581483b90d 371 {
terryfan 0:da581483b90d 372 int vdifu = 0;
terryfan 0:da581483b90d 373 fprintf(results, "Test VPACE After A\n\n Time Action\n");
terryfan 0:da581483b90d 374 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 375 apace_led = 1;
terryfan 0:da581483b90d 376 Thread::wait(twait);
terryfan 0:da581483b90d 377 apace_led = 0;
terryfan 0:da581483b90d 378 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 379 ti->reset();
terryfan 0:da581483b90d 380 vpace_led = 1;
terryfan 0:da581483b90d 381 Thread::wait(twait);
terryfan 0:da581483b90d 382 vpace_led = 0;
terryfan 0:da581483b90d 383
terryfan 2:18b496a20413 384
terryfan 0:da581483b90d 385 Thread::wait(pvarp);
terryfan 0:da581483b90d 386 asignal = 1;
terryfan 0:da581483b90d 387 asignal_led = 1;
terryfan 0:da581483b90d 388 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 389 Thread::wait(twait);
terryfan 0:da581483b90d 390 asignal_led = 0;
terryfan 0:da581483b90d 391 asignal = 0;
terryfan 0:da581483b90d 392
terryfan 2:18b496a20413 393
terryfan 0:da581483b90d 394 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 395 vdifu = ti->read_us();
terryfan 0:da581483b90d 396 vpace_led = 1;
terryfan 0:da581483b90d 397 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 398 Thread::wait(twait);
terryfan 0:da581483b90d 399 vpace_led = 0;
terryfan 0:da581483b90d 400
terryfan 2:18b496a20413 401
terryfan 0:da581483b90d 402 int vdif = vdifu;
terryfan 0:da581483b90d 403 const char * res = ((vdif >= (uri*1000 - thrsh)) &&
terryfan 0:da581483b90d 404 (vdif < (uri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 405
terryfan 2:18b496a20413 406
terryfan 0:da581483b90d 407 fprintf(results, "\nResult: %s %d\n\n", res, vdif);
terryfan 0:da581483b90d 408 }
terryfan 0:da581483b90d 409
terryfan 2:18b496a20413 410
terryfan 0:da581483b90d 411 void test_apace_vpace_av(FILE * results, Timer * ti)
terryfan 0:da581483b90d 412 {
terryfan 0:da581483b90d 413 fprintf(results, "Test APACE After V\n\n Time Action\n");
terryfan 0:da581483b90d 414 int adifu,vdifu = 0;
terryfan 0:da581483b90d 415 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 416 apace_led = 1;
terryfan 0:da581483b90d 417 Thread::wait(twait);
terryfan 0:da581483b90d 418 apace_led = 0;
terryfan 0:da581483b90d 419 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 420 ti->reset();
terryfan 0:da581483b90d 421 vpace_led = 1;
terryfan 0:da581483b90d 422 Thread::wait(twait);
terryfan 0:da581483b90d 423 vpace_led = 0;
terryfan 0:da581483b90d 424
terryfan 2:18b496a20413 425
terryfan 0:da581483b90d 426 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 427 adifu = ti->read_us();
terryfan 0:da581483b90d 428 apace_led = 1;
terryfan 0:da581483b90d 429 fprintf(results, "%6d%8s\n", ti->read_ms(), "AP");
terryfan 0:da581483b90d 430 Thread::wait(twait);
terryfan 0:da581483b90d 431 apace_led = 0;
terryfan 0:da581483b90d 432
terryfan 2:18b496a20413 433
terryfan 0:da581483b90d 434 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 435 vdifu = ti->read_us();
terryfan 0:da581483b90d 436 vpace_led = 1;
terryfan 0:da581483b90d 437 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 438 Thread::wait(twait);
terryfan 0:da581483b90d 439 vpace_led = 0;
terryfan 0:da581483b90d 440
terryfan 2:18b496a20413 441
terryfan 0:da581483b90d 442 int adif = adifu;
terryfan 0:da581483b90d 443 int vdif = vdifu;
terryfan 0:da581483b90d 444 const char * res = ((adif >= ((lri-avi)*1000 - thrsh)) &&
terryfan 0:da581483b90d 445 (adif < ((lri-avi)*1000 + thrsh)) &&
terryfan 0:da581483b90d 446 (vdif >= (lri*1000 - thrsh)) &&
terryfan 0:da581483b90d 447 (vdif < (lri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 448
terryfan 2:18b496a20413 449
terryfan 0:da581483b90d 450 fprintf(results, "\nResult: %s %d %d\n\n", res, adif, vdif);
terryfan 0:da581483b90d 451 }
terryfan 0:da581483b90d 452
terryfan 2:18b496a20413 453
terryfan 0:da581483b90d 454 void test_avi_a(FILE * results, Timer * ti)
terryfan 0:da581483b90d 455 {
terryfan 0:da581483b90d 456 int vdifu,difl = 0;
terryfan 0:da581483b90d 457 fprintf(results, " Test AVI\n\n Time Action\n");
terryfan 0:da581483b90d 458 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 459 apace_led = 1;
terryfan 0:da581483b90d 460 Thread::wait(twait);
terryfan 0:da581483b90d 461 apace_led = 0;
terryfan 0:da581483b90d 462 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 463 ti->reset();
terryfan 0:da581483b90d 464 vpace_led = 1;
terryfan 0:da581483b90d 465 Thread::wait(twait);
terryfan 0:da581483b90d 466 vpace_led = 0;
terryfan 0:da581483b90d 467
terryfan 2:18b496a20413 468
terryfan 0:da581483b90d 469 Thread::wait(uri);
terryfan 0:da581483b90d 470 asignal = 1;
terryfan 0:da581483b90d 471 difl = ti->read_us();
terryfan 0:da581483b90d 472 asignal_led = 1;
terryfan 0:da581483b90d 473 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 474 Thread::wait(twait);
terryfan 0:da581483b90d 475 asignal_led = 0;
terryfan 0:da581483b90d 476 asignal = 0;
terryfan 0:da581483b90d 477
terryfan 2:18b496a20413 478
terryfan 0:da581483b90d 479 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 480 vdifu = ti->read_us();
terryfan 0:da581483b90d 481 vpace_led = 1;
terryfan 0:da581483b90d 482 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 483 Thread::wait(twait);
terryfan 0:da581483b90d 484 vpace_led = 0;
terryfan 0:da581483b90d 485
terryfan 2:18b496a20413 486
terryfan 0:da581483b90d 487 int vpc = (avi*1000) + difl;
terryfan 0:da581483b90d 488 const char * res = ((vpc >= (vdifu - thrsh)) &&
terryfan 0:da581483b90d 489 (vpc < (vdifu + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 490
terryfan 2:18b496a20413 491
terryfan 0:da581483b90d 492 fprintf(results, "\nResult: %s %d\n\n", res, vpc);
terryfan 0:da581483b90d 493
terryfan 2:18b496a20413 494
terryfan 0:da581483b90d 495 }
terryfan 0:da581483b90d 496
terryfan 2:18b496a20413 497
terryfan 0:da581483b90d 498 void test_uri_a(FILE * results, Timer * ti)
terryfan 0:da581483b90d 499 {
terryfan 0:da581483b90d 500 int vdifu = 0;
terryfan 0:da581483b90d 501 fprintf(results, " Test URI\n\n Time Action\n");
terryfan 0:da581483b90d 502 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 503 apace_led = 1;
terryfan 0:da581483b90d 504 Thread::wait(twait);
terryfan 0:da581483b90d 505 apace_led = 0;
terryfan 0:da581483b90d 506 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 507 ti->reset();
terryfan 0:da581483b90d 508 vpace_led = 1;
terryfan 0:da581483b90d 509 Thread::wait(twait);
terryfan 0:da581483b90d 510 vpace_led = 0;
terryfan 0:da581483b90d 511
terryfan 2:18b496a20413 512
terryfan 0:da581483b90d 513 Thread::wait(pvarp);
terryfan 0:da581483b90d 514 asignal = 1;
terryfan 0:da581483b90d 515 asignal_led = 1;
terryfan 0:da581483b90d 516 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 517 Thread::wait(twait);
terryfan 0:da581483b90d 518 asignal_led = 0;
terryfan 0:da581483b90d 519 asignal = 0;
terryfan 0:da581483b90d 520
terryfan 2:18b496a20413 521
terryfan 0:da581483b90d 522 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 523 vdifu = ti->read_us();
terryfan 0:da581483b90d 524 vpace_led = 1;
terryfan 0:da581483b90d 525 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 526 Thread::wait(twait);
terryfan 0:da581483b90d 527 vpace_led = 0;
terryfan 0:da581483b90d 528
terryfan 2:18b496a20413 529
terryfan 0:da581483b90d 530 int vdif = vdifu;
terryfan 0:da581483b90d 531 const char * res = ((vdif >= (uri*1000 - thrsh)) &&
terryfan 0:da581483b90d 532 (vdif < (uri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 533
terryfan 2:18b496a20413 534
terryfan 0:da581483b90d 535 fprintf(results, "\nResult: %s %d\n\n", res, vdif);
terryfan 0:da581483b90d 536
terryfan 2:18b496a20413 537
terryfan 0:da581483b90d 538 }
terryfan 0:da581483b90d 539
terryfan 2:18b496a20413 540
terryfan 0:da581483b90d 541 void test_normal_10(FILE * results, Timer * ti)
terryfan 0:da581483b90d 542 {
terryfan 0:da581483b90d 543 fprintf(results, " Test Normal x10\n\n Time Action\n");
terryfan 0:da581483b90d 544 int adifu,vdifu,difl,i = 0;
terryfan 0:da581483b90d 545 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 546 apace_led = 1;
terryfan 0:da581483b90d 547 Thread::wait(twait);
terryfan 0:da581483b90d 548 apace_led = 0;
terryfan 0:da581483b90d 549 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 550 ti->reset();
terryfan 0:da581483b90d 551 vpace_led = 1;
terryfan 0:da581483b90d 552 Thread::wait(twait);
terryfan 0:da581483b90d 553 vpace_led = 0;
terryfan 0:da581483b90d 554
terryfan 2:18b496a20413 555
terryfan 0:da581483b90d 556 while(i < 10) {
terryfan 0:da581483b90d 557 Thread::wait(pvarp);
terryfan 0:da581483b90d 558 asignal = 1;
terryfan 0:da581483b90d 559 asignal_led = 1;
terryfan 0:da581483b90d 560 fprintf(results, "%6d%8s\n", ti->read_ms(), "AS");
terryfan 0:da581483b90d 561 Thread::wait(twait);
terryfan 0:da581483b90d 562 asignal_led = 0;
terryfan 0:da581483b90d 563 asignal = 0;
terryfan 0:da581483b90d 564
terryfan 2:18b496a20413 565
terryfan 0:da581483b90d 566 Thread::wait(75);
terryfan 0:da581483b90d 567 vsignal = 1;
terryfan 0:da581483b90d 568 difl = ti->read_us();
terryfan 0:da581483b90d 569 vsignal_led = 1;
terryfan 0:da581483b90d 570 fprintf(results, "%6d%8s\n", ti->read_ms(), "VS");
terryfan 0:da581483b90d 571 Thread::wait(twait);
terryfan 0:da581483b90d 572 vsignal = 0;
terryfan 0:da581483b90d 573 vsignal_led = 0;
terryfan 0:da581483b90d 574 i = i+1;
terryfan 0:da581483b90d 575 }
terryfan 0:da581483b90d 576
terryfan 2:18b496a20413 577
terryfan 0:da581483b90d 578 osSignalWait(0x10, osWaitForever);
terryfan 0:da581483b90d 579 adifu = ti->read_us();
terryfan 0:da581483b90d 580 apace_led = 1;
terryfan 0:da581483b90d 581 fprintf(results, "%6d%8s\n", ti->read_ms(), "AP");
terryfan 0:da581483b90d 582 Thread::wait(twait);
terryfan 0:da581483b90d 583 apace_led = 0;
terryfan 0:da581483b90d 584
terryfan 2:18b496a20413 585
terryfan 0:da581483b90d 586 osSignalWait(0x1, osWaitForever);
terryfan 0:da581483b90d 587 vdifu = ti->read_us();
terryfan 0:da581483b90d 588 vpace_led = 1;
terryfan 0:da581483b90d 589 fprintf(results, "%6d%8s\n", ti->read_ms(), "VP");
terryfan 0:da581483b90d 590 Thread::wait(twait);
terryfan 0:da581483b90d 591 vpace_led = 0;
terryfan 0:da581483b90d 592
terryfan 2:18b496a20413 593
terryfan 0:da581483b90d 594 int adif = adifu - difl;
terryfan 0:da581483b90d 595 int vdif = vdifu - difl;
terryfan 0:da581483b90d 596 const char * res = ((adif >= ((lri-avi)*1000 - thrsh)) &&
terryfan 0:da581483b90d 597 (adif < ((lri-avi)*1000 + thrsh)) &&
terryfan 0:da581483b90d 598 (vdif >= (lri*1000 - thrsh)) &&
terryfan 0:da581483b90d 599 (vdif < (lri*1000 + thrsh))) ? "Passed": "Failed";
terryfan 0:da581483b90d 600
terryfan 2:18b496a20413 601
terryfan 0:da581483b90d 602 fprintf(results, "\nResult: %s %d %d\n\n", res, adif, vdif);
terryfan 0:da581483b90d 603 }
terryfan 0:da581483b90d 604
terryfan 2:18b496a20413 605
terryfan 0:da581483b90d 606 void testmode(void const *args)
terryfan 0:da581483b90d 607 {
terryfan 0:da581483b90d 608 Timer *t;
terryfan 1:57cd3ae5f44a 609 testresults = fopen("/local/testreport.txt", "w"); // Open "out.txt" on the local file system for writing
terryfan 0:da581483b90d 610 t = new Timer();
terryfan 0:da581483b90d 611 t->start();
terryfan 0:da581483b90d 612
terryfan 2:18b496a20413 613
terryfan 0:da581483b90d 614 test_vrp_vv(testresults, t);
terryfan 0:da581483b90d 615 test_pvarp_aa(testresults, t);
terryfan 0:da581483b90d 616 test_pvarp_arp_aaa(testresults, t);
terryfan 0:da581483b90d 617 test_pvarp_arp_aav(testresults, t);
terryfan 0:da581483b90d 618 test_vpace_after_a(testresults, t);
terryfan 0:da581483b90d 619 test_apace_vpace_av(testresults, t);
terryfan 0:da581483b90d 620 test_avi_a(testresults, t);
terryfan 0:da581483b90d 621 test_uri_a(testresults, t);
terryfan 0:da581483b90d 622 test_normal_10(testresults, t);
terryfan 0:da581483b90d 623 fclose(testresults);
terryfan 0:da581483b90d 624 }
terryfan 0:da581483b90d 625
terryfan 0:da581483b90d 626
terryfan 2:18b496a20413 627
terryfan 2:18b496a20413 628
terryfan 0:da581483b90d 629 void randommode(void const *args)
terryfan 0:da581483b90d 630 {
terryfan 0:da581483b90d 631 int aorv,sig = 0;
terryfan 0:da581483b90d 632 Timer at,vt;
terryfan 0:da581483b90d 633
terryfan 2:18b496a20413 634
terryfan 0:da581483b90d 635 at.start();
terryfan 0:da581483b90d 636 vt.start();
terryfan 0:da581483b90d 637
terryfan 2:18b496a20413 638
terryfan 0:da581483b90d 639 //osEvent ext_signal = osSignalWait(0, 1);
terryfan 0:da581483b90d 640 //int evt = ext_signal.value.signals;
terryfan 0:da581483b90d 641 //osSignalSet(heartmodeTid, 0x1);
terryfan 0:da581483b90d 642 //osSignalWait(0, osWaitForever);
terryfan 0:da581483b90d 643 while(heartmode == 0) {
terryfan 0:da581483b90d 644 aorv = (float)(rand()%2);
terryfan 0:da581483b90d 645 sig = aorv ? rand()%(lri - avi - at.read_ms()) : rand()%(lri - vt.read_ms());
terryfan 0:da581483b90d 646
terryfan 2:18b496a20413 647
terryfan 0:da581483b90d 648 osEvent ext_signal = osSignalWait(0, sig);
terryfan 0:da581483b90d 649 int evt = ext_signal.value.signals;
terryfan 0:da581483b90d 650
terryfan 2:18b496a20413 651
terryfan 0:da581483b90d 652 switch(evt) {
terryfan 0:da581483b90d 653 case(0x0):
terryfan 0:da581483b90d 654 if(aorv) {
terryfan 0:da581483b90d 655 asignal = 1;
terryfan 0:da581483b90d 656 asignal_led = 1;
terryfan 0:da581483b90d 657 Thread::wait(twait);
terryfan 0:da581483b90d 658 asignal_led = 0;
terryfan 0:da581483b90d 659 asignal = 0;
terryfan 0:da581483b90d 660 break;
terryfan 0:da581483b90d 661 } else {
terryfan 0:da581483b90d 662 vsignal = 1;
terryfan 0:da581483b90d 663 at.reset();
terryfan 0:da581483b90d 664 vt.reset();
terryfan 0:da581483b90d 665 vsignal_led = 1;
terryfan 0:da581483b90d 666 Thread::wait(twait);
terryfan 0:da581483b90d 667 vsignal_led = 0;
terryfan 0:da581483b90d 668 vsignal = 0;
terryfan 0:da581483b90d 669 break;
terryfan 0:da581483b90d 670 }
terryfan 0:da581483b90d 671 case(0x1):
terryfan 0:da581483b90d 672 at.reset();
terryfan 0:da581483b90d 673 vt.reset();
terryfan 0:da581483b90d 674 vpace_led = 1;
terryfan 0:da581483b90d 675 Thread::wait(twait);
terryfan 0:da581483b90d 676 vpace_led = 0;
terryfan 0:da581483b90d 677 break;
terryfan 0:da581483b90d 678
terryfan 2:18b496a20413 679
terryfan 0:da581483b90d 680 case(0x10):
terryfan 0:da581483b90d 681 apace_led = 1;
terryfan 0:da581483b90d 682 Thread::wait(twait);
terryfan 0:da581483b90d 683 apace_led = 0;
terryfan 0:da581483b90d 684 break;
terryfan 1:57cd3ae5f44a 685
terryfan 2:18b496a20413 686
terryfan 1:57cd3ae5f44a 687 // case(0x100):
terryfan 1:57cd3ae5f44a 688 //
terryfan 0:da581483b90d 689 }
terryfan 0:da581483b90d 690 }
terryfan 0:da581483b90d 691 }
terryfan 0:da581483b90d 692
terryfan 2:18b496a20413 693
terryfan 1:57cd3ae5f44a 694 void manualmode(void const *args)
terryfan 1:57cd3ae5f44a 695 {
terryfan 1:57cd3ae5f44a 696 while(1) {
terryfan 1:57cd3ae5f44a 697 osEvent evt = signal_q.get();
terryfan 1:57cd3ae5f44a 698 if(evt.status == osEventMessage) {
terryfan 1:57cd3ae5f44a 699 if((char)evt.value.p == 'a') {
terryfan 1:57cd3ae5f44a 700 asignal = 1;
terryfan 1:57cd3ae5f44a 701 asignal_led = 1;
terryfan 1:57cd3ae5f44a 702 Thread::wait(twait);
terryfan 1:57cd3ae5f44a 703 asignal_led = 0;
terryfan 1:57cd3ae5f44a 704 asignal = 0;
terryfan 1:57cd3ae5f44a 705 } else if((char)evt.value.p == 'v') {
terryfan 1:57cd3ae5f44a 706 vsignal = 1;
terryfan 1:57cd3ae5f44a 707 vsignal_led = 1;
terryfan 1:57cd3ae5f44a 708 Thread::wait(twait);
terryfan 1:57cd3ae5f44a 709 vsignal = 0;
terryfan 1:57cd3ae5f44a 710 vsignal_led = 0;
terryfan 1:57cd3ae5f44a 711 }
terryfan 1:57cd3ae5f44a 712 }
terryfan 1:57cd3ae5f44a 713 }
terryfan 1:57cd3ae5f44a 714 }
terryfan 0:da581483b90d 715
terryfan 0:da581483b90d 716
terryfan 2:18b496a20413 717 void obsinterval()
terryfan 2:18b496a20413 718 {
terryfan 2:18b496a20413 719 char newObsInt[8];
terryfan 2:18b496a20413 720 int isChangingObsInt = 1;
terryfan 2:18b496a20413 721 int i = 0;
terryfan 2:18b496a20413 722 while(isChangingObsInt) {
terryfan 2:18b496a20413 723 osEvent evt = obsint_q.get();
terryfan 2:18b496a20413 724 if(evt.status == osEventMessage) {
terryfan 2:18b496a20413 725 key = (char)evt.value.p;
terryfan 2:18b496a20413 726 if(key != '\r' && i < 7 ){
terryfan 2:18b496a20413 727 newObsInt[i] = key;
terryfan 2:18b496a20413 728 i++;
terryfan 2:18b496a20413 729 } else if((key == '\r') && (i > 0)) {
terryfan 2:18b496a20413 730 int obsint;
terryfan 2:18b496a20413 731 newObsInt[i] = '\0';
terryfan 2:18b496a20413 732 sscanf(newObsInt, "%d", &obsint);
terryfan 2:18b496a20413 733 observation_interval = (obsint > 0 ) ? obsint: 1;
terryfan 2:18b496a20413 734 isChangingObsInt = 0;
terryfan 2:18b496a20413 735 //lcd.printf("%d", observation_interval);
terryfan 2:18b496a20413 736 }
terryfan 2:18b496a20413 737 }
terryfan 2:18b496a20413 738 }
terryfan 2:18b496a20413 739 }
terryfan 1:57cd3ae5f44a 740 osThreadDef(randommode, osPriorityNormal, DEFAULT_STACK_SIZE);
terryfan 0:da581483b90d 741 osThreadDef(testmode, osPriorityNormal, DEFAULT_STACK_SIZE);
terryfan 1:57cd3ae5f44a 742 osThreadDef(manualmode, osPriorityNormal, DEFAULT_STACK_SIZE);
terryfan 1:57cd3ae5f44a 743
terryfan 2:18b496a20413 744
terryfan 0:da581483b90d 745 int main()
terryfan 0:da581483b90d 746 {
terryfan 0:da581483b90d 747 vpace.rise(&vpace_irq);
terryfan 0:da581483b90d 748 apace.rise(&apace_irq);
terryfan 0:da581483b90d 749
terryfan 2:18b496a20413 750
terryfan 1:57cd3ae5f44a 751 pc.attach(&Rx_interrupt, RawSerial::RxIrq);
terryfan 2:18b496a20413 752
terryfan 2:18b496a20413 753
terryfan 0:da581483b90d 754 //heartmodeThread = new Thread();
terryfan 2:18b496a20413 755
terryfan 0:da581483b90d 756 //Callback<void()> testmodeTask((void*)NULL,(void (*)(void *))&testmode);
terryfan 0:da581483b90d 757
terryfan 2:18b496a20413 758
terryfan 1:57cd3ae5f44a 759 heartmodeTid = osThreadCreate(osThread(randommode), NULL);
terryfan 1:57cd3ae5f44a 760 // heartmodeTid = osThreadCreate(osThread(testmode), NULL);
terryfan 1:57cd3ae5f44a 761 // heartmodeTid = osThreadCreate(osThread(manualmode), NULL);
terryfan 2:18b496a20413 762
terryfan 0:da581483b90d 763 // lcd.printf();
terryfan 0:da581483b90d 764 while(true) {
terryfan 1:57cd3ae5f44a 765 // while(pc.readable()) {
terryfan 1:57cd3ae5f44a 766 // key = pc.getc();
terryfan 1:57cd3ae5f44a 767 osEvent evt = mode_q.get();
terryfan 1:57cd3ae5f44a 768 if(evt.status == osEventMessage) {
terryfan 1:57cd3ae5f44a 769 switch((char)evt.value.p) {
terryfan 0:da581483b90d 770 //pvarp = 0.3s
terryfan 0:da581483b90d 771 case('r'):
terryfan 0:da581483b90d 772 lcd.printf("R");
terryfan 1:57cd3ae5f44a 773 // randommode.terminate();
terryfan 1:57cd3ae5f44a 774 osThreadTerminate (heartmodeTid);
terryfan 1:57cd3ae5f44a 775 if (testresults != NULL) {
terryfan 1:57cd3ae5f44a 776 fclose(testresults);
terryfan 1:57cd3ae5f44a 777 }
terryfan 1:57cd3ae5f44a 778 asignal_led = 0;
terryfan 1:57cd3ae5f44a 779 vsignal_led = 0;
terryfan 1:57cd3ae5f44a 780 apace_led = 0;
terryfan 1:57cd3ae5f44a 781 vpace_led = 0;
terryfan 1:57cd3ae5f44a 782
terryfan 2:18b496a20413 783
terryfan 1:57cd3ae5f44a 784 heartmodeTid = osThreadCreate(osThread(randommode), NULL);
terryfan 0:da581483b90d 785 // Thread::wait(100);
terryfan 0:da581483b90d 786 break;
terryfan 0:da581483b90d 787 case('t'):
terryfan 0:da581483b90d 788 lcd.printf("T");
terryfan 1:57cd3ae5f44a 789 osThreadTerminate (heartmodeTid);
terryfan 1:57cd3ae5f44a 790 if (testresults != NULL) {
terryfan 1:57cd3ae5f44a 791 fclose(testresults);
terryfan 1:57cd3ae5f44a 792 }
terryfan 1:57cd3ae5f44a 793 asignal_led = 0;
terryfan 1:57cd3ae5f44a 794 vsignal_led = 0;
terryfan 1:57cd3ae5f44a 795 apace_led = 0;
terryfan 1:57cd3ae5f44a 796 vpace_led = 0;
terryfan 1:57cd3ae5f44a 797
terryfan 2:18b496a20413 798
terryfan 1:57cd3ae5f44a 799 heartmodeTid = osThreadCreate(osThread(testmode), NULL);
terryfan 0:da581483b90d 800 break;
terryfan 0:da581483b90d 801 case('m'):
terryfan 0:da581483b90d 802 lcd.printf("M");
terryfan 1:57cd3ae5f44a 803 osThreadTerminate (heartmodeTid);
terryfan 1:57cd3ae5f44a 804 if (testresults != NULL) {
terryfan 1:57cd3ae5f44a 805 fclose(testresults);
terryfan 1:57cd3ae5f44a 806 }
terryfan 1:57cd3ae5f44a 807 asignal_led = 0;
terryfan 1:57cd3ae5f44a 808 vsignal_led = 0;
terryfan 1:57cd3ae5f44a 809 apace_led = 0;
terryfan 1:57cd3ae5f44a 810 vpace_led = 0;
terryfan 1:57cd3ae5f44a 811
terryfan 2:18b496a20413 812
terryfan 1:57cd3ae5f44a 813 heartmodeTid = osThreadCreate(osThread(manualmode), NULL);
terryfan 0:da581483b90d 814 manual_mode = 1;
terryfan 0:da581483b90d 815
terryfan 2:18b496a20413 816
terryfan 0:da581483b90d 817 break;
terryfan 0:da581483b90d 818 case('o'):
terryfan 2:18b496a20413 819 lcd.printf("modeO");
terryfan 2:18b496a20413 820 obsinterval();
terryfan 0:da581483b90d 821 break;
terryfan 0:da581483b90d 822 }
terryfan 0:da581483b90d 823 }
terryfan 0:da581483b90d 824 }
terryfan 0:da581483b90d 825 }