Simplify backlight logic

This commit is contained in:
Juan Antonio 2023-12-04 18:09:27 +01:00 committed by Krzysiek Egzmont
parent 88f7b90237
commit bafe372cbc
6 changed files with 29 additions and 41 deletions

View File

@ -18,6 +18,7 @@
#include "am_fix.h"
#include "app/action.h"
#ifdef ENABLE_AIRCOPY
#include "app/aircopy.h"
#endif
@ -436,8 +437,9 @@ void APP_StartListening(FUNCTION_Type_t function)
AUDIO_AudioPathOn();
gEnableSpeaker = true;
if (gSetting_backlight_on_tx_rx >= BACKLIGHT_ON_TR_RX)
if (gSetting_backlight_on_tx_rx != BACKLIGHT_ON_TR_OFF) {
BACKLIGHT_TurnOn();
}
if (gScanStateDir != SCAN_OFF)
CHFRSCANNER_Found();
@ -1360,15 +1362,16 @@ void APP_TimeSlice500ms(void)
}
#endif
if (gBacklightCountdown > 0 &&
!gAskToSave &&
!gCssBackgroundScan &&
if (gBacklightCountdown_500ms > 0 && !gAskToSave && !gCssBackgroundScan &&
// don't turn off backlight if user is in backlight menu option
!(gScreenToDisplay == DISPLAY_MENU && (UI_MENU_GetCurrentMenuId() == MENU_ABR || UI_MENU_GetCurrentMenuId() == MENU_ABR_MAX))
)
{ if (--gBacklightCountdown == 0)
if (gEeprom.BACKLIGHT_TIME < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) // backlight is not set to be always on
BACKLIGHT_TurnOff(); // turn backlight off
!(gScreenToDisplay == DISPLAY_MENU && (UI_MENU_GetCurrentMenuId() == MENU_ABR || UI_MENU_GetCurrentMenuId() == MENU_ABR_MAX)))
{
if (--gBacklightCountdown_500ms == 0) {
if (gEeprom.BACKLIGHT_TIME < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) {
// backlight is not set to be always on
BACKLIGHT_TurnOff();
}
}
}
if (gSerialConfigCountDown_500ms > 0)
@ -1641,10 +1644,9 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
}
else // key pressed or held
{
const uint8_t s = gSetting_backlight_on_tx_rx;
const int m = UI_MENU_GetCurrentMenuId();
if ( //not when PTT and the backlight shouldn't turn on on TX
!(Key == KEY_PTT && s != BACKLIGHT_ON_TR_TX && s != BACKLIGHT_ON_TR_TXRX)
!(Key == KEY_PTT && !(gSetting_backlight_on_tx_rx & BACKLIGHT_ON_TR_TX))
// not in the backlight menu
&& !(gScreenToDisplay == DISPLAY_MENU && ( m == MENU_ABR || m == MENU_ABR_MAX || m == MENU_ABR_MIN))
)

View File

@ -22,7 +22,7 @@
#include "settings.h"
// this is decremented once every 500ms
uint16_t gBacklightCountdown = 0;
uint16_t gBacklightCountdown_500ms = 0;
bool backlightOn;
void BACKLIGHT_InitHardware()
@ -54,42 +54,30 @@ void BACKLIGHT_InitHardware()
void BACKLIGHT_TurnOn(void)
{
if (gEeprom.BACKLIGHT_TIME != 0) {
backlightOn = true;
BACKLIGHT_SetBrightness(gEeprom.BACKLIGHT_MAX);
}
else {
if (gEeprom.BACKLIGHT_TIME == 0) {
BACKLIGHT_TurnOff();
return;
}
switch (gEeprom.BACKLIGHT_TIME)
{
backlightOn = true;
BACKLIGHT_SetBrightness(gEeprom.BACKLIGHT_MAX);
switch (gEeprom.BACKLIGHT_TIME) {
default:
case 1: // 5 sec
gBacklightCountdown = 5;
break;
case 2: // 10 sec
gBacklightCountdown = 10;
break;
case 3: // 20 sec
gBacklightCountdown = 20;
gBacklightCountdown_500ms = 1 + (2 << (gEeprom.BACKLIGHT_TIME - 1)) * 10;
break;
case 4: // 1 min
gBacklightCountdown = 60;
break;
case 5: // 2 min
gBacklightCountdown = 60 * 2;
break;
case 6: // 4 min
gBacklightCountdown = 60 * 4;
gBacklightCountdown_500ms = 1 + (2 << (gEeprom.BACKLIGHT_TIME - 4)) * 120;
break;
case 7: // always on
gBacklightCountdown = 0;
gBacklightCountdown_500ms = 0;
break;
}
gBacklightCountdown *= 2;
}
void BACKLIGHT_TurnOff()
@ -106,7 +94,7 @@ void BACKLIGHT_TurnOff()
#else
BACKLIGHT_SetBrightness(gEeprom.BACKLIGHT_MIN);
#endif
gBacklightCountdown = 0;
gBacklightCountdown_500ms = 0;
backlightOn = false;
}

View File

@ -20,7 +20,7 @@
#include <stdint.h>
#include <stdbool.h>
extern uint16_t gBacklightCountdown;
extern uint16_t gBacklightCountdown_500ms;
extern uint8_t gBacklightBrightness;
#ifdef ENABLE_BLMIN_TMP_OFF
@ -38,4 +38,3 @@ bool BACKLIGHT_IsOn();
void BACKLIGHT_SetBrightness(uint8_t brigtness);
#endif

View File

@ -244,9 +244,9 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
else
BK4819_DisableScramble();
if (gSetting_backlight_on_tx_rx == BACKLIGHT_ON_TR_TX ||
gSetting_backlight_on_tx_rx == BACKLIGHT_ON_TR_TXRX)
if (gSetting_backlight_on_tx_rx & BACKLIGHT_ON_TR_TX) {
BACKLIGHT_TurnOn();
}
break;

2
misc.c
View File

@ -89,7 +89,7 @@ bool gSetting_350EN;
uint8_t gSetting_F_LOCK;
bool gSetting_ScrambleEnable;
uint8_t gSetting_backlight_on_tx_rx;
enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx;
#ifdef ENABLE_AM_FIX
bool gSetting_AM_fix;

3
misc.h
View File

@ -153,7 +153,7 @@ extern bool gSetting_350EN;
extern uint8_t gSetting_F_LOCK;
extern bool gSetting_ScrambleEnable;
extern uint8_t gSetting_backlight_on_tx_rx;
extern enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx;
#ifdef ENABLE_AM_FIX
extern bool gSetting_AM_fix;
@ -338,4 +338,3 @@ int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit,
unsigned long StrToUL(const char * str);
#endif