From 0501422c64bb31a69238b7e0cf2acba16ad03bfb Mon Sep 17 00:00:00 2001 From: mrkusypl Date: Tue, 28 Apr 2026 17:45:34 +0200 Subject: [PATCH] Add long-press functionality to ChName, minor refactoring --- App/app/action.c | 16 ++++------------ App/app/app.c | 3 ++- App/app/menu.c | 47 ++++++++++++++++++++++++----------------------- App/app/scanner.c | 13 +++++-------- 4 files changed, 35 insertions(+), 44 deletions(-) diff --git a/App/app/action.c b/App/app/action.c index 8d88b947..dd59cfaa 100644 --- a/App/app/action.c +++ b/App/app/action.c @@ -343,22 +343,14 @@ void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) break; } - if (!bKeyHeld && bKeyPressed) // button pushed - { + if (bKeyHeld != bKeyPressed) { // button pushed or released after hold + // (!bKeyHeld && bKeyPressed) or (bKeyHeld && !bKeyPressed) return; } - // held or released beyond this point + // held or released after short press - if(!(bKeyHeld && !bKeyPressed)) // don't beep on released after hold - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - - if (bKeyHeld && !bKeyPressed) // button released after hold - { - return; - } - - // held or released after short press beyond this point + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; #ifdef ENABLE_FMRADIO if (gFmRadioMode) { // do not run these actions in FM radio mode diff --git a/App/app/app.c b/App/app/app.c index 7cfa3ca3..45243570 100644 --- a/App/app/app.c +++ b/App/app/app.c @@ -2088,7 +2088,8 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } } #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) - else if ((!bKeyHeld && bKeyPressed) || (gAlarmState == ALARM_STATE_TX1750 && bKeyHeld && !bKeyPressed)) { + // else if ((!bKeyHeld && bKeyPressed) || (gAlarmState == ALARM_STATE_TX1750 && bKeyHeld && !bKeyPressed)) { + else if ((bKeyHeld != bKeyPressed) && (gAlarmState == ALARM_STATE_TX1750 || bKeyPressed)) { ALARM_Off(); if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0) diff --git a/App/app/menu.c b/App/app/menu.c index 63a33048..6f2f5b36 100644 --- a/App/app/menu.c +++ b/App/app/menu.c @@ -1507,6 +1507,13 @@ static const char* const char_map[10] = { "wxyz9" // KEY_9 }; +static bool MENU_IsEditingName() { + return !gCssBackgroundScan + && UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME + && gIsInSubMenu + && edit_index >= 0; +} + static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { uint8_t Offset; @@ -1708,12 +1715,7 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) static void MENU_Key_EXIT(bool bKeyPressed, bool bKeyHeld) { - const bool editing_name = !gCssBackgroundScan - && UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME - && gIsInSubMenu - && edit_index >= 0; - - if (editing_name) + if (MENU_IsEditingName()) { if (!bKeyPressed) { @@ -1813,9 +1815,9 @@ Skip: static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) { - if (bKeyHeld || !bKeyPressed) + if (!bKeyPressed || (bKeyHeld && (!MENU_IsEditingName() || gAskForConfirmation))) return; - + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; gRequestDisplayScreen = DISPLAY_MENU; @@ -1884,8 +1886,12 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) { // editing the channel name characters edit_last_key = 255; - if (++edit_index < 10) - return; // next char + if (bKeyHeld) { + edit_index = 10; + } + else if (++edit_index < 10) { + return; + } // exit gFlagAcceptSetting = false; @@ -2013,23 +2019,18 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) uint16_t Channel; bool bCheckScanList; + if (!bKeyPressed) + return; + + if (!bKeyHeld) { + gInputBoxIndex = 0; + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + } + if (!gEeprom.SET_NAV && gIsInSubMenu) { Direction = -Direction; } - if (!bKeyHeld) - { - if (!bKeyPressed) - return; - - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - - gInputBoxIndex = 0; - } - else - if (!bKeyPressed) - return; - if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && gIsInSubMenu && edit_index >= 0) { // change the character if (edit_index < 10 && Direction != 0) diff --git a/App/app/scanner.c b/App/app/scanner.c index afb806ff..617291a2 100644 --- a/App/app/scanner.c +++ b/App/app/scanner.c @@ -243,16 +243,13 @@ static void SCANNER_Key_STAR(bool bKeyPressed, bool bKeyHeld) return; } -static void SCANNER_Key_UP_DOWN(bool bKeyPressed, bool pKeyHeld, int8_t Direction) +static void SCANNER_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) { - if (pKeyHeld) { - if (!bKeyPressed) - return; + if (!bKeyPressed) { + return; } - else { - if (!bKeyPressed) - return; + if (!bKeyHeld) { gInputBoxIndex = 0; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; } @@ -266,7 +263,7 @@ static void SCANNER_Key_UP_DOWN(bool bKeyPressed, bool pKeyHeld, int8_t Directio gShowChPrefix = RADIO_CheckValidChannel(gScanChannel, false, 0); gRequestDisplayScreen = DISPLAY_SCANNER; } - else + else if (!bKeyHeld) gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; }