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.

LAUNCHXL-CC26X2R1: How to use button led code in simple central project?

Part Number: LAUNCHXL-CC26X2R1

I used example projects (Simple_Central & buttonled), Simple Certral for BLE concept and buttonled for multiple button function on the single button (long press, short press, double clicked & GetKeyPressDuration ) , but I did not understood how can I call handle = Button_open(CONFIG_BUTTON0, buttonCallbackFxn, &params);( reference by this link ) and were we can call in SimpleCertral.c, we tried to call button open API in SimpleCentral_init()  but it is giving NULL value because the button handler used one timer which we don't know and we have already one timer use in  our Simple Central project. I request you please suggest me any  code.   

 

  • Hey Prasad,

    The simple_central example already makes use of the buttons in the two button menu. For this reason your calls may not work as the peripheral pin is already setup. Please see the project readme for information on this. Additionally you can navigate to the code and find the Board_initKeys() initialization inside  SimpleCentral_init().

    You can add specific pin based functionality by using SimpleCentral_handleKeys(), which is the called after an event is posted by the callbackFxn (SimpleCentral_keyChangeHandler)  that is set by default in the application.

  • Hello Ammar,

    We are working on the same project and we want to implement short and long press function on the Simple_Central we already implement  one more key in Board_initKeys() so that time tree key is running in our project but on the 3rd key has required long and short function.

    in board_key.c

    static void Board_keyCallback(PIN_Handle hPin, PIN_Id pinId)
    {
    keysPressed = 0;
    #if defined(CC26X2R1_LAUNCHXL) || defined(CC2652RB_LAUNCHXL) || defined(CC13X2R1_LAUNCHXL) || \
    defined (CC13X2P1_LAUNCHXL) || defined (CC13X2P_2_LAUNCHXL) || defined (CC13X2P_4_LAUNCHXL) || \
    defined (CC2652PSIP_LP) || defined (CC2652RSIP_LP) || defined (CC2652R7_LP) || defined (CC1352P7_1_LP) || \
    defined (CC1352P7_4_LP) || defined (CC2651P3_LP) || defined (CC2651R3_LP)
    
    if ( PIN_getInputValue(CONFIG_PIN_BTN1) == 0 )
    {
    keysPressed |= KEY_LEFT;
    }
    
    if ( PIN_getInputValue(CONFIG_PIN_BTN2) == 0 )
    {
    keysPressed |= KEY_RIGHT;
    }
    
    if ( PIN_getInputValue(CONFIG_PIN_BTN3) == 0 )
    {
    keysPressed |= KEY_DOWN;
    }
    #elif defined(CC2650_LAUNCHXL) || defined(CC2640R2_LAUNCHXL) || defined(CC1350_LAUNCHXL)
    if ( PIN_getInputValue(Board_BTN1) == 0 )
    {
    keysPressed |= KEY_LEFT;
    }
    
    if ( PIN_getInputValue(Board_BTN2) == 0 )
    {
    keysPressed |= KEY_RIGHT;
    }
    #elif defined(CC2650DK_7ID) || defined(CC1350DK_7XD)
    if ( PIN_getInputValue(Board_KEY_SELECT) == 0 )
    {
    keysPressed |= KEY_SELECT;
    }
    
    if ( PIN_getInputValue(Board_KEY_UP) == 0 )
    {
    keysPressed |= KEY_UP;
    }
    
    if ( PIN_getInputValue(Board_KEY_DOWN) == 0 )
    {
    keysPressed |= KEY_DOWN;
    }
    
    if ( PIN_getInputValue(Board_KEY_LEFT) == 0 )
    {
    keysPressed |= KEY_LEFT;
    }
    
    if ( PIN_getInputValue(Board_KEY_RIGHT) == 0 )
    {
    keysPressed |= KEY_RIGHT;
    }
    #endif
    
    Util_startClock(&keyChangeClock);
    }


    In side SimpleCentral_handleKeys() how can we implement this  

    if(Button_EV_LONGPRESSED == (events & Button_EV_LONGPRESSED))
    {
    Function1();
    }
    
    if(Button_EV_LONGPRESSED == (events & Button_EV_SHORTPRESSED))
    {
    Function2();
    }
    
    if(Button_EV_DOUBLECLICKED == (events & Button_EV_DOUBLECLICKED))
    {
    Function3();
    }

  • Hey Asutosh,

    Please see the following related thread: https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/621382/ccs-cc2640r2f-cc2640

    In short, you'll have to create a timer to track what you define is a "long press" or "short press" and the "double click" functionality at the application layer. We have a rudimentary example in project_zero (see ProjectZero_bootManagerCheck). I would suggest creating a timer instead of the approach taken in the example though.

  • ProjectZero_bootManagerCheck

    Hello Ammar,

    Thank you for providing the solution. it is working...!PrayPray

  • Thanks for following up. I will mark this thread as closed now.

    If I've resolved your issue, please hit the “This Resolved My Issue” to mark the thread as Resolved. This helps others find the resolved thread easily. Slight smile