-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRacer.lua
executable file
·118 lines (108 loc) · 3.4 KB
/
Racer.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---------------------------------
-- BEGIN OF CONFIGURATION
---------------------------------
-- This is your configuration. Modify it accordingly.
-- Tell us which radio you are using. It can be either x7 (Taranis QX7) or x9 (Taranis X9D / X9D+)
RADIO = "x9" -- Use this line if you are using Taranis X9D / X9D +
-- RADIO = "x7" -- Use this line if you are using Taranis QX7
-- This represents the timer of your flight time. First timer has index 0, second 1, etc...
-- You need to setup the timer yourself in your model. See docs for more details.
FLIGHT_TIMER = 0
-- Enable Real Heading if your drone has a compass. It will replace the arrows in the heading area by "North, West, South, East"
REAL_HEADING = true
-- Enable debug trace (will show debug data)
DEBUG = false
---------------------------------
-- END OF CONFIGURATION
---------------------------------
---------------------------------
-- GLOBAL VARIABLES
---------------------------------
-- Screen is 212x64 pixels
local REFRESH_FREQUENCY_30MS = 3
-- Always redraw each timeout seconds (3 seconds approx.)
local INVALIDATE_TIMEOUT = 300
---------------------------------
-- VARIABLES
---------------------------------
local lastTime
local lastRun
local widgets
local timerMatrix
local refreshMatrix
local firstDraw
-- Load widget from file
local function loadWidget(path)
local w = loadScript(path)()
w.init(RADIO)
timerMatrix[w.tag] = 0
refreshMatrix[w.tag] = false
return w
end
-- Check whether widget should invalidate layout and redraw or not
local function checkRefreshFlag(widget)
if widget.shouldRefresh(lastTime - timerMatrix[widget.tag]) then
timerMatrix[widget.tag] = lastTime
refreshMatrix[widget.tag] = true
end
end
-- Perform screen update of widget
local function refreshWidget(widget, force)
if refreshMatrix[widget.tag] or force then
widget.layout()
widget.redraw()
if DEBUG then
lcd.drawText(46, 32, "drw" .. math.floor(lastTime / 10) % 90 + 10, SMLSIZE)
end
timerMatrix[widget.tag] = lastTime
refreshMatrix[widget.tag] = false
end
end
-- Init telemetry screen
local function init()
firstDraw = true
lastTime = 0
lastRun = 0
timerMatrix = {}
refreshMatrix = {}
widgets = {
loadWidget("/SCRIPTS/TELEMETRY/RESOURCEPOOL/widgets/heading.lua"),
loadWidget("/SCRIPTS/TELEMETRY/RESOURCEPOOL/widgets/flighttime.lua"),
loadWidget("/SCRIPTS/TELEMETRY/RESOURCEPOOL/widgets/battery.lua"),
loadWidget("/SCRIPTS/TELEMETRY/RESOURCEPOOL/widgets/horizon.lua"),
loadWidget("/SCRIPTS/TELEMETRY/RESOURCEPOOL/widgets/rssi.lua"),
loadWidget("/SCRIPTS/TELEMETRY/RESOURCEPOOL/widgets/flightmode.lua")
}
end
local function background()
local currentTime = getTime()
-- Refresh at specific frequency
if currentTime > lastTime + REFRESH_FREQUENCY_30MS then
lastTime = currentTime
for _, w in ipairs(widgets) do
checkRefreshFlag(w)
end
end
-- Force complete refresh at specific intervals
if lastTime - lastRun > INVALIDATE_TIMEOUT then
firstDraw = true
end
end
local function run(event)
if firstDraw then
lcd.clear()
for _, w in ipairs(widgets) do
refreshWidget(w, true)
end
firstDraw = false
lastRun = lastTime
return
end
if DEBUG then
lcd.drawText(46, 24, "cmp" .. math.floor(lastTime / 10) % 90 + 10, SMLSIZE)
end
for _, w in ipairs(widgets) do
refreshWidget(w)
end
end
return { init = init, background = background, run = run }