Changes done in ECG and BT
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_20sept_2017_4th_oct_2017 by
touch_modules.cpp
- Committer:
- nikitateggi
- Date:
- 2017-11-03
- Revision:
- 56:89eb9a977641
- Parent:
- 54:f2a413d5dffd
File content as of revision 56:89eb9a977641:
#include "mbed.h" #include "eeprom_pgm.h" //#include "ili9325.h" #include "display_modules.h" #include "touch_modules.h" #include "main.h" //InterruptIn Touch_D(PTD6); InterruptIn Touch_D(PTD2); int i; unsigned int xt=0; unsigned int yt=0; Serial kc(USBTX, USBRX); Timer t1; void touch1() //determining the touch co-ordinates { xt = (X_MAX*readTouchX()/TOTAL1); yt = (Y_MAX*readTouchY()/TOTAL1); 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); uint32_t time_ms=0; switch (display_state) { case 3: time_ms= 300000; // timer for 5 min touch_func_with_timer(time_ms); break; case 6: time_ms= 60000; // timer for 1 min touch_func_with_timer(time_ms); break; default : touch_func_without_timer(); break; } } void touch_func_without_timer() { while(i==1) { while(Touch_D)//touch detection { wait_ms(200); ///wait for debounce check if (Touch_D) { Touch_D.fall(&touch1); //determine the touch co-ordinates break; } DisableTouch(); //kc.printf("touch"); } } } void no_touch() { xt=0;yt=0; } unsigned char touch_main() //determining the touch for home screen { unsigned char state=0; if ( ((xt >=SYSCFG_HOME_X_MIN) && (xt<=SYSCFG_HOME_X_MAX)) && ( (yt>=SYSCFG_HOME_Y_MIN) && (yt<= SYSCFG_HOME_Y_MAX) ) ) // system configuration { state=2; } else if ( ((xt >=TEST_HOME_X_MIN) && (xt<=TEST_HOME_X_MAX)) && ( (yt>=TEST_HOME_Y_MIN) && (yt<=TEST_HOME_Y_MAX) ) ) // test { state=3; } else state=10; return state; } unsigned char touch_main_1() //determining the touch for System Configuration screen { unsigned char state=0; if ( ((xt >=BT_MAIN_X_MIN) && (xt<=BT_MAIN_X_MAX)) && ( (yt>= BT_MAIN_Y_MIN) && (yt<=BT_MAIN_Y_MAX) ) ) // ble { state = 12; } 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; } else if ( ((xt >= HOME_SYS_CONFIG_X_MIN) && (xt <= HOME_SYS_CONFIG_X_MAX)) && ( (yt >= HOME_SYS_CONFIG_Y_MIN) && (yt <= HOME_SYS_CONFIG_Y_MAX) ) ) // home { state=1; } else if ((read_debug_status()== true) && get_timer_debug()<TIMER_ENABLE_DEBUG_MODE) // checking for the debug status and timer { if ( ((xt >= DEBUG_MAIN_X_MIN) && (xt <= DEBUG_MAIN_X_MAX)) && ( (yt >= DEBUG_MAIN_Y_MIN) && (yt <= DEBUG_MAIN_Y_MAX) ) ) // DELETE { state=13; } } else state=10; kc.printf("state = %d\n", state); return state; } unsigned char touch_main_2() //determining the touch for TEST screen { unsigned char state=0; if ( ((xt >=BG_MAIN_X_MIN) && (xt<=BG_MAIN_X_MAX)) && ( (yt>=BG_MAIN_Y_MIN) && (yt<=BG_MAIN_Y_MAX) ) ) // GLC { state=4; } else if ( ((xt >=ECG_MAIN_X_MIN) && (xt<=ECG_MAIN_X_MAX)) && ( (yt>=ECG_MAIN_Y_MIN) && (yt<=ECG_MAIN_Y_MAX) ) ) // ECG { state=5; } else if ( ((xt >=BP_MAIN_X_MIN) && (xt<=BP_MAIN_X_MAX)) && ( (yt>=BP_MAIN_Y_MIN) && (yt<=BP_MAIN_Y_MAX) ) ) // BP { state=6; } else if ( ((xt >= HOME_MAIN_X_MIN) && (xt<= HOME_MAIN_X_MAX)) && ( (yt>=HOME_MAIN_Y_MIN) && (yt<= HOME_MAIN_Y_MAX) ) ) // Home { state=1; } else if (xt==0 && yt==0) { state=1; } else { state=10; // default - goes to wait for a valid touch } return state; } unsigned char touch_ecg() // determining the touch for ecg main screen { unsigned char state=0; if ( ((xt >=START_MAIN_X_MIN) && (xt<=START_MAIN_X_MAX)) && ( (yt>=START_MAIN_Y_MIN) && (yt<=START_MAIN_Y_MAX) ) ) // START { state=8; } else if ( ((xt >=MAIN_X_MIN) && (xt<=MAIN_X_MAX)) && ( (yt>=MAIN_Y_MIN) && (yt<=MAIN_Y_MAX) ) ) // RETURN { state=3; } else state=10; return state; } unsigned char touch_ret() // determining the touch for ecg screen after the test { unsigned char state=0; int8_t type=0; type=eprom_read_8(30); if ( ((xt >=RET_TEST_X_MIN) && (xt<=RET_TEST_X_MAX)) && ( (yt>=RET_TEST_Y_MIN) && (yt<=RET_TEST_Y_MAX) ) ) // RET //CHANGED 12/06/17// { state=3; } else if ( ((xt >=RETEST_HOME_X_MIN) && (xt<=RETEST_HOME_X_MAX)) && ( (yt>=RETEST_HOME_Y_MIN) && (yt<=RETEST_HOME_Y_MAX) ) ) // RETEST { if (type==0) state=7; else if (type==1) state=8; else if (type==2) state=9; } else if (xt==0 && yt==0) { state=3; } else state=10; return state; } unsigned char touch_bp() // //determining the touch for bp main screen { unsigned char state=0; if ( ((xt >=START_MAIN_X_MIN) && (xt<=START_MAIN_X_MAX)) && ( (yt>=START_MAIN_Y_MIN) && (yt<=START_MAIN_Y_MAX) ) ) // START { state=9; } else if ( ((xt >=MAIN_X_MIN) && (xt<=MAIN_X_MAX)) && ( (yt>=MAIN_Y_MIN) && (yt<=MAIN_Y_MAX) ) ) // RETURN { state=3; } else state=10; return state; } unsigned char touch_glc() //determining the touch for GLC screen { unsigned char state=0; /* if ( ((xt >=70) && (xt<=170)) && ( (yt>= 140) && (yt<= 195) ) ) // START { state=7; } else if ( ((xt >=70) && (xt<=170)) && ( (yt>=70) && (yt<=140) ) ) // RETURN { state=3; } */ if ( ((xt >=FPS_MAIN_X_MIN) && (xt<=FPS_MAIN_X_MAX)) && ( (yt>=FPS_MAIN_Y_MIN) && (yt<=FPS_MAIN_Y_MAX) ) ) //fasting // 12/06/17 newly added { state=7; eprom_write_16(20,0); } else if ( ((xt >=PP_MAIN_X_MIN) && (xt<=PP_MAIN_X_MAX)) && ( (yt>=PP_MAIN_Y_MIN) && (yt<=PP_MAIN_Y_MAX) ) ) // pp { state=7; eprom_write_16(20,1); } else if ( ((xt >= RANDOM_MAIN_X_MIN) && (xt<=RANDOM_MAIN_X_MAX)) && ( (yt>=RANDOM_MAIN_Y_MIN) && (yt<=RANDOM_MAIN_Y_MAX) ) ) // random { state=7; eprom_write_16(20,2); } else if ( ((xt >=BG_RET_MAIN_X_MIN) && (xt<=BG_RET_MAIN_X_MAX)) && ( (yt>=BG_RET_MAIN_Y_MIN) && (yt<=BG_RET_MAIN_Y_MAX) ) ) // return { state=3; ////////// } else state=10; return state; } unsigned char touch_again_ecg() //determining the touch for Repeat test { unsigned char state=0; if ( ((xt >=YES_MAIN_X_MIN) && (xt<=YES_MAIN_X_MAX)) && ( (yt>=YES_MAIN_Y_MIN) && (yt<=YES_MAIN_Y_MAX) ) ) // YES { state=8; } else if ( ((xt >=NO_MAIN_X_MIN) && (xt<=NO_MAIN_X_MAX)) && ( (yt>=NO_MAIN_Y_MIN) && (yt<=NO_MAIN_Y_MAX) ) ) // NO { state=3; } else state=10; return state; } unsigned char touch_again_glc() //determining the touch for Repeat test { unsigned char state=0; if ( ((xt >=YES_MAIN_X_MIN) && (xt<=YES_MAIN_X_MAX)) && ( (yt>=YES_MAIN_Y_MIN) && (yt<=YES_MAIN_Y_MAX) ) ) // YES { state=7; } else if ( ((xt >=YES_MAIN_Y_MAX) && (xt<=NO_MAIN_Y_MIN)) && ( (yt>=NO_MAIN_Y_MIN) && (yt<=NO_MAIN_Y_MAX) ) ) // NO { state=3; } else state=10; return state; } unsigned char touch_again_bp() //determining the touch for Repeat test { unsigned char state=0; if ( ((xt >=YES_MAIN_X_MIN) && (xt<=YES_MAIN_X_MAX)) && ( (yt>=YES_MAIN_Y_MIN) && (yt<=YES_MAIN_Y_MAX) ) ) // YES { state=9; } else if ( ((xt >=NO_MAIN_X_MIN) && (xt<=NO_MAIN_X_MAX)) && ( (yt>=NO_MAIN_Y_MIN) && (yt<=NO_MAIN_Y_MAX) ) ) // NO { state=3; } else state=10; return state; } unsigned char BT_return() // //determining the touch for bp main screen { unsigned char state=0; 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; } unsigned char touch_debug() { unsigned char state=0; 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; } 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// int readTouchY(void) // read the Y co-ordinate { DigitalOut YD(PTD2); DigitalIn XL(PTC13); DigitalOut YU(PTC0); YU = 1; YD = 0; AnalogIn XR(PTB0); XL.mode(PullNone); return XR.read_u16(); } int readTouchX(void) // // read the X co-ordinate { DigitalOut XR(PTB0); DigitalIn YD(PTD2); DigitalOut XL(PTC13); XR = 1; XL = 0; AnalogIn YU(PTC0); YD.mode(PullNone); return YU.read_u16(); } void EnableTouch(void) // Enable touch { DigitalIn YD(PTD2); DigitalOut XL(PTC13); 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(PTD2); DigitalOut XL(PTC13); DigitalOut YU(PTC0); DigitalOut XR(PTB0); } uint32_t get_timer() { kc.printf("time=%d",t1.read_ms()); return t1.read_ms(); } void touch_func_with_timer(uint32_t time_ms) { t1.reset(); while(i==1) { t1.start(); if (get_timer()<time_ms) { while(Touch_D)//touch detection { wait_ms(200); ///wait for debounce check if (Touch_D) { Touch_D.fall(&touch1); //determine the touch co-ordinates break; } DisableTouch(); //kc.printf("touch"); } } else { t1.stop(); t1.reset(); DisableTouch(); no_touch(); break; } } }