feat: add inverted sources (#4722)
Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
@@ -115,6 +115,8 @@ void onSourceLongEnterPress(const char * result)
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (result == STR_MENU_INVERT) {
|
||||
checkIncDecSelection = MIXSRC_INVERT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ extern int8_t s_editMode; // global editmode
|
||||
#define INCDEC_SOURCE 0x10
|
||||
#define INCDEC_REP10 0x40
|
||||
#define NO_DBLKEYS 0x80
|
||||
#define INCDEC_SOURCE_INVERT 0x100
|
||||
|
||||
int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
unsigned int i_flags = 0, IsValueAvailable isValueAvailable = nullptr,
|
||||
@@ -96,7 +97,7 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
vertpos_t rowcount, uint8_t flags = 0);
|
||||
|
||||
#define INCDEC_DECLARE_VARS(f) \
|
||||
uint8_t incdecFlag = (f); \
|
||||
uint16_t incdecFlag = (f); \
|
||||
IsValueAvailable isValueAvailable = nullptr
|
||||
|
||||
#define INCDEC_SET_FLAG(f) incdecFlag = (f)
|
||||
|
||||
@@ -61,6 +61,13 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
#endif
|
||||
|
||||
if (s_editMode > 0) {
|
||||
bool invert = false;
|
||||
if ((i_flags & INCDEC_SOURCE_INVERT) && (newval < 0)) {
|
||||
invert = true;
|
||||
newval = -newval;
|
||||
val = -val;
|
||||
}
|
||||
|
||||
if (event == evt_rot_inc || event == EVT_KEY_FIRST(KEY_PLUS) ||
|
||||
event == EVT_KEY_REPT(KEY_PLUS)) {
|
||||
|
||||
@@ -119,22 +126,19 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (invert) {
|
||||
newval = -newval;
|
||||
val = -val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!READ_ONLY() && i_min == 0 && i_max == 1 &&
|
||||
event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
s_editMode = 0;
|
||||
newval = !val;
|
||||
}
|
||||
|
||||
if (newval != val) {
|
||||
storageDirty(i_flags & (EE_GENERAL|EE_MODEL));
|
||||
checkIncDec_Ret = (newval > val ? 1 : -1);
|
||||
}
|
||||
else {
|
||||
checkIncDec_Ret = 0;
|
||||
}
|
||||
|
||||
if (i_flags & INCDEC_SOURCE) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
killEvents(event);
|
||||
@@ -178,10 +182,11 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i_flags & INCDEC_SOURCE_INVERT) POPUP_MENU_ADD_ITEM(STR_MENU_INVERT);
|
||||
POPUP_MENU_START(onSourceLongEnterPress);
|
||||
}
|
||||
if (checkIncDecSelection != 0) {
|
||||
newval = checkIncDecSelection;
|
||||
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
|
||||
if (checkIncDecSelection != MIXSRC_MIN && checkIncDecSelection != MIXSRC_MAX)
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
checkIncDecSelection = 0;
|
||||
@@ -212,6 +217,15 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
checkIncDecSelection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (newval != val) {
|
||||
storageDirty(i_flags & (EE_GENERAL|EE_MODEL));
|
||||
checkIncDec_Ret = (newval > val ? 1 : -1);
|
||||
}
|
||||
else {
|
||||
checkIncDec_Ret = 0;
|
||||
}
|
||||
|
||||
return newval;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,13 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
#endif
|
||||
|
||||
if (s_editMode > 0) {
|
||||
bool invert = false;
|
||||
if ((i_flags & INCDEC_SOURCE_INVERT) && (newval < 0)) {
|
||||
invert = true;
|
||||
newval = -newval;
|
||||
val = -val;
|
||||
}
|
||||
|
||||
if (event == evt_rot_inc || event == EVT_KEY_FIRST(KEY_PLUS) ||
|
||||
event == EVT_KEY_REPT(KEY_PLUS)) {
|
||||
|
||||
@@ -119,6 +126,11 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (invert) {
|
||||
newval = -newval;
|
||||
val = -val;
|
||||
}
|
||||
}
|
||||
|
||||
if (!READ_ONLY() && i_min == 0 && i_max == 1 &&
|
||||
@@ -127,27 +139,6 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
newval = !val;
|
||||
}
|
||||
|
||||
if (newval != val) {
|
||||
#if !defined(ROTARY_ENCODER_NAVIGATION)
|
||||
if (!(i_flags & NO_INCDEC_MARKS) && (newval != i_max) &&
|
||||
(newval != i_min) && stops.contains(newval)) {
|
||||
bool pause = (newval > val ? !stops.contains(newval + 1)
|
||||
: !stops.contains(newval - 1));
|
||||
if (pause) {
|
||||
pauseEvents(event); // delay before auto-repeat continues
|
||||
}
|
||||
}
|
||||
if (!IS_KEY_REPT(event)) {
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
#endif
|
||||
storageDirty(i_flags & (EE_GENERAL|EE_MODEL));
|
||||
checkIncDec_Ret = (newval > val ? 1 : -1);
|
||||
}
|
||||
else {
|
||||
checkIncDec_Ret = 0;
|
||||
}
|
||||
|
||||
if (i_flags & INCDEC_SOURCE) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
killEvents(event);
|
||||
@@ -191,10 +182,11 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i_flags & INCDEC_SOURCE_INVERT) POPUP_MENU_ADD_ITEM(STR_MENU_INVERT);
|
||||
POPUP_MENU_START(onSourceLongEnterPress);
|
||||
}
|
||||
if (checkIncDecSelection != 0) {
|
||||
newval = checkIncDecSelection;
|
||||
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
|
||||
if (checkIncDecSelection != MIXSRC_MIN && checkIncDecSelection != MIXSRC_MAX)
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
checkIncDecSelection = 0;
|
||||
@@ -225,6 +217,49 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
checkIncDecSelection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (newval != val) {
|
||||
#if !defined(ROTARY_ENCODER_NAVIGATION)
|
||||
if (!(i_flags & NO_INCDEC_MARKS) && (newval != i_max) &&
|
||||
(newval != i_min) && stops.contains(newval)) {
|
||||
bool pause = (newval > val ? !stops.contains(newval + 1)
|
||||
: !stops.contains(newval - 1));
|
||||
if (pause) {
|
||||
pauseEvents(event); // delay before auto-repeat continues
|
||||
}
|
||||
}
|
||||
if (!IS_KEY_REPT(event)) {
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
#endif
|
||||
storageDirty(i_flags & (EE_GENERAL|EE_MODEL));
|
||||
checkIncDec_Ret = (newval > val ? 1 : -1);
|
||||
}
|
||||
else {
|
||||
checkIncDec_Ret = 0;
|
||||
}
|
||||
|
||||
if (newval != val) {
|
||||
#if !defined(ROTARY_ENCODER_NAVIGATION)
|
||||
if (!(i_flags & NO_INCDEC_MARKS) && (newval != i_max) &&
|
||||
(newval != i_min) && stops.contains(newval)) {
|
||||
bool pause = (newval > val ? !stops.contains(newval + 1)
|
||||
: !stops.contains(newval - 1));
|
||||
if (pause) {
|
||||
pauseEvents(event); // delay before auto-repeat continues
|
||||
}
|
||||
}
|
||||
if (!IS_KEY_REPT(event)) {
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
#endif
|
||||
storageDirty(i_flags & (EE_GENERAL|EE_MODEL));
|
||||
checkIncDec_Ret = (newval > val ? 1 : -1);
|
||||
}
|
||||
else {
|
||||
checkIncDec_Ret = 0;
|
||||
}
|
||||
|
||||
return newval;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,13 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
int newval = val;
|
||||
|
||||
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_RIGHT) || event == EVT_KEY_REPT(KEY_RIGHT) ||
|
||||
event == EVT_KEY_FIRST(KEY_UP) || event == EVT_KEY_REPT(KEY_UP)) {
|
||||
do {
|
||||
@@ -109,6 +116,11 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (invert) {
|
||||
newval = -newval;
|
||||
val = -val;
|
||||
}
|
||||
}
|
||||
|
||||
if (!READ_ONLY() && i_min == 0 && i_max == 1 &&
|
||||
@@ -179,10 +191,11 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i_flags & INCDEC_SOURCE_INVERT) POPUP_MENU_ADD_ITEM(STR_MENU_INVERT);
|
||||
POPUP_MENU_START(onSourceLongEnterPress);
|
||||
}
|
||||
if (checkIncDecSelection != 0) {
|
||||
newval = checkIncDecSelection;
|
||||
newval = (checkIncDecSelection == MIXSRC_INVERT ? -newval : checkIncDecSelection);
|
||||
if (checkIncDecSelection != MIXSRC_MIN && checkIncDecSelection != MIXSRC_MAX)
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
checkIncDecSelection = 0;
|
||||
|
||||
Reference in New Issue
Block a user