/*luadoc @function getFieldInfo(name) Return detailed information about field (source) The list of valid sources is available: * for OpenTX 2.0.x at http://downloads-20.open-tx.org/firmware/lua_fields.txt * for OpenTX 2.1.x at http://downloads-21.open-tx.org/firmware/lua_fields.txt (depreciated) * for OpenTX 2.1.x Taranis and Taranis Plus at http://downloads-21.open-tx.org/firmware/lua_fields_taranis.txt * for OpenTX 2.1.x Taranis X9E at http://downloads-21.open-tx.org/firmware/lua_fields_taranis_x9e.txt In OpenTX 2.1.x the telemetry sources no longer have a predefined name. To get a telemetry value simply use it's sensor name. For example: * Altitude sensor has a name "Alt" * to get the current altitude use the source "Alt" * to get the minimum altitude use the source "Alt-", to get the maximum use "Alt+" @param name (string) name of the field @retval table information about requested field, table elements: * `id` (number) field identifier * `name` (string) field name * `desc` (string) field description @retval nil the requested field was not found @status current Introduced in 2.0.8 */ static int luaGetFieldInfo(lua_State *L) { const char * what = luaL_checkstring(L, 1); LuaField field; bool found = luaFindFieldByName(what, field, FIND_FIELD_DESC); if (found) { lua_newtable(L); lua_pushtableinteger(L, "id", field.id); lua_pushtablestring(L, "name", what); lua_pushtablestring(L, "desc", field.desc); return 1; } return 0; }
/*luadoc @function getValue(source) Returns the value of a source. The list of valid sources is available: * for OpenTX 2.0.x at http://downloads-20.open-tx.org/firmware/lua_fields.txt * for OpenTX 2.1.x at http://downloads-21.open-tx.org/firmware/lua_fields.txt (depreciated) * for OpenTX 2.1.x Taranis and Taranis Plus at http://downloads-21.open-tx.org/firmware/lua_fields_taranis.txt * for OpenTX 2.1.x Taranis X9E at http://downloads-21.open-tx.org/firmware/lua_fields_taranis_x9e.txt In OpenTX 2.1.x the telemetry sources no longer have a predefined name. To get a telemetry value simply use it's sensor name. For example: * Altitude sensor has a name "Alt" * to get the current altitude use the source "Alt" * to get the minimum altitude use the source "Alt-", to get the maximum use "Alt+" @param source can be an identifier (number) (which was obtained by the getFieldInfo()) or a name (string) of the source. @retval value current source value (number). Zero is returned for: * non-existing sources * for all telemetry source when the telemetry stream is not received @retval table GPS position is returned in a table: * `lat` (number) latitude, positive is North * `lon` (number) longitude, positive is East * `pilot-lat` (number) pilot latitude, positive is North * `pilot-lon` (number) pilot longitude, positive is East @retval table GPS date/time, see getDateTime() @retval table Cells are returned in a table (except where no cells were detected in which case the returned value is 0): * table has one item for each detected cell: * key (number) cell number (1 to number of cells) * value (number) current cell voltage @status current Introduced in 2.0.0, changed in 2.1.0 @notice Getting a value by its numerical identifier is faster then by its name. */ static int luaGetValue(lua_State *L) { int src = 0; if (lua_isnumber(L, 1)) { src = luaL_checkinteger(L, 1); } else { // convert from field name to its id const char *name = luaL_checkstring(L, 1); LuaField field; bool found = luaFindFieldByName(name, field); if (found) { src = field.id; } } luaGetValueAndPush(src); return 1; }
/*luadoc @function lcd.drawChannel(x, y, source, flags) Display a telemetry value at (x,y) @param x,y (positive numbers) starting coordinate @param source can be a source identifier (number) or a source name (string). See getValue() @param flags (unsigned number) drawing flags @status current Introduced in 2.0.6, changed in 2.1.0 (only telemetry sources are valid) */ static int luaLcdDrawChannel(lua_State *L) { if (!luaLcdAllowed) return 0; int x = luaL_checkinteger(L, 1); int y = luaL_checkinteger(L, 2); int channel = -1; if (lua_isnumber(L, 3)) { channel = luaL_checkinteger(L, 3); } else { const char * what = luaL_checkstring(L, 3); LuaField field; bool found = luaFindFieldByName(what, field); if (found) { channel = field.id; } } unsigned int att = luaL_optunsigned(L, 4, 0); getvalue_t value = getValue(channel); putsTelemetryChannelValue(x, y, (channel-MIXSRC_FIRST_TELEM)/3, value, att); return 0; }