From 684d330965c66823e6213f9cf4a9d4cdca87a938 Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Sun, 16 Feb 2025 05:05:19 +0100 Subject: [PATCH] ENABLE_FEAT_F4HWN_CTR and ENABLE_FEAT_F4HWN_INV refactoring --- Makefile | 10 ++++++--- app/app.c | 19 ++++++---------- app/menu.c | 8 ++++--- compile-with-docker.sh | 2 ++ driver/st7565.c | 2 ++ driver/st7565.h | 2 ++ settings.c | 6 +++++- ui/menu.c | 49 +++++++++++++++++++++++++----------------- ui/menu.h | 1 + ui/welcome.c | 4 ++-- 10 files changed, 62 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 8180f6e..d55d9db 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,8 @@ ENABLE_FEAT_F4HWN_CHARGING_C ?= 0 ENABLE_FEAT_F4HWN_SLEEP ?= 1 ENABLE_FEAT_F4HWN_RESUME_STATE ?= 1 ENABLE_FEAT_F4HWN_NARROWER ?= 1 -ENABLE_FEAT_F4HWN_CONTRAST ?= 1 +ENABLE_FEAT_F4HWN_INV ?= 1 +ENABLE_FEAT_F4HWN_CTR ?= 1 ENABLE_FEAT_F4HWN_RESCUE_OPS ?= 0 ENABLE_FEAT_F4HWN_VOL ?= 0 ENABLE_FEAT_F4HWN_RESET_CHANNEL ?= 0 @@ -450,8 +451,11 @@ endif ifeq ($(ENABLE_FEAT_F4HWN_NARROWER),1) CFLAGS += -DENABLE_FEAT_F4HWN_NARROWER endif -ifeq ($(ENABLE_FEAT_F4HWN_CONTRAST),1) - CFLAGS += -DENABLE_FEAT_F4HWN_CONTRAST +ifeq ($(ENABLE_FEAT_F4HWN_INV),1) + CFLAGS += -DENABLE_FEAT_F4HWN_INV +endif +ifeq ($(ENABLE_FEAT_F4HWN_CTR),1) + CFLAGS += -DENABLE_FEAT_F4HWN_CTR endif ifneq ($(filter $(ENABLE_FEAT_F4HWN_RESCUE_OPS),1 2),) CFLAGS += -DENABLE_FEAT_F4HWN_RESCUE_OPS=$(ENABLE_FEAT_F4HWN_RESCUE_OPS) diff --git a/app/app.c b/app/app.c index da588f1..3fa9e1f 100644 --- a/app/app.c +++ b/app/app.c @@ -969,19 +969,10 @@ void APP_Update(void) //if (gKeyReading1 != KEY_INVALID) // gPttWasReleased = true; } + #if defined(ENABLE_FEAT_F4HWN_CTR) || defined(ENABLE_FEAT_F4HWN_INV) ST7565_ContrastAndInv(); + #endif } - /* - if (gSetting_set_ptt_session) // Improve OnePush if TOT - { - ProcessKey(KEY_PTT, false, false); - gPttIsPressed = false; - gPttOnePushCounter = 0; - if (gKeyReading1 != KEY_INVALID) - gPttWasReleased = true; - ST7565_ContrastAndInv(); - } - */ #endif APP_EndTransmission(); @@ -1216,7 +1207,9 @@ static void CheckKeys(void) if (gKeyReading1 != KEY_INVALID) gPttWasReleased = true; gPttOnePushCounter = 0; - ST7565_ContrastAndInv(); + #if defined(ENABLE_FEAT_F4HWN_CTR) || defined(ENABLE_FEAT_F4HWN_INV) + ST7565_ContrastAndInv(); + #endif } } else @@ -1236,7 +1229,9 @@ static void CheckKeys(void) gPttIsPressed = false; if (gKeyReading1 != KEY_INVALID) gPttWasReleased = true; + #if defined(ENABLE_FEAT_F4HWN_CTR) || defined(ENABLE_FEAT_F4HWN_INV) ST7565_ContrastAndInv(); + #endif } } else diff --git a/app/menu.c b/app/menu.c index d7de178..683a518 100644 --- a/app/menu.c +++ b/app/menu.c @@ -400,17 +400,19 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) //*pMin = 0; *pMax = ARRAY_SIZE(gSubMenu_SET_TOT) - 1; break; -#ifdef ENABLE_FEAT_F4HWN_CONTRAST +#ifdef ENABLE_FEAT_F4HWN_CTR case MENU_SET_CTR: *pMin = 1; *pMax = 15; break; #endif case MENU_TX_LOCK: +#ifdef ENABLE_FEAT_F4HWN_INV case MENU_SET_INV: //*pMin = 0; *pMax = ARRAY_SIZE(gSubMenu_OFF_ON) - 1; break; +#endif case MENU_SET_LCK: //*pMin = 0; *pMax = ARRAY_SIZE(gSubMenu_SET_LCK) - 1; @@ -928,7 +930,7 @@ void MENU_AcceptSetting(void) case MENU_SET_EOT: gSetting_set_eot = gSubMenuSelection; break; -#ifdef ENABLE_FEAT_F4HWN_CONTRAST +#ifdef ENABLE_FEAT_F4HWN_CTR case MENU_SET_CTR: gSetting_set_ctr = gSubMenuSelection; break; @@ -1381,7 +1383,7 @@ void MENU_ShowCurrentSetting(void) case MENU_SET_EOT: gSubMenuSelection = gSetting_set_eot; break; -#ifdef ENABLE_FEAT_F4HWN_CONTRAST +#ifdef ENABLE_FEAT_F4HWN_CTR case MENU_SET_CTR: gSubMenuSelection = gSetting_set_ctr; break; diff --git a/compile-with-docker.sh b/compile-with-docker.sh index 7ead853..a5bb127 100755 --- a/compile-with-docker.sh +++ b/compile-with-docker.sh @@ -75,6 +75,8 @@ voxless() { ENABLE_FEAT_F4HWN_RESUME_STATE=0 \ ENABLE_FEAT_F4HWN_CHARGING_C=0 \ ENABLE_FEAT_F4HWN_NARROWER=0 \ + ENABLE_FEAT_F4HWN_INV=0 \ + ENABLE_FEAT_F4HWN_CTR=0 \ ENABLE_FEAT_F4HWN_RESCUE_OPS=0 \ EDITION_STRING=Voxless \ TARGET=f4hwn.voxless \ diff --git a/driver/st7565.c b/driver/st7565.c index 80670cb..e649380 100644 --- a/driver/st7565.c +++ b/driver/st7565.c @@ -209,6 +209,7 @@ uint8_t cmds[] = { } } + #if defined(ENABLE_FEAT_F4HWN_CTR) || defined(ENABLE_FEAT_F4HWN_INV) void ST7565_ContrastAndInv(void) { SPI_ToggleMasterMode(&SPI0->CR, false); @@ -219,6 +220,7 @@ uint8_t cmds[] = { ST7565_Cmd(i); } } + #endif int16_t map(int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; diff --git a/driver/st7565.h b/driver/st7565.h index 8d4a6e8..5248c57 100644 --- a/driver/st7565.h +++ b/driver/st7565.h @@ -42,7 +42,9 @@ void ST7565_SelectColumnAndLine(uint8_t Column, uint8_t Line); void ST7565_WriteByte(uint8_t Value); #ifdef ENABLE_FEAT_F4HWN + #if defined(ENABLE_FEAT_F4HWN_CTR) || defined(ENABLE_FEAT_F4HWN_INV) void ST7565_ContrastAndInv(void); + #endif #if !defined(ENABLE_SPECTRUM) || !defined(ENABLE_FMRADIO) void ST7565_Gauge(uint8_t line, uint8_t min, uint8_t max, uint8_t value); #endif diff --git a/settings.c b/settings.c index daca4c3..c79fcb3 100644 --- a/settings.c +++ b/settings.c @@ -363,12 +363,16 @@ void SETTINGS_InitEEPROM(void) int tmp = (Data[5] & 0xF0) >> 4; +#ifdef ENABLE_FEAT_F4HWN_INV gSetting_set_inv = (tmp >> 0) & 0x01; +#else + gSetting_set_inv = 0; +#endif gSetting_set_lck = (tmp >> 1) & 0x01; gSetting_set_met = (tmp >> 2) & 0x01; gSetting_set_gui = (tmp >> 3) & 0x01; -#ifdef ENABLE_FEAT_F4HWN_CONTRAST +#ifdef ENABLE_FEAT_F4HWN_CTR int ctr_value = Data[5] & 0x0F; gSetting_set_ctr = (ctr_value > 0 && ctr_value < 16) ? ctr_value : 10; #else diff --git a/ui/menu.c b/ui/menu.c index 848c009..cab289a 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -139,9 +139,7 @@ const t_menu_item MenuList[] = {"SetPTT", MENU_SET_PTT }, {"SetTOT", MENU_SET_TOT }, {"SetEOT", MENU_SET_EOT }, -#ifdef ENABLE_FEAT_F4HWN_CONTRAST {"SetCtr", MENU_SET_CTR }, -#endif {"SetInv", MENU_SET_INV }, {"SetLck", MENU_SET_LCK }, {"SetMet", MENU_SET_MET }, @@ -218,6 +216,11 @@ const char gSubMenu_OFF_ON[][4] = "ON" }; +const char gSubMenu_NA[4] = +{ + "N/A" +}; + const char* const gSubMenu_RXMode[] = { "MAIN\nONLY", // TX and RX on main only @@ -618,7 +621,7 @@ void UI_DisplayMenu(void) #ifdef ENABLE_AUDIO_BAR strcpy(String, gSubMenu_OFF_ON[gSubMenuSelection]); #else - strcpy(String, gSubMenu_OFF_ON[0]); + strcpy(String, gSubMenu_NA); #endif break; @@ -642,7 +645,7 @@ void UI_DisplayMenu(void) case MENU_R_DCS: case MENU_T_DCS: if (gSubMenuSelection == 0) - strcpy(String, "OFF"); + strcpy(String, gSubMenu_OFF_ON[0]); else if (gSubMenuSelection < 105) sprintf(String, "D%03oN", DCS_Options[gSubMenuSelection - 1]); else @@ -653,7 +656,7 @@ void UI_DisplayMenu(void) case MENU_T_CTCS: { if (gSubMenuSelection == 0) - strcpy(String, "OFF"); + strcpy(String, gSubMenu_OFF_ON[0]); else sprintf(String, "%u.%uHz", CTCSS_Options[gSubMenuSelection - 1] / 10, CTCSS_Options[gSubMenuSelection - 1] % 10); break; @@ -699,16 +702,16 @@ void UI_DisplayMenu(void) case MENU_VOX: #ifdef ENABLE_VOX - sprintf(String, gSubMenuSelection == 0 ? "OFF" : "%u", gSubMenuSelection); + sprintf(String, gSubMenuSelection == 0 ? gSubMenu_OFF_ON[0] : "%u", gSubMenuSelection); #else - strcpy(String, gSubMenu_OFF_ON[0]); + strcpy(String, gSubMenu_NA); #endif break; case MENU_ABR: if(gSubMenuSelection == 0) { - strcpy(String, "OFF"); + strcpy(String, gSubMenu_OFF_ON[0]); } else if(gSubMenuSelection < 61) { @@ -743,7 +746,7 @@ void UI_DisplayMenu(void) case MENU_AUTOLK: if (gSubMenuSelection == 0) - strcpy(String, "OFF"); + strcpy(String, gSubMenu_OFF_ON[0]); else { sprintf(String, "%02dm:%02ds", ((gSubMenuSelection * 15) / 60), ((gSubMenuSelection * 15) % 60)); @@ -855,7 +858,7 @@ void UI_DisplayMenu(void) } case MENU_SAVE: - sprintf(String, gSubMenuSelection == 0 ? "OFF" : "1:%u", gSubMenuSelection); + sprintf(String, gSubMenuSelection == 0 ? gSubMenu_OFF_ON[0] : "1:%u", gSubMenuSelection); break; case MENU_TDR: @@ -901,7 +904,7 @@ void UI_DisplayMenu(void) break; case MENU_RP_STE: - sprintf(String, gSubMenuSelection == 0 ? "OFF" : "%u*100ms", gSubMenuSelection); + sprintf(String, gSubMenuSelection == 0 ? gSubMenu_OFF_ON[0] : "%u*100ms", gSubMenuSelection); break; case MENU_S_LIST: @@ -1039,7 +1042,7 @@ void UI_DisplayMenu(void) case MENU_SET_OFF: if(gSubMenuSelection == 0) { - strcpy(String, "OFF"); + strcpy(String, gSubMenu_OFF_ON[0]); } else if(gSubMenuSelection < 121) { @@ -1065,17 +1068,23 @@ void UI_DisplayMenu(void) strcpy(String, gSubMenu_SET_TOT[gSubMenuSelection]); // Same as SET_TOT break; -#ifdef ENABLE_FEAT_F4HWN_CONTRAST case MENU_SET_CTR: - sprintf(String, "%d", gSubMenuSelection); - gSetting_set_ctr = gSubMenuSelection; - ST7565_ContrastAndInv(); + #ifdef ENABLE_FEAT_F4HWN_CTR + sprintf(String, "%d", gSubMenuSelection); + gSetting_set_ctr = gSubMenuSelection; + ST7565_ContrastAndInv(); + #else + strcpy(String, gSubMenu_NA); + #endif break; -#endif case MENU_SET_INV: - strcpy(String, gSubMenu_OFF_ON[gSubMenuSelection]); - ST7565_ContrastAndInv(); + #ifdef ENABLE_FEAT_F4HWN_INV + strcpy(String, gSubMenu_OFF_ON[gSubMenuSelection]); + ST7565_ContrastAndInv(); + #else + strcpy(String, gSubMenu_NA); + #endif break; case MENU_TX_LOCK: @@ -1108,7 +1117,7 @@ void UI_DisplayMenu(void) case MENU_SET_VOL: if(gSubMenuSelection == 0) { - strcpy(String, "OFF"); + strcpy(String, gSubMenu_OFF_ON[0]); } else if(gSubMenuSelection < 64) { diff --git a/ui/menu.h b/ui/menu.h index 733f396..de6f5a1 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -168,6 +168,7 @@ extern const char gSubMenu_TXP[8][6]; extern const char gSubMenu_SFT_D[3][4]; extern const char gSubMenu_W_N[2][7]; extern const char gSubMenu_OFF_ON[2][4]; +extern const char gSubMenu_NA[4]; extern const char gSubMenu_TOT[11][7]; extern const char* const gSubMenu_RXMode[4]; diff --git a/ui/welcome.c b/ui/welcome.c index 6a5d79e..023cee6 100644 --- a/ui/welcome.c +++ b/ui/welcome.c @@ -31,7 +31,7 @@ void UI_DisplayReleaseKeys(void) { memset(gStatusLine, 0, sizeof(gStatusLine)); -#ifdef ENABLE_FEAT_F4HWN +#if defined(ENABLE_FEAT_F4HWN_CTR) || defined(ENABLE_FEAT_F4HWN_INV) ST7565_ContrastAndInv(); #endif UI_DisplayClear(); @@ -52,7 +52,7 @@ void UI_DisplayWelcome(void) memset(gStatusLine, 0, sizeof(gStatusLine)); -#ifdef ENABLE_FEAT_F4HWN +#if defined(ENABLE_FEAT_F4HWN_CTR) || defined(ENABLE_FEAT_F4HWN_INV) ST7565_ContrastAndInv(); #endif UI_DisplayClear();