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