MULTIPAGE_IsPageEnabled index

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • MULTIPAGE_IsPageEnabled index

    I am trying to use MULTIPAGE_IsPageEnabled to detect if a specific page is enable to automatically update a TEXT widget on the page. MULTIPAGE_IsPageEnabled is being called from an interrupt routine and I don't want to update it if the page is not enabled as that appears to cause the system to crash. My problem is the index. The page I am concern with is the second of 2 pages i . MULTIPAGE_IsPageEnabled returns true with both 0 and 1 index values when the page is not enabled and the value gets updated. If I use 2 or higher for the index the if statement never evaluates true. Below is code from main.c that creates the pages and my interrupt callback.


    in main.c

    hMultipage0 = MULTIPAGE_CreateEx(GUI_SCALE_RECT(10, 10, 300, 220), 0, WM_CF_SHOW, 0, GUI_ID_MULTIPAGE0);

    WM_HWIN hPageWin;

    hPageWin = WINDOW_CreateEx(GUI_SCALE_RECT(0, 0, 300, 200), WM_HBKWIN, 0, 0, GUI_ID_PAGEWIN1, cbPageWin1);
    MULTIPAGE_AddPage(hMultipage0, hPageWin, "Sliders & spinbox");

    /* Create widgets on page 2 */
    hSlider0 = SLIDER_CreateEx(GUI_SCALE_RECT(60, 160, 200, 30), hPageWin, WM_CF_SHOW, 0, GUI_ID_SLIDER0);
    SLIDER_SetWidth(hSlider0, GUI_SCALE(10));
    SLIDER_SetValue(hSlider0, 50);

    hSlider1 =
    SLIDER_CreateEx(GUI_SCALE_RECT(10, 10, 30, 180), hPageWin, WM_CF_SHOW, SLIDER_CF_VERTICAL, GUI_ID_SLIDER1);
    SLIDER_SetWidth(hSlider1, GUI_SCALE(10));
    SLIDER_SetValue(hSlider1, 50);

    hSpinbox0 = SPINBOX_CreateEx(GUI_SCALE_RECT(100, 80, 100, 50), hPageWin, WM_CF_SHOW, GUI_ID_SPINBOX0, 0, 100);
    SPINBOX_SetFont(hSpinbox0, GUI_LARGE_FONT);
    SPINBOX_SetValue(hSpinbox0, 50);

    hProgbar0 =
    PROGBAR_CreateEx(GUI_SCALE_RECT(60, 10, 200, 40), hPageWin, WM_CF_SHOW, PROGBAR_CF_HORIZONTAL, GUI_ID_PROGBAR0);
    PROGBAR_SetFont(hProgbar0, GUI_LARGE_FONT);
    PROGBAR_SetValue(hProgbar0, 50);


    hPageWin = WINDOW_CreateEx(GUI_SCALE_RECT(0, 0, 300, 200), WM_HBKWIN, 0, 0, GUI_ID_PAGEWIN2, cbPageWin2);
    MULTIPAGE_AddPage(hMultipage0, hPageWin, "readout");
    hText0 = TEXT_CreateEx(10,10,100,20, hPageWin, WM_CF_SHOW, TEXT_CF_LEFT | TEXT_CF_VCENTER,GUI_ID_TEXT0,string);
    hText1 = TEXT_CreateEx(340,10,100,20, hPageWin, WM_CF_SHOW, TEXT_CF_LEFT | TEXT_CF_VCENTER,GUI_ID_TEXT0,time_string);
    TEXT_SetTextColor(hText0,GUI_RED);



    interrupt callback

    void HAL_RTCEx_AlarmBEventCallback(RTC_HandleTypeDef *hrtc)
    {

    HAL_RTC_GetTime(hrtc, &sTime, FORMAT_BIN);

    HAL_RTC_GetDate(hrtc, &sDate, FORMAT_BCD);

    sprintf(time_string, "%02d:%02d:%02d", sTime.Hours,sTime.Minutes,sTime.Seconds);
    TEXT_SetText(hText1, time_string);
    if(MULTIPAGE_IsPageEnabled (hMultipage0, 1))
    {
    WM_Exec();
    }

    Thanks,

    Frank
  • Hi,

    Did you disabled the second page at one point?

    I'm asking because a page will return true when calling MULTIPAGE_IsPageEnabled(), even though it is currently not shown. Maybe MULTIPAGE_GetSelection() is what you should use.

    If you don't want to update the TEXT widget if page 1 is not visible you should also place the TEXT_SetText() call into the if condition, like:

    C Source Code

    1. if (MULTIPAGE_GetSelection(hMultipage0) == 1) {
    2. HAL_RTC_GetTime(hrtc, &sTime, FORMAT_BIN);
    3. HAL_RTC_GetDate(hrtc, &sDate, FORMAT_BCD);
    4. sprintf(time_string, "d:d:d", sTime.Hours,sTime.Minutes,sTime.Seconds);
    5. TEXT_SetText(hText1, time_string);
    6. WM_Exec();
    7. }


    Otherwise it might happen that the TEXT widget gets invalidated at the next call of WM_Exec()/GUI_Exec()/GUI_Delay().

    Another thing is, that we recommend to call functions like GUI_Exec(), WM_Exec() or GUI_Delay() from only one point in your application. A bit like this:

    C Source Code

    1. void TimerInterrupt(void) {
    2. TEXT_SetText(hText, "New Text"); // Marks the Text widget also as invalid
    3. }
    4. void MainTask(void) {
    5. GUI_Init();
    6. hText = TEXT_CreateEx(10, 10, 80, 20, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_TEXT0, "Text");
    7. while (1) {
    8. GUI_Delay(100); // Redraws all invalid windows among other things, would work with GUI_Exec() as well
    9. }
    10. }
    Display All


    Regards
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Thanks for the advice Sven. Your recommendations fixed the issue. I did not disable the page when it was not selected as I was unaware that the page would still be enabled when it is not the selected (top) page. I also took your advice about calling WM_Exec from only one point in the code.

    Frank