diff --git a/radio/src/datastructs_private.h b/radio/src/datastructs_private.h index e863330a8e9..727974e9202 100644 --- a/radio/src/datastructs_private.h +++ b/radio/src/datastructs_private.h @@ -974,6 +974,15 @@ PACK(struct RadioData { uint8_t modelSFDisabled:1; uint8_t modelCustomScriptsDisabled:1; uint8_t modelTelemetryDisabled:1; + + NOBACKUP(uint8_t getBrightness() const + { +#if defined(OLED_SCREEN) + return contrast; +#else + return backlightBright; +#endif + }); }); #undef SWITCHES_WARNING_DATA diff --git a/radio/src/functions.cpp b/radio/src/functions.cpp index e3da70f9efb..0a1a9322524 100644 --- a/radio/src/functions.cpp +++ b/radio/src/functions.cpp @@ -399,6 +399,8 @@ void evalFunctions(const CustomFunctionData * functions, CustomFunctionsContext requiredBacklightBright = (1024 - raw) * (BACKLIGHT_LEVEL_MAX - BACKLIGHT_LEVEL_MIN) / 2048; +#elif defined(OLED_SCREEN) + requiredBacklightBright = (raw + 1024) * 254 / 2048; #else requiredBacklightBright = (1024 - raw) * 100 / 2048; #endif diff --git a/radio/src/gui/128x64/lcd.cpp b/radio/src/gui/128x64/lcd.cpp index 1b4bd55f478..0a7f8739cd7 100644 --- a/radio/src/gui/128x64/lcd.cpp +++ b/radio/src/gui/128x64/lcd.cpp @@ -979,6 +979,10 @@ void lcdSetContrast(bool useDefault) { #if defined(BOOT) lcdSetRefVolt(LCD_CONTRAST_DEFAULT); +#elif defined(OLED_SCREEN) + // Handled by brightness feature + if (useDefault) + lcdSetRefVolt(LCD_CONTRAST_DEFAULT); #else lcdSetRefVolt(useDefault ? LCD_CONTRAST_DEFAULT : g_eeGeneral.contrast); #endif diff --git a/radio/src/gui/128x64/radio_setup.cpp b/radio/src/gui/128x64/radio_setup.cpp index 70cf5f6b65d..396fc05f903 100644 --- a/radio/src/gui/128x64/radio_setup.cpp +++ b/radio/src/gui/128x64/radio_setup.cpp @@ -81,7 +81,6 @@ enum { CASE_IMU(ITEM_RADIO_SETUP_IMU_LABEL) CASE_IMU(ITEM_RADIO_SETUP_IMU_MAX) CASE_IMU(ITEM_RADIO_SETUP_IMU_OFFSET) - ITEM_RADIO_SETUP_CONTRAST, ITEM_RADIO_SETUP_ALARMS_LABEL, ITEM_RADIO_SETUP_BATTERY_WARNING, CASE_CAPACITY(ITEM_RADIO_SETUP_CAPACITY_WARNING) @@ -96,6 +95,7 @@ enum { CASE_PWM_BACKLIGHT(ITEM_RADIO_SETUP_BACKLIGHT_BRIGHTNESS_OFF) CASE_PWM_BACKLIGHT(ITEM_RADIO_SETUP_BACKLIGHT_BRIGHTNESS_ON) CASE_BACKLIGHT(ITEM_RADIO_SETUP_FLASH_BEEP) + ITEM_RADIO_SETUP_CONTRAST, CASE_SPLASH_PARAM(ITEM_RADIO_SETUP_DISABLE_SPLASH) ITEM_RADIO_SETUP_START_SOUND, CASE_PWR_BUTTON_PRESS(ITEM_RADIO_SETUP_PWR_ON_SPEED) @@ -183,7 +183,7 @@ void menuRadioSetup(event_t event) CASE_IMU(LABEL(IMU)) CASE_IMU(0) CASE_IMU(0) - 0, LABEL(ALARMS), 0, CASE_CAPACITY(0) + LABEL(ALARMS), 0, CASE_CAPACITY(0) 0, 0, 0, 0, /* ITEM_RADIO_SETUP_INACTIVITY_ALARM ITEM_RADIO_SETUP_MEMORY_WARNING ITEM_RADIO_SETUP_ALARM_WARNING ITEM_RADIO_SETUP_RSSI_POWEROFF_ALARM */ CASE_BACKLIGHT(LABEL(BACKLIGHT)) CASE_BACKLIGHT(0) @@ -192,6 +192,7 @@ void menuRadioSetup(event_t event) CASE_PWM_BACKLIGHT(0) CASE_PWM_BACKLIGHT(0) CASE_BACKLIGHT(0) + 0, // Contrast CASE_SPLASH_PARAM(0) 0, CASE_PWR_BUTTON_PRESS(0) @@ -463,7 +464,11 @@ void menuRadioSetup(event_t event) #endif case ITEM_RADIO_SETUP_CONTRAST: +#if defined(OLED_SCREEN) + lcdDrawTextAlignedLeft(y, STR_BRIGHTNESS); +#else lcdDrawTextAlignedLeft(y, STR_CONTRAST); +#endif lcdDrawNumber(LCD_W-2, y, g_eeGeneral.contrast, attr|RIGHT); if (attr) { CHECK_INCDEC_GENVAR(event, g_eeGeneral.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX); diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index b9878455d9e..03fbc83bd2d 100644 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -1068,7 +1068,7 @@ void evalMixes(uint8_t tick10ms) // must be done before limits because of the applyLimit function: it checks for safety switches which would be not initialized otherwise if (tick10ms) { requiredSpeakerVolume = g_eeGeneral.speakerVolume + VOLUME_LEVEL_DEF; - requiredBacklightBright = g_eeGeneral.backlightBright; + requiredBacklightBright = g_eeGeneral.getBrightness(); if (radioGFEnabled()) { evalFunctions(g_eeGeneral.customFn, globalFunctionsContext); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index a4c41f9cab9..08270412258 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -524,7 +524,7 @@ void checkBacklight() } if (requiredBacklightBright == BACKLIGHT_FORCED_ON) { - currentBacklightBright = g_eeGeneral.backlightBright; + currentBacklightBright = g_eeGeneral.getBrightness(); BACKLIGHT_ENABLE(); } else { bool backlightOn = ((g_eeGeneral.backlightMode == e_backlight_mode_on) || @@ -1567,7 +1567,8 @@ void opentxInit() initSerialPorts(); currentSpeakerVolume = requiredSpeakerVolume = g_eeGeneral.speakerVolume + VOLUME_LEVEL_DEF; - currentBacklightBright = requiredBacklightBright = g_eeGeneral.backlightBright; + currentBacklightBright = requiredBacklightBright = g_eeGeneral.getBrightness(); + #if !defined(SOFTWARE_VOLUME) setScaledVolume(currentSpeakerVolume); #endif diff --git a/radio/src/targets/taranis/board.h b/radio/src/targets/taranis/board.h index d70e51246c7..111ac60b538 100644 --- a/radio/src/targets/taranis/board.h +++ b/radio/src/targets/taranis/board.h @@ -248,8 +248,14 @@ void pwrResetHandler(); bool UNEXPECTED_SHUTDOWN(); // Backlight driver +#if defined(OLED_SCREEN) +#define BACKLIGHT_DISABLE() lcdSetRefVolt(0) +#define BACKLIGHT_FORCED_ON 255 +#else #define BACKLIGHT_DISABLE() backlightDisable() #define BACKLIGHT_FORCED_ON 101 +#endif + void backlightInit(); void backlightDisable(); @@ -260,6 +266,8 @@ uint8_t isBacklightEnabled(); void backlightEnable(uint8_t level, uint8_t color); #define BACKLIGHT_ENABLE() \ backlightEnable(currentBacklightBright, g_eeGeneral.backlightColor) +#elif defined(OLED_SCREEN) + #define BACKLIGHT_ENABLE() lcdSetRefVolt(currentBacklightBright) #else void backlightEnable(uint8_t level); #define BACKLIGHT_ENABLE() backlightEnable(currentBacklightBright) @@ -401,15 +409,15 @@ void ledBlue(); #define LCD_DEPTH 1 #define IS_LCD_RESET_NEEDED() true #if defined(OLED_SCREEN) -#define LCD_CONTRAST_MIN 5 -#define LCD_CONTRAST_MAX 255 +#define LCD_CONTRAST_MIN 2 +#define LCD_CONTRAST_MAX 254 #else #define LCD_CONTRAST_MIN 10 #define LCD_CONTRAST_MAX 30 #endif #if defined(OLED_SCREEN) - #define LCD_CONTRAST_DEFAULT 255 // full brightness + #define LCD_CONTRAST_DEFAULT 254 // full brightness #elif defined(RADIO_TX12) || defined(RADIO_TX12MK2) || defined(RADIO_BOXER) #define LCD_CONTRAST_DEFAULT 20 #elif defined(RADIO_TPRO) || defined(RADIO_FAMILY_JUMPER_T12) || defined(RADIO_TPRO) || defined(RADIO_COMMANDO8)