Commit a404ce4c authored by Jeffrey Lee's avatar Jeffrey Lee

Power saving tweaks & timer fixes

Detail:
  * When help is enabled, use event_poll_idle() (i.e. Wimp_PollIdle) instead of regular event_poll() to limit our update rate to a sensible value
  * Adjust send_help_request() so that it won't send another request if the pointer state hasn't changed since the last request (otherwise constant wimp message activity will prevent the Wimp from entering low power mode)
  * Fix a couple of time value comparisons to not be subject to problems when the monotonic timer wraps around
  Files changed: c/main, h/defines
Admin:
  Tested on Raspberry Pi 3
  Fixes issue reported on forums with !Help preventing the system from switching to low CPU speed:
  https://www.riscosopen.org/forum/forums/4/topics/9074


Version 3.24. Tagged as 'Help2-3_24'
parent 98ddc415
/* (3.23)
/* (3.24)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 3.23
#define Module_MajorVersion_CMHG 3.24
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 30 Oct 2016
#define Module_Date_CMHG 23 Jul 2017
#define Module_MajorVersion "3.23"
#define Module_Version 323
#define Module_MajorVersion "3.24"
#define Module_Version 324
#define Module_MinorVersion ""
#define Module_Date "30 Oct 2016"
#define Module_Date "23 Jul 2017"
#define Module_ApplicationDate "30-Oct-16"
#define Module_ApplicationDate "23-Jul-17"
#define Module_ComponentName "Help2"
#define Module_ComponentPath "castle/RiscOS/Sources/Apps/Help2"
#define Module_FullVersion "3.23"
#define Module_HelpVersion "3.23 (30 Oct 2016)"
#define Module_LibraryVersionInfo "3:23"
#define Module_FullVersion "3.24"
#define Module_HelpVersion "3.24 (23 Jul 2017)"
#define Module_LibraryVersionInfo "3:24"
......@@ -70,8 +70,8 @@ static char fontname[256]; /* the chosen font name */
/* Status variables */
static int screen_w, screen_h; /* Width and height of screen in the current mode */
static int request_handle=0; /* Task handle of app that last help request was sent to */
static int request_x=-1, request_y=-1; /* x and y co-ords of the last help request sent */
static int reply_time=0, reply_x=-1, reply_y=-1; /* The time and position of the last help reply received */
static WimpGetPointerInfoBlock request_pi; /* Pointer location + icon that help request was last sent to */
static int reply_time=-1, reply_x=-1, reply_y=-1;/* The time and position of the last help reply received */
static int check_time=0, check_x=-1, check_y=-1; /* The time & position of the last check */
static int still_time=0; /* How long the pointer has been still for */
static int num_icons=-1; /* Current number of icons in the help box */
......@@ -214,9 +214,10 @@ static _kernel_oserror* update_help_box(char* string, int length)
if (length>1024) return common_error(messages_lookup("Error4"));
strcpy(help_box_message, string);
reply_x = request_x;
reply_y = request_y;
reply_x = request_pi.x;
reply_y = request_pi.y;
_swix(OS_ReadMonotonicTime, _OUT(0), &reply_time);
if (reply_time==-1) reply_time = 0; /* Avoid getting confused with the reset value */
/* Find the size of the ' ' in the helpbox font */
_swix(Font_ConverttoOS, _INR(1, 2)|_OUT(1), return_string_length(helpbox_font_handle, " "), 0,
......@@ -404,7 +405,7 @@ static void check_new_help_message(char* message)
* *
* In: gpi -> block returned by Wimp_GetPointerInfo *
* *
* Globals: request_x, request_y *
* Globals: request_pi *
*---------------------------------------------------------------------------*/
static void send_help_request(WimpGetPointerInfoBlock* gpi)
......@@ -414,11 +415,14 @@ static void send_help_request(WimpGetPointerInfoBlock* gpi)
char token[12];
int icon = gpi->icon_handle;
/* Don't bother sendig requests to ourself */
/* Don't bother sending requests to ourself */
if ( (gpi->window_handle == help_box_wimp) || (gpi->window_handle == shadow_wimp) ) return;
request_x = gpi->x;
request_y = gpi->y;
/* Don't bother sending if the mouse state hasn't changed since the last request - otherwise the constant message traffic will prevent the Wimp from lowering the CPU speed
Note that we check the entire state, just in case the window/icon has changed without the mouse moving (e.g. close icon clicked) */
if ( !memcmp(&request_pi,gpi,sizeof(WimpGetPointerInfoBlock)) ) return;
request_pi = *gpi;
if ( (icon<=-2) && (icon>=-14) )
{
......@@ -683,14 +687,14 @@ static int null_event(int event_code, WimpPollBlock *event, IdBlock *id_block, v
_swix(OS_ReadMonotonicTime, _OUT(0), &time);
/* Check for timeout */
if ( (reply_time > -1) && (timeout > 0) && (time > reply_time + timeout) )
if ( (reply_time != -1) && (timeout > 0) && (time - reply_time > timeout) )
{
remove_help_box();
still_time = 0;
}
/* We check the position of the pointer every n centiseconds */
if ( time > check_time + DelayBetweenChecks )
if ( time - check_time > DelayBetweenChecks )
{
/* Have we moved since the last check? */
if ( (check_x >= gpi.x-still_distance) && (check_x <= gpi.x+still_distance)
......@@ -839,7 +843,16 @@ int main(int argc, char **argv)
while (TRUE)
{
error_trap(event_poll(&event_code, &wpb, NULL), 0);
if (help_on)
{
unsigned int time;
_swix(OS_ReadMonotonicTime, _OUT(0), &time);
error_trap(event_poll_idle(&event_code, &wpb, time + NullPollRate, NULL), 0);
}
else
{
error_trap(event_poll(&event_code, &wpb, NULL), 0);
}
}
return 0;
......
......@@ -25,6 +25,9 @@
/* Delay between help requests (cs) */
#define DelayBetweenChecks 10
/* Delay between null poll events (cs), essentially limits our max responsiveness */
#define NullPollRate 4
/* CMOS Double click cancel distance byte */
#define WimpDoubleClickMove 22
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment