Repository navigation
Expand file tree
/
Copy pathapp.lua
More file actions
270 lines (213 loc) · 6.6 KB
/
Copy pathapp.lua
File metadata and controls
270 lines (213 loc) · 6.6 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
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
--[[#######################################################################
## app.lua ##
## ModelList - app ##
## ##
## Author: BeGab ##
## ##
## URL : https://github.com/Be-Gab/ModelList ##
## ##
## Copyright (C) "BeGab" ##
## ##
###########################################################################
## License GNU General Public License v3.0 ##
#########################################################################]]
local app = ...
local A = {}
app.STATE = {}
app.STATE.INIT = 1
app.STATE.SHOW_MODEL_LIST = 20
app.STATE.SHOW_MODEL_LIST_WAIT = 30
app.STATE.QUIT = 999
app.state = app.STATE.INIT
local function getModelsTable()
local models = {}
for fname in dir("/MODELS") do
-- Csak a modelXX.yml fájlokat vesszük
local num = string.match( fname , "^model(%d+)%.yml$" )
if num then
local id = tonumber(num)
local modelName = fname -- fallback a fájlnévre
-- Megpróbáljuk kiolvasni a valódi nevet a YAML-ból
local f = io.open("/MODELS/" .. fname, "r")
if f then
while true do
local line = io.read(f, 120)
if not line or #line == 0 then break end
-- Keresés: name: "Valami név" vagy name: Valami név
local found = string.match( line , 'name:%s*"?([^"\r\n]+)"?' )
if found then
modelName = string.match( found , "^%s*(.-)%s*$" ) -- trim
break
end
end
io.close(f)
end
models[id] = { ["id"] = id,
["modelName"] = modelName,
["fileName" ] = fname
}
end
end
return models
end
local function isFileExist(fileName)
if type(fileName) ~= "string" or fileName == "" then
return false
end
local fileName = io.open(fileName, "r")
if fileName then
io.close(fileName)
return true
end
return false
end
local function getFilesByExtension(path, extension)
if type(path) ~= "string" or path == "" then
return {}
end
local result = {}
local extLen = -1 * #extension
-- EdgeTX-ben a dir() iterator-t ad vissza
for fname in dir(path) do
app.d.log( "fname" , fname , "getFilesByExtension()" )
if string.sub( fname, extLen ) == extension then
table.insert(result, fname)
end
end
app.d.printAssoc( "getFilesByExtension() :: result" , result )
return result
end
local function modelsNamesForCfgFiles( aCfgFiles, aAllModel )
local cfgModels = {}, id
for k , f in ipairs( cfgFiles ) do
id = tonumber( string.match( f , "(%d+)") )
if aAllModel[ id ] then
-- Csak azok a .cfg állományok melyenek van párja az aAllModel-ben -> van ilye a /MODELS mappában is. Teszten érdekes ez.
cfgModels[ id ] = { ["name"] = aAllModel[ id ] ,
["cfgFile"] = f
}
end
end
-- app.d.printAssoc( "Return" , cfgModels )
return cfgModels
end
-- ====================================================================================================================
local function showErrorMessage( s )
dispErrorMsg( s )
app.state = app.STATE.SHOW_MODEL_LIST_WAIT
return 0
end
local function proc_ShowModelList()
local mdlTable = getModelsTable()
local function modelLine( mdl )
local ui = { type = "rectangle" ,
filled = false ,
thickness = 2 ,
rounded = 6 ,
flexFlow = lvgl.FLOW_ROW , flexPad = 0 ,
scrollBar = false, scrollDir = 0 ,
children = {
{ type = "label" ,
align = CENTER ,
w = 40 * lvgl.LCD_SCALE ,
text = mdl.id
} ,
{ type = "label" ,
align = CENTER ,
w = 250 * lvgl.LCD_SCALE ,
text = mdl.modelName
} ,
{ type = "label" ,
align= RIGHT,
w = 100 * lvgl.LCD_SCALE ,
text = mdl.fileName
}
}
}
return ui
end
local lineUi = {}
for id , mdl in pairs( mdlTable ) do
lineUi[ #lineUi+1 ] = modelLine( mdl )
end
lvgl.clear()
ui =
{
{ type = "box", -- id = "fullScreen" ,
scrollBar = false, scrollDir = 0,
flexFlow = lvgl.FLOW_COLUMN ,
flexPad = 0 ,
x = 0 ,
y = 0 ,
w = LCD_W ,
h = LCD_H ,
children = {
{ type = "rectangle" ,
flexFlow = lvgl.FLOW_ROW ,
flexPad = 0 ,
scrollBar = false, scrollDir = 0,
w = LCD_W ,
align = CENTER,
color = COLOR_THEME_SECONDARY1 ,
h = 40 * lvgl.LCD_SCALE ,
children = {
{ type = "label" ,
w = LCD_W * 0.6,
align = CENTER,
text = "Models on the radio"
},
{ type = "button" ,
text = " Quit ",
press = (function() app.state = app.STATE.QUIT; end)
}
}
},
{ type = "box",
flexFlow = lvgl.FLOW_COLUMN ,
flexPad = lvgl.PAD_MEDIUM ,
scrollBar = true, scrollDir = lvgl.SCROLL_VER,
w = LCD_W ,
h = LCD_H - ( 40 * lvgl.LCD_SCALE ) ,
children = lineUi
}
}
}
}
lvgl.build( ui )
app.state = app.STATE.SHOW_MODEL_LIST_WAIT
return 0
end
local function state_INIT()
app.d = loadScript( app.otsFolder .. "d.lua" , "tbd" )( app.shortname )
-- -----------------------------------------------------------------------
app.state = app.STATE.SHOW_MODEL_LIST
return 0
end
function proc_WAIT()
return 0
end
-- #############################################################
function A.init()
state_INIT()
return 0
end
function A.run(event, touchState)
-- Alap eseménykezelés
if event == EVT_VIRTUAL_EXIT then
return 1
end
if app.state == app.STATE.INIT then
return state_INIT()
elseif app.state == app.STATE.SHOW_MODEL_LIST then
proc_ShowModelList()
elseif app.state == app.STATE.SHOW_MODEL_LIST_WAIT then
proc_WAIT()
elseif app.state == app.STATE.QUIT then
return 2
else
error( "state not exist : " .. app.state )
return 2
end
return 0
end
return A