export test

Dependencies:   SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217

Fork of Int_Demo_09May2017_Suhasini_HRavg_Nikita_ili9341 by nikita teggi

touch_modules.cpp

Committer:
nikitateggi
Date:
2017-07-08
Revision:
29:7edc76b15e3d
Parent:
24:d992ee8369f4
Child:
31:37d3ae1fa1eb

File content as of revision 29:7edc76b15e3d:

#include "mbed.h"
#include "eeprom_pgm.h"
//#include "ili9325.h"
#include "display_modules.h"
#include "touch_modules.h"
//InterruptIn Touch_D(PTD6);
InterruptIn Touch_D(PTD2);
int i;
unsigned int xt;
unsigned int yt;
Serial kc(USBTX, USBRX);


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()   // detect the touch //debounce
{
    
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");
           
         }
 }
  EnableTouch();
  
  }



unsigned char touch_main()    //determining the touch for home screen
{
    
    unsigned char state;
        
                  if ( ((xt >=SYSCFG_MAIN_X_MIN) && (xt<=SYSCFG_MAIN_X_MAX)) && ( (yt>=SYSCFG_MAIN_Y_MIN) && (yt<= SYSCFG_MAIN_Y_MAX) ) ) // system configuration
                       {
                          
                          state=2;
                        }
    
                 else if ( ((xt >=TEST_MAIN_X_MIN) && (xt<=TEST_MAIN_X_MAX)) && ( (yt>=TEST_MAIN_Y_MIN) && (yt<=TEST_MAIN_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;
        
                  if ( ((xt >=BLE_MAIN_X_MIN) && (xt<=BLE_MAIN_X_MAX)) && ( (yt>= BLE_MAIN_Y_MIN) && (yt<=BLE_MAIN_Y_MAX) ) ) // ble
                       {
                          
                          state=12;
                        }
    
                 else if ( ((xt >=ERASE_MAIN_X_MIN) && (xt<=ERASE_MAIN_X_MAX)) && ( (yt>=ERASE_MAIN_Y_MIN) && (yt<=ERASE_MAIN_Y_MAX) ) ) // erase
                      {
                          // state=4;
                        
                          
                       }
                 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;
                         
                       }
                 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 
                     state=10;     
                   
         return state;     
    }


 unsigned char touch_main_2()    //determining the touch for TEST screen
{
    
    unsigned char state;
        
                  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 
                     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;
                 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 >=RET_MAIN_X_MIN) && (xt<=RET_MAIN_X_MAX)) && ( (yt>=RET_MAIN_Y_MIN) && (yt<=RET_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;
      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_MAIN_X_MIN) && (xt<=RETEST_MAIN_X_MAX)) && ( (yt>=RETEST_MAIN_Y_MIN) && (yt<=RETEST_MAIN_Y_MAX) ) ) // RETEST
                       {
                                 if (type==0)
                                     state=7;
                                 else if (type==1)
                                     state=8;
                                     else if (type==2)
                                     state=9;
                       }
              else 
                     state=10;                      
           return state;
    }
    



unsigned char touch_bp()   // //determining the touch for bp main screen

{
        unsigned char state;
                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 >=RET_MAIN_X_MIN) && (xt<=RET_MAIN_X_MAX)) && ( (yt>=RET_MAIN_Y_MIN) && (yt<=RET_MAIN_Y_MAX) ) ) // RETURN
                      {
                          state=3;
                 } 
                else 
                     state=10;
           
           return state;
    }
    
    
    
  unsigned char touch_glc()        //determining the touch for GLC screen
    {
        unsigned char state;

               /* 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 >=HOME_MAIN_X_MIN) && (xt<=HOME_MAIN_X_MAX)) && ( (yt>=HOME_MAIN_Y_MIN) && (yt<=HOME_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;
        
                    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;
        
                    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;
        
                    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;     
    } 
 
 
 
 //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();
}
    
    
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 
{
    
    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);
    }
 */
 
 
 //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);
    }