Changes done in ECG and BT

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of merged_code2_20sept_2017_4th_oct_2017 by nikita teggi

Committer:
nikitateggi
Date:
Wed Sep 20 07:48:55 2017 +0000
Revision:
51:1a4693774b60
Parent:
50:b42238e7f46d
Child:
52:7d9ff7781bdc
modifications done in debug mode. Unless a message is typed it does not go into debug mode. And debug option  is enabled only for 10 mins

Who changed what in which revision?

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