From 8fdfcb279e0c121dd9a3fa5241b99aaac92203f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B5=A9?= <1131761436@qq.com> Date: Fri, 18 Sep 2026 11:57:40 +0800 Subject: [PATCH 1/2] Add CC1101 to implement 'Hold ESC 3s to return home' --- src/core/cc1101_chat_app.cpp | 82 ++++++++++++++++++++++++++++-- src/core/cc1101_chat_app.hpp | 6 +++ src/radio/linux_cc1101_backend.cpp | 2 +- 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/core/cc1101_chat_app.cpp b/src/core/cc1101_chat_app.cpp index 1423141..71dd50d 100644 --- a/src/core/cc1101_chat_app.cpp +++ b/src/core/cc1101_chat_app.cpp @@ -9,6 +9,8 @@ namespace cc1101_chat { namespace { +constexpr uint32_t kEscHintDelayMs = 500; + #if LV_USE_SDL bool sdlHelpKeyHeld() { @@ -113,6 +115,10 @@ void CC1101ChatApp::start() _started = true; _quit_requested = false; _help_pressed = false; + _esc_hold_active = false; + _esc_hold_hint_shown = false; + _esc_down_ms = 0; + _esc_hold_hint = nullptr; lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0x000000), LV_PART_MAIN); lv_obj_set_style_bg_opa(lv_screen_active(), LV_OPA_COVER, LV_PART_MAIN); setupInputGroup(); @@ -140,6 +146,7 @@ void CC1101ChatApp::stop() _current_vm->onExit(); _current_vm = nullptr; } + hideEscHoldHint(); _help_view.reset(); _model.stop(); if (_input_group) { @@ -157,6 +164,45 @@ void CC1101ChatApp::stop() } _started = false; _help_pressed = false; + _esc_hold_active = false; + _esc_hold_hint_shown = false; + _esc_down_ms = 0; +} + +void CC1101ChatApp::showEscHoldHint() +{ + if (_esc_hold_hint) { + return; + } + + _esc_hold_hint = lv_obj_create(lv_layer_top()); + if (!_esc_hold_hint) { + return; + } + lv_obj_remove_style_all(_esc_hold_hint); + lv_obj_set_size(_esc_hold_hint, 224, 30); + lv_obj_align(_esc_hold_hint, LV_ALIGN_TOP_MID, 0, 6); + lv_obj_set_style_bg_color(_esc_hold_hint, lv_color_hex(0x1B1E24), LV_PART_MAIN); + lv_obj_set_style_bg_opa(_esc_hold_hint, LV_OPA_COVER, LV_PART_MAIN); + lv_obj_set_style_border_width(_esc_hold_hint, 1, LV_PART_MAIN); + lv_obj_set_style_border_color(_esc_hold_hint, lv_color_hex(0x5A6070), LV_PART_MAIN); + lv_obj_set_style_radius(_esc_hold_hint, 4, LV_PART_MAIN); + + lv_obj_t* label = lv_label_create(_esc_hold_hint); + lv_label_set_text(label, "Hold ESC 3s to return home"); + lv_obj_set_style_text_color(label, lv_color_hex(0xF2F4F7), LV_PART_MAIN); + lv_obj_set_style_text_font(label, &lv_font_montserrat_12, LV_PART_MAIN); + lv_obj_center(label); + lv_obj_move_foreground(_esc_hold_hint); +} + +void CC1101ChatApp::hideEscHoldHint() +{ + if (!_esc_hold_hint) { + return; + } + lv_obj_del(_esc_hold_hint); + _esc_hold_hint = nullptr; } void CC1101ChatApp::onKey(uint32_t key) @@ -204,14 +250,34 @@ bool CC1101ChatApp::onLvglKeyState(uint32_t lvKey, const char* utf8, bool presse return true; } + if (lvKey == LV_KEY_ESC) { + if (!pressed) { + if (_esc_hold_active) { + _esc_hold_active = false; + _esc_hold_hint_shown = false; + hideEscHoldHint(); + } + return true; + } + if (_help_view && _help_view->visible()) { + onKey('\x1b'); + return true; + } + if (_router.page() == PageId::Chat && !_chat_vm.modalActive()) { + _esc_hold_active = true; + _esc_hold_hint_shown = false; + _esc_down_ms = lv_tick_get(); + return true; + } + onKey('\x1b'); + return true; + } + if (!pressed) { return true; } switch (lvKey) { - case LV_KEY_ESC: - onKey('\x1b'); - return true; case LV_KEY_ENTER: onKey('\r'); return true; @@ -296,6 +362,16 @@ void CC1101ChatApp::tick(uint32_t nowMs) if (_current_view) { _current_view->tick(nowMs); } + if (_esc_hold_active) { + if (_router.page() != PageId::Chat || _chat_vm.modalActive()) { + _esc_hold_active = false; + _esc_hold_hint_shown = false; + hideEscHoldHint(); + } else if (!_esc_hold_hint_shown && nowMs - _esc_down_ms >= kEscHintDelayMs) { + _esc_hold_hint_shown = true; + showEscHoldHint(); + } + } if (_help_view && _help_view->visible()) { _help_view->keepFocus(); } diff --git a/src/core/cc1101_chat_app.hpp b/src/core/cc1101_chat_app.hpp index 33c7f33..0be7977 100644 --- a/src/core/cc1101_chat_app.hpp +++ b/src/core/cc1101_chat_app.hpp @@ -44,6 +44,10 @@ class CC1101ChatApp { bool _quit_requested = false; bool _started = false; bool _help_pressed = false; + bool _esc_hold_active = false; + bool _esc_hold_hint_shown = false; + uint32_t _esc_down_ms = 0; + lv_obj_t* _esc_hold_hint = nullptr; std::array _view_models; std::array _views; @@ -52,6 +56,8 @@ class CC1101ChatApp { View* viewFor(PageId page); void setupInputGroup(); void setCurrentPage(PageId page); + void showEscHoldHint(); + void hideEscHoldHint(); static void onRouteChanged(void* context, const PageId& page); static void onKeyboardEvent(lv_event_t* event); }; diff --git a/src/radio/linux_cc1101_backend.cpp b/src/radio/linux_cc1101_backend.cpp index 97eaada..ae6b1da 100644 --- a/src/radio/linux_cc1101_backend.cpp +++ b/src/radio/linux_cc1101_backend.cpp @@ -22,7 +22,7 @@ namespace { using Clock = std::chrono::steady_clock; constexpr auto kPowerSettle = - std::chrono::milliseconds{500}; + std::chrono::milliseconds{1500}; uint64_t monotonicMilliseconds() { From 6fd5b6db23b0e213e4cb514f3aecadf817ed0eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B5=A9?= <1131761436@qq.com> Date: Fri, 18 Sep 2026 14:12:36 +0800 Subject: [PATCH 2/2] Limit CC1101 ESC exit hint to base pages --- src/core/cc1101_chat_app.cpp | 18 ++++++++++++++---- src/core/cc1101_chat_app.hpp | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/core/cc1101_chat_app.cpp b/src/core/cc1101_chat_app.cpp index 71dd50d..d0011ae 100644 --- a/src/core/cc1101_chat_app.cpp +++ b/src/core/cc1101_chat_app.cpp @@ -9,7 +9,7 @@ namespace cc1101_chat { namespace { -constexpr uint32_t kEscHintDelayMs = 500; +constexpr uint32_t kEscHintDelayMs = 50; #if LV_USE_SDL bool sdlHelpKeyHeld() @@ -205,6 +205,16 @@ void CC1101ChatApp::hideEscHoldHint() _esc_hold_hint = nullptr; } +bool CC1101ChatApp::escExitAllowed() +{ + if (_router.page() != PageId::Chat || _chat_vm.modalActive()) { + return false; + } + + const ChatSection section = _chat_vm.section().get(); + return section == ChatSection::Messages || section == ChatSection::Info; +} + void CC1101ChatApp::onKey(uint32_t key) { if (key == cc1101_chat_key::Help && _help_view) { @@ -219,7 +229,7 @@ void CC1101ChatApp::onKey(uint32_t key) return; } - if (key == '\x1b' && _router.page() == PageId::Chat && !_chat_vm.modalActive()) { + if (key == '\x1b' && escExitAllowed()) { spdlog::info("CC1101ChatApp: quit requested"); _quit_requested = true; return; @@ -263,7 +273,7 @@ bool CC1101ChatApp::onLvglKeyState(uint32_t lvKey, const char* utf8, bool presse onKey('\x1b'); return true; } - if (_router.page() == PageId::Chat && !_chat_vm.modalActive()) { + if (escExitAllowed()) { _esc_hold_active = true; _esc_hold_hint_shown = false; _esc_down_ms = lv_tick_get(); @@ -363,7 +373,7 @@ void CC1101ChatApp::tick(uint32_t nowMs) _current_view->tick(nowMs); } if (_esc_hold_active) { - if (_router.page() != PageId::Chat || _chat_vm.modalActive()) { + if (!escExitAllowed()) { _esc_hold_active = false; _esc_hold_hint_shown = false; hideEscHoldHint(); diff --git a/src/core/cc1101_chat_app.hpp b/src/core/cc1101_chat_app.hpp index 0be7977..35d0869 100644 --- a/src/core/cc1101_chat_app.hpp +++ b/src/core/cc1101_chat_app.hpp @@ -56,6 +56,7 @@ class CC1101ChatApp { View* viewFor(PageId page); void setupInputGroup(); void setCurrentPage(PageId page); + bool escExitAllowed(); void showEscHoldHint(); void hideEscHoldHint(); static void onRouteChanged(void* context, const PageId& page);