/batmon.lua Secret
Created
November 6, 2013 02:30
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
local batbox = nil | |
function yesno(val) | |
if val then | |
return "Yes" | |
else | |
return "No" | |
end | |
end | |
function centerize(string, tty) | |
tty = tty or term | |
curx, cury = tty.getCursorPos() | |
maxx, maxy = tty.getSize() | |
l = #string | |
padn = math.floor(maxx-l)/2 | |
tty.setCursorPos(padn + 1, cury) | |
print(string) | |
end | |
for i, side in ipairs(peripheral.getNames()) do | |
if peripheral.getType(side) == "batbox" then | |
batbox = peripheral.wrap(side) | |
break | |
end | |
end | |
if not batbox then | |
print "BatBox not present" | |
return | |
end | |
term.clear() | |
while true do | |
term.setCursorPos(1,1) | |
centerize("******************") | |
centerize("* *") | |
centerize("* BatBox Monitor *") | |
centerize("* by hron84 *") | |
centerize("* *") | |
centerize("******************") | |
print "" | |
charge = batbox.getStored() | |
cap = batbox.getCapacity() | |
cpct = math.floor((charge / cap) * 100) | |
out = batbox.getOutput() | |
maxout = batbox.getMaxEnergyOutput() | |
opct = math.floor((out / maxout) * 100) | |
centerize("Curently stored: " .. charge .. " EU (" .. cpct .. "%)") | |
centerize("Current output: " .. out .. " EU/t (" .. opct .. "%)") | |
centerize("") | |
centerize("Connected to network: " .. yesno(batbox.isAddedToEnergyNet())) | |
sleep(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment