Merge with latest 2.3
This commit is contained in:
@@ -375,6 +375,26 @@ bool luaFindFieldByName(const char * name, LuaField & field, unsigned int flags)
|
||||
return false; // not found
|
||||
}
|
||||
|
||||
/*luadoc
|
||||
@function getRotEncSpeed()
|
||||
|
||||
Return rotary encoder current speed
|
||||
|
||||
@retval number in list: ROTENC_LOWSPEED, ROTENC_MIDSPEED, ROTENC_HIGHSPEED
|
||||
return 0 on radio without rotary encoder
|
||||
|
||||
@status current Introduced in 2.3.10
|
||||
*/
|
||||
static int luaGetRotEncSpeed(lua_State * L)
|
||||
{
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
lua_pushunsigned(L, rotencSpeed);
|
||||
#else
|
||||
lua_pushunsigned(L, 0);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*luadoc
|
||||
@function sportTelemetryPop()
|
||||
|
||||
@@ -847,7 +867,7 @@ Return the internal GPS position or nil if no valid hardware found
|
||||
static int luaGetTxGPS(lua_State * L)
|
||||
{
|
||||
#if defined(INTERNAL_GPS)
|
||||
lua_createtable(L, 0, 7);
|
||||
lua_createtable(L, 0, 8);
|
||||
lua_pushtablenumber(L, "lat", gpsData.latitude * 0.000001);
|
||||
lua_pushtablenumber(L, "lon", gpsData.longitude * 0.000001);
|
||||
lua_pushtableinteger(L, "numsat", gpsData.numSat);
|
||||
@@ -1680,6 +1700,7 @@ const luaL_Reg opentxLib[] = {
|
||||
{ "getVersion", luaGetVersion },
|
||||
{ "getGeneralSettings", luaGetGeneralSettings },
|
||||
{ "getGlobalTimer", luaGetGlobalTimer },
|
||||
{ "getRotEncSpeed", luaGetRotEncSpeed },
|
||||
{ "getValue", luaGetValue },
|
||||
{ "getRAS", luaGetRAS },
|
||||
{ "getTxGPS", luaGetTxGPS },
|
||||
@@ -1742,6 +1763,7 @@ const luaR_value_entry opentxConstants[] = {
|
||||
{ "VALUE", INPUT_TYPE_VALUE },
|
||||
{ "SOURCE", INPUT_TYPE_SOURCE },
|
||||
{ "REPLACE", MLTPX_REP },
|
||||
{ "MIXSRC_MAX", MIXSRC_MAX },
|
||||
{ "MIXSRC_FIRST_INPUT", MIXSRC_FIRST_INPUT },
|
||||
{ "MIXSRC_Rud", MIXSRC_Rud },
|
||||
{ "MIXSRC_Ele", MIXSRC_Ele },
|
||||
@@ -1813,6 +1835,9 @@ const luaR_value_entry opentxConstants[] = {
|
||||
{ "EVT_VIRTUAL_NEXT", EVT_ROTARY_RIGHT },
|
||||
{ "EVT_VIRTUAL_DEC", EVT_ROTARY_LEFT },
|
||||
{ "EVT_VIRTUAL_INC", EVT_ROTARY_RIGHT },
|
||||
{ "ROTENC_LOWSPEED", ROTENC_LOWSPEED },
|
||||
{ "ROTENC_MIDSPEED", ROTENC_MIDSPEED },
|
||||
{ "ROTENC_HIGHSPEED", ROTENC_HIGHSPEED },
|
||||
#elif defined(PCBX9D) || defined(PCBX9DP) // key reverted between field nav and value change
|
||||
{ "EVT_VIRTUAL_PREV", EVT_KEY_FIRST(KEY_PLUS) },
|
||||
{ "EVT_VIRTUAL_PREV_REPT", EVT_KEY_REPT(KEY_PLUS) },
|
||||
@@ -1980,6 +2005,9 @@ const luaR_value_entry opentxConstants[] = {
|
||||
{"UNIT_MILLILITERS", UNIT_MILLILITERS },
|
||||
{"UNIT_FLOZ", UNIT_FLOZ },
|
||||
{"UNIT_MILLILITERS_PER_MINUTE", UNIT_MILLILITERS_PER_MINUTE },
|
||||
{"UNIT_HERTZ", UNIT_HERTZ },
|
||||
{"UNIT_MS", UNIT_MS },
|
||||
{"UNIT_US", UNIT_US },
|
||||
{"UNIT_HOURS", UNIT_HOURS },
|
||||
{"UNIT_MINUTES", UNIT_MINUTES },
|
||||
{"UNIT_SECONDS", UNIT_SECONDS },
|
||||
|
||||
+186
-5
@@ -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 },
|
||||
|
||||
@@ -253,23 +253,23 @@ class LuaWidget: public Widget
|
||||
LuaWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData, int widgetData):
|
||||
Widget(factory, zone, persistentData),
|
||||
widgetData(widgetData),
|
||||
errorMessage(0)
|
||||
errorMessage(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~LuaWidget()
|
||||
~LuaWidget() override
|
||||
{
|
||||
luaL_unref(lsWidgets, LUA_REGISTRYINDEX, widgetData);
|
||||
if (errorMessage) free(errorMessage);
|
||||
free(errorMessage);
|
||||
}
|
||||
|
||||
virtual void update();
|
||||
void update() override;
|
||||
|
||||
void refresh() override;
|
||||
|
||||
virtual void background();
|
||||
void background() override;
|
||||
|
||||
virtual const char * getErrorMessage() const;
|
||||
const char * getErrorMessage() const override;
|
||||
|
||||
protected:
|
||||
int widgetData;
|
||||
@@ -300,7 +300,7 @@ class LuaWidgetFactory: public WidgetFactory
|
||||
{
|
||||
}
|
||||
|
||||
virtual Widget * create(const Zone & zone, Widget::PersistentData * persistentData, bool init=true) const
|
||||
Widget * create(const Zone & zone, Widget::PersistentData * persistentData, bool init=true) const override
|
||||
{
|
||||
if (lsWidgets == 0) return 0;
|
||||
if (init) {
|
||||
|
||||
Reference in New Issue
Block a user