feat: More rotary encoder options for B&W screens (see #2045)

* First build

* Fix X9

* Update api_general.cpp

* Update translations.h

* clean up translations

* fix: B&W option handling, remove magic numbers, cleanup
- Remove references to invertRotary, change to RotEncDir or similar
- Add compatabilty importing to companion, firmware
- Rename Lua API call
- Move magic numbers to enum
- Improve B&W option handling so it doesn't apply changes while in menu

* chore: yaml regen

* fix: Add missing guards for X9D/X9D+

* fix: Wrong enum name in simu

* fix(cpn): Use correct names for UI elements

* fix: Translations

* fix: Allow `rotEncMode` in all yaml due to x9d var
Of the three X9D variants, the X9D+2019 is the only one that
has a rotary encoder as standard. However, as the base config
file is for the X9D, this meant it wasn't reading or writing the
config value. Rather than add a seperate config file for it for
a single variable, simple to just allow it across all targets.

* fix: Companion string, change colorlcd to `Choice`

Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
breadoven
2022-08-04 20:06:17 +10:00
committed by GitHub
co-authored by Peter Feerick
parent 5752cf4061
commit 62692dba6a
53 changed files with 435 additions and 131 deletions
+20 -4
View File
@@ -102,7 +102,7 @@ enum {
ITEM_RADIO_SETUP_USB_MODE,
CASE_JACK_DETECT(ITEM_RADIO_SETUP_JACK_MODE)
ITEM_RADIO_SETUP_RX_CHANNEL_ORD,
CASE_ROTARY_ENCODER(ITEM_RADIO_SETUP_ROTARY_INVERSE)
CASE_ROTARY_ENCODER(ITEM_RADIO_SETUP_ROTARY_ENC_MODE)
ITEM_RADIO_SETUP_STICK_MODE_LABELS,
ITEM_RADIO_SETUP_STICK_MODE,
ITEM_RADIO_SETUP_MAX
@@ -137,7 +137,7 @@ void menuRadioSetup(event_t event)
#endif
uint8_t old_editMode = s_editMode;
MENU(STR_RADIO_SETUP, menuTabGeneral, MENU_RADIO_SETUP, HEADER_LINE+ITEM_RADIO_SETUP_MAX, {
HEADER_LINE_COLUMNS CASE_RTCLOCK(2) CASE_RTCLOCK(2) CASE_BATTGRAPH(1)
LABEL(SOUND), CASE_AUDIO(0)
@@ -181,6 +181,9 @@ void menuRadioSetup(event_t event)
if (event == EVT_ENTRY) {
reusableBuffer.generalSettings.stickMode = g_eeGeneral.stickMode;
#if defined(ROTARY_ENCODER_NAVIGATION)
reusableBuffer.generalSettings.rotaryEncoderMode = g_eeGeneral.rotEncMode;
#endif
}
uint8_t sub = menuVerticalPosition - HEADER_LINE;
@@ -661,8 +664,21 @@ void menuRadioSetup(event_t event)
break;
#if defined(ROTARY_ENCODER_NAVIGATION)
case ITEM_RADIO_SETUP_ROTARY_INVERSE:
g_eeGeneral.rotEncDirection = editCheckBox(g_eeGeneral.rotEncDirection, RADIO_SETUP_2ND_COLUMN, y, STR_INVERT_ROTARY, attr, event);
case ITEM_RADIO_SETUP_ROTARY_ENC_MODE:
lcdDrawTextAlignedLeft(y, STR_ROTARY_ENC_MODE);
lcdDrawTextAtIndex(RADIO_SETUP_2ND_COLUMN, y, STR_ROTARY_ENC_OPT,
reusableBuffer.generalSettings.rotaryEncoderMode,
attr);
if (attr && s_editMode > 0) {
CHECK_INCDEC_GENVAR(event,
reusableBuffer.generalSettings.rotaryEncoderMode,
ROTARY_ENCODER_MODE_NORMAL,
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_ALT);
} else if (reusableBuffer.generalSettings.rotaryEncoderMode !=
g_eeGeneral.rotEncMode) {
g_eeGeneral.rotEncMode =
reusableBuffer.generalSettings.rotaryEncoderMode;
}
break;
#endif
+20 -4
View File
@@ -95,7 +95,7 @@ enum MenuRadioSetupItems {
ITEM_RADIO_SETUP_SWITCHES_DELAY,
ITEM_RADIO_SETUP_USB_MODE,
ITEM_RADIO_SETUP_RX_CHANNEL_ORD,
CASE_ROTARY_ENCODER(ITEM_RADIO_SETUP_ROTARY_INVERSE)
CASE_ROTARY_ENCODER(ITEM_RADIO_SETUP_ROTARY_ENC_MODE)
ITEM_RADIO_SETUP_STICK_MODE_LABELS,
ITEM_RADIO_SETUP_STICK_MODE,
ITEM_RADIO_SETUP_MAX
@@ -124,7 +124,7 @@ void menuRadioSetup(event_t event)
#endif
uint8_t old_editMode = s_editMode;
MENU(STR_RADIO_SETUP, menuTabGeneral, MENU_RADIO_SETUP, ITEM_RADIO_SETUP_MAX, {
2, // date
2, // time
@@ -183,6 +183,9 @@ void menuRadioSetup(event_t event)
if (event == EVT_ENTRY) {
reusableBuffer.generalSettings.stickMode = g_eeGeneral.stickMode;
#if defined(ROTARY_ENCODER_NAVIGATION)
reusableBuffer.generalSettings.rotaryEncoderMode = g_eeGeneral.rotEncMode;
#endif
}
int sub = menuVerticalPosition;
@@ -591,8 +594,21 @@ void menuRadioSetup(event_t event)
break;
#if defined(ROTARY_ENCODER_NAVIGATION)
case ITEM_RADIO_SETUP_ROTARY_INVERSE:
g_eeGeneral.rotEncDirection = editCheckBox(g_eeGeneral.rotEncDirection, RADIO_SETUP_2ND_COLUMN, y, STR_INVERT_ROTARY, attr, event);
case ITEM_RADIO_SETUP_ROTARY_ENC_MODE:
lcdDrawTextAlignedLeft(y, STR_ROTARY_ENC_MODE);
lcdDrawTextAtIndex(RADIO_SETUP_2ND_COLUMN, y, STR_ROTARY_ENC_OPT,
reusableBuffer.generalSettings.rotaryEncoderMode,
attr);
if (attr && s_editMode > 0) {
CHECK_INCDEC_GENVAR(event,
reusableBuffer.generalSettings.rotaryEncoderMode,
ROTARY_ENCODER_MODE_NORMAL,
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_ALT);
} else if (reusableBuffer.generalSettings.rotaryEncoderMode !=
g_eeGeneral.rotEncMode) {
g_eeGeneral.rotEncMode =
reusableBuffer.generalSettings.rotaryEncoderMode;
}
break;
#endif
+4 -2
View File
@@ -698,8 +698,10 @@ void RadioSetupPage::build(FormWindow * window)
#if defined(ROTARY_ENCODER_NAVIGATION)
line = window->newLine(&grid);
new StaticText(line, rect_t{}, STR_INVERT_ROTARY, 0, COLOR_THEME_PRIMARY1);
new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.rotEncDirection));
new StaticText(line, rect_t{}, STR_ROTARY_ENC_MODE, 0, COLOR_THEME_PRIMARY1);
new Choice(line, rect_t{}, STR_ROTARY_ENC_OPT, ROTARY_ENCODER_MODE_NORMAL,
ROTARY_ENCODER_MODE_INVERT_BOTH,
GET_SET_DEFAULT(g_eeGeneral.rotEncMode));
#endif
// RX channel order
+13 -1
View File
@@ -94,7 +94,19 @@ const char * runPopupMenu(event_t event)
drawVerticalScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_DISPLAY_LINES * (FH+1), popupMenuOffset, popupMenuItemsCount, display_count);
}
switch (event) {
event_t eventTemp = event;
#if defined(ROTARY_ENCODER_NAVIGATION) && !defined(COLORLCD)
if (g_eeGeneral.rotEncMode >= ROTARY_ENCODER_MODE_INVERT_BOTH) {
if (eventTemp == EVT_ROTARY_LEFT) {
eventTemp = EVT_ROTARY_RIGHT;
} else if (eventTemp == EVT_ROTARY_RIGHT) {
eventTemp = EVT_ROTARY_LEFT;
}
}
#endif
switch (eventTemp) {
#if defined(ROTARY_ENCODER_NAVIGATION)
CASE_EVT_ROTARY_LEFT
#endif
+24 -5
View File
@@ -345,7 +345,16 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
case EVT_KEY_FIRST(KEY_DOWN):
if (s_editMode>0) break;
do {
#if defined(ROTARY_ENCODER_NAVIGATION)
if (g_eeGeneral.rotEncMode >=
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_NORM) {
DEC(l_posVert, 0, maxrow);
} else {
INC(l_posVert, 0, maxrow);
}
#else
INC(l_posVert, 0, maxrow);
#endif
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
#if defined(ROTARY_ENCODER_NAVIGATION)
@@ -368,12 +377,13 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
if (l_posHorz > 0) {
l_posHorz--;
break;
}
else if (IS_ROTARY_LEFT(event) && s_editMode == 0) {
} else if (IS_ROTARY_LEFT(event) && s_editMode == 0) {
l_posHorz = 0xff;
}
else {
l_posHorz = maxcol;
} else {
l_posHorz =
g_eeGeneral.rotEncMode == ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_ALT
? 0
: maxcol;
break;
}
#else
@@ -388,7 +398,16 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
if (s_editMode>0) break;
do {
#if defined(ROTARY_ENCODER_NAVIGATION)
if (g_eeGeneral.rotEncMode >=
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_NORM) {
INC(l_posVert, 0, maxrow);
} else {
DEC(l_posVert, 0, maxrow);
}
#else
DEC(l_posVert, 0, maxrow);
#endif
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
#if defined(ROTARY_ENCODER_NAVIGATION)
+27 -4
View File
@@ -344,7 +344,16 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
}
do {
#if defined(ROTARY_ENCODER_NAVIGATION)
if (g_eeGeneral.rotEncMode >=
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_NORM) {
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
@@ -365,17 +374,31 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
DEC(l_posHorz, 0, maxcol);
break;
}
}
else if (l_posHorz > 0) {
} else if (l_posHorz > 0) {
l_posHorz--;
break;
}
else {
} 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) {
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
+29 -6
View File
@@ -439,7 +439,16 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
}
do {
INC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
#if defined(ROTARY_ENCODER_NAVIGATION)
if (g_eeGeneral.rotEncMode >=
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_NORM) {
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount - 1);
} else {
INC(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 down, we must be in this mode
@@ -458,17 +467,31 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
DEC(l_posHorz, 0, maxcol);
break;
}
}
else if (l_posHorz > 0) {
} else if (l_posHorz > 0) {
l_posHorz--;
break;
}
else {
} 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 {
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
#if defined(ROTARY_ENCODER_NAVIGATION)
if (g_eeGeneral.rotEncMode >=
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_NORM) {
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