Skip to content

Commit 30b4440

Browse files
flights: fix bug in heli mode, debug view now widget size dependent (#135)
1 parent a32e341 commit 30b4440

11 files changed

+243
-82
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

sdcard/c480x272/WIDGETS/Flights/lib_flights_history.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function M.writeHeaderIfNeeded()
5353
io.close(hFile)
5454
end
5555

56-
function M.addFlightLog(duration, flight_count)
56+
function M.addFlightLog(flight_start_date_time, duration, flight_count)
5757
M.m_log.info("addFlightLog(%s, %s)", duration, flight_count)
5858

5959
M.writeHeaderIfNeeded()
@@ -65,8 +65,8 @@ function M.addFlightLog(duration, flight_count)
6565
end
6666

6767
-- flight_date =
68-
local now = getDateTime()
69-
local flight_date = string.format("%04d-%02d-%02d %02d:%02d", now.year, now.mon, now.day, now.hour, now.min)
68+
local dt = flight_start_date_time
69+
local flight_date = string.format("%04d-%02d-%02d %02d:%02d", dt.year, dt.mon, dt.day, dt.hour, dt.min)
7070
M.m_log.info("date_str: %s", flight_date)
7171

7272
-- model name

sdcard/c480x272/WIDGETS/Flights/lib_widget_tools.lua

+98-24
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ local FONT_12 = MIDSIZE -- 12px
1616
local FONT_8 = 0 -- Default 8px
1717
local FONT_6 = SMLSIZE -- 6px
1818

19+
local FONT_LIST = {FONT_6, FONT_8, FONT_12, FONT_16, FONT_38}
20+
1921
---------------------------------------------------------------------------------------------------
2022
local function log(fmt, ...)
2123
m_log.info(fmt, ...)
@@ -46,7 +48,8 @@ function M.unitIdToString(unitId)
4648
return txtUnit
4749
end
4850

49-
return "-#-"
51+
--return "-#-"
52+
return ""
5053
end
5154

5255
---------------------------------------------------------------------------------------------------
@@ -63,31 +66,36 @@ function M.periodicStart(t, durationMili)
6366
t.durationMili = durationMili;
6467
end
6568

66-
function M.periodicHasPassed(t)
69+
function M.periodicHasPassed(t, show_log)
6770
-- not started yet
6871
if (t.durationMili <= 0) then
6972
return false;
7073
end
7174

7275
local elapsed = getTime() - t.startTime;
7376
--log('elapsed: %d (t.durationMili: %d)', elapsed, t.durationMili)
77+
if show_log == true then
78+
log('elapsed: %0.1f/%0.1f sec', elapsed/100, t.durationMili/1000)
79+
end
7480
local elapsedMili = elapsed * 10;
7581
if (elapsedMili < t.durationMili) then
7682
return false;
7783
end
7884
return true;
7985
end
8086

81-
function M.periodicGetElapsedTime(t)
87+
function M.periodicGetElapsedTime(t, show_log)
8288
local elapsed = getTime() - t.startTime;
8389
local elapsedMili = elapsed * 10;
84-
--log("elapsedMili: %d",elapsedMili);
90+
if show_log == true then
91+
log('elapsed: %0.1f/%0.1f sec', elapsed/100, t.durationMili/1000)
92+
end
8593
return elapsedMili;
8694
end
8795

8896
function M.periodicReset(t)
8997
t.startTime = getTime();
90-
log("periodicReset()");
98+
--log("periodicReset()");
9199
M.periodicGetElapsedTime(t)
92100
end
93101

@@ -100,24 +108,23 @@ end
100108
function M.isTelemetryAvailable()
101109
-- select telemetry source
102110
if not M.tele_src_id then
103-
log("select telemetry source")
111+
--log("select telemetry source")
104112
local tele_src = getFieldInfo("RSSI")
105-
if not tele_src then tele_src = getFieldInfo("RxBt") end
106-
if not tele_src then tele_src = getFieldInfo("A1") end
107-
if not tele_src then tele_src = getFieldInfo("A2") end
108113
if not tele_src then tele_src = getFieldInfo("1RSS") end
109114
if not tele_src then tele_src = getFieldInfo("2RSS") end
110115
if not tele_src then tele_src = getFieldInfo("RQly") end
111-
if not tele_src then tele_src = getFieldInfo("TRSS") end
112116
if not tele_src then tele_src = getFieldInfo("VFR%") end
117+
if not tele_src then tele_src = getFieldInfo("TRSS") end
118+
if not tele_src then tele_src = getFieldInfo("RxBt") end
119+
if not tele_src then tele_src = getFieldInfo("A1") end
113120

114121
if tele_src == nil then
115-
log("no telemetry sensor found")
122+
--log("no telemetry sensor found")
116123
M.tele_src_id = nil
117124
M.tele_src_name = "---"
118125
return false
119126
else
120-
log("telemetry sensor found: " .. tele_src.name)
127+
--log("telemetry sensor found: " .. tele_src.name)
121128
M.tele_src_id = tele_src.id
122129
M.tele_src_name = tele_src.name
123130
end
@@ -241,36 +248,103 @@ function M.cleanInvalidCharFromGetFiledInfo(sourceName)
241248
end
242249

243250
------------------------------------------------------------------------------------------------------
251+
function M.getFontSizeRelative(orgFontSize, delta)
252+
for i = 1, #FONT_LIST do
253+
if FONT_LIST[i] == orgFontSize then
254+
local newIndex = i + delta
255+
newIndex = math.min(newIndex, #FONT_LIST)
256+
newIndex = math.max(newIndex, 1)
257+
return FONT_LIST[newIndex]
258+
end
259+
end
260+
return orgFontSize
261+
end
244262

263+
------------------------------------------------------------------------------------------------------
245264
function M.lcdSizeTextFixed(txt, font_size)
246265
local ts_w, ts_h = lcd.sizeText(txt, font_size)
247266

248267
local v_offset = 0
249268
if font_size == FONT_38 then
250-
v_offset = -11
269+
v_offset = -15
251270
elseif font_size == FONT_16 then
252-
v_offset = -5
271+
v_offset = -8
253272
elseif font_size == FONT_12 then
254-
v_offset = -4
273+
v_offset = -6
255274
elseif font_size == FONT_8 then
256-
v_offset = -3
275+
v_offset = -4
257276
elseif font_size == FONT_6 then
258-
v_offset = 0
277+
v_offset = -3
259278
end
260-
return ts_w, ts_h, v_offset
279+
return ts_w, ts_h +2*v_offset, v_offset
261280
end
262281

263282
------------------------------------------------------------------------------------------------------
283+
function M.drawText(x, y, text, font_size, text_color, bg_color)
284+
local ts_w, ts_h, v_offset = M.lcdSizeTextFixed(text, font_size)
285+
lcd.drawRectangle(x, y, ts_w, ts_h, BLUE)
286+
lcd.drawText(x, y + v_offset, text, font_size + text_color)
287+
return ts_w, ts_h, v_offset
288+
end
264289

265-
function M.drawBadgedText(txt, txtX, txtY, font_size, text_color, background_color)
266-
local ts_w, ts_h = lcd.sizeText(txt, font_size)
290+
function M.drawBadgedText(txt, txtX, txtY, font_size, text_color, bg_color)
291+
local ts_w, ts_h, v_offset = M.lcdSizeTextFixed(txt, font_size)
292+
local v_space = 2
293+
local bdg_h = v_space + ts_h + v_space
294+
local r = bdg_h / 2
295+
lcd.drawFilledCircle(txtX , txtY + r, r, bg_color)
296+
lcd.drawFilledCircle(txtX + ts_w , txtY + r, r, bg_color)
297+
lcd.drawFilledRectangle(txtX, txtY , ts_w, bdg_h, bg_color)
298+
299+
lcd.drawText(txtX, txtY + v_offset + v_space, txt, font_size + text_color)
300+
301+
--lcd.drawRectangle(txtX, txtY , ts_w, bdg_h, RED) -- dbg
302+
end
303+
304+
function M.drawBadgedTextCenter(txt, txtX, txtY, font_size, text_color, bg_color)
305+
local ts_w, ts_h, v_offset = M.lcdSizeTextFixed(txt, font_size)
267306
local r = ts_h / 2
268-
lcd.drawFilledCircle(txtX , txtY + r, r, background_color)
269-
lcd.drawFilledCircle(txtX + ts_w , txtY + r, r, background_color)
270-
lcd.drawFilledRectangle(txtX, txtY , ts_w, ts_h, background_color)
271-
lcd.drawText(txtX, txtY, txt, font_size + text_color)
307+
local x = txtX - ts_w/2
308+
local y = txtY - ts_h/2
309+
lcd.drawFilledCircle(x + r * 0.3, y + r, r, bg_color)
310+
lcd.drawFilledCircle(x - r * 0.3 + ts_w , y + r, r, bg_color)
311+
lcd.drawFilledRectangle(x, y, ts_w, ts_h, bg_color)
312+
313+
lcd.drawText(x, y + v_offset, txt, font_size + text_color)
314+
315+
-- dbg
316+
--lcd.drawRectangle(x, y , ts_w, ts_h, RED) -- dbg
317+
--lcd.drawLine(txtX-30, txtY, txtX+30, txtY, SOLID, RED) -- dbg
318+
--lcd.drawLine(txtX, txtY-20, txtX, txtY+20, SOLID, RED) -- dbg
272319
end
273320

321+
------------------------------------------------------------------------------------------------------
322+
-- usage:
323+
--log("bbb----------------------------------------------------------")
324+
--wgt.tools.heap_dump(wgt, 0, 60)
325+
--log("ccc----------------------------------------------------------")
326+
function M.heap_dump(tbl, indent, max_dept)
327+
local spaces = string.rep(" ", indent)
328+
if max_dept == 0 then
329+
log(spaces .. "---- max dept ----")
330+
return
331+
end
332+
max_dept = max_dept -1
333+
indent = indent or 0
334+
335+
for key, value in pairs(tbl) do
336+
if key ~= "_G" then
337+
if type(value) == "table" then
338+
--log(spaces .. key .. " (table) = {")
339+
log(spaces .. key .. " = {")
340+
M.heap_dump(value, indent + 1, max_dept)
341+
log(spaces .. "}")
342+
else
343+
log(spaces .. key .. " = " .. tostring(value))
344+
end
345+
end
346+
end
347+
end
274348
------------------------------------------------------------------------------------------------------
275349

276350
return M

0 commit comments

Comments
 (0)