From 14d4d54c729e8f9db203c0e7497abc07579ec8f6 Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Wed, 8 Jul 2026 20:43:01 +0200 Subject: [PATCH] both button press locks device in joystick ui --- zephcore/helpers/ui-joystick/joystick_defs.h | 1 + .../helpers/ui-joystick/joystick_ui_task.cpp | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/zephcore/helpers/ui-joystick/joystick_defs.h b/zephcore/helpers/ui-joystick/joystick_defs.h index 1995056..aeda5b1 100644 --- a/zephcore/helpers/ui-joystick/joystick_defs.h +++ b/zephcore/helpers/ui-joystick/joystick_defs.h @@ -22,6 +22,7 @@ #define KEY_ENTER_LONG 0xF1 /* long press enter */ #define KEY_TO_TOP 0xF2 /* long press up → page up */ #define KEY_TO_BOTTOM 0xF3 /* long press down → page down */ +#define KEY_LOCK 0xF4 /* user button + joystick center held together → screen lock */ /* Global action keys emitted by multi tap filter, handled in loop() */ #define KEY_FLOOD_ADVERT 0x42 /* INPUT_KEY_B: 2 taps → flood advert */ diff --git a/zephcore/helpers/ui-joystick/joystick_ui_task.cpp b/zephcore/helpers/ui-joystick/joystick_ui_task.cpp index 15d0aec..76e47be 100644 --- a/zephcore/helpers/ui-joystick/joystick_ui_task.cpp +++ b/zephcore/helpers/ui-joystick/joystick_ui_task.cpp @@ -372,6 +372,32 @@ static void joystick_ui_input_cb(struct input_event *evt, void *user_data) } #endif + /* Screen-lock combo: user button (INPUT_KEY_0) + joystick center + * (INPUT_KEY_ENTER) held simultaneously. Tracked on raw press/release, + * which are visible here on the global input bus before the per-key + * handling below (INPUT_KEY_0 is otherwise only consumed by the + * longpress/multi-tap filters). Latched so it fires once per combo + * until at least one of the two is released; the stray key events the + * two buttons emit afterwards land in the locked handler harmlessly. */ + static bool s_userbtn_down; + static bool s_center_down; + static bool s_lock_combo_latched; + if (evt->code == INPUT_KEY_0) { + s_userbtn_down = (evt->value != 0); + } else if (evt->code == INPUT_KEY_ENTER) { + s_center_down = (evt->value != 0); + } + if (s_userbtn_down && s_center_down) { + if (!s_lock_combo_latched) { + s_lock_combo_latched = true; + if (joystick_queue_initialized) { + JoystickUITask::enqueueKey(KEY_LOCK); + } + } + } else { + s_lock_combo_latched = false; + } + /* Long press fires on RELEASE so hold duration is known */ if (evt->code == INPUT_KEY_ENTER) { if (evt->value) { @@ -809,6 +835,18 @@ void JoystickUITask::loop() continue; } + if (key == KEY_LOCK) { + /* Manual lock combo — engage now and stop the idle timer + * (unlock reschedules it). Same locked state the idle + * lockTimerCb would set. */ + _locked = true; + _lock_step = 0; + k_timer_stop(&_lock_timer); + _render_immediate = true; + _pending_render = true; + continue; + } + scheduleLockTimer(); bool consumed = false; if (key == KEY_BUZZ_TOGGLE) {