Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vos.loadApi('core.api')
- vos.loadApi('relay.api')
- local net = peripheral.wrap("bottom")
- Relay.find()
- local percent
- local banks = 0
- local rsside = 'top'
- local lastReading
- rs.setOutput(rsside, false)
- local function getCells()
- local cells = {}
- local names = peripheral.getNames()
- for _,name in pairs(names) do
- if string.find(name, "energycell") then
- table.insert(cells, name)
- end
- end
- return cells
- end
- Event.addHandler('heartbeat', function()
- local total = 0
- local max = 0
- banks = 0
- for k, cellName in pairs(getCells()) do
- local cell = peripheral.wrap(cellName)
- local cellStored = peripheral.call(cellName, 'getEnergyStored', "unknown")
- local cellMax = peripheral.call(cellName, 'getMaxEnergyStored', "unknown")
- total = total + cellStored
- max = max + cellMax
- if cellStored < cellMax then
- banks = banks + 1
- end
- end
- percent = math.floor(total * 100 / max)
- print(total .. " (" .. percent .. "%)")
- if percent < 90 then
- rs.setOutput(rsside, true)
- elseif percent >= 95 then
- rs.setOutput(rsside, false)
- end
- local meterColor = colors.green
- if percent < 75 then
- meterColor = colors.red
- elseif percent < 90 then
- meterColor = colors.orange
- end
- Relay.send('panelUpdate', {
- uid = 'power',
- type = 'meter',
- text = 'Power',
- value = percent,
- color = meterColor
- })
- Relay.send('panelUpdate', {
- uid = 'dynamos',
- text = 'Dynamos',
- type = 'radio',
- active = rs.getOutput(rsside),
- })
- if lastReading then
- local diff = math.floor((total - lastReading) / 600)
- print('diff: ' .. diff)
- Relay.send('panelUpdate', {
- uid = 'powerDiff',
- type = 'text',
- text = string.format('Power Usage: %+d RF/t', diff),
- })
- end
- lastReading = total
- end)
- Event.addHandler('char', function()
- Event.exitPullEvents()
- end)
- os.queueEvent('heartbeat')
- Event.heartbeat(30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement