diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index 2aacda979..5cdf45328 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -741,6 +741,29 @@ static int luaModelSetOutput(lua_State *L) return 0; } + +static int luaModelGetGlobalVariable(lua_State *L) +{ + int idx = luaL_checkunsigned(L, 1); + int phase = luaL_checkunsigned(L, 2); + if (phase < MAX_PHASES && idx < MAX_GVARS) + lua_pushinteger(L, g_model.phaseData[phase].gvars[idx]); + else + lua_pushnil(L); + return 1; +} + +static int luaModelSetGlobalVariable(lua_State *L) +{ + int idx = luaL_checkunsigned(L, 1); + int phase = luaL_checkunsigned(L, 2); + int value = luaL_checkinteger(L, 3); + if (phase < MAX_PHASES && idx < MAX_GVARS && value <= 500) { + g_model.phaseData[phase].gvars[idx] = value; + } + return 0; +} + static int luaPopupInput(lua_State *L) { uint8_t event = luaL_checkinteger(L, 2); @@ -849,6 +872,8 @@ static const luaL_Reg modelLib[] = { { "setCustomFunction", luaModelSetCustomFunction }, { "getOutput", luaModelGetOutput }, { "setOutput", luaModelSetOutput }, + { "getGlobalVariable", luaModelGetGlobalVariable }, + { "setGlobalVariable", luaModelSetGlobalVariable }, { NULL, NULL } /* sentinel */ }; diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 0d6a1bbe1..451e78f71 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -692,7 +692,7 @@ PACK(typedef struct t_MixData { PACK( union u_gvarint_t { struct { int8_t lo; - uint8_t hi; + uint8_t hi; } bytes_t; int16_t word;