From 0be0751dc8adcbe8a0de91733c900ccc1c04ced7 Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Mon, 16 May 2022 10:58:50 +0100 Subject: [PATCH 1/4] hdop calc for CRSF log replay --- src/SCRIPTS/TELEMETRY/iNav/load.lua | 2 +- src/SCRIPTS/TELEMETRY/iNav/log_c.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SCRIPTS/TELEMETRY/iNav/load.lua b/src/SCRIPTS/TELEMETRY/iNav/load.lua index 57995bbf..07369e26 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/load.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/load.lua @@ -46,4 +46,4 @@ for days = 1, 15 do end end -return \ No newline at end of file +return diff --git a/src/SCRIPTS/TELEMETRY/iNav/log_c.lua b/src/SCRIPTS/TELEMETRY/iNav/log_c.lua index a0ef9cd6..b5fb8de4 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/log_c.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/log_c.lua @@ -29,7 +29,7 @@ local function fake(data, config, record, label, toNum) data.mode = 5 data.satellites = toNum(record[label.sats]) --Fake HDOP based on satellite lock count and assume GPS fix when there's at least 6 satellites - data.satellites = data.satellites + (math.floor(math.min(data.satellites + 10, 25) * 0.36 + 0.5) * 100) + (data.satellites >= 6 and 3000 or 0) + data.hdop = data.satellites + (math.floor(math.min(data.satellites + 10, 25) * 0.36 + 0.5) * 100) + (data.satellites >= 6 and 3000 or 0) end -return fake \ No newline at end of file +return fake From 49b2b921968263506681913c7356383a9816bd05 Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Wed, 18 May 2022 11:48:28 +0100 Subject: [PATCH 2/4] separate log loaders for ETX and OTX --- src/SCRIPTS/TELEMETRY/iNav.lua | 10 +- src/SCRIPTS/TELEMETRY/iNav/load.lua | 65 +++---- src/SCRIPTS/TELEMETRY/iNav/load_e.lua | 54 ++++++ src/SCRIPTS/TELEMETRY/iNav/log.lua | 247 +++++++++++++------------- src/SCRIPTS/TELEMETRY/iNav/menu.lua | 2 +- 5 files changed, 215 insertions(+), 163 deletions(-) create mode 100644 src/SCRIPTS/TELEMETRY/iNav/load_e.lua diff --git a/src/SCRIPTS/TELEMETRY/iNav.lua b/src/SCRIPTS/TELEMETRY/iNav.lua index e49d5ed2..ca54f222 100644 --- a/src/SCRIPTS/TELEMETRY/iNav.lua +++ b/src/SCRIPTS/TELEMETRY/iNav.lua @@ -2,7 +2,7 @@ -- Docs: https://github.com/iNavFlight/OpenTX-Telemetry-Widget local zone, options = ... -local VERSION = "2.1.0" +local VERSION = "2.1.1-a1" local FILE_PATH = "/SCRIPTS/TELEMETRY/iNav/" local SMLCD = LCD_W < 212 local HORUS = LCD_W >= 480 or LCD_H >= 480 @@ -20,9 +20,7 @@ if string.sub(r, 0, 4) == "nv14" or string.sub(r, 0, 4) == "NV14" then EVT_EXIT_BREAK = 5 --516 end ---[[ if string.sub(r, -4) == "simu" then - env = "btd" - end ]] +if string.sub(r, -4) == "simu" then env = "btd" end local config = loadScript(FILE_PATH .. "config" .. ext, env)(SMLCD) collectgarbage() @@ -35,7 +33,7 @@ collectgarbage() data.etx = osname ~= nil and osname == "EdgeTX" -loadScript(FILE_PATH .. "load" .. ext, env)(config, data, FILE_PATH) +loadScript(FILE_PATH .. (data.etx and "load_e" or "load") .. ext, env)(config, data, FILE_PATH) collectgarbage() --[[ Simulator language testing @@ -412,7 +410,7 @@ function inav.background() -- Initialize variables on flight reset (uses timer3) tmp = model.getTimer(2) if tmp.value == 0 then - loadScript(FILE_PATH .. "load" .. ext, env)(config, data, FILE_PATH) + loadScript(FILE_PATH .. (data.etx and "load_e" or "load") .. ext, env)(config, data, FILE_PATH) loadScript(FILE_PATH .. "reset" .. ext, env)(data) tmp.value = 3600 model.setTimer(2, tmp) diff --git a/src/SCRIPTS/TELEMETRY/iNav/load.lua b/src/SCRIPTS/TELEMETRY/iNav/load.lua index 07369e26..cf8b7dc7 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/load.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/load.lua @@ -1,49 +1,50 @@ +-- OpenTX log loader + local config, data, FILE_PATH = ... -- Load config for model fh = io.open(FILE_PATH .. "cfg/" .. model.getInfo().name .. ".dat") if fh ~= nil then - for i = 1, #config do - local tmp = io.read(fh, config[i].c) - if tmp ~= "" then - config[i].v = config[i].d == nil and math.min(tonumber(tmp), config[i].x == nil and 1 or config[i].x) or tmp * 0.1 - end - end - io.close(fh) + for i = 1, #config do + local tmp = io.read(fh, config[i].c) + if tmp ~= "" then + config[i].v = config[i].d == nil and math.min(tonumber(tmp), config[i].x == nil and 1 or config[i].x) or tmp * 0.1 + end + end + io.close(fh) end -- Look for language override fh = io.open(FILE_PATH .. "cfg/lang.dat") if fh ~= nil then - local tmp = io.read(fh, 2) - io.close(fh) - data.lang = tmp - data.voice = tmp + local tmp = io.read(fh, 2) + io.close(fh) + data.lang = tmp + data.voice = tmp end local log = getDateTime() -local path = "/LOGS/" .. string.gsub(model.getInfo().name, " ", "_") .. "-20" -config[34].x = -1 +config[34].x = -1 +local path = "/LOGS/" .. string.gsub(model.getInfo().name, " ", "_") .. "-20" for days = 1, 15 do - local logDate = string.sub(log.year, 3) .. "-" .. string.sub("0" .. log.mon, -2) .. "-" .. string.sub("0" .. log.day, -2) - local fh = io.open(path .. logDate .. ".csv") - if fh ~= nil then - io.close(fh) - config[34].x = config[34].x + 1 - config[34].l[config[34].x] = logDate - collectgarbage() - if config[34].x == 5 then break end - end - log.day = log.day - 1 - if log.day == 0 then - log.day = 31 - log.mon = log.mon - 1 - if log.mon == 0 then - log.mon = 12 - log.year = log.year - 1 - end - end + local logDate = string.sub(log.year, 3) .. "-" .. string.sub("0" .. log.mon, -2) .. "-" .. string.sub("0" .. log.day, -2) + local fh = io.open(path .. logDate .. ".csv") + if fh ~= nil then + io.close(fh) + config[34].x = config[34].x + 1 + config[34].l[config[34].x] = logDate + collectgarbage() + if config[34].x == 5 then break end + end + log.day = log.day - 1 + if log.day == 0 then + log.day = 31 + log.mon = log.mon - 1 + if log.mon == 0 then + log.mon = 12 + log.year = log.year - 1 + end + end end - return diff --git a/src/SCRIPTS/TELEMETRY/iNav/load_e.lua b/src/SCRIPTS/TELEMETRY/iNav/load_e.lua new file mode 100644 index 00000000..9eff5275 --- /dev/null +++ b/src/SCRIPTS/TELEMETRY/iNav/load_e.lua @@ -0,0 +1,54 @@ +-- Log loader for EdgeTX + +local config, data, FILE_PATH = ... + +-- Load config for model +fh = io.open(FILE_PATH .. "cfg/" .. model.getInfo().name .. ".dat") +if fh ~= nil then + for i = 1, #config do + local tmp = io.read(fh, config[i].c) + if tmp ~= "" then + config[i].v = config[i].d == nil and math.min(tonumber(tmp), config[i].x == nil and 1 or config[i].x) or tmp * 0.1 + end + end + io.close(fh) +end + +-- Look for language override +fh = io.open(FILE_PATH .. "cfg/lang.dat") +if fh ~= nil then + local tmp = io.read(fh, 2) + io.close(fh) + data.lang = tmp + data.voice = tmp +end + +local log = getDateTime() +config[34].x = -1 + +local mbase = string.gsub(model.getInfo().name, " ", ".") .. "-20" +local mblen = string.len(mbase) +local tempf = {} +local tempi = 0 +for fname in dir("/LOGS") do + if string.find(fname, mbase, 1, true) == 1 then + local dstr = string.sub(fname, mblen+1, -5) + local lyr = tonumber(string.sub(dstr, 1, 2))+2000 + local lmo = tonumber(string.sub(dstr, 4, 5)) + local lda = tonumber(string.sub(dstr, 7, 8)) + tdiff = 366*(log.year-lyr) + (log.mon-lmo)*31 + log.day - lda + if tdiff < 16 then + tempi = tempi + 1 + tempf[tempi] = dstr + end + end +end +table.sort( tempf ) +for i = #tempf, 1, -1 do + config[34].x = config[34].x + 1 + config[34].l[config[34].x] = tempf[i] + collectgarbage() + if config[34].x == 5 then break end +end +collectgarbage() +return diff --git a/src/SCRIPTS/TELEMETRY/iNav/log.lua b/src/SCRIPTS/TELEMETRY/iNav/log.lua index 657b0517..0888e9d9 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/log.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/log.lua @@ -30,135 +30,134 @@ local function parseLine(line) end local function playLog(data, config, distCalc, date) + local gpsTemp = nil + local replc = data.etx and "." or "_" + if logfh == nil then + logfh = io.open("/LOGS/" .. string.gsub(model.getInfo().name, " ", replc) .. "-20" .. date .. ".csv") + fake = loadScript(FILE_PATH .. "log_" .. (data.crsf and "c" or "s") .. ".luac", env)() + data.showMax = false + seek = 0 + end + if logfh ~= nil then + local pos = string.find(raw, "\n") + local read = nil + local ele = getValue(ele_id) * 0.005 + local ail = getValue(ail_id) + local speed = 0 + if ail > 940 and seek > 2 then + -- Pause + pause = true + start = nil + elseif math.abs(ele) > 1 or (start ~= nil and time ~= start and (getTime() - starti) - (time - start) * 100 > 10) then + -- Seek forward/back + if not pause or ele < 0 then + speed = ele > 0 and math.floor(ele) or math.ceil(ele) - 2 + seek = math.max(seek + speed, 0) + io.seek(logfh, seek * 400) + raw = "" + pos = nil + start = nil + pause = false + while pos == nil and read ~= "" do + read = io.read(logfh, 400) + raw = raw .. read + pos = string.find(raw, "\n") + seek = seek + 1 + end + if pos ~= nil then + raw = string.sub(raw, pos + 1) + pos = string.find(raw, "\n") + end + end + elseif ail < -940 then + -- Exit playback + io.close(logfh) + data.doLogs = false + return 0 + elseif pause and ail <= 940 then + -- Resume + pause = false + elseif timel ~= nil and time - timel > 2 then + -- Jump to next log segment + start = nil + end - local gpsTemp = nil + -- Load next record + if not pause and (start == nil or speed ~= 0 or (time - start) * 100 < getTime() - starti) then + while pos == nil and read ~= "" do + read = io.read(logfh, 400) + raw = raw .. read + pos = string.find(raw, "\n") + end + if read == "" then + -- End of file + pause = true + else + -- Parse record + seek = seek + 1 + if pos == nil then + pos = string.len(raw) + end + local ln = string.sub(raw, 0, pos) + raw = string.sub(raw, pos + 1) + record = parseLine(ln) + end + end - if logfh == nil then - logfh = io.open("/LOGS/" .. string.gsub(model.getInfo().name, " ", "_") .. "-20" .. date .. ".csv") - fake = loadScript(FILE_PATH .. "log_" .. (data.crsf and "c" or "s") .. ".luac", env)() - data.showMax = false - seek = 0 - end - if logfh ~= nil then - local pos = string.find(raw, "\n") - local read = nil - local ele = getValue(ele_id) * 0.005 - local ail = getValue(ail_id) - local speed = 0 - if ail > 940 and seek > 2 then - -- Pause - pause = true - start = nil - elseif math.abs(ele) > 1 or (start ~= nil and time ~= start and (getTime() - starti) - (time - start) * 100 > 10) then - -- Seek forward/back - if not pause or ele < 0 then - speed = ele > 0 and math.floor(ele) or math.ceil(ele) - 2 - seek = math.max(seek + speed, 0) - io.seek(logfh, seek * 400) - raw = "" - pos = nil - start = nil - pause = false - while pos == nil and read ~= "" do - read = io.read(logfh, 400) - raw = raw .. read - pos = string.find(raw, "\n") - seek = seek + 1 - end - if pos ~= nil then - raw = string.sub(raw, pos + 1) - pos = string.find(raw, "\n") - end - end - elseif ail < -940 then - -- Exit playback - io.close(logfh) - data.doLogs = false - return 0 - elseif pause and ail <= 940 then - -- Resume - pause = false - elseif timel ~= nil and time - timel > 2 then - -- Jump to next log segment - start = nil - end - - -- Load next record - if not pause and (start == nil or speed ~= 0 or (time - start) * 100 < getTime() - starti) then - while pos == nil and read ~= "" do - read = io.read(logfh, 400) - raw = raw .. read - pos = string.find(raw, "\n") - end - if read == "" then - -- End of file - pause = true - else - -- Parse record - seek = seek + 1 - if pos == nil then - pos = string.len(raw) - end - local ln = string.sub(raw, 0, pos) - raw = string.sub(raw, pos + 1) - record = parseLine(ln) - end - end + -- Define column labels + if label == nil then + label = {} + for i = 0, #record do + local unit = string.find(record[i], "%(") + if unit ~= nil then + label[string.lower(string.sub(record[i], 0, unit - 1))] = i + else + if record[i] == "Rud" then break end + label[string.lower(record[i])] = i + end + end + else + -- Fake telemetry specific to Crossfire or S.Port + fake(data, config, record, label, toNum) - -- Define column labels - if label == nil then - label = {} - for i = 0, #record do - local unit = string.find(record[i], "%(") - if unit ~= nil then - label[string.lower(string.sub(record[i], 0, unit - 1))] = i - else - if record[i] == "Rud" then break end - label[string.lower(record[i])] = i - end - end - else - -- Fake telemetry specific to Crossfire or S.Port - fake(data, config, record, label, toNum) - - -- Sync playback to clock - timel = time - time = toNum(string.sub(record[label.time], 1, 2)) * 3600 + toNum(string.sub(record[label.time], 4, 5)) * 60 + toNum(string.sub(record[label.time], 7)) - if start == nil then - start = time - starti = getTime() - end + -- Sync playback to clock + timel = time + time = toNum(string.sub(record[label.time], 1, 2)) * 3600 + toNum(string.sub(record[label.time], 4, 5)) * 60 + toNum(string.sub(record[label.time], 7)) + if start == nil then + start = time + starti = getTime() + end - -- Fake telemetry that's similar on Crossfire and S.Port - data.time = string.sub(record[label.time], 0, 8) - data.altitude = toNum(record[label.alt]) - if data.alt_id == -1 and data.gpsAltBase and data.gpsFix and data.satellites > 3000 then - data.altitude = data.gpsAlt - data.gpsAltBase - end - data.speed = toNum(record[label.gspd]) - data.vspeed = toNum(record[label.vspd]) - if data.showCurr then - data.current = toNum(record[label.curr]) - end - if data.a4_id > -1 then - data.cell = toNum(record[label.a4]) - end - if record[label.gps] ~= nil then - pos = string.find(record[label.gps], " ") - if pos ~= nil then - gpsTemp = { - lat = toNum(string.sub(record[label.gps], 0, pos - 1)), - lon = toNum(string.sub(record[label.gps], pos + 1)) - } - end - end - data.telem = true - end - else - data.doLogs = false - end + -- Fake telemetry that's similar on Crossfire and S.Port + data.time = string.sub(record[label.time], 0, 8) + data.altitude = toNum(record[label.alt]) + if data.alt_id == -1 and data.gpsAltBase and data.gpsFix and data.satellites > 3000 then + data.altitude = data.gpsAlt - data.gpsAltBase + end + data.speed = toNum(record[label.gspd]) + data.vspeed = toNum(record[label.vspd]) + if data.showCurr then + data.current = toNum(record[label.curr]) + end + if data.a4_id > -1 then + data.cell = toNum(record[label.a4]) + end + if record[label.gps] ~= nil then + pos = string.find(record[label.gps], " ") + if pos ~= nil then + gpsTemp = { + lat = toNum(string.sub(record[label.gps], 0, pos - 1)), + lon = toNum(string.sub(record[label.gps], pos + 1)) + } + end + end + data.telem = true + end + else + data.doLogs = false + end - return gpsTemp + return gpsTemp end return playLog diff --git a/src/SCRIPTS/TELEMETRY/iNav/menu.lua b/src/SCRIPTS/TELEMETRY/iNav/menu.lua index 60dd6cc1..0c5a6547 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/menu.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/menu.lua @@ -239,7 +239,7 @@ local function view(data, config, units, lang, event, gpsDegMin, getTelemetryId, if not config2[z].l then text(CONFIG_X + RSIDE, y, config[z].v, data.set_flags(FONT + tmp, tmpf)) else - text(z == 16 and LCD_W - CONFIG_X or CONFIG_X + RSIDE, y, config2[z].l[config[z].v] .. ((config2[z].a == nil or config[z].v == 0) and "" or config2[z].a), data.set_flags(FONT + tmp + (z == 16 and RIGHT or 0), tmpf)) + text((z == 16 or z == 34) and LCD_W - CONFIG_X or CONFIG_X + RSIDE, y, config2[z].l[config[z].v] .. ((config2[z].a == nil or config[z].v == 0) and "" or config2[z].a), data.set_flags(FONT + tmp + ((z == 16 or z == 34) and RIGHT or 0), tmpf)) end end config2[z] = nil From d70ffa103a340325430863893f1f39b14948af33 Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Wed, 18 May 2022 12:39:37 +0100 Subject: [PATCH 3/4] explicitly separate log loaders for ETX and OTX --- src/SCRIPTS/TELEMETRY/iNav.lua | 4 ++-- src/SCRIPTS/TELEMETRY/iNav/{load.lua => load_o.lua} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename src/SCRIPTS/TELEMETRY/iNav/{load.lua => load_o.lua} (100%) diff --git a/src/SCRIPTS/TELEMETRY/iNav.lua b/src/SCRIPTS/TELEMETRY/iNav.lua index ca54f222..839f7e36 100644 --- a/src/SCRIPTS/TELEMETRY/iNav.lua +++ b/src/SCRIPTS/TELEMETRY/iNav.lua @@ -33,7 +33,7 @@ collectgarbage() data.etx = osname ~= nil and osname == "EdgeTX" -loadScript(FILE_PATH .. (data.etx and "load_e" or "load") .. ext, env)(config, data, FILE_PATH) +loadScript(FILE_PATH .. "load_" .. (data.etx and "e" or "o") .. ext, env)(config, data, FILE_PATH) collectgarbage() --[[ Simulator language testing @@ -410,7 +410,7 @@ function inav.background() -- Initialize variables on flight reset (uses timer3) tmp = model.getTimer(2) if tmp.value == 0 then - loadScript(FILE_PATH .. (data.etx and "load_e" or "load") .. ext, env)(config, data, FILE_PATH) + loadScript(FILE_PATH .. "load_" .. (data.etx and "e" or "o") .. ext, env)(config, data, FILE_PATH) loadScript(FILE_PATH .. "reset" .. ext, env)(data) tmp.value = 3600 model.setTimer(2, tmp) diff --git a/src/SCRIPTS/TELEMETRY/iNav/load.lua b/src/SCRIPTS/TELEMETRY/iNav/load_o.lua similarity index 100% rename from src/SCRIPTS/TELEMETRY/iNav/load.lua rename to src/SCRIPTS/TELEMETRY/iNav/load_o.lua From d649d034c944374bf5770be1a849c2fafd73c7cc Mon Sep 17 00:00:00 2001 From: Jonathan Hudson Date: Wed, 18 May 2022 20:02:49 +0100 Subject: [PATCH 4/4] update log name conventions for EdgeTX --- src/SCRIPTS/TELEMETRY/iNav.lua | 2 +- src/SCRIPTS/TELEMETRY/iNav/load_e.lua | 3 +- src/SCRIPTS/TELEMETRY/iNav/log.lua | 7 ++-- src/SCRIPTS/TELEMETRY/iNav/log_c.lua | 56 +++++++++++++-------------- src/SCRIPTS/TELEMETRY/iNav/log_s.lua | 2 +- src/SCRIPTS/TELEMETRY/iNav/menu.lua | 5 --- 6 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/SCRIPTS/TELEMETRY/iNav.lua b/src/SCRIPTS/TELEMETRY/iNav.lua index 839f7e36..0337f846 100644 --- a/src/SCRIPTS/TELEMETRY/iNav.lua +++ b/src/SCRIPTS/TELEMETRY/iNav.lua @@ -2,7 +2,7 @@ -- Docs: https://github.com/iNavFlight/OpenTX-Telemetry-Widget local zone, options = ... -local VERSION = "2.1.1-a1" +local VERSION = "2.1.1-rc1" local FILE_PATH = "/SCRIPTS/TELEMETRY/iNav/" local SMLCD = LCD_W < 212 local HORUS = LCD_W >= 480 or LCD_H >= 480 diff --git a/src/SCRIPTS/TELEMETRY/iNav/load_e.lua b/src/SCRIPTS/TELEMETRY/iNav/load_e.lua index 9eff5275..ebc6cb94 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/load_e.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/load_e.lua @@ -26,7 +26,8 @@ end local log = getDateTime() config[34].x = -1 -local mbase = string.gsub(model.getInfo().name, " ", ".") .. "-20" +-- From EdgeTX 2.7.1 (at least) we don't need to translate spaces +local mbase = model.getInfo().name .. "-20" local mblen = string.len(mbase) local tempf = {} local tempi = 0 diff --git a/src/SCRIPTS/TELEMETRY/iNav/log.lua b/src/SCRIPTS/TELEMETRY/iNav/log.lua index 0888e9d9..7ce6b448 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/log.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/log.lua @@ -31,10 +31,9 @@ end local function playLog(data, config, distCalc, date) local gpsTemp = nil - local replc = data.etx and "." or "_" if logfh == nil then - logfh = io.open("/LOGS/" .. string.gsub(model.getInfo().name, " ", replc) .. "-20" .. date .. ".csv") - fake = loadScript(FILE_PATH .. "log_" .. (data.crsf and "c" or "s") .. ".luac", env)() + local mbase = data.etx and model.getInfo().name or string.gsub(model.getInfo().name, " ", "_") + logfh = io.open("/LOGS/" .. mbase .. "-20" .. date .. ".csv") data.showMax = false seek = 0 end @@ -115,7 +114,9 @@ local function playLog(data, config, distCalc, date) if record[i] == "Rud" then break end label[string.lower(record[i])] = i end + if record[i] == "1RSS(dB)" then data.crsf = true end end + fake = loadScript(FILE_PATH .. "log_" .. (data.crsf and "c" or "s") .. ".luac", env)() else -- Fake telemetry specific to Crossfire or S.Port fake(data, config, record, label, toNum) diff --git a/src/SCRIPTS/TELEMETRY/iNav/log_c.lua b/src/SCRIPTS/TELEMETRY/iNav/log_c.lua index b5fb8de4..a584e4f4 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/log_c.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/log_c.lua @@ -2,34 +2,34 @@ --Date,Time,FM,1RSS(dB),2RSS(dB),RQly(%),RSNR(dB),RFMD,TPWR(mW),TRSS(dB),TQly(%),TSNR(dB),RxBt(V),Curr(A),Capa(mAh),GPS,GSpd(mph),Hdg(@),Alt(ft),Sats,Ptch(rad),Roll(rad),Yaw(rad),Rud,Ele,Thr,Ail,S1,6P,S2,LS,RS,SA,SB,SC,SD,SE,SF,SG,SH,LSW,TxBat(V) local function fake(data, config, record, label, toNum) - data.rssi = toNum(record[label.rqly]) - data.tpwr = toNum(record[label.tpwr]) - data.rfmd = toNum(record[label.rfmd]) - data.pitch = math.deg(toNum(record[label.ptch])) * 10 - data.roll = math.deg(toNum(record[label.roll])) * 10 - data.batt = toNum(record[label.rxbt]) - if data.lang == "fr" and data.batt == 0 then data.batt = toNum(record[label.btrx]) end - -- Overflow shenanigans - local tmp = toNum(record[label.yaw]) - data.heading = math.deg(tmp < 0 and tmp + 6.55 or tmp) - if data.fpv_id > -1 then - tmp = toNum(record[label.hdg]) - data.fpv = (tmp < 0 and tmp + 65.54 or tmp) * 10 - end - --[[ Replacement code once the Crossfire/OpenTX Yaw/Hdg int overflow shenanigans are corrected - data.heading = math.deg(toNum(record[label.yaw])) - if data.fpv_id > -1 then data.fpv =toNum(record[label.hdg]) * 10 end - ]] - data.fuel = toNum(record[label.capa]) - data.fuelRaw = data.fuel - if data.showFuel and config[23].v == 0 then - data.fuel = math.max(math.min(math.floor((1 - (data.fuel) / config[27].v) * 100 + 0.5), 100), 0) - end - -- Don't know the flight mode with Crossfire, so assume armed and ACRO - data.mode = 5 - data.satellites = toNum(record[label.sats]) - --Fake HDOP based on satellite lock count and assume GPS fix when there's at least 6 satellites - data.hdop = data.satellites + (math.floor(math.min(data.satellites + 10, 25) * 0.36 + 0.5) * 100) + (data.satellites >= 6 and 3000 or 0) + data.rssi = toNum(record[label.rqly]) + data.tpwr = toNum(record[label.tpwr]) + data.rfmd = toNum(record[label.rfmd]) + data.pitch = math.deg(toNum(record[label.ptch])) * 10 + data.roll = math.deg(toNum(record[label.roll])) * 10 + data.batt = toNum(record[label.rxbt]) + if data.lang == "fr" and data.batt == 0 then data.batt = toNum(record[label.btrx]) end + -- Overflow shenanigans + local tmp = toNum(record[label.yaw]) + data.heading = math.deg(tmp < 0 and tmp + 6.55 or tmp) + if data.fpv_id > -1 then + tmp = toNum(record[label.hdg]) + data.fpv = (tmp < 0 and tmp + 65.54 or tmp) * 10 + end + --[[ Replacement code once the Crossfire/OpenTX Yaw/Hdg int overflow shenanigans are corrected + data.heading = math.deg(toNum(record[label.yaw])) + if data.fpv_id > -1 then data.fpv =toNum(record[label.hdg]) * 10 end + ]] + data.fuel = toNum(record[label.capa]) + data.fuelRaw = data.fuel + if data.showFuel and config[23].v == 0 then + data.fuel = math.max(math.min(math.floor((1 - (data.fuel) / config[27].v) * 100 + 0.5), 100), 0) + end + -- Don't know the flight mode with Crossfire, so assume armed and ACRO + data.mode = 5 + data.satellites = toNum(record[label.sats]) + --Fake HDOP based on satellite lock count and assume GPS fix when there's at least 6 satellites + data.satellites = data.satellites + (math.floor(math.min(data.satellites + 10, 25) * 0.36 + 0.5) * 100) + (data.satellites >= 6 and 3000 or 0) end return fake diff --git a/src/SCRIPTS/TELEMETRY/iNav/log_s.lua b/src/SCRIPTS/TELEMETRY/iNav/log_s.lua index d8a66ae7..120edb2e 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/log_s.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/log_s.lua @@ -22,4 +22,4 @@ local function fake(data, config, record, label, toNum) data.batt = toNum(record[label.vfas]) end -return fake \ No newline at end of file +return fake diff --git a/src/SCRIPTS/TELEMETRY/iNav/menu.lua b/src/SCRIPTS/TELEMETRY/iNav/menu.lua index 0c5a6547..b03c09ec 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/menu.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/menu.lua @@ -136,11 +136,6 @@ local function view(data, config, units, lang, event, gpsDegMin, getTelemetryId, ]] -- Select config option if data.configSelect == 0 then ---[[ - if event ~= 0 then - print("DBG EVT="..event.." VNEXT="..EVT_VIRTUAL_NEXT.." VPREV="..EVT_VIRTUAL_PREV) - end -]] if event == EVT_VIRTUAL_NEXT then -- Next option data.configStatus = data.configStatus == #config and 1 or data.configStatus + 1 data.configTop = data.configStatus > math.min(#config, data.configTop + ROWS) and data.configTop + 1 or (data.configStatus == 1 and 1 or data.configTop)