Skip to content

Commit

Permalink
SoarETX: Added a number of checks to graph widget (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrickmann authored Mar 21, 2022
1 parent 9d8f7e1 commit 4b2a238
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions sdcard/horus/WIDGETS/SoarETX/1/graph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- SoarETX graph of log data --
-- --
-- Author: Jesper Frickmann --
-- Date: 2022-03-19 --
-- Date: 2022-03-20 --
-- Version: 1.0.0 --
-- --
-- Copyright (C) EdgeTX --
Expand Down Expand Up @@ -121,12 +121,24 @@ local function buildFileTree()
end

local function readLines(fileName)
-- data[2] = min values, data[3] = max values
data = { { }, { FMAX }, { -FMAX } }

if not fileName then
return
end

fileName = "/LOGS/" .. fileName
local fileStat = fstat(fileName)

if not fileStat then
return
end

local l = string.len(DEFAULT_PLOT)
local plotIdx = 2
fileName = "/LOGS/" .. fileName
local fileLen = fstat(fileName).size
local logFile = io.open(fileName, "r")
local logString = io.read(logFile, fileLen)
local logString = io.read(logFile, fileStat.size)
io.close(logFile)
lines = { }

Expand All @@ -136,6 +148,10 @@ local function readLines(fileName)
lines[i] = line
end

if #lines < 3 then
return
end

local headers = { }
i = -1
for field in string.gmatch(lines[1], "[^,]+") do
Expand All @@ -145,9 +161,6 @@ local function readLines(fileName)
end
end

-- data[2] = min values, data[3] = max values
data = { { }, { FMAX }, { -FMAX } }

for i = 2, #headers do
if string.sub(headers[i], 1, l) == DEFAULT_PLOT then
plotIdx = i
Expand Down Expand Up @@ -268,11 +281,16 @@ do

local function refreshTimes()
local date = menu1.items[menu1.selected]
local times = { }
for t in pairs(fileTree[date]) do
times[#times + 1] = t
local times
if fileTree[date] then
times = { }
for t in pairs(fileTree[date]) do
times[#times + 1] = t
end
table.sort(times)
else
times = { "No files" }
end
table.sort(times)
menu2.items = times
menu2.selected = 1
end
Expand Down Expand Up @@ -313,7 +331,7 @@ do
local toggleCursor

local y = TOP
guiGraph.ddPlot = guiGraph.dropDown(BUTTON_X, y, BUTTON_W, HEIGHT, { "1", "2", "3", "4", "5", "6", "7" }, 7, nil, CENTER)
guiGraph.ddPlot = guiGraph.dropDown(BUTTON_X, y, BUTTON_W, HEIGHT, { "1", "2", "3", "4", "5", "6", "- - -" }, 7, nil, CENTER)

y = y + LINE
guiGraph.button(BUTTON_X, y, BUTTON_W, HEIGHT, "New file", function() gui = guiFile end)
Expand Down

0 comments on commit 4b2a238

Please sign in to comment.