Skip to content

Commit

Permalink
flights: fix bug in heli mode, debug view now widget size dependent (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
offer-shmuely authored Mar 10, 2024
1 parent a32e341 commit 30b4440
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 82 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified sdcard/c480x272/WIDGETS/Flights/flight_logged.wav
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions sdcard/c480x272/WIDGETS/Flights/lib_flights_history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function M.writeHeaderIfNeeded()
io.close(hFile)
end

function M.addFlightLog(duration, flight_count)
function M.addFlightLog(flight_start_date_time, duration, flight_count)
M.m_log.info("addFlightLog(%s, %s)", duration, flight_count)

M.writeHeaderIfNeeded()
Expand All @@ -65,8 +65,8 @@ function M.addFlightLog(duration, flight_count)
end

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

-- model name
Expand Down
122 changes: 98 additions & 24 deletions sdcard/c480x272/WIDGETS/Flights/lib_widget_tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ local FONT_12 = MIDSIZE -- 12px
local FONT_8 = 0 -- Default 8px
local FONT_6 = SMLSIZE -- 6px

local FONT_LIST = {FONT_6, FONT_8, FONT_12, FONT_16, FONT_38}

---------------------------------------------------------------------------------------------------
local function log(fmt, ...)
m_log.info(fmt, ...)
Expand Down Expand Up @@ -46,7 +48,8 @@ function M.unitIdToString(unitId)
return txtUnit
end

return "-#-"
--return "-#-"
return ""
end

---------------------------------------------------------------------------------------------------
Expand All @@ -63,31 +66,36 @@ function M.periodicStart(t, durationMili)
t.durationMili = durationMili;
end

function M.periodicHasPassed(t)
function M.periodicHasPassed(t, show_log)
-- not started yet
if (t.durationMili <= 0) then
return false;
end

local elapsed = getTime() - t.startTime;
--log('elapsed: %d (t.durationMili: %d)', elapsed, t.durationMili)
if show_log == true then
log('elapsed: %0.1f/%0.1f sec', elapsed/100, t.durationMili/1000)
end
local elapsedMili = elapsed * 10;
if (elapsedMili < t.durationMili) then
return false;
end
return true;
end

function M.periodicGetElapsedTime(t)
function M.periodicGetElapsedTime(t, show_log)
local elapsed = getTime() - t.startTime;
local elapsedMili = elapsed * 10;
--log("elapsedMili: %d",elapsedMili);
if show_log == true then
log('elapsed: %0.1f/%0.1f sec', elapsed/100, t.durationMili/1000)
end
return elapsedMili;
end

function M.periodicReset(t)
t.startTime = getTime();
log("periodicReset()");
--log("periodicReset()");
M.periodicGetElapsedTime(t)
end

Expand All @@ -100,24 +108,23 @@ end
function M.isTelemetryAvailable()
-- select telemetry source
if not M.tele_src_id then
log("select telemetry source")
--log("select telemetry source")
local tele_src = getFieldInfo("RSSI")
if not tele_src then tele_src = getFieldInfo("RxBt") end
if not tele_src then tele_src = getFieldInfo("A1") end
if not tele_src then tele_src = getFieldInfo("A2") end
if not tele_src then tele_src = getFieldInfo("1RSS") end
if not tele_src then tele_src = getFieldInfo("2RSS") end
if not tele_src then tele_src = getFieldInfo("RQly") end
if not tele_src then tele_src = getFieldInfo("TRSS") end
if not tele_src then tele_src = getFieldInfo("VFR%") end
if not tele_src then tele_src = getFieldInfo("TRSS") end
if not tele_src then tele_src = getFieldInfo("RxBt") end
if not tele_src then tele_src = getFieldInfo("A1") end

if tele_src == nil then
log("no telemetry sensor found")
--log("no telemetry sensor found")
M.tele_src_id = nil
M.tele_src_name = "---"
return false
else
log("telemetry sensor found: " .. tele_src.name)
--log("telemetry sensor found: " .. tele_src.name)
M.tele_src_id = tele_src.id
M.tele_src_name = tele_src.name
end
Expand Down Expand Up @@ -241,36 +248,103 @@ function M.cleanInvalidCharFromGetFiledInfo(sourceName)
end

------------------------------------------------------------------------------------------------------
function M.getFontSizeRelative(orgFontSize, delta)
for i = 1, #FONT_LIST do
if FONT_LIST[i] == orgFontSize then
local newIndex = i + delta
newIndex = math.min(newIndex, #FONT_LIST)
newIndex = math.max(newIndex, 1)
return FONT_LIST[newIndex]
end
end
return orgFontSize
end

------------------------------------------------------------------------------------------------------
function M.lcdSizeTextFixed(txt, font_size)
local ts_w, ts_h = lcd.sizeText(txt, font_size)

local v_offset = 0
if font_size == FONT_38 then
v_offset = -11
v_offset = -15
elseif font_size == FONT_16 then
v_offset = -5
v_offset = -8
elseif font_size == FONT_12 then
v_offset = -4
v_offset = -6
elseif font_size == FONT_8 then
v_offset = -3
v_offset = -4
elseif font_size == FONT_6 then
v_offset = 0
v_offset = -3
end
return ts_w, ts_h, v_offset
return ts_w, ts_h +2*v_offset, v_offset
end

------------------------------------------------------------------------------------------------------
function M.drawText(x, y, text, font_size, text_color, bg_color)
local ts_w, ts_h, v_offset = M.lcdSizeTextFixed(text, font_size)
lcd.drawRectangle(x, y, ts_w, ts_h, BLUE)
lcd.drawText(x, y + v_offset, text, font_size + text_color)
return ts_w, ts_h, v_offset
end

function M.drawBadgedText(txt, txtX, txtY, font_size, text_color, background_color)
local ts_w, ts_h = lcd.sizeText(txt, font_size)
function M.drawBadgedText(txt, txtX, txtY, font_size, text_color, bg_color)
local ts_w, ts_h, v_offset = M.lcdSizeTextFixed(txt, font_size)
local v_space = 2
local bdg_h = v_space + ts_h + v_space
local r = bdg_h / 2
lcd.drawFilledCircle(txtX , txtY + r, r, bg_color)
lcd.drawFilledCircle(txtX + ts_w , txtY + r, r, bg_color)
lcd.drawFilledRectangle(txtX, txtY , ts_w, bdg_h, bg_color)

lcd.drawText(txtX, txtY + v_offset + v_space, txt, font_size + text_color)

--lcd.drawRectangle(txtX, txtY , ts_w, bdg_h, RED) -- dbg
end

function M.drawBadgedTextCenter(txt, txtX, txtY, font_size, text_color, bg_color)
local ts_w, ts_h, v_offset = M.lcdSizeTextFixed(txt, font_size)
local r = ts_h / 2
lcd.drawFilledCircle(txtX , txtY + r, r, background_color)
lcd.drawFilledCircle(txtX + ts_w , txtY + r, r, background_color)
lcd.drawFilledRectangle(txtX, txtY , ts_w, ts_h, background_color)
lcd.drawText(txtX, txtY, txt, font_size + text_color)
local x = txtX - ts_w/2
local y = txtY - ts_h/2
lcd.drawFilledCircle(x + r * 0.3, y + r, r, bg_color)
lcd.drawFilledCircle(x - r * 0.3 + ts_w , y + r, r, bg_color)
lcd.drawFilledRectangle(x, y, ts_w, ts_h, bg_color)

lcd.drawText(x, y + v_offset, txt, font_size + text_color)

-- dbg
--lcd.drawRectangle(x, y , ts_w, ts_h, RED) -- dbg
--lcd.drawLine(txtX-30, txtY, txtX+30, txtY, SOLID, RED) -- dbg
--lcd.drawLine(txtX, txtY-20, txtX, txtY+20, SOLID, RED) -- dbg
end

------------------------------------------------------------------------------------------------------
-- usage:
--log("bbb----------------------------------------------------------")
--wgt.tools.heap_dump(wgt, 0, 60)
--log("ccc----------------------------------------------------------")
function M.heap_dump(tbl, indent, max_dept)
local spaces = string.rep(" ", indent)
if max_dept == 0 then
log(spaces .. "---- max dept ----")
return
end
max_dept = max_dept -1
indent = indent or 0

for key, value in pairs(tbl) do
if key ~= "_G" then
if type(value) == "table" then
--log(spaces .. key .. " (table) = {")
log(spaces .. key .. " = {")
M.heap_dump(value, indent + 1, max_dept)
log(spaces .. "}")
else
log(spaces .. key .. " = " .. tostring(value))
end
end
end
end
------------------------------------------------------------------------------------------------------

return M
Loading

0 comments on commit 30b4440

Please sign in to comment.