From b1d3a95ca2260af50f3fb17e99d1ec99024e201e Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Mon, 6 Nov 2023 01:25:44 +0100 Subject: [PATCH] Replace RX CSS menu scanning procedure with BK scanning method --- app/action.c | 3 +- app/app.c | 84 ++++++------------ app/dtmf.c | 2 +- app/generic.c | 37 +++----- app/main.c | 5 +- app/menu.c | 215 +++++++++++++++++++---------------------------- app/menu.h | 4 +- app/scanner.c | 57 +++++++++---- app/scanner.h | 3 +- functions.c | 18 ++-- helper/battery.c | 2 +- misc.c | 2 +- misc.h | 13 +-- radio.c | 11 +-- radio.h | 2 - scheduler.c | 6 +- ui/menu.c | 51 ++++++----- ui/menu.h | 5 +- ui/status.c | 7 +- ui/ui.c | 2 +- 20 files changed, 232 insertions(+), 297 deletions(-) diff --git a/app/action.c b/app/action.c index 202f61c..d3e2861 100644 --- a/app/action.c +++ b/app/action.c @@ -24,6 +24,7 @@ #ifdef ENABLE_FMRADIO #include "app/fm.h" #endif +#include "app/scanner.h" #include "audio.h" #include "bsp/dp32g030/gpio.h" #ifdef ENABLE_FMRADIO @@ -164,7 +165,7 @@ void ACTION_Scan(bool bRestart) } #endif - if (gScreenToDisplay != DISPLAY_SCANNER) + if (!SCANNER_IsScanning()) { // not scanning gMonitor = false; diff --git a/app/app.c b/app/app.c index 3c2e79b..7f1111b 100644 --- a/app/app.c +++ b/app/app.c @@ -93,15 +93,6 @@ static void CheckForIncoming(void) if (gScanStateDir == SCAN_OFF) { // not RF scanning - - if (gCssScanMode != CSS_SCAN_MODE_OFF && gRxReceptionMode == RX_MODE_NONE) - { // CTCSS/DTS scanning - - gScanPauseDelayIn_10ms = scan_pause_delay_in_5_10ms; - gScheduleScanListen = false; - gRxReceptionMode = RX_MODE_DETECTED; - } - if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF) { // dual watch is disabled @@ -220,7 +211,7 @@ static void HandleIncoming(void) if (!bFlag) return; - if (gScanStateDir == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF) + if (gScanStateDir == SCAN_OFF) { // not scanning if (gRxVfo->DTMF_DECODING_ENABLE || gSetting_KILLED) { // DTMF DCD is enabled @@ -498,11 +489,7 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) } #endif - if (gCssScanMode != CSS_SCAN_MODE_OFF) - gCssScanMode = CSS_SCAN_MODE_FOUND; - if (gScanStateDir == SCAN_OFF && - gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { // not scanning, dual watch is enabled @@ -634,7 +621,7 @@ static void DualwatchAlternate(void) static void CheckRadioInterrupts(void) { - if (gScreenToDisplay == DISPLAY_SCANNER) + if (SCANNER_IsScanning()) return; while (BK4819_ReadRegister(BK4819_REG_0C) & 1u) @@ -806,7 +793,7 @@ void APP_EndTransmission(void) if (gCurrentFunction == FUNCTION_RECEIVE || gCurrentFunction == FUNCTION_MONITOR) return; - if (gScanStateDir != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF) + if (gScanStateDir != SCAN_OFF) return; if (gVOX_NoiseDetected) @@ -897,25 +884,14 @@ void APP_Update(void) #endif #ifdef ENABLE_VOICE - if (gScreenToDisplay != DISPLAY_SCANNER && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed && gVoiceWriteIndex == 0) + if (!SCANNER_IsScanning() && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed && gVoiceWriteIndex == 0) #else - if (gScreenToDisplay != DISPLAY_SCANNER && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed) + if (!SCANNER_IsScanning() && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed) #endif { // scanning CHFRSCANNER_ContinueScanning(); } -#ifdef ENABLE_VOICE - if (gCssScanMode == CSS_SCAN_MODE_SCANNING && gScheduleScanListen && gVoiceWriteIndex == 0) -#else - if (gCssScanMode == CSS_SCAN_MODE_SCANNING && gScheduleScanListen) -#endif - { - MENU_SelectNextCode(); - - gScheduleScanListen = false; - } - #ifdef ENABLE_NOAA #ifdef ENABLE_VOICE if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF && gIsNoaaMode && gScheduleNOAA && gVoiceWriteIndex == 0) @@ -932,7 +908,7 @@ void APP_Update(void) #endif // toggle between the VFO's if dual watch is enabled - if (gScreenToDisplay != DISPLAY_SCANNER && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + if (!SCANNER_IsScanning() && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { #ifdef ENABLE_VOICE if (gScheduleDualWatch && gVoiceWriteIndex == 0) @@ -940,7 +916,7 @@ void APP_Update(void) if (gScheduleDualWatch) #endif { - if (gScanStateDir == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF) + if (gScanStateDir == SCAN_OFF) { if (!gPttIsPressed && #ifdef ENABLE_FMRADIO @@ -991,7 +967,7 @@ void APP_Update(void) gKeyBeingHeld || gEeprom.BATTERY_SAVE == 0 || gScanStateDir != SCAN_OFF || - gCssScanMode != CSS_SCAN_MODE_OFF || + gCssBackgroundScan || gScreenToDisplay != DISPLAY_MAIN || gDTMF_CallState != DTMF_CALL_STATE_NONE) { @@ -1015,7 +991,7 @@ void APP_Update(void) gKeyBeingHeld || gEeprom.BATTERY_SAVE == 0 || gScanStateDir != SCAN_OFF || - gCssScanMode != CSS_SCAN_MODE_OFF || + gCssBackgroundScan || gScreenToDisplay != DISPLAY_MAIN || gDTMF_CallState != DTMF_CALL_STATE_NONE) { @@ -1049,7 +1025,7 @@ void APP_Update(void) if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && gScanStateDir == SCAN_OFF && - gCssScanMode == CSS_SCAN_MODE_OFF) + !gCssBackgroundScan) { // dual watch mode, toggle between the two VFO's DualwatchAlternate(); @@ -1062,7 +1038,7 @@ void APP_Update(void) gRxIdleMode = false; // RX is awake } else - if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF || gScanStateDir != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF || gUpdateRSSI) + if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF || gScanStateDir != SCAN_OFF || gCssBackgroundScan || gUpdateRSSI) { // dual watch mode off or scanning or rssi update request UpdateRSSI(gEeprom.RX_VFO); @@ -1447,9 +1423,9 @@ void APP_TimeSlice500ms(void) if (gBacklightCountdown > 0 && !gAskToSave && - gCssScanMode == CSS_SCAN_MODE_OFF && + !gCssBackgroundScan && // don't turn off backlight if user is in backlight menu option - !(gScreenToDisplay == DISPLAY_MENU && (GetCurrentMenuId() == MENU_ABR || GetCurrentMenuId() == MENU_ABR_MAX)) + !(gScreenToDisplay == DISPLAY_MENU && (UI_MENU_GetCurrentMenuId() == MENU_ABR || UI_MENU_GetCurrentMenuId() == MENU_ABR_MAX)) ) { if (--gBacklightCountdown == 0) if (gEeprom.BACKLIGHT_TIME < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) // backlight is not set to be always on @@ -1504,15 +1480,15 @@ void APP_TimeSlice500ms(void) } #ifdef ENABLE_FMRADIO - if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && gCssScanMode == CSS_SCAN_MODE_OFF) + if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && !gCssBackgroundScan) #else - if (gCssScanMode == CSS_SCAN_MODE_OFF) + if (!gCssBackgroundScan) #endif { #ifdef ENABLE_AIRCOPY - if (gScanStateDir == SCAN_OFF && gScreenToDisplay != DISPLAY_AIRCOPY && (gScreenToDisplay != DISPLAY_SCANNER || gScanCssState >= SCAN_CSS_STATE_FOUND)) + if (gScanStateDir == SCAN_OFF && gScreenToDisplay != DISPLAY_AIRCOPY && !SCANNER_IsScanning()) #else - if (gScanStateDir == SCAN_OFF && (gScreenToDisplay != DISPLAY_SCANNER || gScanCssState >= SCAN_CSS_STATE_FOUND)) + if (gScanStateDir == SCAN_OFF && !SCANNER_IsScanning()) #endif { if (gEeprom.AUTO_KEYPAD_LOCK && gKeyLockCountdown > 0 && !gDTMF_InputMode && gScreenToDisplay != DISPLAY_MENU) @@ -1534,7 +1510,7 @@ void APP_TimeSlice500ms(void) if (gInputBoxIndex > 0 || gDTMF_InputMode) AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL); /* - if (gScreenToDisplay == DISPLAY_SCANNER) + if (SCANNER_IsScanning()) { BK4819_StopScan(); @@ -1570,10 +1546,10 @@ void APP_TimeSlice500ms(void) if (disp == DISPLAY_INVALID) { - #ifndef ENABLE_CODE_SCAN_TIMEOUT - if (gScreenToDisplay != DISPLAY_SCANNER) - #endif - disp = DISPLAY_MAIN; +#ifndef ENABLE_CODE_SCAN_TIMEOUT + if (!SCANNER_IsScanning()) +#endif + disp = DISPLAY_MAIN; } if (disp != DISPLAY_INVALID) @@ -1727,7 +1703,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) else // key pressed or held { const uint8_t s = gSetting_backlight_on_tx_rx; - const int m = GetCurrentMenuId(); + const int m = UI_MENU_GetCurrentMenuId(); if ( //not when PTT and the backlight shouldn't turn on on TX !(Key == KEY_PTT && s != BACKLIGHT_ON_TR_TX && s != BACKLIGHT_ON_TR_TXRX) // not in the backlight menu @@ -1816,7 +1792,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (Key <= KEY_9 || Key == KEY_F) { - if (gScanStateDir != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF) + if (gScanStateDir != SCAN_OFF || gCssBackgroundScan) { // FREQ/CTCSS/DCS scanning if (bKeyPressed && !bKeyHeld) AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL); @@ -1972,9 +1948,9 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } else #ifdef ENABLE_AIRCOPY - if (gScreenToDisplay != DISPLAY_SCANNER && gScreenToDisplay != DISPLAY_AIRCOPY) + if (!SCANNER_IsScanning() && gScreenToDisplay != DISPLAY_AIRCOPY) #else - if (gScreenToDisplay != DISPLAY_SCANNER) + if (!SCANNER_IsScanning()) #endif { ACTION_Handle(Key, bKeyPressed, bKeyHeld); @@ -2000,12 +1976,6 @@ Skip: gFlagAcceptSetting = false; } - if (gFlagStopScan) - { - BK4819_StopScan(); - gFlagStopScan = false; - } - if (gRequestSaveSettings) { if (!bKeyHeld) @@ -2042,7 +2012,7 @@ Skip: { SETTINGS_SaveChannel(gTxVfo->CHANNEL_SAVE, gEeprom.TX_VFO, gTxVfo, gRequestSaveChannel); - if (gScreenToDisplay != DISPLAY_SCANNER) + if (!SCANNER_IsScanning()) if (gVfoConfigureMode == VFO_CONFIGURE_NONE) // 'if' is so as we don't wipe out previously setting this variable elsewhere gVfoConfigureMode = VFO_CONFIGURE; } diff --git a/app/dtmf.c b/app/dtmf.c index c21644f..7f03958 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -210,7 +210,7 @@ void DTMF_HandleRequest(void) if (!gDTMF_RX_pending) return; // nothing new received - if (gScanStateDir != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF) + if (gScanStateDir != SCAN_OFF || gCssBackgroundScan) { // we're busy scanning DTMF_clear_RX(); return; diff --git a/app/generic.c b/app/generic.c index cab97f4..a8c7572 100644 --- a/app/generic.c +++ b/app/generic.c @@ -143,36 +143,21 @@ void GENERIC_Key_PTT(bool bKeyPressed) // PTT pressed - if (gScanStateDir != SCAN_OFF || // frequency/channel scanning - gScreenToDisplay == DISPLAY_SCANNER || // CTCSS/CDCSS scanning - gCssScanMode != CSS_SCAN_MODE_OFF) // " " - { // we're scanning .. stop - - if (gScreenToDisplay == DISPLAY_SCANNER) - { // CTCSS/CDCSS scanning .. stop - gEeprom.CROSS_BAND_RX_TX = gBackup_CROSS_BAND_RX_TX; - gFlagStopScan = true; - gVfoConfigureMode = VFO_CONFIGURE_RELOAD; - gFlagResetVfos = true; - } - else - if (gScanStateDir != SCAN_OFF) - { // frequency/channel scanning . .stop - CHFRSCANNER_Stop(); - } - else - if (gCssScanMode != CSS_SCAN_MODE_OFF) - { // CTCSS/CDCSS scanning .. stop - MENU_StopCssScan(); - - #ifdef ENABLE_VOICE - gAnotherVoiceID = VOICE_ID_SCANNING_STOP; - #endif - } + if (SCANNER_IsScanning()) + { // CTCSS/CDCSS scanning .. stop + SCANNER_Stop(); goto cancel_tx; } + if (gScanStateDir != SCAN_OFF) + { // frequency/channel scanning . .stop + CHFRSCANNER_Stop(); + goto cancel_tx; + } + + + #ifdef ENABLE_FMRADIO if (gFM_ScanState != FM_SCAN_OFF) { // FM radio is scanning .. stop diff --git a/app/main.c b/app/main.c index 1869e08..26ca9c4 100644 --- a/app/main.c +++ b/app/main.c @@ -46,7 +46,7 @@ void toggle_chan_scanlist(void) { // toggle the selected channels scanlist setting - if (gScreenToDisplay == DISPLAY_SCANNER || !IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) + if ( SCANNER_IsScanning() || !IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) return; if (gTxVfo->SCANLIST1_PARTICIPATION) @@ -106,7 +106,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; #ifdef ENABLE_COPY_CHAN_TO_VFO - if (gEeprom.VFO_OPEN && gCssScanMode == CSS_SCAN_MODE_OFF) + if (gEeprom.VFO_OPEN && !gCssBackgroundScan) { if (gScanStateDir != SCAN_OFF) @@ -664,7 +664,6 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; SCANNER_Start(true); gRequestDisplayScreen = DISPLAY_SCANNER; - } gPttWasReleased = true; diff --git a/app/menu.c b/app/menu.c index 3440f06..dcb4c89 100644 --- a/app/menu.c +++ b/app/menu.c @@ -75,27 +75,39 @@ } #endif -void MENU_StartCssScan(int8_t Direction) +void MENU_StartCssScan(void) { - gCssScanMode = CSS_SCAN_MODE_SCANNING; + SCANNER_Start(true); gUpdateStatus = true; + gCssBackgroundScan = true; - gMenuScrollDirection = Direction; + gRequestDisplayScreen = DISPLAY_MENU; +} - RADIO_SelectVfos(); +void MENU_CssScanFound(void) +{ + if(gScanCssResultType == CODE_TYPE_DIGITAL || gScanCssResultType == CODE_TYPE_REVERSE_DIGITAL) { + gMenuCursor = UI_MENU_GetMenuIdx(MENU_R_DCS); + } + else if(gScanCssResultType == CODE_TYPE_CONTINUOUS_TONE) { + gMenuCursor = UI_MENU_GetMenuIdx(MENU_R_CTCS); + } - MENU_SelectNextCode(); + MENU_ShowCurrentSetting(); - gScanPauseDelayIn_10ms = scan_pause_delay_in_2_10ms; - gScheduleScanListen = false; + gUpdateStatus = true; + gUpdateDisplay = true; } void MENU_StopCssScan(void) { - gCssScanMode = CSS_SCAN_MODE_OFF; + gCssBackgroundScan = false; + +#ifdef ENABLE_VOICE + gAnotherVoiceID = VOICE_ID_SCANNING_STOP; +#endif + gUpdateDisplay = true; gUpdateStatus = true; - - RADIO_SetupRegisters(true); } int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) @@ -367,14 +379,14 @@ void MENU_AcceptSetting(void) uint8_t Code; FREQ_Config_t *pConfig = &gTxVfo->freq_config_RX; - if (!MENU_GetLimits(GetCurrentMenuId(), &Min, &Max)) + if (!MENU_GetLimits(UI_MENU_GetCurrentMenuId(), &Min, &Max)) { if (gSubMenuSelection < Min) gSubMenuSelection = Min; else if (gSubMenuSelection > Max) gSubMenuSelection = Max; } - switch (GetCurrentMenuId()) + switch (UI_MENU_GetCurrentMenuId()) { default: return; @@ -808,7 +820,7 @@ void MENU_AcceptSetting(void) &gEeprom.KEY_2_SHORT_PRESS_ACTION, &gEeprom.KEY_2_LONG_PRESS_ACTION, &gEeprom.KEY_M_LONG_PRESS_ACTION}; - *fun[GetCurrentMenuId()-MENU_F1SHRT] = gSubMenu_SIDEFUNCTIONS[gSubMenuSelection].id; + *fun[UI_MENU_GetCurrentMenuId()-MENU_F1SHRT] = gSubMenu_SIDEFUNCTIONS[gSubMenuSelection].id; } break; @@ -817,53 +829,12 @@ void MENU_AcceptSetting(void) gRequestSaveSettings = true; } -void MENU_SelectNextCode(void) -{ - int32_t UpperLimit; - - if (GetCurrentMenuId() == MENU_R_DCS) - UpperLimit = 208; - //UpperLimit = ARRAY_SIZE(DCS_Options); - else if (GetCurrentMenuId() == MENU_R_CTCS) - UpperLimit = ARRAY_SIZE(CTCSS_Options) - 1; - else - return; - - gSubMenuSelection = NUMBER_AddWithWraparound(gSubMenuSelection, gMenuScrollDirection, 1, UpperLimit); - - if (GetCurrentMenuId() == MENU_R_DCS) - { - if (gSubMenuSelection > 104) - { - gSelectedCodeType = CODE_TYPE_REVERSE_DIGITAL; - gSelectedCode = gSubMenuSelection - 105; - } - else - { - gSelectedCodeType = CODE_TYPE_DIGITAL; - gSelectedCode = gSubMenuSelection - 1; - } - - } - else - { - gSelectedCodeType = CODE_TYPE_CONTINUOUS_TONE; - gSelectedCode = gSubMenuSelection - 1; - } - - RADIO_SetupRegisters(true); - - gScanPauseDelayIn_10ms = (gSelectedCodeType == CODE_TYPE_CONTINUOUS_TONE) ? scan_pause_delay_in_3_10ms : scan_pause_delay_in_4_10ms; - - gUpdateDisplay = true; -} - static void MENU_ClampSelection(int8_t Direction) { int32_t Min; int32_t Max; - if (!MENU_GetLimits(GetCurrentMenuId(), &Min, &Max)) + if (!MENU_GetLimits(UI_MENU_GetCurrentMenuId(), &Min, &Max)) { int32_t Selection = gSubMenuSelection; if (Selection < Min) Selection = Min; @@ -875,7 +846,7 @@ static void MENU_ClampSelection(int8_t Direction) void MENU_ShowCurrentSetting(void) { - switch (GetCurrentMenuId()) + switch (UI_MENU_GetCurrentMenuId()) { case MENU_SQL: gSubMenuSelection = gEeprom.SQUELCH_LEVEL; @@ -889,28 +860,41 @@ void MENU_ShowCurrentSetting(void) gSubMenuSelection = gTxVfo->OUTPUT_POWER; break; - case MENU_R_DCS: - switch (gTxVfo->freq_config_RX.CodeType) - { + case MENU_RESET: + gSubMenuSelection = 0; + break; + + case MENU_R_DCS: + case MENU_R_CTCS: + { + DCS_CodeType_t type = gTxVfo->freq_config_RX.CodeType; + uint8_t code = gTxVfo->freq_config_RX.Code; + int menuid = UI_MENU_GetCurrentMenuId(); + + if(gScanUseCssResult) { + gScanUseCssResult = false; + type = gScanCssResultType; + code = gScanCssResultCode; + } + if((menuid==MENU_R_CTCS) ^ (type==CODE_TYPE_CONTINUOUS_TONE)) { //not the same type + gSubMenuSelection = 0; + break; + } + + switch (type) { + case CODE_TYPE_CONTINUOUS_TONE: case CODE_TYPE_DIGITAL: - gSubMenuSelection = gTxVfo->freq_config_RX.Code + 1; + gSubMenuSelection = code + 1; break; case CODE_TYPE_REVERSE_DIGITAL: - gSubMenuSelection = gTxVfo->freq_config_RX.Code + 105; + gSubMenuSelection = code + 105; break; default: gSubMenuSelection = 0; break; } - break; - - case MENU_RESET: - gSubMenuSelection = 0; - break; - - case MENU_R_CTCS: - gSubMenuSelection = (gTxVfo->freq_config_RX.CodeType == CODE_TYPE_CONTINUOUS_TONE) ? gTxVfo->freq_config_RX.Code + 1 : 0; - break; + break; + } case MENU_T_DCS: switch (gTxVfo->freq_config_TX.CodeType) @@ -1199,7 +1183,7 @@ void MENU_ShowCurrentSetting(void) &gEeprom.KEY_2_SHORT_PRESS_ACTION, &gEeprom.KEY_2_LONG_PRESS_ACTION, &gEeprom.KEY_M_LONG_PRESS_ACTION}; - uint8_t id = *fun[GetCurrentMenuId()-MENU_F1SHRT]; + uint8_t id = *fun[UI_MENU_GetCurrentMenuId()-MENU_F1SHRT]; for(int i = 0; i < gSubMenu_SIDEFUNCTIONS_size; i++) { if(gSubMenu_SIDEFUNCTIONS[i].id==id) { @@ -1228,7 +1212,7 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - if (GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0) + if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0) { // currently editing the channel name if (edit_index < 10) @@ -1293,7 +1277,7 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) return; } - if (GetCurrentMenuId() == MENU_OFFSET) + if (UI_MENU_GetCurrentMenuId() == MENU_OFFSET) { uint32_t Frequency; @@ -1316,10 +1300,10 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) return; } - if (GetCurrentMenuId() == MENU_MEM_CH || - GetCurrentMenuId() == MENU_DEL_CH || - GetCurrentMenuId() == MENU_1_CALL || - GetCurrentMenuId() == MENU_MEM_NAME) + if (UI_MENU_GetCurrentMenuId() == MENU_MEM_CH || + UI_MENU_GetCurrentMenuId() == MENU_DEL_CH || + UI_MENU_GetCurrentMenuId() == MENU_1_CALL || + UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME) { // enter 3-digit channel number if (gInputBoxIndex < 3) @@ -1348,7 +1332,7 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) return; } - if (MENU_GetLimits(GetCurrentMenuId(), &Min, &Max)) + if (MENU_GetLimits(UI_MENU_GetCurrentMenuId(), &Min, &Max)) { gInputBoxIndex = 0; gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; @@ -1389,11 +1373,11 @@ static void MENU_Key_EXIT(bool bKeyPressed, bool bKeyHeld) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - if (gCssScanMode == CSS_SCAN_MODE_OFF) + if (!gCssBackgroundScan) { if (gIsInSubMenu) { - if (gInputBoxIndex == 0 || GetCurrentMenuId() != MENU_OFFSET) + if (gInputBoxIndex == 0 || UI_MENU_GetCurrentMenuId() != MENU_OFFSET) { gAskForConfirmation = 0; gIsInSubMenu = false; @@ -1449,12 +1433,12 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) if (!gIsInSubMenu) { #ifdef ENABLE_VOICE - if (GetCurrentMenuId() != MENU_SCR) + if (UI_MENU_GetCurrentMenuId() != MENU_SCR) gAnotherVoiceID = MenuList[gMenuCursor].voice_id; #endif #if 1 - if (GetCurrentMenuId() == MENU_DEL_CH || GetCurrentMenuId() == MENU_MEM_NAME) + if (UI_MENU_GetCurrentMenuId() == MENU_DEL_CH || UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME) if (!RADIO_CheckValidChannel(gSubMenuSelection, false, 0)) return; // invalid channel #endif @@ -1462,7 +1446,7 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) gAskForConfirmation = 0; gIsInSubMenu = true; -// if (GetCurrentMenuId() != MENU_D_LIST) +// if (UI_MENU_GetCurrentMenuId() != MENU_D_LIST) { gInputBoxIndex = 0; edit_index = -1; @@ -1471,7 +1455,7 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) return; } - if (GetCurrentMenuId() == MENU_MEM_NAME) + if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME) { if (edit_index < 0) { // enter channel name edit mode @@ -1518,10 +1502,10 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) if (gIsInSubMenu) { - if (GetCurrentMenuId() == MENU_RESET || - GetCurrentMenuId() == MENU_MEM_CH || - GetCurrentMenuId() == MENU_DEL_CH || - GetCurrentMenuId() == MENU_MEM_NAME) + if (UI_MENU_GetCurrentMenuId() == MENU_RESET || + UI_MENU_GetCurrentMenuId() == MENU_MEM_CH || + UI_MENU_GetCurrentMenuId() == MENU_DEL_CH || + UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME) { switch (gAskForConfirmation) { @@ -1534,7 +1518,7 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) UI_DisplayMenu(); - if (GetCurrentMenuId() == MENU_RESET) + if (UI_MENU_GetCurrentMenuId() == MENU_RESET) { #ifdef ENABLE_VOICE AUDIO_SetVoiceID(0, VOICE_ID_CONFIRM); @@ -1562,14 +1546,10 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) } } - if (gCssScanMode != CSS_SCAN_MODE_OFF) - { - gCssScanMode = CSS_SCAN_MODE_OFF; - gUpdateStatus = true; - } + SCANNER_Stop(); #ifdef ENABLE_VOICE - if (GetCurrentMenuId() == MENU_SCR) + if (UI_MENU_GetCurrentMenuId() == MENU_SCR) gAnotherVoiceID = (gSubMenuSelection == 0) ? VOICE_ID_SCRAMBLER_OFF : VOICE_ID_SCRAMBLER_ON; else gAnotherVoiceID = VOICE_ID_CONFIRM; @@ -1585,7 +1565,7 @@ static void MENU_Key_STAR(const bool bKeyPressed, const bool bKeyHeld) gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - if (GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0) + if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0) { // currently editing the channel name if (edit_index < 10) @@ -1612,26 +1592,12 @@ static void MENU_Key_STAR(const bool bKeyPressed, const bool bKeyHeld) if (gRxVfo->Modulation == MODULATION_FM) #endif { - if (GetCurrentMenuId() == MENU_R_CTCS || GetCurrentMenuId() == MENU_R_DCS) + if ((UI_MENU_GetCurrentMenuId() == MENU_R_CTCS || UI_MENU_GetCurrentMenuId() == MENU_R_DCS) && gIsInSubMenu) { // scan CTCSS or DCS to find the tone/code of the incoming signal - - if (gCssScanMode == CSS_SCAN_MODE_OFF) - { - MENU_StartCssScan(1); - gRequestDisplayScreen = DISPLAY_MENU; - #ifdef ENABLE_VOICE - AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN); - AUDIO_PlaySingleVoice(1); - #endif - } + if (!SCANNER_IsScanning()) + MENU_StartCssScan(); else - { MENU_StopCssScan(); - gRequestDisplayScreen = DISPLAY_MENU; - #ifdef ENABLE_VOICE - gAnotherVoiceID = VOICE_ID_SCANNING_STOP; - #endif - } } gPttWasReleased = true; @@ -1647,7 +1613,7 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) uint8_t Channel; bool bCheckScanList; - if (GetCurrentMenuId() == MENU_MEM_NAME && gIsInSubMenu && edit_index >= 0) + if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && gIsInSubMenu && edit_index >= 0) { // change the character if (bKeyPressed && edit_index < 10 && Direction != 0) { @@ -1682,12 +1648,7 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) if (!bKeyPressed) return; - if (gCssScanMode != CSS_SCAN_MODE_OFF) - { - MENU_StartCssScan(Direction); - - gPttWasReleased = true; - gRequestDisplayScreen = DISPLAY_MENU; + if (SCANNER_IsScanning()) { return; } @@ -1699,7 +1660,7 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) gRequestDisplayScreen = DISPLAY_MENU; - if (GetCurrentMenuId() != MENU_ABR && gEeprom.BACKLIGHT_TIME == 0) // backlight always off and not in the backlight menu + if (UI_MENU_GetCurrentMenuId() != MENU_ABR && gEeprom.BACKLIGHT_TIME == 0) // backlight always off and not in the backlight menu { BACKLIGHT_TurnOff(); } @@ -1707,7 +1668,7 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) return; } - if (GetCurrentMenuId() == MENU_OFFSET) + if (UI_MENU_GetCurrentMenuId() == MENU_OFFSET) { int32_t Offset = (Direction * gTxVfo->StepFrequency) + gSubMenuSelection; if (Offset < 99999990) @@ -1725,7 +1686,7 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) VFO = 0; - switch (GetCurrentMenuId()) + switch (UI_MENU_GetCurrentMenuId()) { case MENU_DEL_CH: case MENU_1_CALL: @@ -1785,7 +1746,7 @@ void MENU_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) MENU_Key_STAR(bKeyPressed, bKeyHeld); break; case KEY_F: - if (GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0) + if (UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME && edit_index >= 0) { // currently editing the channel name if (!bKeyHeld && bKeyPressed) { @@ -1817,11 +1778,11 @@ void MENU_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (gScreenToDisplay == DISPLAY_MENU) { - if (GetCurrentMenuId() == MENU_VOL || + if (UI_MENU_GetCurrentMenuId() == MENU_VOL || #ifdef ENABLE_F_CAL_MENU - GetCurrentMenuId() == MENU_F_CALI || + UI_MENU_GetCurrentMenuId() == MENU_F_CALI || #endif - GetCurrentMenuId() == MENU_BATCAL) + UI_MENU_GetCurrentMenuId() == MENU_BATCAL) { gMenuCountdown = menu_timeout_long_500ms; } diff --git a/app/menu.h b/app/menu.h index 0ad421f..8c46f2f 100644 --- a/app/menu.h +++ b/app/menu.h @@ -25,9 +25,9 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax); void MENU_AcceptSetting(void); -void MENU_SelectNextCode(void); void MENU_ShowCurrentSetting(void); -void MENU_StartCssScan(int8_t Direction); +void MENU_StartCssScan(void); +void MENU_CssScanFound(void); void MENU_StopCssScan(void); void MENU_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); diff --git a/app/scanner.c b/app/scanner.c index d064e1d..1daa8b6 100644 --- a/app/scanner.c +++ b/app/scanner.c @@ -17,6 +17,7 @@ #include "app/app.h" #include "app/dtmf.h" #include "app/generic.h" +#include "app/menu.h" #include "app/scanner.h" #include "audio.h" #include "driver/bk4819.h" @@ -29,7 +30,6 @@ DCS_CodeType_t gScanCssResultType; uint8_t gScanCssResultCode; -bool gFlagStopScan; bool gScanSingleFrequency; // scan CTCSS/DCS codes for current frequency SCAN_SaveState_t gScannerSaveState; uint8_t gScanChannel; @@ -84,16 +84,8 @@ static void SCANNER_Key_EXIT(bool bKeyPressed, bool bKeyHeld) switch (gScannerSaveState) { case SCAN_SAVE_NO_PROMPT: + SCANNER_Stop(); gRequestDisplayScreen = DISPLAY_MAIN; - - gEeprom.CROSS_BAND_RX_TX = gBackup_CROSS_BAND_RX_TX; - gUpdateStatus = true; - gFlagStopScan = true; - gVfoConfigureMode = VFO_CONFIGURE_RELOAD; - gFlagResetVfos = true; -#ifdef ENABLE_VOICE - gAnotherVoiceID = VOICE_ID_CANCEL; -#endif break; case SCAN_SAVE_CHAN_SEL: @@ -374,9 +366,25 @@ void SCANNER_Start(bool singleFreq) gScanProgressIndicator = 0; } +void SCANNER_Stop(void) +{ + if(SCANNER_IsScanning()) { + gEeprom.CROSS_BAND_RX_TX = gBackup_CROSS_BAND_RX_TX; + gVfoConfigureMode = VFO_CONFIGURE_RELOAD; + gFlagResetVfos = true; + gUpdateStatus = true; + gCssBackgroundScan = false; + gScanUseCssResult = false; +#ifdef ENABLE_VOICE + gAnotherVoiceID = VOICE_ID_CANCEL; +#endif + BK4819_StopScan(); + } +} + void SCANNER_TimeSlice10ms(void) { - if (gScreenToDisplay != DISPLAY_SCANNER) + if (!SCANNER_IsScanning()) return; if (gScanDelay_10ms > 0) { @@ -419,7 +427,8 @@ void SCANNER_TimeSlice10ms(void) gScanProgressIndicator = 0; gScanCssState = SCAN_CSS_STATE_SCANNING; - GUI_SelectNextDisplay(DISPLAY_SCANNER); + if(!gCssBackgroundScan) + GUI_SelectNextDisplay(DISPLAY_SCANNER); gUpdateStatus = true; } @@ -466,23 +475,33 @@ void SCANNER_TimeSlice10ms(void) } } - if (gScanCssState < SCAN_CSS_STATE_FOUND) { + if (gScanCssState < SCAN_CSS_STATE_FOUND) { // scanning or off BK4819_SetScanFrequency(gScanFrequency); gScanDelay_10ms = scan_delay_10ms; break; } - GUI_SelectNextDisplay(DISPLAY_SCANNER); + if(gCssBackgroundScan) { + gCssBackgroundScan = false; + if(gScanUseCssResult) + MENU_CssScanFound(); + } + else + GUI_SelectNextDisplay(DISPLAY_SCANNER); + + break; } default: + gCssBackgroundScan = false; break; } + } void SCANNER_TimeSlice500ms(void) { - if (gScreenToDisplay == DISPLAY_SCANNER && gScannerSaveState == SCAN_SAVE_NO_PROMPT && gScanCssState < SCAN_CSS_STATE_FOUND) { + if (SCANNER_IsScanning() && gScannerSaveState == SCAN_SAVE_NO_PROMPT && gScanCssState < SCAN_CSS_STATE_FOUND) { gScanProgressIndicator++; #ifdef ENABLE_CODE_SCAN_TIMEOUT if (gScanProgressIndicator > 32) { @@ -496,4 +515,12 @@ void SCANNER_TimeSlice500ms(void) #endif gUpdateDisplay = true; } + else if(gCssBackgroundScan) { + gUpdateDisplay = true; + } +} + +bool SCANNER_IsScanning(void) +{ + return gCssBackgroundScan || (gScreenToDisplay == DISPLAY_SCANNER); } \ No newline at end of file diff --git a/app/scanner.h b/app/scanner.h index 20e6f6c..a62deb6 100644 --- a/app/scanner.h +++ b/app/scanner.h @@ -38,7 +38,6 @@ typedef enum extern DCS_CodeType_t gScanCssResultType; extern uint8_t gScanCssResultCode; -extern bool gFlagStopScan; extern bool gScanSingleFrequency; extern SCAN_SaveState_t gScannerSaveState; extern uint8_t gScanChannel; @@ -49,8 +48,10 @@ extern bool gScanUseCssResult; void SCANNER_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); void SCANNER_Start(bool singleFreq); +void SCANNER_Stop(void); void SCANNER_TimeSlice10ms(void); void SCANNER_TimeSlice500ms(void); +bool SCANNER_IsScanning(void); #endif diff --git a/functions.c b/functions.c index 24f8866..feff175 100644 --- a/functions.c +++ b/functions.c @@ -44,18 +44,16 @@ FUNCTION_Type_t gCurrentFunction; void FUNCTION_Init(void) { - #ifdef ENABLE_NOAA - if (!IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) - #endif +#ifdef ENABLE_NOAA + if (!IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) +#endif { - gCurrentCodeType = gSelectedCodeType; - if (gCssScanMode == CSS_SCAN_MODE_OFF) - gCurrentCodeType = (gRxVfo->Modulation != MODULATION_FM) ? CODE_TYPE_OFF : gRxVfo->pRX->CodeType; + gCurrentCodeType = (gRxVfo->Modulation != MODULATION_FM) ? CODE_TYPE_OFF : gRxVfo->pRX->CodeType; } - #ifdef ENABLE_NOAA - else - gCurrentCodeType = CODE_TYPE_CONTINUOUS_TONE; - #endif +#ifdef ENABLE_NOAA + else + gCurrentCodeType = CODE_TYPE_CONTINUOUS_TONE; +#endif DTMF_clear_RX(); diff --git a/helper/battery.c b/helper/battery.c index ab4a53d..13f43c1 100644 --- a/helper/battery.c +++ b/helper/battery.c @@ -120,7 +120,7 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel) } - if ((gScreenToDisplay == DISPLAY_MENU) && GetCurrentMenuId() == MENU_VOL) + if ((gScreenToDisplay == DISPLAY_MENU) && UI_MENU_GetCurrentMenuId() == MENU_VOL) gUpdateDisplay = true; if (gBatteryCurrent < 501) diff --git a/misc.c b/misc.c index 3bada8b..40e6ef6 100644 --- a/misc.c +++ b/misc.c @@ -154,7 +154,7 @@ uint8_t gVFO_RSSI_bar_level[2]; uint8_t gReducedService; uint8_t gBatteryVoltageIndex; -CssScanMode_t gCssScanMode; +bool gCssBackgroundScan; volatile bool gScheduleScanListen = true; volatile uint16_t gScanPauseDelayIn_10ms; diff --git a/misc.h b/misc.h index 8ebc05e..d35fb2e 100644 --- a/misc.h +++ b/misc.h @@ -75,14 +75,6 @@ enum ReceptionMode_t { }; typedef enum ReceptionMode_t ReceptionMode_t; -enum CssScanMode_t -{ - CSS_SCAN_MODE_OFF = 0, - CSS_SCAN_MODE_SCANNING, - CSS_SCAN_MODE_FOUND, -}; -typedef enum CssScanMode_t CssScanMode_t; - enum BacklightOnRxTx_t { BACKLIGHT_ON_TR_OFF, BACKLIGHT_ON_TR_TX, @@ -229,9 +221,8 @@ extern uint8_t gVFO_RSSI_bar_level[2]; extern uint8_t gReducedService; extern uint8_t gBatteryVoltageIndex; -// if not equal CSS_SCAN_MODE_OFF we are scanning CTCSS/DCS -// this is a scanning inside RX ctcss/dcs menu -extern CssScanMode_t gCssScanMode; +// we are searching CTCSS/DCS inside RX ctcss/dcs menu +extern bool gCssBackgroundScan; enum diff --git a/radio.c b/radio.c index 3431f2d..026fd36 100644 --- a/radio.c +++ b/radio.c @@ -38,9 +38,7 @@ VFO_Info_t *gTxVfo; VFO_Info_t *gRxVfo; VFO_Info_t *gCurrentVfo; -DCS_CodeType_t gSelectedCodeType; DCS_CodeType_t gCurrentCodeType; -uint8_t gSelectedCode; VfoState_t VfoState[2]; const char gModulationStr[][4] = @@ -681,13 +679,8 @@ void RADIO_SetupRegisters(bool switchToForeground) { if (gRxVfo->Modulation == MODULATION_FM) { // FM - uint8_t CodeType = gSelectedCodeType; - uint8_t Code = gSelectedCode; - if (gCssScanMode == CSS_SCAN_MODE_OFF) - { - CodeType = gRxVfo->pRX->CodeType; - Code = gRxVfo->pRX->Code; - } + uint8_t CodeType = gRxVfo->pRX->CodeType; + uint8_t Code = gRxVfo->pRX->Code; switch (CodeType) { diff --git a/radio.h b/radio.h index 0c0becd..a4a5400 100644 --- a/radio.h +++ b/radio.h @@ -149,9 +149,7 @@ extern VFO_Info_t *gRxVfo; // Equal to gTxVfo unless dual watch changes it on incomming transmition (this can only happen when XB off and DW on) extern VFO_Info_t *gCurrentVfo; -extern DCS_CodeType_t gSelectedCodeType; extern DCS_CodeType_t gCurrentCodeType; -extern uint8_t gSelectedCode; extern VfoState_t VfoState[2]; diff --git a/scheduler.c b/scheduler.c index 37ba725..faa16cd 100644 --- a/scheduler.c +++ b/scheduler.c @@ -78,18 +78,18 @@ void SystickHandler(void) if (gCurrentFunction == FUNCTION_POWER_SAVE) DECREMENT_AND_TRIGGER(gPowerSave_10ms, gPowerSaveCountdownExpired); - if (gScanStateDir == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + if (gScanStateDir == SCAN_OFF && !gCssBackgroundScan && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) DECREMENT_AND_TRIGGER(gDualWatchCountdown_10ms, gScheduleDualWatch); #ifdef ENABLE_NOAA - if (gScanStateDir == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF) + if (gScanStateDir == SCAN_OFF && !gCssBackgroundScan && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF) if (gIsNoaaMode && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) if (gCurrentFunction != FUNCTION_RECEIVE) DECREMENT_AND_TRIGGER(gNOAA_Countdown_10ms, gScheduleNOAA); #endif - if (gScanStateDir != SCAN_OFF || gCssScanMode == CSS_SCAN_MODE_SCANNING) + if (gScanStateDir != SCAN_OFF) if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) DECREMENT_AND_TRIGGER(gScanPauseDelayIn_10ms, gScheduleScanListen); diff --git a/ui/menu.c b/ui/menu.c index 09c0b8f..80fefc1 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -367,13 +367,21 @@ const uint8_t gSubMenu_SIDEFUNCTIONS_size = ARRAY_SIZE(SIDEFUNCTIONS); bool gIsInSubMenu; uint8_t gMenuCursor; -int GetCurrentMenuId() { +int UI_MENU_GetCurrentMenuId() { if(gMenuCursor < ARRAY_SIZE(MenuList)) return MenuList[gMenuCursor].menu_id; else return MenuList[ARRAY_SIZE(MenuList)-1].menu_id; } -int8_t gMenuScrollDirection; + +uint8_t UI_MENU_GetMenuIdx(uint8_t id) +{ + for(uint8_t i = 0; i < ARRAY_SIZE(MenuList); i++) + if(MenuList[i].menu_id == id) + return i; + return 0; +} + int32_t gSubMenuSelection; // edit box @@ -476,7 +484,7 @@ void UI_DisplayMenu(void) bool already_printed = false; - switch (GetCurrentMenuId()) + switch (UI_MENU_GetCurrentMenuId()) { case MENU_SQL: sprintf(String, "%d", gSubMenuSelection); @@ -884,9 +892,9 @@ void UI_DisplayMenu(void) } } - if (GetCurrentMenuId() == MENU_SLIST1 || GetCurrentMenuId() == MENU_SLIST2) + if (UI_MENU_GetCurrentMenuId() == MENU_SLIST1 || UI_MENU_GetCurrentMenuId() == MENU_SLIST2) { - i = (GetCurrentMenuId() == MENU_SLIST1) ? 0 : 1; + i = (UI_MENU_GetCurrentMenuId() == MENU_SLIST1) ? 0 : 1; // if (gSubMenuSelection == 0xFF) if (gSubMenuSelection < 0) @@ -931,9 +939,9 @@ void UI_DisplayMenu(void) } } - if (GetCurrentMenuId() == MENU_MEM_CH || - GetCurrentMenuId() == MENU_DEL_CH || - GetCurrentMenuId() == MENU_1_CALL) + if (UI_MENU_GetCurrentMenuId() == MENU_MEM_CH || + UI_MENU_GetCurrentMenuId() == MENU_DEL_CH || + UI_MENU_GetCurrentMenuId() == MENU_1_CALL) { // display the channel name char s[11]; BOARD_fetchChannelName(s, gSubMenuSelection); @@ -942,18 +950,19 @@ void UI_DisplayMenu(void) UI_PrintString(s, menu_item_x1, menu_item_x2, 2, 8); } - if ((GetCurrentMenuId() == MENU_R_CTCS || GetCurrentMenuId() == MENU_R_DCS) && gCssScanMode != CSS_SCAN_MODE_OFF) + if ((UI_MENU_GetCurrentMenuId() == MENU_R_CTCS || UI_MENU_GetCurrentMenuId() == MENU_R_DCS) && gCssBackgroundScan) UI_PrintString("SCAN", menu_item_x1, menu_item_x2, 4, 8); + - if (GetCurrentMenuId() == MENU_UPCODE) + if (UI_MENU_GetCurrentMenuId() == MENU_UPCODE) if (strlen(gEeprom.DTMF_UP_CODE) > 8) UI_PrintString(gEeprom.DTMF_UP_CODE + 8, menu_item_x1, menu_item_x2, 4, 8); - if (GetCurrentMenuId() == MENU_DWCODE) + if (UI_MENU_GetCurrentMenuId() == MENU_DWCODE) if (strlen(gEeprom.DTMF_DOWN_CODE) > 8) UI_PrintString(gEeprom.DTMF_DOWN_CODE + 8, menu_item_x1, menu_item_x2, 4, 8); - if (GetCurrentMenuId() == MENU_D_LIST && gIsDtmfContactValid) + if (UI_MENU_GetCurrentMenuId() == MENU_D_LIST && gIsDtmfContactValid) { Contact[11] = 0; memmove(&gDTMF_ID, Contact + 8, 4); @@ -961,20 +970,20 @@ void UI_DisplayMenu(void) UI_PrintString(String, menu_item_x1, menu_item_x2, 4, 8); } - if (GetCurrentMenuId() == MENU_R_CTCS || - GetCurrentMenuId() == MENU_T_CTCS || - GetCurrentMenuId() == MENU_R_DCS || - GetCurrentMenuId() == MENU_T_DCS || - GetCurrentMenuId() == MENU_D_LIST) + if (UI_MENU_GetCurrentMenuId() == MENU_R_CTCS || + UI_MENU_GetCurrentMenuId() == MENU_T_CTCS || + UI_MENU_GetCurrentMenuId() == MENU_R_DCS || + UI_MENU_GetCurrentMenuId() == MENU_T_DCS || + UI_MENU_GetCurrentMenuId() == MENU_D_LIST) { sprintf(String, "%2d", gSubMenuSelection); UI_PrintStringSmall(String, 105, 0, 0); } - if ((GetCurrentMenuId() == MENU_RESET || - GetCurrentMenuId() == MENU_MEM_CH || - GetCurrentMenuId() == MENU_MEM_NAME || - GetCurrentMenuId() == MENU_DEL_CH) && gAskForConfirmation) + if ((UI_MENU_GetCurrentMenuId() == MENU_RESET || + UI_MENU_GetCurrentMenuId() == MENU_MEM_CH || + UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME || + UI_MENU_GetCurrentMenuId() == MENU_DEL_CH) && gAskForConfirmation) { // display confirmation strcpy(String, (gAskForConfirmation == 1) ? "SURE?" : "WAIT!"); UI_PrintString(String, menu_item_x1, menu_item_x2, 5, 8); diff --git a/ui/menu.h b/ui/menu.h index 39465da..db70598 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -165,8 +165,7 @@ extern const t_sidefunction* gSubMenu_SIDEFUNCTIONS; extern bool gIsInSubMenu; extern uint8_t gMenuCursor; -int GetCurrentMenuId(); -extern int8_t gMenuScrollDirection; + extern int32_t gSubMenuSelection; extern char edit_original[17]; @@ -174,5 +173,7 @@ extern char edit[17]; extern int edit_index; void UI_DisplayMenu(void); +int UI_MENU_GetCurrentMenuId(); +uint8_t UI_MENU_GetMenuIdx(uint8_t id); #endif diff --git a/ui/status.c b/ui/status.c index 06ae919..cac1f41 100644 --- a/ui/status.c +++ b/ui/status.c @@ -20,6 +20,7 @@ #ifdef ENABLE_FMRADIO #include "app/fm.h" #endif +#include "app/scanner.h" #include "bitmaps.h" #include "driver/keyboard.h" #include "driver/st7565.h" @@ -86,10 +87,10 @@ void UI_DisplayStatus() } else // SCAN indicator - if (gScanStateDir != SCAN_OFF || gScreenToDisplay == DISPLAY_SCANNER) + if (gScanStateDir != SCAN_OFF || SCANNER_IsScanning()) { char * s = ""; - if (IS_MR_CHANNEL(gNextMrChannel) && gScreenToDisplay != DISPLAY_SCANNER) + if (IS_MR_CHANNEL(gNextMrChannel) && !SCANNER_IsScanning()) { // channel mode switch(gEeprom.SCAN_LIST_DEFAULT) { case 0: s = "1"; break; @@ -119,7 +120,7 @@ void UI_DisplayStatus() #endif x++; - if(gScreenToDisplay != DISPLAY_SCANNER) { + if(!SCANNER_IsScanning()) { uint8_t dw = (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2; if(dw == 1 || dw == 3) { // DWR - dual watch + respond if(gDualWatchActive) diff --git a/ui/ui.c b/ui/ui.c index eb7cab3..90efcc2 100644 --- a/ui/ui.c +++ b/ui/ui.c @@ -86,7 +86,7 @@ void GUI_SelectNextDisplay(GUI_DisplayType_t Display) gInputBoxIndex = 0; gIsInSubMenu = false; - gCssScanMode = CSS_SCAN_MODE_OFF; + gCssBackgroundScan = false; gScanStateDir = SCAN_OFF; #ifdef ENABLE_FMRADIO gFM_ScanState = FM_SCAN_OFF;