
Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
Revision 31:0f67acfc6236, committed 2017-07-15
- Comitter:
- nikitateggi
- Date:
- Sat Jul 15 05:39:45 2017 +0000
- Parent:
- 30:f2f48ed43aae
- Child:
- 32:76892fdf5e4c
- Commit message:
- new display code 15/07/17
Changed in this revision
--- a/bp.cpp Sat Jul 08 12:06:16 2017 +0000 +++ b/bp.cpp Sat Jul 15 05:39:45 2017 +0000 @@ -270,14 +270,21 @@ BLEMsg_info_bp.cal_data.cal_sbp_dummy = (uint16_t) SBP; BLEMsg_info_bp.cal_data.cal_dbp_OTtyp = (uint16_t) DBP; - + if((SBP>190 || SBP<70) && (DBP>100 || DBP<40)) // checking for range below and above and then displaying error + { + screen_bp_error(); // checking for error out of range- nikita 10-7-17 + + } - create_single_BPfile(pid); // Copy ECG and PPG data to BP file - structure_file(ptr_BLEMsg_info_bp, pid); // Copy BP structure to main file - bpfile_mainfile(pid); + else + { - screen_bp1(SBP,DBP); - + create_single_BPfile(pid); // Copy ECG and PPG data to BP file + structure_file(ptr_BLEMsg_info_bp, pid); // Copy BP structure to main file + bpfile_mainfile(pid); + + screen_bp1(SBP,DBP); + } } //Added Nidhin 16/6/17 else //Added Nidhin 16/6/17
--- a/bt.cpp Sat Jul 08 12:06:16 2017 +0000 +++ b/bt.cpp Sat Jul 15 05:39:45 2017 +0000 @@ -9,7 +9,7 @@ #define NACK 0xFF #define sos 0xc0 #define eos 0xc0 -#define no_of_samples 1500 +#define no_of_samples 150 #include "eeprom_pgm.h" //#define len 6000 @@ -61,8 +61,9 @@ file_pointer_position=0; bt_file_tosend=eprom_read(6); // reading the file number(pid) from eeprom which has to be sent to bluetooth current_file=eprom_read(1); - bt_file_tosend=bt_file_tosend+1; - eprom_write(6,bt_file_tosend); // read the current pid + // current_file=2; + //bt_file_tosend=bt_file_tosend+1; + //eprom_write(6,bt_file_tosend); // read the current pid mc.printf("eeprom file=%d",bt_file_tosend); mc.printf("currentfile=%d",current_file); if (bt_file_tosend>current_file) // if the file sent to bluetooth and current file are same, @@ -74,7 +75,7 @@ file=sd_open_read(bt_file_tosend); if(file==0) { - state_tx =6; + state_rx =6; } else { @@ -116,7 +117,7 @@ } - check_sum=checksum(v1); // calculating checksum + check_sum=checksum((uint8_t *)v1,counter); // calculating checksum // calculating checksum state_tx =0; state_rx =3; send_data_str2(check_sum); // send the remaining part of the string @@ -140,6 +141,7 @@ state_tx=0; state_rx=4; + check_sum=checksum((uint8_t *)v1,counter); // calculating checksum send_data_str2(check_sum); } @@ -284,11 +286,14 @@ break; case 6: state_rx =0; + bt_file_tosend=bt_file_tosend+1; + eprom_write(6,bt_file_tosend); + mc.printf("next file"); /*myBleMsg->proto=ACK; blue.scanf("%02x%02x%08x%02x",&sos_rx,&ack_rx,&eos_rx,&chksum_rx); if (ack_rx==myBleMsg->proto) {*/ - if (bt_file_tosend!=current_file) + if (bt_file_tosend<=current_file) { sd_close(); // bt_file_tosend=bt_file_tosend+1; // eprom_write(6,bt_file_tosend); @@ -352,7 +357,7 @@ blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_sbp_dummy); blue.printf("%04x",myBleMsg->bt_msg.cal_data.cal_dbp_OTtyp); myBleMsg->end_of_string=eos; - myBleMsg->chk_sum=checksum_struct(); + myBleMsg->chk_sum = checksum_struct((uint8_t *)myBleMsg, sizeof(Point)); blue.printf("%02x",myBleMsg->end_of_string); blue.printf("%02x",myBleMsg->chk_sum); @@ -437,7 +442,7 @@ blue.printf("%02x",myBleMsg->chk_sum); } -uint8_t checksum(uint32_t *v1) // this function to calculate the checksum for the raw data +/*uint8_t checksum(uint32_t *v1) // this function to calculate the checksum for the raw data { uint32_t sum=0; @@ -466,4 +471,48 @@ sum=myBleMsg->start_of_string+myBleMsg->proto+myBleMsg->bt_msg.length+myBleMsg->bt_msg.device_id+myBleMsg->bt_msg.date_time.date+myBleMsg->bt_msg.date_time.month+myBleMsg->bt_msg.date_time.year+myBleMsg->bt_msg.date_time.hour+myBleMsg->bt_msg.date_time.mins+myBleMsg->bt_msg.date_time.sec+myBleMsg->bt_msg.test_type+myBleMsg->bt_msg.sampling_freq+myBleMsg->bt_msg.num_samples.num_sample_ppg_dummy+myBleMsg->bt_msg.num_samples.num_sample_ecg_OTtyp+myBleMsg->bt_msg.cal_data.cal_sbp_dummy+myBleMsg->bt_msg.cal_data.cal_dbp_OTtyp+myBleMsg->end_of_string+myBleMsg->chk_sum; chksum_struct=sum & 0x000000FF; return chksum_struct; +}*/ + +uint8_t checksum_struct(const uint8_t data[], uint16_t numBytes) // calculating checksum for +{ + uint32_t chksum_struct = 0; + uint16_t index = 0; + + for (index=0U; index < (numBytes-1); index++) + { + chksum_struct += data[index]; + //blue.printf("data=%02x\n",data[index]); + + } + // blue.printf("%08x\n",chksum_struct); + return chksum_struct; } + + +uint8_t checksum(const uint8_t data[], uint32_t numBytes) // this function to calculate the checksum for the raw data +{ + +uint32_t sum=0; +uint8_t chksum_datatrfr=0; +uint8_t i = 0; +uint32_t index = 0; +uint32_t index1 = 0; + sum += sos; + sum += data_trfr; + index1=(numBytes*4); + sum +=(index1>>(8*0))&0xFF; + sum +=(index1>>(8*1))&0xFF; + +for (index=0U; index<(numBytes*4); index++) +{ + sum += data[index]; + +} + + sum+=eos; + + chksum_datatrfr = sum & 0x000000FF; + mc.printf("chksum_datatrfr=%02x\n",chksum_datatrfr); + return chksum_datatrfr; +} +
--- a/display_modules.cpp Sat Jul 08 12:06:16 2017 +0000 +++ b/display_modules.cpp Sat Jul 15 05:39:45 2017 +0000 @@ -536,4 +536,147 @@ TFT.BusEnable(false) ; backlight = 1 ; } - \ No newline at end of file + void screen_ecg_error() + { + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(White) ; + TFT.foreground(Red) ; + TFT.fillrect(5,90,230,150,White); + TFT.locate(50,100) ; + TFT.printf("ERROR!") ; + TFT.locate(20,130) ; + TFT.printf("Take ReTest") ; + //TFT.locate(45,160) ; + // TFT.printf("") ; + TFT.BusEnable(false) ; + backlight = 1 ; + } + + void screen_bp_error() + { + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(White) ; + TFT.foreground(Red) ; + TFT.fillrect(5,90,230,150,White); + TFT.locate(50,100) ; + TFT.printf("ERROR!") ; + TFT.locate(20,130) ; + TFT.printf("Take ReTest") ; + //TFT.locate(45,160) ; + // TFT.printf("") ; + TFT.BusEnable(false) ; + backlight = 1 ; + } + + + void glc_error() + { + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(White) ; + TFT.foreground(Red) ; + TFT.fillrect(5,90,230,300,White); + TFT.locate(50,100) ; + TFT.printf("ERROR!") ; + TFT.locate(20,130) ; + TFT.printf("Take ReTest") ; + //TFT.locate(45,160) ; + // TFT.printf("") ; + TFT.BusEnable(false) ; + backlight = 1 ; + } + + + void BT_connection() + { + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(White) ; + TFT.foreground(Blue) ; + TFT.fillrect(5,90,230,300,White); + TFT.locate(40,140) ; + TFT.printf("Connected") ; + TFT.locate(20,170) ; + TFT.printf("Sending Files") ; + //TFT.locate(45,160) ; + // TFT.printf("") ; + TFT.BusEnable(false) ; + backlight = 1 ; + } + + void BT_no_connection() + { + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(White) ; + TFT.foreground(Blue) ; + TFT.fillrect(5,90,230,300,White); + TFT.locate(80,140) ; + TFT.printf("Not") ; + TFT.locate(40,160) ; + TFT.printf("Connected") ; + //TFT.locate(45,160) ; + // TFT.printf("") ; + TFT.BusEnable(false) ; + backlight = 1 ; + } + +void BT_finished() + { + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(White) ; + TFT.foreground(Blue) ; + TFT.fillrect(5,90,230,300,White); + TFT.locate(20,140) ; + TFT.printf("Files Tranfer") ; + TFT.locate(40,170) ; + TFT.printf("Completed") ; + //TFT.locate(45,160) ; + // TFT.printf("") ; + TFT.BusEnable(false) ; + backlight = 1 ; + } + + + void screen_BT_return() // BT main screen + { + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(Green) ; + TFT.foreground(Black) ; + TFT.fillrect(5,90,230,300,White); + TFT.fillrect( 60,230,180,300,Green); + TFT.locate(80,250) ; + TFT.printf("MAIN") ; + TFT.BusEnable(false) ; + backlight = 1 ; + + } + + +void screen_patient_info(uint32_t current_test_pid,uint32_t bt_file_sent_pid) +{ + char buf[10]; + sprintf (buf, "current pid %d",current_test_pid); + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(White); + TFT.foreground(Blue); + TFT.fillrect(5,90,230,300,White); + TFT.locate(20,140) ; + TFT.printf(buf) ; + sprintf (buf, "Bt pid %d",bt_file_sent_pid); + TFT.locate(20,170) ; + TFT.printf(buf) ; + TFT.background(Green) ; + TFT.foreground(Black) ; + TFT.fillrect( 60,230,180,300,Green); + TFT.locate(80,250) ; + TFT.printf("MAIN") ; + TFT.BusEnable(false) ; + backlight = 1 ; + +} \ No newline at end of file
--- a/display_modules.h Sat Jul 08 12:06:16 2017 +0000 +++ b/display_modules.h Sat Jul 15 05:39:45 2017 +0000 @@ -26,4 +26,12 @@ void screen_ecg_lead_bp_fingerdetect(); void bat_screen_nocharge(); void bat_screen_charge(); +void screen_ecg_error(); // display of error condition for Heart rate +void screen_bp_error(); // display of error condition for BP +void glc_error(); //display of error condition for BG +void BT_connection(); // displaying bluetooth connected +void BT_no_connection(); // displaying bluetooth not connected +void BT_finished(); //Files transfer completed +void screen_BT_return(); // dispaly of return option to bluetooth +void screen_patient_info(uint32_t current_test_pid,uint32_t bt_file_sent_pid); #endif
--- a/ecgg.cpp Sat Jul 08 12:06:16 2017 +0000 +++ b/ecgg.cpp Sat Jul 15 05:39:45 2017 +0000 @@ -258,23 +258,33 @@ fclose(fpeecg1); pc.printf("temporary file closed\n"); -BLEMsg_info_ecg.cal_data.cal_sbp_dummy = 0; -BLEMsg_info_ecg.cal_data.cal_dbp_OTtyp = HR1; //To be modified after HR code is added. + +if(HR_avg>100 || HR_avg<40) + { + + return 1; // out of range condition returning 1 //nikita//10/7 + + } + else + { + + BLEMsg_info_ecg.cal_data.cal_sbp_dummy = 0; + BLEMsg_info_ecg.cal_data.cal_dbp_OTtyp = HR1; //To be modified after HR code is added. -structure_file(ptr_BLEMsg_info_ecg, pid); //copy the ECG structure to Main file //COMMENTED Nidhin 10/6/2017 -ecgfile_mainfile(pid); // copy raw data to the main file and ECG file is cleared. //COMMENTED Nidhin 10/6/2017 + structure_file(ptr_BLEMsg_info_ecg, pid); //copy the ECG structure to Main file //COMMENTED Nidhin 10/6/2017 + ecgfile_mainfile(pid); // copy raw data to the main file and ECG file is cleared. //COMMENTED Nidhin 10/6/2017 -pc.printf("Closed the main file\n"); + pc.printf("Closed the main file\n"); //return HR1; - return HR_avg; - + return HR_avg; + } } else { - pc.printf("no - leadoff"); + pc.printf("improper lead connection"); return 0; } pc.printf("closing temporary file\n");
--- a/glc.cpp Sat Jul 08 12:06:16 2017 +0000 +++ b/glc.cpp Sat Jul 15 05:39:45 2017 +0000 @@ -432,7 +432,7 @@ structure_file(ptr_BLEMsg_info_glc, pid); // Copy the structure into the GLC file glcfile_mainfile(pid); } - else + else if(err==1 || mgdl>200 || mgdl<40) // added threshold to check value out of range { gtc.printf("replace teststip"); }
--- a/main.cpp Sat Jul 08 12:06:16 2017 +0000 +++ b/main.cpp Sat Jul 15 05:39:45 2017 +0000 @@ -18,7 +18,8 @@ DigitalIn q(PTC5); DigitalIn q3(PTC12); DigitalIn BT(PTA5); //bluetooth status pin - +static uint32_t current_test_pid=0; +static uint32_t bt_file_sent_pid=0; uint8_t touch(uint8_t state); // touch state uint8_t display(uint8_t state1); // display state int32_t pid=0; // patient ID @@ -94,11 +95,16 @@ case 3: DisableTouch(); // bluetooth send if(BT==1) { + + BT_connection() ; // displaying connection on bluetooth state_r=bt_send(state_t); main_state=4; } else + { + BT_no_connection(); gc.printf("timeout"); + } break; case 4: @@ -107,8 +113,11 @@ // gc.printf("statet=%d",state_t); if(state_t ==0) { + BT_finished(); + screen_BT_return(); EnableTouch(); main_state=1; + state_touch=12; // jumping to touch case 12 } break; @@ -196,6 +205,10 @@ nstate1=state1; break; + case 12: state1=BT_return(); + state=0; + nstate1=state1; + break; default : DisableTouch(); wait_ms(300); @@ -341,7 +354,11 @@ gc.printf("hi"); screen_ecg_lead(); } - + else if(heart_rate==1) // if heart rate goes above or below range display error // 10/7/17 nikita + { + screen_ecg_error(); + + } else { gc.printf("hif"); @@ -377,9 +394,24 @@ nstate=state; EnableTouch(); break; - - - + + + case 10 : DisableTouch(); + wait_ms(300); + EnableTouch(); + state=nstate; + break; + + case 11 : DisableTouch(); + current_test_pid=eprom_read(1); + bt_file_sent_pid=eprom_read(6); + screen_patient_info(current_test_pid, bt_file_sent_pid); + state1=0; + state=12; + EnableTouch(); + break; + + default : state1=nstate1;
--- a/struct.h Sat Jul 08 12:06:16 2017 +0000 +++ b/struct.h Sat Jul 15 05:39:45 2017 +0000 @@ -87,8 +87,11 @@ void sendlast(); void send_data_str1(); void send_data_str2(uint8_t check_sum); -uint8_t checksum(uint32_t *v1); +//uint8_t checksum(uint32_t *v1); uint8_t checksum_init();; uint8_t checksum_last(); -uint8_t checksum_struct(); +//uint8_t checksum_struct(); + +uint8_t checksum_struct(const uint8_t data[], uint16_t numBytes) ; +uint8_t checksum(const uint8_t data[], uint32_t numBytes) ; #endif \ No newline at end of file
--- a/touch_modules.cpp Sat Jul 08 12:06:16 2017 +0000 +++ b/touch_modules.cpp Sat Jul 15 05:39:45 2017 +0000 @@ -87,7 +87,7 @@ } else if ( ((xt >=FILE_MAIN_X_MIN) && (xt<=FILE_MAIN_X_MAX)) && ( (yt>=FILE_MAIN_Y_MIN) && (yt<=FILE_MAIN_Y_MAX) ) ) // file { - // state=5; + state=11; } else if ( ((xt >=HOME_MAIN_X_MIN) && (xt<=HOME_MAIN_X_MAX)) && ( (yt>=HOME_MAIN_Y_MIN) && (yt<=HOME_MAIN_Y_MAX) ) ) // home @@ -151,7 +151,7 @@ state=8; } - else if ( ((xt >=RET_MAIN_X_MIN) && (xt<=RET_MAIN_X_MAX)) && ( (yt>=RET_MAIN_Y_MIN) && (yt<=RET_MAIN_Y_MAX) ) ) // RETURN + else if ( ((xt >=MAIN_X_MIN) && (xt<=MAIN_X_MAX)) && ( (yt>=MAIN_Y_MIN) && (yt<=MAIN_Y_MAX) ) ) // RETURN { state=3; } @@ -201,7 +201,7 @@ state=9; } - else if ( ((xt >=RET_MAIN_X_MIN) && (xt<=RET_MAIN_X_MAX)) && ( (yt>=RET_MAIN_Y_MIN) && (yt<=RET_MAIN_Y_MAX) ) ) // RETURN + else if ( ((xt >=MAIN_X_MIN) && (xt<=MAIN_X_MAX)) && ( (yt>=MAIN_Y_MIN) && (yt<=MAIN_Y_MAX) ) ) // RETURN { state=3; } @@ -324,7 +324,20 @@ return state; } - + unsigned char BT_return() // //determining the touch for bp main screen + +{ + unsigned char state; + + if ( ((xt >=MAIN_X_MIN) && (xt<=MAIN_X_MAX)) && ( (yt>=MAIN_Y_MIN) && (yt<=MAIN_Y_MAX) ) ) // RETURN + { + state=1; + } + else + state=10; + + return state; + } //TOUCH Functionalities for old display//
--- a/touch_modules.h Sat Jul 08 12:06:16 2017 +0000 +++ b/touch_modules.h Sat Jul 15 05:39:45 2017 +0000 @@ -114,8 +114,10 @@ unsigned char touch_ecg(); unsigned char touch_bp(); unsigned char touch_ret(); - unsigned char touch_again_ecg(); - unsigned char touch_again_glc(); - unsigned char touch_again_bp(); - void screen_bp2(); +unsigned char touch_again_ecg(); +unsigned char touch_again_glc(); +unsigned char touch_again_bp(); +void screen_bp2(); +unsigned char BT_return(); // //determining the touch for bp main screen + #endif \ No newline at end of file