This commit is contained in:
Evgeny
2021-09-01 13:14:44 +03:00
parent 589a9e3fea
commit ea079e220f
2 changed files with 30 additions and 30 deletions

View File

@@ -3,29 +3,29 @@
ticks = -1 ticks = -1
function on_tick() function on_tick()
-- Update one time per 10 seconds -- Update one time per 10 seconds
ticks = ticks + 1 ticks = ticks + 1
if ticks % 10 ~= 0 then if ticks % 10 ~= 0 then
return return
end end
ticks = 0 ticks = 0
local batt_info = system:get_battery_info() local batt_info = system:get_battery_info()
local batt_strings = stringify_table(batt_info) local batt_strings = stringify_table(batt_info)
ui:show_lines(batt_strings) ui:show_lines(batt_strings)
end end
function stringify_table(tab) function stringify_table(tab)
local new_tab = {} local new_tab = {}
for k,v in pairs(tab) do for k,v in pairs(tab) do
table.insert(new_tab, capitalize(k)..": "..tostring(v)) table.insert(new_tab, capitalize(k)..": "..tostring(v))
end end
return new_tab return new_tab
end end
function capitalize(string) function capitalize(string)
return string:gsub("^%l", string.upper) return string:gsub("^%l", string.upper)
end end

View File

@@ -3,30 +3,30 @@
ticks = -1 ticks = -1
function on_tick() function on_tick()
-- Update one time per 10 seconds -- Update one time per 10 seconds
ticks = ticks + 1 ticks = ticks + 1
if ticks % 10 ~= 0 then if ticks % 10 ~= 0 then
return return
end end
ticks = 0 ticks = 0
local info = system:get_system_info() local info = system:get_system_info()
local strings = stringify_table(info) local strings = stringify_table(info)
ui:show_lines(strings) ui:show_lines(strings)
end end
function stringify_table(tab) function stringify_table(tab)
local new_tab = {} local new_tab = {}
for k,v in pairs(tab) do for k,v in pairs(tab) do
table.insert(new_tab, capitalize(k):replace("_", " ")..": "..tostring(v)) table.insert(new_tab, capitalize(k):replace("_", " ")..": "..tostring(v))
end end
return new_tab return new_tab
end end
function capitalize(string) function capitalize(string)
return string:gsub("^%l", string.upper) return string:gsub("^%l", string.upper)
end end