Skip to content

Commit

Permalink
Add widget fmode.lua
Browse files Browse the repository at this point in the history
- Outputs a string representing the actual flight mode
  • Loading branch information
Matze-Jung committed Sep 21, 2019
1 parent 60d8a5f commit 34a29cd
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/SCRIPTS/WIDGETS/fmode.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--[[ ** TELEMETRY SCREEN WIDGET **
Outputs a string representing the actual flight mode.
NOTE: This is a wrapper function using valueWidget() [WIDGETS/value.lua].
Define source and flightmodes below.
PLATFORM
X7, X9 and relatives
SCALING
vert: scalable
horiz: scalable
PARAMETER
zone: table [x, y, w, h]
- Location on display in px
(x-pos, y-pos, width, height)
event: int
- User event
opts: table
- Configurations
src: function or sensor-ID string/number
- Data source
lbl: string (optional)
- Label text
style: int (optional, default 0)
- Text Attributes: 0, DBLSIZE, MIDSIZE, SMLSIZE, INVERS, BLINK, XXLSIZE, LEFT
All att values can be combined together using the + character. ie BLINK + DBLSIZE
p: table (optional, default [t=0, r=2, b=0, l=0])
- Padding between content and widget boundaries in px
(top, right, bottom, left)
--]]

local valueWidget = assert(loadScript("/SCRIPTS/WIDGETS/value.lua"))()

local function flightModeWidget(zone, event, opts)
local _opts = {}

for i, opt in pairs(opts) do
_opts[i] = opt
end

local val = getValue("ch5") -- switchname, global variable or other source

_opts.src = function() -- returns the string
if val < -512 then
return "Turtle"
elseif val > -100 and val < 100 then
return "Acro"
elseif val > 512 then
return "Horizon"
end
return "?"
end

valueWidget.run(zone, event, _opts)
end

return { run=flightModeWidget }

0 comments on commit 34a29cd

Please sign in to comment.