Advertisement
cyber_Ahn

Energy Cell Status

Sep 7th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. --Energy Cell Monitor
  2. --automatic search in network
  3.  
  4. local hw = {}
  5. local col = colors.white
  6. --load API
  7. shell.run("delete caAPI")
  8. shell.run("pastebin get EDLdR1nF caAPI")
  9. os.loadAPI("caAPI")
  10.  
  11. --set monitor
  12. function set_monitor()
  13. local monitor_number = caAPI.get_hardware("monitor")
  14. local found = fs.exists("config/monitor.cfg")
  15. if found == true then
  16. file = fs.open("config/monitor.cfg","r")
  17. local fileData = {}
  18. local line = file.readLine()
  19. repeat
  20. table.insert(fileData,line)
  21. line = file.readLine()
  22. until line == nil
  23. file.close()
  24. monitor_number = fileData[1]
  25. end
  26. mon = peripheral.wrap(monitor_number)
  27. end
  28.  
  29. --search Energy Cells
  30. function search()
  31. local periList = peripheral.getNames()
  32. for i = 1, #periList do
  33. if peripheral.getType(periList[i]) == "powered_tile" then
  34. table.insert(hw,periList[i])
  35. end
  36. end
  37. end
  38.  
  39. --draw screen
  40. function draw_screen()
  41. xi = true
  42. mon.setTextColor(1)
  43. mon.setBackgroundColor(colors.black)
  44. mon.clear()
  45. while xi == true do
  46. sleep(1)
  47. mon.setCursorPos(2,1)
  48. mon.setTextColor(colors.blue)
  49. num = #hw
  50. mon.write("Energy Cell Status Screen Found "..num.." Cells")
  51. mon.setCursorPos(2,2)
  52. mon.write("Cell Number:")
  53. start_x = 2
  54. start_y = 3
  55. for i = 1, #hw do
  56. cell = peripheral.wrap(hw[i])
  57. max = cell.getMaxEnergyStored()
  58. stored = cell.getEnergyStored()
  59. percent = math.floor(100 * stored / max)
  60. mon.setTextColor(colors.white)
  61. mon.setCursorPos(start_x,start_y)
  62. mon.write(tostring(i))
  63. max_lines = 23
  64. lines = math.floor(percent * max_lines / 100)
  65. yx = 28
  66. for lix = 1, lines do
  67. if lix > 6 then
  68. mon.setBackgroundColor(colors.green)
  69. elseif lix > 3 then
  70. mon.setBackgroundColor(colors.yellow)
  71. else
  72. mon.setBackgroundColor(colors.red)
  73. end
  74. mon.setCursorPos(start_x,(yx-lix))
  75. mon.write("  ")
  76. end
  77. mon.setBackgroundColor(colors.black)
  78. start_x = start_x + 4
  79. end
  80. end
  81. end
  82.  
  83. --start program
  84. set_monitor()
  85. search()
  86. draw_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement