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.

Disabling Push Button Widget after it is pressed



Hi,

I am using the TIVA and Kentec LCD Display, and I would like to ask if it is possible to be able to disable the push button widget after pressing the said button. 

Thanks!

  • Hi Eisen,

    I don't know what is the "said" button in your question. Please check the TivaWare Graphic Library user Guide:

    www.ti.com/.../spmu300a.pdf

    Regards,
    QJ
  • Hi QJ,

    It's like lets say I want to disable the "Start" button in the LCD after pressing it. Is that possible?

     Thanks!

  • Hello Eisen

    Yes, that is possible. Can you please share the call back function for the button press?

    Regards
    Amit
  • This is the part:

    while(1)
    {
    //
    // Start Button is pressed.
    //
    if(PushButtonCallbackSet(g_sStartButton, pfnOnClik) == 0x00)
    {
    ROM_SysCtlDelay(900000); //Delay to ensure no accidental pressing
    UARTprintf("%s\r\n", "RUN");
    }

    //
    // Stop Button is pressed.
    //
    if(PushButtonCallbackSet(g_sStartButton, pfnOnClik)) == 0x00)
    {
    ROM_SysCtlDelay(900000); ////Delay to ensure no accidental pressing
    UARTprintf("%s\r\n", "STP");
    }
    }
    }


    I would like to disable the start button once it is pressed and the same for the stop button.
    Thanks!

    Eisen
  • Hello Eisen,

    If you are using the grlib, then the Push button widget has the ability to call a function on press. It seems that you are using a while 1 loop in main which is not a good idea. Can you perform the same with the callback function called on the button press?

    Regards
    Amit
  • Oh wait sorry, I didn't give the updated code, it is supposed to look like this:

    while(1)
    {
    //
    // Means the Start Button is pressed.
    //
    if(g_sStartButtonState == true)
    {
    ROM_SysCtlDelay(900000);
    UARTprintf("%s\r\n", "RUN");
    }

    //
    // Means the Stop Button is pressed.
    //
    if(g_sStopButtonState == true)
    {
    ROM_SysCtlDelay(900000);
    UARTprintf("%s\r\n", "STP");
    }
    }
    }

    And i used a while 1 loop because my code isn't very complex so I thought that I could just use this. And the disable the code button, do i just add a g_sStartButtonState == false after the UARTprintf?
  • Hello Eisen

    But how are g_sStartButtonState and g_sStoptButtonState are being updated?

    Regards
    Amit
  • I have another code for the Kentec LCD.

    Here is the void part:

    void StartButtonPress(tWidget *pWidget){
    g_sStartButtonState = !g_sStartButtonState; //change StartButtonState to True
    WidgetRemove((tWidget *)&g_sStartButton);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sStopButton);
    WidgetPaint(WIDGET_ROOT);
    }
    //-----------------------------------------------------------------------------
    void StopButtonPress(tWidget *pWidget){
    g_sStopButtonState = !g_sStopButtonState; //change StopButtonState to True
    WidgetRemove((tWidget *)&g_sStopButton);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sStartButton);
    WidgetPaint(WIDGET_ROOT);
    }
  • Hello Eisen,

    There is no disable a push button function. I would create a single button that can toggle between Start and Stop and have the same callback.

    Regards
    Amit
  • Hi Amit,

    Thanks for the suggestion, the button can be used now.

    Eisen
  • Hello Eisen

    If you can share your code on the forum, it may be a useful resource for others.

    Regards
    Amit
  • Hi,

    Yeah here it is for the buttons:

    //-----------------------------------------------------------------------------
    void StartButtonPress(tWidget *pWidget){
    g_sStartButtonState = !g_sStartButtonState; //change StartButtonState to True
    WidgetRemove((tWidget *)&g_sStartButton);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sStopButton);
    WidgetPaint(WIDGET_ROOT);
    }
    //-----------------------------------------------------------------------------
    void StopButtonPress(tWidget *pWidget){
    g_sStopButtonState = !g_sStopButtonState; //change StopButtonState to True
    WidgetRemove((tWidget *)&g_sStopButton);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sStartButton);
    WidgetPaint(WIDGET_ROOT);
    }

    void main(void){
    SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    LCD_Init();
    StartUpScreen();
    while(1)
    {
    WidgetMessageQueueProcess();
    }
    }