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 11:02:08 2017 +0000
Revision:
53:cc6e65480a67
Parent:
52:7d9ff7781bdc
Child:
54:f2a413d5dffd
Merged code 2. Includes debug option(sd read, sd erase), lpf, modifications on bluetooth part and PID tracking (as suggested on saturday )

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