Monday, April 23rd 2018, 7:41am UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Frank_D

Beginner

Date of registration: Jan 5th 2018

Posts: 2

1

Friday, January 5th 2018, 11:44pm

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

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 561

2

Monday, January 8th 2018, 2:27pm

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/C++ Source code

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


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/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
void TimerInterrupt(void) {
  TEXT_SetText(hText, "New Text");  // Marks the Text widget also as invalid
}

void MainTask(void) {
  GUI_Init();
  hText = TEXT_CreateEx(10, 10, 80, 20, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_TEXT0, "Text");
  while (1) {
	GUI_Delay(100);  // Redraws all invalid windows among other things, would work with GUI_Exec() as well
  }
}


Regards
Sven

Frank_D

Beginner

Date of registration: Jan 5th 2018

Posts: 2

3

Tuesday, January 9th 2018, 12:11am

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

Similar threads