Fix-n-clean DTMF live decoder

This commit is contained in:
OneOfEleven 2023-09-29 20:48:23 +01:00
parent fd0e166315
commit f4643adb2a
12 changed files with 94 additions and 84 deletions

View File

@ -138,9 +138,9 @@ OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size
# the user might not have/want git installed
# can set own version string here (max 7 chars here)
# can set own version string here (max 7 chars)
GIT_HASH := $(shell git rev-parse --short HEAD)
#GIT_HASH := 230925b
#GIT_HASH := 230930b
$(info GIT_HASH = $(GIT_HASH))
@ -150,6 +150,10 @@ ifeq ($(ENABLE_OVERLAY),1)
endif
CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD
#CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c99 -MMD
#CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=gnu99 -MMD
#CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=gnu11 -MMD
CFLAGS += -DPRINTF_INCLUDE_CONFIG_H
CFLAGS += -DGIT_HASH=\"$(GIT_HASH)\"
ifeq ($(ENABLE_SWD),1)
@ -287,4 +291,4 @@ bsp/dp32g030/%.h: hardware/dp32g030/%.def
-include $(DEPS)
clean:
rm -f $(TARGET).bin $(TARGET).packed.bin $(TARGET) $(OBJS) $(DEPS)
rm -f $(TARGET).bin $(TARGET).packed.bin $(TARGET) $(OBJS) $(DEPS)

View File

@ -340,7 +340,7 @@ const uint8_t orig_pga = 6; // -3dB
case FUNCTION_TRANSMIT:
case FUNCTION_BAND_SCOPE:
case FUNCTION_POWER_SAVE:
counter = display_update_rate - 1;
counter = display_update_rate; // queue up a display update as soon as we switch to RX mode
return;
// only adjust stuff if we're in one of these modes
@ -442,9 +442,9 @@ const uint8_t orig_pga = 6; // -3dB
hold_counter[vfo] = 30; // 300ms hold
if (hold_counter[vfo] == 0)
{ // hold has been released/timed-out, we're free to increase gain
const unsigned int index = gain_table_index[vfo] + 1; // move up to next gain table index
gain_table_index[vfo] = (index <= max_index) ? index : max_index; // limit the gain index and save it
{ // hold has been released, we're free to increase gain
const unsigned int index = gain_table_index[vfo] + 1; // move up to next gain index
gain_table_index[vfo] = (index <= max_index) ? index : max_index; // limit the gain index
}
if (gain_table_index[vfo] == gain_table_index_prev[vfo])

View File

@ -783,25 +783,26 @@ void APP_CheckRadioInterrupts(void)
const char c = DTMF_GetCharacter(BK4819_GetDTMF_5TONE_Code());
if (c != 0xff)
{
gDTMF_RequestPending = true;
gDTMF_RecvTimeout = DTMF_RX_timeout_500ms;
// shift the RX buffer down one - if need be
if (gDTMF_WriteIndex >= sizeof(gDTMF_Received))
memmove(gDTMF_Received, &gDTMF_Received[1], gDTMF_WriteIndex-- - 1);
gDTMF_Received[gDTMF_WriteIndex++] = c;
if (gCurrentFunction == FUNCTION_RECEIVE)
if (gCurrentFunction == FUNCTION_RECEIVE ||
gCurrentFunction == FUNCTION_INCOMING ||
gCurrentFunction == FUNCTION_MONITOR)
{
{ // live DTMF decoder
gDTMF_RecvTimeoutSaved = DTMF_RX_timeout_saved_500ms;
size_t len = strlen(gDTMF_ReceivedSaved);
// shift the RX buffer down one - if need be
if (len >= (sizeof(gDTMF_ReceivedSaved) - 1))
memmove(gDTMF_ReceivedSaved, &gDTMF_ReceivedSaved[1], len--);
gDTMF_ReceivedSaved[len++] = c;
gDTMF_ReceivedSaved[len] = '\0';
gUpdateDisplay = true;
}
gDTMF_RequestPending = true;
gDTMF_RecvTimeout = DTMF_RX_timeout_500ms;
// shift the RX buffer down one - if need be
if (gDTMF_WriteIndex >= sizeof(gDTMF_Received))
memmove(gDTMF_Received, &gDTMF_Received[1], --gDTMF_WriteIndex);
gDTMF_Received[gDTMF_WriteIndex++] = c;
// live DTMF decoder
size_t len = strlen(gDTMF_RX_live);
// shift the RX buffer down one - if need be
if (len >= (sizeof(gDTMF_RX_live) - 1))
memmove(&gDTMF_RX_live[0], &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;
DTMF_HandleRequest();
}
@ -1687,6 +1688,15 @@ void APP_TimeSlice500ms(void)
if (--gKeyInputCountdown == 0)
cancelUserInputModes();
if (gDTMF_RX_live_timeout > 0)
{
if (--gDTMF_RX_live_timeout == 0)
{
gDTMF_RX_live[0] = 0;
gUpdateDisplay = true;
}
}
// Skipped authentic device check
#ifdef ENABLE_FMRADIO
@ -1936,15 +1946,6 @@ void APP_TimeSlice500ms(void)
memset(gDTMF_Received, 0, sizeof(gDTMF_Received));
}
}
if (gDTMF_RecvTimeoutSaved > 0)
{
if (--gDTMF_RecvTimeoutSaved == 0)
{
gDTMF_ReceivedSaved[0] = '\0';
gUpdateDisplay = true;
}
}
}
#ifdef ENABLE_ALARM
@ -2019,11 +2020,11 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
if (gEeprom.AUTO_KEYPAD_LOCK)
gKeyLockCountdown = 30; // 15 seconds
if (Key == KEY_EXIT && bKeyPressed && bKeyHeld && gDTMF_ReceivedSaved[0] > 0)
if (Key == KEY_EXIT && bKeyPressed && bKeyHeld && gDTMF_RX_live[0] != 0)
{ // clear the live DTMF decoder if the EXIT key is held
gDTMF_RecvTimeoutSaved = 0;
gDTMF_ReceivedSaved[0] = '\0';
gUpdateDisplay = true;
gDTMF_RX_live_timeout = 0;
gDTMF_RX_live[0] = 0;
gUpdateDisplay = true;
}
if (!bKeyPressed)

View File

@ -40,8 +40,8 @@ uint8_t gDTMF_WriteIndex = 0;
uint8_t gDTMF_PreviousIndex = 0;
uint8_t gDTMF_RecvTimeout = 0;
char gDTMF_ReceivedSaved[20];
uint8_t gDTMF_RecvTimeoutSaved = 0;
char gDTMF_RX_live[20];
uint8_t gDTMF_RX_live_timeout = 0;
bool gIsDtmfContactValid;
char gDTMF_ID[4];

View File

@ -63,8 +63,8 @@ extern uint8_t gDTMF_WriteIndex;
extern uint8_t gDTMF_PreviousIndex;
extern uint8_t gDTMF_RecvTimeout;
extern char gDTMF_ReceivedSaved[20];
extern uint8_t gDTMF_RecvTimeoutSaved;
extern char gDTMF_RX_live[20];
extern uint8_t gDTMF_RX_live_timeout;
extern bool gIsDtmfContactValid;
extern char gDTMF_ID[4];

View File

@ -595,8 +595,8 @@ void MENU_AcceptSetting(void)
return;
case MENU_D_LIVE_DEC:
gDTMF_RecvTimeoutSaved = 0;
gDTMF_ReceivedSaved[0] = '\0';
gDTMF_RX_live_timeout = 0;
gDTMF_RX_live[0] = '\0';
gSetting_live_DTMF_decoder = gSubMenuSelection;
if (!gSetting_live_DTMF_decoder)
BK4819_DisableDTMF();

Binary file not shown.

Binary file not shown.

View File

@ -59,8 +59,8 @@ void FUNCTION_Init(void)
gDTMF_WriteIndex = 0;
memset(gDTMF_Received, 0, sizeof(gDTMF_Received));
// gDTMF_RecvTimeoutSaved = 0;
// gDTMF_ReceivedSaved[0] = '\0';
// gDTMF_RX_timeout_live = 0;
// gDTMF_RX_timeout_live[0] = '\0';
g_CxCSS_TAIL_Found = false;
g_CDCSS_Lost = false;
@ -152,7 +152,8 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
// if DTMF is enabled when TX'ing, it changes the TX audio filtering !! .. 1of11
BK4819_DisableDTMF();
gDTMF_ReceivedSaved[0] = 0;
gDTMF_RX_live_timeout = 0;
gDTMF_RX_live[0] = 0;
#if defined(ENABLE_FMRADIO)
if (gFmRadioMode)

4
misc.c
View File

@ -26,8 +26,8 @@ const uint16_t fm_restore_countdown_10ms = 5000 / 10; // 5 seconds
const uint8_t menu_timeout_500ms = 20000 / 500; // 20 seconds
const uint8_t DTMF_RX_timeout_500ms = 2500 / 500; // 2.5 seconds
const uint8_t DTMF_RX_timeout_saved_500ms = 20000 / 500; // 20 seconds
const uint8_t DTMF_RX_live_timeout_500ms = 6000 / 500; // 6 seconds live decoder on screen
const uint8_t DTMF_RX_timeout_500ms = 10000 / 500; // 10 seconds till we wipe the DTMF receiver
const uint8_t DTMF_decode_ring_countdown_500ms = 15000 / 500; // 15 seconds
const uint8_t DTMF_txstop_countdown_500ms = 3000 / 500; // 6 seconds

2
misc.h
View File

@ -91,8 +91,8 @@ extern const uint16_t fm_restore_countdown_10ms;
extern const uint8_t menu_timeout_500ms;
extern const uint8_t DTMF_RX_live_timeout_500ms;
extern const uint8_t DTMF_RX_timeout_500ms;
extern const uint8_t DTMF_RX_timeout_saved_500ms;
extern const uint8_t DTMF_decode_ring_countdown_500ms;
extern const uint8_t DTMF_txstop_countdown_500ms;

View File

@ -117,36 +117,40 @@
#if defined(ENABLE_RSSI_BAR)
void UI_DisplayRSSIBar(const int16_t rssi, const bool now)
{
const int16_t s9_dBm = -73; // S9
const int16_t s0_dBm = -127; // S0
const int16_t bar_max_dBm = s9_dBm + 30; // S9+30dB
const int16_t bar_min_dBm = s0_dBm; // S0
// ************
const unsigned int txt_width = 7 * 8; // 8 text chars
const unsigned int bar_x = 2 + txt_width + 4; // X coord of bar graph
const unsigned int bar_width = LCD_WIDTH - 1 - bar_x;
const int16_t dBm = (rssi / 2) - 160;
const int16_t clamped_dBm = (dBm <= bar_min_dBm) ? bar_min_dBm : (dBm >= bar_max_dBm) ? bar_max_dBm : dBm;
const unsigned int bar_range_dB = bar_max_dBm - bar_min_dBm;
const unsigned int len = ((clamped_dBm - bar_min_dBm) * bar_width) / bar_range_dB;
const unsigned int line = 3;
uint8_t *pLine = gFrameBuffer[line];
char s[16];
unsigned int i;
const int16_t max_dB = -33; // S9+40dB
const int16_t min_dB = -127; // S0
const unsigned int txt_width = 7 * 8; // 8 text chars
const unsigned int bar_x = txt_width + 4;
const unsigned int bar_width = LCD_WIDTH - 1 - bar_x;
const int16_t dBm = (rssi / 2) - 160;
const int16_t clamped_dBm = (dBm <= min_dB) ? min_dB : (dBm >= max_dB) ? max_dB : dBm;
const unsigned int range_dB = max_dB - min_dB;
const unsigned int len = ((clamped_dBm - min_dB) * bar_width) / range_dB;
const unsigned int line = 3;
uint8_t *pLine = gFrameBuffer[line];
unsigned int s_level = 0;
unsigned int s_level = 0; // S0
if (gEeprom.KEY_LOCK && gKeypadLocked > 0)
return; // display is in use
if (gCurrentFunction == FUNCTION_TRANSMIT || gScreenToDisplay != DISPLAY_MAIN)
return; // display is in use
if (dBm >= -63) // S9+10dB
s_level = 10 + (((dBm - -63) / 10) * 10);
if (dBm >= (s9_dBm + 10)) // S9+10dB
s_level = ((dBm - s9_dBm) / 10) * 10;
else
if (clamped_dBm >= -127) // S0
s_level = (clamped_dBm - -127) / 6;
if (dBm >= s0_dBm) // S0
s_level = (dBm - s0_dBm) / 6; // 6dB per S point
if (now)
memset(pLine, 0, LCD_WIDTH);
@ -154,7 +158,7 @@
if (s_level < 10)
sprintf(s, "%-4d S%u ", dBm, s_level); // S0 ~ S9
else
sprintf(s, "%-4d +%2u", dBm, s_level); // S9+
sprintf(s, "%-4d +%2u", dBm, s_level); // S9+XX
UI_PrintStringSmall(s, 2, 0, line);
#if 1
@ -182,7 +186,7 @@ void UI_UpdateRSSI(const int16_t rssi, const int vfo)
#if defined(ENABLE_AM_FIX) && defined(ENABLE_AM_FIX_SHOW_DATA)
if (gEeprom.VfoInfo[gEeprom.RX_CHANNEL].AM_mode && gSetting_AM_fix)
{
{ // AM test data is currently being shown
}
else
#endif
@ -692,13 +696,19 @@ void UI_DisplayMain(void)
gCurrentFunction == FUNCTION_MONITOR ||
gCurrentFunction == FUNCTION_INCOMING);
#ifdef ENABLE_AUDIO_BAR
if (gSetting_mic_bar && gCurrentFunction == FUNCTION_TRANSMIT)
UI_DisplayAudioBar();
else
#endif
#if defined(ENABLE_AM_FIX) && defined(ENABLE_AM_FIX_SHOW_DATA)
if (gEeprom.VfoInfo[gEeprom.RX_CHANNEL].AM_mode && gSetting_AM_fix)
{
if (rx)
{
AM_fix_print_data(gEeprom.RX_CHANNEL, String);
UI_PrintStringSmall(String, 0, 0, 3);
UI_PrintStringSmall(String, 2, 0, 3);
}
}
else
@ -710,20 +720,14 @@ void UI_DisplayMain(void)
else
#endif
#ifdef ENABLE_AUDIO_BAR
if (gSetting_mic_bar && gCurrentFunction == FUNCTION_TRANSMIT)
UI_DisplayAudioBar();
else
#endif
if (rx || gCurrentFunction == FUNCTION_FOREGROUND)
{
if (gSetting_live_DTMF_decoder && gDTMF_ReceivedSaved[0] >= 32)
if (gSetting_live_DTMF_decoder && gDTMF_RX_live[0] >= 32)
{ // show live DTMF decode
const unsigned int len = strlen(gDTMF_ReceivedSaved);
const unsigned int idx = (len > (17 - 5)) ? len - (17 - 5) : 0; // just the last 'n' chars
const unsigned int len = strlen(gDTMF_RX_live);
const unsigned int idx = (len > (17 - 5)) ? len - (17 - 5) : 0; // limit to last 'n' chars
strcpy(String, "DTMF ");
strcat(String, gDTMF_ReceivedSaved + idx);
strcat(String, gDTMF_RX_live + idx);
UI_PrintStringSmall(String, 2, 0, 3);
}