diff --git a/app/app.c b/app/app.c index 1886c3268..e4c926e60 100644 --- a/app/app.c +++ b/app/app.c @@ -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)) ) diff --git a/driver/backlight.c b/driver/backlight.c index f3c300660..80dbd8dc1 100644 --- a/driver/backlight.c +++ b/driver/backlight.c @@ -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; } diff --git a/driver/backlight.h b/driver/backlight.h index 8ab3ee4a0..8119f9073 100644 --- a/driver/backlight.h +++ b/driver/backlight.h @@ -20,7 +20,7 @@ #include #include -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 - diff --git a/functions.c b/functions.c index 72674de60..d2a4d8643 100644 --- a/functions.c +++ b/functions.c @@ -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; diff --git a/misc.c b/misc.c index 888075a38..592fb09f2 100644 --- a/misc.c +++ b/misc.c @@ -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; diff --git a/misc.h b/misc.h index db00e9e6d..d635dca64 100644 --- a/misc.h +++ b/misc.h @@ -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 -