![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Part of the Pacemaker Project; this models the Pacemaker.
Dependencies: mbed TextLCD mbed-rtos
PacemakerController.cpp@36:03704a3ec2e3, 2015-12-02 (annotated)
- Committer:
- amiche
- Date:
- Wed Dec 02 04:52:19 2015 +0000
- Revision:
- 36:03704a3ec2e3
- Parent:
- 33:b68c1648206e
Add mode changes for LRI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chadnach1 | 0:d92e0b71c6b5 | 1 | #include "mbed.h" |
lucastai | 2:5e9c4d83d038 | 2 | #include "LPC17xx.h" |
lucastai | 2:5e9c4d83d038 | 3 | #include "TextLCD.h" |
lucastai | 2:5e9c4d83d038 | 4 | #include "rtos.h" |
lucastai | 2:5e9c4d83d038 | 5 | #include "Thread.h" |
lucastai | 2:5e9c4d83d038 | 6 | using namespace rtos; |
chadnach1 | 0:d92e0b71c6b5 | 7 | |
chadnach1 | 0:d92e0b71c6b5 | 8 | // This is for the pacemaker |
lucastai | 2:5e9c4d83d038 | 9 | volatile unsigned short timer_count; |
lucastai | 2:5e9c4d83d038 | 10 | Serial pc(USBTX, USBRX); |
lucastai | 2:5e9c4d83d038 | 11 | TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7 |
lucastai | 2:5e9c4d83d038 | 12 | |
mhowar | 5:9eee15818b0e | 13 | int keyboard_needs_numeric = 0; // boolean - is in middle of interval input? |
chadnach1 | 0:d92e0b71c6b5 | 14 | |
chadnach1 | 0:d92e0b71c6b5 | 15 | int h_clock; |
amiche | 3:44d132582373 | 16 | int pm_clock; |
chadnach1 | 27:2c5aefcf3000 | 17 | Timer avi_clk; |
chadnach1 | 32:c58b6651336c | 18 | Timer t_count; |
chadnach1 | 0:d92e0b71c6b5 | 19 | |
chadnach1 | 4:f04eb7f96f4b | 20 | int LRI = 1000; |
chadnach1 | 4:f04eb7f96f4b | 21 | int AVI = 150; |
chadnach1 | 4:f04eb7f96f4b | 22 | int PVARP = 300; |
chadnach1 | 4:f04eb7f96f4b | 23 | int VRP = 200; |
lucastai | 2:5e9c4d83d038 | 24 | |
lucastai | 2:5e9c4d83d038 | 25 | // constants |
lucastai | 2:5e9c4d83d038 | 26 | int MAX_PM_RT = 180; |
lucastai | 2:5e9c4d83d038 | 27 | int MIN_PM_RT = 40; |
lucastai | 2:5e9c4d83d038 | 28 | enum mode {NORMAL, SLEEP, EXERCISE, MANUAL}; |
lucastai | 2:5e9c4d83d038 | 29 | |
lucastai | 2:5e9c4d83d038 | 30 | // counters |
lucastai | 2:5e9c4d83d038 | 31 | int beats = 0; |
lucastai | 2:5e9c4d83d038 | 32 | |
lucastai | 2:5e9c4d83d038 | 33 | // state variables |
lucastai | 2:5e9c4d83d038 | 34 | int upper_bound = 100; |
lucastai | 2:5e9c4d83d038 | 35 | int lower_bound = 40; |
lucastai | 2:5e9c4d83d038 | 36 | int obs_int = 10; |
lucastai | 2:5e9c4d83d038 | 37 | mode curr_mode = NORMAL; |
lucastai | 2:5e9c4d83d038 | 38 | |
amiche | 19:f3615321b5c4 | 39 | // alarms |
lucastai | 14:a16b636c2bbc | 40 | DigitalOut led_apace(LED1); |
lucastai | 14:a16b636c2bbc | 41 | DigitalOut led_vpace(LED2); |
chadnach1 | 33:b68c1648206e | 42 | DigitalOut led_asense(LED3); |
chadnach1 | 33:b68c1648206e | 43 | DigitalOut led_vsense(LED4); |
lucastai | 2:5e9c4d83d038 | 44 | |
chadnach1 | 27:2c5aefcf3000 | 45 | DigitalIn agetSignal(p24); |
chadnach1 | 27:2c5aefcf3000 | 46 | DigitalIn vgetSignal(p23); |
chadnach1 | 27:2c5aefcf3000 | 47 | DigitalOut apaceSignal(p22); |
chadnach1 | 27:2c5aefcf3000 | 48 | DigitalOut vpaceSignal(p21); |
chadnach1 | 27:2c5aefcf3000 | 49 | |
chadnach1 | 27:2c5aefcf3000 | 50 | bool v_sense; |
chadnach1 | 27:2c5aefcf3000 | 51 | bool a_sense; |
chadnach1 | 27:2c5aefcf3000 | 52 | |
chadnach1 | 27:2c5aefcf3000 | 53 | void asense() |
chadnach1 | 27:2c5aefcf3000 | 54 | { |
chadnach1 | 27:2c5aefcf3000 | 55 | a_sense = 1; |
chadnach1 | 33:b68c1648206e | 56 | led_asense = 1; |
chadnach1 | 30:97db5a684eaa | 57 | lcd.printf("asense fired\n"); |
chadnach1 | 27:2c5aefcf3000 | 58 | Thread::wait(10); |
chadnach1 | 33:b68c1648206e | 59 | led_asense = 0; |
chadnach1 | 27:2c5aefcf3000 | 60 | a_sense = 0; |
chadnach1 | 27:2c5aefcf3000 | 61 | } |
lucastai | 18:d4cd9d12345e | 62 | |
chadnach1 | 27:2c5aefcf3000 | 63 | void vsense() |
chadnach1 | 27:2c5aefcf3000 | 64 | { |
chadnach1 | 27:2c5aefcf3000 | 65 | v_sense = 1; |
chadnach1 | 33:b68c1648206e | 66 | led_vsense = 1; |
chadnach1 | 30:97db5a684eaa | 67 | lcd.printf("vssense fired\n"); |
chadnach1 | 27:2c5aefcf3000 | 68 | Thread::wait(10); |
chadnach1 | 33:b68c1648206e | 69 | led_vsense = 0; |
chadnach1 | 27:2c5aefcf3000 | 70 | v_sense = 0; |
chadnach1 | 27:2c5aefcf3000 | 71 | } |
chadnach1 | 27:2c5aefcf3000 | 72 | |
chadnach1 | 27:2c5aefcf3000 | 73 | void apace() |
chadnach1 | 27:2c5aefcf3000 | 74 | { |
chadnach1 | 27:2c5aefcf3000 | 75 | |
chadnach1 | 30:97db5a684eaa | 76 | lcd.printf("apace fired\n"); |
chadnach1 | 27:2c5aefcf3000 | 77 | apaceSignal = 1; |
chadnach1 | 27:2c5aefcf3000 | 78 | led_apace = 1; |
chadnach1 | 27:2c5aefcf3000 | 79 | Thread::wait(10); |
chadnach1 | 33:b68c1648206e | 80 | led_apace = 0; |
chadnach1 | 27:2c5aefcf3000 | 81 | apaceSignal = 0; |
chadnach1 | 27:2c5aefcf3000 | 82 | |
chadnach1 | 27:2c5aefcf3000 | 83 | } |
chadnach1 | 27:2c5aefcf3000 | 84 | |
chadnach1 | 27:2c5aefcf3000 | 85 | void vpace() |
chadnach1 | 27:2c5aefcf3000 | 86 | { |
chadnach1 | 30:97db5a684eaa | 87 | lcd.printf("vpace fired\n"); |
chadnach1 | 27:2c5aefcf3000 | 88 | vpaceSignal = 1; |
chadnach1 | 27:2c5aefcf3000 | 89 | led_vpace = 1; |
chadnach1 | 27:2c5aefcf3000 | 90 | Thread::wait(10); |
chadnach1 | 33:b68c1648206e | 91 | led_vpace = 0; |
chadnach1 | 27:2c5aefcf3000 | 92 | vpaceSignal = 0; |
chadnach1 | 27:2c5aefcf3000 | 93 | |
chadnach1 | 27:2c5aefcf3000 | 94 | } |
amiche | 24:81cd9ef5c4f6 | 95 | |
lucastai | 2:5e9c4d83d038 | 96 | // hardware interrupt handler, adapted from code in piazza post by Dagaen |
chadnach1 | 33:b68c1648206e | 97 | /*extern "C" void TIMER0_IRQHandler (void) |
lucastai | 2:5e9c4d83d038 | 98 | { |
amiche | 19:f3615321b5c4 | 99 | if((LPC_TIM0->IR & 0x01) == 0x01) { // if MR0 interrupt, proceed |
amiche | 19:f3615321b5c4 | 100 | LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag |
amiche | 19:f3615321b5c4 | 101 | timer_count++; //increment timer_count |
lucastai | 2:5e9c4d83d038 | 102 | } |
lucastai | 2:5e9c4d83d038 | 103 | } |
chadnach1 | 33:b68c1648206e | 104 | */ |
chadnach1 | 33:b68c1648206e | 105 | /*// init the hardware interrupt (timer0), adapted same as above |
lucastai | 2:5e9c4d83d038 | 106 | void timer0_init(void) |
lucastai | 2:5e9c4d83d038 | 107 | { |
lucastai | 2:5e9c4d83d038 | 108 | LPC_SC->PCONP |=1<1; //timer0 power on |
lucastai | 2:5e9c4d83d038 | 109 | LPC_SC-> PCLKSEL0 |= 1 << 2; // set timer clock to CCLCK nondivided (1 clock cycle = 1 increment) |
lucastai | 2:5e9c4d83d038 | 110 | LPC_TIM0->MR0 = 1000000; //100mhz clock cycle, 1 cycle = 10ns, 10ms = 10 000 000 ns = 1M cycles |
lucastai | 2:5e9c4d83d038 | 111 | LPC_TIM0->MCR = 3; //interrupt and reset control |
amiche | 19:f3615321b5c4 | 112 | //3 = Interrupt & reset timer0 on match (111) sets all three bits |
lucastai | 2:5e9c4d83d038 | 113 | NVIC_EnableIRQ(TIMER0_IRQn); //enable timer0 interrupt |
chadnach1 | 33:b68c1648206e | 114 | }*/ |
chadnach1 | 0:d92e0b71c6b5 | 115 | |
lucastai | 2:5e9c4d83d038 | 116 | |
chadnach1 | 27:2c5aefcf3000 | 117 | void PM_ALARM(void const *args) |
amiche | 19:f3615321b5c4 | 118 | { |
chadnach1 | 29:5cec671cb80d | 119 | while (1) { |
chadnach1 | 29:5cec671cb80d | 120 | // min hr alarm |
chadnach1 | 29:5cec671cb80d | 121 | if( beats < MIN_PM_RT) { |
chadnach1 | 30:97db5a684eaa | 122 | lcd.cls(); |
chadnach1 | 29:5cec671cb80d | 123 | lcd.locate(0,1); |
chadnach1 | 30:97db5a684eaa | 124 | lcd.printf("!<\n"); |
chadnach1 | 29:5cec671cb80d | 125 | } |
chadnach1 | 31:7f0e865e3d4b | 126 | |
chadnach1 | 29:5cec671cb80d | 127 | // max hr alarm |
chadnach1 | 29:5cec671cb80d | 128 | if(beats > MAX_PM_RT) { |
chadnach1 | 30:97db5a684eaa | 129 | lcd.cls(); |
chadnach1 | 29:5cec671cb80d | 130 | lcd.locate(0,1); |
chadnach1 | 30:97db5a684eaa | 131 | lcd.printf("!>\n"); |
chadnach1 | 29:5cec671cb80d | 132 | } |
amiche | 19:f3615321b5c4 | 133 | } |
amiche | 19:f3615321b5c4 | 134 | |
chadnach1 | 0:d92e0b71c6b5 | 135 | } |
chadnach1 | 0:d92e0b71c6b5 | 136 | |
lucastai | 2:5e9c4d83d038 | 137 | // hw interrupt callback, deal with the keyboard input from PC |
lucastai | 2:5e9c4d83d038 | 138 | |
chadnach1 | 27:2c5aefcf3000 | 139 | void pm_sense(void const *args) |
amiche | 19:f3615321b5c4 | 140 | { |
amiche | 19:f3615321b5c4 | 141 | |
chadnach1 | 4:f04eb7f96f4b | 142 | while(1) { |
chadnach1 | 30:97db5a684eaa | 143 | //lcd.locate(0,1); |
chadnach1 | 30:97db5a684eaa | 144 | //lcd.printf("in pmsense\n"); |
chadnach1 | 32:c58b6651336c | 145 | |
chadnach1 | 33:b68c1648206e | 146 | /*if (agetSignal == 0) { |
chadnach1 | 33:b68c1648206e | 147 | pc.printf("Aget:LO\n"); |
chadnach1 | 33:b68c1648206e | 148 | } |
chadnach1 | 33:b68c1648206e | 149 | |
chadnach1 | 33:b68c1648206e | 150 | if (vgetSignal == 0) { |
chadnach1 | 33:b68c1648206e | 151 | pc.printf("Vget:LO\n"); |
chadnach1 | 33:b68c1648206e | 152 | } |
chadnach1 | 33:b68c1648206e | 153 | if (agetSignal == 1) { |
chadnach1 | 33:b68c1648206e | 154 | pc.printf("Aget:HI\n"); |
chadnach1 | 33:b68c1648206e | 155 | } |
chadnach1 | 33:b68c1648206e | 156 | |
chadnach1 | 33:b68c1648206e | 157 | if (vgetSignal == 1) { |
chadnach1 | 33:b68c1648206e | 158 | pc.printf("Vget:HI\n"); |
chadnach1 | 33:b68c1648206e | 159 | }*/ |
chadnach1 | 33:b68c1648206e | 160 | |
amiche | 19:f3615321b5c4 | 161 | |
chadnach1 | 33:b68c1648206e | 162 | if (t_count.read_ms() >= VRP && vgetSignal == 1) { |
chadnach1 | 32:c58b6651336c | 163 | lcd.printf("valid v state\n"); |
chadnach1 | 32:c58b6651336c | 164 | pc.printf("valid v state\n"); |
chadnach1 | 32:c58b6651336c | 165 | //Thread::wait(2); |
amiche | 24:81cd9ef5c4f6 | 166 | // Valid_V state |
amiche | 24:81cd9ef5c4f6 | 167 | |
chadnach1 | 32:c58b6651336c | 168 | t_count.reset(); |
chadnach1 | 33:b68c1648206e | 169 | //t_count.start(); |
amiche | 24:81cd9ef5c4f6 | 170 | vsense(); |
amiche | 19:f3615321b5c4 | 171 | // do something with Vsense! |
amiche | 24:81cd9ef5c4f6 | 172 | |
chadnach1 | 33:b68c1648206e | 173 | } else if (t_count.read_ms() < VRP && vgetSignal == 1) { |
chadnach1 | 32:c58b6651336c | 174 | lcd.printf("invalid v state\n"); |
chadnach1 | 32:c58b6651336c | 175 | pc.printf("invalid v state\n"); |
chadnach1 | 33:b68c1648206e | 176 | //pc.printf("%d\n",t_count.read()); |
chadnach1 | 32:c58b6651336c | 177 | |
chadnach1 | 33:b68c1648206e | 178 | //t_count.start(); |
chadnach1 | 32:c58b6651336c | 179 | |
chadnach1 | 32:c58b6651336c | 180 | //Thread::wait(2); |
chadnach1 | 20:dc272bfaa276 | 181 | // Invalid_V state |
chadnach1 | 4:f04eb7f96f4b | 182 | } |
amiche | 19:f3615321b5c4 | 183 | |
chadnach1 | 33:b68c1648206e | 184 | if (t_count.read_ms() < PVARP && agetSignal == 1) { |
chadnach1 | 20:dc272bfaa276 | 185 | // Invalid_A state |
chadnach1 | 32:c58b6651336c | 186 | lcd.printf("invalid a state\n"); |
chadnach1 | 32:c58b6651336c | 187 | pc.printf("invalid a state\n"); |
chadnach1 | 33:b68c1648206e | 188 | // pc.printf("%d\n",t_count.read()); |
chadnach1 | 33:b68c1648206e | 189 | //t_count.start(); |
chadnach1 | 32:c58b6651336c | 190 | |
chadnach1 | 32:c58b6651336c | 191 | //Thread::wait(2); |
chadnach1 | 33:b68c1648206e | 192 | } else if (t_count.read_ms() >= PVARP && agetSignal == 1) { |
chadnach1 | 20:dc272bfaa276 | 193 | // Valid_A state |
chadnach1 | 32:c58b6651336c | 194 | lcd.printf("valid a state\n"); |
chadnach1 | 32:c58b6651336c | 195 | pc.printf("valid a state\n"); |
chadnach1 | 32:c58b6651336c | 196 | //Thread::wait(2); |
chadnach1 | 33:b68c1648206e | 197 | //t_count.start(); |
amiche | 24:81cd9ef5c4f6 | 198 | asense(); |
chadnach1 | 4:f04eb7f96f4b | 199 | // do something with Asense! |
chadnach1 | 4:f04eb7f96f4b | 200 | } |
amiche | 19:f3615321b5c4 | 201 | |
chadnach1 | 4:f04eb7f96f4b | 202 | } |
amiche | 3:44d132582373 | 203 | } |
amiche | 3:44d132582373 | 204 | |
chadnach1 | 27:2c5aefcf3000 | 205 | void pm_response(void const *args) |
amiche | 19:f3615321b5c4 | 206 | { |
chadnach1 | 4:f04eb7f96f4b | 207 | while(1) { |
chadnach1 | 30:97db5a684eaa | 208 | //lcd.cls(); |
chadnach1 | 33:b68c1648206e | 209 | lcd.printf("in response\n"); |
chadnach1 | 33:b68c1648206e | 210 | pc.printf("in response %d\n", t_count.read()); |
chadnach1 | 27:2c5aefcf3000 | 211 | bool goInitalState = 1; |
chadnach1 | 33:b68c1648206e | 212 | if (t_count.read_ms() >= LRI - AVI) { |
chadnach1 | 33:b68c1648206e | 213 | |
chadnach1 | 30:97db5a684eaa | 214 | //lcd.cls(); |
chadnach1 | 32:c58b6651336c | 215 | //lcd.printf("t_count.reasd() >= LRI-AVI\n"); |
chadnach1 | 27:2c5aefcf3000 | 216 | goInitalState = 0; |
amiche | 19:f3615321b5c4 | 217 | // PM_A! sets the LED high |
chadnach1 | 33:b68c1648206e | 218 | pc.printf("in pmresponse"); |
amiche | 19:f3615321b5c4 | 219 | led_apace = 1; |
amiche | 19:f3615321b5c4 | 220 | |
amiche | 19:f3615321b5c4 | 221 | // avi_clk = 0 |
amiche | 19:f3615321b5c4 | 222 | avi_clk.reset(); |
amiche | 19:f3615321b5c4 | 223 | |
amiche | 19:f3615321b5c4 | 224 | apace(); |
amiche | 19:f3615321b5c4 | 225 | // At Atrial Event State |
chadnach1 | 33:b68c1648206e | 226 | while (avi_clk.read_ms() < AVI) { |
chadnach1 | 30:97db5a684eaa | 227 | //lcd.cls(); |
chadnach1 | 30:97db5a684eaa | 228 | //lcd.printf("avi_clk.read() < AVI\n"); |
chadnach1 | 27:2c5aefcf3000 | 229 | if (v_sense == 1) { |
chadnach1 | 27:2c5aefcf3000 | 230 | goInitalState = 1; |
amiche | 24:81cd9ef5c4f6 | 231 | break; |
amiche | 24:81cd9ef5c4f6 | 232 | } |
amiche | 24:81cd9ef5c4f6 | 233 | } |
chadnach1 | 27:2c5aefcf3000 | 234 | if (!goInitalState) { |
amiche | 24:81cd9ef5c4f6 | 235 | // Ventricular Event |
chadnach1 | 32:c58b6651336c | 236 | t_count.reset(); |
amiche | 19:f3615321b5c4 | 237 | |
amiche | 24:81cd9ef5c4f6 | 238 | // PM_V! sets the LED high |
amiche | 24:81cd9ef5c4f6 | 239 | led_vpace = 1; |
amiche | 19:f3615321b5c4 | 240 | |
chadnach1 | 32:c58b6651336c | 241 | t_count.reset(); |
chadnach1 | 33:b68c1648206e | 242 | pc.printf("in pmresponse 2"); |
amiche | 24:81cd9ef5c4f6 | 243 | vpace(); |
amiche | 24:81cd9ef5c4f6 | 244 | } |
chadnach1 | 33:b68c1648206e | 245 | } else if (t_count.read_ms() < LRI - AVI) { |
chadnach1 | 31:7f0e865e3d4b | 246 | //lcd.cls(); |
chadnach1 | 32:c58b6651336c | 247 | //lcd.printf("t_count.read() < LRI - AVI\n"); |
amiche | 24:81cd9ef5c4f6 | 248 | // if Asense, move on to atrial event |
chadnach1 | 27:2c5aefcf3000 | 249 | if (a_sense == 1) { |
chadnach1 | 27:2c5aefcf3000 | 250 | goInitalState = 0; |
chadnach1 | 31:7f0e865e3d4b | 251 | |
amiche | 24:81cd9ef5c4f6 | 252 | // avi_clk = 0 |
amiche | 24:81cd9ef5c4f6 | 253 | avi_clk.reset(); |
amiche | 19:f3615321b5c4 | 254 | |
amiche | 24:81cd9ef5c4f6 | 255 | // At Atrial Event State |
amiche | 24:81cd9ef5c4f6 | 256 | while (avi_clk.read() < AVI) { |
chadnach1 | 27:2c5aefcf3000 | 257 | if (v_sense == 1) { |
chadnach1 | 27:2c5aefcf3000 | 258 | goInitalState = 1; |
amiche | 24:81cd9ef5c4f6 | 259 | break; |
amiche | 24:81cd9ef5c4f6 | 260 | } |
amiche | 24:81cd9ef5c4f6 | 261 | } |
amiche | 19:f3615321b5c4 | 262 | |
amiche | 24:81cd9ef5c4f6 | 263 | // Ventricular Event |
chadnach1 | 32:c58b6651336c | 264 | t_count.reset(); |
amiche | 24:81cd9ef5c4f6 | 265 | |
amiche | 24:81cd9ef5c4f6 | 266 | // PM_V! sets the LED high |
amiche | 24:81cd9ef5c4f6 | 267 | led_vpace = 1; |
amiche | 24:81cd9ef5c4f6 | 268 | |
chadnach1 | 32:c58b6651336c | 269 | t_count.reset(); |
amiche | 24:81cd9ef5c4f6 | 270 | vpace(); |
amiche | 24:81cd9ef5c4f6 | 271 | } |
amiche | 19:f3615321b5c4 | 272 | } |
amiche | 19:f3615321b5c4 | 273 | } |
amiche | 3:44d132582373 | 274 | } |
lucastai | 2:5e9c4d83d038 | 275 | |
amiche | 19:f3615321b5c4 | 276 | int main() |
amiche | 19:f3615321b5c4 | 277 | { |
chadnach1 | 16:ae9df4194011 | 278 | // https://developer.mbed.org/users/chadnach1/code/PacemakerController/ |
lucastai | 2:5e9c4d83d038 | 279 | // connect the serial device (PC keybd) to the interrupt |
chadnach1 | 31:7f0e865e3d4b | 280 | //pc.attach(&keyboard_handler); |
chadnach1 | 30:97db5a684eaa | 281 | lcd.printf("in main\n"); |
amiche | 19:f3615321b5c4 | 282 | |
chadnach1 | 16:ae9df4194011 | 283 | // Start LED's Off |
chadnach1 | 17:c89cddf30925 | 284 | led_apace = 0; |
chadnach1 | 17:c89cddf30925 | 285 | led_vpace = 0; |
amiche | 19:f3615321b5c4 | 286 | |
chadnach1 | 16:ae9df4194011 | 287 | // Start the avi_clock |
chadnach1 | 16:ae9df4194011 | 288 | avi_clk.start(); |
chadnach1 | 33:b68c1648206e | 289 | avi_clk.reset(); |
amiche | 19:f3615321b5c4 | 290 | |
chadnach1 | 30:97db5a684eaa | 291 | Thread t1(pm_sense, (void *)""); |
chadnach1 | 30:97db5a684eaa | 292 | Thread t2(pm_response, (void *)""); |
chadnach1 | 31:7f0e865e3d4b | 293 | Thread t3(PM_ALARM, (void *)""); |
chadnach1 | 33:b68c1648206e | 294 | t_count.start(); |
chadnach1 | 33:b68c1648206e | 295 | t_count.reset(); |
chadnach1 | 33:b68c1648206e | 296 | //pc.printf("PM CLOCK time isss %d\n",t_count.read_ms()); |
chadnach1 | 33:b68c1648206e | 297 | // pc.printf("AVI CLK %d\n",avi_clk.read_ms()); |
chadnach1 | 31:7f0e865e3d4b | 298 | |
chadnach1 | 31:7f0e865e3d4b | 299 | char a = 'Z'; |
chadnach1 | 31:7f0e865e3d4b | 300 | while(1) { |
chadnach1 | 33:b68c1648206e | 301 | |
chadnach1 | 33:b68c1648206e | 302 | |
chadnach1 | 33:b68c1648206e | 303 | |
chadnach1 | 31:7f0e865e3d4b | 304 | if (pc.readable()) { |
chadnach1 | 31:7f0e865e3d4b | 305 | |
chadnach1 | 31:7f0e865e3d4b | 306 | a = pc.getc(); |
chadnach1 | 31:7f0e865e3d4b | 307 | |
chadnach1 | 31:7f0e865e3d4b | 308 | // Handle different keyboard inputs |
chadnach1 | 31:7f0e865e3d4b | 309 | |
chadnach1 | 31:7f0e865e3d4b | 310 | if (a >= '0' && a <= '9') { |
chadnach1 | 31:7f0e865e3d4b | 311 | // update observation interval |
chadnach1 | 31:7f0e865e3d4b | 312 | obs_int = (a - '0' + 1) * 5; |
chadnach1 | 31:7f0e865e3d4b | 313 | } else { |
chadnach1 | 31:7f0e865e3d4b | 314 | lcd.printf("MODE IS N\n"); |
chadnach1 | 31:7f0e865e3d4b | 315 | pc.printf("Expected numeric key\n"); |
chadnach1 | 31:7f0e865e3d4b | 316 | } |
chadnach1 | 31:7f0e865e3d4b | 317 | } else if(a == 'N') { |
chadnach1 | 31:7f0e865e3d4b | 318 | // if the char is N, update bounds to normal mode |
chadnach1 | 31:7f0e865e3d4b | 319 | curr_mode = NORMAL; |
chadnach1 | 31:7f0e865e3d4b | 320 | upper_bound = 100; |
amiche | 36:03704a3ec2e3 | 321 | LRI = 100; |
chadnach1 | 31:7f0e865e3d4b | 322 | lower_bound = 40; |
chadnach1 | 31:7f0e865e3d4b | 323 | lcd.printf("MODE IS N\n"); |
chadnach1 | 31:7f0e865e3d4b | 324 | pc.printf("MODE IS N\n"); |
chadnach1 | 31:7f0e865e3d4b | 325 | // if the char is S, set bounds to sleep |
chadnach1 | 31:7f0e865e3d4b | 326 | } else if (a == 'S') { |
chadnach1 | 31:7f0e865e3d4b | 327 | curr_mode = SLEEP; |
chadnach1 | 31:7f0e865e3d4b | 328 | upper_bound = 60; |
amiche | 36:03704a3ec2e3 | 329 | LRI = 60; |
chadnach1 | 31:7f0e865e3d4b | 330 | lower_bound = 30; |
chadnach1 | 31:7f0e865e3d4b | 331 | lcd.printf("MODE IS S\n"); |
chadnach1 | 31:7f0e865e3d4b | 332 | pc.printf("MODE IS S\n"); |
chadnach1 | 31:7f0e865e3d4b | 333 | // if the char is E, set bounds to exercise |
chadnach1 | 31:7f0e865e3d4b | 334 | } else if (a == 'E') { |
chadnach1 | 31:7f0e865e3d4b | 335 | curr_mode = EXERCISE; |
chadnach1 | 31:7f0e865e3d4b | 336 | upper_bound = 175; |
amiche | 36:03704a3ec2e3 | 337 | LRI = 175; |
chadnach1 | 31:7f0e865e3d4b | 338 | lower_bound = 100; |
chadnach1 | 31:7f0e865e3d4b | 339 | lcd.printf("MODE IS E\n"); |
chadnach1 | 31:7f0e865e3d4b | 340 | pc.printf("MODE IS E\n"); |
chadnach1 | 31:7f0e865e3d4b | 341 | beats = 2; |
chadnach1 | 31:7f0e865e3d4b | 342 | // if the char is M, set to manual |
chadnach1 | 31:7f0e865e3d4b | 343 | } else if (a == 'M') { |
chadnach1 | 31:7f0e865e3d4b | 344 | curr_mode = MANUAL; |
chadnach1 | 31:7f0e865e3d4b | 345 | upper_bound = 175; |
amiche | 36:03704a3ec2e3 | 346 | LRI = 175; |
chadnach1 | 31:7f0e865e3d4b | 347 | lower_bound = 30; |
chadnach1 | 31:7f0e865e3d4b | 348 | beats = 300; |
chadnach1 | 31:7f0e865e3d4b | 349 | lcd.printf("MODE IS MANUAL\n"); |
chadnach1 | 31:7f0e865e3d4b | 350 | pc.printf("MODE IS MANUAL\n"); |
chadnach1 | 31:7f0e865e3d4b | 351 | // check for A if mode is manual |
chadnach1 | 31:7f0e865e3d4b | 352 | } else if (a == 'A') { |
chadnach1 | 31:7f0e865e3d4b | 353 | if(curr_mode == MANUAL) { |
chadnach1 | 31:7f0e865e3d4b | 354 | pc.printf("MODE IS MANUAL GOT APACE\n"); |
chadnach1 | 31:7f0e865e3d4b | 355 | } |
chadnach1 | 31:7f0e865e3d4b | 356 | // check for V is mode is manual |
chadnach1 | 31:7f0e865e3d4b | 357 | } else if (a == 'V') { |
chadnach1 | 31:7f0e865e3d4b | 358 | if(curr_mode == MANUAL) { |
chadnach1 | 31:7f0e865e3d4b | 359 | pc.printf("MODE IS MANUAL GOT VPACE\n"); |
chadnach1 | 31:7f0e865e3d4b | 360 | } |
chadnach1 | 31:7f0e865e3d4b | 361 | } else if (a == 'O') { |
chadnach1 | 31:7f0e865e3d4b | 362 | keyboard_needs_numeric = 1; |
chadnach1 | 31:7f0e865e3d4b | 363 | } else { |
chadnach1 | 31:7f0e865e3d4b | 364 | // do nothing for invalid char |
chadnach1 | 31:7f0e865e3d4b | 365 | } |
chadnach1 | 31:7f0e865e3d4b | 366 | } |
chadnach1 | 31:7f0e865e3d4b | 367 | } |