Advertisement
Guest User

ecdisplay

a guest
Feb 20th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. -- DebiECDisplay - (c) monster010 - v1.0.0
  2.  
  3.  
  4.  
  5. ----------------------------------
  6. ----- DONT CHANGE UNDER THIS -----
  7. ----------------------------------
  8. os.loadAPI('debiecdisplay/api/monster010')
  9. os.loadAPI('debiecdisplay/api/config')
  10. os.loadAPI('debiecdisplay/api/lbl')
  11. os.loadAPI('debiecdisplay/api/bars')
  12.  
  13. local monsid
  14. local monitor = {}
  15. local ecells = {}
  16.  
  17. function convEnergy(str)
  18.     str = tostring(str)
  19.  
  20.     if string.len(str) >= 8 then
  21.         str = string.sub(str, 0, 2).."M"
  22.     elseif string.len(str) >= 7 then
  23.         str = string.sub(str, 0, 1).."M"
  24.     end
  25.  
  26.     return str
  27. end
  28.  
  29. function connect()
  30.     for k, v in pairs(peripheral.getNames()) do
  31.         if peripheral.getType(v) == "tile_thermalexpansion_cell_resonant_name" or peripheral.getType(v) == "cofh_thermalexpansion_energycell" or peripheral.getType(v) == "powered_tile" or peripheral.getType(v) == "tile_thermalexpansion_cell_hardened_name" or peripheral.getType(v) == "tile_blockcapacitorbank_name"  or peripheral.getType(v) == "tile_thermalexpansion_cell_basic_name" or peripheral.getType(v) == "tile_thermalexpansion_cell_reinforced_name" or peripheral.getType(v) == "Induktionsmatrix" then
  32.             local conn = peripheral.wrap(v)
  33.  
  34.             ecells[k] = {}
  35.             ecells[k]['conn'] = conn
  36.             ecells[k]['energy'] = conn.getEnergyStored()
  37.             ecells[k]['max'] = conn.getMaxEnergyStored()
  38.         elseif peripheral.getType(v) == "monitor" then
  39.             monsid = tostring(v)
  40.         end
  41.     end
  42. end
  43.  
  44. function refreshECells()
  45.     local mtimer = os.startTimer(1)
  46.  
  47.     while true do
  48.         local event, args = os.pullEvent()
  49.  
  50.         if event == "timer" and args == mtimer then
  51.             for k, v in pairs(ecells) do
  52.                 v['energy'] = v['conn'].getEnergyStored()
  53.                 v['max'] = v['conn'].getMaxEnergyStored()
  54.  
  55.                 bars.set("bar_"..k, "cur", monster010.round(v['max']-v['energy'])-1)
  56.                 lbl.set("lbl1_"..k, "stxt", convEnergy(v['energy']))
  57.             end
  58.  
  59.             bars.screen()
  60.             lbl.screen()
  61.             break
  62.         end
  63.     end
  64. end
  65.  
  66. function setup()
  67.     local mx, my = monitor.getSize()
  68.  
  69.     local an, bx, lx, ly, llx = 0, 0, mx / 2, 1, 0
  70.  
  71.     for k, v in pairs(ecells) do
  72.         an = an + 1
  73.         bx = bx + 2
  74.         ly = ly + 2
  75.         llx = llx + 2
  76.  
  77.         bars.add("bar_"..k, "ver", v['max'], monster010.round(v['max']-v['energy'])-1, bx, 3, 1, my - 4, colors.gray, colors.green)
  78.  
  79.         if ly > my - 2 then
  80.             ly = 3
  81.             lx = lx + 11
  82.         end
  83.  
  84.         lbl.add("lbl1_"..k, "Z."..an, lx, ly, convEnergy(v['energy']))
  85.         lbl.add("lbl2_"..k, tostring(an), llx, my-1)
  86.     end
  87.  
  88.     bars.screen()
  89.     lbl.screen()
  90. end
  91.  
  92. function launchRestart()
  93.     while true do
  94.         local event, args = os.pullEvent("key")
  95.  
  96.         if args == 19 then
  97.             os.reboot()
  98.         end
  99.     end
  100. end
  101.  
  102.  
  103. connect()
  104.  
  105. monster010.construct(monsid, "Energy")
  106. monster010.startUp()
  107. monster010.heading()
  108.  
  109. monitor = monster010.getMonitor()
  110.  
  111. bars.construct(monitor)
  112. lbl.construct(monitor)
  113.  
  114. setup()
  115.  
  116. monster010.startUpDone()
  117.  
  118. while true do
  119.     parallel.waitForAny(refreshECells, launchRestart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement