forked from EdgeTX/edgetx-sdcard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(color): Shmuely/gauge rotary v0.6 (EdgeTX#94)
* new Rotary Gauge widget * Rotary Gauge widget: less ticks on small size * new Rotary Gauge widget * new Rotary Gauge widget * widget GaugeRotary: v0.6 better min/max increase max value (for RPM) stability changes log ot file (if needed) * widget GaugeRotary: v0.6 better min/max increase max value (for RPM) stability changes log ot file (if needed) * widget GaugeRotary: v0.6 fix bug in highAsGreen option * widget GaugeRotary: v0.6 update lib file names * GaugeRotary: double tap to exit full screen * GaugeRotary: mix max layout --------- Co-authored-by: Shmuely <offer.shmuely@cognyte.com> Co-authored-by: oshmuely <AbCd321654>
- Loading branch information
1 parent
6373a8f
commit a9de667
Showing
5 changed files
with
511 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
local app_name, script_dir = ... | ||
|
||
local ENABLE_LOG_TO_CONSOLE = false | ||
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 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 and log.outfile 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 |
Oops, something went wrong.