Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Energy Cell Monitor
- --automatic search in network
- local hw = {}
- local col = colors.white
- --load API
- shell.run("delete caAPI")
- shell.run("pastebin get EDLdR1nF caAPI")
- os.loadAPI("caAPI")
- --set monitor
- function set_monitor()
- local monitor_number = caAPI.get_hardware("monitor")
- local found = fs.exists("config/monitor.cfg")
- if found == true then
- file = fs.open("config/monitor.cfg","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- monitor_number = fileData[1]
- end
- mon = peripheral.wrap(monitor_number)
- end
- --search Energy Cells
- function search()
- local periList = peripheral.getNames()
- for i = 1, #periList do
- if peripheral.getType(periList[i]) == "powered_tile" then
- table.insert(hw,periList[i])
- end
- end
- end
- --draw screen
- function draw_screen()
- xi = true
- mon.setTextColor(1)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- while xi == true do
- sleep(1)
- mon.setCursorPos(2,1)
- mon.setTextColor(colors.blue)
- num = #hw
- mon.write("Energy Cell Status Screen Found "..num.." Cells")
- mon.setCursorPos(2,2)
- mon.write("Cell Number:")
- start_x = 2
- start_y = 3
- for i = 1, #hw do
- cell = peripheral.wrap(hw[i])
- max = cell.getMaxEnergyStored()
- stored = cell.getEnergyStored()
- percent = math.floor(100 * stored / max)
- mon.setTextColor(colors.white)
- mon.setCursorPos(start_x,start_y)
- mon.write(tostring(i))
- max_lines = 23
- lines = math.floor(percent * max_lines / 100)
- yx = 28
- for lix = 1, lines do
- if lix > 6 then
- mon.setBackgroundColor(colors.green)
- elseif lix > 3 then
- mon.setBackgroundColor(colors.yellow)
- else
- mon.setBackgroundColor(colors.red)
- end
- mon.setCursorPos(start_x,(yx-lix))
- mon.write(" ")
- end
- mon.setBackgroundColor(colors.black)
- start_x = start_x + 4
- end
- end
- end
- --start program
- set_monitor()
- search()
- draw_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement