Skip to content

Commit

Permalink
separate log loaders for ETX and OTX
Browse files Browse the repository at this point in the history
  • Loading branch information
stronnag committed May 18, 2022
1 parent 0be0751 commit 49b2b92
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 163 deletions.
10 changes: 4 additions & 6 deletions src/SCRIPTS/TELEMETRY/iNav.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
65 changes: 33 additions & 32 deletions src/SCRIPTS/TELEMETRY/iNav/load.lua
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions src/SCRIPTS/TELEMETRY/iNav/load_e.lua
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 49b2b92

Please sign in to comment.