Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model presets #119

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0b2f353
new Rotary Gauge widget
offer-shmuely-cognyte Apr 26, 2022
cbf4c49
Rotary Gauge widget: less ticks on small size
offer-shmuely-cognyte May 1, 2022
4b6b883
new Rotary Gauge widget
offer-shmuely-cognyte May 1, 2022
4da81b3
new Rotary Gauge widget
offer-shmuely-cognyte May 6, 2022
74724ee
Merge branch 'EdgeTX:master' into master
offer-shmuely May 12, 2022
de3a49d
Merge branch 'EdgeTX:master' into master
offer-shmuely Jul 9, 2022
556da6c
Merge branch 'EdgeTX:master' into master
offer-shmuely Jul 24, 2022
371c347
Merge branch 'EdgeTX:master' into master
offer-shmuely Aug 21, 2022
6810b35
Merge branch 'EdgeTX:master' into master
offer-shmuely Sep 12, 2022
e4c197e
Merge branch 'EdgeTX:master' into master
offer-shmuely Oct 1, 2022
1a4f3e0
Merge branch 'EdgeTX:master' into master
offer-shmuely Oct 18, 2022
05212a0
Merge branch 'EdgeTX:master' into master
offer-shmuely Oct 19, 2022
cfaa10e
Merge branch 'EdgeTX:master' into master
offer-shmuely Dec 30, 2022
a065761
Merge branch 'EdgeTX:master' into master
offer-shmuely Jan 26, 2023
bfe1248
Merge branch 'EdgeTX:master' into master
offer-shmuely Feb 1, 2023
07b65c8
Merge branch 'EdgeTX:master' into master
offer-shmuely Feb 23, 2023
7f46640
Merge branch 'EdgeTX:master' into master
offer-shmuely Mar 31, 2023
f879578
Merge branch 'EdgeTX:master' into master
offer-shmuely May 30, 2023
833cd22
Merge branch 'EdgeTX:master' into master
offer-shmuely Jun 16, 2023
fe180b0
Merge branch 'EdgeTX:master' into master
offer-shmuely Aug 5, 2023
d3c2f1f
Merge branch 'EdgeTX:master' into master
offer-shmuely Sep 11, 2023
5960243
model presets wizard: first version
Sep 11, 2023
3a16626
model presets wizard: first version
Oct 5, 2023
61160f1
model presets wizard: add flight count adjust for "Flights widget"
Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions sdcard/c480x272/SCRIPTS/PRESETS/engine/lib_log.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
local app_name, script_dir = ...

local function is_simulator()
local _, rv = getVersion()
return string.sub(rv, -5) == "-simu"
end

local ENABLE_LOG_TO_CONSOLE = is_simulator() -- false|true|is_simulator()
local ENABLE_LOG_TO_FILE = false


local M = {}
M.app_name = app_name
M.script_dir = script_dir

local log = {
outfile = script_dir .. "/app.log",
enable_file = ENABLE_LOG_TO_FILE,
enable_console = ENABLE_LOG_TO_CONSOLE,
current_level = nil,

-- func
trace = nil,
debug = nil,
info = nil,
warn = nil,
error = nil,
fatal = nil,

levels = {
trace = 1,
debug = 2,
info = 3,
warn = 4,
error = 5,
fatal = 6,
no_logs = 99
}
}
log.current_level = log.levels["info"] -- trace|debug|info|warn|error|fatal


local function round(x, increment)
increment = increment or 1
x = x / increment
return (x > 0 and math.floor(x + .5) or math.ceil(x - .5)) * increment
end

local _tostring = tostring

local function tostring(...)
local t = {}
for i = 1, select('#', ...) do
local x = select(i, ...)
if type(x) == "number" then
x = round(x, .01)
end
t[#t + 1] = _tostring(x)
end
return table.concat(t, " ")
end

function M.do_log(iLevel, ulevel, fmt, ...)
if log.enable_console == false and log.enable_file == false then
return
end

if iLevel < log.current_level then
--below the log level
return
end

local num_arg = #{ ... }
local msg
if num_arg > 0 then
msg = string.format(fmt, ...)
else
msg = fmt
end

--local lineinfo = "f.lua:0"
--local msg2 = string.format("[%-4s][%-8s] %s: %s", ulevel, M.app_name, lineinfo, msg)
local msg2 = string.format("[%-8s][%-4s] %s", M.app_name, ulevel, msg)

-- output to console
print(msg2)

-- Output to log file
if log.enable_file == true then
local fp = io.open(log.outfile, "a")
io.write(fp, msg2 .. "\n")
io.close(fp)
end
end

function M.trace(fmt, ...)
M.do_log(log.levels.trace, "TRACE", fmt, ...)
end
function M.debug(fmt, ...)
M.do_log(log.levels.debug, "DEBUG", fmt, ...)
end
function M.info(fmt, ...)
M.do_log(log.levels.info, "INFO", fmt, ...)
end
function M.warn(fmt, ...)
M.do_log(log.levels.warn, "WARN", fmt, ...)
end
function M.error(fmt, ...)
M.do_log(log.levels.error, "ERROR", fmt, ...)
end
function M.fatal(fmt, ...)
M.do_log(log.levels.fatal, "FATAL", fmt, ...)
end

return M
174 changes: 174 additions & 0 deletions sdcard/c480x272/SCRIPTS/PRESETS/engine/lib_utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
local m_log, app_name, m_script_folder = ...

local M = {}
M.m_log = m_log
M.app_name = app_name

-- state machine
M.PRESET_RC = {
OK_CONTINUE = 10,
PREV_PAGE = 11,
NEXT_PAGE = 12,
ERROR_EXIT = 13,
}

M.STICK_NUMBER_AIL = 3
M.STICK_NUMBER_ELE = 1
M.STICK_NUMBER_THR = 2
M.STICK_NUMBER_RUD = 0

M.defaultChannel_AIL = defaultChannel(M.STICK_NUMBER_AIL) + 1
M.defaultChannel_ELE = defaultChannel(M.STICK_NUMBER_ELE) + 1
M.defaultChannel_THR = defaultChannel(M.STICK_NUMBER_THR) + 1
M.defaultChannel_RUD = defaultChannel(M.STICK_NUMBER_RUD) + 1

M.defaultChannel_0_AIL = defaultChannel(M.STICK_NUMBER_AIL)
M.defaultChannel_0_ELE = defaultChannel(M.STICK_NUMBER_ELE)
M.defaultChannel_0_THR = defaultChannel(M.STICK_NUMBER_THR)
M.defaultChannel_0_RUD = defaultChannel(M.STICK_NUMBER_RUD)

local script_folder = m_script_folder
local ImgBackground = Bitmap.open(script_folder .. "img/background.png")
local ImgPageUp = Bitmap.open(script_folder .. "img/pageup.png")
local ImgPageDn = Bitmap.open(script_folder .. "img/pagedn.png")

-----------------------------------------------------------------

-- better font size names
M.FONT_38 = XXLSIZE -- 38px
M.FONT_16 = DBLSIZE -- 16px
M.FONT_12 = MIDSIZE -- 12px
M.FONT_8 = 0 -- Default 8px
M.FONT_6 = SMLSIZE -- 6px


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

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

function M.drawBadgedText(txt, field, font_size, is_selected, is_edit)
local ts_w, ts_h, v_offset = lcdSizeTextFixed(txt, font_size)
local bdg_h = 5 + ts_h + 5
local r = bdg_h / 2

if (field.w > 0) then
ts_w = field.w
else
if (ts_w < 30) then
ts_w = 30
end
end
local bg_color = WHITE
if (is_selected) then
bg_color = GREEN
end
lcd.drawFilledCircle(field.x, field.y + r, r, bg_color)
lcd.drawFilledCircle(field.x + ts_w, field.y + r, r, bg_color)
lcd.drawFilledRectangle(field.x, field.y, ts_w, bdg_h, bg_color)
local attr = 0
if (is_selected and is_edit) then
attr = attr + BLINK
end

lcd.drawText(field.x, field.y + v_offset + 5, txt, font_size + BLACK + attr)
end

-----------------------------------------------------------------
function M.drawTitle(txt, is_prev, is_next, img)
lcd.clear()
lcd.drawBitmap(img, 0, 0)

lcd.drawText(120, 8, txt, COLOR_THEME_PRIMARY1)

if is_prev == true then
lcd.drawBitmap(ImgPageUp, 0, 95)
end
if is_next == true then
lcd.drawBitmap(ImgPageDn, 455, 95)
end
end

-----------------------------------------------------------------
function M.func1(text)
local cnt = 0
local result = {}
M.m_log.info("func1: ", text)
return result, cnt
end
-----------------------------------------------------------------

function M.readFileToString(filename)
m_log.info("readFileToString: %s", filename)
local file = io.open(filename, "r") -- Open the file in read mode
if not file then
return nil -- File does not exist or could not be opened
end

--local content = file:read("*a") -- Read the entire file content
local content = io.read(file, 2000) -- Read the entire file content
io.close(file) -- Close the file

m_log.info("readFileToString: - content: %s", content)
return content
end

function M.readMeta(filename)
m_log.info("readMeta: %s", filename)

local content = M.readFileToString(filename)
m_log.info("readMeta: content: %s", content)

local properties = {}
if content == nil then
return properties
end

--for line in string.gmatch(content, "([^,]+),?") do
for line in string.gmatch(content, "(.-)\r?\n") do
m_log.info("line: %s", line)

local key, value = string.match(line, "^(.-)%s*=%s*(.*)$")
if key and value then
properties[key] = value
m_log.info("%s: %s", key, value)
end
end

return properties
end

--------------------------------------------------------------------

function M.input_search_by_name(neededInputName)
for inputIdx = 0, 3 do
for lineNo = 0, 2 do
m_log.info("%d/%d", inputIdx,lineNo)
local inInfo = model.getInput(inputIdx, lineNo)
if inInfo ~= nil then
m_log.info("%d/%d, name:%s, inputName:%s, source: %s", inputIdx,lineNo, inInfo.name, inInfo.inputName, inInfo.source)
if inInfo.inputName == neededInputName then
return inputIdx
end
end
end
end
return -1
end

-----------------------------------------------------------------------

return M
Loading
Loading