Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
main.cpp@48:f90edb35a20e, 2017-09-15 (annotated)
- Committer:
- nikitateggi
- Date:
- Fri Sep 15 07:38:47 2017 +0000
- Revision:
- 48:f90edb35a20e
- Parent:
- 47:3716dd41dba6
- Child:
- 49:3ff80c4bc1be
Merged code with battery monitoring, bluetooth connection timeout and ack timeout
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikitateggi | 0:c47fb0c1bbf6 | 1 | #include "mbed.h" |
nikitateggi | 0:c47fb0c1bbf6 | 2 | #include "display_modules.h" |
nikitateggi | 0:c47fb0c1bbf6 | 3 | #include "touch_modules.h" |
nikitateggi | 1:8316c23ec6b9 | 4 | #include "ecg_dec.h" |
nikitateggi | 1:8316c23ec6b9 | 5 | #include "touch_modules.h" |
nikitateggi | 1:8316c23ec6b9 | 6 | #include "glc.h" |
nikitateggi | 3:9a06c2bed650 | 7 | #include "bp.h" |
nikitateggi | 1:8316c23ec6b9 | 8 | #include "sdcard.h" |
nikitateggi | 4:6bd81bb1790d | 9 | #include "eeprom_pgm.h" |
nikitateggi | 19:1650bbc923cc | 10 | #include "struct.h" |
nikitateggi | 22:ffa88619551d | 11 | #include "battery.h" |
rashmivenkataramaiah | 41:1141a75eacc4 | 12 | #include "main.h" |
nikitateggi | 45:067673dae242 | 13 | |
nikitateggi | 45:067673dae242 | 14 | #define TIMER_RXACK_BTCONNECTION 10000 |
nikitateggi | 45:067673dae242 | 15 | #define BATTERY_TIMER_VALUE 600000 |
nikitateggi | 45:067673dae242 | 16 | #define SERIAL_BAUD_RATE 115200 |
nikitateggi | 45:067673dae242 | 17 | #define BATTERY_SCREEN_NO_CHARGE_CONDITION 3 |
nikitateggi | 24:d992ee8369f4 | 18 | |
nikitateggi | 0:c47fb0c1bbf6 | 19 | Serial gc(USBTX, USBRX); |
nikitateggi | 0:c47fb0c1bbf6 | 20 | DigitalIn q1(PTB11); |
nikitateggi | 29:7edc76b15e3d | 21 | DigitalIn q(PTC5); |
nikitateggi | 29:7edc76b15e3d | 22 | DigitalIn q3(PTC12); |
rashmivenkataramaiah | 42:c81673b04b6a | 23 | DigitalIn BT(PTA5); |
nikitateggi | 44:05dbea558c9a | 24 | Serial blue1(PTC4,PTC3); |
nikitateggi | 44:05dbea558c9a | 25 | uint32_t get_timer_bluetooth(); |
nikitateggi | 45:067673dae242 | 26 | static void battery_status_monitoring(); //bluetooth status pin |
nikitateggi | 45:067673dae242 | 27 | uint8_t touch(uint8_t state); // touch state |
nikitateggi | 45:067673dae242 | 28 | uint8_t display(uint8_t state1); // display state |
nikitateggi | 45:067673dae242 | 29 | |
rashmivenkataramaiah | 42:c81673b04b6a | 30 | static uint8_t nstate=0; |
rashmivenkataramaiah | 42:c81673b04b6a | 31 | static uint8_t nstate1=0; |
rashmivenkataramaiah | 43:85a7f399cb9d | 32 | static uint32_t pid = 0; // patient ID |
rashmivenkataramaiah | 43:85a7f399cb9d | 33 | static bool file_created_status = false; //initialise file created to 0 |
rashmivenkataramaiah | 43:85a7f399cb9d | 34 | static uint32_t filepid_btpid[2] = {}; |
nikitateggi | 45:067673dae242 | 35 | Timer timer_bt; // timer for bluetooth |
nikitateggi | 45:067673dae242 | 36 | Timer timer_battery; // timer for battery |
nikitateggi | 44:05dbea558c9a | 37 | |
nikitateggi | 44:05dbea558c9a | 38 | |
nikitateggi | 0:c47fb0c1bbf6 | 39 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 40 | int main() |
rashmivenkataramaiah | 41:1141a75eacc4 | 41 | { |
rashmivenkataramaiah | 41:1141a75eacc4 | 42 | static uint8_t main_state=1; |
rashmivenkataramaiah | 41:1141a75eacc4 | 43 | static uint8_t state_display = 0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 44 | static uint8_t state_touch = 1; |
nikitateggi | 47:3716dd41dba6 | 45 | uint8_t state_t = 1; // state to transmit to bluetooth |
nikitateggi | 47:3716dd41dba6 | 46 | uint8_t state_r = 0; // state to receive from bluetooth |
nikitateggi | 45:067673dae242 | 47 | |
avp2417 | 37:92fcbf22bf91 | 48 | |
avp2417 | 37:92fcbf22bf91 | 49 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 50 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 51 | gc.baud(115200); |
nikitateggi | 47:3716dd41dba6 | 52 | blue1.baud(115200); |
rashmivenkataramaiah | 41:1141a75eacc4 | 53 | init_screen(); //initialize lcd |
rashmivenkataramaiah | 42:c81673b04b6a | 54 | pid = get_filepid(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 55 | screen_main(); // display of main screen |
nikitateggi | 45:067673dae242 | 56 | battery_monitor(); // monitor battery at the start only |
nikitateggi | 45:067673dae242 | 57 | battery_status_display(); // display of main screen |
nikitateggi | 45:067673dae242 | 58 | timer_battery.start(); |
avp2417 | 37:92fcbf22bf91 | 59 | |
nikitateggi | 0:c47fb0c1bbf6 | 60 | while(1) |
nikitateggi | 0:c47fb0c1bbf6 | 61 | { |
nikitateggi | 45:067673dae242 | 62 | battery_status_monitoring(); // to monitior battery status after every 10 min. |
nikitateggi | 45:067673dae242 | 63 | |
nikitateggi | 45:067673dae242 | 64 | if (get_battery_status() == BATTERY_SCREEN_NO_CHARGE_CONDITION) // to check battery status and take action |
nikitateggi | 45:067673dae242 | 65 | { |
nikitateggi | 45:067673dae242 | 66 | DisableTouch(); |
nikitateggi | 45:067673dae242 | 67 | } |
nikitateggi | 45:067673dae242 | 68 | else |
nikitateggi | 45:067673dae242 | 69 | { |
nikitateggi | 45:067673dae242 | 70 | |
nikitateggi | 45:067673dae242 | 71 | EnableTouch(); |
nikitateggi | 45:067673dae242 | 72 | switch(main_state) // main state machine |
nikitateggi | 45:067673dae242 | 73 | { |
nikitateggi | 45:067673dae242 | 74 | case 1: |
nikitateggi | 45:067673dae242 | 75 | state_display = touch(state_touch); // touch state |
nikitateggi | 45:067673dae242 | 76 | if(state_display == 12) |
nikitateggi | 45:067673dae242 | 77 | { |
nikitateggi | 45:067673dae242 | 78 | main_state = 3; |
nikitateggi | 45:067673dae242 | 79 | } |
nikitateggi | 45:067673dae242 | 80 | else |
nikitateggi | 45:067673dae242 | 81 | { |
nikitateggi | 45:067673dae242 | 82 | main_state = 2; |
nikitateggi | 45:067673dae242 | 83 | } |
nikitateggi | 45:067673dae242 | 84 | break; |
avp2417 | 37:92fcbf22bf91 | 85 | |
nikitateggi | 45:067673dae242 | 86 | case 2: |
nikitateggi | 45:067673dae242 | 87 | state_touch = display(state_display); //display state |
nikitateggi | 45:067673dae242 | 88 | main_state = 1; |
nikitateggi | 45:067673dae242 | 89 | break; |
nikitateggi | 19:1650bbc923cc | 90 | |
nikitateggi | 19:1650bbc923cc | 91 | |
nikitateggi | 45:067673dae242 | 92 | case 3: |
nikitateggi | 45:067673dae242 | 93 | DisableTouch(); // bluetooth send |
nikitateggi | 45:067673dae242 | 94 | timer_bt.start(); |
nikitateggi | 45:067673dae242 | 95 | if(get_timer_bluetooth()<TIMER_RXACK_BTCONNECTION) // bluetooth connection timer 15 sec |
nikitateggi | 45:067673dae242 | 96 | { |
nikitateggi | 44:05dbea558c9a | 97 | |
nikitateggi | 45:067673dae242 | 98 | if(BT==1) // checking for bluetooth connection |
nikitateggi | 45:067673dae242 | 99 | { |
nikitateggi | 44:05dbea558c9a | 100 | |
nikitateggi | 45:067673dae242 | 101 | timer_bt.stop(); // stop the timer once connected to app |
nikitateggi | 45:067673dae242 | 102 | timer_bt.reset(); |
nikitateggi | 44:05dbea558c9a | 103 | BT_connection() ; // displaying connection on bluetooth |
nikitateggi | 44:05dbea558c9a | 104 | state_r=bt_send(state_t); |
nikitateggi | 45:067673dae242 | 105 | timer_bt.start(); |
nikitateggi | 47:3716dd41dba6 | 106 | //gc.printf(" state_t = %d\n", state_t); |
nikitateggi | 48:f90edb35a20e | 107 | // gc.printf(" state_r = %d\n", state_r); |
nikitateggi | 44:05dbea558c9a | 108 | if (state_r==0) // if the state received is zero, then there is no new file to send |
nikitateggi | 45:067673dae242 | 109 | { |
nikitateggi | 45:067673dae242 | 110 | timer_bt.stop(); // stop the timer once connected to app |
nikitateggi | 45:067673dae242 | 111 | timer_bt.reset(); |
nikitateggi | 45:067673dae242 | 112 | BT_finished(); // screen to display communication finished |
nikitateggi | 45:067673dae242 | 113 | screen_BT_return(); //screen to return back |
nikitateggi | 45:067673dae242 | 114 | EnableTouch(); |
nikitateggi | 45:067673dae242 | 115 | main_state=1; |
nikitateggi | 45:067673dae242 | 116 | state_touch=12; |
nikitateggi | 45:067673dae242 | 117 | break; |
nikitateggi | 44:05dbea558c9a | 118 | } |
nikitateggi | 44:05dbea558c9a | 119 | |
nikitateggi | 44:05dbea558c9a | 120 | else |
nikitateggi | 44:05dbea558c9a | 121 | { |
nikitateggi | 44:05dbea558c9a | 122 | main_state=4; // move to receving stste of bluetooth |
nikitateggi | 44:05dbea558c9a | 123 | } |
nikitateggi | 44:05dbea558c9a | 124 | |
nikitateggi | 45:067673dae242 | 125 | } |
nikitateggi | 44:05dbea558c9a | 126 | |
nikitateggi | 45:067673dae242 | 127 | else |
nikitateggi | 45:067673dae242 | 128 | { |
nikitateggi | 45:067673dae242 | 129 | BT_no_connection(); // display screen to show that there is no connection |
nikitateggi | 45:067673dae242 | 130 | } |
nikitateggi | 45:067673dae242 | 131 | } |
nikitateggi | 44:05dbea558c9a | 132 | |
nikitateggi | 45:067673dae242 | 133 | else |
nikitateggi | 45:067673dae242 | 134 | { |
nikitateggi | 45:067673dae242 | 135 | BT_no_connection(); // display screen to show that there is no connection |
nikitateggi | 45:067673dae242 | 136 | gc.printf("stopped"); |
nikitateggi | 45:067673dae242 | 137 | screen_BT_return(); // button to return |
nikitateggi | 45:067673dae242 | 138 | EnableTouch(); |
nikitateggi | 45:067673dae242 | 139 | main_state=1; |
nikitateggi | 45:067673dae242 | 140 | state_touch=12; |
nikitateggi | 47:3716dd41dba6 | 141 | sd_close(); |
nikitateggi | 45:067673dae242 | 142 | timer_bt.stop(); |
nikitateggi | 45:067673dae242 | 143 | timer_bt.reset(); |
nikitateggi | 45:067673dae242 | 144 | } |
nikitateggi | 45:067673dae242 | 145 | break; |
nikitateggi | 19:1650bbc923cc | 146 | |
nikitateggi | 45:067673dae242 | 147 | case 4: |
nikitateggi | 45:067673dae242 | 148 | DisableTouch(); |
nikitateggi | 44:05dbea558c9a | 149 | |
nikitateggi | 45:067673dae242 | 150 | if(get_timer_bluetooth()<TIMER_RXACK_BTCONNECTION) |
nikitateggi | 45:067673dae242 | 151 | { |
nikitateggi | 45:067673dae242 | 152 | if (blue1.readable()) // if there is data to receive enter the loop |
nikitateggi | 45:067673dae242 | 153 | { |
nikitateggi | 46:162ed3f051b2 | 154 | |
nikitateggi | 46:162ed3f051b2 | 155 | state_t=bt_receive(state_r); |
nikitateggi | 48:f90edb35a20e | 156 | // gc.printf(" state_t = %d\n", state_t); |
nikitateggi | 47:3716dd41dba6 | 157 | // gc.printf(" state_r = %d\n", state_r); |
nikitateggi | 45:067673dae242 | 158 | timer_bt.stop(); |
nikitateggi | 45:067673dae242 | 159 | timer_bt.reset(); |
nikitateggi | 45:067673dae242 | 160 | if(state_t ==0) // if state_t is zero, there is no other file to send |
nikitateggi | 45:067673dae242 | 161 | { |
nikitateggi | 45:067673dae242 | 162 | |
nikitateggi | 45:067673dae242 | 163 | BT_finished(); |
nikitateggi | 45:067673dae242 | 164 | screen_BT_return(); |
nikitateggi | 45:067673dae242 | 165 | EnableTouch(); |
nikitateggi | 45:067673dae242 | 166 | main_state=1; |
nikitateggi | 45:067673dae242 | 167 | state_touch=12; // jumping to touch case 12 |
nikitateggi | 45:067673dae242 | 168 | break; |
nikitateggi | 45:067673dae242 | 169 | } |
nikitateggi | 45:067673dae242 | 170 | else // move to bluetooth transmit if the states are 1,2,3,4 |
nikitateggi | 45:067673dae242 | 171 | { |
nikitateggi | 44:05dbea558c9a | 172 | main_state=3; |
nikitateggi | 45:067673dae242 | 173 | } |
nikitateggi | 45:067673dae242 | 174 | } |
nikitateggi | 45:067673dae242 | 175 | } |
nikitateggi | 44:05dbea558c9a | 176 | |
nikitateggi | 45:067673dae242 | 177 | else |
nikitateggi | 45:067673dae242 | 178 | { |
nikitateggi | 45:067673dae242 | 179 | DisableTouch(); |
nikitateggi | 45:067673dae242 | 180 | BT_no_connection(); // display screen to show that there is no connection |
nikitateggi | 45:067673dae242 | 181 | gc.printf("stopped"); |
nikitateggi | 45:067673dae242 | 182 | screen_BT_return(); // button to return |
nikitateggi | 45:067673dae242 | 183 | EnableTouch(); |
nikitateggi | 45:067673dae242 | 184 | main_state=1; |
nikitateggi | 45:067673dae242 | 185 | state_touch=12; |
nikitateggi | 47:3716dd41dba6 | 186 | state_t = 1; // state to transmit to bluetooth |
nikitateggi | 48:f90edb35a20e | 187 | state_r = 0; // state to receive from bluetooth |
nikitateggi | 46:162ed3f051b2 | 188 | sd_close(); ///close the opened file which was used for bluetooth |
nikitateggi | 45:067673dae242 | 189 | timer_bt.stop(); |
nikitateggi | 45:067673dae242 | 190 | timer_bt.reset(); |
nikitateggi | 45:067673dae242 | 191 | } |
nikitateggi | 45:067673dae242 | 192 | break; |
nikitateggi | 45:067673dae242 | 193 | } |
nikitateggi | 45:067673dae242 | 194 | } |
nikitateggi | 45:067673dae242 | 195 | } |
nikitateggi | 45:067673dae242 | 196 | |
nikitateggi | 22:ffa88619551d | 197 | } |
nikitateggi | 19:1650bbc923cc | 198 | uint8_t touch(uint8_t state) |
nikitateggi | 19:1650bbc923cc | 199 | { |
nikitateggi | 19:1650bbc923cc | 200 | static uint8_t state1=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 201 | detect_touch(state); // determine the touch points |
nikitateggi | 1:8316c23ec6b9 | 202 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 203 | switch(state) // state for touch |
nikitateggi | 0:c47fb0c1bbf6 | 204 | { |
rashmivenkataramaiah | 41:1141a75eacc4 | 205 | case 1: |
rashmivenkataramaiah | 41:1141a75eacc4 | 206 | state1=touch_main(); // determining the touch for main screen |
nikitateggi | 0:c47fb0c1bbf6 | 207 | state=0; |
nikitateggi | 1:8316c23ec6b9 | 208 | nstate1=state1; |
rashmivenkataramaiah | 41:1141a75eacc4 | 209 | break; |
nikitateggi | 0:c47fb0c1bbf6 | 210 | |
nikitateggi | 0:c47fb0c1bbf6 | 211 | case 2: |
rashmivenkataramaiah | 41:1141a75eacc4 | 212 | state1=touch_main_1(); // determining the touch for SYSTEM CONFIGURATION screen |
nikitateggi | 0:c47fb0c1bbf6 | 213 | state=0; |
nikitateggi | 3:9a06c2bed650 | 214 | nstate1=state1; |
nikitateggi | 0:c47fb0c1bbf6 | 215 | break; |
nikitateggi | 0:c47fb0c1bbf6 | 216 | |
nikitateggi | 0:c47fb0c1bbf6 | 217 | case 3: |
rashmivenkataramaiah | 41:1141a75eacc4 | 218 | state1=touch_main_2(); // determining the touch for TEST screen |
nikitateggi | 0:c47fb0c1bbf6 | 219 | state=0; |
nikitateggi | 1:8316c23ec6b9 | 220 | nstate1=state1; |
nikitateggi | 0:c47fb0c1bbf6 | 221 | break; |
nikitateggi | 0:c47fb0c1bbf6 | 222 | |
nikitateggi | 0:c47fb0c1bbf6 | 223 | case 4: |
rashmivenkataramaiah | 41:1141a75eacc4 | 224 | state1=touch_glc(); // determining the touch for GLC screen |
nikitateggi | 1:8316c23ec6b9 | 225 | state=0; |
nikitateggi | 1:8316c23ec6b9 | 226 | nstate1=state1; |
nikitateggi | 1:8316c23ec6b9 | 227 | break; |
nikitateggi | 1:8316c23ec6b9 | 228 | |
nikitateggi | 1:8316c23ec6b9 | 229 | case 5: |
rashmivenkataramaiah | 41:1141a75eacc4 | 230 | state1=touch_ecg(); // determining the touch for ECG screen |
nikitateggi | 1:8316c23ec6b9 | 231 | state=0; |
nikitateggi | 3:9a06c2bed650 | 232 | nstate1=state1; |
nikitateggi | 3:9a06c2bed650 | 233 | break; |
nikitateggi | 4:6bd81bb1790d | 234 | case 6: |
rashmivenkataramaiah | 41:1141a75eacc4 | 235 | state1=touch_ret(); // determining the touch for returning back to the main screen |
nikitateggi | 0:c47fb0c1bbf6 | 236 | state=0; |
nikitateggi | 3:9a06c2bed650 | 237 | nstate1=state1; |
nikitateggi | 1:8316c23ec6b9 | 238 | break; |
nikitateggi | 1:8316c23ec6b9 | 239 | |
nikitateggi | 4:6bd81bb1790d | 240 | case 7: |
rashmivenkataramaiah | 41:1141a75eacc4 | 241 | state1=touch_again_ecg(); // determining the touch when readings are taken more than once screen |
nikitateggi | 1:8316c23ec6b9 | 242 | state=0; |
nikitateggi | 1:8316c23ec6b9 | 243 | nstate1=state1; |
nikitateggi | 1:8316c23ec6b9 | 244 | break; |
nikitateggi | 0:c47fb0c1bbf6 | 245 | |
nikitateggi | 3:9a06c2bed650 | 246 | case 8: |
rashmivenkataramaiah | 41:1141a75eacc4 | 247 | state1=touch_bp(); // determining the touch for BP screen |
nikitateggi | 3:9a06c2bed650 | 248 | state=0; |
nikitateggi | 3:9a06c2bed650 | 249 | nstate1=state1; |
nikitateggi | 3:9a06c2bed650 | 250 | break; |
nikitateggi | 3:9a06c2bed650 | 251 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 252 | case 9: |
rashmivenkataramaiah | 41:1141a75eacc4 | 253 | state1=touch_again_glc(); |
suhasini | 5:a3ea7c82b7e1 | 254 | state=0; |
suhasini | 5:a3ea7c82b7e1 | 255 | nstate1=state1; |
suhasini | 5:a3ea7c82b7e1 | 256 | break; |
nikitateggi | 3:9a06c2bed650 | 257 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 258 | case 10 : |
rashmivenkataramaiah | 41:1141a75eacc4 | 259 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 260 | wait_ms(300); |
rashmivenkataramaiah | 41:1141a75eacc4 | 261 | EnableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 262 | state=nstate; |
rashmivenkataramaiah | 41:1141a75eacc4 | 263 | break; |
suhasini | 5:a3ea7c82b7e1 | 264 | |
suhasini | 5:a3ea7c82b7e1 | 265 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 266 | case 11: |
rashmivenkataramaiah | 41:1141a75eacc4 | 267 | state1=touch_again_bp(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 268 | state=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 269 | nstate1=state1; |
rashmivenkataramaiah | 41:1141a75eacc4 | 270 | break; |
suhasini | 5:a3ea7c82b7e1 | 271 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 272 | case 12: |
rashmivenkataramaiah | 41:1141a75eacc4 | 273 | state1=BT_return(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 274 | state=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 275 | nstate1=state1; |
rashmivenkataramaiah | 41:1141a75eacc4 | 276 | break; |
suhasini | 5:a3ea7c82b7e1 | 277 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 278 | default : |
rashmivenkataramaiah | 41:1141a75eacc4 | 279 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 280 | wait_ms(300); |
rashmivenkataramaiah | 41:1141a75eacc4 | 281 | EnableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 282 | state=nstate; |
rashmivenkataramaiah | 41:1141a75eacc4 | 283 | break; |
nikitateggi | 1:8316c23ec6b9 | 284 | |
nikitateggi | 0:c47fb0c1bbf6 | 285 | } |
nikitateggi | 0:c47fb0c1bbf6 | 286 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 287 | return state1; |
rashmivenkataramaiah | 41:1141a75eacc4 | 288 | } |
nikitateggi | 0:c47fb0c1bbf6 | 289 | |
nikitateggi | 0:c47fb0c1bbf6 | 290 | |
nikitateggi | 19:1650bbc923cc | 291 | uint8_t display(uint8_t state1) |
nikitateggi | 19:1650bbc923cc | 292 | { |
rashmivenkataramaiah | 41:1141a75eacc4 | 293 | static uint8_t state=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 294 | static uint8_t ecg_flag=0; // ecg_flag to indicate the ecg test is already done for the same pid |
rashmivenkataramaiah | 41:1141a75eacc4 | 295 | static uint8_t glc_flag=0; // glc_flag to indicate the glc test is already done for the same pid |
rashmivenkataramaiah | 41:1141a75eacc4 | 296 | uint16_t heart_rate=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 297 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 298 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 299 | switch(state1) // state for display screens |
rashmivenkataramaiah | 41:1141a75eacc4 | 300 | { |
nikitateggi | 4:6bd81bb1790d | 301 | |
nikitateggi | 1:8316c23ec6b9 | 302 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 303 | case 1: |
rashmivenkataramaiah | 41:1141a75eacc4 | 304 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 305 | screen_main(); // main screen |
nikitateggi | 1:8316c23ec6b9 | 306 | state1=0; |
nikitateggi | 1:8316c23ec6b9 | 307 | state=1; |
nikitateggi | 1:8316c23ec6b9 | 308 | nstate=state; |
rashmivenkataramaiah | 41:1141a75eacc4 | 309 | ecg_flag=0; // ecg, glc flag to determine whether the readings are taken more than once |
nikitateggi | 1:8316c23ec6b9 | 310 | glc_flag=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 311 | clear_filecreated_status(); |
rashmivenkataramaiah | 42:c81673b04b6a | 312 | pid = get_filepid(); |
nikitateggi | 45:067673dae242 | 313 | battery_status_display(); //Display battery status on LCD |
nikitateggi | 3:9a06c2bed650 | 314 | EnableTouch(); |
nikitateggi | 1:8316c23ec6b9 | 315 | break; |
nikitateggi | 1:8316c23ec6b9 | 316 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 317 | case 2: |
rashmivenkataramaiah | 41:1141a75eacc4 | 318 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 319 | screen_main_1(); // System configration screen |
nikitateggi | 0:c47fb0c1bbf6 | 320 | state1=0; |
nikitateggi | 0:c47fb0c1bbf6 | 321 | state=2; |
nikitateggi | 1:8316c23ec6b9 | 322 | nstate=state; |
nikitateggi | 45:067673dae242 | 323 | battery_status_display(); //Display battery status on LCD |
nikitateggi | 3:9a06c2bed650 | 324 | EnableTouch(); |
nikitateggi | 0:c47fb0c1bbf6 | 325 | break; |
nikitateggi | 0:c47fb0c1bbf6 | 326 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 327 | case 3: |
rashmivenkataramaiah | 41:1141a75eacc4 | 328 | DisableTouch(); |
rashmivenkataramaiah | 42:c81673b04b6a | 329 | //sd_read(pid_btpid); //read pid from sd card |
rashmivenkataramaiah | 42:c81673b04b6a | 330 | //pid=pid_btpid[0]; //copy pid to a variable |
nikitateggi | 19:1650bbc923cc | 331 | gc.printf("pidinit=%d",pid); |
rashmivenkataramaiah | 41:1141a75eacc4 | 332 | screen_main_2(pid); |
rashmivenkataramaiah | 41:1141a75eacc4 | 333 | state1=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 334 | state=3; |
rashmivenkataramaiah | 41:1141a75eacc4 | 335 | nstate=state; |
nikitateggi | 45:067673dae242 | 336 | battery_status_display(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 337 | EnableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 338 | break; |
nikitateggi | 0:c47fb0c1bbf6 | 339 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 340 | case 4: |
rashmivenkataramaiah | 41:1141a75eacc4 | 341 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 342 | if (glc_flag==1) // glc_flag=1 when already the reading has been taken |
rashmivenkataramaiah | 41:1141a75eacc4 | 343 | { |
rashmivenkataramaiah | 41:1141a75eacc4 | 344 | screen_again(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 345 | state1=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 346 | state=9; |
rashmivenkataramaiah | 41:1141a75eacc4 | 347 | nstate=state; |
rashmivenkataramaiah | 41:1141a75eacc4 | 348 | } |
rashmivenkataramaiah | 41:1141a75eacc4 | 349 | else |
nikitateggi | 19:1650bbc923cc | 350 | { |
rashmivenkataramaiah | 41:1141a75eacc4 | 351 | screen_glc(); // glc screen |
rashmivenkataramaiah | 41:1141a75eacc4 | 352 | state1=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 353 | state=4; |
rashmivenkataramaiah | 41:1141a75eacc4 | 354 | nstate=state; |
rashmivenkataramaiah | 41:1141a75eacc4 | 355 | } |
nikitateggi | 3:9a06c2bed650 | 356 | EnableTouch(); |
nikitateggi | 3:9a06c2bed650 | 357 | |
nikitateggi | 0:c47fb0c1bbf6 | 358 | break; |
nikitateggi | 1:8316c23ec6b9 | 359 | |
nikitateggi | 1:8316c23ec6b9 | 360 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 361 | case 5: |
rashmivenkataramaiah | 41:1141a75eacc4 | 362 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 363 | if (ecg_flag==1) |
rashmivenkataramaiah | 41:1141a75eacc4 | 364 | { |
rashmivenkataramaiah | 41:1141a75eacc4 | 365 | screen_again(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 366 | state1=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 367 | state=7; |
nikitateggi | 1:8316c23ec6b9 | 368 | nstate=state; |
rashmivenkataramaiah | 41:1141a75eacc4 | 369 | } |
rashmivenkataramaiah | 41:1141a75eacc4 | 370 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 371 | else |
rashmivenkataramaiah | 41:1141a75eacc4 | 372 | { |
rashmivenkataramaiah | 41:1141a75eacc4 | 373 | screen_ecg(); //ecg main screen |
rashmivenkataramaiah | 41:1141a75eacc4 | 374 | state1=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 375 | state=5; |
nikitateggi | 1:8316c23ec6b9 | 376 | nstate=state; |
rashmivenkataramaiah | 41:1141a75eacc4 | 377 | } |
rashmivenkataramaiah | 41:1141a75eacc4 | 378 | EnableTouch(); |
nikitateggi | 1:8316c23ec6b9 | 379 | break; |
nikitateggi | 1:8316c23ec6b9 | 380 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 381 | case 6: |
rashmivenkataramaiah | 41:1141a75eacc4 | 382 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 383 | screen_bp(); // bp main screen |
nikitateggi | 3:9a06c2bed650 | 384 | state1=0; |
nikitateggi | 3:9a06c2bed650 | 385 | state=8; |
rashmivenkataramaiah | 41:1141a75eacc4 | 386 | nstate=state; |
rashmivenkataramaiah | 41:1141a75eacc4 | 387 | EnableTouch(); |
nikitateggi | 3:9a06c2bed650 | 388 | break; |
nikitateggi | 3:9a06c2bed650 | 389 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 390 | case 7: |
rashmivenkataramaiah | 41:1141a75eacc4 | 391 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 392 | glc(pid); // glc measurement |
nikitateggi | 1:8316c23ec6b9 | 393 | glc_flag=1; |
avp2417 | 35:43133f017ed4 | 394 | wait(1); |
nikitateggi | 4:6bd81bb1790d | 395 | state1=0; |
nikitateggi | 4:6bd81bb1790d | 396 | screen_glc_2(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 397 | state=6; |
rashmivenkataramaiah | 41:1141a75eacc4 | 398 | eprom_write_8(30,0); |
rashmivenkataramaiah | 41:1141a75eacc4 | 399 | nstate=state; |
rashmivenkataramaiah | 41:1141a75eacc4 | 400 | EnableTouch(); |
nikitateggi | 1:8316c23ec6b9 | 401 | break; |
nikitateggi | 1:8316c23ec6b9 | 402 | |
nikitateggi | 3:9a06c2bed650 | 403 | case 8: DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 404 | ecg_countdown(); // countdown before ecg capture |
rashmivenkataramaiah | 41:1141a75eacc4 | 405 | heart_rate=ecg(pid); // capturing ecg |
nikitateggi | 1:8316c23ec6b9 | 406 | state1=0; |
nikitateggi | 20:7c64e6ecad76 | 407 | if (heart_rate==0) |
nikitateggi | 20:7c64e6ecad76 | 408 | { |
avp2417 | 34:8f6b0dc124e8 | 409 | |
nikitateggi | 20:7c64e6ecad76 | 410 | screen_ecg_lead(); |
nikitateggi | 20:7c64e6ecad76 | 411 | } |
rashmivenkataramaiah | 41:1141a75eacc4 | 412 | else if(heart_rate==1) // if heart rate goes above or below range display error // 10/7/17 nikita |
nikitateggi | 31:0f67acfc6236 | 413 | { |
nikitateggi | 31:0f67acfc6236 | 414 | screen_ecg_error(); |
nikitateggi | 31:0f67acfc6236 | 415 | |
nikitateggi | 31:0f67acfc6236 | 416 | } |
avp2417 | 34:8f6b0dc124e8 | 417 | else |
avp2417 | 34:8f6b0dc124e8 | 418 | { |
avp2417 | 34:8f6b0dc124e8 | 419 | |
nikitateggi | 20:7c64e6ecad76 | 420 | screen_ecg_2(heart_rate); |
nikitateggi | 20:7c64e6ecad76 | 421 | ecg_flag=1; |
rashmivenkataramaiah | 43:85a7f399cb9d | 422 | } |
nikitateggi | 1:8316c23ec6b9 | 423 | state=6; |
nikitateggi | 24:d992ee8369f4 | 424 | eprom_write_8(30,1); |
nikitateggi | 20:7c64e6ecad76 | 425 | nstate=state; |
nikitateggi | 20:7c64e6ecad76 | 426 | screen_ecg_bp(); |
nikitateggi | 4:6bd81bb1790d | 427 | EnableTouch(); |
nikitateggi | 1:8316c23ec6b9 | 428 | break; |
rashmivenkataramaiah | 41:1141a75eacc4 | 429 | |
nikitateggi | 19:1650bbc923cc | 430 | case 9: |
nikitateggi | 3:9a06c2bed650 | 431 | DisableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 432 | screen_bp2(); // bp main screen |
rashmivenkataramaiah | 41:1141a75eacc4 | 433 | bp_countdown(); // countdown for bp |
rashmivenkataramaiah | 41:1141a75eacc4 | 434 | bp(pid); // measuring bp earlier bp() changed to bp(pid) 28/4/2017 |
nikitateggi | 3:9a06c2bed650 | 435 | state1=0; |
nikitateggi | 3:9a06c2bed650 | 436 | state=6; |
nikitateggi | 24:d992ee8369f4 | 437 | eprom_write_8(30,2); |
nikitateggi | 3:9a06c2bed650 | 438 | nstate=state; |
nikitateggi | 3:9a06c2bed650 | 439 | EnableTouch(); |
nikitateggi | 3:9a06c2bed650 | 440 | break; |
nikitateggi | 31:0f67acfc6236 | 441 | |
nikitateggi | 31:0f67acfc6236 | 442 | |
nikitateggi | 31:0f67acfc6236 | 443 | case 10 : DisableTouch(); |
nikitateggi | 31:0f67acfc6236 | 444 | wait_ms(300); |
nikitateggi | 31:0f67acfc6236 | 445 | EnableTouch(); |
nikitateggi | 31:0f67acfc6236 | 446 | state=nstate; |
nikitateggi | 31:0f67acfc6236 | 447 | break; |
nikitateggi | 31:0f67acfc6236 | 448 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 449 | case 11 : |
rashmivenkataramaiah | 41:1141a75eacc4 | 450 | DisableTouch(); |
rashmivenkataramaiah | 42:c81673b04b6a | 451 | //sd_read(pid_btpid); //read pid from sd card |
rashmivenkataramaiah | 42:c81673b04b6a | 452 | //current_test_pid=pid_btpid[0]; |
rashmivenkataramaiah | 42:c81673b04b6a | 453 | //bt_file_sent_pid=pid_btpid[1]; |
rashmivenkataramaiah | 42:c81673b04b6a | 454 | //screen_patient_info(current_test_pid, bt_file_sent_pid); |
rashmivenkataramaiah | 42:c81673b04b6a | 455 | screen_patient_info(get_filepid(), get_btpid()); |
rashmivenkataramaiah | 41:1141a75eacc4 | 456 | state1=0; |
rashmivenkataramaiah | 41:1141a75eacc4 | 457 | state=12; |
rashmivenkataramaiah | 41:1141a75eacc4 | 458 | EnableTouch(); |
rashmivenkataramaiah | 41:1141a75eacc4 | 459 | break; |
nikitateggi | 31:0f67acfc6236 | 460 | |
nikitateggi | 31:0f67acfc6236 | 461 | |
nikitateggi | 1:8316c23ec6b9 | 462 | default : |
nikitateggi | 3:9a06c2bed650 | 463 | |
nikitateggi | 1:8316c23ec6b9 | 464 | state1=nstate1; |
nikitateggi | 1:8316c23ec6b9 | 465 | break; |
nikitateggi | 1:8316c23ec6b9 | 466 | |
nikitateggi | 0:c47fb0c1bbf6 | 467 | |
nikitateggi | 0:c47fb0c1bbf6 | 468 | } |
nikitateggi | 0:c47fb0c1bbf6 | 469 | |
nikitateggi | 0:c47fb0c1bbf6 | 470 | |
nikitateggi | 0:c47fb0c1bbf6 | 471 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 472 | return state; |
nikitateggi | 0:c47fb0c1bbf6 | 473 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 474 | } |
rashmivenkataramaiah | 41:1141a75eacc4 | 475 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 476 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 477 | bool get_filecreated_status(void) //function to get file created status |
rashmivenkataramaiah | 41:1141a75eacc4 | 478 | { |
rashmivenkataramaiah | 41:1141a75eacc4 | 479 | return file_created_status; |
rashmivenkataramaiah | 41:1141a75eacc4 | 480 | } |
rashmivenkataramaiah | 41:1141a75eacc4 | 481 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 482 | void set_filecreated_status(void) //function to set file created status |
rashmivenkataramaiah | 41:1141a75eacc4 | 483 | { |
rashmivenkataramaiah | 42:c81673b04b6a | 484 | file_created_status = true; |
rashmivenkataramaiah | 41:1141a75eacc4 | 485 | } |
rashmivenkataramaiah | 41:1141a75eacc4 | 486 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 487 | |
rashmivenkataramaiah | 41:1141a75eacc4 | 488 | void clear_filecreated_status(void) //function to clear file created status |
rashmivenkataramaiah | 41:1141a75eacc4 | 489 | { |
rashmivenkataramaiah | 42:c81673b04b6a | 490 | file_created_status = false; |
rashmivenkataramaiah | 42:c81673b04b6a | 491 | } |
rashmivenkataramaiah | 42:c81673b04b6a | 492 | |
rashmivenkataramaiah | 43:85a7f399cb9d | 493 | void increment_filepid (void) //increment pid if a test is completed |
rashmivenkataramaiah | 42:c81673b04b6a | 494 | { |
rashmivenkataramaiah | 43:85a7f399cb9d | 495 | //uint32_t filepid_btpid[2] = {}; |
rashmivenkataramaiah | 42:c81673b04b6a | 496 | |
rashmivenkataramaiah | 42:c81673b04b6a | 497 | //set_filecreated_status(); //set it to make it append mode |
rashmivenkataramaiah | 42:c81673b04b6a | 498 | sd_read(filepid_btpid); //read pid from sd card |
rashmivenkataramaiah | 42:c81673b04b6a | 499 | filepid_btpid[0] = filepid_btpid[0] + 1; //increment it by 1 |
rashmivenkataramaiah | 42:c81673b04b6a | 500 | sd_write(filepid_btpid); //write it back to sd card |
rashmivenkataramaiah | 42:c81673b04b6a | 501 | |
rashmivenkataramaiah | 42:c81673b04b6a | 502 | } |
rashmivenkataramaiah | 42:c81673b04b6a | 503 | |
rashmivenkataramaiah | 43:85a7f399cb9d | 504 | void increment_btpid (void) //increment pid if a test is completed |
rashmivenkataramaiah | 43:85a7f399cb9d | 505 | { |
rashmivenkataramaiah | 43:85a7f399cb9d | 506 | //uint32_t filepid_btpid[2] = {}; |
rashmivenkataramaiah | 43:85a7f399cb9d | 507 | |
rashmivenkataramaiah | 43:85a7f399cb9d | 508 | //set_filecreated_status(); //set it to make it append mode |
rashmivenkataramaiah | 43:85a7f399cb9d | 509 | sd_read(filepid_btpid); //read pid from sd card |
nikitateggi | 45:067673dae242 | 510 | filepid_btpid[1] = filepid_btpid[1] + 1; //increment it by 1 |
rashmivenkataramaiah | 43:85a7f399cb9d | 511 | sd_write(filepid_btpid); //write it back to sd card |
rashmivenkataramaiah | 43:85a7f399cb9d | 512 | |
rashmivenkataramaiah | 43:85a7f399cb9d | 513 | } |
rashmivenkataramaiah | 43:85a7f399cb9d | 514 | |
rashmivenkataramaiah | 42:c81673b04b6a | 515 | uint32_t get_filepid(void) |
rashmivenkataramaiah | 42:c81673b04b6a | 516 | { |
rashmivenkataramaiah | 42:c81673b04b6a | 517 | //uint32_t filepid_btpid[2] = {}; |
rashmivenkataramaiah | 42:c81673b04b6a | 518 | uint32_t filepid = 0; |
rashmivenkataramaiah | 42:c81673b04b6a | 519 | |
rashmivenkataramaiah | 42:c81673b04b6a | 520 | sd_read(filepid_btpid); //read pid from sd card |
nikitateggi | 45:067673dae242 | 521 | filepid = filepid_btpid[0]; |
rashmivenkataramaiah | 42:c81673b04b6a | 522 | return filepid; |
rashmivenkataramaiah | 42:c81673b04b6a | 523 | |
rashmivenkataramaiah | 42:c81673b04b6a | 524 | } |
rashmivenkataramaiah | 42:c81673b04b6a | 525 | |
rashmivenkataramaiah | 42:c81673b04b6a | 526 | void store_filepid(uint32_t pid) |
rashmivenkataramaiah | 42:c81673b04b6a | 527 | { |
rashmivenkataramaiah | 42:c81673b04b6a | 528 | //uint32_t filepid_btpid[2] = {}; |
rashmivenkataramaiah | 42:c81673b04b6a | 529 | sd_read(filepid_btpid); //read pid from sd card |
rashmivenkataramaiah | 42:c81673b04b6a | 530 | filepid_btpid[0] = pid; |
rashmivenkataramaiah | 42:c81673b04b6a | 531 | sd_write(filepid_btpid); //write it back to sd card |
rashmivenkataramaiah | 42:c81673b04b6a | 532 | |
rashmivenkataramaiah | 42:c81673b04b6a | 533 | } |
rashmivenkataramaiah | 42:c81673b04b6a | 534 | |
rashmivenkataramaiah | 42:c81673b04b6a | 535 | uint32_t get_btpid(void) |
rashmivenkataramaiah | 42:c81673b04b6a | 536 | { |
rashmivenkataramaiah | 42:c81673b04b6a | 537 | //uint32_t filepid_btpid[2] = {}; |
rashmivenkataramaiah | 42:c81673b04b6a | 538 | uint32_t btpid = 0; |
rashmivenkataramaiah | 42:c81673b04b6a | 539 | |
rashmivenkataramaiah | 42:c81673b04b6a | 540 | sd_read(filepid_btpid); //read pid from sd card |
nikitateggi | 45:067673dae242 | 541 | btpid = filepid_btpid[1]; |
rashmivenkataramaiah | 42:c81673b04b6a | 542 | return btpid; |
rashmivenkataramaiah | 42:c81673b04b6a | 543 | |
rashmivenkataramaiah | 42:c81673b04b6a | 544 | } |
rashmivenkataramaiah | 42:c81673b04b6a | 545 | |
rashmivenkataramaiah | 42:c81673b04b6a | 546 | void store_btpid(uint32_t bt_pid) |
rashmivenkataramaiah | 42:c81673b04b6a | 547 | { |
rashmivenkataramaiah | 42:c81673b04b6a | 548 | //uint32_t filepid_btpid[2] = {}; |
rashmivenkataramaiah | 42:c81673b04b6a | 549 | |
rashmivenkataramaiah | 42:c81673b04b6a | 550 | sd_read(filepid_btpid); //read pid from sd card |
rashmivenkataramaiah | 42:c81673b04b6a | 551 | filepid_btpid[1] = bt_pid; |
rashmivenkataramaiah | 42:c81673b04b6a | 552 | sd_write(filepid_btpid); //write it back to sd card |
rashmivenkataramaiah | 42:c81673b04b6a | 553 | |
rashmivenkataramaiah | 42:c81673b04b6a | 554 | } |
rashmivenkataramaiah | 42:c81673b04b6a | 555 | |
nikitateggi | 45:067673dae242 | 556 | |
nikitateggi | 44:05dbea558c9a | 557 | uint32_t get_timer_bluetooth() |
nikitateggi | 44:05dbea558c9a | 558 | { |
nikitateggi | 45:067673dae242 | 559 | return timer_bt.read_ms(); |
nikitateggi | 44:05dbea558c9a | 560 | } |
nikitateggi | 45:067673dae242 | 561 | |
nikitateggi | 45:067673dae242 | 562 | void battery_status_monitoring() |
nikitateggi | 45:067673dae242 | 563 | { |
nikitateggi | 45:067673dae242 | 564 | if(timer_battery.read_ms() > BATTERY_TIMER_VALUE ) |
nikitateggi | 45:067673dae242 | 565 | { |
nikitateggi | 45:067673dae242 | 566 | battery_monitor(); |
nikitateggi | 45:067673dae242 | 567 | timer_battery.reset(); |
nikitateggi | 45:067673dae242 | 568 | } |
nikitateggi | 45:067673dae242 | 569 | } |