Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local computer = require("computer")
- local component = require("component")
- local sides = require("sides")
- local Black = 0x000000
- local Blue = 0x0000FF
- local Green = 0x008000
- local Red = 0xFF0000
- local White = 0xFFFFFF
- local Yellow = 0xFFFF00
- local gpu = component.gpu
- local batBuffer = component.batterybuffer_16_tier_03
- local w, h = gpu.getResolution()
- local previousCharge = 0
- local refreshRate = 5
- local function round(num) return math.floor(num+.5) end
- local function drawMainScreen()
- gpu.setBackground(Black)
- gpu.fill(1, 1, w, h, " ") -- clears the screen
- gpu.setForeground(Yellow)
- gpu.setResolution(17, 3)
- end
- local function getStoredCharge(c)
- local inv = c.getAllStacks()
- local storedCharge = 0
- local maxCharge = 0
- local differenceCharge = 0
- for i = 1, c.getInventorySize(), 1 do
- if inv[i] == nil then
- else
- storedCharge = storedCharge + inv[i].charge
- maxCharge = maxCharge + inv[i].maxCharge
- end
- end
- maxCharge = maxCharge + c.getEUCapacity()
- storedCharge = storedCharge + c.getStoredEU()
- if previousCharge > storedCharge then
- differenceCharge = 0
- previousCharge = storedCharge
- else
- differenceCharge = 1
- previousCharge = storedCharge
- end
- return maxCharge, storedCharge, differenceCharge
- end
- local function updateScreen()
- local maxCharge, storedCharge, differenceCharge = getStoredCharge(batBuffer)
- gpu.fill(1, 2, 17, 3, " ")
- gpu.fill(1, 3, 17, 3, " ")
- gpu.setForeground(Blue)
- gpu.set(1, 1, "Stored EU")
- gpu.setForeground(Yellow)
- gpu.set(1, 2, "Max: " .. maxCharge .. " EU")
- if differenceCharge == 0 then
- gpu.setForeground(Red)
- else
- gpu.setForeground(Green)
- end
- gpu.set(1, 3, tostring(storedCharge) .. " EU " .. tostring(round(((storedCharge/maxCharge)*100))) .. "%")
- end
- drawMainScreen()
- while true do
- updateScreen()
- os.sleep(refreshRate)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement