diff --git a/app/app.c b/app/app.c index afb613255..11205696a 100644 --- a/app/app.c +++ b/app/app.c @@ -542,36 +542,79 @@ static void DualwatchAlternate(void) { #ifdef ENABLE_NOAA if (gIsNoaaMode) { - if (!IS_NOAA_CHANNEL(gEeprom.ScreenChannel[0]) || !IS_NOAA_CHANNEL(gEeprom.ScreenChannel[1])) + if (!IS_NOAA_CHANNEL(gEeprom.ScreenChannel[0]) || !IS_NOAA_CHANNEL(gEeprom.ScreenChannel[1])) { gEeprom.RX_VFO = (gEeprom.RX_VFO + 1) & 1; - else + } else { gEeprom.RX_VFO = 0; + } gRxVfo = &gEeprom.VfoInfo[gEeprom.RX_VFO]; + gDualWatchCountdown_10ms = dual_watch_count_noaa_10ms - if (IS_NOAA_CHANNEL(gEeprom.VfoInfo[0].CHANNEL_SAVE)) + if (IS_NOAA_CHANNEL(gEeprom.VfoInfo[0].CHANNEL_SAVE)) { NOAA_IncreaseChannel(); + } } else #endif { // toggle between VFO's gEeprom.RX_VFO = !gEeprom.RX_VFO; gRxVfo = &gEeprom.VfoInfo[gEeprom.RX_VFO]; + gDualWatchCountdown_10ms = dual_watch_count_toggle_10ms; - if (!gDualWatchActive) - { // let the user see DW is active + if (!gDualWatchActive) { + // let the user see DW is active gDualWatchActive = true; gUpdateStatus = true; } } RADIO_SetupRegisters(false); +} - #ifdef ENABLE_NOAA - gDualWatchCountdown_10ms = gIsNoaaMode ? dual_watch_count_noaa_10ms : dual_watch_count_toggle_10ms; - #else - gDualWatchCountdown_10ms = dual_watch_count_toggle_10ms; - #endif +#ifdef ENABLE_DTMF +static void HandleDTMFTone(void) +{ + const char c = DTMF_GetCharacter(BK4819_GetDTMF_5TONE_Code()); // save the RX'ed DTMF character + if (c == 0xff) { + return; + } + + if (gCurrentFunction == FUNCTION_TRANSMIT) { + return; + } + + if (gSetting_live_DTMF_decoder) { + size_t len = strlen(gDTMF_RX_live); + if (len >= sizeof(gDTMF_RX_live) - 1) { // make room + memmove(&gDTMF_RX_live[0], &gDTMF_RX_live[1], sizeof(gDTMF_RX_live) - 1); + len--; + } + + gDTMF_RX_live[len++] = c; + gDTMF_RX_live[len] = 0; + gDTMF_RX_live_timeout = DTMF_RX_live_timeout_500ms; // time till we delete it + gUpdateDisplay = true; + } + +#ifdef ENABLE_DTMF_CALLING + if (gRxVfo->DTMF_DECODING_ENABLE || gSetting_KILLED) { + if (gDTMF_RX_index >= sizeof(gDTMF_RX) - 1) { // make room + memmove(&gDTMF_RX[0], &gDTMF_RX[1], sizeof(gDTMF_RX) - 1); + gDTMF_RX_index--; + } + + gDTMF_RX[gDTMF_RX_index++] = c; + gDTMF_RX[gDTMF_RX_index] = 0; + gDTMF_RX_timeout = DTMF_RX_timeout_500ms; // time till we delete it + gDTMF_RX_pending = true; + + SYSTEM_DelayMs(3);//fix DTMF not reply@Yurisu + DTMF_HandleRequest(); + } +#endif } +#endif + static void CheckRadioInterrupts(void) { @@ -616,57 +659,30 @@ static void CheckRadioInterrupts(void) // g_CTCSS_Lost = true; #ifdef ENABLE_DTMF if (interrupts.dtmf5ToneFound) { - const char c = DTMF_GetCharacter(BK4819_GetDTMF_5TONE_Code()); // save the RX'ed DTMF character - if (c != 0xff) { - if (gCurrentFunction != FUNCTION_TRANSMIT) { - if (gSetting_live_DTMF_decoder) { - size_t len = strlen(gDTMF_RX_live); - if (len >= sizeof(gDTMF_RX_live) - 1) { // make room - memmove(&gDTMF_RX_live[0], &gDTMF_RX_live[1], sizeof(gDTMF_RX_live) - 1); - len--; - } - gDTMF_RX_live[len++] = c; - gDTMF_RX_live[len] = 0; - gDTMF_RX_live_timeout = DTMF_RX_live_timeout_500ms; // time till we delete it - gUpdateDisplay = true; - } - -#ifdef ENABLE_DTMF_CALLING - if (gRxVfo->DTMF_DECODING_ENABLE || gSetting_KILLED) { - if (gDTMF_RX_index >= sizeof(gDTMF_RX) - 1) { // make room - memmove(&gDTMF_RX[0], &gDTMF_RX[1], sizeof(gDTMF_RX) - 1); - gDTMF_RX_index--; - } - gDTMF_RX[gDTMF_RX_index++] = c; - gDTMF_RX[gDTMF_RX_index] = 0; - gDTMF_RX_timeout = DTMF_RX_timeout_500ms; // time till we delete it - gDTMF_RX_pending = true; - - SYSTEM_DelayMs(3);//fix DTMF not reply@Yurisu - DTMF_HandleRequest(); - } -#endif - } - } + HandleDTMFTone(); } #endif - if (interrupts.cssTailFound) + if (interrupts.cssTailFound) { g_CxCSS_TAIL_Found = true; + } if (interrupts.cdcssLost) { g_CDCSS_Lost = true; gCDCSSCodeType = BK4819_GetCDCSSCodeType(); } - if (interrupts.cdcssFound) + if (interrupts.cdcssFound) { g_CDCSS_Lost = false; + } - if (interrupts.ctcssLost) + if (interrupts.ctcssLost) { g_CTCSS_Lost = true; + } - if (interrupts.ctcssFound) + if (interrupts.ctcssFound) { g_CTCSS_Lost = false; + } #ifdef ENABLE_VOX if (interrupts.voxLost) { @@ -1310,32 +1326,12 @@ void APP_TimeSlice500ms(void) } #ifdef ENABLE_DTMF - if (gDTMF_RX_live_timeout > 0) - { - #ifdef ENABLE_RSSI_BAR - if (center_line == CENTER_LINE_DTMF_DEC || - center_line == CENTER_LINE_NONE) // wait till the center line is free for us to use before timing out - #endif - { - if (--gDTMF_RX_live_timeout == 0) - { - if (gDTMF_RX_live[0] != 0) - { - memset(gDTMF_RX_live, 0, sizeof(gDTMF_RX_live)); - gUpdateDisplay = true; - } - } - } - } + DTMF_TimeSlice500ms(); #endif - if (gMenuCountdown > 0 && --gMenuCountdown == 0) + if (gMenuCountdown > 0 && --gMenuCountdown == 0) { exit_menu = (gScreenToDisplay == DISPLAY_MENU); // exit menu mode - -#ifdef ENABLE_DTMF_CALLING - if (gDTMF_RX_timeout > 0 && --gDTMF_RX_timeout == 0) - DTMF_clear_RX(); -#endif + } // Skipped authentic device check @@ -1490,35 +1486,12 @@ void APP_TimeSlice500ms(void) BATTERY_TimeSlice500ms(); SCANNER_TimeSlice500ms(); UI_MAIN_TimeSlice500ms(); - #ifdef ENABLE_DTMF_CALLING - if (gCurrentFunction != FUNCTION_TRANSMIT) { - if (gDTMF_DecodeRingCountdown_500ms > 0) { - // make "ring-ring" sound - gDTMF_DecodeRingCountdown_500ms--; - AUDIO_PlayBeep(BEEP_880HZ_200MS); - } - } else { - gDTMF_DecodeRingCountdown_500ms = 0; - } + DTMF_Calling_TimeSlice500ms(); +#endif + - if (gDTMF_CallState != DTMF_CALL_STATE_NONE && gCurrentFunction != FUNCTION_TRANSMIT - && gCurrentFunction != FUNCTION_RECEIVE && gDTMF_auto_reset_time_500ms > 0 - && --gDTMF_auto_reset_time_500ms == 0) - { - gUpdateDisplay = true; - if (gDTMF_CallState == DTMF_CALL_STATE_RECEIVED && gEeprom.DTMF_auto_reset_time >= DTMF_HOLD_MAX) { - gDTMF_CallState = DTMF_CALL_STATE_RECEIVED_STAY; // keep message on-screen till a key is pressed - } else { - gDTMF_CallState = DTMF_CALL_STATE_NONE; - } - } - if (gDTMF_IsTx && gDTMF_TxStopCountdown_500ms > 0 && --gDTMF_TxStopCountdown_500ms == 0) { - gDTMF_IsTx = false; - gUpdateDisplay = true; - } -#endif } #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) @@ -1709,7 +1682,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)) { + if (gWasFKeyPressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2)) { // cancel the F-key gWasFKeyPressed = false; gUpdateStatus = true; diff --git a/app/dtmf.c b/app/dtmf.c index 5541b5821..eaa0e444c 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -17,13 +17,12 @@ #ifdef ENABLE_DTMF #include -#include // NULL - -#include "app/chFrScanner.h" +#include +#include "chFrScanner.h" #ifdef ENABLE_FMRADIO - #include "app/fm.h" + #include "fm.h" #endif -#include "app/scanner.h" +#include "scanner.h" #include "bsp/dp32g030/gpio.h" #include "audio.h" #include "driver/bk4819.h" @@ -34,7 +33,9 @@ #include "external/printf/printf.h" #include "misc.h" #include "settings.h" -#include "ui/ui.h" +#include "../ui/ui.h" +#include "../ui/main.h" +#include "../functions.h" char gDTMF_String[15]; @@ -249,7 +250,34 @@ void DTMF_Reply(void) BK4819_ExitDTMF_TX(false); } +void DTMF_TimeSlice500ms(void) +{ + if (gDTMF_RX_live_timeout > 0) { +#ifdef ENABLE_RSSI_BAR + if (center_line == CENTER_LINE_DTMF_DEC || + center_line == CENTER_LINE_NONE) // wait till the center line is free for us to use before timing out +#endif + { + if (--gDTMF_RX_live_timeout == 0) + { + if (gDTMF_RX_live[0] != 0) + { + memset(gDTMF_RX_live, 0, sizeof(gDTMF_RX_live)); + gUpdateDisplay = true; + } + } + } + +#ifdef ENABLE_DTMF_CALLING + if (--gDTMF_RX_timeout == 0){ + DTMF_clear_RX(); + } +#endif + } +} + #ifdef ENABLE_DTMF_CALLING + void DTMF_clear_RX(void) { gDTMF_RX_timeout = 0; @@ -499,6 +527,36 @@ void DTMF_HandleRequest(void) } } +void DTMF_Calling_TimeSlice500ms(void) +{ + if (gCurrentFunction != FUNCTION_TRANSMIT) { + if (gDTMF_DecodeRingCountdown_500ms > 0) { + // make "ring-ring" sound + gDTMF_DecodeRingCountdown_500ms--; + AUDIO_PlayBeep(BEEP_880HZ_200MS); + } + } else { + gDTMF_DecodeRingCountdown_500ms = 0; + } + + if (gDTMF_CallState != DTMF_CALL_STATE_NONE && gCurrentFunction != FUNCTION_TRANSMIT + && gCurrentFunction != FUNCTION_RECEIVE && gDTMF_auto_reset_time_500ms > 0 + && --gDTMF_auto_reset_time_500ms == 0) + { + gUpdateDisplay = true; + if (gDTMF_CallState == DTMF_CALL_STATE_RECEIVED && gEeprom.DTMF_auto_reset_time >= DTMF_HOLD_MAX) { + gDTMF_CallState = DTMF_CALL_STATE_RECEIVED_STAY; // keep message on-screen till a key is pressed + } else { + gDTMF_CallState = DTMF_CALL_STATE_NONE; + } + } + + if (gDTMF_IsTx && gDTMF_TxStopCountdown_500ms > 0 && --gDTMF_TxStopCountdown_500ms == 0) { + gDTMF_IsTx = false; + gUpdateDisplay = true; + } +} + #endif -#endif \ No newline at end of file +#endif diff --git a/app/dtmf.h b/app/dtmf.h index 9d3143cf0..aac77b190 100644 --- a/app/dtmf.h +++ b/app/dtmf.h @@ -82,6 +82,9 @@ extern uint8_t gDTMF_RX_live_timeout; extern DTMF_ReplyState_t gDTMF_ReplyState; +extern const uint8_t DTMF_RX_live_timeout_500ms; +extern bool gSetting_live_DTMF_decoder; + bool DTMF_ValidateCodes(char *pCode, const unsigned int size); char DTMF_GetCharacter(const unsigned int code); void DTMF_clear_input_box(void); @@ -89,9 +92,15 @@ void DTMF_StringAppend(const char code); void DTMF_StringDeleteOne(); void DTMF_Reply(void); void DTMF_SendEndOfTransmission(void); +void DTMF_TimeSlice500ms(void); #ifdef ENABLE_DTMF_CALLING +extern const uint8_t DTMF_RX_timeout_500ms; +extern const uint8_t DTMF_decode_ring_countdown_500ms; +extern const uint8_t DTMF_txstop_countdown_500ms; +extern bool gSetting_KILLED; + extern char gDTMF_RX[17]; extern uint8_t gDTMF_RX_index; extern uint8_t gDTMF_RX_timeout; @@ -116,6 +125,7 @@ DTMF_CallMode_t DTMF_CheckGroupCall(const char *pMsg, const unsigned int size); bool DTMF_GetContact(const int Index, char *pContact); bool DTMF_FindContact(const char *pContact, char *pResult); void DTMF_HandleRequest(void); +void DTMF_Calling_TimeSlice500ms(void); #endif diff --git a/app/menu.c b/app/menu.c index a1b77d364..af6e95169 100644 --- a/app/menu.c +++ b/app/menu.c @@ -1401,17 +1401,26 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) if (!gIsInSubMenu) { - #ifdef ENABLE_VOICE - if (UI_MENU_GetCurrentMenuId() != MENU_SCR) - gAnotherVoiceID = MenuList[gMenuCursor].voice_id; - #endif - if (UI_MENU_GetCurrentMenuId() == MENU_ANI_ID || UI_MENU_GetCurrentMenuId() == MENU_UPCODE|| UI_MENU_GetCurrentMenuId() == MENU_DWCODE) +#ifdef ENABLE_VOICE + if (UI_MENU_GetCurrentMenuId() != MENU_SCR) { + gAnotherVoiceID = MenuList[gMenuCursor].voice_id; + } +#endif + if (UI_MENU_GetCurrentMenuId() == MENU_UPCODE + || UI_MENU_GetCurrentMenuId() == MENU_DWCODE +#ifdef ENABLE_DTMF_CALLING + || UI_MENU_GetCurrentMenuId() == MENU_ANI_ID +#endif + ) { return; - #if 1 - if (UI_MENU_GetCurrentMenuId() == MENU_DEL_CH || UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME) - if (!RADIO_CheckValidChannel(gSubMenuSelection, false, 0)) - return; // invalid channel - #endif + } +#if 1 + if (UI_MENU_GetCurrentMenuId() == MENU_DEL_CH || UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME) { + if (!RADIO_CheckValidChannel(gSubMenuSelection, false, 0)) { + return; // invalid channel + } + } +#endif gAskForConfirmation = 0; gIsInSubMenu = true; diff --git a/misc.h b/misc.h index e408b63e5..104216903 100644 --- a/misc.h +++ b/misc.h @@ -88,19 +88,6 @@ extern const uint8_t vfo_state_resume_countdown_500ms; extern const uint8_t menu_timeout_500ms; extern const uint16_t menu_timeout_long_500ms; -#ifdef ENABLE_DTMF - -extern const uint8_t DTMF_RX_live_timeout_500ms; -extern bool gSetting_live_DTMF_decoder; - -#ifdef ENABLE_DTMF_CALLING -extern const uint8_t DTMF_RX_timeout_500ms; -extern const uint8_t DTMF_decode_ring_countdown_500ms; -extern const uint8_t DTMF_txstop_countdown_500ms; -extern bool gSetting_KILLED; -#endif - -#endif extern const uint8_t key_input_timeout_500ms; diff --git a/radio.c b/radio.c index 21934435e..e1e172dd8 100644 --- a/radio.c +++ b/radio.c @@ -698,7 +698,10 @@ void RADIO_SetupRegisters(bool switchToForeground) // RX expander BK4819_SetCompander((gRxVfo->Modulation == MODULATION_FM && gRxVfo->Compander >= 2) ? gRxVfo->Compander : 0); +#ifdef ENABLE_DTMF BK4819_EnableDTMF(); +#endif + InterruptMask |= BK4819_REG_3F_DTMF_5TONE_FOUND; RADIO_SetupAGC(gRxVfo->Modulation == MODULATION_AM, false); diff --git a/ui/main.h b/ui/main.h index 16a6ec333..951b43186 100644 --- a/ui/main.h +++ b/ui/main.h @@ -17,6 +17,8 @@ #ifndef UI_MAIN_H #define UI_MAIN_H +#include + enum center_line_t { CENTER_LINE_NONE = 0, CENTER_LINE_IN_USE, diff --git a/ui/status.c b/ui/status.c index 3945b6a38..fdbb83bf2 100644 --- a/ui/status.c +++ b/ui/status.c @@ -34,6 +34,10 @@ #include "ui/ui.h" #include "ui/status.h" +#ifdef ENABLE_DTMF_CALLING + #include "../app/dtmf.h" +#endif + void UI_DisplayStatus() { gUpdateStatus = false;