From 34dadf7b65bcdf7b054e9c0b9a4f141f41ce0c4e Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 19 Aug 2022 07:00:50 +0200 Subject: [PATCH] fix: Audio/haptic feedback for all hard keys except trim switches (#2201) * Added audio/haptic feedback for all hard keys excpet trim switches. Changed logic from application decides if feedback has to be given (was inconsistent and inefficient) to key driver detects button down and triggers immediate feedback if radio settings allowed for acoustic and/or haptic feedback (radio settings, radio setup, sound set to All) With this change all instances of the application calling for feedback were removed in favor of the centralized approach. This first commit also introduces a dummy function for providing feedback on key presses in boot.cpp because keys.cpp is also used as the bootloader key driver but with no logic to determine if feedback is allowed. Using a define that indicates keys.cpp is compiled for use in the bootloader would make a much nicer and backwards compatible solution. * don't want to change libopenui so silence onKeyPress (application requests feedback) in audio.cpp * made generation of acoustic/haptic feedback conditional on BOOT define, i.e. no feedback if keys.cpp is compiled for the bootloader * removed onKeyPress() * fixed crash on acoustic/haptic feedback on hard keys by restoring keys.cpp and moving logic to LvglWrapper.cpp/keyboardDriverRead(). Removed call to getWindowEvent() which would just call getEvent(false) by directly calling getEvent(false). This allowed to remove getWindowEvent() entirely as it was only used by keyboardDriverRead(). * fix: Audio header include no longer needed --- radio/src/audio.cpp | 5 ----- radio/src/gui/colorlcd/LvglWrapper.cpp | 20 ++++++++++++++----- radio/src/gui/colorlcd/access_settings.cpp | 1 - radio/src/gui/colorlcd/color_editor_popup.cpp | 1 - radio/src/gui/colorlcd/lcd.cpp | 6 ------ radio/src/gui/colorlcd/radio_theme.cpp | 1 - radio/src/gui/colorlcd/view_main_menu.h | 1 - radio/src/thirdparty/libopenui | 2 +- 8 files changed, 16 insertions(+), 21 deletions(-) diff --git a/radio/src/audio.cpp b/radio/src/audio.cpp index d2d4aa55f..89ddb230b 100644 --- a/radio/src/audio.cpp +++ b/radio/src/audio.cpp @@ -1267,11 +1267,6 @@ void pushPrompt(uint16_t prompt, uint8_t id) #endif } -void onKeyPress() -{ - audioKeyPress(); -} - void onKeyError() { audioKeyError(); diff --git a/radio/src/gui/colorlcd/LvglWrapper.cpp b/radio/src/gui/colorlcd/LvglWrapper.cpp index 50dfddc17..2471af36c 100644 --- a/radio/src/gui/colorlcd/LvglWrapper.cpp +++ b/radio/src/gui/colorlcd/LvglWrapper.cpp @@ -121,8 +121,18 @@ static void keyboardDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data) { data->key = 0; - if (isEvent()) { - event_t evt = getWindowEvent(); + if (isEvent()) { // event waiting + event_t evt = getEvent(false); // get keyEvent for hard keys other than trim switches + + if(evt == EVT_KEY_FIRST(KEY_PGUP) || // generate acoustic/haptic feedback if radio settings allow + evt == EVT_KEY_FIRST(KEY_PGDN) || + evt == EVT_KEY_FIRST(KEY_ENTER) || + evt == EVT_KEY_FIRST(KEY_MODEL) || + evt == EVT_KEY_FIRST(KEY_EXIT) || + evt == EVT_KEY_FIRST(KEY_TELEM) || + evt == EVT_KEY_FIRST(KEY_RADIO)) { + audioKeyPress(); + } // no focused item ? auto obj = get_focus_obj(keyboardDevice); @@ -209,9 +219,9 @@ extern "C" void touchDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data) copy_ts_to_indev_data(st, data); } - if (st.event == TE_UP) { // on Touch Up - reset_inactivity(); // reset activity counter - onKeyPress(); // provide acoustic and/or haptic feedback if requested in settings + if (st.event == TE_DOWN) { // on first touch (same logic as key down) + reset_inactivity(); // reset activity counter + audioKeyPress(); // provide acoustic and/or haptic feedback if requested in settings } backup_touch_data(data); diff --git a/radio/src/gui/colorlcd/access_settings.cpp b/radio/src/gui/colorlcd/access_settings.cpp index 9a8f45fdb..feedd07cd 100644 --- a/radio/src/gui/colorlcd/access_settings.cpp +++ b/radio/src/gui/colorlcd/access_settings.cpp @@ -117,7 +117,6 @@ bool BindRxChoiceMenu::onTouchEnd(coord_t x, coord_t y) // by clicking outside the menu window and the onCancel // handler is not accessible from here moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; - onKeyPress(); deleteLater(); return true; } diff --git a/radio/src/gui/colorlcd/color_editor_popup.cpp b/radio/src/gui/colorlcd/color_editor_popup.cpp index 50c602294..03e90629b 100644 --- a/radio/src/gui/colorlcd/color_editor_popup.cpp +++ b/radio/src/gui/colorlcd/color_editor_popup.cpp @@ -220,7 +220,6 @@ bool ColorEditorPopup::onTouchEnd(coord_t x, coord_t y) { TRACE("ColorEditorPopup::onTouchEnd"); if (!Window::onTouchEnd(x, y) && closeWhenClickOutside) { - onKeyPress(); deleteLater(); } return true; diff --git a/radio/src/gui/colorlcd/lcd.cpp b/radio/src/gui/colorlcd/lcd.cpp index d63fd6882..92a370a01 100644 --- a/radio/src/gui/colorlcd/lcd.cpp +++ b/radio/src/gui/colorlcd/lcd.cpp @@ -258,9 +258,3 @@ void lcdFlushed() if (refr_disp != nullptr) lv_disp_flush_ready(refr_disp); } - -//TODO: move this somewhere else -event_t getWindowEvent() -{ - return getEvent(false); -} diff --git a/radio/src/gui/colorlcd/radio_theme.cpp b/radio/src/gui/colorlcd/radio_theme.cpp index cc30277f7..86afaf419 100644 --- a/radio/src/gui/colorlcd/radio_theme.cpp +++ b/radio/src/gui/colorlcd/radio_theme.cpp @@ -182,7 +182,6 @@ public: for (auto i = 0; i < (int) _tabs.size(); i++) _tabs[i]->check(i == _activeTab); _colorEditor->setColorEditorType(_activeTab == 1 ? HSV_COLOR_EDITOR : RGB_COLOR_EDITOR); - onKeyPress(); } } diff --git a/radio/src/gui/colorlcd/view_main_menu.h b/radio/src/gui/colorlcd/view_main_menu.h index fdca78a1e..a6161379c 100644 --- a/radio/src/gui/colorlcd/view_main_menu.h +++ b/radio/src/gui/colorlcd/view_main_menu.h @@ -36,7 +36,6 @@ class ViewMainMenu : public Window bool onTouchStart(coord_t /*x*/, coord_t /*y*/) override { return true; } bool onTouchEnd(coord_t x, coord_t y) override { - onKeyPress(); deleteLater(); return true; } diff --git a/radio/src/thirdparty/libopenui b/radio/src/thirdparty/libopenui index ef09f4616..83009f63f 160000 --- a/radio/src/thirdparty/libopenui +++ b/radio/src/thirdparty/libopenui @@ -1 +1 @@ -Subproject commit ef09f46164599e6a1c0593af86eed9808bc3810b +Subproject commit 83009f63f382913091c5bcae77fdccf509756584