From bbbc55306455cbddd783fffa4db818434a1963a0 Mon Sep 17 00:00:00 2001 From: mrkusypl Date: Tue, 24 Mar 2026 00:31:45 +0100 Subject: [PATCH] Improvements to the FM radio and side buttons --- App/app/action.c | 53 +++++++++++++++++++++++++++++++++++++++++++ App/app/app.c | 12 ++++------ App/app/fm.c | 35 +++++++++++++++++++++++----- App/app/main.c | 26 ++++++++------------- App/audio.c | 10 +++++++- App/driver/keyboard.c | 5 ++++ App/driver/keyboard.h | 2 ++ App/frequencies.c | 13 ++++------- App/main.c | 1 + App/ui/ui.c | 3 +-- 10 files changed, 119 insertions(+), 41 deletions(-) diff --git a/App/app/action.c b/App/app/action.c index f62d4bb0..3c7d40fd 100644 --- a/App/app/action.c +++ b/App/app/action.c @@ -290,6 +290,8 @@ void ACTION_SwitchDemodul(void) void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { + HideFKeyIcon(); + if (gScreenToDisplay == DISPLAY_MAIN && gDTMF_InputMode){ // entering DTMF code @@ -357,6 +359,55 @@ void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } // held or released after short press beyond this point + +#ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS + if(gEeprom.MENU_LOCK) { // do not run these actions in RescueOps mode + switch (func) { + case ACTION_OPT_SCAN: + case ACTION_OPT_VFO_MR: + #ifdef ENABLE_FMRADIO + case ACTION_OPT_FM: + #endif + return; + break; + + default: + break; + } + } +#endif + +#ifdef ENABLE_FMRADIO + if (gFmRadioMode) { // do not run these actions in FM radio mode + switch (func) { + case ACTION_OPT_POWER: + case ACTION_OPT_MONITOR: + case ACTION_OPT_A_B: + case ACTION_OPT_VFO_MR: + case ACTION_OPT_SWITCH_DEMODUL: + #ifdef ENABLE_VOX + case ACTION_OPT_VOX: + #endif + #ifdef ENABLE_FEAT_F4HWN + case ACTION_OPT_RXMODE: + case ACTION_OPT_MAINONLY: + case ACTION_OPT_WN: + #ifdef ENABLE_FEAT_F4HWN_AUDIO + case ACTION_OPT_RXA: + #endif + #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS + case ACTION_OPT_POWER_HIGH: + case ACTION_OPT_REMOVE_OFFSET: + #endif + #endif + gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + return; + + default: + break; + } + } +#endif action_opt_table[func](); } @@ -546,6 +597,8 @@ void ACTION_RxA(void) void ACTION_Ptt(void) { gSetting_set_ptt_session = !gSetting_set_ptt_session; + + ACTION_Update(); } void ACTION_Wn(void) diff --git a/App/app/app.c b/App/app/app.c index d9319ebd..9de9ab6c 100644 --- a/App/app/app.c +++ b/App/app/app.c @@ -1503,10 +1503,10 @@ void cancelUserInputModes(void) if (gWasFKeyPressed || gKeyInputCountdown > 0 || gInputBoxIndex > 0) { - gWasFKeyPressed = false; + HideFKeyIcon(); + gInputBoxIndex = 0; gKeyInputCountdown = 0; - gUpdateStatus = true; gUpdateDisplay = true; } } @@ -1528,7 +1528,7 @@ void APP_TimeSlice500ms(void) if (--gKeyInputCountdown == 0) { - if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE) && (gInputBoxIndex > 0 && gInputBoxIndex < 4)) + if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE) && (gInputBoxIndex > 0 && gInputBoxIndex < 4) && (!gFmRadioMode)) { channelMoveSwitch(); @@ -1724,13 +1724,12 @@ void APP_TimeSlice500ms(void) */ DTMF_clear_input_box(); - gWasFKeyPressed = false; + HideFKeyIcon(); gInputBoxIndex = 0; gAskToSave = false; gAskToDelete = false; - gUpdateStatus = true; gUpdateDisplay = true; GUI_DisplayType_t disp = DISPLAY_INVALID; @@ -2022,8 +2021,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (gWasFKeyPressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2)) { #endif // cancel the F-key - gWasFKeyPressed = false; - gUpdateStatus = true; + HideFKeyIcon(); } if (bFlag) { diff --git a/App/app/fm.c b/App/app/fm.c index 5e79f95c..6614f41b 100644 --- a/App/app/fm.c +++ b/App/app/fm.c @@ -257,6 +257,7 @@ static void Key_DIGITS(KEY_Code_t Key, uint8_t state) } INPUTBOX_Append(Key); + gKeyInputCountdown = key_input_timeout_500ms; gRequestDisplayScreen = DISPLAY_FM; @@ -272,6 +273,8 @@ static void Key_DIGITS(KEY_Code_t Key, uint8_t state) uint32_t Frequency; gInputBoxIndex = 0; + gKeyInputCountdown = 1; + Frequency = StrToUL(INPUTBOX_GetAscii()); if (Frequency < BK1080_GetFreqLoLimit(gEeprom.FM_Band) || BK1080_GetFreqHiLimit(gEeprom.FM_Band) < Frequency) { @@ -294,6 +297,8 @@ static void Key_DIGITS(KEY_Code_t Key, uint8_t state) uint8_t Channel; gInputBoxIndex = 0; + gKeyInputCountdown = 1; + Channel = ((gInputBox[0] * 10) + gInputBox[1]) - 1; if (State == STATE_MR_MODE) { @@ -336,8 +341,7 @@ static void Key_FUNC(KEY_Code_t Key, uint8_t state) bool autoScan = gWasFKeyPressed || (state == BUTTON_EVENT_HELD); gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - gWasFKeyPressed = false; - gUpdateStatus = true; + HideFKeyIcon(); gRequestDisplayScreen = DISPLAY_FM; switch (Key) { @@ -404,6 +408,7 @@ static void Key_EXIT(uint8_t state) } else { gInputBox[--gInputBoxIndex] = 10; + gKeyInputCountdown = key_input_timeout_500ms; if (gInputBoxIndex) { if (gInputBoxIndex != 1) { @@ -435,14 +440,25 @@ static void Key_EXIT(uint8_t state) static void Key_MENU(uint8_t state) { - if (state != BUTTON_EVENT_SHORT) + if (state == BUTTON_EVENT_HELD) { + ACTION_Handle(KEY_MENU, true, true); return; - + } + else if (state != BUTTON_EVENT_SHORT) { + return; + } gRequestDisplayScreen = DISPLAY_FM; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + HideFKeyIcon(); + if (gFM_ScanState == FM_SCAN_OFF) { + if (gInputBoxIndex) { + gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + return; + } + if (!gEeprom.FM_IsMrMode) { if (gAskToSave) { gFM_Channels[gFM_ChannelPosition] = gEeprom.FM_FrequencyPlaying; @@ -479,6 +495,8 @@ static void Key_MENU(uint8_t state) static void Key_UP_DOWN(uint8_t state, int8_t Step) { + HideFKeyIcon(); + if (state == BUTTON_EVENT_PRESSED) { if (gInputBoxIndex) { gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; @@ -563,9 +581,14 @@ void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) case KEY_PTT: GENERIC_Key_PTT(bKeyPressed); break; - default: - if (!bKeyHeld && bKeyPressed) + case KEY_SIDE1: + case KEY_SIDE2: + if (state != BUTTON_EVENT_PRESSED) { gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + HideFKeyIcon(); + } + break; + default: break; } } diff --git a/App/app/main.c b/App/app/main.c index df341e2d..5eb8d7d2 100644 --- a/App/app/main.c +++ b/App/app/main.c @@ -120,8 +120,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS if(gEeprom.MENU_LOCK == true && Key != 2) { - gUpdateStatus = true; - gWasFKeyPressed = false; + HideFKeyIcon(); return; } @@ -141,8 +140,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) case KEY_1: if (!IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) { - gWasFKeyPressed = false; - gUpdateStatus = true; + HideFKeyIcon(); #ifdef ENABLE_COPY_CHAN_TO_VFO if (!gEeprom.VFO_OPEN || gCssBackgroundScan) { @@ -224,11 +222,10 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) break; case KEY_4: - gWasFKeyPressed = false; + HideFKeyIcon(); gBackup_CROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; - gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; - gUpdateStatus = true; + gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; SCANNER_Start(false); gRequestDisplayScreen = DISPLAY_SCANNER; @@ -339,8 +336,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) #endif default: - gUpdateStatus = true; - gWasFKeyPressed = false; + HideFKeyIcon(); if (beep) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; @@ -430,8 +426,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gRequestDisplayScreen = DISPLAY_MAIN; } - gWasFKeyPressed = false; - gUpdateStatus = true; + HideFKeyIcon(); processFKeyFunction(Key, true); } @@ -654,8 +649,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) return; } - gWasFKeyPressed = false; - gUpdateStatus = true; + HideFKeyIcon(); #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS if(gEeprom.MENU_LOCK == true && Key != 2) { @@ -815,8 +809,7 @@ static void MAIN_Key_MENU(bool bKeyPressed, bool bKeyHeld) #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS if(gEeprom.MENU_LOCK == true) { - gUpdateStatus = true; - gWasFKeyPressed = false; + HideFKeyIcon(); return; } @@ -852,8 +845,7 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS if(gEeprom.MENU_LOCK == true) { - gUpdateStatus = true; - gWasFKeyPressed = false; + HideFKeyIcon(); return; // prevent F function if MENU LOCK is true } diff --git a/App/audio.c b/App/audio.c index 022515b8..44295ef0 100644 --- a/App/audio.c +++ b/App/audio.c @@ -177,11 +177,19 @@ void AUDIO_PlayBeep(BEEP_Type_t Beep) SYSTEM_DelayMs(5); BK4819_WriteRegister(BK4819_REG_71, ToneConfig); +#ifdef ENABLE_FMRADIO + const bool isFmRadio = gFmRadioMode; + + if (isFmRadio) + SYSTEM_DelayMs(10); +#endif + + if (gEnableSpeaker) AUDIO_AudioPathOn(); #ifdef ENABLE_FMRADIO - if (gFmRadioMode) + if (isFmRadio) BK1080_Mute(false); #endif diff --git a/App/driver/keyboard.c b/App/driver/keyboard.c index 9b3e7815..0634ac1e 100644 --- a/App/driver/keyboard.c +++ b/App/driver/keyboard.c @@ -260,4 +260,9 @@ KEY_Code_t KEYBOARD_GetKey(void) btn = KEY_PTT; } return btn; +} + +void HideFKeyIcon(void) { + gWasFKeyPressed = false; + gUpdateStatus = true; } \ No newline at end of file diff --git a/App/driver/keyboard.h b/App/driver/keyboard.h index a4e1b406..3fe092a9 100644 --- a/App/driver/keyboard.h +++ b/App/driver/keyboard.h @@ -71,4 +71,6 @@ bool KEYBOARD_ProcessProtocolByte(ParseState_t *state, uint8_t b); KEY_Code_t KEYBOARD_Poll(void); KEY_Code_t KEYBOARD_GetKey(void); +void HideFKeyIcon(void); + #endif \ No newline at end of file diff --git a/App/frequencies.c b/App/frequencies.c index 1a71b950..53a9bb06 100644 --- a/App/frequencies.c +++ b/App/frequencies.c @@ -163,11 +163,8 @@ int32_t TX_freq_check(const uint32_t Frequency) { // return '0' if TX frequency is allowed // otherwise return '-1' - if (Frequency < frequencyBandTable[0].lower || Frequency > frequencyBandTable[BAND_N_ELEM - 1].upper) - return -1; // not allowed outside this range - - if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower) - return -1; // BX chip does not work in this range + if (RX_freq_check(Frequency)) + return -1; switch (gSetting_F_LOCK) { @@ -280,10 +277,10 @@ int32_t RX_freq_check(const uint32_t Frequency) // otherwise return '-1' if (Frequency < frequencyBandTable[0].lower || Frequency > frequencyBandTable[BAND_N_ELEM - 1].upper) - return -1; + return -1; // not allowed outside this range if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower) - return -1; + return -1; // BX chip does not work in this range - return 0; // OK frequency + return 0; // OK frequency } diff --git a/App/main.c b/App/main.c index 1eb13710..e3522787 100644 --- a/App/main.c +++ b/App/main.c @@ -129,6 +129,7 @@ void Main(void) if (BootMode == BOOT_MODE_RESCUE_OPS) { gEeprom.MENU_LOCK = !gEeprom.MENU_LOCK; + gEeprom.CURRENT_STATE = 0; // Don't resume is active... SETTINGS_SaveSettings(); } diff --git a/App/ui/ui.c b/App/ui/ui.c index f6906289..387a2000 100644 --- a/App/ui/ui.c +++ b/App/ui/ui.c @@ -94,9 +94,8 @@ void GUI_SelectNextDisplay(GUI_DisplayType_t Display) gAskForConfirmation = 0; gAskToSave = false; gAskToDelete = false; - gWasFKeyPressed = false; - gUpdateStatus = true; + HideFKeyIcon(); } gScreenToDisplay = Display;