nikita teggi / Mbed 2 deprecated merged_code2_3rd_nov_2017

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of merged_code2_20sept_2017_4th_oct_2017 by nikita teggi

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