summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2020-12-10 00:42:05 -0500
committerPete Johanson <peter@peterjohanson.com>2020-12-14 15:31:10 -0500
commitb5e17e3b0f527bea95d27db1b27d5a4be3fed4a1 (patch)
treef7486706d0d71c3c239e227a9e7ad1477768d2ba
parentf7c16dfe69eb551fa0eb50b8ebcf6f00e23c2bad (diff)
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.
-rw-r--r--app/src/display/main.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/app/src/display/main.c b/app/src/display/main.c
index 3683897..ea1e21a 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 <drivers/display.h>
#include <lvgl.h>
+#include <zmk/event-manager.h>
+#include <zmk/events/activity-state-changed.h>
#include <zmk/display/status_screen.h>
#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