This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR2512: how to identify long press and short in sensor EVM430-CAPMINI development board

Part Number: MSP430FR2512
Other Parts Discussed in Thread: EVM430-CAPMINI

Hi TI Team,

Planning to add multi-function touch on same touch sensor:

Using EVM430-CAPMINI development board,  is there a way to identify the short press(~1sec) and long press(~10sec) on single sensor button?

Regards,

Walter

  • Hi Walter,

    Yes you can. The scan rate is around 33ms. You can define a counter in the callback function.

    if bTouch == true 
        if bPrevTouch == false, reset the counter; 
        else counter++;
    
        if counter >= 303, report a long touch;
    
    else
        if bPrevTouch == true and counter <= 33, report a short touch
    

    Regards,

    Ling

  • Hi Ling,

    Here is my working callback with our new board for 3 sensors. Planning to insert the code you recommended. What do you mean by "bPrevTouch" above? This "(pButton->bSensorPrevTouch == 0)"?

    --------------------------------------------
    void
    ButtonEventHandler(tSensor *pButton)
    {
    if(pButton->bSensorTouch) // Button is touched
    {
    Now_Key_Value = 0;
    if(pButton->pCycle[0]->pElements[0]->bTouch == 1)
    {
    Now_Key_Value |= Key1;
    LED1_ON; // LED1
    }
    else
    LED1_OFF;
    if(pButton->pCycle[1]->pElements[0]->bTouch == 1)
    {
    Now_Key_Value |= Key2;
    LED2_ON; // LED2
    }
    else
    LED2_OFF;
    if(pButton->pCycle[2]->pElements[0]->bTouch == 1)
    {
    Now_Key_Value |= Key3;
    LED3_ON; //LED3
    }
    else
    LED3_OFF;


    if(pButton->bSensorPrevTouch == 0)
    {
    TA1CTL = TASSEL__SMCLK | MC__UP | TACLR; // SMCLK, up mode, clear TAR
    P2SEL0 |= BIT2; // P2.2 options select
    }
    }
    else // No button is touched. Clear Timer and turn off LEDs
    {
    TA1CTL = 0;
    P1OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3);

    }

    // Save Parameter if updated
    APP_CheckForParamenterUpdate();
    }
  • Hi Walter,

    Yes, you are right.

    Ling
  • Hi Ling,

    The behavior we want is :

    normal short touch - ON led

    5 seconds long touch, release - do something  

    10seconds long touch, release - reset device

    Regards,

    1.First, the short touch not working, if I do in the below:

    if(pButton->bSensorPrevTouch == 1)
    {
      if(Long_Press_Cntr <= 33)
      {

      }

    }

    2. Toggle once if 5 secs, or toggle twice if  10 secs.  It seems ok, how to put sleep in between?

    if(Long_Press_Cntr >= 151)
    {
            if(Long_Press_Cntr < 303)
            { 
            LED4_ON; //LED4
           }
    }
    if(Long_Press_Cntr >= 303)
    {
         LED4_ON; //LED4 

        //sleep
         LED4_OFF; //LED4

        //sleep
         LED4_ON; //LED4
         LED4_OFF; //LED4
    }

    }

    }

    ----------

    void

    ButtonEventHandler(tSensor *pButton)
    {
    if(pButton->bSensorTouch) // Button is touched
    {

    if(pButton->bSensorPrevTouch == 0)
    {
    TA1CTL = TASSEL__SMCLK | MC__UP | TACLR; // SMCLK, up mode, clear TAR
    P2SEL0 |= BIT2; // P2.2 options select

    /* Aztech Modify*/
    Long_Press_Cntr = 0;
    /* end of Aztech Modify*/
    }
    /* Aztech Modify*/
    else
    {
    Long_Press_Cntr++;
    }
    /* end of Aztech Modify*/

    /* Aztech Modify*/

    //report a 5sec/10sec/15sec long touch
    //will work, but is not a 5sectouch remove, 5sec touch remove
    /*if(Long_Press_Cntr == 151 || Long_Press_Cntr == 303 || Long_Press_Cntr == 453)
    {
    LED4_OFF; //LED4
    LED4_ON; //LED4
    }
    */

    /* Aztech Modify*/

    }
    else // No button is touched. Clear Timer and turn off LEDs
    {
    TA1CTL = 0;
    /*AZTECH Modify */
    #if 0
    P2SEL0 &= ~BIT2;
    P2OUT &= ~(BIT2 + BIT3 + BIT4 + BIT5 + BIT6);
    #else
    P1OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3);
    //if bPrevTouch == true and counter <= 33, report a short touch
    if(pButton->bSensorPrevTouch == 1)
    {
    if(Long_Press_Cntr <= 33)
    {
    //not coming here
    Now_Key_Value = 0;
    if(pButton->pCycle[0]->pElements[0]->bTouch == 1)
    {
    Now_Key_Value |= Key1;
    LED1_ON; // LED1
    }
    else
    LED1_OFF;
    if(pButton->pCycle[1]->pElements[0]->bTouch == 1)
    {
    Now_Key_Value |= Key2;
    LED2_ON; // LED2
    }
    else
    LED2_OFF;
    if(pButton->pCycle[2]->pElements[0]->bTouch == 1)
    {
    Now_Key_Value |= Key3;
    LED3_ON; //LED3
    }
    else
    LED3_OFF;
    }

    if(Long_Press_Cntr >= 151)
    {
            if(Long_Press_Cntr < 303)
            { 
            LED4_ON; //LED4
           }
    }
    if(Long_Press_Cntr >= 303)
    {
         LED4_ON; //LED4 
         LED4_OFF; //LED4
         LED4_ON; //LED4
         LED4_OFF; //LED4
    }

    }

    #endif
    /* end of AZTECH Modify */

    }

**Attention** This is a public forum