diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp
index 3248f1fa4..1d8545b26 100644
--- a/companion/src/firmwares/customfunctiondata.cpp
+++ b/companion/src/firmwares/customfunctiondata.cpp
@@ -159,24 +159,24 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
if (func <= FuncInstantTrim) {
return QString("%1").arg(param);
}
- else if (func==FuncLogs) {
+ else if (func == FuncLogs) {
return QString("%1").arg(param/10.0) + tr("s");
}
- else if (func==FuncPlaySound) {
+ else if (func == FuncPlaySound) {
CustomFunctionData::populatePlaySoundParams(qs);
if (param>=0 && param<(int)qs.count())
return qs.at(param);
else
return tr("Inconsistent parameter");
}
- else if (func==FuncPlayHaptic) {
+ else if (func == FuncPlayHaptic) {
CustomFunctionData::populateHapticParams(qs);
if (param>=0 && param<(int)qs.count())
return qs.at(param);
else
return tr("Inconsistent parameter");
}
- else if (func==FuncReset) {
+ else if (func == FuncReset) {
QComboBox cb;
CustomFunctionData::populateResetParams(model, &cb);
int pos = cb.findData(param);
@@ -185,11 +185,11 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
else
return tr("Inconsistent parameter");
}
- else if ((func==FuncVolume)|| (func==FuncPlayValue)) {
+ else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) {
RawSource item(param);
return item.toString(model);
}
- else if ((func==FuncPlayPrompt) || (func==FuncPlayBoth)) {
+ else if (func == FuncPlayPrompt || func == FuncPlayBoth) {
if ( getCurrentFirmware()->getCapability(VoicesAsNumbers)) {
return QString("%1").arg(param);
}
@@ -197,7 +197,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
return paramarm;
}
}
- else if ((func>=FuncAdjustGV1) && (func= FuncAdjustGV1 && func < FuncCount) {
switch (adjustMode) {
case FUNC_ADJUST_GVAR_CONSTANT:
return tr("Value ")+QString("%1").arg(param);
@@ -231,11 +231,12 @@ QString CustomFunctionData::repeatToString() const
QString CustomFunctionData::enabledToString() const
{
- if ((func>=FuncOverrideCH1 && func<=FuncOverrideCH32) ||
- (func>=FuncAdjustGV1 && func<=FuncAdjustGVLast) ||
- (func==FuncReset) ||
- (func>=FuncSetTimer1 && func<=FuncSetTimer2) ||
- (func==FuncVolume) ||
+ if ((func >= FuncOverrideCH1 && func <= FuncOverrideCH32) ||
+ (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast) ||
+ (func == FuncReset) ||
+ (func >= FuncSetTimer1 && func <= FuncSetTimer2) ||
+ (func == FuncVolume) ||
+ (func == FuncBacklight) ||
(func <= FuncInstantTrim)) {
if (!enabled) {
return tr("DISABLED");
@@ -249,7 +250,7 @@ void CustomFunctionData::convert(RadioDataConversionState & cstate)
cstate.setComponent(tr("CFN"), 8);
cstate.setSubComp(nameToString(cstate.subCompIdx, (cstate.toModel() ? false : true)));
swtch.convert(cstate);
- if (func == FuncVolume || func == FuncPlayValue || (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast && adjustMode == 1)) {
+ if (func == FuncVolume || func == FuncBacklight || func == FuncPlayValue || (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast && adjustMode == 1)) {
param = RawSource(param).convert(cstate.withComponentField("PARAM")).toValue();
}
}
diff --git a/companion/src/firmwares/modeldata.cpp b/companion/src/firmwares/modeldata.cpp
index d849468c6..16ba240e0 100644
--- a/companion/src/firmwares/modeldata.cpp
+++ b/companion/src/firmwares/modeldata.cpp
@@ -718,7 +718,7 @@ int ModelData::updateReference()
updateAssignFunc(cfd);
if (!cfd->isEmpty()) {
updateSwitchRef(cfd->swtch);
- if (cfd->func == FuncVolume || cfd->func == FuncPlayValue || (cfd->func >= FuncAdjustGV1 && cfd->func <= FuncAdjustGVLast && (cfd->adjustMode == FUNC_ADJUST_GVAR_GVAR || cfd->adjustMode == FUNC_ADJUST_GVAR_SOURCE))) {
+ if (cfd->func == FuncVolume || cfd->func == FuncBacklight || cfd->func == FuncPlayValue || (cfd->func >= FuncAdjustGV1 && cfd->func <= FuncAdjustGVLast && (cfd->adjustMode == FUNC_ADJUST_GVAR_GVAR || cfd->adjustMode == FUNC_ADJUST_GVAR_SOURCE))) {
updateSourceIntRef(cfd->param);
if (cfd->param == 0)
cfd->clear();
diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp
index 6b8456eb2..f5c42443e 100644
--- a/companion/src/modeledit/customfunctions.cpp
+++ b/companion/src/modeledit/customfunctions.cpp
@@ -462,7 +462,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
else if (func >= FuncSetFailsafeInternalModule && func <= FuncBindExternalModule) {
widgetsMask |= CUSTOM_FUNCTION_ENABLE;
}
- else if (func == FuncVolume) {
+ else if (func == FuncVolume || func == FuncBacklight) {
if (modified)
cfn.param = fswtchParamT[i]->currentData().toInt();
populateFuncParamCB(fswtchParamT[i], func, cfn.param);
@@ -554,12 +554,6 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
}
Helpers::populateFileComboBox(fswtchParamArmT[i], scriptsSet, cfn.paramarm);
}
- else if (func == FuncBacklight && IS_TARANIS_PLUS(getCurrentBoard())) {
- if (modified)
- cfn.param = (uint8_t)fswtchBLcolor[i]->value();
- fswtchBLcolor[i]->setValue(cfn.param);
- widgetsMask |= CUSTOM_FUNCTION_BL_COLOR;
- }
else {
if (modified)
cfn.param = fswtchParam[i]->value();
@@ -701,28 +695,28 @@ void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsi
{
QStringList qs;
b->setModel(new QStandardItemModel(b)); // clear combo box but not any shared item model
- if (function==FuncPlaySound) {
+ if (function == FuncPlaySound) {
CustomFunctionData::populatePlaySoundParams(qs);
b->addItems(qs);
b->setCurrentIndex(value);
}
- else if (function==FuncPlayHaptic) {
+ else if (function == FuncPlayHaptic) {
CustomFunctionData::populateHapticParams(qs);
b->addItems(qs);
b->setCurrentIndex(value);
}
- else if (function==FuncReset) {
+ else if (function == FuncReset) {
CustomFunctionData::populateResetParams(model, b, value);
}
- else if (function==FuncVolume) {
+ else if (function == FuncVolume || function == FuncBacklight) {
b->setModel(rawSrcInputsItemModel);
b->setCurrentIndex(b->findData(value));
}
- else if (function==FuncPlayValue) {
+ else if (function == FuncPlayValue) {
b->setModel(rawSrcAllItemModel);
b->setCurrentIndex(b->findData(value));
}
- else if (function>=FuncAdjustGV1 && function<=FuncAdjustGVLast) {
+ else if (function >= FuncAdjustGV1 && function <= FuncAdjustGVLast) {
switch (adjustmode) {
case 1:
b->setModel(rawSrcInputsItemModel);
diff --git a/radio/src/functions.cpp b/radio/src/functions.cpp
index 0d1ebbf38..6b41254c4 100644
--- a/radio/src/functions.cpp
+++ b/radio/src/functions.cpp
@@ -340,7 +340,7 @@ void evalFunctions(const CustomFunctionData * functions, CustomFunctionsContext
#if defined(VARIO)
case FUNC_VARIO:
- newActiveFunctions |= (1 << FUNCTION_VARIO);
+ newActiveFunctions |= (1u << FUNCTION_VARIO);
break;
#endif
@@ -348,15 +348,22 @@ void evalFunctions(const CustomFunctionData * functions, CustomFunctionsContext
#if defined(SDCARD)
case FUNC_LOGS:
if (CFN_PARAM(cfn)) {
- newActiveFunctions |= (1 << FUNCTION_LOGS);
+ newActiveFunctions |= (1u << FUNCTION_LOGS);
logDelay = CFN_PARAM(cfn);
}
break;
#endif
case FUNC_BACKLIGHT:
- newActiveFunctions |= (1 << FUNCTION_BACKLIGHT);
+ {
+ getvalue_t raw = getValue(CFN_PARAM(cfn));
+#if defined(COLORLCD)
+ requiredBacklightBright = (1024 - raw) * (BACKLIGHT_LEVEL_MAX - BACKLIGHT_LEVEL_MIN) / 2048;
+#else
+ requiredBacklightBright = (1024 - raw) * 100 / 2048;
+#endif
break;
+ }
case FUNC_SCREENSHOT:
if (!(functionsContext.activeSwitches & switch_mask)) {
diff --git a/radio/src/globals.h b/radio/src/globals.h
index cf67dbc4a..f63dfefe0 100644
--- a/radio/src/globals.h
+++ b/radio/src/globals.h
@@ -50,6 +50,7 @@ extern uint8_t trimsDisplayMask;
extern uint16_t maxMixerDuration;
extern uint8_t requiredSpeakerVolume;
+extern uint8_t requiredBacklightBright;
enum MainRequest {
REQUEST_SCREENSHOT,
diff --git a/radio/src/gui/128x64/model_special_functions.cpp b/radio/src/gui/128x64/model_special_functions.cpp
index 2eaad8f2b..c85cdf2f2 100644
--- a/radio/src/gui/128x64/model_special_functions.cpp
+++ b/radio/src/gui/128x64/model_special_functions.cpp
@@ -338,6 +338,14 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
INCDEC_ENABLE_CHECK(isSourceAvailable);
}
}
+ else if (func == FUNC_BACKLIGHT) {
+ val_max = MIXSRC_LAST_CH;
+ drawSource(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr);
+ if (active) {
+ INCDEC_SET_FLAG(eeFlags | INCDEC_SOURCE);
+ INCDEC_ENABLE_CHECK(isSourceAvailable);
+ }
+ }
#if defined(SDCARD)
else if (func == FUNC_LOGS) {
if (val_displayed) {
diff --git a/radio/src/gui/212x64/model_special_functions.cpp b/radio/src/gui/212x64/model_special_functions.cpp
index 7c2d1e139..c8b74a124 100644
--- a/radio/src/gui/212x64/model_special_functions.cpp
+++ b/radio/src/gui/212x64/model_special_functions.cpp
@@ -338,14 +338,14 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
lcdDrawMMM(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, attr);
}
}
-#if defined(PCBX9E) || defined(PCBX9DP)
else if (func == FUNC_BACKLIGHT) {
- drawSlider(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, CFN_PARAM(cfn), 100, attr);
- if (active) INCDEC_SET_FLAG(eeFlags | NO_INCDEC_MARKS);
- val_min = 0;
- val_max = 100;
+ val_max = MIXSRC_LAST_CH;
+ drawSource(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr);
+ if (active) {
+ INCDEC_SET_FLAG(eeFlags | INCDEC_SOURCE);
+ INCDEC_ENABLE_CHECK(isSourceAvailable);
+ }
}
-#endif
#if defined(GVARS)
else if (func == FUNC_ADJUST_GVAR) {
switch (CFN_GVAR_MODE(cfn)) {
diff --git a/radio/src/gui/480x272/model_special_functions.cpp b/radio/src/gui/480x272/model_special_functions.cpp
index d8876a35d..712ab7ba2 100644
--- a/radio/src/gui/480x272/model_special_functions.cpp
+++ b/radio/src/gui/480x272/model_special_functions.cpp
@@ -333,6 +333,14 @@ bool menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
INCDEC_ENABLE_CHECK(isSourceAvailable);
}
}
+ else if (func == FUNC_BACKLIGHT) {
+ val_max = MIXSRC_LAST_CH;
+ drawSource(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr);
+ if (active) {
+ INCDEC_SET_FLAG(eeFlags | INCDEC_SOURCE);
+ INCDEC_ENABLE_CHECK(isSourceAvailable);
+ }
+ }
else if (func == FUNC_LOGS) {
if (val_displayed) {
lcdDrawNumber(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr|PREC1|LEFT, 0, NULL, "s");
diff --git a/radio/src/main.cpp b/radio/src/main.cpp
index 1490fb989..66426fd20 100644
--- a/radio/src/main.cpp
+++ b/radio/src/main.cpp
@@ -22,6 +22,8 @@
uint8_t currentSpeakerVolume = 255;
uint8_t requiredSpeakerVolume = 255;
+uint8_t currentBacklightBright = 255;
+uint8_t requiredBacklightBright = 255;
uint8_t mainRequestFlags = 0;
#if defined(STM32)
diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp
index 0e75f94d7..ee03c9f47 100644
--- a/radio/src/mixer.cpp
+++ b/radio/src/mixer.cpp
@@ -964,6 +964,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;
if (!g_model.noGlobalFunctions) {
evalFunctions(g_eeGeneral.customFn, globalFunctionsContext);
diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h
index 952e94770..304012a0c 100644
--- a/radio/src/myeeprom.h
+++ b/radio/src/myeeprom.h
@@ -57,7 +57,7 @@
#define IS_HAPTIC_FUNC(func) (0)
#endif
-#define HAS_ENABLE_PARAM(func) ((func) < FUNC_FIRST_WITHOUT_ENABLE)
+#define HAS_ENABLE_PARAM(func) ((func) < FUNC_FIRST_WITHOUT_ENABLE || (func == FUNC_BACKLIGHT))
#define HAS_REPEAT_PARAM(func) (IS_PLAY_FUNC(func) || IS_HAPTIC_FUNC(func))
#define CFN_EMPTY(p) (!(p)->swtch)
diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp
index 77bb1b894..93572e07a 100644
--- a/radio/src/opentx.cpp
+++ b/radio/src/opentx.cpp
@@ -689,12 +689,19 @@ void checkBacklight()
}
}
- bool backlightOn = (g_eeGeneral.backlightMode == e_backlight_mode_on || (g_eeGeneral.backlightMode != e_backlight_mode_off && lightOffCounter) || isFunctionActive(FUNCTION_BACKLIGHT));
- if (flashCounter) backlightOn = !backlightOn;
- if (backlightOn)
+ bool backlightOn = (g_eeGeneral.backlightMode == e_backlight_mode_on || (g_eeGeneral.backlightMode != e_backlight_mode_off && lightOffCounter));
+
+ if (flashCounter) {
+ backlightOn = !backlightOn;
+ }
+
+ if (backlightOn) {
+ currentBacklightBright = requiredBacklightBright;
BACKLIGHT_ENABLE();
- else
+ }
+ else {
BACKLIGHT_DISABLE();
+ }
}
}
@@ -1951,6 +1958,7 @@ void opentxInit()
#endif
currentSpeakerVolume = requiredSpeakerVolume = g_eeGeneral.speakerVolume + VOLUME_LEVEL_DEF;
+ currentBacklightBright = requiredBacklightBright = g_eeGeneral.backlightBright;
#if !defined(SOFTWARE_VOLUME)
setScaledVolume(currentSpeakerVolume);
#endif
diff --git a/radio/src/opentx.h b/radio/src/opentx.h
index 0d21d5df5..241b12f0c 100644
--- a/radio/src/opentx.h
+++ b/radio/src/opentx.h
@@ -487,6 +487,7 @@ void doMixerCalculations();
void scheduleNextMixerCalculation(uint8_t module, uint32_t period_ms);
void checkTrims();
+extern uint8_t currentBacklightBright;
void perMain();
void per10ms();
@@ -846,7 +847,6 @@ enum FunctionsActive {
FUNCTION_TRAINER_CHANNELS = FUNCTION_TRAINER_STICK1 + NUM_STICKS,
FUNCTION_INSTANT_TRIM,
FUNCTION_VARIO,
- FUNCTION_BACKLIGHT,
#if defined(SDCARD)
FUNCTION_LOGS,
#endif
diff --git a/radio/src/targets/horus/board.h b/radio/src/targets/horus/board.h
index e4e99d40f..46e382d3f 100644
--- a/radio/src/targets/horus/board.h
+++ b/radio/src/targets/horus/board.h
@@ -552,7 +552,7 @@ void backlightEnable(uint8_t dutyCycle = 0);
#else
#define BACKLIGHT_LEVEL_MIN 46
#endif
-#define BACKLIGHT_ENABLE() backlightEnable(globalData.unexpectedShutdown ? BACKLIGHT_LEVEL_MAX : BACKLIGHT_LEVEL_MAX - g_eeGeneral.backlightBright)
+#define BACKLIGHT_ENABLE() backlightEnable(globalData.unexpectedShutdown ? BACKLIGHT_LEVEL_MAX : BACKLIGHT_LEVEL_MAX - currentBacklightBright)
#define BACKLIGHT_DISABLE() backlightEnable(globalData.unexpectedShutdown ? BACKLIGHT_LEVEL_MAX : ((g_eeGeneral.blOffBright == BACKLIGHT_LEVEL_MIN) && (g_eeGeneral.backlightMode != e_backlight_mode_off)) ? 0 : g_eeGeneral.blOffBright)
#define isBacklightEnabled() true
diff --git a/radio/src/targets/sky9x/board.h b/radio/src/targets/sky9x/board.h
index 8b1c7275c..fd737ceb3 100644
--- a/radio/src/targets/sky9x/board.h
+++ b/radio/src/targets/sky9x/board.h
@@ -269,7 +269,7 @@ extern "C" {
#endif
// Backlight driver
-#define backlightEnable() (PWM->PWM_CH_NUM[0].PWM_CDTY = g_eeGeneral.backlightBright)
+#define backlightEnable() (PWM->PWM_CH_NUM[0].PWM_CDTY = currentBacklightBright)
#define backlightDisable() (PWM->PWM_CH_NUM[0].PWM_CDTY = 100)
#define isBacklightEnabled() (PWM->PWM_CH_NUM[0].PWM_CDTY != 100)
#define BACKLIGHT_ENABLE() backlightEnable()
diff --git a/radio/src/targets/taranis/board.h b/radio/src/targets/taranis/board.h
index 62ad32a5f..5a0b2fbdf 100644
--- a/radio/src/targets/taranis/board.h
+++ b/radio/src/targets/taranis/board.h
@@ -665,10 +665,10 @@ uint8_t isBacklightEnabled();
#define backlightEnable(...)
#elif defined(PCBX9E) || defined(PCBX9DP)
void backlightEnable(uint8_t level = 0, uint8_t color = 0);
- #define BACKLIGHT_ENABLE() backlightEnable(g_eeGeneral.backlightBright, g_eeGeneral.backlightColor)
+ #define BACKLIGHT_ENABLE() backlightEnable(currentBacklightBright, g_eeGeneral.backlightColor)
#else
void backlightEnable(uint8_t level = 0);
- #define BACKLIGHT_ENABLE() backlightEnable(g_eeGeneral.backlightBright)
+ #define BACKLIGHT_ENABLE() backlightEnable(currentBacklightBright)
#endif
#if !defined(SIMU)