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

Add unit to lua getFieldInfo (#4750)

* Create getUnit lua function

* Cosmetics

* Expend getFieldInfo instead of creating a new function

* Streamline units table

* @projeckk2glider comments

* Cosmetics

* Use simple division
This commit is contained in:
3djc 2017-04-06 22:31:17 +02:00 committed by Bertrand Songis
parent 537fe906ce
commit b291faf7a7

View file

@ -478,10 +478,12 @@ static int luaCrossfireTelemetryPush(lua_State * L)
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
| OpenTX Version | Radio |
|----------------|-------|
| 2.0 | [all](http://downloads-20.open-tx.org/firmware/lua_fields.txt) |
| 2.1 | [X9D and X9D+](http://downloads-21.open-tx.org/firmware/lua_fields_taranis.txt), [X9E](http://downloads-21.open-tx.org/firmware/lua_fields_taranis_x9e.txt) |
| 2.2 | [X9D and X9D+](http://downloads.open-tx.org/2.2/firmware/lua_fields_x9d.txt), [X9E](http://downloads.open-tx.org/2.2/firmware/lua_fields_x9e.txt), [Horus](http://downloads.open-tx.org/2.2/firmware/lua_fields_x12s.txt) |
@param name (string) name of the field
@ -489,10 +491,11 @@ The list of valid sources is available:
* `id` (number) field identifier
* `name` (string) field name
* `desc` (string) field description
* 'unit' (number) unit identifier [Full list](../appendix/units.html)
@retval nil the requested field was not found
@status current Introduced in 2.0.8
@status current Introduced in 2.0.8, 'unit' field added in 2.2.0
*/
static int luaGetFieldInfo(lua_State * L)
{
@ -504,6 +507,13 @@ static int luaGetFieldInfo(lua_State * L)
lua_pushtableinteger(L, "id", field.id);
lua_pushtablestring(L, "name", what);
lua_pushtablestring(L, "desc", field.desc);
if (field.id >= MIXSRC_FIRST_TELEM && field.id <= MIXSRC_LAST_TELEM) {
TelemetrySensor & telemetrySensor = g_model.telemetrySensors[(int)((field.id-MIXSRC_FIRST_TELEM)/3)];
lua_pushtableinteger(L, "unit", telemetrySensor.unit);
}
else {
lua_pushtablenil(L, "unit");
}
return 1;
}
return 0;
@ -663,7 +673,7 @@ Play a numerical value (text to speech)
@param value (number) number to play. Value is interpreted as integer.
@param unit (number) unit identifier (see table todo)
@param unit (number) unit identifier [Full list]((../appendix/units.html))
@param attributes (unsigned number) possible values:
* `0 or not present` plays integral part of the number (for a number 123 it plays 123)
@ -672,37 +682,6 @@ Play a numerical value (text to speech)
@status current Introduced in 2.0.0
| 2.2 Unit | Sound |
| --- | --- |
| 0 | (no unit played) |
| 1 | Volts |
| 2 | Amps |
| 3 | Milliamps |
| 4 | Knots |
| 5 | Meters per Second |
| 6 | Feet per Second |
| 7 | Kilometers per Hour|
| 8 | Miles per Hour |
| 9 | Meters |
| 10 | Feet |
| 11 | Degrees Celsius |
| 12 | Degrees Fahrenheit |
| 13 | Percent |
| 14 | Milliamp Hours |
| 15 | Watts |
| 16 | Milliwatts |
| 17 | DB |
| 18 | RPM |
| 19 | Gee |
| 20 | Degrees |
| 21 | Radians |
| 22 | Milliliters |
| 23 | Fluid Ounces |
| 24 | Hours |
| 25 | Minutes |
| 26 | Seconds |
*/
static int luaPlayNumber(lua_State * L)
{
@ -1004,14 +983,7 @@ static int luaDefaultStick(lua_State * L)
@param value fed to the sensor
@param unit unit of the sensor.
* `0 or not present` UNIT_RAW.
* `!= 0` Valid values are 1 (UNIT_VOLTS), 2 (UNIT_AMPS), 3 (UNIT_MILLIAMPS),
4 (UNIT_KTS), 5 (UNIT_METERS_PER_SECOND), 6 (UNIT_FEET_PER_SECOND), 7 (UNIT_KMH), 8 (UNIT_MPH), 9 (UNIT_METERS),
10 (UNIT_FEET), 11 (UNIT_CELSIUS), 12 (UNIT_FAHRENHEIT), 13 (UNIT_PERCENT), 14 (UNIT_MAH), 15 (UNIT_WATTS),
16 (UNIT_MILLIWATTS), 17 (UNIT_DB), 18 (UNIT_RPMS), 19 (UNIT_G), 20 (UNIT_DEGREE), 21 (UNIT_RADIANS),
22 (UNIT_MILLILITERS), 23 (UNIT_FLOZ), 24 (UNIT_HOURS), 25 (UNIT_MINUTES), 26 (UNIT_SECONDS), 27 (UNIT_CELLS),
28 (UNIT_DATETIME), 29 (UNIT_GPS), 30 (UNIT_BITFIELD), 31 (UNIT_TEXT)
@param unit unit of the sensor [Full list](../appendix/units.html)
@param precision the precision of the sensor
* `0 or not present` no decimal precision.
@ -1116,7 +1088,7 @@ static int luaGetRSSI(lua_State * L)
/*luadoc
@function loadScript(file [, mode], [,env])
Load a Lua script file. This is similar to Lua's own [loadfile()](https://www.lua.org/manual/5.2/manual.html#pdf-loadfile)
Load a Lua script file. This is similar to Lua's own [loadfile()](https://www.lua.org/manual/5.2/manual.html#pdf-loadfile)
API method, but it uses OpenTx's optional pre-compilation feature to save memory and time during load.
Return values are same as from Lua API loadfile() method: If the script was loaded w/out errors
@ -1128,20 +1100,20 @@ then the loaded script (or "chunk") is returned as a function. Otherwise, return
@param mode (string) (optional) Controls whether to force loading the text (.lua) or pre-compiled binary (.luac)
version of the script. By default OTx will load the newest version and compile a new binary if necessary (overwriting any
existing .luac version of the same script, and stripping some debug info like line numbers).
existing .luac version of the same script, and stripping some debug info like line numbers).
You can use `mode` to control the loading behavior more specifically. Possible values are:
* `b` only binary.
* `t` only text.
* `T` (default on simulator) prefer text but load binary if that is the only version available.
* `bt` (default on radio) either binary or text, whichever is newer (binary preferred when timestamps are equal).
* Add `x` to avoid automatic compilation of source file to .luac version.
* Add `x` to avoid automatic compilation of source file to .luac version.
Eg: "tx", "bx", or "btx".
* Add `c` to force compilation of source file to .luac version (even if existing version is newer than source file).
* Add `c` to force compilation of source file to .luac version (even if existing version is newer than source file).
Eg: "tc" or "btc" (forces "t", overrides "x").
* Add `d` to keep extra debug info in the compiled binary.
* Add `d` to keep extra debug info in the compiled binary.
Eg: "td", "btd", or "tcd" (no effect with just "b" or with "x").
@notice
@notice
Note that you will get an error if you specify `mode` as "b" or "t" and that specific version of the file does not exist (eg. no .luac file when "b" is used).
Also note that `mode` is NOT passed on to Lua's loader function, so unlike with loadfile() the actual file content is not checked (as if no mode or "bt" were passed to loadfile()).