Skip to content

Commit

Permalink
Merge pull request #45 from iNavFlight/crsf-replay
Browse files Browse the repository at this point in the history
Update log name usage for EdgeTX
  • Loading branch information
stronnag authored May 18, 2022
2 parents 04fe8e9 + d649d03 commit 1f3e324
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 215 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-rc1"
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 .. "load_" .. (data.etx and "e" or "o") .. 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 .. "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)
Expand Down
49 changes: 0 additions & 49 deletions src/SCRIPTS/TELEMETRY/iNav/load.lua

This file was deleted.

55 changes: 55 additions & 0 deletions src/SCRIPTS/TELEMETRY/iNav/load_e.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- 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

-- 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
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
50 changes: 50 additions & 0 deletions src/SCRIPTS/TELEMETRY/iNav/load_o.lua
Original file line number Diff line number Diff line change
@@ -0,0 +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)
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 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
end
return
Loading

0 comments on commit 1f3e324

Please sign in to comment.