Browse Source

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.
xmkb
Pete Johanson 4 years ago
parent
commit
b5e17e3b0f
  1. 39
      app/src/display/main.c

39
app/src/display/main.c

@ -14,6 +14,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <drivers/display.h> #include <drivers/display.h>
#include <lvgl.h> #include <lvgl.h>
#include <zmk/event-manager.h>
#include <zmk/events/activity-state-changed.h>
#include <zmk/display/status_screen.h> #include <zmk/display/status_screen.h>
#define ZMK_DISPLAY_NAME CONFIG_LVGL_DISPLAY_DEV_NAME #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); 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() { int zmk_display_init() {
LOG_DBG(""); LOG_DBG("");
@ -54,10 +68,29 @@ int zmk_display_init() {
lv_scr_load(screen); lv_scr_load(screen);
lv_task_handler(); lv_task_handler();
display_blanking_off(display);
k_timer_start(&display_timer, K_MSEC(10), K_MSEC(10)); start_display_updates();
LOG_DBG(""); LOG_DBG("");
return 0; return 0;
} }
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);
Loading…
Cancel
Save