chore(bw): simplify navigation code (#5269)
This commit is contained in:
@@ -20,15 +20,248 @@
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "navigation.h"
|
||||
|
||||
#if defined(NAVIGATION_X9D)
|
||||
#include "navigation_x9d.cpp"
|
||||
#elif defined(NAVIGATION_9X)
|
||||
#include "navigation_9x.cpp"
|
||||
#elif defined(NAVIGATION_XLITE)
|
||||
#include "navigation_xlite.cpp"
|
||||
#elif defined(NAVIGATION_X7)
|
||||
#include "switches.h"
|
||||
|
||||
vertpos_t menuVerticalOffset;
|
||||
vertpos_t menuVerticalPosition;
|
||||
horzpos_t menuHorizontalPosition;
|
||||
|
||||
int8_t s_editMode;
|
||||
uint8_t noHighlightCounter;
|
||||
uint8_t menuCalibrationState;
|
||||
|
||||
int8_t checkIncDec_Ret;
|
||||
|
||||
tmr10ms_t menuEntryTime;
|
||||
|
||||
extern int checkIncDecSelection;
|
||||
|
||||
INIT_STOPS(stops100, 3, -100, 0, 100)
|
||||
INIT_STOPS(stops1000, 3, -1000, 0, 1000)
|
||||
INIT_STOPS(stopsSwitch, 15, SWSRC_FIRST,
|
||||
CATEGORY_END(-SWSRC_FIRST_LOGICAL_SWITCH),
|
||||
CATEGORY_END(-SWSRC_FIRST_TRIM),
|
||||
CATEGORY_END(-SWSRC_LAST_SWITCH + 1), 0,
|
||||
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 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)
|
||||
{
|
||||
int cc = curr + direction;
|
||||
while (cc != curr) {
|
||||
if (cc < 0)
|
||||
cc = menuTabSize - 1;
|
||||
else if (cc >= menuTabSize)
|
||||
cc = 0;
|
||||
if (menuTab[cc].isEnabled())
|
||||
return cc;
|
||||
cc += direction;
|
||||
}
|
||||
return curr;
|
||||
}
|
||||
|
||||
uint8_t menuSize(const MenuHandler * menuTab, uint8_t menuTabSize)
|
||||
{
|
||||
uint8_t sz = 0;
|
||||
for (int i = 0; i < menuTabSize; i += 1) {
|
||||
if (menuTab[i].isEnabled()) {
|
||||
sz += 1;
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
uint8_t menuIdx(const MenuHandler * menuTab, uint8_t curr)
|
||||
{
|
||||
return menuSize(menuTab, curr + 1) - 1;
|
||||
}
|
||||
|
||||
inline int showPopupMenus(event_t event, int newval, int i_min, int i_max,
|
||||
unsigned int i_flags, IsValueAvailable isValueAvailable,
|
||||
bool& isSource)
|
||||
{
|
||||
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 &&
|
||||
(i_flags & INCDEC_SOURCE_NOINPUTS) == 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
else if (i_flags & INCDEC_SWITCH) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
checkIncDecSelection = SWSRC_NONE;
|
||||
if (i_min <= SWSRC_FIRST_SWITCH && i_max >= SWSRC_LAST_SWITCH) POPUP_MENU_ADD_ITEM(STR_MENU_SWITCHES);
|
||||
if (i_min <= SWSRC_FIRST_TRIM && i_max >= SWSRC_LAST_TRIM) POPUP_MENU_ADD_ITEM(STR_MENU_TRIMS);
|
||||
if (i_min <= SWSRC_FIRST_LOGICAL_SWITCH && i_max >= SWSRC_LAST_LOGICAL_SWITCH) {
|
||||
for (int i = 0; i < MAX_LOGICAL_SWITCHES; i++) {
|
||||
if (isValueAvailable && isValueAvailable(SWSRC_FIRST_LOGICAL_SWITCH+i)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_MENU_LOGICAL_SWITCHES);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isValueAvailable && isValueAvailable(SWSRC_ON)) POPUP_MENU_ADD_ITEM(STR_MENU_OTHER);
|
||||
if (isValueAvailable && isValueAvailable(-newval)) POPUP_MENU_ADD_ITEM(STR_MENU_INVERT);
|
||||
POPUP_MENU_START(onSwitchLongEnterPress);
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
}
|
||||
if (checkIncDecSelection != 0) {
|
||||
newval = (checkIncDecSelection == SWSRC_INVERT ? -newval : checkIncDecSelection);
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
checkIncDecSelection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return newval;
|
||||
}
|
||||
|
||||
int checkMovedInput(int newval, int i_min, int i_max, unsigned int i_flags, bool isSource)
|
||||
{
|
||||
#if defined(AUTOSWITCH)
|
||||
if (i_flags & INCDEC_SWITCH) {
|
||||
newval = checkIncDecMovedSwitch(newval);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(AUTOSOURCE)
|
||||
if (i_flags & (INCDEC_SOURCE|INCDEC_SOURCE_VALUE)) {
|
||||
int source = GET_MOVED_SOURCE(i_min, i_max);
|
||||
if (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 {
|
||||
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)
|
||||
#include "navigation_9x.cpp"
|
||||
#else
|
||||
static_assert("navigation not defined");
|
||||
#endif
|
||||
|
||||
@@ -19,31 +19,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "navigation.h"
|
||||
|
||||
#include "switches.h"
|
||||
|
||||
vertpos_t menuVerticalOffset;
|
||||
vertpos_t menuVerticalPosition;
|
||||
horzpos_t menuHorizontalPosition;
|
||||
|
||||
int8_t s_editMode;
|
||||
uint8_t noHighlightCounter;
|
||||
uint8_t menuCalibrationState;
|
||||
|
||||
int8_t checkIncDec_Ret;
|
||||
|
||||
INIT_STOPS(stops100, 3, -100, 0, 100)
|
||||
INIT_STOPS(stops1000, 3, -1000, 0, 1000)
|
||||
INIT_STOPS(stopsSwitch, 15, SWSRC_FIRST,
|
||||
CATEGORY_END(-SWSRC_FIRST_LOGICAL_SWITCH),
|
||||
CATEGORY_END(-SWSRC_FIRST_TRIM),
|
||||
CATEGORY_END(-SWSRC_LAST_SWITCH + 1), 0,
|
||||
CATEGORY_END(SWSRC_LAST_SWITCH), CATEGORY_END(SWSRC_FIRST_TRIM - 1),
|
||||
CATEGORY_END(SWSRC_FIRST_LOGICAL_SWITCH - 1), SWSRC_LAST)
|
||||
|
||||
extern int checkIncDecSelection;
|
||||
#define POS_HORZ_INIT(posVert) 0
|
||||
|
||||
int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
unsigned int i_flags, IsValueAvailable isValueAvailable,
|
||||
@@ -98,7 +74,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
}
|
||||
} while (isValueAvailable && !isValueAvailable(newval) &&
|
||||
newval >= i_min);
|
||||
|
||||
|
||||
if (newval < i_min) {
|
||||
newval = val;
|
||||
killEvents(event);
|
||||
@@ -106,35 +82,7 @@ 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|INCDEC_SOURCE_VALUE)) {
|
||||
int source = GET_MOVED_SOURCE(i_min, i_max);
|
||||
if (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 {
|
||||
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, isSource);
|
||||
|
||||
if (invert) {
|
||||
newval = -newval;
|
||||
@@ -142,99 +90,11 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (i_flags & (INCDEC_SOURCE | INCDEC_SOURCE_VALUE)) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
checkIncDecSelection = MIXSRC_NONE;
|
||||
newval = showPopupMenus(event, newval, i_min, i_max, i_flags, isValueAvailable, isSource);
|
||||
|
||||
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)) {
|
||||
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);
|
||||
|
||||
if (i_flags & INCDEC_SOURCE_VALUE) {
|
||||
SourceNumVal v;
|
||||
@@ -246,48 +106,36 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
return newval;
|
||||
}
|
||||
|
||||
#define SCROLL_POT1_TH 32
|
||||
|
||||
#define CURSOR_NOT_ALLOWED_IN_ROW(row) ((int8_t)MAXCOL(row) < 0)
|
||||
|
||||
#define INC(val, min, max) if (val<max) {val++;} else {val=min;}
|
||||
#define DEC(val, min, max) if (val>min) {val--;} else {val=max;}
|
||||
|
||||
tmr10ms_t menuEntryTime;
|
||||
|
||||
#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 POS_HORZ_INIT(posVert) 0
|
||||
|
||||
uint8_t chgMenu(uint8_t curr, const MenuHandler * menuTab, uint8_t menuTabSize, int direction)
|
||||
vertpos_t prevRow(vertpos_t l_posVert, vertpos_t maxrow, bool wrap,
|
||||
horzpos_t& l_posHorz, const uint8_t *horTab, uint8_t horTabMax)
|
||||
{
|
||||
int cc = curr + direction;
|
||||
while (cc != curr) {
|
||||
if (cc < 0)
|
||||
cc = menuTabSize - 1;
|
||||
else if (cc >= menuTabSize)
|
||||
cc = 0;
|
||||
if (menuTab[cc].isEnabled())
|
||||
return cc;
|
||||
cc += direction;
|
||||
}
|
||||
return curr;
|
||||
}
|
||||
|
||||
uint8_t menuSize(const MenuHandler * menuTab, uint8_t menuTabSize)
|
||||
{
|
||||
uint8_t sz = 0;
|
||||
for (int i = 0; i < menuTabSize; i += 1) {
|
||||
if (menuTab[i].isEnabled()) {
|
||||
sz += 1;
|
||||
if (s_editMode <= 0) {
|
||||
vertpos_t origPos = l_posVert;
|
||||
do {
|
||||
DEC(l_posVert, 0, maxrow - 1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
if (origPos == 0 && !wrap) {
|
||||
l_posVert = origPos;
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
l_posHorz = min<horzpos_t>(l_posHorz, MAXCOL(l_posVert));
|
||||
return l_posVert;
|
||||
}
|
||||
|
||||
uint8_t menuIdx(const MenuHandler * menuTab, uint8_t curr)
|
||||
vertpos_t nextRow(vertpos_t l_posVert, vertpos_t maxrow, bool wrap,
|
||||
horzpos_t& l_posHorz, const uint8_t *horTab, uint8_t horTabMax)
|
||||
{
|
||||
return menuSize(menuTab, curr + 1) - 1;
|
||||
if (s_editMode <= 0) {
|
||||
vertpos_t origPos = l_posVert;
|
||||
do {
|
||||
INC(l_posVert, 0, maxrow - 1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
if (l_posVert == 0 && !wrap) {
|
||||
l_posVert = origPos;
|
||||
}
|
||||
}
|
||||
l_posHorz = min<horzpos_t>(l_posHorz, MAXCOL(l_posVert));
|
||||
return l_posVert;
|
||||
}
|
||||
|
||||
void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
@@ -324,7 +172,6 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
|
||||
menuCalibrationState = 0;
|
||||
drawScreenIndex(menuIdx(menuTab, curr), menuSize(menuTab, menuTabSize), attr);
|
||||
|
||||
}
|
||||
|
||||
switch (event) {
|
||||
@@ -336,7 +183,7 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if (!menuTab || l_posVert>0) {
|
||||
if (!menuTab || l_posVert > 0) {
|
||||
s_editMode = (s_editMode <= 0);
|
||||
}
|
||||
break;
|
||||
@@ -348,12 +195,12 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
AUDIO_KEY_PRESS();
|
||||
if (s_editMode>0) {
|
||||
if (s_editMode > 0) {
|
||||
s_editMode = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (l_posVert==0 || !menuTab) {
|
||||
if (l_posVert == 0 || !menuTab) {
|
||||
popMenu(); // beeps itself
|
||||
}
|
||||
else {
|
||||
@@ -363,52 +210,48 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
break;
|
||||
|
||||
case EVT_KEY_REPT(KEY_RIGHT): //inc
|
||||
if (l_posHorz==maxcol) break;
|
||||
if (l_posHorz == maxcol) break;
|
||||
// no break
|
||||
|
||||
case EVT_KEY_FIRST(KEY_RIGHT)://inc
|
||||
if (!horTab || s_editMode>0) break;
|
||||
if (!horTab || s_editMode > 0) break;
|
||||
INC(l_posHorz, 0, maxcol);
|
||||
break;
|
||||
|
||||
case EVT_KEY_REPT(KEY_DOWN):
|
||||
if (l_posVert==maxrow) break;
|
||||
// no break
|
||||
l_posVert = nextRow(l_posVert, maxrow, false, l_posHorz, horTab, horTabMax);
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_DOWN):
|
||||
if (s_editMode>0) break;
|
||||
do {
|
||||
INC(l_posVert, 0, maxrow - 1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
l_posHorz = min<horzpos_t>(l_posHorz, MAXCOL(l_posVert));
|
||||
l_posVert = nextRow(l_posVert, maxrow, true, l_posHorz, horTab, horTabMax);
|
||||
break;
|
||||
|
||||
case EVT_KEY_REPT(KEY_LEFT): //dec
|
||||
if (l_posHorz==0) break;
|
||||
if (l_posHorz == 0) break;
|
||||
// no break
|
||||
|
||||
case EVT_KEY_FIRST(KEY_LEFT)://dec
|
||||
if (!horTab || s_editMode>0) break;
|
||||
if (!horTab || s_editMode > 0) break;
|
||||
DEC(l_posHorz, 0, maxcol);
|
||||
break;
|
||||
|
||||
case EVT_KEY_REPT(KEY_UP):
|
||||
if (l_posVert==0) break;
|
||||
// no break
|
||||
case EVT_KEY_FIRST(KEY_UP):
|
||||
if (s_editMode>0) break;
|
||||
l_posVert = prevRow(l_posVert, maxrow, false, l_posHorz, horTab, horTabMax);
|
||||
break;
|
||||
|
||||
do {
|
||||
DEC(l_posVert, 0, maxrow - 1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
l_posHorz = min((uint8_t)l_posHorz, MAXCOL(l_posVert));
|
||||
case EVT_KEY_FIRST(KEY_UP):
|
||||
l_posVert = prevRow(l_posVert, maxrow, true, l_posHorz, horTab, horTabMax);
|
||||
break;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -418,8 +261,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;
|
||||
@@ -453,8 +295,7 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (l_posVert>maxLines+menuVerticalOffset) {
|
||||
menuVerticalOffset = l_posVert-maxLines;
|
||||
}
|
||||
|
||||
@@ -19,32 +19,15 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "navigation.h"
|
||||
|
||||
#include "switches.h"
|
||||
#include "hal/rotary_encoder.h"
|
||||
|
||||
vertpos_t menuVerticalOffset;
|
||||
vertpos_t menuVerticalPosition;
|
||||
horzpos_t menuHorizontalPosition;
|
||||
#define COLATTR(row) (MAXCOL_RAW(row) == (uint8_t)-1 ? (const uint8_t)0 : (const uint8_t)(MAXCOL_RAW(row) & NAVIGATION_LINE_BY_LINE))
|
||||
#define POS_HORZ_INIT(posVert) ((COLATTR(posVert) & NAVIGATION_LINE_BY_LINE) ? -1 : 0)
|
||||
|
||||
int8_t s_editMode;
|
||||
uint8_t noHighlightCounter;
|
||||
uint8_t menuCalibrationState;
|
||||
|
||||
int8_t checkIncDec_Ret;
|
||||
|
||||
INIT_STOPS(stops100, 3, -100, 0, 100)
|
||||
INIT_STOPS(stops1000, 3, -1000, 0, 1000)
|
||||
INIT_STOPS(stopsSwitch, 15, SWSRC_FIRST,
|
||||
CATEGORY_END(-SWSRC_FIRST_LOGICAL_SWITCH),
|
||||
CATEGORY_END(-SWSRC_FIRST_TRIM),
|
||||
CATEGORY_END(-SWSRC_LAST_SWITCH + 1), 0,
|
||||
CATEGORY_END(SWSRC_LAST_SWITCH), CATEGORY_END(SWSRC_FIRST_TRIM - 1),
|
||||
CATEGORY_END(SWSRC_FIRST_LOGICAL_SWITCH - 1), SWSRC_LAST)
|
||||
|
||||
extern int checkIncDecSelection;
|
||||
#if LCD_W >= 212
|
||||
#define DEFAULT_SCROLLBAR_X (LCD_W-1)
|
||||
coord_t scrollbar_X = DEFAULT_SCROLLBAR_X;
|
||||
#endif
|
||||
|
||||
int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
unsigned int i_flags, IsValueAvailable isValueAvailable,
|
||||
@@ -116,35 +99,7 @@ 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|INCDEC_SOURCE_VALUE)) {
|
||||
int source = GET_MOVED_SOURCE(i_min, i_max);
|
||||
if (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 {
|
||||
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, isSource);
|
||||
|
||||
if (invert) {
|
||||
newval = -newval;
|
||||
@@ -152,113 +107,11 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (i_flags & (INCDEC_SOURCE | INCDEC_SOURCE_VALUE)) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
checkIncDecSelection = MIXSRC_NONE;
|
||||
newval = showPopupMenus(event, newval, i_min, i_max, i_flags, isValueAvailable, isSource);
|
||||
|
||||
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 &&
|
||||
(i_flags & INCDEC_SOURCE_NOINPUTS) == 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
else if (i_flags & INCDEC_SWITCH) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
checkIncDecSelection = SWSRC_NONE;
|
||||
if (i_min <= SWSRC_FIRST_SWITCH && i_max >= SWSRC_LAST_SWITCH) POPUP_MENU_ADD_ITEM(STR_MENU_SWITCHES);
|
||||
if (i_min <= SWSRC_FIRST_TRIM && i_max >= SWSRC_LAST_TRIM) POPUP_MENU_ADD_ITEM(STR_MENU_TRIMS);
|
||||
if (i_min <= SWSRC_FIRST_LOGICAL_SWITCH && i_max >= SWSRC_LAST_LOGICAL_SWITCH) {
|
||||
for (int i = 0; i < MAX_LOGICAL_SWITCHES; i++) {
|
||||
if (isValueAvailable && isValueAvailable(SWSRC_FIRST_LOGICAL_SWITCH+i)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_MENU_LOGICAL_SWITCHES);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isValueAvailable && isValueAvailable(SWSRC_ON)) POPUP_MENU_ADD_ITEM(STR_MENU_OTHER);
|
||||
if (isValueAvailable && isValueAvailable(-newval)) POPUP_MENU_ADD_ITEM(STR_MENU_INVERT);
|
||||
POPUP_MENU_START(onSwitchLongEnterPress);
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
}
|
||||
if (checkIncDecSelection != 0) {
|
||||
newval = (checkIncDecSelection == SWSRC_INVERT ? -newval : checkIncDecSelection);
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
checkIncDecSelection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (newval != val || isSource != origIsSource) {
|
||||
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);
|
||||
|
||||
if (i_flags & INCDEC_SOURCE_VALUE) {
|
||||
SourceNumVal v;
|
||||
@@ -270,49 +123,14 @@ int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
return newval;
|
||||
}
|
||||
|
||||
#define SCROLL_POT1_TH 32
|
||||
|
||||
#define CURSOR_NOT_ALLOWED_IN_ROW(row) ((int8_t)MAXCOL(row) < 0)
|
||||
|
||||
#define INC(val, min, max) if (val<max) {val++;} else {val=min;}
|
||||
#define DEC(val, min, max) if (val>min) {val--;} else {val=max;}
|
||||
|
||||
tmr10ms_t menuEntryTime;
|
||||
|
||||
#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 COLATTR(row) (MAXCOL_RAW(row) == (uint8_t)-1 ? (const uint8_t)0 : (const uint8_t)(MAXCOL_RAW(row) & NAVIGATION_LINE_BY_LINE))
|
||||
#define POS_HORZ_INIT(posVert) ((COLATTR(posVert) & NAVIGATION_LINE_BY_LINE) ? -1 : 0)
|
||||
|
||||
uint8_t chgMenu(uint8_t curr, const MenuHandler * menuTab, uint8_t menuTabSize, int direction)
|
||||
void onLongMenuPress(const char * result)
|
||||
{
|
||||
int cc = curr + direction;
|
||||
while (cc != curr) {
|
||||
if (cc < 0)
|
||||
cc = menuTabSize - 1;
|
||||
else if (cc >= menuTabSize)
|
||||
cc = 0;
|
||||
if (menuTab[cc].isEnabled())
|
||||
return cc;
|
||||
cc += direction;
|
||||
if (result == STR_VIEW_CHANNELS) {
|
||||
pushMenu(menuChannelsView);
|
||||
}
|
||||
return curr;
|
||||
}
|
||||
|
||||
uint8_t menuSize(const MenuHandler * menuTab, uint8_t menuTabSize)
|
||||
{
|
||||
uint8_t sz = 0;
|
||||
for (int i = 0; i < menuTabSize; i += 1) {
|
||||
if (menuTab[i].isEnabled()) {
|
||||
sz += 1;
|
||||
}
|
||||
else if (result == STR_VIEW_NOTES) {
|
||||
pushModelNotes();
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
uint8_t menuIdx(const MenuHandler * menuTab, uint8_t curr)
|
||||
{
|
||||
return menuSize(menuTab, curr + 1) - 1;
|
||||
}
|
||||
|
||||
void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
@@ -327,6 +145,20 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
if (menuTab) {
|
||||
int cc = curr;
|
||||
switch (event) {
|
||||
case EVT_KEY_LONG(KEY_MENU):
|
||||
case EVT_KEY_LONG(KEY_MODEL):
|
||||
if (menuTab == menuTabModel) {
|
||||
if (modelHasNotes()) {
|
||||
POPUP_MENU_ADD_SD_ITEM(STR_VIEW_CHANNELS);
|
||||
POPUP_MENU_ADD_ITEM(STR_VIEW_NOTES);
|
||||
POPUP_MENU_START(onLongMenuPress);
|
||||
}
|
||||
else {
|
||||
pushMenu(menuChannelsView);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_PAGEUP):
|
||||
if (s_editMode>0)
|
||||
break;
|
||||
@@ -346,7 +178,13 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
chainMenu(menuTab[cc].menuFunc);
|
||||
}
|
||||
|
||||
drawScreenIndex(menuIdx(menuTab, curr), menuSize(menuTab, menuTabSize), 0);
|
||||
if (!(flags&CHECK_FLAG_NO_SCREEN_INDEX)) {
|
||||
drawScreenIndex(menuIdx(menuTab, curr), menuSize(menuTab, menuTabSize), 0);
|
||||
}
|
||||
|
||||
#if LCD_W >= 212
|
||||
lcdDrawFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, SOLID, FILL_WHITE|GREY_DEFAULT);
|
||||
#endif
|
||||
}
|
||||
|
||||
switch (event) {
|
||||
@@ -355,12 +193,18 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
s_editMode = EDIT_MODE_INIT;
|
||||
l_posVert = MENU_FIRST_LINE_EDIT(horTab, horTabMax);
|
||||
l_posHorz = POS_HORZ_INIT(l_posVert);
|
||||
#if LCD_W >= 212
|
||||
scrollbar_X = DEFAULT_SCROLLBAR_X;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case EVT_ENTRY_UP:
|
||||
menuEntryTime = get_tmr10ms();
|
||||
s_editMode = 0;
|
||||
l_posHorz = POS_HORZ_INIT(l_posVert);
|
||||
#if LCD_W >= 212
|
||||
scrollbar_X = DEFAULT_SCROLLBAR_X;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
@@ -410,7 +254,7 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
case EVT_KEY_FIRST(KEY_MINUS):
|
||||
case EVT_KEY_REPT(KEY_MINUS):
|
||||
AUDIO_KEY_PRESS();
|
||||
if (s_editMode > 0) break; // TODO it was !=
|
||||
if (s_editMode > 0) break;
|
||||
if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
|
||||
if (l_posHorz >= 0) {
|
||||
INC(l_posHorz, 0, maxcol);
|
||||
@@ -436,7 +280,7 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
}
|
||||
#else
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
#endif
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
|
||||
@@ -449,7 +293,7 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
case EVT_KEY_FIRST(KEY_PLUS):
|
||||
case EVT_KEY_REPT(KEY_PLUS):
|
||||
AUDIO_KEY_PRESS();
|
||||
if (s_editMode > 0) break; // TODO it was !=
|
||||
if (s_editMode > 0) break;
|
||||
if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
|
||||
if (l_posHorz >= 0) {
|
||||
DEC(l_posHorz, 0, maxcol);
|
||||
@@ -478,7 +322,7 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
}
|
||||
#else
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
#endif
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
|
||||
@@ -550,6 +394,12 @@ void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
}
|
||||
}
|
||||
|
||||
#if LCD_W >= 212
|
||||
if (scrollbar_X && linesCount > NUM_BODY_LINES) {
|
||||
drawVerticalScrollbar(scrollbar_X, MENU_HEADER_HEIGHT, LCD_H-MENU_HEADER_HEIGHT, menuVerticalOffset, linesCount, NUM_BODY_LINES);
|
||||
}
|
||||
#endif
|
||||
|
||||
menuVerticalPosition = l_posVert;
|
||||
menuHorizontalPosition = l_posHorz;
|
||||
}
|
||||
|
||||
@@ -1,617 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "navigation.h"
|
||||
|
||||
#include "switches.h"
|
||||
#include "hal/rotary_encoder.h"
|
||||
|
||||
vertpos_t menuVerticalOffset;
|
||||
vertpos_t menuVerticalPosition;
|
||||
horzpos_t menuHorizontalPosition;
|
||||
|
||||
int8_t s_editMode;
|
||||
uint8_t noHighlightCounter;
|
||||
uint8_t menuCalibrationState;
|
||||
|
||||
int8_t checkIncDec_Ret;
|
||||
|
||||
INIT_STOPS(stops100, 3, -100, 0, 100)
|
||||
INIT_STOPS(stops1000, 3, -1000, 0, 1000)
|
||||
INIT_STOPS(stopsSwitch, 15, SWSRC_FIRST,
|
||||
CATEGORY_END(-SWSRC_FIRST_LOGICAL_SWITCH),
|
||||
CATEGORY_END(-SWSRC_FIRST_TRIM),
|
||||
CATEGORY_END(-SWSRC_LAST_SWITCH + 1), 0,
|
||||
CATEGORY_END(SWSRC_LAST_SWITCH), CATEGORY_END(SWSRC_FIRST_TRIM - 1),
|
||||
CATEGORY_END(SWSRC_FIRST_LOGICAL_SWITCH - 1), SWSRC_LAST)
|
||||
|
||||
extern int checkIncDecSelection;
|
||||
|
||||
int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
unsigned int i_flags, IsValueAvailable isValueAvailable,
|
||||
const CheckIncDecStops &stops)
|
||||
{
|
||||
int newval = val;
|
||||
event_t evt_rot_inc = EVT_ROTARY_RIGHT;
|
||||
event_t evt_rot_dec = EVT_ROTARY_LEFT;
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
if (g_eeGeneral.rotEncMode == ROTARY_ENCODER_MODE_VERT_NORM_HORZ_INVERT) {
|
||||
evt_rot_inc = EVT_ROTARY_LEFT;
|
||||
evt_rot_dec = EVT_ROTARY_RIGHT;
|
||||
}
|
||||
#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)) {
|
||||
invert = true;
|
||||
newval = -newval;
|
||||
val = -val;
|
||||
}
|
||||
|
||||
if (event == evt_rot_inc || event == EVT_KEY_FIRST(KEY_PLUS) ||
|
||||
event == EVT_KEY_REPT(KEY_PLUS)) {
|
||||
|
||||
if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) {
|
||||
newval += min(10, i_max - val);
|
||||
} else {
|
||||
newval += min<int>(rotaryEncoderGetAccel(), i_max - val);
|
||||
}
|
||||
|
||||
while (isValueAvailable && !isValueAvailable(newval) && newval <= i_max) {
|
||||
newval++;
|
||||
}
|
||||
|
||||
if (newval > i_max) {
|
||||
newval = val;
|
||||
AUDIO_KEY_ERROR();
|
||||
}
|
||||
} else if (event == evt_rot_dec || event == EVT_KEY_FIRST(KEY_MINUS) ||
|
||||
event == EVT_KEY_REPT(KEY_MINUS)) {
|
||||
|
||||
if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) {
|
||||
newval -= min(10, val - i_min);
|
||||
} else {
|
||||
newval -= min<int>(rotaryEncoderGetAccel(), val - i_min);
|
||||
}
|
||||
|
||||
while (isValueAvailable && !isValueAvailable(newval) && newval >= i_min) {
|
||||
newval--;
|
||||
}
|
||||
|
||||
if (newval < i_min) {
|
||||
newval = val;
|
||||
AUDIO_KEY_ERROR();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(AUTOSWITCH)
|
||||
if (i_flags & INCDEC_SWITCH) {
|
||||
newval = checkIncDecMovedSwitch(newval);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(AUTOSOURCE)
|
||||
if (i_flags & (INCDEC_SOURCE|INCDEC_SOURCE_VALUE)) {
|
||||
int source = GET_MOVED_SOURCE(i_min, i_max);
|
||||
if (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 {
|
||||
unsigned int swtch = abs(getMovedSwitch());
|
||||
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
|
||||
newval = switchToMix(swtch);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (invert) {
|
||||
newval = -newval;
|
||||
val = -val;
|
||||
}
|
||||
}
|
||||
|
||||
if (i_min == 0 && i_max == 1 &&
|
||||
event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
s_editMode = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
else if (i_flags & INCDEC_SWITCH) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
checkIncDecSelection = SWSRC_NONE;
|
||||
if (i_min <= SWSRC_FIRST_SWITCH && i_max >= SWSRC_LAST_SWITCH) POPUP_MENU_ADD_ITEM(STR_MENU_SWITCHES);
|
||||
if (i_min <= SWSRC_FIRST_TRIM && i_max >= SWSRC_LAST_TRIM) POPUP_MENU_ADD_ITEM(STR_MENU_TRIMS);
|
||||
if (i_min <= SWSRC_FIRST_LOGICAL_SWITCH && i_max >= SWSRC_LAST_LOGICAL_SWITCH) {
|
||||
for (int i = 0; i < MAX_LOGICAL_SWITCHES; i++) {
|
||||
if (isValueAvailable && isValueAvailable(SWSRC_FIRST_LOGICAL_SWITCH+i)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_MENU_LOGICAL_SWITCHES);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isValueAvailable && isValueAvailable(SWSRC_ON)) POPUP_MENU_ADD_ITEM(STR_MENU_OTHER);
|
||||
if (isValueAvailable && isValueAvailable(-newval)) POPUP_MENU_ADD_ITEM(STR_MENU_INVERT);
|
||||
POPUP_MENU_START(onSwitchLongEnterPress);
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
}
|
||||
if (checkIncDecSelection != 0) {
|
||||
newval = (checkIncDecSelection == SWSRC_INVERT ? -newval : checkIncDecSelection);
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
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;
|
||||
}
|
||||
|
||||
if (i_flags & INCDEC_SOURCE_VALUE) {
|
||||
SourceNumVal v;
|
||||
v.isSource = isSource;
|
||||
v.value = newval;
|
||||
newval = v.rawValue;
|
||||
}
|
||||
|
||||
return newval;
|
||||
}
|
||||
|
||||
#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 COLATTR(row) (MAXCOL_RAW(row) == (uint8_t)-1 ? (const uint8_t)0 : (const uint8_t)(MAXCOL_RAW(row) & NAVIGATION_LINE_BY_LINE))
|
||||
#define INC(val, min, max) if (val<max) {val++;} else if (max>min) {val=min;}
|
||||
#define DEC(val, min, max) if (val>min) {val--;} else {val=max;}
|
||||
|
||||
coord_t scrollbar_X = DEFAULT_SCROLLBAR_X;
|
||||
|
||||
void onLongMenuPress(const char * result)
|
||||
{
|
||||
if (result == STR_VIEW_CHANNELS) {
|
||||
pushMenu(menuChannelsView);
|
||||
}
|
||||
else if (result == STR_VIEW_NOTES) {
|
||||
pushModelNotes();
|
||||
}
|
||||
}
|
||||
|
||||
tmr10ms_t menuEntryTime;
|
||||
|
||||
uint8_t chgMenu(uint8_t curr, const MenuHandler * menuTab, uint8_t menuTabSize, int direction)
|
||||
{
|
||||
int cc = curr + direction;
|
||||
while (cc != curr) {
|
||||
if (cc < 0)
|
||||
cc = menuTabSize - 1;
|
||||
else if (cc >= menuTabSize)
|
||||
cc = 0;
|
||||
if (menuTab[cc].isEnabled())
|
||||
return cc;
|
||||
cc += direction;
|
||||
}
|
||||
return curr;
|
||||
}
|
||||
|
||||
uint8_t menuSize(const MenuHandler * menuTab, uint8_t menuTabSize)
|
||||
{
|
||||
uint8_t sz = 0;
|
||||
for (int i = 0; i < menuTabSize; i += 1) {
|
||||
if (menuTab[i].isEnabled()) {
|
||||
sz += 1;
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
uint8_t menuIdx(const MenuHandler * menuTab, uint8_t curr)
|
||||
{
|
||||
return menuSize(menuTab, curr + 1) - 1;
|
||||
}
|
||||
|
||||
void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
uint8_t menuTabSize, const uint8_t *horTab, uint8_t horTabMax,
|
||||
vertpos_t rowcount, uint8_t flags)
|
||||
{
|
||||
vertpos_t l_posVert = menuVerticalPosition;
|
||||
horzpos_t l_posHorz = menuHorizontalPosition;
|
||||
|
||||
uint8_t maxcol = MAXCOL(l_posVert);
|
||||
|
||||
if (menuTab) {
|
||||
int cc = curr;
|
||||
switch (event) {
|
||||
case EVT_KEY_LONG(KEY_MENU):
|
||||
if (menuTab == menuTabModel) {
|
||||
if (modelHasNotes()) {
|
||||
POPUP_MENU_ADD_SD_ITEM(STR_VIEW_CHANNELS);
|
||||
POPUP_MENU_ADD_ITEM(STR_VIEW_NOTES);
|
||||
POPUP_MENU_START(onLongMenuPress);
|
||||
}
|
||||
else {
|
||||
pushMenu(menuChannelsView);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_PAGEUP):
|
||||
if (s_editMode>0)
|
||||
break;
|
||||
|
||||
cc = chgMenu(curr, menuTab, menuTabSize, -1);
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_PAGEDN):
|
||||
if (s_editMode>0)
|
||||
break;
|
||||
|
||||
cc = chgMenu(curr, menuTab, menuTabSize, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!menuCalibrationState && cc != curr) {
|
||||
chainMenu(menuTab[cc].menuFunc);
|
||||
}
|
||||
|
||||
if (!(flags&CHECK_FLAG_NO_SCREEN_INDEX)) {
|
||||
drawScreenIndex(menuIdx(menuTab, curr), menuSize(menuTab, menuTabSize), 0);
|
||||
}
|
||||
|
||||
lcdDrawFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, SOLID, FILL_WHITE|GREY_DEFAULT);
|
||||
}
|
||||
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
menuEntryTime = get_tmr10ms();
|
||||
s_editMode = EDIT_MODE_INIT;
|
||||
l_posVert = MENU_FIRST_LINE_EDIT(horTab, horTabMax);
|
||||
l_posHorz = POS_HORZ_INIT(l_posVert);
|
||||
SET_SCROLLBAR_X(LCD_W-1);
|
||||
break;
|
||||
|
||||
case EVT_ENTRY_UP:
|
||||
menuEntryTime = get_tmr10ms();
|
||||
s_editMode = 0;
|
||||
l_posHorz = POS_HORZ_INIT(l_posVert);
|
||||
SET_SCROLLBAR_X(LCD_W-1);
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if (s_editMode > 1)
|
||||
break;
|
||||
if (menuHorizontalPosition < 0 && maxcol > 0) {
|
||||
l_posHorz = 0;
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
else {
|
||||
s_editMode = (s_editMode<=0);
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_EXIT):
|
||||
s_editMode = 0; // TODO needed? we call ENTRY_UP after which does the same
|
||||
popMenu();
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
if (s_editMode > 0) {
|
||||
s_editMode = 0;
|
||||
AUDIO_KEY_PRESS();
|
||||
break;
|
||||
}
|
||||
|
||||
if (l_posHorz >= 0 && (COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
|
||||
l_posHorz = -1;
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
else {
|
||||
uint8_t posVertInit = MENU_FIRST_LINE_EDIT(horTab, horTabMax);
|
||||
if (menuVerticalOffset != 0 || l_posVert != posVertInit) {
|
||||
menuVerticalOffset = 0;
|
||||
l_posVert = posVertInit;
|
||||
l_posHorz = POS_HORZ_INIT(l_posVert);
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
else {
|
||||
popMenu();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_RIGHT:
|
||||
case EVT_KEY_FIRST(KEY_MINUS):
|
||||
case EVT_KEY_REPT(KEY_MINUS):
|
||||
AUDIO_KEY_PRESS();
|
||||
if (s_editMode != 0) break;
|
||||
if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
|
||||
if (l_posHorz >= 0) {
|
||||
INC(l_posHorz, 0, maxcol);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (l_posHorz < maxcol) {
|
||||
l_posHorz++;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
l_posHorz = 0;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
if (g_eeGeneral.rotEncMode == ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_NORM || \
|
||||
g_eeGeneral.rotEncMode == ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_ALT) {
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
} else {
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
}
|
||||
#else
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
#endif
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
|
||||
s_editMode = 0; // if we go down, we must be in this mode
|
||||
|
||||
l_posHorz = POS_HORZ_INIT(l_posVert);
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_LEFT:
|
||||
case EVT_KEY_FIRST(KEY_PLUS):
|
||||
case EVT_KEY_REPT(KEY_PLUS):
|
||||
AUDIO_KEY_PRESS();
|
||||
if (s_editMode != 0) break;
|
||||
if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
|
||||
if (l_posHorz >= 0) {
|
||||
DEC(l_posHorz, 0, maxcol);
|
||||
break;
|
||||
}
|
||||
} else if (l_posHorz > 0) {
|
||||
l_posHorz--;
|
||||
break;
|
||||
} else {
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
l_posHorz =
|
||||
g_eeGeneral.rotEncMode == ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_ALT
|
||||
? 0
|
||||
: 0xff;
|
||||
#else
|
||||
l_posHorz = 0xff;
|
||||
#endif
|
||||
}
|
||||
|
||||
do {
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
if (g_eeGeneral.rotEncMode == ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_NORM || \
|
||||
g_eeGeneral.rotEncMode == ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_ALT) {
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
} else {
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
}
|
||||
#else
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
|
||||
#endif
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
|
||||
s_editMode = 0; // if we go up, we must be in this mode
|
||||
|
||||
if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE))
|
||||
l_posHorz = -1;
|
||||
else
|
||||
l_posHorz = min((uint8_t)l_posHorz, MAXCOL(l_posVert));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
int linesCount = rowcount;
|
||||
|
||||
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;
|
||||
for (int i=0; i<rowcount; i++) {
|
||||
if (i>horTabMax || horTab[i] != HIDDEN_ROW) {
|
||||
linesCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (horTab) {
|
||||
if (rowcount > NUM_BODY_LINES) {
|
||||
while (1) {
|
||||
vertpos_t firstLine = 0;
|
||||
for (int numLines=0; firstLine<rowcount && numLines<menuVerticalOffset; firstLine++) {
|
||||
if (firstLine>=horTabMax || horTab[firstLine] != HIDDEN_ROW) {
|
||||
numLines++;
|
||||
}
|
||||
}
|
||||
if (l_posVert < firstLine) {
|
||||
menuVerticalOffset--;
|
||||
}
|
||||
else {
|
||||
vertpos_t lastLine = firstLine;
|
||||
for (int numLines=0; lastLine<rowcount && numLines<NUM_BODY_LINES; lastLine++) {
|
||||
if (lastLine>=horTabMax || horTab[lastLine] != HIDDEN_ROW) {
|
||||
numLines++;
|
||||
}
|
||||
}
|
||||
if (l_posVert >= lastLine) {
|
||||
menuVerticalOffset++;
|
||||
}
|
||||
else {
|
||||
linesCount = menuVerticalOffset + NUM_BODY_LINES;
|
||||
for (int i=lastLine; i<rowcount; i++) {
|
||||
if (i>horTabMax || horTab[i] != HIDDEN_ROW) {
|
||||
linesCount++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (l_posVert>=NUM_BODY_LINES+menuVerticalOffset) {
|
||||
menuVerticalOffset = l_posVert-NUM_BODY_LINES+1;
|
||||
}
|
||||
else if (l_posVert<menuVerticalOffset) {
|
||||
menuVerticalOffset = l_posVert;
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollbar_X && linesCount > NUM_BODY_LINES) {
|
||||
drawVerticalScrollbar(scrollbar_X, MENU_HEADER_HEIGHT, LCD_H-MENU_HEADER_HEIGHT, menuVerticalOffset, linesCount, NUM_BODY_LINES);
|
||||
}
|
||||
|
||||
menuVerticalPosition = l_posVert;
|
||||
menuHorizontalPosition = l_posHorz;
|
||||
}
|
||||
@@ -1,497 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "switches.h"
|
||||
|
||||
vertpos_t menuVerticalOffset;
|
||||
vertpos_t menuVerticalPosition;
|
||||
horzpos_t menuHorizontalPosition;
|
||||
|
||||
int8_t s_editMode;
|
||||
uint8_t noHighlightCounter;
|
||||
uint8_t menuCalibrationState;
|
||||
|
||||
int8_t checkIncDec_Ret;
|
||||
|
||||
INIT_STOPS(stops100, 3, -100, 0, 100)
|
||||
INIT_STOPS(stops1000, 3, -1000, 0, 1000)
|
||||
INIT_STOPS(stopsSwitch, 15, SWSRC_FIRST,
|
||||
CATEGORY_END(-SWSRC_FIRST_LOGICAL_SWITCH),
|
||||
CATEGORY_END(-SWSRC_FIRST_TRIM),
|
||||
CATEGORY_END(-SWSRC_LAST_SWITCH + 1), 0,
|
||||
CATEGORY_END(SWSRC_LAST_SWITCH), CATEGORY_END(SWSRC_FIRST_TRIM - 1),
|
||||
CATEGORY_END(SWSRC_FIRST_LOGICAL_SWITCH - 1), SWSRC_LAST)
|
||||
|
||||
extern int checkIncDecSelection;
|
||||
|
||||
int checkIncDec(event_t event, int val, int i_min, int i_max,
|
||||
unsigned int i_flags, IsValueAvailable isValueAvailable,
|
||||
const CheckIncDecStops &stops)
|
||||
{
|
||||
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_RIGHT) || event == EVT_KEY_REPT(KEY_RIGHT) ||
|
||||
event == EVT_KEY_FIRST(KEY_UP) || event == EVT_KEY_REPT(KEY_UP)) {
|
||||
do {
|
||||
if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) {
|
||||
newval += min(10, i_max-val);
|
||||
}
|
||||
else {
|
||||
newval++;
|
||||
}
|
||||
} while (isValueAvailable && !isValueAvailable(newval) &&
|
||||
newval <= i_max);
|
||||
|
||||
if (newval > i_max) {
|
||||
newval = val;
|
||||
killEvents(event);
|
||||
AUDIO_KEY_ERROR();
|
||||
}
|
||||
} else if (event == EVT_KEY_FIRST(KEY_LEFT) ||
|
||||
event == EVT_KEY_REPT(KEY_LEFT) ||
|
||||
event == EVT_KEY_FIRST(KEY_DOWN) ||
|
||||
event == EVT_KEY_REPT(KEY_DOWN)) {
|
||||
do {
|
||||
if (IS_KEY_REPT(event) && (i_flags & INCDEC_REP10)) {
|
||||
newval -= min(10, val-i_min);
|
||||
}
|
||||
else {
|
||||
newval--;
|
||||
}
|
||||
} while (isValueAvailable && !isValueAvailable(newval) && newval>=i_min);
|
||||
|
||||
if (newval < i_min) {
|
||||
newval = val;
|
||||
killEvents(event);
|
||||
AUDIO_KEY_ERROR();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(AUTOSWITCH)
|
||||
if (i_flags & INCDEC_SWITCH) {
|
||||
newval = checkIncDecMovedSwitch(newval);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(AUTOSOURCE)
|
||||
if (i_flags & (INCDEC_SOURCE|INCDEC_SOURCE_VALUE)) {
|
||||
int source = GET_MOVED_SOURCE(i_min, i_max);
|
||||
if (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 {
|
||||
uint8_t swtch = abs(getMovedSwitch());
|
||||
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
|
||||
newval = switchToMix(swtch);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (invert) {
|
||||
newval = -newval;
|
||||
val = -val;
|
||||
}
|
||||
}
|
||||
|
||||
if (i_min == 0 && i_max == 1 &&
|
||||
event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
s_editMode = 0;
|
||||
newval = !val;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 &&
|
||||
(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;
|
||||
}
|
||||
}
|
||||
else if (i_flags & INCDEC_SWITCH) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER) && !keysGetState(KEY_SHIFT)) {
|
||||
checkIncDecSelection = SWSRC_NONE;
|
||||
if (i_min <= SWSRC_FIRST_SWITCH && i_max >= SWSRC_LAST_SWITCH) POPUP_MENU_ADD_ITEM(STR_MENU_SWITCHES);
|
||||
if (i_min <= SWSRC_FIRST_TRIM && i_max >= SWSRC_LAST_TRIM) POPUP_MENU_ADD_ITEM(STR_MENU_TRIMS);
|
||||
if (i_min <= SWSRC_FIRST_LOGICAL_SWITCH && i_max >= SWSRC_LAST_LOGICAL_SWITCH) {
|
||||
for (int i = 0; i < MAX_LOGICAL_SWITCHES; i++) {
|
||||
if (isValueAvailable && isValueAvailable(SWSRC_FIRST_LOGICAL_SWITCH+i)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_MENU_LOGICAL_SWITCHES);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isValueAvailable && isValueAvailable(SWSRC_ON)) POPUP_MENU_ADD_ITEM(STR_MENU_OTHER);
|
||||
if (isValueAvailable && isValueAvailable(-newval)) POPUP_MENU_ADD_ITEM(STR_MENU_INVERT);
|
||||
POPUP_MENU_START(onSwitchLongEnterPress);
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
}
|
||||
if (checkIncDecSelection != 0) {
|
||||
newval = (checkIncDecSelection == SWSRC_INVERT ? -newval : checkIncDecSelection);
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
checkIncDecSelection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i_flags & INCDEC_SOURCE_VALUE) {
|
||||
SourceNumVal v;
|
||||
v.isSource = isSource;
|
||||
v.value = newval;
|
||||
newval = v.rawValue;
|
||||
}
|
||||
|
||||
return newval;
|
||||
}
|
||||
|
||||
#define SCROLL_POT1_TH 32
|
||||
|
||||
#define CURSOR_NOT_ALLOWED_IN_ROW(row) ((int8_t)MAXCOL(row) < 0)
|
||||
|
||||
#define INC(val, min, max) if (val<max) {val++;} else {val=min;}
|
||||
#define DEC(val, min, max) if (val>min) {val--;} else {val=max;}
|
||||
|
||||
tmr10ms_t menuEntryTime;
|
||||
|
||||
#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 POS_HORZ_INIT(posVert) 0
|
||||
|
||||
uint8_t chgMenu(uint8_t curr, const MenuHandler * menuTab, uint8_t menuTabSize, int direction)
|
||||
{
|
||||
int cc = curr + direction;
|
||||
while (cc != curr) {
|
||||
if (cc < 0)
|
||||
cc = menuTabSize - 1;
|
||||
else if (cc >= menuTabSize)
|
||||
cc = 0;
|
||||
if (menuTab[cc].isEnabled())
|
||||
return cc;
|
||||
cc += direction;
|
||||
}
|
||||
return curr;
|
||||
}
|
||||
|
||||
uint8_t menuSize(const MenuHandler * menuTab, uint8_t menuTabSize)
|
||||
{
|
||||
uint8_t sz = 0;
|
||||
for (int i = 0; i < menuTabSize; i += 1) {
|
||||
if (menuTab[i].isEnabled()) {
|
||||
sz += 1;
|
||||
}
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
uint8_t menuIdx(const MenuHandler * menuTab, uint8_t curr)
|
||||
{
|
||||
return menuSize(menuTab, curr + 1) - 1;
|
||||
}
|
||||
|
||||
void check(event_t event, uint8_t curr, const MenuHandler *menuTab,
|
||||
uint8_t menuTabSize, const uint8_t *horTab, uint8_t horTabMax,
|
||||
vertpos_t maxrow, uint8_t flags)
|
||||
{
|
||||
vertpos_t l_posVert = menuVerticalPosition;
|
||||
horzpos_t l_posHorz = menuHorizontalPosition;
|
||||
|
||||
uint8_t maxcol = MAXCOL(l_posVert);
|
||||
|
||||
if (menuTab) {
|
||||
uint8_t attr = 0;
|
||||
|
||||
if (l_posVert==0 && !menuCalibrationState) {
|
||||
attr = INVERS;
|
||||
|
||||
int8_t cc = curr;
|
||||
|
||||
switch (event) {
|
||||
case EVT_KEY_FIRST(KEY_LEFT):
|
||||
cc = chgMenu(curr, menuTab, menuTabSize, -1);
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_RIGHT):
|
||||
cc = chgMenu(curr, menuTab, menuTabSize, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (cc != curr) {
|
||||
chainMenu(menuTab[cc].menuFunc);
|
||||
}
|
||||
}
|
||||
|
||||
menuCalibrationState = 0;
|
||||
drawScreenIndex(menuIdx(menuTab, curr), menuSize(menuTab, menuTabSize), attr);
|
||||
}
|
||||
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
menuEntryTime = get_tmr10ms();
|
||||
l_posVert = 0;
|
||||
l_posHorz = POS_HORZ_INIT(l_posVert);
|
||||
s_editMode = EDIT_MODE_INIT;
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_ENTER):
|
||||
if (!menuTab || l_posVert > 0) {
|
||||
s_editMode = (s_editMode <= 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_EXIT):
|
||||
s_editMode = 0; // TODO needed? we call ENTRY_UP after which does the same
|
||||
popMenu();
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
AUDIO_KEY_PRESS();
|
||||
if (s_editMode > 0) {
|
||||
s_editMode = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (l_posVert == 0 || !menuTab) {
|
||||
popMenu(); // beeps itself
|
||||
}
|
||||
else {
|
||||
l_posVert = 0;
|
||||
l_posHorz = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_REPT(KEY_RIGHT): //inc
|
||||
if (l_posHorz == maxcol) break;
|
||||
// no break
|
||||
|
||||
case EVT_KEY_FIRST(KEY_RIGHT)://inc
|
||||
if (!horTab || s_editMode > 0) break;
|
||||
INC(l_posHorz, 0, maxcol);
|
||||
break;
|
||||
|
||||
case EVT_KEY_REPT(KEY_DOWN):
|
||||
if (l_posVert == maxrow) break;
|
||||
// no break
|
||||
|
||||
case EVT_KEY_FIRST(KEY_DOWN):
|
||||
if (s_editMode > 0) break;
|
||||
do {
|
||||
INC(l_posVert, 0, maxrow);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
l_posHorz = min<horzpos_t>(l_posHorz, MAXCOL(l_posVert));
|
||||
break;
|
||||
|
||||
case EVT_KEY_REPT(KEY_LEFT): //dec
|
||||
if (l_posHorz==0) break;
|
||||
// no break
|
||||
|
||||
case EVT_KEY_FIRST(KEY_LEFT)://dec
|
||||
if (!horTab || s_editMode > 0) break;
|
||||
DEC(l_posHorz, 0, maxcol);
|
||||
break;
|
||||
|
||||
case EVT_KEY_REPT(KEY_UP):
|
||||
if (l_posVert == 0) break;
|
||||
// no break
|
||||
case EVT_KEY_FIRST(KEY_UP):
|
||||
if (s_editMode > 0) break;
|
||||
do {
|
||||
DEC(l_posVert, 0, maxrow);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
l_posHorz = min((uint8_t)l_posHorz, MAXCOL(l_posVert));
|
||||
break;
|
||||
}
|
||||
|
||||
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)) {
|
||||
menuVerticalOffset = 0;
|
||||
if (horTab) {
|
||||
linesCount = 0;
|
||||
for (int i=0; i<maxrow; i++) {
|
||||
if (i>=horTabMax || horTab[i] != HIDDEN_ROW) {
|
||||
linesCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (horTab) {
|
||||
if (maxrow > maxLines) {
|
||||
while (1) {
|
||||
vertpos_t firstLine = 0;
|
||||
for (int numLines=0; firstLine<maxrow && numLines<menuVerticalOffset; firstLine++) {
|
||||
if (firstLine>=horTabMax || horTab[firstLine+1] != HIDDEN_ROW) {
|
||||
numLines++;
|
||||
}
|
||||
}
|
||||
if (l_posVert <= firstLine) {
|
||||
menuVerticalOffset--;
|
||||
}
|
||||
else {
|
||||
vertpos_t lastLine = firstLine;
|
||||
for (int numLines=0; lastLine<maxrow && numLines<maxLines; lastLine++) {
|
||||
if (lastLine>=horTabMax || horTab[lastLine+1] != HIDDEN_ROW) {
|
||||
numLines++;
|
||||
}
|
||||
}
|
||||
if (l_posVert > lastLine) {
|
||||
menuVerticalOffset++;
|
||||
}
|
||||
else {
|
||||
linesCount = menuVerticalOffset + maxLines;
|
||||
for (int i=lastLine; i<maxrow; i++) {
|
||||
if (i>=horTabMax || horTab[i] != HIDDEN_ROW) {
|
||||
linesCount++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (l_posVert>maxLines+menuVerticalOffset) {
|
||||
menuVerticalOffset = l_posVert-maxLines;
|
||||
}
|
||||
else if (l_posVert<=menuVerticalOffset) {
|
||||
menuVerticalOffset = l_posVert-1;
|
||||
}
|
||||
}
|
||||
|
||||
menuVerticalPosition = l_posVert;
|
||||
menuHorizontalPosition = l_posHorz;
|
||||
// cosmetics on 9x
|
||||
if (menuVerticalOffset > 0) {
|
||||
l_posVert--;
|
||||
if (l_posVert == menuVerticalOffset && CURSOR_NOT_ALLOWED_IN_ROW(l_posVert)) {
|
||||
menuVerticalOffset = l_posVert-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user