Skip to content

Commit

Permalink
Improve screen saver wake up event on button press. Avoid invisible b…
Browse files Browse the repository at this point in the history
…utton action.
  • Loading branch information
Mictronics committed Feb 22, 2023
1 parent d94c27f commit 2ae401f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
12 changes: 9 additions & 3 deletions gfx/gfx_gui_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

#define MAIN_MENU_ID 0

extern uint8_t screen_saver_off(void);
extern void screen_saver_task_reset(void);

struct gfx_frame *current_frame;
struct gfx_graphic_menu *current_menu;
struct gfx_frame *splash;
Expand Down Expand Up @@ -87,12 +90,15 @@ void gfx_switch_to_menu(struct gfx_graphic_menu *graphic_menu)
current_menu = graphic_menu;
graphic_menu->draw(graphic_menu);
}
extern void screen_saver_on(void);
extern void screen_saver_task_reset(void);

void gfx_handle_button(uint8_t keycode)
{
screen_saver_on();
screen_saver_task_reset();
if(screen_saver_off()) {
// When screen saver was on we just wake up the display on the first button press
// but don't handle the event to avoid "invisible" button action.
return;
}
if (gfx_in_menu())
current_menu->handle_button(current_menu, keycode);
else
Expand Down
11 changes: 8 additions & 3 deletions screens/settings/screensaver.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#define MIN_SCREEN_SAVER_TIME 5
#define MAX_SCREEN_SAVER_TIME_MIN 15

void screen_saver_off(void);
void screen_saver_on(void);
uint8_t screen_saver_off(void);
uint8_t screen_saver_get_time_seconds(void);

typedef enum {
Expand All @@ -29,13 +29,18 @@ typedef enum {
static screen_saver_unit_e screen_saver_unit = SCREEN_SAVER_DEFAULT_UNIT;
static uint8_t screen_saver_enabled = SCREEN_SAVER_DEFAULT_ENABLE;
static uint8_t screen_saver_time = SCREEN_SAVER_DEFAULT_TIME;
static uint8_t screen_saver_status = 0;

void screen_saver_off(void){
void screen_saver_on(void){
ssd1306_display_off();
screen_saver_status = 1;
}

void screen_saver_on(void){
uint8_t screen_saver_off(void){
uint8_t was = screen_saver_status;
ssd1306_display_on();
screen_saver_status = 0;
return was;
}


Expand Down
4 changes: 2 additions & 2 deletions tasks/screensaver_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

void screen_saver_task_reset(void);
extern uint8_t screen_saver_get_time_seconds(void);
extern void screen_saver_off(void);
extern void screen_saver_on(void);
volatile int screen_saver_timeout = 0;

void screen_saver_task_reset(void) {
Expand All @@ -32,7 +32,7 @@ static void save_screen(void *data)
if(screen_saver_timeout < t) {
++screen_saver_timeout;
} else {
screen_saver_off();
screen_saver_on();
}

}
Expand Down

0 comments on commit 2ae401f

Please sign in to comment.