fix: Use keysGetMaxTrims() instead of MAX_TRIMS (#3860)
* fix: use keysGetMaxTrims() instead of MAX_TRIMS * feat: add support for virtual trims This is necessary for radios like X-lite where half of the trims are simulated
This commit is contained in:
@@ -488,7 +488,7 @@ static int luaModelGetFlightMode(lua_State * L)
|
||||
lua_pushtableinteger(L, "fadeOut", fm->fadeOut);
|
||||
lua_pushstring(L, "trimsValues");
|
||||
lua_newtable(L);
|
||||
for (uint8_t i = 0; i < MAX_TRIMS; i++) {
|
||||
for (uint8_t i = 0; i < keysGetMaxTrims(); i++) {
|
||||
lua_pushinteger(L, i + 1);
|
||||
lua_pushinteger(L, fm->trim[i].value);
|
||||
lua_settable(L, -3);
|
||||
@@ -496,7 +496,7 @@ static int luaModelGetFlightMode(lua_State * L)
|
||||
lua_settable(L, -3);
|
||||
lua_pushstring(L, "trimsModes");
|
||||
lua_newtable(L);
|
||||
for (uint8_t i = 0; i < MAX_TRIMS; i++) {
|
||||
for (uint8_t i = 0; i < keysGetMaxTrims(); i++) {
|
||||
lua_pushinteger(L, i + 1);
|
||||
lua_pushinteger(L, fm->trim[i].mode);
|
||||
lua_settable(L, -3);
|
||||
@@ -530,6 +530,7 @@ static int luaModelSetFlightMode(lua_State * L)
|
||||
}
|
||||
FlightModeData * fm = flightModeAddress(flightMode);
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
auto max_trims = keysGetMaxTrims();
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
||||
luaL_checktype(L, -2, LUA_TSTRING); // key is string
|
||||
const char * key = luaL_checkstring(L, -2);
|
||||
@@ -550,13 +551,13 @@ static int luaModelSetFlightMode(lua_State * L)
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
||||
int idx = luaL_checkinteger(L, -2) - 1; // key is integer
|
||||
if (idx < 0 || idx >= MAX_TRIMS) continue;
|
||||
if (idx < 0 || idx >= max_trims) continue;
|
||||
int16_t val = luaL_checkinteger(L, -1);
|
||||
if (g_model.extendedTrims)
|
||||
val = limit<int16_t>(val, TRIM_EXTENDED_MIN, TRIM_EXTENDED_MAX);
|
||||
else
|
||||
val = limit<int16_t>(val, TRIM_MIN, TRIM_MAX);
|
||||
if (idx < MAX_TRIMS)
|
||||
if (idx < max_trims)
|
||||
fm->trim[idx].value = val;
|
||||
}
|
||||
}
|
||||
@@ -564,9 +565,9 @@ static int luaModelSetFlightMode(lua_State * L)
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
||||
int idx = luaL_checkinteger(L, -2) - 1; // key is integer
|
||||
if (idx < 0 || idx >= MAX_TRIMS) continue;
|
||||
if (idx < 0 || idx >= max_trims) continue;
|
||||
uint16_t val = luaL_checkinteger(L, -1);
|
||||
if (idx < MAX_TRIMS)
|
||||
if (idx < max_trims)
|
||||
fm->trim[idx].mode = (val & 0x1F);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user