From e5367257314355aedaf20fba0c3a59514e3f06ab Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Wed, 15 Apr 2026 00:20:13 +0200 Subject: [PATCH] Show homologated CTCSS index in Rx/Tx CTCSS menus --- App/dcs.c | 33 +++++++++++++++++++++++++++++++++ App/dcs.h | 2 +- App/ui/menu.c | 28 ++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/App/dcs.c b/App/dcs.c index 655bbcb9..a54f48b2 100644 --- a/App/dcs.c +++ b/App/dcs.c @@ -26,6 +26,12 @@ const uint16_t CTCSS_Options[50] = { 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541 }; +// Indices in CTCSS_Options for the 12 non-homologated tones. +static const uint8_t CTCSS_ExtraIdx[12] = { + 1, 26, 28, 30, 32, 34, 36, 38, 39, 41, + 45, 49 +}; + const uint16_t DCS_Options[104] = { 0x0013, 0x0015, 0x0016, 0x0019, 0x001A, 0x001E, 0x0023, 0x0027, 0x0029, 0x002B, 0x002C, 0x0035, 0x0039, 0x003A, 0x003B, 0x003C, @@ -108,3 +114,30 @@ uint8_t DCS_GetCtcssCode(int Code) return Result; } + +uint8_t DCS_GetCtcssApprovedIndex(uint8_t Option) +{ + unsigned int i; + unsigned int extra_pos = 0; + uint8_t approved_index = 0; + + if (Option >= ARRAY_SIZE(CTCSS_Options)) + return 0xFF; + + for (i = 0; i < ARRAY_SIZE(CTCSS_Options); i++) { + const bool is_extra = extra_pos < ARRAY_SIZE(CTCSS_ExtraIdx) && + i == CTCSS_ExtraIdx[extra_pos]; + + if (is_extra) { + extra_pos++; + continue; + } + + if (i == Option) + return approved_index; + + approved_index++; + } + + return 0xFF; +} diff --git a/App/dcs.h b/App/dcs.h index 2b4fbdfd..c05ecff2 100644 --- a/App/dcs.h +++ b/App/dcs.h @@ -40,6 +40,6 @@ extern const uint16_t DCS_Options[104]; uint32_t DCS_GetGolayCodeWord(DCS_CodeType_t CodeType, uint8_t Option); uint8_t DCS_GetCdcssCode(uint32_t Code); uint8_t DCS_GetCtcssCode(int Code); +uint8_t DCS_GetCtcssApprovedIndex(uint8_t Option); #endif - diff --git a/App/ui/menu.c b/App/ui/menu.c index 7ef16ad5..209115e6 100644 --- a/App/ui/menu.c +++ b/App/ui/menu.c @@ -27,6 +27,7 @@ #include "../driver/eeprom.h" #include "../driver/st7565.h" #include "../external/printf/printf.h" +#include "../font.h" #include "../frequencies.h" #include "../helper/battery.h" #include "../misc.h" @@ -1351,8 +1352,31 @@ void UI_DisplayMenu(void) || UI_MENU_GetCurrentMenuId() == MENU_D_LIST #endif ) { - sprintf(String, "%03d", gSubMenuSelection); - UI_PrintStringSmallNormal(String, 107, 0, 0); + uint8_t text_x = 107; + + if (UI_MENU_GetCurrentMenuId() == MENU_R_CTCS || + UI_MENU_GetCurrentMenuId() == MENU_T_CTCS) { + const uint8_t approved_index = + (gSubMenuSelection > 0) ? DCS_GetCtcssApprovedIndex(gSubMenuSelection - 1) : 0xFF; + + if (gSubMenuSelection == 0) + sprintf(String, "00 (00)"); + else if (approved_index != 0xFF) + sprintf(String, "%02u (%02u)", (unsigned)gSubMenuSelection, approved_index + 1); + else + sprintf(String, "%02u (--)", (unsigned)gSubMenuSelection); + + { + const uint8_t char_spacing = ARRAY_SIZE(gFontSmall[0]) + 1; + const size_t text_width = strlen(String) * char_spacing; + + text_x = (text_width < LCD_WIDTH) ? (uint8_t)(LCD_WIDTH - text_width) : 0; + } + } else { + sprintf(String, "%03d", gSubMenuSelection); + } + + UI_PrintStringSmallNormal(String, text_x, 0, 0); } if ((UI_MENU_GetCurrentMenuId() == MENU_RESET ||