feat(lua): add state & persistent properties to the logical switch API (#6327)

Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
Co-authored-by: Peter Feerick <pfeerick@users.noreply.github.com>
This commit is contained in:
philmoz
2025-05-30 12:53:15 +10:00
committed by GitHub
co-authored by philmoz Peter Feerick
parent aa6938eed7
commit 1611c1ff52
+13 -3
View File
@@ -1037,8 +1037,10 @@ Get Logical Switch parameters
* `and` (number) AND switch index
* `delay` (number) delay (time in 1/10 s)
* `duration` (number) duration (time in 1/10 s)
* `state` (boolean) current state of the logical switch
* `persistent` (boolean) if true then the state is persistent across reboot of the radio
@status current Introduced in 2.0.0
@status current Introduced in 2.0.0, state and persistent added in 2.11.2
*/
static int luaModelGetLogicalSwitch(lua_State *L)
{
@@ -1052,7 +1054,9 @@ static int luaModelGetLogicalSwitch(lua_State *L)
lua_pushtableinteger(L, "v3", sw->v3);
lua_pushtableinteger(L, "and", sw->andsw);
lua_pushtableinteger(L, "delay", sw->delay);
lua_pushtableinteger(L, "duration", sw->duration);
lua_pushtableinteger(L, "duration", sw->duration);
lua_pushtableboolean(L, "state", sw->lsState);
lua_pushtableboolean(L, "persistent", sw->lsPersist);
}
else {
lua_pushnil(L);
@@ -1075,7 +1079,7 @@ that parameter remains unchanged.
@notice To set the `and` member (which is Lua keyword)
use the following syntax: `model.setLogicalSwitch(30, {func=4,v1=1,v2=-99, ["and"]=24})`
@status current Introduced in 2.0.0
@status current Introduced in 2.0.0, state and persistent added in 2.11.2
*/
static int luaModelSetLogicalSwitch(lua_State *L)
{
@@ -1108,6 +1112,12 @@ static int luaModelSetLogicalSwitch(lua_State *L)
else if (!strcmp(key, "duration")) {
sw->duration = luaL_checkinteger(L, -1);
}
else if (!strcmp(key, "state")) {
sw->lsState = lua_toboolean(L, -1);
}
else if (!strcmp(key, "persistent")) {
sw->lsPersist = lua_toboolean(L, -1);
}
}
storageDirty(EE_MODEL);
}