Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function padLeft(str, w)
- return string.rep(" ", w - #str) .. str
- end
- local function findPeripheral(_type)
- for _,name in pairs(peripheral.getNames()) do
- if peripheral.getType(name) == _type then
- return peripheral.wrap(name)
- end
- end
- end
- local m = findPeripheral("monitor")
- local mfsu = findPeripheral("mfsu")
- local batbox = findPeripheral("batbox")
- if not m then
- error("Cannot find monitor attached to this computer", 0)
- end
- if not mfsu and not batbox then
- error("Cannot find mfsu attached to this computer", 0)
- end
- m.setTextScale(0.5)
- local w, h = m.getSize()
- local total = 0
- if mfsu then
- total = mfsu.getEUCapacity()
- elseif batbox then
- total = batbox.getCapacity()
- end
- os.startTimer(1)
- while true do
- local stored = 0
- if mfsu then
- stored = mfsu.getEUStored()
- elseif batbox then
- stored = batbox.getStored()
- end
- m.clear()
- m.setCursorPos(1, 2)
- m.setTextColour(colours.orange)
- m.write("Energy:")
- m.setTextColour(colours.white)
- m.write(padLeft(tostring(stored), w - 7))
- m.setCursorPos(1, 4)
- m.setTextColour(colours.orange)
- m.write("Total:")
- m.setTextColour(colours.white)
- m.write(padLeft(tostring(total), w - 6))
- local p = (w-2) * stored / total
- m.setBackgroundColour(colours.lightGrey)
- m.setCursorPos(2, 8)
- m.write(string.rep(" ", w-2))
- m.setBackgroundColour(colours.grey)
- m.setCursorPos(2, 8)
- m.write(string.rep(" ", p))
- m.setBackgroundColour(colours.black)
- os.pullEvent("timer")
- os.startTimer(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment