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
+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;
}