feat: use any source for expo/weight/offset (#5220)

Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
Co-authored-by: 3djc <3djc@gh.com>
Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
philmoz
2024-07-26 20:51:21 +10:00
committed by GitHub
co-authored by philmoz 3djc elecpower
parent 326c58a7fd
commit 4b917b762c
87 changed files with 2751 additions and 1671 deletions
+2
View File
@@ -117,6 +117,8 @@ void onSourceLongEnterPress(const char * result)
}
} else if (result == STR_MENU_INVERT) {
checkIncDecSelection = MIXSRC_INVERT;
} else if (result == STR_CONSTANT) {
checkIncDecSelection = MIXSRC_VALUE;
}
}
+2
View File
@@ -74,6 +74,8 @@ extern int8_t s_editMode; // global editmode
#define INCDEC_REP10 0x40
#define NO_DBLKEYS 0x80
#define INCDEC_SOURCE_INVERT 0x100
#define INCDEC_SOURCE_VALUE 0x200 // Field can be source or value
#define INCDEC_SOURCE_NOINPUTS 0x400 // Do not allow Inputs in source selection
int checkIncDec(event_t event, int val, int i_min, int i_max,
unsigned int i_flags = 0, IsValueAvailable isValueAvailable = nullptr,
+110 -3
View File
@@ -51,7 +51,26 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
{
int newval = val;
bool isSource = false;
bool origIsSource = false;
if (i_flags & INCDEC_SOURCE_VALUE) {
SourceNumVal v;
v.rawValue = val;
// Save isSource flag;
origIsSource = isSource = v.isSource;
// Remove isSource flag;
val = v.value;
newval = v.value;
}
if (s_editMode > 0) {
bool invert = false;
if ((i_flags & INCDEC_SOURCE_INVERT) && (newval < 0)) {
invert = true;
newval = -newval;
val = -val;
}
if (event == EVT_KEY_FIRST(KEY_UP) || event == EVT_KEY_REPT(KEY_UP) ||
event == EVT_KEY_FIRST(KEY_RIGHT) || event == EVT_KEY_REPT(KEY_RIGHT)) {
do {
@@ -94,10 +113,17 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
#endif
#if defined(AUTOSOURCE)
if (i_flags & INCDEC_SOURCE) {
int8_t source = GET_MOVED_SOURCE(i_min, i_max);
if (i_flags & (INCDEC_SOURCE|INCDEC_SOURCE_VALUE)) {
int source = GET_MOVED_SOURCE(i_min, i_max);
if (source) {
newval = source;
if (i_flags & INCDEC_SOURCE_VALUE) {
if (isSource) {
// Only use moved source if already a source value
newval = source;
}
} else {
newval = source;
}
}
#if defined(AUTOSWITCH)
else {
@@ -109,6 +135,11 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
#endif
}
#endif
if (invert) {
newval = -newval;
val = -val;
}
}
if (i_min == 0 && i_max == 1 &&
@@ -117,6 +148,75 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
newval = !val;
}
if (i_flags & (INCDEC_SOURCE | INCDEC_SOURCE_VALUE)) {
if (event == EVT_KEY_LONG(KEY_ENTER)) {
checkIncDecSelection = MIXSRC_NONE;
if (i_flags & INCDEC_SOURCE_VALUE && isSource) {
POPUP_MENU_ADD_ITEM(STR_CONSTANT);
}
if (i_min <= MIXSRC_FIRST_INPUT && i_max >= MIXSRC_FIRST_INPUT) {
if (getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE &&
(i_flags & INCDEC_SOURCE_NOINPUTS) == 0) {
POPUP_MENU_ADD_ITEM(STR_MENU_INPUTS);
}
}
#if defined(LUA_MODEL_SCRIPTS)
if (i_min <= MIXSRC_FIRST_LUA && i_max >= MIXSRC_FIRST_LUA) {
if (getFirstAvailable(MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, isSourceAvailable) != MIXSRC_NONE) {
POPUP_MENU_ADD_ITEM(STR_MENU_LUA);
}
}
#endif
if (i_min <= MIXSRC_FIRST_STICK && i_max >= MIXSRC_FIRST_STICK) POPUP_MENU_ADD_ITEM(STR_MENU_STICKS);
if (i_min <= MIXSRC_FIRST_POT && i_max >= MIXSRC_FIRST_POT) POPUP_MENU_ADD_ITEM(STR_MENU_POTS);
if (i_min <= MIXSRC_MIN && i_max >= MIXSRC_MIN) POPUP_MENU_ADD_ITEM(STR_MENU_MIN);
if (i_min <= MIXSRC_MAX && i_max >= MIXSRC_MAX) POPUP_MENU_ADD_ITEM(STR_MENU_MAX);
#if defined(HELI)
if (modelHeliEnabled())
if (i_min <= MIXSRC_FIRST_HELI && i_max >= MIXSRC_FIRST_HELI && isValueAvailable && isValueAvailable(MIXSRC_FIRST_HELI))
POPUP_MENU_ADD_ITEM(STR_MENU_HELI);
#endif
if (i_min <= MIXSRC_FIRST_TRIM && i_max >= MIXSRC_FIRST_TRIM) POPUP_MENU_ADD_ITEM(STR_MENU_TRIMS);
if (i_min <= MIXSRC_FIRST_SWITCH && i_max >= MIXSRC_FIRST_SWITCH) POPUP_MENU_ADD_ITEM(STR_MENU_SWITCHES);
if (i_min <= MIXSRC_FIRST_TRAINER && i_max >= MIXSRC_FIRST_TRAINER) POPUP_MENU_ADD_ITEM(STR_MENU_TRAINER);
if (i_min <= MIXSRC_FIRST_CH && i_max >= MIXSRC_FIRST_CH) POPUP_MENU_ADD_ITEM(STR_MENU_CHANNELS);
if (i_min <= MIXSRC_FIRST_GVAR && i_max >= MIXSRC_FIRST_GVAR && isValueAvailable && isValueAvailable(MIXSRC_FIRST_GVAR)) {
POPUP_MENU_ADD_ITEM(STR_MENU_GVARS);
}
if (modelTelemetryEnabled() && i_min <= MIXSRC_FIRST_TELEM && i_max >= MIXSRC_FIRST_TELEM) {
for (int i = 0; i < MAX_TELEMETRY_SENSORS; i++) {
TelemetrySensor * sensor = & g_model.telemetrySensors[i];
if (sensor->isAvailable()) {
POPUP_MENU_ADD_ITEM(STR_MENU_TELEMETRY);
break;
}
}
}
if (i_flags & INCDEC_SOURCE_INVERT) POPUP_MENU_ADD_ITEM(STR_MENU_INVERT);
POPUP_MENU_START(onSourceLongEnterPress);
}
if (checkIncDecSelection != 0) {
if (i_flags & INCDEC_SOURCE_VALUE) {
if (checkIncDecSelection == MIXSRC_VALUE) {
newval = 0;
isSource = false;
} else {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
if (checkIncDecSelection != MIXSRC_INVERT)
isSource = true;
}
} else {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
}
if (checkIncDecSelection != MIXSRC_MIN && checkIncDecSelection != MIXSRC_MAX)
s_editMode = EDIT_MODIFY_FIELD;
checkIncDecSelection = 0;
}
}
if (newval != val) {
if (!(i_flags & NO_INCDEC_MARKS) && (newval != i_max) &&
(newval != i_min) && stops.contains(newval)) {
@@ -136,6 +236,13 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
checkIncDec_Ret = 0;
}
if (i_flags & INCDEC_SOURCE_VALUE) {
SourceNumVal v;
v.isSource = isSource;
v.value = newval;
newval = v.rawValue;
}
return newval;
}
+50 -7
View File
@@ -60,6 +60,18 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
}
#endif
bool isSource = false;
bool origIsSource = false;
if (i_flags & INCDEC_SOURCE_VALUE) {
SourceNumVal v;
v.rawValue = val;
// Save isSource flag;
origIsSource = isSource = v.isSource;
// Remove isSource flag;
val = v.value;
newval = v.value;
}
if (s_editMode > 0) {
bool invert = false;
if ((i_flags & INCDEC_SOURCE_INVERT) && (newval < 0)) {
@@ -111,10 +123,17 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
#endif
#if defined(AUTOSOURCE)
if (i_flags & INCDEC_SOURCE) {
if (i_flags & (INCDEC_SOURCE|INCDEC_SOURCE_VALUE)) {
int source = GET_MOVED_SOURCE(i_min, i_max);
if (source) {
newval = source;
if (i_flags & INCDEC_SOURCE_VALUE) {
if (isSource) {
// Only use moved source if already a source value
newval = source;
}
} else {
newval = source;
}
}
#if defined(AUTOSWITCH)
else {
@@ -139,18 +158,24 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
newval = !val;
}
if (i_flags & INCDEC_SOURCE) {
if (i_flags & (INCDEC_SOURCE | INCDEC_SOURCE_VALUE)) {
if (event == EVT_KEY_LONG(KEY_ENTER)) {
checkIncDecSelection = MIXSRC_NONE;
if (i_flags & INCDEC_SOURCE_VALUE && isSource) {
POPUP_MENU_ADD_ITEM(STR_CONSTANT);
}
if (i_min <= MIXSRC_FIRST_INPUT && i_max >= MIXSRC_FIRST_INPUT) {
if (getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE) {
if (getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE &&
(i_flags & INCDEC_SOURCE_NOINPUTS) == 0) {
POPUP_MENU_ADD_ITEM(STR_MENU_INPUTS);
}
}
#if defined(LUA_MODEL_SCRIPTS)
if (i_min <= MIXSRC_FIRST_LUA && i_max >= MIXSRC_FIRST_LUA) {
if (getFirstAvailable(MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, isSourceAvailable) != MIXSRC_NONE) {
if (getFirstAvailable(MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, isSourceAvailable) != MIXSRC_NONE &&
(i_flags & INCDEC_SOURCE_NOINPUTS) == 0) {
POPUP_MENU_ADD_ITEM(STR_MENU_LUA);
}
}
@@ -185,7 +210,18 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
POPUP_MENU_START(onSourceLongEnterPress);
}
if (checkIncDecSelection != 0) {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
if (i_flags & INCDEC_SOURCE_VALUE) {
if (checkIncDecSelection == MIXSRC_VALUE) {
newval = 0;
isSource = false;
} else {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
if (checkIncDecSelection != MIXSRC_INVERT)
isSource = true;
}
} else {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
}
if (checkIncDecSelection != MIXSRC_MIN && checkIncDecSelection != MIXSRC_MAX)
s_editMode = EDIT_MODIFY_FIELD;
checkIncDecSelection = 0;
@@ -216,7 +252,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
}
}
if (newval != val) {
if (newval != val || isSource != origIsSource) {
storageDirty(i_flags & (EE_GENERAL|EE_MODEL));
checkIncDec_Ret = (newval > val ? 1 : -1);
}
@@ -224,6 +260,13 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
checkIncDec_Ret = 0;
}
if (i_flags & INCDEC_SOURCE_VALUE) {
SourceNumVal v;
v.isSource = isSource;
v.value = newval;
newval = v.rawValue;
}
return newval;
}
+47 -5
View File
@@ -60,6 +60,18 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
}
#endif
bool isSource = false;
bool origIsSource = false;
if (i_flags & INCDEC_SOURCE_VALUE) {
SourceNumVal v;
v.rawValue = val;
// Save isSource flag;
origIsSource = isSource = v.isSource;
// Remove isSource flag;
val = v.value;
newval = v.value;
}
if (s_editMode > 0) {
bool invert = false;
if ((i_flags & INCDEC_SOURCE_INVERT) && (newval < 0)) {
@@ -111,10 +123,17 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
#endif
#if defined(AUTOSOURCE)
if (i_flags & INCDEC_SOURCE) {
if (i_flags & (INCDEC_SOURCE|INCDEC_SOURCE_VALUE)) {
int source = GET_MOVED_SOURCE(i_min, i_max);
if (source) {
newval = source;
if (i_flags & INCDEC_SOURCE_VALUE) {
if (isSource) {
// Only use moved source if already a source value
newval = source;
}
} else {
newval = source;
}
}
#if defined(AUTOSWITCH)
else {
@@ -139,12 +158,17 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
newval = !val;
}
if (i_flags & INCDEC_SOURCE) {
if (i_flags & (INCDEC_SOURCE | INCDEC_SOURCE_VALUE)) {
if (event == EVT_KEY_LONG(KEY_ENTER)) {
checkIncDecSelection = MIXSRC_NONE;
if (i_flags & INCDEC_SOURCE_VALUE && isSource) {
POPUP_MENU_ADD_ITEM(STR_CONSTANT);
}
if (i_min <= MIXSRC_FIRST_INPUT && i_max >= MIXSRC_FIRST_INPUT) {
if (getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE) {
if (getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE &&
(i_flags & INCDEC_SOURCE_NOINPUTS) == 0) {
POPUP_MENU_ADD_ITEM(STR_MENU_INPUTS);
}
}
@@ -185,7 +209,18 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
POPUP_MENU_START(onSourceLongEnterPress);
}
if (checkIncDecSelection != 0) {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
if (i_flags & INCDEC_SOURCE_VALUE) {
if (checkIncDecSelection == MIXSRC_VALUE) {
newval = 0;
isSource = false;
} else {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
if (checkIncDecSelection != MIXSRC_INVERT)
isSource = true;
}
} else {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
}
if (checkIncDecSelection != MIXSRC_MIN && checkIncDecSelection != MIXSRC_MAX)
s_editMode = EDIT_MODIFY_FIELD;
checkIncDecSelection = 0;
@@ -258,6 +293,13 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
checkIncDec_Ret = 0;
}
if (i_flags & INCDEC_SOURCE_VALUE) {
SourceNumVal v;
v.isSource = isSource;
v.value = newval;
newval = v.rawValue;
}
return newval;
}
+48 -6
View File
@@ -49,6 +49,18 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
{
int newval = val;
bool isSource = false;
bool origIsSource = false;
if (i_flags & INCDEC_SOURCE_VALUE) {
SourceNumVal v;
v.rawValue = val;
// Save isSource flag;
origIsSource = isSource = v.isSource;
// Remove isSource flag;
val = v.value;
newval = v.value;
}
if (s_editMode > 0) {
bool invert = false;
if ((i_flags & INCDEC_SOURCE_INVERT) && (newval < 0)) {
@@ -101,10 +113,17 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
#endif
#if defined(AUTOSOURCE)
if (i_flags & INCDEC_SOURCE) {
int8_t source = GET_MOVED_SOURCE(i_min, i_max);
if (i_flags & (INCDEC_SOURCE|INCDEC_SOURCE_VALUE)) {
int source = GET_MOVED_SOURCE(i_min, i_max);
if (source) {
newval = source;
if (i_flags & INCDEC_SOURCE_VALUE) {
if (isSource) {
// Only use moved source if already a source value
newval = source;
}
} else {
newval = source;
}
}
#if defined(AUTOSWITCH)
else {
@@ -148,12 +167,17 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
checkIncDec_Ret = 0;
}
if (i_flags & INCDEC_SOURCE) {
if (i_flags & (INCDEC_SOURCE | INCDEC_SOURCE_VALUE)) {
if (event == EVT_KEY_LONG(KEY_ENTER) && !keysGetState(KEY_SHIFT)) {
checkIncDecSelection = MIXSRC_NONE;
if (i_flags & INCDEC_SOURCE_VALUE && isSource) {
POPUP_MENU_ADD_ITEM(STR_CONSTANT);
}
if (i_min <= MIXSRC_FIRST_INPUT && i_max >= MIXSRC_FIRST_INPUT) {
if (getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE) {
if (getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE &&
(i_flags & INCDEC_SOURCE_NOINPUTS) == 0) {
POPUP_MENU_ADD_ITEM(STR_MENU_INPUTS);
}
}
@@ -194,7 +218,18 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
POPUP_MENU_START(onSourceLongEnterPress);
}
if (checkIncDecSelection != 0) {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
if (i_flags & INCDEC_SOURCE_VALUE) {
if (checkIncDecSelection == MIXSRC_VALUE) {
newval = 0;
isSource = false;
} else {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
if (checkIncDecSelection != MIXSRC_INVERT)
isSource = true;
}
} else {
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
}
if (checkIncDecSelection != MIXSRC_MIN && checkIncDecSelection != MIXSRC_MAX)
s_editMode = EDIT_MODIFY_FIELD;
checkIncDecSelection = 0;
@@ -225,6 +260,13 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
}
}
if (i_flags & INCDEC_SOURCE_VALUE) {
SourceNumVal v;
v.isSource = isSource;
v.value = newval;
newval = v.rawValue;
}
return newval;
}