From 4a144cb52246f2897ae1ebedbc753c5e674dcf54 Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Tue, 24 Sep 2024 22:55:33 +0200 Subject: [PATCH] Add SetOff menu (experimental) --- Makefile | 4 ++++ app/app.c | 25 +++++++++++++++++++++++++ app/menu.c | 18 ++++++++++++++++++ driver/backlight.c | 8 ++++++++ driver/backlight.h | 4 ++++ driver/st7565.c | 11 +++++++++++ driver/st7565.h | 3 +++ main.c | 6 +++++- misc.c | 5 +++++ misc.h | 5 +++++ settings.c | 9 ++++++++- ui/menu.c | 16 ++++++++++++++++ ui/menu.h | 3 +++ 13 files changed, 115 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index adfadba..bc3d846 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ ENABLE_FEAT_F4HWN_SCREENSHOT ?= 0 ENABLE_FEAT_F4HWN_SPECTRUM ?= 1 ENABLE_FEAT_F4HWN_RX_TX_TIMER ?= 1 ENABLE_FEAT_F4HWN_CHARGING_C ?= 1 +ENABLE_FEAT_F4HWN_SLEEP ?= 1 ENABLE_FEAT_F4HWN_PMR ?= 0 ENABLE_FEAT_F4HWN_GMRS_FRS_MURS ?= 0 ENABLE_FEAT_F4HWN_CA ?= 1 @@ -418,6 +419,9 @@ endif ifeq ($(ENABLE_FEAT_F4HWN_CHARGING_C),1) CFLAGS += -DENABLE_FEAT_F4HWN_CHARGING_C endif +ifeq ($(ENABLE_FEAT_F4HWN_SLEEP),1) + CFLAGS += -DENABLE_FEAT_F4HWN_SLEEP +endif ifeq ($(ENABLE_FEAT_F4HWN_PMR),1) CFLAGS += -DENABLE_FEAT_F4HWN_PMR endif diff --git a/app/app.c b/app/app.c index a0c364a..1bd862e 100644 --- a/app/app.c +++ b/app/app.c @@ -1567,6 +1567,31 @@ void APP_TimeSlice500ms(void) BACKLIGHT_TurnOff(); } +#ifdef ENABLE_FEAT_F4HWN_SLEEP + if (gSleepModeCountdown_500ms == gSetting_set_off * 120 && gWakeUp) { + ST7565_Init(); + BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, false); + BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false); + gWakeUp = false; + } + + if (gSleepModeCountdown_500ms > 0 && --gSleepModeCountdown_500ms == 0) { + gBacklightCountdown_500ms = 0; + BACKLIGHT_TurnOff(); + ST7565_ShutDown(); + gWakeUp = true; + gPowerSaveCountdownExpired = true; + } + + if (gWakeUp) { + static bool swap = true; + swap = !swap; // Alterne l'état à chaque exécution + BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, swap); + BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, swap); + FUNCTION_Select(FUNCTION_POWER_SAVE); + } +#endif + if (gReducedService) { BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage, &gBatteryCurrent); diff --git a/app/menu.c b/app/menu.c index c440677..958dd60 100644 --- a/app/menu.c +++ b/app/menu.c @@ -376,6 +376,12 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) *pMax = gSubMenu_SIDEFUNCTIONS_size-1; break; +#ifdef ENABLE_FEAT_F4HWN_SLEEP + case MENU_SET_OFF: + *pMax = 120; + break; +#endif + #ifdef ENABLE_FEAT_F4HWN case MENU_SET_PWR: *pMax = ARRAY_SIZE(gSubMenu_SET_PWR) - 1; @@ -868,6 +874,12 @@ void MENU_AcceptSetting(void) } break; +#ifdef ENABLE_FEAT_F4HWN_SLEEP + case MENU_SET_OFF: + gSetting_set_off = gSubMenuSelection; + break; +#endif + #ifdef ENABLE_FEAT_F4HWN case MENU_SET_PWR: gSetting_set_pwr = gSubMenuSelection; @@ -1294,6 +1306,12 @@ void MENU_ShowCurrentSetting(void) break; } +#ifdef ENABLE_FEAT_F4HWN_SLEEP + case MENU_SET_OFF: + gSubMenuSelection = gSetting_set_off; + break; +#endif + #ifdef ENABLE_FEAT_F4HWN case MENU_SET_PWR: gSubMenuSelection = gSetting_set_pwr; diff --git a/driver/backlight.c b/driver/backlight.c index 8bac46a..1248975 100644 --- a/driver/backlight.c +++ b/driver/backlight.c @@ -31,6 +31,10 @@ uint16_t gBacklightCountdown_500ms = 0; bool backlightOn; +#ifdef ENABLE_FEAT_F4HWN_SLEEP + uint16_t gSleepModeCountdown_500ms = 0; +#endif + void BACKLIGHT_InitHardware() { // 48MHz / 94 / 1024 ~ 500Hz @@ -117,6 +121,10 @@ void BACKLIGHT_TurnOn(void) gBacklightCountdown_500ms = 0; break; } + + #ifdef ENABLE_FEAT_F4HWN_SLEEP + gSleepModeCountdown_500ms = gSetting_set_off * 120; + #endif } void BACKLIGHT_TurnOff() diff --git a/driver/backlight.h b/driver/backlight.h index ae3b268..12271e2 100644 --- a/driver/backlight.h +++ b/driver/backlight.h @@ -23,6 +23,10 @@ extern uint16_t gBacklightCountdown_500ms; extern uint8_t gBacklightBrightness; +#ifdef ENABLE_FEAT_F4HWN_SLEEP + extern uint16_t gSleepModeCountdown_500ms; +#endif + #ifdef ENABLE_BLMIN_TMP_OFF typedef enum { BLMIN_STAT_ON, diff --git a/driver/st7565.c b/driver/st7565.c index 4e008f3..fc3723d 100644 --- a/driver/st7565.c +++ b/driver/st7565.c @@ -256,6 +256,17 @@ void ST7565_Init(void) ST7565_FillScreen(0x00); } +#ifdef ENABLE_FEAT_F4HWN_SLEEP + void ST7565_ShutDown(void) + { + SPI_ToggleMasterMode(&SPI0->CR, false); + ST7565_WriteByte(ST7565_CMD_POWER_CIRCUIT | 0b000); // VB=0 VR=1 VF=1 + ST7565_WriteByte(ST7565_CMD_SET_START_LINE | 0); // line 0 + ST7565_WriteByte(ST7565_CMD_DISPLAY_ON_OFF | 0); // D=1 + SPI_ToggleMasterMode(&SPI0->CR, true); + } +#endif + void ST7565_FixInterfGlitch(void) { SPI_ToggleMasterMode(&SPI0->CR, false); diff --git a/driver/st7565.h b/driver/st7565.h index 80b43e1..d7e9e17 100644 --- a/driver/st7565.h +++ b/driver/st7565.h @@ -33,6 +33,9 @@ void ST7565_BlitLine(unsigned line); void ST7565_BlitStatusLine(void); void ST7565_FillScreen(uint8_t Value); void ST7565_Init(void); +#ifdef ENABLE_FEAT_F4HWN_SLEEP + void ST7565_ShutDown(void); +#endif void ST7565_FixInterfGlitch(void); void ST7565_HardwareReset(void); void ST7565_SelectColumnAndLine(uint8_t Column, uint8_t Line); diff --git a/main.c b/main.c index ec83117..3af6286 100644 --- a/main.c +++ b/main.c @@ -131,7 +131,11 @@ void Main(void) #ifndef ENABLE_VOX gMenuCursor = 64; // move to hidden section, fix me if change... !!! Remove VOX and Mic Bar #else - gMenuCursor = 66; // move to hidden section, fix me if change... !!! + #ifdef ENABLE_FEAT_F4HWN_SLEEP + gMenuCursor = 67; // move to hidden section, fix me if change... !!! + #else + gMenuCursor = 66; // move to hidden section, fix me if change... !!! + #endif #endif gSubMenuSelection = gSetting_F_LOCK; #endif diff --git a/misc.c b/misc.c index 6abf843..0e0b476 100644 --- a/misc.c +++ b/misc.c @@ -104,6 +104,11 @@ enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx; bool gSetting_AM_fix = true; #endif +#ifdef ENABLE_FEAT_F4HWN_SLEEP + uint8_t gSetting_set_off = 1; + bool gWakeUp = false; +#endif + #ifdef ENABLE_FEAT_F4HWN uint8_t gSetting_set_pwr = 1; bool gSetting_set_ptt = 0; diff --git a/misc.h b/misc.h index 854e6e4..2377fc1 100644 --- a/misc.h +++ b/misc.h @@ -156,6 +156,11 @@ extern enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx; extern bool gSetting_AM_fix; #endif +#ifdef ENABLE_FEAT_F4HWN_SLEEP + extern uint8_t gSetting_set_off; + extern bool gWakeUp; +#endif + #ifdef ENABLE_FEAT_F4HWN extern uint8_t gSetting_set_pwr; extern bool gSetting_set_ptt; diff --git a/settings.c b/settings.c index 129eb58..cd5d0b9 100644 --- a/settings.c +++ b/settings.c @@ -346,7 +346,10 @@ void SETTINGS_InitEEPROM(void) int ctr_value = Data[5] & 0x0F; gSetting_set_ctr = (ctr_value > 0 && ctr_value < 16) ? ctr_value : 10; - gSetting_set_tmr = Data[4] & 1; + gSetting_set_tmr = Data[4] & 0x01; +#ifdef ENABLE_FEAT_F4HWN_SLEEP + gSetting_set_off = Data[4] >> 1; +#endif // Warning // Be aware, Data[3] is use by Spectrum @@ -740,7 +743,11 @@ void SETTINGS_SaveSettings(void) tmp = tmp | (1 << 3); */ +#ifdef ENABLE_FEAT_F4HWN_SLEEP + State[4] = (gSetting_set_off << 1) | (gSetting_set_tmr & 0x01); +#else State[4] = gSetting_set_tmr ? (1 << 0) : 0; +#endif tmp = (gSetting_set_inv << 0) | (gSetting_set_lck << 1) | diff --git a/ui/menu.c b/ui/menu.c index ae94141..8fad146 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -147,6 +147,9 @@ const t_menu_item MenuList[] = {"SetMet", MENU_SET_MET }, {"SetGui", MENU_SET_GUI }, {"SetTmr", MENU_SET_TMR }, +#ifdef ENABLE_FEAT_F4HWN_SLEEP + {"SetOff", MENU_SET_OFF }, +#endif #endif // hidden menu items from here on // enabled if pressing both the PTT and upper side button at power-on @@ -978,6 +981,19 @@ void UI_DisplayMenu(void) strcpy(String, gSubMenu_SIDEFUNCTIONS[gSubMenuSelection].name); break; +#ifdef ENABLE_FEAT_F4HWN_SLEEP + case MENU_SET_OFF: + if(gSubMenuSelection == 0) + { + sprintf(String, "%s", "OFF"); + } + else if(gSubMenuSelection < 121) + { + sprintf(String, "%02dh:%02dm", (gSubMenuSelection / 60), (gSubMenuSelection % 60)); + } + break; +#endif + #ifdef ENABLE_FEAT_F4HWN case MENU_SET_PWR: sprintf(String, "%s\n%sW", gSubMenu_TXP[gSubMenuSelection + 1], gSubMenu_SET_PWR[gSubMenuSelection]); diff --git a/ui/menu.h b/ui/menu.h index 4b4ac43..d4f1d28 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -125,6 +125,9 @@ enum #ifdef ENABLE_F_CAL_MENU MENU_F_CALI, // reference xtal calibration #endif +#ifdef ENABLE_FEAT_F4HWN_SLEEP + MENU_SET_OFF, +#endif #ifdef ENABLE_FEAT_F4HWN MENU_SET_PWR, MENU_SET_PTT,