Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD mbed-rtos mbed
PMTest.cpp
00001 #include "mbed.h" 00002 #include "LPC17xx.h" 00003 #include "TextLCD.h" 00004 #include "rtos.h" 00005 #include "Thread.h" 00006 00007 DigitalOut vsense(p23); 00008 DigitalOut asense(p24); 00009 DigitalIn apace(p22); 00010 DigitalIn vpace(p21); 00011 00012 Ticker rate_monitor; 00013 00014 00015 TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7 00016 00017 volatile int beats = 0; 00018 volatile double bpm = 0; 00019 00020 DigitalOut led_apace(LED1); 00021 DigitalOut led_vpace(LED2); 00022 DigitalOut led_asense(LED3); 00023 DigitalOut led_vsense(LED4); 00024 00025 Serial serial_in(USBTX, USBRX); 00026 00027 00028 int test_time_count; 00029 int curr_test; 00030 int minwaitV = 200; 00031 int minwaitA = 400; 00032 00033 int obs_int = 10; 00034 00035 00036 int needs_num_input = 0; 00037 00038 enum mode {RANDOM,MANUAL,TEST}; 00039 mode test_curr_mode = RANDOM; 00040 Timer t; 00041 00042 00043 void test_LRI(){ 00044 Timer test_timer; 00045 00046 test_timer.start(); 00047 // wait for next vpace 00048 while(vpace != 1){} 00049 serial_in.printf("LRI: The separation between Ventricle events was %i ", test_timer.read_ms()); 00050 00051 } 00052 00053 void test_PVARP(){ 00054 Timer test_timer; 00055 00056 test_timer.start(); 00057 00058 while(apace != 1){} 00059 serial_in.printf("PVARP: The separation between Ventricular and Atrial events was %i ", test_timer.read_ms()); 00060 00061 00062 } 00063 00064 void test_VRP(){ 00065 Timer test_timer; 00066 00067 test_timer.start(); 00068 00069 while(vpace != 1 && vsense != 1){} 00070 serial_in.printf("VRP: The separation between Ventricle events was %i ", test_timer.read_ms()); 00071 00072 00073 } 00074 00075 00076 void test_AVI(){ 00077 Timer test_timer; 00078 00079 test_timer.start(); 00080 00081 while(vpace != 1){} 00082 serial_in.printf("AVI: The separation between Atrial and Ventricle events was %i ", test_timer.read_ms()); 00083 00084 00085 } 00086 00087 void test_AVI2(){ 00088 Timer test_timer; 00089 00090 test_timer.start(); 00091 00092 while(apace != 1){} 00093 serial_in.printf("LRI-AVI: The separation between Ventricle and Atrial events was %i ", test_timer.read_ms()); 00094 00095 00096 } 00097 00098 00099 00100 00101 void random_heart(void const *args) 00102 { 00103 t.reset(); 00104 t.start(); 00105 while(1){ 00106 while(test_curr_mode == RANDOM) { 00107 int r = rand(); 00108 if(r%2 == 0) { 00109 if(t.read_ms() > minwaitA) { 00110 led_asense = 1; 00111 asense = 1; 00112 Thread::wait(10); 00113 asense = 0; 00114 led_asense = 0; 00115 t.reset(); 00116 00117 }else{ 00118 Thread::wait(100); 00119 } 00120 } else { 00121 if(t.read_ms() > minwaitV) { 00122 led_vsense = 1; 00123 vsense = 1; 00124 Thread::wait(10); 00125 vsense = 0; 00126 beats++; 00127 led_vsense = 0; 00128 t.reset(); 00129 00130 }else{ 00131 Thread::wait(100); 00132 } 00133 } 00134 00135 Thread::wait(150); 00136 00137 00138 00139 } 00140 } 00141 } 00142 00143 void pm_beat_update(void const *args){ 00144 while(1){ 00145 lcd.locate(0,0); 00146 lcd.printf("BPM: %.1f ", bpm); 00147 } 00148 } 00149 00150 00151 void kbd_intrp() 00152 { 00153 00154 char a = serial_in.getc(); 00155 serial_in.printf("char was " + a); 00156 if(needs_num_input) { 00157 // DO O handling 00158 needs_num_input = 0; 00159 return; 00160 } 00161 00162 if(a == 'R') { 00163 test_curr_mode = RANDOM; 00164 } else if(a == 'T') { 00165 test_curr_mode = TEST; 00166 } else if(a == 'M') { 00167 test_curr_mode = MANUAL; 00168 } 00169 00170 if(a == 'A' && test_curr_mode == MANUAL) { 00171 asense = 1; 00172 Thread::wait(10); 00173 asense = 0; 00174 } 00175 00176 if(a == 'V' && test_curr_mode == MANUAL) { 00177 vsense = 1; 00178 Thread::wait(10); 00179 vsense = 0; 00180 } 00181 00182 } 00183 00184 void rec_apace(){ 00185 led_apace = 1; 00186 Thread::wait(10); 00187 led_apace = 0; 00188 } 00189 00190 void rec_vpace(){ 00191 led_vpace = 1; 00192 Thread::wait(10); 00193 led_vpace = 0; 00194 } 00195 00196 void heart_response1(void const *args){ 00197 while(1){ 00198 if(apace == 1){ 00199 rec_apace(); 00200 } 00201 00202 } 00203 00204 } 00205 00206 void heart_response2(void const *args){ 00207 while(1){ 00208 00209 if(vpace == 1){ 00210 rec_vpace(); 00211 } 00212 } 00213 00214 } 00215 00216 // interrupt function 00217 void interrupt_and_run_test() 00218 { 00219 test_curr_mode = TEST; 00220 serial_in.printf("--BEGIN TEST--"); 00221 while(vpace != 1){} 00222 while(vpace == 1){} 00223 test_LRI(); 00224 while(vpace != 1){} 00225 while(vpace == 1){} 00226 test_PVARP(); 00227 while(vpace != 1){} 00228 while(vpace == 1){} 00229 test_VRP(); 00230 while(apace != 1){} 00231 while(apace == 1){} 00232 test_AVI(); 00233 serial_in.printf("--END TEST--"); 00234 test_curr_mode = RANDOM; 00235 } 00236 00237 void update_display() { 00238 bpm = beats / (double) obs_int * 60; 00239 //reset count 00240 beats = 0; 00241 } 00242 00243 int main(void) 00244 { 00245 00246 00247 00248 00249 Thread t3(random_heart, (void *)""); 00250 Thread t2(heart_response1, (void *)""); 00251 Thread t4(heart_response2, (void *)""); 00252 Thread t5(pm_beat_update, (void *)""); 00253 00254 rate_monitor.attach(&update_display, obs_int); 00255 char a = 'Z'; 00256 00257 00258 while(1) { 00259 00260 if(serial_in.readable()) { 00261 a = serial_in.getc(); 00262 serial_in.printf("GOT %c!!",a); 00263 00264 if (needs_num_input) { 00265 if (a >= '0' && a <= '9') { 00266 // update observation interval 00267 obs_int = (a - '0' + 1) * 5; 00268 needs_num_input = 0; 00269 rate_monitor.attach(&update_display, obs_int); 00270 serial_in.printf("Set observation interval to %d seconds\n", obs_int); 00271 } else { 00272 serial_in.printf("Expected numeric key\n"); 00273 } 00274 } 00275 00276 if(a == 'R') { 00277 serial_in.printf("GOT R!!"); 00278 test_curr_mode = RANDOM; 00279 } else if(a == 'T') { 00280 serial_in.printf("GOT T!!"); 00281 test_curr_mode = TEST; 00282 interrupt_and_run_test(); 00283 00284 } else if(a == 'M') { 00285 serial_in.printf("GOT M!!"); 00286 test_curr_mode = MANUAL; 00287 } 00288 else if(a == 'O') { 00289 serial_in.printf("GOT obs!!"); 00290 needs_num_input = 1; 00291 } 00292 00293 if(a == 'A' && test_curr_mode == MANUAL) { 00294 asense = 1; 00295 led_asense = 1; 00296 Thread::wait(10); 00297 led_asense = 0; 00298 asense = 0; 00299 } 00300 00301 if(a == 'V' && test_curr_mode == MANUAL) { 00302 vsense = 1; 00303 led_vsense = 1; 00304 Thread::wait(10); 00305 led_vsense = 0; 00306 vsense = 0; 00307 } 00308 00309 while(serial_in.readable()){ 00310 serial_in.printf("GOT TO CONSUME!!",a); 00311 serial_in.getc(); 00312 } 00313 00314 00315 } 00316 } 00317 00318 00319 }
Generated on Wed Aug 3 2022 09:04:35 by
1.7.2