1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-17 13:25:20 +03:00

The script for SBEC now searches for a SBEC sensor

This commit is contained in:
Bertrand Songis 2019-04-01 18:48:14 +02:00
parent 3bc75c1d55
commit d5ce54047c
3 changed files with 67 additions and 14 deletions

View file

@ -20,25 +20,19 @@ local version = "v1.2"
local VALUE = 0 local VALUE = 0
local COMBO = 1 local COMBO = 1
local FLPOI = 2
local edit = false local edit = false
local page = 1 local page = 1
local current = 1 --row local current = 1 --row
local refreshState = 0 local refreshState = 0
local refreshIndex = 0 local refreshIndex = 0
local refreshIndex3 = 0
local pageOffset = 0 local pageOffset = 0
local pages = {} local pages = {}
local fields = {} local fields = {}
local modifications = {} local modifications = {}
local thistime = getTime()
local lastTime = thistime
local margin = 1 local margin = 1
local spacing = 8 local spacing = 8
local configFields = {} local appId = 0
local counter = 0
local function drawScreenTitle(title,page, pages) local function drawScreenTitle(title,page, pages)
if math.fmod(math.floor(getTime()/100),10) == 0 then if math.fmod(math.floor(getTime()/100),10) == 0 then
@ -156,19 +150,19 @@ local function redrawFieldsPage()
end end
local function telemetryRead(fieldx) local function telemetryRead(fieldx)
return sportTelemetryPush(0x17, 0x30, 0x0e50, fieldx) return sportTelemetryPush(0x17, 0x30, appId, fieldx)
end end
local function telemetryIdle(field) local function telemetryIdle(field)
return sportTelemetryPush(0x17, 0x21, 0x0e50, field) return sportTelemetryPush(0x17, 0x21, appId, field)
end end
local function telemetryUnIdle(field) local function telemetryUnIdle(field)
return sportTelemetryPush(0x17, 0x20, 0x0e50, field) return sportTelemetryPush(0x17, 0x20, appId, field)
end end
local function telemetryWrite(fieldx, valuex) local function telemetryWrite(fieldx, valuex)
return sportTelemetryPush(0x17, 0x31, 0x0e50, fieldx + valuex*256) return sportTelemetryPush(0x17, 0x31, appId, fieldx + valuex*256)
end end
local telemetryPopTimeout = 0 local telemetryPopTimeout = 0
@ -188,7 +182,7 @@ local function refreshNext()
end end
elseif refreshState == 1 then elseif refreshState == 1 then
local physicalId, primId, dataId, value = sportTelemetryPop() local physicalId, primId, dataId, value = sportTelemetryPop()
if primId == 0x32 and dataId >= 0x0e50 and dataId <= 0x0e5f then if primId == 0x32 and dataId == appId then
local fieldId = value % 256 local fieldId = value % 256
local field = fields[refreshIndex + 1] local field = fields[refreshIndex + 1]
if fieldId == field[3] then if fieldId == field[3] then
@ -261,6 +255,18 @@ local function init()
runSettingsPage, runSettingsPage,
} }
for index = 1, 40, 1 do
local sensor = model.getSensor(index)
if sensor ~= nil and sensor.id >= 0x0e50 and sensor.id <= 0x0e5f then
appId = sensor.id
break
end
end
if appId == 0 then
error("No SBEC sensor in this model!")
end
telemetryIdle(0x80) telemetryIdle(0x80)
end end

View file

@ -1096,7 +1096,8 @@ static int luaSetTelemetryValue(lua_State * L)
const char* name = luaL_optstring(L, 7, NULL); const char* name = luaL_optstring(L, 7, NULL);
if (name != NULL && strlen(name) > 0) { if (name != NULL && strlen(name) > 0) {
str2zchar(zname, name, 4); str2zchar(zname, name, 4);
} else { }
else {
zname[0] = hex2zchar((id & 0xf000) >> 12); zname[0] = hex2zchar((id & 0xf000) >> 12);
zname[1] = hex2zchar((id & 0x0f00) >> 8); zname[1] = hex2zchar((id & 0x0f00) >> 8);
zname[2] = hex2zchar((id & 0x00f0) >> 4); zname[2] = hex2zchar((id & 0x00f0) >> 4);
@ -1111,7 +1112,8 @@ static int luaSetTelemetryValue(lua_State * L)
telemetrySensor.instance = instance; telemetrySensor.instance = instance;
telemetrySensor.init(zname, unit, prec); telemetrySensor.init(zname, unit, prec);
lua_pushboolean(L, true); lua_pushboolean(L, true);
} else { }
else {
lua_pushboolean(L, false); lua_pushboolean(L, false);
} }
return 1; return 1;

View file

@ -1314,6 +1314,50 @@ static int luaModelSetGlobalVariable(lua_State *L)
return 0; 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[] = { const luaL_Reg modelLib[] = {
{ "getInfo", luaModelGetInfo }, { "getInfo", luaModelGetInfo },
{ "setInfo", luaModelSetInfo }, { "setInfo", luaModelSetInfo },
@ -1343,5 +1387,6 @@ const luaL_Reg modelLib[] = {
{ "setOutput", luaModelSetOutput }, { "setOutput", luaModelSetOutput },
{ "getGlobalVariable", luaModelGetGlobalVariable }, { "getGlobalVariable", luaModelGetGlobalVariable },
{ "setGlobalVariable", luaModelSetGlobalVariable }, { "setGlobalVariable", luaModelSetGlobalVariable },
{ "getSensor", luaModelGetSensor },
{ NULL, NULL } /* sentinel */ { NULL, NULL } /* sentinel */
}; };