mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 01:35:21 +03:00
Brightness adjust from backlight function (#7680)
Adjust brightness from backlight function
This commit is contained in:
parent
ac9f510005
commit
035cc6c031
16 changed files with 76 additions and 46 deletions
|
@ -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("<font color=red><b>Inconsistent parameter</b></font>");
|
||||
}
|
||||
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("<font color=red><b>Inconsistent parameter</b></font>");
|
||||
}
|
||||
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("<font color=red><b>Inconsistent parameter</b></font>");
|
||||
}
|
||||
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<FuncCount)) {
|
||||
else if (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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -50,6 +50,7 @@ extern uint8_t trimsDisplayMask;
|
|||
extern uint16_t maxMixerDuration;
|
||||
|
||||
extern uint8_t requiredSpeakerVolume;
|
||||
extern uint8_t requiredBacklightBright;
|
||||
|
||||
enum MainRequest {
|
||||
REQUEST_SCREENSHOT,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -689,13 +689,20 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void resetBacklightTimeout()
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue