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

View File

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

View File

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

View File

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

2
misc.c
View File

@ -89,7 +89,7 @@ bool gSetting_350EN;
uint8_t gSetting_F_LOCK; uint8_t gSetting_F_LOCK;
bool gSetting_ScrambleEnable; bool gSetting_ScrambleEnable;
uint8_t gSetting_backlight_on_tx_rx; enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx;
#ifdef ENABLE_AM_FIX #ifdef ENABLE_AM_FIX
bool gSetting_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 uint8_t gSetting_F_LOCK;
extern bool gSetting_ScrambleEnable; 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 #ifdef ENABLE_AM_FIX
extern bool gSetting_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); unsigned long StrToUL(const char * str);
#endif #endif