-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsticks_colorlcd.lua
321 lines (291 loc) · 11.2 KB
/
sticks_colorlcd.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
-- TNS|Stick Command Viewer|TNE
--------------------------------------------------------------------------
-- Inspired by Lee Scholfied (Painless360)
-- Scrollable stick commands reference (INAV, Betaflight, HDZero)
-- Version 1.1
-- Assumes a display resolution of 468 x 272 (TX16S, T16, others)
-- Assumes Mode 2
--------------------------------------------------------------------------
local currentRow = 20 -- Betaflight = 1, HDZero = 14, INAV = 20
local resetRow = 20
local maxRows = 41
local textSize = MIDSIZE
local screenWidth = LCD_W
local screenHeight = LCD_H
local stickRect = 22
local lineHeight = 24
local labelCol = 24
local row = 0
local currentHeadingLeft = 0
local currentHeadingRight = 0
local function drawStick(x, y, heading)
stick = stickRect / 2
y = y + 4
lcd.drawRectangle(x, y, stickRect, stickRect, 0, 2)
if (heading == "C") then
lcd.drawLine(x + stick-1, y + stick, x + stick+1, y + stick, SOLID, 0)
lcd.drawLine(x + stick, y + stick-1, x + stick, y + stick+1, SOLID, 0)
elseif (heading == "N") then
lcd.drawLine(x + stick, y + stick, x + stick-1, y + 0, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + stick, y + 0, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + stick+1, y + 0, SOLID, 0)
elseif (heading == "NE") then
lcd.drawLine(x + stick, y + stick, x + (stick * 2), y + 0, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + (stick * 2), y + 1, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + (stick * 2), y - 1, SOLID, 0)
elseif (heading == "E") then
lcd.drawLine(x + stick, y + stick, x + (stick * 2), y + stick, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + (stick * 2), y + stick-1, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + (stick * 2), y + stick+1, SOLID, 0)
elseif (heading == "SE") then
lcd.drawLine(x + stick, y + stick, x + (stick * 2), y + (stick * 2), SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + (stick * 2), y + (stick * 2)-1, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + (stick * 2), y + (stick * 2)+1, SOLID, 0)
elseif (heading == "S") then
lcd.drawLine(x + stick, y + stick, x + stick, y + (stick * 2), SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + stick-1, y + (stick * 2), SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + stick+1, y + (stick * 2), SOLID, 0)
elseif (heading == "SW") then
lcd.drawLine(x + stick, y + stick, x + 0, y + (stick * 2), SOLID, 0)
lcd.drawLine(x + stick, y + stick, x - 1, y + (stick * 2), SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + 1, y + (stick * 2), SOLID, 0)
elseif (heading == "W") then
lcd.drawLine(x + stick, y + stick, x + 0, y + stick, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + 0, y + stick-1, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + 0, y + stick+1, SOLID, 0)
elseif (heading == "NW") then
lcd.drawLine(x + stick, y + stick, x + 0, y + 0, SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + 0, y - 1 , SOLID, 0)
lcd.drawLine(x + stick, y + stick, x + 0, y + 1, SOLID, 0)
end
end
local function drawStickCommand(x, y, label, headingLeft, headingRight, isBanner)
stickCol = 360
stickSize = 22
stickOffset = 4
stickGutter = 30
if isBanner == true then
lcd.drawFilledRectangle(0, row + 2, screenWidth, lineHeight, CUSTOM_COLOR)
-- lcd.drawRectangle(0, row + lineHeight, screenWidth, 2, 0, 1)
lcd.setColor(CUSTOM_COLOR, WHITE)
lcd.drawText(x - 12, y, label, MIDSIZE + CUSTOM_COLOR)
lcd.setColor(CUSTOM_COLOR, BLACK)
else
lcd.drawText(x, y, label, MIDSIZE + CUSTOM_COLOR)
drawStick(stickCol, y, headingLeft)
drawStick(stickCol + stickGutter, y, headingRight)
if headingLeft == currentHeadingLeft and headingRight == currentHeadingRight then
lcd.drawRectangle(stickCol - 10, y + 3, (stickRect * 2) + stickGutter, stickRect + 2, DOTTED, 1)
end
end
return lineHeight
end
local function processEvents(event)
if event > 0 then
lastNumberMessage = event
end
if event == EVT_VIRTUAL_NEXT then
lastMessage = "Jog wheel CW"
if (currentRow + 11) <= maxRows then
currentRow = currentRow + 1
end
killEvents(EVT_VIRTUAL_NEXT)
end
if event == EVT_VIRTUAL_PREV then
lastMessage = "Jog wheel CCW"
if (currentRow - 1) > 0 then
currentRow = currentRow - 1
end
killEvents(EVT_VIRTUAL_PREV)
end
if event == 96 or event == 1538 then
lastMessage = "Menu or Jog wheel Button Pressed"
currentRow = resetRow
killEvents(96)
end
if event == 98 then
lastMessage = "Navigate Button Pressed"
killEvents(98)
end
return event
end
local function getStickHeading(stick)
s1 = 0
s2 = 0
dz = 12
hdg = ""
if (stick == "LEFT") then
s1 = getValue("thr") / 10.24
s2 = getValue("rud") / 10.24
elseif (stick == "RIGHT") then
s1 = getValue("ele") / 10.24
s2 = getValue("ail") / 10.24
end
if s1 >= -dz and s1 <= dz and s2 >= -dz and s2 <= dz then
hdg = "C"
elseif s1 >= 100-dz and s2 >= -dz and s2 <= dz then
hdg = "N"
elseif s1 >= 100-dz and s2 >= 100-dz then
hdg = "NE"
elseif s1 >= -dz and s1 <= dz and s2 >= 100-dz then
hdg = "E"
elseif s1 <= -100+dz and s2 >= 100-dz then
hdg = "SE"
elseif s1 <= -100+dz and s2 >= -dz and s2 <= dz then
hdg = "S"
elseif s1 <= -100+dz and s2 <= -100+dz then
hdg = "SW"
elseif s1 >= -dz and s1 <= dz and s2 <= -100+dz then
hdg = "W"
elseif s1 >= 100-dz and s2 <= -100+dz then
hdg = "NW"
end
return hdg
end
local function testRow(itemRow)
if itemRow >= currentRow and itemRow <= currentRow + 10 then
return true
else
return false
end
end
local function run(event)
lcd.clear()
processEvents(event)
currentHeadingLeft = getStickHeading("LEFT")
currentHeadingRight = getStickHeading("RIGHT")
col = 24
row = 0
if testRow(1) == true then
row = row + drawStickCommand(col, row, "Betaflight", "C", "C", true)
end
if testRow(2) == true then
row = row + drawStickCommand(col, row, "Betaflight Menu", "W", "N", false )
end
if testRow(3) == true then
row = row + drawStickCommand(col, row, "Betaflight <enter>", "C", "E", false )
end
if testRow(4) == true then
row = row + drawStickCommand(col, row, "Arm", "SE", "C", false)
end
if testRow(5) == true then
row = row + drawStickCommand(col, row, "Disarm", "SW", "C", false)
end
if testRow(6) == true then
row = row + drawStickCommand(col, row, "Calibrate Gyro", "SW", "S", false)
end
if testRow(7) == true then
row = row + drawStickCommand(col, row, "Calibrate Accel", "NW", "S", false)
end
if testRow(8) == true then
row = row + drawStickCommand(col, row, "Calibrate Compass", "NE", "S", false)
end
if testRow(9) == true then
row = row + drawStickCommand(col, row, "Save Settings", "SW", "SE", false)
end
if testRow(10) == true then
row = row + drawStickCommand(col, row, "Accel Trim Left", "N", "W", false)
end
if testRow(11) == true then
row = row + drawStickCommand(col, row, "Accel Trim Right", "N", "E", false)
end
if testRow(12) == true then
row = row + drawStickCommand(col, row, "Accel Trim Up/Fwd", "N", "N", false)
end
if testRow(13) == true then
row = row + drawStickCommand(col, row, "Accel Trim Dn/Bak", "N", "S", false)
end
if testRow(14) == true then
row = row + drawStickCommand(col, row, "HDZero", "C", "C", true)
end
if testRow(15) == true then
row = row + drawStickCommand(col, row, "Camera Control", "E", "C", false)
end
if testRow(16) == true then
row = row + drawStickCommand(col, row, "Non-HDZ Cam Exit", "W", "C", false)
end
if testRow(17) == true then
row = row + drawStickCommand(col, row, "Switch to 0mw", "SW", "SE", false)
end
if testRow(18) == true then
row = row + drawStickCommand(col, row, "Exit 0mw", "SE", "SW", false)
end
if testRow(19) == true then
row = row + drawStickCommand(col, row, "Enter VTX Menu", "SE", "SW", false)
end
if testRow(20) == true then
row = row + drawStickCommand(col, row, "INAV", "C", "C", true)
end
if testRow(21) == true then
row = row + drawStickCommand(col, row, "OSD Menu (CMS)", "W", "N", false)
end
if testRow(22) == true then
row = row + drawStickCommand(col, row, "Save settings", "SW", "SE", false)
end
if testRow(23) == true then
row = row + drawStickCommand(col, row, "Load WP mission", "S", "NE", false)
end
if testRow(24) == true then
row = row + drawStickCommand(col, row, "Save WP mission", "S", "NW", false)
end
if testRow(25) == true then
row = row + drawStickCommand(col, row, "Unload WP mission", "S", "SE", false)
end
if testRow(26) == true then
row = row + drawStickCommand(col, row, "Inc WP mission index", "W", "E", false)
end
if testRow(27) == true then
row = row + drawStickCommand(col, row, "Dec WP mission index", "W", "W", false)
end
if testRow(28) == true then
row = row + drawStickCommand(col, row, "Profile 1", "SW", "W", false)
end
if testRow(29) == true then
row = row + drawStickCommand(col, row, "Profile 2", "SW", "N", false)
end
if testRow(30) == true then
row = row + drawStickCommand(col, row, "Profile 3", "SW", "E", false)
end
if testRow(31) == true then
row = row + drawStickCommand(col, row, "Battery Profile 1", "NW", "W", false)
end
if testRow(32) == true then
row = row + drawStickCommand(col, row, "Battery Profile 2", "NW", "N", false)
end
if testRow(33) == true then
row = row + drawStickCommand(col, row, "Battery Profile 3", "NW", "E", false)
end
if testRow(34) == true then
row = row + drawStickCommand(col, row, "Calibrate Gyro", "SW", "S", false)
end
if testRow(35) == true then
row = row + drawStickCommand(col, row, "Calibrate Accel", "NW", "S", false)
end
if testRow(36) == true then
row = row + drawStickCommand(col, row, "Calibrate Compass", "NE", "S", false)
end
if testRow(37) == true then
row = row + drawStickCommand(col, row, "Trim Accel Left", "N", "W", false)
end
if testRow(38) == true then
row = row + drawStickCommand(col, row, "Trim Accel Right", "N", "E", false)
end
if testRow(39) == true then
row = row + drawStickCommand(col, row, "Trim Accel Forward", "N", "N", false)
end
if testRow(40) == true then
row = row + drawStickCommand(col, row, "Trim Accel Backward", "N", "S", false)
end
if testRow(41) == true then
row = row + drawStickCommand(col, row, "Bypass Arming Checks", "SE", "C", false)
end
return 0
end
local function init_func()
-- Called once when model is loaded, only need to get model name once...
local modeldata = model.getInfo()
if modeldata then
modelName = modeldata['name']
end
end
return { run=run, init=init_func }