Friday, April 20th 2018, 12:33pm 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.

danilotto

Beginner

Date of registration: Jun 9th 2017

Posts: 4

1

Wednesday, February 21st 2018, 4:16pm

Restart timer when a Window become visible

Hi all,

I have an application where, in the main window, after 5 seconds of inactivity, display controller and backlight are switched off, then, touching the screen, they are activated again.
I create a timer:

C/C++ Source code

1
2
case WM_INIT_DIALOG:
    hTimer = WM_CreateTimer(pMsg->hWin, 0, 5000, 0);


In the timer expired messages I switch off the screen (excuse me for the crude and not readable method, it will be changed after)...

C/C++ Source code

1
2
3
4
case WM_TIMER:
    *(__IO uint16_t *) ((uint32_t)0x60000000) = 0x0010;												                // put display controller in sleep mode (see SSD1963 datasheet)
    __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0);													// disable display backlight
    break;


Then, when the screen is touched, the LCD is enabled again and the timer restarted:

C/C++ Source code

1
2
3
4
5
case WM_TOUCH:
   *(__IO uint16_t *) ((uint32_t)0x60000000) = 0x0011;												// put display controller out sleep mode (see SSD1963 datasheet)
   __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 50);											//enable display backlight
    WM_RestartTimer(hTimer, 5000);															        //restart display sleep timer
   break;


Then, pressing a button on the main screen I create a new window with a setting menu and delete the timer because, leaving the main screen, display must not be switched off.

C/C++ Source code

1
2
3
4
5
6
7
 case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
				inSettings = 1;
				WM_DeleteTimer(hTimer);
				CreateSettings();
        // USER END
        break;


The background window is not deleted but when I leave the setting menu only the new window is deleted and the background window gets visibility.
How do I activate the timer again when the background windows become visible again?

Thanks

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 561

2

Wednesday, February 21st 2018, 4:58pm

Hi,

You can react on WM_DELETE of the setting menu and create a timer attached to the main window.

Like this:

C/C++ Source code

1
2
3
4
  case WM_DELETE:
	hParent = WM_GetParent(pMsg->hWin);
	WM_CreateTimer(hParent, ID_TIMER, 5000, 0);
	break;


If the main window is not the parent you can also save its handle in a global variable.

You can also try to react on WM_NOTIFY_VIS_CHANGED in the callback of the main window.

Regards
Sven

Similar threads