Unify throttle source check/conversion code

This commit is contained in:
Raphael Coeffic
2021-07-14 13:54:12 +02:00
committed by Raphael Coeffic
parent 2cbc7a6209
commit 90bd1b6329
7 changed files with 51 additions and 62 deletions
+7 -6
View File
@@ -631,12 +631,13 @@ void menuModelSetup(event_t event)
case ITEM_MODEL_SETUP_THROTTLE_TRACE:
{
lcdDrawTextAlignedLeft(y, STR_TTRACE);
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, g_model.thrTraceSrc, NUM_POTS+NUM_SLIDERS+MAX_OUTPUT_CHANNELS);
uint8_t idx = g_model.thrTraceSrc + MIXSRC_Thr;
if (idx > MIXSRC_Thr)
idx += 1;
if (idx >= MIXSRC_FIRST_POT+NUM_POTS+NUM_SLIDERS)
idx += MIXSRC_CH1 - MIXSRC_FIRST_POT - NUM_POTS - NUM_SLIDERS;
if (attr)
CHECK_INCDEC_MODELVAR_ZERO_CHECK(
event, g_model.thrTraceSrc,
NUM_POTS + NUM_SLIDERS + MAX_OUTPUT_CHANNELS,
isThrottleSourceAvailable);
uint8_t idx = throttleSource2Source(g_model.thrTraceSrc);
drawSource(MODEL_SETUP_2ND_COLUMN, y, idx, attr);
break;
}
+7 -6
View File
@@ -606,12 +606,13 @@ void menuModelSetup(event_t event)
case ITEM_MODEL_SETUP_THROTTLE_TRACE:
{
lcdDrawTextAlignedLeft(y, STR_TTRACE);
if (attr) CHECK_INCDEC_MODELVAR_ZERO_CHECK(event, g_model.thrTraceSrc, NUM_POTS+NUM_SLIDERS+MAX_OUTPUT_CHANNELS, isThrottleSourceAvailable);
uint8_t idx = g_model.thrTraceSrc + MIXSRC_Thr;
if (idx > MIXSRC_Thr)
idx += 1;
if (idx >= MIXSRC_FIRST_POT+NUM_POTS+NUM_SLIDERS)
idx += MIXSRC_CH1 - MIXSRC_FIRST_POT - NUM_POTS - NUM_SLIDERS;
if (attr)
CHECK_INCDEC_MODELVAR_ZERO_CHECK(
event, g_model.thrTraceSrc,
NUM_POTS + NUM_SLIDERS + MAX_OUTPUT_CHANNELS,
isThrottleSourceAvailable);
uint8_t idx = throttleSource2Source(g_model.thrTraceSrc);
drawSource(MODEL_SETUP_2ND_COLUMN, y, idx, attr);
break;
}
+7 -19
View File
@@ -1141,27 +1141,15 @@ void ModelSetupPage::build(FormWindow * window)
new StaticText(window, grid.getLabelSlot(true), STR_TTRACE);
auto sc = new SourceChoice(
window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH,
[=]() {
int16_t src = g_model.thrTraceSrc;
if (src == 0) return (int16_t)MIXSRC_Thr;
if (--src < NUM_POTS + NUM_SLIDERS) return (int16_t)(src + MIXSRC_FIRST_POT);
return (int16_t)(src - (NUM_POTS + NUM_SLIDERS) + MIXSRC_FIRST_CH);
},
[=]() { return throttleSource2Source(g_model.thrTraceSrc); },
[=](int16_t src) {
if (src == MIXSRC_Thr)
g_model.thrTraceSrc = 0;
else if (src <= MIXSRC_LAST_POT)
g_model.thrTraceSrc = src - MIXSRC_FIRST_POT + 1;
else if (src <= MIXSRC_LAST_CH)
g_model.thrTraceSrc = src - MIXSRC_FIRST_CH + NUM_POTS + NUM_SLIDERS + 1;
SET_DIRTY();
int16_t val = source2ThrottleSource(src);
if (val >= 0) {
g_model.thrTraceSrc = val;
SET_DIRTY();
}
});
sc->setAvailableHandler([=](int16_t src) {
return isSourceAvailable(src) &&
((src == MIXSRC_Thr) ||
((src >= MIXSRC_FIRST_POT) && (src <= MIXSRC_LAST_POT)) ||
((src >= MIXSRC_FIRST_CH) && (src <= MIXSRC_LAST_CH)));
});
sc->setAvailableHandler(isThrottleSourceAvailable);
grid.nextLine();
// Throttle trim
+8 -5
View File
@@ -442,12 +442,15 @@ bool isSwitch2POSWarningStateAvailable(int state)
// return isSwitchAvailable(swtch, TimersContext);
//}
bool isThrottleSourceAvailable(int source)
bool isThrottleSourceAvailable(int src)
{
if (source >= THROTTLE_SOURCE_FIRST_POT && source < THROTTLE_SOURCE_FIRST_POT+NUM_POTS+NUM_SLIDERS && !IS_POT_SLIDER_AVAILABLE(POT1+source-THROTTLE_SOURCE_FIRST_POT))
return false;
else
return true;
#if !defined(LIBOPENUI)
src = throttleSource2Source(src);
#endif
return isSourceAvailable(src) &&
((src == MIXSRC_Thr) ||
((src >= MIXSRC_FIRST_POT) && (src <= MIXSRC_LAST_POT)) ||
((src >= MIXSRC_FIRST_CH) && (src <= MIXSRC_LAST_CH)));
}
bool isLogicalSwitchFunctionAvailable(int function)