
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 49:3ff80c4bc1be, committed 2017-09-15
- Comitter:
- nikitateggi
- Date:
- Fri Sep 15 19:44:48 2017 +0000
- Parent:
- 48:f90edb35a20e
- Child:
- 50:b42238e7f46d
- Commit message:
- Merged code -2; it includes sd card read, delete , entering into the debug mode and lpf for ecg - need to be tested
Changed in this revision
--- a/display_modules.cpp Fri Sep 15 07:38:47 2017 +0000 +++ b/display_modules.cpp Fri Sep 15 19:44:48 2017 +0000 @@ -2,7 +2,7 @@ #include "display_modules.h" #include "touch_modules.h" #include "rtc.h" -//#include "main.h" +#include "main.h" #include "ILI9341.h" //#include <ILI932x.h> #include "Arial12x12.h" @@ -120,9 +120,14 @@ TFT.fillrect( 10,130,100,200,GreenYellow); TFT.locate(38,160) ; //changed from 30 to 38 //rashmi 24/7/17 //changed from 40 to 30 //rashmi 22/7/17 TFT.printf("BT") ; ////changed from BLE to BT //rashmi 24/7/17 - TFT.fillrect( 130,130,220,200,GreenYellow); - TFT.locate(145,160) ; //changed from 135 to 145 //rashmi 22/7/17 - TFT.printf("DEL") ; //changed from ERASE to DEL //rashmi 22/7/17 + if (read_debug_status()== 1) + { + TFT.fillrect( 130,130,220,200,GreenYellow); + TFT.locate(150,140) ; //changed from 135 to 145 //rashmi 22/7/17 // + TFT.printf("DE-") ; + TFT.locate(145,170) ; //changed from 135 to 145 //rashmi 22/7/17 // + TFT.printf("BUG"); //changed from ERASE to DEL //rashmi 22/7/17 + } TFT.fillrect( 10,215,100,285,GreenYellow); TFT.locate(22,245) ; //changed from 26 to 22 //rashmi 24/7/17 //changed from 30 to 26 //rashmi 22/7/17 TFT.printf("P-Inf") ; @@ -788,4 +793,79 @@ // TFT.printf("") ; TFT.BusEnable(false) ; backlight = 1 ; - } \ No newline at end of file +} + +void screen_debug() +{ + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.background(GreenYellow) ; + TFT.fillrect(5,127,230,320,White ); + TFT.set_font((unsigned char*) Arial24x23); + TFT.foreground(Black); + TFT.fillrect( 10,130,100,200,GreenYellow); + TFT.locate(45,140) ; //changed from 30 to 38 //rashmi 24/7/17 //changed from 40 to 30 //rashmi 22/7/17 + TFT.printf("SD") ; ////changed from BLE to BT //rashmi 24/7/17 + TFT.locate(30,170) ; //changed from 30 to 38 //rashmi 24/7/17 //changed from 40 to 30 //rashmi 22/7/17 + TFT.printf("DEL") ; + TFT.fillrect( 130,130,220,200,GreenYellow); + TFT.locate(150,140) ; //changed from 135 to 145 //rashmi 22/7/17 + TFT.printf("SD") ; + TFT.locate(140,170) ; //changed from 135 to 145 //rashmi 22/7/17 + TFT.printf("READ") ; //changed from ERASE to DEL //rashmi 22/7/17 + TFT.fillrect( 10,215,100,285,GreenYellow); + TFT.locate(22,245) ; //changed from 26 to 22 //rashmi 24/7/17 //changed from 30 to 26 //rashmi 22/7/17 + TFT.printf("*") ; + TFT.fillrect(130,215,220,285,GreenYellow); + TFT.locate(130,245) ; + TFT.printf("BACK") ; + TFT.BusEnable(false) ; + backlight = 1 ; + + +} + +void screen_sdcard_delete(void) +{ + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.fillrect(10,130,100,200,White); + TFT.fillrect(130,130,220,200,White); + TFT.fillrect(10,215,100,285,White); + TFT.fillrect(130,215,220,285,White); + TFT.fillrect(5,5,115,20,White); + TFT.background(White) ; + TFT.foreground(Red); + TFT.locate(15,140) ; + TFT.printf("SD card erased"); + + TFT.fillrect( 60,230,180,300,Green); + TFT.background(Green) ; + TFT.foreground(Black) ; + TFT.locate(80,250) ; + TFT.printf("MAIN") ; + TFT.BusEnable(false) ; + backlight = 1 ; +} + +void screen_sdcard_read(void) +{ + backlight = 0 ; + TFT.BusEnable(true) ; + TFT.fillrect(10,130,100,200,White); + TFT.fillrect(130,130,220,200,White); + TFT.fillrect(10,215,100,285,White); + TFT.fillrect(130,215,220,285,White); + TFT.fillrect(5,5,115,20,White); + TFT.background(White) ; + TFT.foreground(Red); + TFT.locate(15,140) ; + TFT.printf("SD read finished"); + TFT.fillrect( 60,230,180,300,Green); + TFT.background(Green) ; + TFT.foreground(Black) ; + TFT.locate(80,250) ; + TFT.printf("MAIN") ; + TFT.BusEnable(false) ; + backlight = 1 ; +} \ No newline at end of file
--- a/display_modules.h Fri Sep 15 07:38:47 2017 +0000 +++ b/display_modules.h Fri Sep 15 19:44:48 2017 +0000 @@ -37,4 +37,7 @@ void battery_critically_low_charge(); void battery_low_charge(); void glc_error_test_strip_removed();// added on 11/8/17 nikita +void screen_debug(); +void screen_sdcard_delete(void); +void screen_sdcard_read(void); #endif
--- a/main.cpp Fri Sep 15 07:38:47 2017 +0000 +++ b/main.cpp Fri Sep 15 19:44:48 2017 +0000 @@ -15,6 +15,7 @@ #define BATTERY_TIMER_VALUE 600000 #define SERIAL_BAUD_RATE 115200 #define BATTERY_SCREEN_NO_CHARGE_CONDITION 3 +#define TIMER_ENTER_DEBUG_MODE 10000 Serial gc(USBTX, USBRX); DigitalIn q1(PTB11); @@ -34,7 +35,7 @@ static uint32_t filepid_btpid[2] = {}; Timer timer_bt; // timer for bluetooth Timer timer_battery; // timer for battery - +uint8_t debug_mode=0; int main() @@ -44,7 +45,7 @@ static uint8_t state_touch = 1; uint8_t state_t = 1; // state to transmit to bluetooth uint8_t state_r = 0; // state to receive from bluetooth - + DisableTouch(); @@ -56,7 +57,23 @@ battery_monitor(); // monitor battery at the start only battery_status_display(); // display of main screen timer_battery.start(); + timer_bt.start(); + gc.printf("Press any key to enter into debug mode\n"); + while(timer_bt.read_ms()<TIMER_ENTER_DEBUG_MODE) + { + + if (gc.readable()) + { + debug_mode = 1; + timer_bt.stop(); + timer_bt.reset(); + break; + } + } + + timer_bt.stop(); + timer_bt.reset(); while(1) { battery_status_monitoring(); // to monitior battery status after every 10 min. @@ -138,7 +155,7 @@ EnableTouch(); main_state=1; state_touch=12; - sd_close(); + //sd_close(); timer_bt.stop(); timer_bt.reset(); } @@ -274,7 +291,12 @@ state=0; nstate1=state1; break; - + + case 13: + state1 = touch_debug(); //touch state for debug + //state=0; + nstate1=state1; + break; default : DisableTouch(); wait_ms(300); @@ -294,7 +316,7 @@ static uint8_t ecg_flag=0; // ecg_flag to indicate the ecg test is already done for the same pid static uint8_t glc_flag=0; // glc_flag to indicate the glc test is already done for the same pid uint16_t heart_rate=0; - + uint32_t pid_read = 0; switch(state1) // state for display screens { @@ -311,6 +333,7 @@ clear_filecreated_status(); pid = get_filepid(); battery_status_display(); //Display battery status on LCD + debug_mode = 0; EnableTouch(); break; @@ -427,7 +450,7 @@ EnableTouch(); break; - case 9: + case 9: DisableTouch(); screen_bp2(); // bp main screen bp_countdown(); // countdown for bp @@ -456,8 +479,40 @@ state1=0; state=12; EnableTouch(); - break; - + break; + + case 13 : //display screen for debug + DisableTouch(); + screen_debug(); + state1=0; + state=13; + nstate=state; + EnableTouch(); + break; + + case 14 : + DisableTouch(); //state to delete SD card + delete_sdcard(); + screen_sdcard_delete(); + state1=0; + state= 12; + nstate=state; + EnableTouch(); + break; + + case 15 : + DisableTouch(); + // screen_sdcard_read(); //state to delete SD card + gc.printf("Enter the PID number......!!"); + gc.scanf("%d\n", &pid_read); + gc.printf("%d\n",pid_read); + read_sdcard_file(pid_read); + // screen_sdcard_read(); + state1=0; + state= 12; + nstate=state; + EnableTouch(); + break; default : @@ -566,4 +621,9 @@ battery_monitor(); timer_battery.reset(); } +} + +uint8_t read_debug_status() +{ + return debug_mode; } \ No newline at end of file
--- a/main.h Fri Sep 15 07:38:47 2017 +0000 +++ b/main.h Fri Sep 15 19:44:48 2017 +0000 @@ -12,5 +12,6 @@ void store_btpid(uint32_t bt_pid); uint32_t get_filepid(void); void store_filepid(uint32_t pid); +uint8_t read_debug_status(); #endif
--- a/sdcard.cpp Fri Sep 15 07:38:47 2017 +0000 +++ b/sdcard.cpp Fri Sep 15 19:44:48 2017 +0000 @@ -424,6 +424,10 @@ sprintf(buffer3, "/sd/%d_ECG.csv", pid); success = remove(buffer3); snd.printf("DELETE STATUS = %d\n", success); +success = 1; + sprintf(buffer3, "/sd/%d_ECG_lpf.csv", pid); + success = remove(buffer3); + snd.printf("DELETE STATUS = %d\n", success); } @@ -495,6 +499,16 @@ snd.printf("\nECG file delete : Successful"); // Checks for SUCCESS else snd.printf("\nECG file delete : UnSuccessful"); + + success3 = 1; + sprintf(buffer3, "/sd/%d_ECG_lpf.csv", pid); + success3 = remove(buffer3); + snd.printf("DELETE STATUS = %d\n", success3); + + if( success3 == 0 ) + snd.printf("\nECG_lpf file delete : Successful"); // Checks for SUCCESS + else + snd.printf("\nECG_lpf file delete : UnSuccessful"); } @@ -552,4 +566,134 @@ } +void delete_sdcard(void) +{ + FILE *fp; + uint32_t pid[2] = {1,1}; + fp= fopen("/sd/pid_info.txt","w"); + fwrite(&pid, sizeof(uint32_t),2,fp); + fclose(fp); + +} + + +/*void read_sdcard_file() +{ + uint32_t pid=0; + snd.printf("Enter the PID number......!!\n"); + snd.scanf("%d", &pid); + snd.printf("%d\n",pid); + readfile(pid); + snd.printf("Finished reading\n"); + +}*/ + + + +void read_sdcard_file(uint32_t pid) +{ + FILE *fp_read_sdcard_file ; // PPG and ECG File pointers for BP + char buffer[32]; + sprintf(buffer,"/sd/%d.csv",pid); + fp_read_sdcard_file = fopen(buffer, "rb"); + + if(fp_read_sdcard_file == NULL) + { + snd.printf("No FILE Found .... !!\n"); + } + + else + { + read_structure(fp_read_sdcard_file); + snd.printf("Finished Reading File Content....!!\n"); + fclose(fp_read_sdcard_file); + } //end of else loop + + } + +void read_structure(FILE * fp_read_sdcard_file) + + { + BLEMsg_info bt_file2; + uint32_t buf[1000]; + uint16_t sample = 0; + while (!feof(fp_read_sdcard_file)) + { + fread(&bt_file2,sizeof(BLEMsg_info),1,fp_read_sdcard_file); + snd.printf("%d\n",bt_file2.length); + snd.printf("%d\n",bt_file2.device_id); + snd.printf("%d\n",bt_file2.patient_id); + snd.printf("%d\n",bt_file2.date_time.date); + snd.printf("%d\n",bt_file2.date_time.month); + snd.printf("%d\n",bt_file2.date_time.year); + snd.printf("%d\n",bt_file2.date_time.hour); + snd.printf("%d\n",bt_file2.date_time.mins); + snd.printf("%d\n",bt_file2.date_time.sec); + snd.printf("%d\n",bt_file2.test_type); + snd.printf("%d\n",bt_file2.sampling_freq); + snd.printf("%d\n",bt_file2.num_samples.num_sample_ppg_dummy); + snd.printf("%d\n",bt_file2.num_samples.num_sample_ecg_OTtyp); + sample=(bt_file2.num_samples.num_sample_ppg_dummy + bt_file2.num_samples.num_sample_ecg_OTtyp); + snd.printf("%d\n",bt_file2.cal_data.cal_sbp_dummy); + snd.printf("%d\n",bt_file2.cal_data.cal_dbp_OTtyp); + + + switch(sample) + { + + case 2: + fread(&buf,sizeof(uint32_t),sample,fp_read_sdcard_file); + for(uint16_t file_start1=0;file_start1<sample;file_start1++) + { + snd.printf("%08x", buf[file_start1]); + } + break; + + case 2000: + for(uint16_t file_start=0;file_start<(sample/1000);file_start++) + { + + fread(&buf,sizeof(uint32_t),1000,fp_read_sdcard_file); + for(uint16_t file_start1=0;file_start1<(1000);file_start1++) + { + snd.printf("%08x", buf[file_start1]); + } + + } + break; + + case 2668: + for(uint16_t file_start=0;file_start<(sample/1000);file_start++) + { + + fread(&buf,sizeof(uint32_t),1000,fp_read_sdcard_file); + for(uint16_t file_start1=0;file_start1<(1000);file_start1++) + { + snd.printf("%08x", buf[file_start1]); + } + + } + + + for(uint16_t i=0;i<1000;i++) + { + buf[i]=NULL; + } + + fread(&buf,sizeof(uint32_t),(sample-(1000*(sample/1000))),fp_read_sdcard_file); + + for(uint16_t file_start1=0;file_start1<(sample-(1000*(sample/1000)));file_start1++) + { + snd.printf("%08x", buf[file_start1]); + } + break; + } + + + } + + } + + + \ No newline at end of file
--- a/sdcard.h Fri Sep 15 07:38:47 2017 +0000 +++ b/sdcard.h Fri Sep 15 19:44:48 2017 +0000 @@ -20,6 +20,7 @@ void sd_read1(BLEMsg_info &f); void setpos(); void setpos1(uint32_t position); + //void sd_BP_ppgwrite (uint32_t value); //void sd_BP_ecgwrite (int value); uint16_t heart_cal(int pid); @@ -54,6 +55,9 @@ void del_ppg_ecg_BPfile(uint32_t pid); // deletes temporary ECG_PPG files in BP when ERROR condition- 22/7/17-Suhasini void sd_write(uint32_t *pid_btpid); void sd_read(uint32_t *pid_btpid); - - +void delete_sdcard(void); //delete sd card +//void readfile(uint32_t pid); +void read_structure(FILE *fp_read_sdcard_file); +void read_sdcard_file(uint32_t pid); +// void print_structure(uint32_t pid); #endif \ No newline at end of file
--- a/touch_modules.cpp Fri Sep 15 07:38:47 2017 +0000 +++ b/touch_modules.cpp Fri Sep 15 19:44:48 2017 +0000 @@ -3,6 +3,7 @@ //#include "ili9325.h" #include "display_modules.h" #include "touch_modules.h" +#include "main.h" //InterruptIn Touch_D(PTD6); InterruptIn Touch_D(PTD2); int i; @@ -15,14 +16,14 @@ { xt = (X_MAX*readTouchX()/TOTAL1); yt = (Y_MAX*readTouchY()/TOTAL1); - kc.printf("%d\n", xt); - kc.printf("%d\n", yt); + //kc.printf("%d\n", xt); + // kc.printf("%d\n", yt); } void detect_touch(unsigned char display_state) // detect the touch //debounce { -kc.printf("display state=%d\n",display_state); +//kc.printf("display state=%d\n",display_state); uint32_t time_ms=0; switch (display_state) @@ -98,15 +99,16 @@ if ( ((xt >=BT_MAIN_X_MIN) && (xt<=BT_MAIN_X_MAX)) && ( (yt>= BT_MAIN_Y_MIN) && (yt<=BT_MAIN_Y_MAX) ) ) // ble { - state=12; + state = 12; } - - else if ( ((xt >=DELETE_MAIN_X_MIN) && (xt<=DELETE_MAIN_X_MAX)) && ( (yt>=DELETE_MAIN_Y_MIN) && (yt<=DELETE_MAIN_Y_MAX) ) ) // DELETE - { - // state=4; - - - } + if (read_debug_status()== 1) + { + if ( ((xt >=DELETE_MAIN_X_MIN) && (xt<=DELETE_MAIN_X_MAX)) && ( (yt>=DELETE_MAIN_Y_MIN) && (yt<=DELETE_MAIN_Y_MAX) ) ) // DELETE + { + state=13; + } + } + else if ( ((xt >=PATIENT_INFO_MAIN_X_MIN) && (xt<=PATIENT_INFO_MAIN_X_MAX)) && ( (yt>=PATIENT_INFO_MAIN_Y_MIN) && (yt<=PATIENT_INFO_MAIN_Y_MAX) ) ) // file { state=11; @@ -367,63 +369,40 @@ state=10; return state; - } - - //TOUCH Functionalities for old display// +} -/*int readTouchY(void) // read the Y co-ordinate -{ - DigitalOut YD(PTD6); - DigitalIn XL(PTD7); - DigitalOut YU(PTC0); - YU = 1; - YD = 0; - AnalogIn XR(PTB0); - XL.mode(PullNone); - return XR.read_u16(); -} +unsigned char touch_debug() +{ + unsigned char state=0; -int readTouchX(void) // // read the X co-ordinate -{ - DigitalOut XR(PTB0); - DigitalIn YD(PTD6); - DigitalOut XL(PTD7); - - XR = 1; - XL = 0; - AnalogIn YU(PTC0); - YD.mode(PullNone); - return YU.read_u16(); -} - -void EnableTouch(void) // Enable touch -{ + if ( ((xt >= SD_DEL_X_MIN) && (xt <= SD_DEL_X_MAX)) && ( (yt >= SD_DEL_Y_MIN) && (yt <= SD_DEL_Y_MAX) ) ) //fasting // 12/06/17 newly added + { + state = 14 ; + } + + else if ( ((xt >= SD_READ_X_MIN) && (xt <= SD_READ_X_MAX)) && ( (yt >= SD_READ_Y_MIN) && (yt <= SD_READ_Y_MAX) ) ) // pp + { + state = 15; - DigitalIn YD(PTD6); - DigitalOut XL(PTD7); - DigitalIn YU(PTC0); - DigitalIn XR(PTB0); - XL=0; - YD.mode(PullUp); - YU.mode(PullNone); - XR.mode(PullNone); - i=1; - Touch_D.fall(&touch1); - Touch_D.enable_irq(); - - } - -void DisableTouch (void) // Disable touch -{ - Touch_D.disable_irq(); - i=0; - DigitalOut YD(PTD6); - DigitalOut XL(PTD7); - DigitalOut YU(PTC0); - DigitalOut XR(PTB0); + } + else if ( ((xt >= Z_X_MIN) && (xt <= Z_X_MAX)) && ( (yt >= Z_Y_MIN) && (yt <= Z_Y_MAX) ) ) // random + { + //state = ; + } + else if ( ((xt >= DEBUG_BACK_X_MIN) && (xt <= DEBUG_BACK_X_MAX)) && ( (yt >= DEBUG_BACK_Y_MIN) && (yt <= DEBUG_BACK_Y_MAX) ) ) // return + { + state = 2 ; } - */ + + else + state=10; + + return state; + +} + + //TOUCH Functionalities for new display//
--- a/touch_modules.h Fri Sep 15 07:38:47 2017 +0000 +++ b/touch_modules.h Fri Sep 15 19:44:48 2017 +0000 @@ -101,6 +101,26 @@ #define NO_MAIN_Y_MIN 180 #define NO_MAIN_Y_MAX 260 +#define SD_DEL_X_MIN 110 //Co-ordinates for SD-DEL +#define SD_DEL_X_MAX 140 +#define SD_DEL_Y_MIN 50 +#define SD_DEL_Y_MAX 130 + +#define SD_READ_X_MIN 110 //Co-ordinates for SD-READ +#define SD_READ_X_MAX 145 +#define SD_READ_Y_MIN 180 +#define SD_READ_Y_MAX 260 + +#define Z_X_MIN 60 +#define Z_X_MAX 90 +#define Z_Y_MIN 50 +#define Z_Y_MAX 130 + +#define DEBUG_BACK_X_MIN 60 //Co-ordinates for BACK in DEBUG +#define DEBUG_BACK_X_MAX 90 +#define DEBUG_BACK_Y_MIN 180 +#define DEBUG_BACK_Y_MAX 260 + unsigned char touch_main(); unsigned char touch_main_1(); unsigned char touch_main_2(); @@ -124,5 +144,6 @@ void touch_func_without_timer(); uint32_t get_timer(); void no_touch(); +unsigned char touch_debug(); #endif \ No newline at end of file