Merge pull request #1401 from opentx/projectkk2glider/lua_stuff
Projectkk2glider/lua stuff
This commit is contained in:
@@ -1061,12 +1061,14 @@ void eeCheck(bool immediately)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s_eeDirtyMsk & EE_GENERAL) {
|
if (s_eeDirtyMsk & EE_GENERAL) {
|
||||||
|
TRACE("eeprom write general");
|
||||||
s_eeDirtyMsk -= EE_GENERAL;
|
s_eeDirtyMsk -= EE_GENERAL;
|
||||||
theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL, (uint8_t*)&g_eeGeneral, sizeof(EEGeneral), immediately);
|
theFile.writeRlc(FILE_GENERAL, FILE_TYP_GENERAL, (uint8_t*)&g_eeGeneral, sizeof(EEGeneral), immediately);
|
||||||
if (!immediately) return;
|
if (!immediately) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_eeDirtyMsk & EE_MODEL) {
|
if (s_eeDirtyMsk & EE_MODEL) {
|
||||||
|
TRACE("eeprom write model");
|
||||||
s_eeDirtyMsk = 0;
|
s_eeDirtyMsk = 0;
|
||||||
theFile.writeRlc(FILE_MODEL(g_eeGeneral.currModel), FILE_TYP_MODEL, (uint8_t*)&g_model, sizeof(g_model), immediately);
|
theFile.writeRlc(FILE_MODEL(g_eeGeneral.currModel), FILE_TYP_MODEL, (uint8_t*)&g_model, sizeof(g_model), immediately);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -407,6 +407,34 @@ static int luaLcdDrawCombobox(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int luaModelGetInfo(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_newtable(L);
|
||||||
|
lua_pushtablezstring(L, "name", g_model.header.name);
|
||||||
|
lua_pushtablenumber(L, "id", g_model.header.modelId);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int luaModelSetInfo(lua_State *L)
|
||||||
|
{
|
||||||
|
luaL_checktype(L, -1, LUA_TTABLE);
|
||||||
|
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);
|
||||||
|
if (!strcmp(key, "name")) {
|
||||||
|
const char * name = luaL_checkstring(L, -1);
|
||||||
|
str2zchar(g_model.header.name, name, sizeof(g_model.header.name));
|
||||||
|
memcpy(modelHeaders[g_eeGeneral.currModel].name, g_model.header.name, sizeof(g_model.header.name));
|
||||||
|
}
|
||||||
|
else if (!strcmp(key, "id")) {
|
||||||
|
g_model.header.modelId = luaL_checkinteger(L, -1);
|
||||||
|
modelHeaders[g_eeGeneral.currModel].modelId = g_model.header.modelId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eeDirty(EE_MODEL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int luaModelGetTimer(lua_State *L)
|
static int luaModelGetTimer(lua_State *L)
|
||||||
{
|
{
|
||||||
int idx = luaL_checkunsigned(L, 1);
|
int idx = luaL_checkunsigned(L, 1);
|
||||||
@@ -760,6 +788,7 @@ static int luaModelSetLogicalSwitch(lua_State *L)
|
|||||||
sw->duration = luaL_checkinteger(L, -1);
|
sw->duration = luaL_checkinteger(L, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
eeDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -822,6 +851,7 @@ static int luaModelSetCustomFunction(lua_State *L)
|
|||||||
CFN_ACTIVE(cfn) = luaL_checkinteger(L, -1);
|
CFN_ACTIVE(cfn) = luaL_checkinteger(L, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
eeDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -889,6 +919,7 @@ static int luaModelSetOutput(lua_State *L)
|
|||||||
limit->curve = luaL_checkinteger(L, -1) + 1;
|
limit->curve = luaL_checkinteger(L, -1) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
eeDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -912,6 +943,7 @@ static int luaModelSetGlobalVariable(lua_State *L)
|
|||||||
int value = luaL_checkinteger(L, 3);
|
int value = luaL_checkinteger(L, 3);
|
||||||
if (phase < MAX_FLIGHT_MODES && idx < MAX_GVARS && value >= -GVAR_LIMIT && value <= GVAR_LIMIT) {
|
if (phase < MAX_FLIGHT_MODES && idx < MAX_GVARS && value >= -GVAR_LIMIT && value <= GVAR_LIMIT) {
|
||||||
g_model.flightModeData[phase].gvars[idx] = value;
|
g_model.flightModeData[phase].gvars[idx] = value;
|
||||||
|
eeDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1032,6 +1064,8 @@ int luaGetOutputs(ScriptInputsOutputs & sid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_Reg modelLib[] = {
|
static const luaL_Reg modelLib[] = {
|
||||||
|
{ "getInfo", luaModelGetInfo },
|
||||||
|
{ "setInfo", luaModelSetInfo },
|
||||||
{ "getTimer", luaModelGetTimer },
|
{ "getTimer", luaModelGetTimer },
|
||||||
{ "setTimer", luaModelSetTimer },
|
{ "setTimer", luaModelSetTimer },
|
||||||
{ "getInputsCount", luaModelGetInputsCount },
|
{ "getInputsCount", luaModelGetInputsCount },
|
||||||
@@ -1108,6 +1142,7 @@ void luaInit()
|
|||||||
lua_registerint(L, "SMLSIZE", SMLSIZE);
|
lua_registerint(L, "SMLSIZE", SMLSIZE);
|
||||||
lua_registerint(L, "INVERS", INVERS);
|
lua_registerint(L, "INVERS", INVERS);
|
||||||
lua_registerint(L, "PREC1", PREC1);
|
lua_registerint(L, "PREC1", PREC1);
|
||||||
|
lua_registerint(L, "PREC2", PREC2);
|
||||||
lua_registerint(L, "BLINK", BLINK);
|
lua_registerint(L, "BLINK", BLINK);
|
||||||
lua_registerint(L, "VALUE", 0);
|
lua_registerint(L, "VALUE", 0);
|
||||||
lua_registerint(L, "SOURCE", 1);
|
lua_registerint(L, "SOURCE", 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user