Skip to content

Commit

Permalink
Move more common code.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Jul 8, 2024
1 parent 1b1bb03 commit dc03118
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 102 deletions.
74 changes: 69 additions & 5 deletions radio/src/gui/navigation/navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ INIT_STOPS(stopsSwitch, 15, SWSRC_FIRST,
CATEGORY_END(SWSRC_LAST_SWITCH), CATEGORY_END(SWSRC_FIRST_TRIM - 1),
CATEGORY_END(SWSRC_FIRST_LOGICAL_SWITCH - 1), SWSRC_LAST)

#define INC(val, min, max) if (val<max) {val++;} else {val=min;}
#define DEC(val, min, max) if (val>min) {val--;} else {val=max;}
#define INC(val, min, max) if (val<max) {val++;} else {val=min;}
#define DEC(val, min, max) if (val>min) {val--;} else {val=max;}

#define CURSOR_NOT_ALLOWED_IN_ROW(row) ((int8_t)MAXCOL(row) < 0)
#define MAXCOL_RAW(row) (horTab ? *(horTab+min(row, (vertpos_t)horTabMax)) : (const uint8_t)0)
#define MAXCOL(row) (MAXCOL_RAW(row) >= HIDDEN_ROW ? MAXCOL_RAW(row) : (const uint8_t)(MAXCOL_RAW(row) & (~NAVIGATION_LINE_BY_LINE)))

#define MAXCOL_RAW(row) (horTab ? *(horTab+min(row, (vertpos_t)horTabMax)) : (const uint8_t)0)
#define MAXCOL(row) (MAXCOL_RAW(row) >= HIDDEN_ROW ? MAXCOL_RAW(row) : (const uint8_t)(MAXCOL_RAW(row) & (~NAVIGATION_LINE_BY_LINE)))
#define CURSOR_NOT_ALLOWED_IN_ROW(row) ((int8_t)MAXCOL(row) < 0)

uint8_t chgMenu(uint8_t curr, const MenuHandler * menuTab, uint8_t menuTabSize, int direction)
{
Expand Down Expand Up @@ -169,6 +169,70 @@ inline int showPopupMenus(event_t event, int newval, int i_min, int i_max,
return newval;
}

int checkMovedInput(int newval, int i_min, int i_max, unsigned int i_flags)
{
#if defined(AUTOSWITCH)
if (i_flags & INCDEC_SWITCH) {
newval = checkIncDecMovedSwitch(newval);
}
#endif

#if defined(AUTOSOURCE)
if (i_flags & INCDEC_SOURCE) {
int8_t source = GET_MOVED_SOURCE(i_min, i_max);
if (source) {
newval = source;
}
#if defined(AUTOSWITCH)
else {
uint8_t swtch = abs(getMovedSwitch());
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
newval = switchToMix(swtch);
}
}
#endif
}
#endif
return newval;
}

int checkBoolean(event_t event, int i_min, int i_max, int newval, int val)
{
if (i_min == 0 && i_max == 1 &&
(event == EVT_KEY_BREAK(KEY_ENTER))) {
s_editMode = 0;
newval = !val;
}

return newval;
}

void finishCheckIncDec(event_t event, int i_min, int i_max,
unsigned int i_flags, int newval, int val,
const CheckIncDecStops &stops)
{
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 defined(NAVIGATION_X7) || defined(NAVIGATION_X9D)
#include "navigation_x7.cpp"
#elif defined(NAVIGATION_9X) || defined(NAVIGATION_XLITE)
Expand Down
60 changes: 10 additions & 50 deletions radio/src/gui/navigation/navigation_9x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,61 +70,19 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
}
}

#if defined(AUTOSWITCH)
if (i_flags & INCDEC_SWITCH) {
newval = checkIncDecMovedSwitch(newval);
}
#endif

#if defined(AUTOSOURCE)
if (i_flags & INCDEC_SOURCE) {
int8_t source = GET_MOVED_SOURCE(i_min, i_max);
if (source) {
newval = source;
}
#if defined(AUTOSWITCH)
else {
uint8_t swtch = abs(getMovedSwitch());
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
newval = switchToMix(swtch);
}
}
#endif
}
#endif
newval = checkMovedInput(newval, i_min, i_max, i_flags);

if (invert) {
newval = -newval;
val = -val;
}
}

if (i_min == 0 && i_max == 1 &&
(event == EVT_KEY_BREAK(KEY_ENTER))) {
s_editMode = 0;
newval = !val;
}
newval = checkBoolean(event, i_min, i_max, newval, val);

newval = showPopupMenus(event, newval, i_min, i_max, i_flags, isValueAvailable);

if (newval != val) {
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();
}
storageDirty(i_flags & (EE_GENERAL|EE_MODEL));
checkIncDec_Ret = (newval > val ? 1 : -1);
}
else {
checkIncDec_Ret = 0;
}
finishCheckIncDec(event, i_min, i_max, i_flags, newval, val, stops);

return newval;
}
Expand Down Expand Up @@ -270,7 +228,11 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
uint8_t maxLines = menuTab ? LCD_LINES-1 : LCD_LINES-2;

int linesCount = maxrow;
if (l_posVert == 0 || (l_posVert==1 && MAXCOL(vertpos_t(0)) >= HIDDEN_ROW) || (l_posVert==2 && MAXCOL(vertpos_t(0)) >= HIDDEN_ROW && MAXCOL(vertpos_t(1)) >= HIDDEN_ROW)) {

if (l_posVert == 0 ||
(l_posVert==1 && MAXCOL(vertpos_t(0)) >= HIDDEN_ROW) ||
(l_posVert==2 && MAXCOL(vertpos_t(0)) >= HIDDEN_ROW &&
MAXCOL(vertpos_t(1)) >= HIDDEN_ROW)) {
menuVerticalOffset = 0;
if (horTab) {
linesCount = 0;
Expand All @@ -280,8 +242,7 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
}
}
}
}
else if (horTab) {
} else if (horTab) {
if (maxrow > maxLines) {
while (1) {
vertpos_t firstLine = 0;
Expand Down Expand Up @@ -315,8 +276,7 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
}
}
}
}
else {
} else {
if (l_posVert>maxLines+menuVerticalOffset) {
menuVerticalOffset = l_posVert-maxLines;
}
Expand Down
50 changes: 3 additions & 47 deletions radio/src/gui/navigation/navigation_x7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,63 +87,19 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
}
}

#if defined(AUTOSWITCH)
if (i_flags & INCDEC_SWITCH) {
newval = checkIncDecMovedSwitch(newval);
}
#endif

#if defined(AUTOSOURCE)
if (i_flags & INCDEC_SOURCE) {
int source = GET_MOVED_SOURCE(i_min, i_max);
if (source) {
newval = source;
}
#if defined(AUTOSWITCH)
else {
unsigned int swtch = abs(getMovedSwitch());
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
newval = switchToMix(swtch);
}
}
#endif
}
#endif
newval = checkMovedInput(newval, i_min, i_max, i_flags);

if (invert) {
newval = -newval;
val = -val;
}
}

if (i_min == 0 && i_max == 1 &&
event == EVT_KEY_BREAK(KEY_ENTER)) {
s_editMode = 0;
newval = !val;
}
newval = checkBoolean(event, i_min, i_max, newval, val);

newval = showPopupMenus(event, newval, i_min, i_max, i_flags, isValueAvailable);

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;
}
finishCheckIncDec(event, i_min, i_max, i_flags, newval, val, stops);

return newval;
}
Expand Down

0 comments on commit dc03118

Please sign in to comment.