mirror of
https://github.com/opentx/opentx.git
synced 2025-07-19 14:25:11 +03:00
The script for SBEC now searches for a SBEC sensor
This commit is contained in:
parent
3bc75c1d55
commit
d5ce54047c
3 changed files with 67 additions and 14 deletions
|
@ -1096,7 +1096,8 @@ static int luaSetTelemetryValue(lua_State * L)
|
|||
const char* name = luaL_optstring(L, 7, NULL);
|
||||
if (name != NULL && strlen(name) > 0) {
|
||||
str2zchar(zname, name, 4);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
zname[0] = hex2zchar((id & 0xf000) >> 12);
|
||||
zname[1] = hex2zchar((id & 0x0f00) >> 8);
|
||||
zname[2] = hex2zchar((id & 0x00f0) >> 4);
|
||||
|
@ -1111,7 +1112,8 @@ static int luaSetTelemetryValue(lua_State * L)
|
|||
telemetrySensor.instance = instance;
|
||||
telemetrySensor.init(zname, unit, prec);
|
||||
lua_pushboolean(L, true);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
lua_pushboolean(L, false);
|
||||
}
|
||||
return 1;
|
||||
|
|
|
@ -1314,6 +1314,50 @@ static int luaModelSetGlobalVariable(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*luadoc
|
||||
@function model.getSensor(sensor)
|
||||
|
||||
Get Telemetry Sensor parameters
|
||||
|
||||
@param sensor (unsigned number) sensor number (use 0 for sensor 1)
|
||||
|
||||
@retval nil requested logical switch does not exist
|
||||
|
||||
@retval table logical switch data:
|
||||
* `func` (number) function index
|
||||
* `v1` (number) V1 value (index)
|
||||
* `v2` (number) V2 value (index or value)
|
||||
* `v3` (number) V3 value (index or value)
|
||||
* `and` (number) AND switch index
|
||||
* `delay` (number) delay (time in 1/10 s)
|
||||
* `duration` (number) duration (time in 1/10 s)
|
||||
|
||||
@status current Introduced in 2.3.0
|
||||
*/
|
||||
static int luaModelGetSensor(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
if (idx < MAX_TELEMETRY_SENSORS) {
|
||||
TelemetrySensor & sensor = g_model.telemetrySensors[idx];
|
||||
lua_newtable(L);
|
||||
lua_pushtableinteger(L, "type", sensor.type);
|
||||
lua_pushtablezstring(L, "name", sensor.label);
|
||||
lua_pushtableinteger(L, "unit", sensor.unit);
|
||||
lua_pushtableinteger(L, "prec", sensor.prec);
|
||||
if (sensor.type == TELEM_TYPE_CUSTOM) {
|
||||
lua_pushtableinteger(L, "id", sensor.id);
|
||||
lua_pushtableinteger(L, "instance", sensor.instance);
|
||||
}
|
||||
else {
|
||||
lua_pushtableinteger(L, "formula", sensor.formula);
|
||||
}
|
||||
}
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg modelLib[] = {
|
||||
{ "getInfo", luaModelGetInfo },
|
||||
{ "setInfo", luaModelSetInfo },
|
||||
|
@ -1343,5 +1387,6 @@ const luaL_Reg modelLib[] = {
|
|||
{ "setOutput", luaModelSetOutput },
|
||||
{ "getGlobalVariable", luaModelGetGlobalVariable },
|
||||
{ "setGlobalVariable", luaModelSetGlobalVariable },
|
||||
{ "getSensor", luaModelGetSensor },
|
||||
{ NULL, NULL } /* sentinel */
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue