Unify throttle source check/conversion code
This commit is contained in:
committed by
Raphael Coeffic
parent
2cbc7a6209
commit
90bd1b6329
@@ -631,12 +631,13 @@ void menuModelSetup(event_t event)
|
|||||||
case ITEM_MODEL_SETUP_THROTTLE_TRACE:
|
case ITEM_MODEL_SETUP_THROTTLE_TRACE:
|
||||||
{
|
{
|
||||||
lcdDrawTextAlignedLeft(y, STR_TTRACE);
|
lcdDrawTextAlignedLeft(y, STR_TTRACE);
|
||||||
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, g_model.thrTraceSrc, NUM_POTS+NUM_SLIDERS+MAX_OUTPUT_CHANNELS);
|
if (attr)
|
||||||
uint8_t idx = g_model.thrTraceSrc + MIXSRC_Thr;
|
CHECK_INCDEC_MODELVAR_ZERO_CHECK(
|
||||||
if (idx > MIXSRC_Thr)
|
event, g_model.thrTraceSrc,
|
||||||
idx += 1;
|
NUM_POTS + NUM_SLIDERS + MAX_OUTPUT_CHANNELS,
|
||||||
if (idx >= MIXSRC_FIRST_POT+NUM_POTS+NUM_SLIDERS)
|
isThrottleSourceAvailable);
|
||||||
idx += MIXSRC_CH1 - MIXSRC_FIRST_POT - NUM_POTS - NUM_SLIDERS;
|
|
||||||
|
uint8_t idx = throttleSource2Source(g_model.thrTraceSrc);
|
||||||
drawSource(MODEL_SETUP_2ND_COLUMN, y, idx, attr);
|
drawSource(MODEL_SETUP_2ND_COLUMN, y, idx, attr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -606,12 +606,13 @@ void menuModelSetup(event_t event)
|
|||||||
case ITEM_MODEL_SETUP_THROTTLE_TRACE:
|
case ITEM_MODEL_SETUP_THROTTLE_TRACE:
|
||||||
{
|
{
|
||||||
lcdDrawTextAlignedLeft(y, STR_TTRACE);
|
lcdDrawTextAlignedLeft(y, STR_TTRACE);
|
||||||
if (attr) CHECK_INCDEC_MODELVAR_ZERO_CHECK(event, g_model.thrTraceSrc, NUM_POTS+NUM_SLIDERS+MAX_OUTPUT_CHANNELS, isThrottleSourceAvailable);
|
if (attr)
|
||||||
uint8_t idx = g_model.thrTraceSrc + MIXSRC_Thr;
|
CHECK_INCDEC_MODELVAR_ZERO_CHECK(
|
||||||
if (idx > MIXSRC_Thr)
|
event, g_model.thrTraceSrc,
|
||||||
idx += 1;
|
NUM_POTS + NUM_SLIDERS + MAX_OUTPUT_CHANNELS,
|
||||||
if (idx >= MIXSRC_FIRST_POT+NUM_POTS+NUM_SLIDERS)
|
isThrottleSourceAvailable);
|
||||||
idx += MIXSRC_CH1 - MIXSRC_FIRST_POT - NUM_POTS - NUM_SLIDERS;
|
|
||||||
|
uint8_t idx = throttleSource2Source(g_model.thrTraceSrc);
|
||||||
drawSource(MODEL_SETUP_2ND_COLUMN, y, idx, attr);
|
drawSource(MODEL_SETUP_2ND_COLUMN, y, idx, attr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1141,27 +1141,15 @@ void ModelSetupPage::build(FormWindow * window)
|
|||||||
new StaticText(window, grid.getLabelSlot(true), STR_TTRACE);
|
new StaticText(window, grid.getLabelSlot(true), STR_TTRACE);
|
||||||
auto sc = new SourceChoice(
|
auto sc = new SourceChoice(
|
||||||
window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH,
|
window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH,
|
||||||
[=]() {
|
[=]() { return throttleSource2Source(g_model.thrTraceSrc); },
|
||||||
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);
|
|
||||||
},
|
|
||||||
[=](int16_t src) {
|
[=](int16_t src) {
|
||||||
if (src == MIXSRC_Thr)
|
int16_t val = source2ThrottleSource(src);
|
||||||
g_model.thrTraceSrc = 0;
|
if (val >= 0) {
|
||||||
else if (src <= MIXSRC_LAST_POT)
|
g_model.thrTraceSrc = val;
|
||||||
g_model.thrTraceSrc = src - MIXSRC_FIRST_POT + 1;
|
SET_DIRTY();
|
||||||
else if (src <= MIXSRC_LAST_CH)
|
}
|
||||||
g_model.thrTraceSrc = src - MIXSRC_FIRST_CH + NUM_POTS + NUM_SLIDERS + 1;
|
|
||||||
SET_DIRTY();
|
|
||||||
});
|
});
|
||||||
sc->setAvailableHandler([=](int16_t src) {
|
sc->setAvailableHandler(isThrottleSourceAvailable);
|
||||||
return isSourceAvailable(src) &&
|
|
||||||
((src == MIXSRC_Thr) ||
|
|
||||||
((src >= MIXSRC_FIRST_POT) && (src <= MIXSRC_LAST_POT)) ||
|
|
||||||
((src >= MIXSRC_FIRST_CH) && (src <= MIXSRC_LAST_CH)));
|
|
||||||
});
|
|
||||||
grid.nextLine();
|
grid.nextLine();
|
||||||
|
|
||||||
// Throttle trim
|
// Throttle trim
|
||||||
|
|||||||
@@ -442,12 +442,15 @@ bool isSwitch2POSWarningStateAvailable(int state)
|
|||||||
// return isSwitchAvailable(swtch, TimersContext);
|
// 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))
|
#if !defined(LIBOPENUI)
|
||||||
return false;
|
src = throttleSource2Source(src);
|
||||||
else
|
#endif
|
||||||
return true;
|
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)
|
bool isLogicalSwitchFunctionAvailable(int function)
|
||||||
|
|||||||
@@ -229,32 +229,6 @@ enum SwashType {
|
|||||||
|
|
||||||
#include "pulses/modules_constants.h"
|
#include "pulses/modules_constants.h"
|
||||||
|
|
||||||
enum ThrottleSources {
|
|
||||||
THROTTLE_SOURCE_THR,
|
|
||||||
THROTTLE_SOURCE_FIRST_POT,
|
|
||||||
#if defined(PCBX9E)
|
|
||||||
THROTTLE_SOURCE_F1 = THROTTLE_SOURCE_FIRST_POT,
|
|
||||||
THROTTLE_SOURCE_F2,
|
|
||||||
THROTTLE_SOURCE_F3,
|
|
||||||
THROTTLE_SOURCE_F4,
|
|
||||||
THROTTLE_SOURCE_S1,
|
|
||||||
THROTTLE_SOURCE_S2,
|
|
||||||
THROTTLE_SOURCE_LS,
|
|
||||||
THROTTLE_SOURCE_RS,
|
|
||||||
#elif defined(PCBTARANIS)
|
|
||||||
THROTTLE_SOURCE_S1 = THROTTLE_SOURCE_FIRST_POT,
|
|
||||||
THROTTLE_SOURCE_S2,
|
|
||||||
THROTTLE_SOURCE_S3,
|
|
||||||
THROTTLE_SOURCE_LS,
|
|
||||||
THROTTLE_SOURCE_RS,
|
|
||||||
#else
|
|
||||||
THROTTLE_SOURCE_P1 = THROTTLE_SOURCE_FIRST_POT,
|
|
||||||
THROTTLE_SOURCE_P2,
|
|
||||||
THROTTLE_SOURCE_P3,
|
|
||||||
#endif
|
|
||||||
THROTTLE_SOURCE_CH1,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum DisplayTrims
|
enum DisplayTrims
|
||||||
{
|
{
|
||||||
DISPLAY_TRIMS_NEVER,
|
DISPLAY_TRIMS_NEVER,
|
||||||
|
|||||||
@@ -174,3 +174,22 @@ void evalTimers(int16_t throttle, uint8_t tick10ms)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t throttleSource2Source(int16_t thrSrc)
|
||||||
|
{
|
||||||
|
if (thrSrc == 0) return (int16_t)MIXSRC_Thr;
|
||||||
|
if (--thrSrc < NUM_POTS + NUM_SLIDERS)
|
||||||
|
return (int16_t)(thrSrc + MIXSRC_FIRST_POT);
|
||||||
|
return (int16_t)(thrSrc - (NUM_POTS + NUM_SLIDERS) + MIXSRC_FIRST_CH);
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t source2ThrottleSource(int16_t src)
|
||||||
|
{
|
||||||
|
if (src == MIXSRC_Thr)
|
||||||
|
return 0;
|
||||||
|
else if (src <= MIXSRC_LAST_POT)
|
||||||
|
return src - MIXSRC_FIRST_POT + 1;
|
||||||
|
else if (src <= MIXSRC_LAST_CH)
|
||||||
|
return src - MIXSRC_FIRST_CH + NUM_POTS + NUM_SLIDERS + 1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,4 +62,7 @@ static inline tmr10ms_t get_tmr10ms()
|
|||||||
return g_tmr10ms;
|
return g_tmr10ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t throttleSource2Source(int16_t thrSrc);
|
||||||
|
int16_t source2ThrottleSource(int16_t src);
|
||||||
|
|
||||||
#endif // _TIMERS_H_
|
#endif // _TIMERS_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user