scripts reorganisation
This commit is contained in:
35
main/battery-widget.lua
Normal file
35
main/battery-widget.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
-- name = "Battery info"
|
||||
-- description = "Simple battery info widget"
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||
|
||||
ticks = -1
|
||||
|
||||
function on_tick()
|
||||
-- Update one time per 10 seconds
|
||||
ticks = ticks + 1
|
||||
if ticks % 10 ~= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
ticks = 0
|
||||
|
||||
local batt_info = system:get_battery_info()
|
||||
local batt_strings = stringify_table(batt_info)
|
||||
local folded_str = "Battery: "..batt_info.percent.."% | "..batt_info.temp.."° | "..batt_info.voltage.." mV"
|
||||
|
||||
ui:show_lines(batt_strings, nil, folded_str)
|
||||
end
|
||||
|
||||
function stringify_table(tab)
|
||||
local new_tab = {}
|
||||
|
||||
for k,v in pairs(tab) do
|
||||
table.insert(new_tab, capitalize(k)..": "..tostring(v))
|
||||
end
|
||||
|
||||
return new_tab
|
||||
end
|
||||
|
||||
function capitalize(string)
|
||||
return string:gsub("^%l", string.upper)
|
||||
end
|
||||
41
main/dice-widget.lua
Normal file
41
main/dice-widget.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
-- name = "Dice widget"
|
||||
-- description = "Roll the Dice"
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||
-- foldable = "false"
|
||||
|
||||
local dices = {
|
||||
"fa:dice-one",
|
||||
"fa:dice-two",
|
||||
"fa:dice-three",
|
||||
"fa:dice-four",
|
||||
"fa:dice-five",
|
||||
"fa:dice-six",
|
||||
}
|
||||
|
||||
function on_resume()
|
||||
ui:show_buttons{
|
||||
"Roll the dice",
|
||||
"fa:dice-six",
|
||||
"fa:dice-six",
|
||||
}
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if idx == 1 then
|
||||
roll_dice(2)
|
||||
roll_dice(3)
|
||||
else
|
||||
roll_dice(idx)
|
||||
end
|
||||
end
|
||||
|
||||
function roll_dice(idx)
|
||||
local tab = {}
|
||||
|
||||
for i=1,10 do
|
||||
table.insert(tab, dices[math.random(1, 6)])
|
||||
end
|
||||
|
||||
morph:change_text_seq(idx, tab, 150)
|
||||
end
|
||||
|
||||
23
main/facts-widget.lua
Normal file
23
main/facts-widget.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
-- name = "Random facts"
|
||||
-- description = "Radom useless facts"
|
||||
-- data_source = "https://uselessfacts.jsph.pl/"
|
||||
-- type = "widget"
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||
-- version = "1.0"
|
||||
-- foldable = "false"
|
||||
|
||||
function on_alarm()
|
||||
http:get("https://uselessfacts.jsph.pl/random.json?language=en")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
text = ajson:get_value(result, "object string:text")
|
||||
|
||||
ui:show_lines{ text }
|
||||
end
|
||||
|
||||
function on_click()
|
||||
if text ~= nil then
|
||||
system:copy_to_clipboard(text)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user