1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-23 19:08:05 +11:00
OC-KittenOS/apps/batmon.lua
gamemanj 2ae3f9a93a Initial commit
Currently eeprog pirate-speak language is unsupported, but... oh well.
2016-10-23 13:27:16 +01:00

69 lines
1.3 KiB
Lua

local math, stat = A.request("math", "stat")
local app = {}
-- How much did energy change
-- over 1 second?
local lastChange = 0
local lastValue = nil
local lastTimer = nil
local usage = {
"[####]:",
"[###:]:",
"[### ]:",
"[##: ]:",
"[## ]:",
"[#: ]:",
"[# ]:",
"[: ]:",
"[ ]:",
"WARNING"
}
local function getText(y)
if y == 2 then
if not lastChange then
return "Wait..."
end
local ind = "Dc. "
local wc = lastChange
local wv = stat.energy()
if wc > 0 then
wc = -wc
wv = stat.maxEnergy() - wv
ind = "Ch. "
end
local m = math.floor((wv / -wc) / 60)
return ind .. m .. "m"
end
local dec = stat.energy() / stat.maxEnergy()
-- dec is from 0 to 1.
local potential = math.floor(dec * #usage)
if potential < 0 then potential = 1 end
if potential >= #usage then potential = #usage - 1 end
return usage[#usage - potential]
end
function app.key(ka, kc, down)
if down then
if ka == ("C"):byte() then
A.die()
return false
end
end
end
function app.update()
local nv = stat.energy()
if lastValue then
lastChange = (nv - lastValue) / lastTimer
end
lastValue = nv
lastTimer = 10
if lastChange then
if lastChange > 10 then
lastTimer = 1
end
end
A.timer(lastTimer)
return true
end
function app.get_ch(x, y)
return getText(y):sub(x, x)
end
return app, 7, 2