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
+42 -21
View File
@@ -567,6 +567,26 @@ static int luaGetRotEncSpeed(lua_State * L)
return 1;
}
/*luadoc
@function getRotEncMode()
Return rotary encoder mode
@retval number in list: Normal = 0, Both V and H inverted = 1, V-N = 2, V-A = 3
return 0 on radio without rotary encoder
@status current Introduced in 2.8.0
*/
static int luaGetRotEncMode(lua_State * L)
{
#if defined(ROTARY_ENCODER_NAVIGATION)
lua_pushunsigned(L, g_eeGeneral.rotEncMode);
#else
lua_pushunsigned(L, 0);
#endif
return 1;
}
/*luadoc
@function sportTelemetryPop()
@@ -1020,12 +1040,12 @@ static int luaGetFieldInfo(lua_State * L)
{
bool found;
LuaField field;
if (lua_type(L, 1) == LUA_TNUMBER)
found = luaFindFieldById(luaL_checkinteger(L, 1), field, FIND_FIELD_DESC);
else
found = luaFindFieldByName(luaL_checkstring(L, 1), field, FIND_FIELD_DESC);
if (found) {
lua_newtable(L);
lua_pushtableinteger(L, "id", field.id);
@@ -1594,7 +1614,7 @@ static int luaPopupConfirmation(lua_State * L)
warningText = nullptr;
lua_pushnil(L);
}
return 1;
}
@@ -1996,7 +2016,7 @@ static int luaSerialWrite(lua_State * L)
const char* p = str;
while(wr_len--) _sendCb(_ctx, *p++);
}
return 0;
}
@@ -2055,7 +2075,7 @@ static int luaSerialRead(lua_State * L)
static int shmVar[16] = {0};
/*luadoc
@function setShmVar(id, value)
@function setShmVar(id, value)
@param id: integer between 1 and 16 identifying the shared memory variable.
@@ -2072,10 +2092,10 @@ static int luaSetShmVar(lua_State * L)
{
int id = luaL_checkinteger(L, 1);
int value = luaL_checkinteger(L, 2);
if (1 <= id && id <= 16)
shmVar[id - 1] = value;
return 0;
}
@@ -2096,7 +2116,7 @@ Gets the value of a shared memory variable that can be used for passing data bet
static int luaGetShmVar(lua_State * L)
{
int id = luaL_checkinteger(L, 1);
if (1 <= id && id <= 16)
lua_pushinteger(L, shmVar[id - 1]);
else
@@ -2107,14 +2127,14 @@ static int luaGetShmVar(lua_State * L)
#endif
/*luadoc
@function setStickySwitch(id, value)
@function setStickySwitch(id, value)
@param id: integer identifying the sticky logical switch (zero for LS1 etc.).
@param value: true/false. The new value of the sticky logical switch.
@retval bufferFull: true/false. This function sends a message from Lua to the logical switch processor
via a buffer with eight slots that are read 10 times per second. If the buffer is full, then a true value
@retval bufferFull: true/false. This function sends a message from Lua to the logical switch processor
via a buffer with eight slots that are read 10 times per second. If the buffer is full, then a true value
is returned and no messages was sent (i.e. the switch was not changed).
Sets the value of a sticky logical switch.
@@ -2165,7 +2185,7 @@ static int luaGetLogicalSwitchValue(lua_State * L)
/*luadoc
@function getSwitchIndex(positionName)
@param positionName: string naming a switch position as it is shown on radio menus where you can select a switch. Notice that many names have
@param positionName: string naming a switch position as it is shown on radio menus where you can select a switch. Notice that many names have
special characters in them like arrow up/down etc.
@retval value: integer. The switchIndex, which can be used as input for `getSwitchName(switchIndex)` and `getSwitchValue(switchIndex)`. Also corresponds
@@ -2180,12 +2200,12 @@ static int luaGetSwitchIndex(lua_State * L)
bool negate = false;
bool found = false;
swsrc_t idx;
if (name[0] == '!') {
name++;
negate = true;
}
for (idx = SWSRC_NONE; idx < SWSRC_COUNT; idx++) {
if (isSwitchAvailable(idx, ModelCustomFunctionsContext)) {
char* s = getSwitchPositionName(idx);
@@ -2195,7 +2215,7 @@ static int luaGetSwitchIndex(lua_State * L)
}
}
}
if (found) {
if (negate)
idx = -idx;
@@ -2210,7 +2230,7 @@ static int luaGetSwitchIndex(lua_State * L)
/*luadoc
@function getSwitchName(switchIndex)
@param switchIndex: integer identifying a switch as returned by `getSwitchIndex(positionName)` or fields in the table returned by
@param switchIndex: integer identifying a switch as returned by `getSwitchIndex(positionName)` or fields in the table returned by
`model.getLogicalSwitch(switch)` identifying switches.
@retval value: string naming the switch position as it is shown on radio menus where a switch can be chosen.
@@ -2233,7 +2253,7 @@ static int luaGetSwitchName(lua_State * L)
/*luadoc
@function getSwitchValue(switchIndex)
@param switchIndex: integer identifying a switch as returned by `getSwitchIndex(positionName)` or fields in the table returned by
@param switchIndex: integer identifying a switch as returned by `getSwitchIndex(positionName)` or fields in the table returned by
`model.getLogicalSwitch(switch)` identifying switches.
@retval value: true/false. The value of the switch.
@@ -2267,7 +2287,7 @@ static int luaNextSwitch(lua_State * L)
{
swsrc_t last = luaL_checkinteger(L, 1);
swsrc_t idx = luaL_checkinteger(L, 2);
while (++idx <= last) {
if (isSwitchAvailable(idx, ModelCustomFunctionsContext)) {
char* name = getSwitchPositionName(idx);
@@ -2276,7 +2296,7 @@ static int luaNextSwitch(lua_State * L)
return 2;
}
}
lua_pushnil(L);
return 1;
}
@@ -2285,7 +2305,7 @@ static int luaSwitches(lua_State * L)
{
swsrc_t first;
swsrc_t last;
if (lua_isnumber(L, 1)) {
first = luaL_checkinteger(L, 1) - 1;
if (first < SWSRC_FIRST - 1)
@@ -2385,7 +2405,7 @@ static int luaNextSource(lua_State * L)
{
mixsrc_t last = luaL_checkinteger(L, 1);
mixsrc_t idx = luaL_checkinteger(L, 2);
while (++idx <= last) {
if (isSourceAvailable(idx)) {
char srcName[maxSourceNameLength];
@@ -2433,6 +2453,7 @@ const luaL_Reg opentxLib[] = {
{ "getGeneralSettings", luaGetGeneralSettings },
{ "getGlobalTimer", luaGetGlobalTimer },
{ "getRotEncSpeed", luaGetRotEncSpeed },
{ "getRotEncMode", luaGetRotEncMode },
{ "getValue", luaGetValue },
{ "getRAS", luaGetRAS },
{ "getTxGPS", luaGetTxGPS },