1
0
Fork 0
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:
DanielGeA 2020-07-31 16:06:11 +01:00 committed by GitHub
parent ac9f510005
commit 035cc6c031
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 76 additions and 46 deletions

View file

@ -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);
@ -236,6 +236,7 @@ QString CustomFunctionData::enabledToString() const
(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();
}
}

View file

@ -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();

View file

@ -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();
@ -714,7 +708,7 @@ void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsi
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));
}

View file

@ -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)) {

View file

@ -50,6 +50,7 @@ extern uint8_t trimsDisplayMask;
extern uint16_t maxMixerDuration;
extern uint8_t requiredSpeakerVolume;
extern uint8_t requiredBacklightBright;
enum MainRequest {
REQUEST_SCREENSHOT,

View file

@ -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) {

View file

@ -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)) {

View file

@ -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");

View file

@ -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)

View file

@ -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);

View file

@ -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)

View file

@ -689,14 +689,21 @@ 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

View file

@ -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

View file

@ -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

View file

@ -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()

View file

@ -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)