-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathX9.lua
More file actions
159 lines (134 loc) · 4.06 KB
/
Copy pathX9.lua
File metadata and controls
159 lines (134 loc) · 4.06 KB
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
local current_screen = 1
-- minimum and maximum FPV frequencies
local min_freq = 5645
local max_freq = 5945
-- Uncomment following two lines for EU
--local min_allowed = 5725
--local max_allowed = 5875
-- minimum and maximum screen x-coordinates for position screen
local min_xpos = 11
local max_xpos = 201
local freq = {
A = {"5865", "5845", "5825", "5805", "5785", "5765", "5745", "5725"},
B = {"5733", "5752", "5771", "5790", "5809", "5828", "5847", "5866"},
E = {"5705", "5685", "5665", "5645", "5885", "5905", "5925", "5945"},
F = {"5740", "5760", "5780", "5800", "5820", "5840", "5860", "5880"},
R = {"5658", "5695", "5732", "5769", "5806", "5843", "5880", "5917"}
}
local pos = {
A = {},
B = {},
E = {},
F = {},
R = {}
}
-- initialize frequency positions (pos) for screen 2
local function init_func()
local freq_range = max_freq - min_freq
local pos_range = max_xpos - min_xpos
-- populate postion arrays
for band, freqs in pairs(freq) do
for i=1,8 do
pos[band][i] = (tonumber(freqs[i]) - min_freq) / freq_range * pos_range + min_xpos
end
end
end
-- returns if a frequency is legal
local function is_legal(freq)
if max_allowed == nil or min_allowed == nil then
return true
else
return tonumber(freq) > min_allowed and tonumber(freq) < max_allowed
end
end
-- draw a channel number and border
local function draw_chan(chan, x, y, flags)
-- draw number
lcd.drawText(x+2, y+2, chan, SMLSIZE + flags)
-- draw border
lcd.drawLine(x, y, x+7, y, SOLID, FORCE)
lcd.drawLine(x, y, x, y+9, SOLID, FORCE)
lcd.drawLine(x+7, y, x+7, y+9, SOLID, FORCE)
lcd.drawLine(x, y+9, x+7, y+9, SOLID, FORCE)
-- clear other pixel(s) inside the border
if flags ~= INVERS then
lcd.drawLine(x+1, y+5, x+1, y+5, SOLID, ERASE)
end
end
-- frequency screen
local function draw_freq_screen()
lcd.clear()
-- table coordinates
local xpos = { 13, 38, 63, 88, 113, 138, 163, 188 }
local ypos = { A = 12, B = 22, E = 32, F = 42, R = 52 }
-- draw vertical dividers
for i=9,209,25 do
lcd.drawLine(i, 1, i, 59, SOLID, FORCE)
end
-- draw horizontal dividers
for i=10,60,10 do
lcd.drawLine(1, i, 209, i, SOLID, FORCE)
end
-- draw channel numbers
for i=1,8 do
lcd.drawText(xpos[i]+7, 2, i)
end
-- draw band letters and frequencies
for band, freqs in pairs(freq) do
-- draw band letter
lcd.drawText(2, ypos[band], band)
-- draw frequencies
for i=1,8 do
if is_legal(freqs[i]) then
lcd.drawText(xpos[i], ypos[band], freqs[i])
else
-- fill out box
lcd.drawFilledRectangle(xpos[i]-4, ypos[band]-2, 26, 10, SOLID)
lcd.drawText(xpos[i], ypos[band], freqs[i], INVERS)
end
end
end
end
-- position screen
local function draw_pos_screen()
lcd.clear()
-- band coordinates
local ypos = { A = 3, B = 15, E = 27, F = 39, R = 51 }
-- draw vertical divider
lcd.drawLine(8, 3, 8, 60, SOLID, FORCE)
-- draw horizontal dividers
for i=8,56,12 do
lcd.drawLine(9, i, 210, i, SOLID, FORCE)
end
-- draw band letters and channel boxes
for band, freqs in pairs(freq) do
-- draw band letter
lcd.drawText(2, ypos[band]+2, band, SMLSIZE)
-- draw channel boxes
for i=1,8 do
local flags = 0
if not is_legal(freqs[i]) then
flags = INVERS
end
draw_chan(i, pos[band][i], ypos[band], flags)
end
end
end
local function run_func(event)
-- handle keypresses
if event == EVT_MENU_BREAK then
if current_screen == 1 then
current_screen = 2
else
current_screen = 1
end
end
-- draw current screen
if current_screen == 1 then
draw_freq_screen()
elseif current_screen == 2 then
draw_pos_screen()
end
return 0
end
return { init=init_func, run=run_func }