mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 12:25:12 +03:00
parent
3dfb27f220
commit
fcedcb9c56
1 changed files with 186 additions and 5 deletions
|
@ -363,6 +363,136 @@ static int luaModelGetInputsCount(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*luadoc
|
||||
@function model.deleteFlightModes()
|
||||
|
||||
Clear all flightModes
|
||||
|
||||
@status current Introduced in 2.3.10
|
||||
*/
|
||||
static int luaModelDeleteFlightModes(lua_State *L)
|
||||
{
|
||||
memset(g_model.flightModeData, 0, sizeof(g_model.flightModeData));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*luadoc
|
||||
@function model.getFlightMode(index)
|
||||
|
||||
@param index (unsigned number) flight mode number (use 0 for FM0)
|
||||
|
||||
Return input data for given input and line number
|
||||
|
||||
@retval nil requested input or line does not exist
|
||||
|
||||
@retval table input data:
|
||||
* `name` (string) input line name
|
||||
* `switch` (number) input switch index
|
||||
* `fadeIn` (number) fade in value (in 0.1s)
|
||||
* `fadeOut` (number) fade out value (in 0.1s)
|
||||
* `trimsValues` (table) table of trim values:
|
||||
* `key` is trim number (zero based)
|
||||
* `value` is trim value
|
||||
* `trimsModes` (table) table of trim mode:
|
||||
* `key` is trim number (zero based)
|
||||
* `value` is trim mode
|
||||
|
||||
@status current Introduced in 2.3.10
|
||||
*/
|
||||
static int luaModelGetFlightMode(lua_State * L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
if (idx < MAX_FLIGHT_MODES) {
|
||||
FlightModeData * fm = flightModeAddress(idx);
|
||||
lua_newtable(L);
|
||||
lua_pushtablezstring(L, "name", fm->name);
|
||||
lua_pushtableinteger(L, "switch", fm->swtch);
|
||||
lua_pushtableinteger(L, "fadeIn", fm->fadeIn);
|
||||
lua_pushtableinteger(L, "fadeOut", fm->fadeOut);
|
||||
lua_pushstring(L, "trimsValues");
|
||||
lua_newtable(L);
|
||||
for (uint8_t i = 0; i < NUM_TRIMS; i++) {
|
||||
lua_pushinteger(L, i);
|
||||
lua_pushinteger(L, fm->trim[i].value);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
lua_settable(L, -3);
|
||||
lua_pushstring(L, "trimsModes");
|
||||
lua_newtable(L);
|
||||
for (uint8_t i = 0; i < NUM_TRIMS; i++) {
|
||||
lua_pushinteger(L, i);
|
||||
lua_pushinteger(L, fm->trim[i].mode);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*luadoc
|
||||
@function model.setFlightMode(index, params)
|
||||
|
||||
Set Flight mode parameters
|
||||
|
||||
@param index (unsigned number) flight mode number (use 0 for FM0)
|
||||
|
||||
@param params see model.getFlightMode return format for table format.
|
||||
|
||||
@status current Introduced in 2.3.10
|
||||
*/
|
||||
static int luaModelSetFlightMode(lua_State * L)
|
||||
{
|
||||
unsigned int flightMode = luaL_checkunsigned(L, 1);
|
||||
|
||||
if (flightMode >= MAX_FLIGHT_MODES) {
|
||||
lua_pushinteger(L, 2);
|
||||
return 1;
|
||||
}
|
||||
FlightModeData * fm = flightModeAddress(flightMode);
|
||||
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(fm->name, name, sizeof(fm->name));
|
||||
}
|
||||
else if (!strcmp(key, "switch")) {
|
||||
fm->swtch = luaL_checkinteger(L, -1);
|
||||
}
|
||||
else if (!strcmp(key, "fadeIn")) {
|
||||
fm->fadeIn = luaL_checkinteger(L, -1);
|
||||
}
|
||||
else if (!strcmp(key, "fadeOut")) {
|
||||
fm->fadeOut = luaL_checkinteger(L, -1);
|
||||
}
|
||||
else if (!strcmp(key, "trimsValues")) {
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
uint8_t idx = 0;
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1), idx++) {
|
||||
int16_t val = luaL_checkinteger(L, -1);
|
||||
if (idx < NUM_TRIMS)
|
||||
fm->trim[idx].value = (val & 0x3FF);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(key, "trimsModes")) {
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
uint8_t idx = 0;
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1), idx++) {
|
||||
uint16_t val = luaL_checkinteger(L, -1);
|
||||
if (idx < NUM_TRIMS)
|
||||
fm->trim[idx].mode = (val & 0x1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
storageDirty(EE_MODEL);
|
||||
lua_pushinteger(L, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*luadoc
|
||||
@function model.getInput(input, line)
|
||||
|
||||
|
@ -376,6 +506,7 @@ Return input data for given input and line number
|
|||
|
||||
@retval table input data:
|
||||
* `name` (string) input line name
|
||||
* `inputName` (string) input input name
|
||||
* `source` (number) input source index
|
||||
* `weight` (number) input weight
|
||||
* `offset` (number) input offset
|
||||
|
@ -383,8 +514,9 @@ Return input data for given input and line number
|
|||
* `curveType` (number) curve type (function, expo, custom curve)
|
||||
* `curveValue` (number) curve index
|
||||
* `carryTrim` (boolean) input trims applied
|
||||
* 'flightModes' (table) table of enabled flightModes {0,2,7} means that the input is enabled for FM0, FM2 and FM7
|
||||
|
||||
@status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3
|
||||
@status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, flightModes, inputName added 2.3.10
|
||||
*/
|
||||
static int luaModelGetInput(lua_State *L)
|
||||
{
|
||||
|
@ -396,6 +528,7 @@ static int luaModelGetInput(lua_State *L)
|
|||
ExpoData * expo = expoAddress(first+idx);
|
||||
lua_newtable(L);
|
||||
lua_pushtablezstring(L, "name", expo->name);
|
||||
lua_pushtablezstring(L, "inputName", g_model.inputNames[chn]);
|
||||
lua_pushtableinteger(L, "source", expo->srcRaw);
|
||||
lua_pushtableinteger(L, "weight", expo->weight);
|
||||
lua_pushtableinteger(L, "offset", expo->offset);
|
||||
|
@ -403,6 +536,16 @@ static int luaModelGetInput(lua_State *L)
|
|||
lua_pushtableinteger(L, "curveType", expo->curve.type);
|
||||
lua_pushtableinteger(L, "curveValue", expo->curve.value);
|
||||
lua_pushtableinteger(L, "carryTrim", expo->carryTrim);
|
||||
lua_pushstring(L, "flightModes");
|
||||
lua_newtable(L);
|
||||
for (int i = 0, cnt = 0; i < MAX_FLIGHT_MODES; i++) {
|
||||
if (!(expo->flightModes & (1 << i))) {
|
||||
lua_pushinteger(L, cnt++);
|
||||
lua_pushinteger(L, i);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
}
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
|
@ -421,7 +564,7 @@ Insert an Input at specified line
|
|||
|
||||
@param value (table) input data, see model.getInput()
|
||||
|
||||
@status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3
|
||||
@status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, inputName added 2.3.10
|
||||
*/
|
||||
static int luaModelInsertInput(lua_State *L)
|
||||
{
|
||||
|
@ -444,6 +587,10 @@ static int luaModelInsertInput(lua_State *L)
|
|||
const char * name = luaL_checkstring(L, -1);
|
||||
str2zchar(expo->name, name, sizeof(expo->name));
|
||||
}
|
||||
else if (!strcmp(key, "inputName")) {
|
||||
const char * name = luaL_checkstring(L, -1);
|
||||
str2zchar(g_model.inputNames[chn], name, LEN_INPUT_NAME);
|
||||
}
|
||||
else if (!strcmp(key, "source")) {
|
||||
expo->srcRaw = luaL_checkinteger(L, -1);
|
||||
}
|
||||
|
@ -465,6 +612,16 @@ static int luaModelInsertInput(lua_State *L)
|
|||
else if (!strcmp(key, "carryTrim")) {
|
||||
expo->carryTrim = lua_toboolean(L, -1);
|
||||
}
|
||||
else if (!strcmp(key, "flightModes")) {
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
int flighModes = 0x1FF;
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
||||
uint16_t val = luaL_checkinteger(L, -1);
|
||||
if (val < MAX_FLIGHT_MODES)
|
||||
flighModes &= ~(1 << val);
|
||||
}
|
||||
expo->flightModes = flighModes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -596,8 +753,9 @@ Get configuration for specified Mix
|
|||
* `delayDown` (number) delay down
|
||||
* `speedUp` (number) speed up
|
||||
* `speedDown` (number) speed down
|
||||
* 'flightModes' (table) table of enabled flightModes {0,2,7} means that the input is enabled for FM0, FM2 and FM7
|
||||
|
||||
@status current Introduced in 2.0.0, parameters below `multiplex` added in 2.0.13
|
||||
@status current Introduced in 2.0.0, parameters below `multiplex` added in 2.0.13, flightModes added 2.3.10
|
||||
*/
|
||||
static int luaModelGetMix(lua_State *L)
|
||||
{
|
||||
|
@ -623,6 +781,16 @@ static int luaModelGetMix(lua_State *L)
|
|||
lua_pushtableinteger(L, "delayDown", mix->delayDown);
|
||||
lua_pushtableinteger(L, "speedUp", mix->speedUp);
|
||||
lua_pushtableinteger(L, "speedDown", mix->speedDown);
|
||||
lua_pushstring(L, "flightModes");
|
||||
lua_newtable(L);
|
||||
for (int i = 0, cnt = 0; i < MAX_FLIGHT_MODES; i++) {
|
||||
if (!(mix->flightModes & (1 << i))) {
|
||||
lua_pushinteger(L, cnt++);
|
||||
lua_pushinteger(L, i);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
}
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
|
@ -641,7 +809,7 @@ Insert a mixer line into Channel
|
|||
|
||||
@param value (table) see model.getMix() for table format
|
||||
|
||||
@status current Introduced in 2.0.0, parameters below `multiplex` added in 2.0.13
|
||||
@status current Introduced in 2.0.0, parameters below `multiplex` added in 2.0.13, flightModes added 2.3.10
|
||||
*/
|
||||
static int luaModelInsertMix(lua_State *L)
|
||||
{
|
||||
|
@ -706,6 +874,16 @@ static int luaModelInsertMix(lua_State *L)
|
|||
else if (!strcmp(key, "speedDown")) {
|
||||
mix->speedDown = luaL_checkinteger(L, -1);
|
||||
}
|
||||
else if (!strcmp(key, "flightModes")) {
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
int flighModes = 0x1FF;
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
||||
uint16_t val = luaL_checkinteger(L, -1);
|
||||
if (val < MAX_FLIGHT_MODES)
|
||||
flighModes &= ~(1 << val);
|
||||
}
|
||||
mix->flightModes = flighModes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -997,7 +1175,7 @@ static int luaModelSetCurve(lua_State *L)
|
|||
bool isX = !strcmp(key, "x");
|
||||
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
||||
int idx = luaL_checkinteger(L, -2)-1;
|
||||
int idx = luaL_checkinteger(L, -2) - 1;
|
||||
if (idx < 0 || idx > MAX_POINTS_PER_CURVE) {
|
||||
lua_pushinteger(L, 4);
|
||||
return 1;
|
||||
|
@ -1418,6 +1596,9 @@ const luaL_Reg modelLib[] = {
|
|||
{ "getTimer", luaModelGetTimer },
|
||||
{ "setTimer", luaModelSetTimer },
|
||||
{ "resetTimer", luaModelResetTimer },
|
||||
{ "deleteFlightModes", luaModelDeleteFlightModes },
|
||||
{ "getFlightMode", luaModelGetFlightMode },
|
||||
{ "setFlightMode", luaModelSetFlightMode },
|
||||
{ "getInputsCount", luaModelGetInputsCount },
|
||||
{ "getInput", luaModelGetInput },
|
||||
{ "insertInput", luaModelInsertInput },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue