Skip to content

Commit

Permalink
feat: improved OLED brightness handling (#3773)
Browse files Browse the repository at this point in the history
  • Loading branch information
3djc authored Aug 12, 2023
1 parent f1968f9 commit 3342d21
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
9 changes: 9 additions & 0 deletions radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions radio/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions radio/src/gui/128x64/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions radio/src/gui/128x64/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion radio/src/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions radio/src/targets/taranis/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3342d21

Please sign in to comment.