Modification into 17th July New display demo code

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of Ext_Demo_17July2017_newdis by SenseSemi

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers touch_modules.cpp Source File

touch_modules.cpp

00001 #include "mbed.h"
00002 #include "eeprom_pgm.h"
00003 //#include "ili9325.h"
00004 #include "display_modules.h"
00005 #include "touch_modules.h"
00006 //InterruptIn Touch_D(PTD6);
00007 InterruptIn Touch_D(PTD2);
00008 int i;
00009 unsigned int xt;
00010 unsigned int yt;
00011 Serial kc(USBTX, USBRX);
00012 
00013 
00014 void touch1()  //determining the touch co-ordinates
00015  {
00016             xt = (X_MAX*readTouchX()/TOTAL1);
00017             yt = (Y_MAX*readTouchY()/TOTAL1);
00018             kc.printf("%d\n", xt); 
00019               kc.printf("%d\n", yt); 
00020  }
00021 
00022 
00023 void detect_touch()   // detect the touch //debounce
00024 {
00025     
00026 while(i==1)
00027 {
00028     while(Touch_D)//touch detection 
00029     {
00030          wait_ms(200); ///wait for debounce check
00031            if (Touch_D)
00032            {   
00033             
00034              Touch_D.fall(&touch1);
00035                //determine the touch co-ordinates
00036              break;
00037             }
00038         DisableTouch();
00039           //kc.printf("touch");
00040            
00041          }
00042  }
00043   EnableTouch();
00044   
00045   }
00046 
00047 
00048 
00049 unsigned char touch_main()    //determining the touch for home screen
00050 {
00051     
00052     unsigned char state;
00053         
00054                   if ( ((xt >=SYSCFG_MAIN_X_MIN) && (xt<=SYSCFG_MAIN_X_MAX)) && ( (yt>=SYSCFG_MAIN_Y_MIN) && (yt<= SYSCFG_MAIN_Y_MAX) ) ) // system configuration
00055                        {
00056                           
00057                           state=2;
00058                         }
00059     
00060                  else if ( ((xt >=TEST_MAIN_X_MIN) && (xt<=TEST_MAIN_X_MAX)) && ( (yt>=TEST_MAIN_Y_MIN) && (yt<=TEST_MAIN_Y_MAX) ) ) // test
00061                       {
00062                            state=3;
00063                  }   
00064                  else 
00065                      state=10;   
00066                           
00067          return state;     
00068     }
00069    
00070    
00071 unsigned char touch_main_1()    //determining the touch for System Configuration screen
00072 {
00073     
00074     unsigned char state;
00075         
00076                   if ( ((xt >=BLE_MAIN_X_MIN) && (xt<=BLE_MAIN_X_MAX)) && ( (yt>= BLE_MAIN_Y_MIN) && (yt<=BLE_MAIN_Y_MAX) ) ) // ble
00077                        {
00078                           
00079                           state=12;
00080                         }
00081     
00082                  else if ( ((xt >=ERASE_MAIN_X_MIN) && (xt<=ERASE_MAIN_X_MAX)) && ( (yt>=ERASE_MAIN_Y_MIN) && (yt<=ERASE_MAIN_Y_MAX) ) ) // erase
00083                       {
00084                           // state=4;
00085                         
00086                           
00087                        }
00088                  else if ( ((xt >=FILE_MAIN_X_MIN) && (xt<=FILE_MAIN_X_MAX)) && ( (yt>=FILE_MAIN_Y_MIN) && (yt<=FILE_MAIN_Y_MAX) ) ) // file
00089                       {
00090                                 state=11;
00091                          
00092                        }
00093                  else if ( ((xt >=HOME_MAIN_X_MIN) && (xt<=HOME_MAIN_X_MAX)) && ( (yt>=HOME_MAIN_Y_MIN) && (yt<=HOME_MAIN_Y_MAX) ) ) // home
00094                        {
00095                                  state=1;         //////////
00096                         
00097                        }
00098                    else 
00099                      state=10;     
00100                    
00101          return state;     
00102     }
00103 
00104 
00105  unsigned char touch_main_2()    //determining the touch for TEST screen
00106 {
00107     
00108     unsigned char state;
00109         
00110                   if ( ((xt >=BG_MAIN_X_MIN) && (xt<=BG_MAIN_X_MAX)) && ( (yt>=BG_MAIN_Y_MIN) && (yt<=BG_MAIN_Y_MAX) ) ) // GLC
00111                        {
00112                           
00113                           state=4;
00114                         }
00115     
00116                  else if ( ((xt >=ECG_MAIN_X_MIN) && (xt<=ECG_MAIN_X_MAX)) && ( (yt>=ECG_MAIN_Y_MIN) && (yt<=ECG_MAIN_Y_MAX) ) ) // ECG
00117                       {
00118                            state=5;
00119                         
00120                           
00121                        }
00122                  else if ( ((xt >=BP_MAIN_X_MIN) && (xt<=BP_MAIN_X_MAX)) && ( (yt>=BP_MAIN_Y_MIN) && (yt<=BP_MAIN_Y_MAX) ) ) // BP
00123                       {
00124                                 state=6;
00125                          
00126                        }
00127                  else if ( ((xt >= HOME_MAIN_X_MIN) && (xt<= HOME_MAIN_X_MAX)) && ( (yt>=HOME_MAIN_Y_MIN) && (yt<= HOME_MAIN_Y_MAX) ) ) // Home
00128                        {
00129                                  state=1;
00130                         
00131                        }
00132                    
00133                 else 
00134                      state=10;      // default -  goes to wait for a valid touch
00135                    
00136          return state;     
00137     }
00138 
00139 
00140 
00141 
00142 
00143 
00144 unsigned char touch_ecg()     // determining the touch for ecg  main screen
00145 {
00146       
00147       unsigned char state;
00148                  if ( ((xt >=START_MAIN_X_MIN) && (xt<=START_MAIN_X_MAX)) && ( (yt>=START_MAIN_Y_MIN) && (yt<=START_MAIN_Y_MAX) ) ) // START
00149                        {
00150                           
00151                           state=8;
00152                         }
00153     
00154                  else if ( ((xt >=MAIN_X_MIN) && (xt<=MAIN_X_MAX)) && ( (yt>=MAIN_Y_MIN) && (yt<=MAIN_Y_MAX) ) ) // RETURN
00155                       {
00156                           state=3;
00157                  } 
00158                else 
00159                      state=10;   
00160                                    
00161            return state;
00162     }
00163     
00164 
00165 unsigned char touch_ret()     // determining the touch for ecg screen after the test
00166 {
00167       
00168       unsigned char state;
00169       int8_t type=0;
00170        type=eprom_read_8(30);
00171                  
00172                   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// 
00173                       {
00174                                 state=3;
00175                          
00176                        }
00177                  else if ( ((xt >=RETEST_MAIN_X_MIN) && (xt<=RETEST_MAIN_X_MAX)) && ( (yt>=RETEST_MAIN_Y_MIN) && (yt<=RETEST_MAIN_Y_MAX) ) ) // RETEST
00178                        {
00179                                  if (type==0)
00180                                      state=7;
00181                                  else if (type==1)
00182                                      state=8;
00183                                      else if (type==2)
00184                                      state=9;
00185                        }
00186               else 
00187                      state=10;                      
00188            return state;
00189     }
00190     
00191 
00192 
00193 
00194 unsigned char touch_bp()   // //determining the touch for bp main screen
00195 
00196 {
00197         unsigned char state;
00198                 if ( ((xt >=START_MAIN_X_MIN) && (xt<=START_MAIN_X_MAX)) && ( (yt>=START_MAIN_Y_MIN) && (yt<=START_MAIN_Y_MAX) ) ) // START
00199                        {
00200                           
00201                           state=9;
00202                         }
00203     
00204                  else if ( ((xt >=MAIN_X_MIN) && (xt<=MAIN_X_MAX)) && ( (yt>=MAIN_Y_MIN) && (yt<=MAIN_Y_MAX) ) ) // RETURN
00205                       {
00206                           state=3;
00207                  } 
00208                 else 
00209                      state=10;
00210            
00211            return state;
00212     }
00213     
00214     
00215     
00216   unsigned char touch_glc()        //determining the touch for GLC screen
00217     {
00218         unsigned char state;
00219 
00220                /* if ( ((xt >=70) && (xt<=170)) && ( (yt>= 140) && (yt<= 195) ) ) // START
00221                        {
00222                           
00223                           state=7;
00224                         }
00225     
00226                  else if ( ((xt >=70) && (xt<=170)) && ( (yt>=70) && (yt<=140) ) ) // RETURN
00227                       {
00228                            state=3;
00229                  } */
00230                  
00231                    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
00232                        {
00233                           
00234                           state=7;
00235                           eprom_write_16(20,0);  
00236                         }
00237     
00238                  else if ( ((xt >=PP_MAIN_X_MIN) && (xt<=PP_MAIN_X_MAX)) && ( (yt>=PP_MAIN_Y_MIN) && (yt<=PP_MAIN_Y_MAX) ) ) // pp
00239                       {
00240                            state=7;
00241                            eprom_write_16(20,1);    
00242                         
00243                           
00244                        }
00245                  else if ( ((xt >= RANDOM_MAIN_X_MIN) && (xt<=RANDOM_MAIN_X_MAX)) && ( (yt>=RANDOM_MAIN_Y_MIN) && (yt<=RANDOM_MAIN_Y_MAX) ) ) // random
00246                       {
00247                            state=7;
00248                            eprom_write_16(20,2); 
00249                          
00250                        }
00251                  else if ( ((xt >=HOME_MAIN_X_MIN) && (xt<=HOME_MAIN_X_MAX)) && ( (yt>=HOME_MAIN_Y_MIN) && (yt<=HOME_MAIN_Y_MAX) ) ) // return
00252                        {
00253                            state=3;         //////////
00254                  
00255                        }
00256                  
00257                  
00258               else 
00259                      state=10;
00260            
00261            return state;
00262     } 
00263       
00264  
00265  
00266  unsigned char touch_again_ecg()    //determining the touch for Repeat test 
00267 {
00268     
00269     unsigned char state;
00270         
00271                     if ( ((xt >=YES_MAIN_X_MIN) && (xt<=YES_MAIN_X_MAX)) && ( (yt>=YES_MAIN_Y_MIN) && (yt<=YES_MAIN_Y_MAX) ) ) // YES
00272                       {
00273                                 state=8;
00274                          
00275                        }
00276                  else if ( ((xt >=NO_MAIN_X_MIN) && (xt<=NO_MAIN_X_MAX)) && ( (yt>=NO_MAIN_Y_MIN) && (yt<=NO_MAIN_Y_MAX) ) ) // NO
00277                        {
00278                                  state=3;
00279                         
00280                        }
00281                    else 
00282                      state=10; 
00283          return state;     
00284     }
00285  
00286  
00287  unsigned char touch_again_glc()    //determining the touch for Repeat test 
00288 {
00289     
00290     unsigned char state;
00291         
00292                     if ( ((xt >=YES_MAIN_X_MIN) && (xt<=YES_MAIN_X_MAX)) && ( (yt>=YES_MAIN_Y_MIN) && (yt<=YES_MAIN_Y_MAX) ) ) // YES
00293                       {
00294                                 state=7;
00295                          
00296                        }
00297                  else if ( ((xt >=YES_MAIN_Y_MAX) && (xt<=NO_MAIN_Y_MIN)) && ( (yt>=NO_MAIN_Y_MIN) && (yt<=NO_MAIN_Y_MAX) ) ) // NO
00298                        {
00299                                  state=3;
00300                         
00301                        }
00302                    else 
00303                      state=10; 
00304          return state;     
00305     }
00306     
00307    unsigned char touch_again_bp()    //determining the touch for Repeat test 
00308 {
00309     
00310     unsigned char state;
00311         
00312                     if ( ((xt >=YES_MAIN_X_MIN) && (xt<=YES_MAIN_X_MAX)) && ( (yt>=YES_MAIN_Y_MIN) && (yt<=YES_MAIN_Y_MAX) ) ) // YES
00313                       {
00314                                 state=9;
00315                          
00316                        }
00317                  else if ( ((xt >=NO_MAIN_X_MIN) && (xt<=NO_MAIN_X_MAX)) && ( (yt>=NO_MAIN_Y_MIN) && (yt<=NO_MAIN_Y_MAX) ) ) // NO
00318                        {
00319                                  state=3;
00320                         
00321                        }
00322                    else 
00323                      state=10; 
00324          return state;     
00325     } 
00326  
00327  unsigned char BT_return()   // //determining the touch for bp main screen
00328 
00329 {
00330         unsigned char state;
00331                
00332                      if ( ((xt >=MAIN_X_MIN) && (xt<=MAIN_X_MAX)) && ( (yt>=MAIN_Y_MIN) && (yt<=MAIN_Y_MAX) ) ) // RETURN
00333                       {
00334                           state=1;
00335                        } 
00336                 else 
00337                      state=10;
00338            
00339            return state;
00340     } 
00341  
00342  //TOUCH Functionalities for old display//    
00343 
00344 /*int readTouchY(void)      // read the Y co-ordinate
00345 {      
00346     DigitalOut YD(PTD6);
00347      DigitalIn XL(PTD7);
00348      DigitalOut YU(PTC0);
00349      YU = 1;
00350      YD = 0;
00351      AnalogIn XR(PTB0);
00352      XL.mode(PullNone);
00353      return XR.read_u16();
00354 }
00355     
00356     
00357 int readTouchX(void)    // // read the X co-ordinate
00358 {
00359     DigitalOut XR(PTB0);
00360     DigitalIn YD(PTD6);
00361      DigitalOut XL(PTD7);
00362      
00363      XR = 1;
00364      XL = 0;
00365      AnalogIn YU(PTC0);
00366      YD.mode(PullNone);
00367      return YU.read_u16();
00368 }
00369 
00370 void EnableTouch(void)       // Enable touch 
00371 {
00372     
00373     DigitalIn YD(PTD6);
00374     DigitalOut XL(PTD7);
00375     DigitalIn YU(PTC0);
00376     DigitalIn XR(PTB0);
00377      XL=0;
00378       YD.mode(PullUp);
00379      YU.mode(PullNone);
00380      XR.mode(PullNone);
00381     i=1;
00382     Touch_D.fall(&touch1);
00383     Touch_D.enable_irq();
00384    
00385  }
00386 
00387 void DisableTouch (void)    // Disable touch 
00388 {
00389     Touch_D.disable_irq();
00390     i=0;
00391     DigitalOut YD(PTD6);
00392     DigitalOut XL(PTD7);
00393     DigitalOut YU(PTC0);
00394     DigitalOut XR(PTB0);
00395     }
00396  */
00397  
00398  
00399  //TOUCH Functionalities for new display// 
00400  
00401  int readTouchY(void)      // read the Y co-ordinate
00402 {      
00403     DigitalOut YD(PTD2);
00404      DigitalIn XL(PTC13);
00405      DigitalOut YU(PTC0);
00406      YU = 1;
00407      YD = 0;
00408      AnalogIn XR(PTB0);
00409      XL.mode(PullNone);
00410      return XR.read_u16();
00411 }
00412     
00413     
00414 int readTouchX(void)    // // read the X co-ordinate
00415 {
00416     DigitalOut XR(PTB0);
00417     DigitalIn YD(PTD2);
00418      DigitalOut XL(PTC13);
00419      
00420      XR = 1;
00421      XL = 0;
00422      AnalogIn YU(PTC0);
00423      YD.mode(PullNone);
00424      return YU.read_u16();
00425 }
00426 
00427 void EnableTouch(void)       // Enable touch 
00428 {
00429     
00430     DigitalIn YD(PTD2);
00431     DigitalOut XL(PTC13);
00432     DigitalIn YU(PTC0);
00433     DigitalIn XR(PTB0);
00434      XL=0;
00435       YD.mode(PullUp);
00436      YU.mode(PullNone);
00437      XR.mode(PullNone);
00438     i=1;
00439     Touch_D.fall(&touch1);
00440     Touch_D.enable_irq();
00441    
00442  }
00443 
00444 void DisableTouch (void)    // Disable touch 
00445 {
00446     Touch_D.disable_irq();
00447     i=0;
00448     DigitalOut YD(PTD2);
00449     DigitalOut XL(PTC13);
00450     DigitalOut YU(PTC0);
00451     DigitalOut XR(PTB0);
00452     }   
00453     
00454    
00455