Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local serialization = require("serialization")
- local gpu = component.gpu -- get primary gpu component
- local computer = component.computer
- local modem = component.modem
- local w, h = gpu.getResolution()
- local energy = {}
- local arraySize=0
- local maxEnergy=0
- local currEnergy=0
- modem.open(17)
- if not modem.isOpen(17) then
- print("Modem failed to open on port 17. Exiting...")
- os.exit()
- end
- local colors = { blue = 0x4286F4, purple = 0xB673d6, red = 0xC14141, green = 0xDA841,
- black = 0x000000, white = 0xFFFFFF, grey = 0x47494C, lightGrey = 0xBBBBBB, orange = 0xFFA500, alert = 0xFF0000}
- function parseMsg(psMsgRaw)
- local loS = require("serialization")
- -- Parse the raw message into a destination and a command
- local ltMsg = loS.unserialize(tostring(psMsgRaw))
- currEnergy = ltMsg.curr
- maxEnergy = ltMsg.max
- end
- function show()
- gpu.set( w/2-7, 1, "Current energy")
- gpu.setBackground(colors.grey)
- gpu.fill( w*(currEnergy/maxEnergy), 2, w, 4, " ")
- if currEnergy > maxEnergy*66/100 then
- gpu.setBackground(colors.green)
- elseif currEnergy > maxEnergy*33/100 then
- gpu.setBackground(colors.orange)
- elseif currEnergy > maxEnergy*11/100 then
- gpu.setBackground(colors.red)
- else
- gpu.setBackground(colors.alert)
- computer.beep()
- end
- gpu.fill( 1, 2, w*(currEnergy/maxEnergy), 4, " ")
- --gpu.set( 1, 4, currEnergy .. "/" .. maxEnergy)
- gpu.setBackground(colors.black)
- end
- gpu.fill(1, 1, w, h, " ")
- while true do
- _, _, _, _, _, msg = event.pull("modem_message")
- parseMsg(msg)
- show()
- end
Advertisement
Add Comment
Please, Sign In to add comment