From b5e17e3b0f527bea95d27db1b27d5a4be3fed4a1 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Thu, 10 Dec 2020 00:42:05 -0500 Subject: [PATCH] feature(display): Blank display on idle/sleep. * Set display blanking, and stop refresh timer for displays when the activity state goes to idle/sleep, and resume when transitioning to active again. --- app/src/display/main.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/app/src/display/main.c b/app/src/display/main.c index 36838973..ea1e21ab 100644 --- a/app/src/display/main.c +++ b/app/src/display/main.c @@ -14,6 +14,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include +#include +#include #include #define ZMK_DISPLAY_NAME CONFIG_LVGL_DISPLAY_DEV_NAME @@ -35,6 +37,18 @@ void display_timer_cb() { k_work_submit(&display_tick_work); } K_TIMER_DEFINE(display_timer, display_timer_cb, NULL); +static void start_display_updates() { + display_blanking_off(display); + + k_timer_start(&display_timer, K_MSEC(10), K_MSEC(10)); +} + +static void stop_display_updates() { + display_blanking_on(display); + + k_timer_stop(&display_timer); +} + int zmk_display_init() { LOG_DBG(""); @@ -54,10 +68,29 @@ int zmk_display_init() { lv_scr_load(screen); lv_task_handler(); - display_blanking_off(display); - k_timer_start(&display_timer, K_MSEC(10), K_MSEC(10)); + start_display_updates(); LOG_DBG(""); return 0; -} \ No newline at end of file +} + +int display_event_handler(const struct zmk_event_header *eh) { + struct activity_state_changed *ev = cast_activity_state_changed(eh); + switch (ev->state) { + case ZMK_ACTIVITY_ACTIVE: + start_display_updates(); + break; + case ZMK_ACTIVITY_IDLE: + case ZMK_ACTIVITY_SLEEP: + stop_display_updates(); + break; + default: + LOG_WRN("Unhandled activity state: %d", ev->state); + return -EINVAL; + } + return 0; +} + +ZMK_LISTENER(display, display_event_handler); +ZMK_SUBSCRIPTION(display, activity_state_changed); \ No newline at end of file