monster010

CC - DebiTurbineDisplay

Apr 20th, 2016
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.09 KB | None | 0 0
  1. -- DebiTurbineDisplay - (c) monster010
  2.  
  3.  
  4.  
  5. ----------------------------------
  6. ----- DONT CHANGE UNDER THIS -----
  7. ----------------------------------
  8. os.loadAPI("/debiturbinedisplay/api/config")
  9. os.loadAPI("/debiturbinedisplay/api/monster010")
  10. os.loadAPI("/debiturbinedisplay/api/bars")
  11. os.loadAPI("/debiturbinedisplay/api/lbl")
  12.  
  13.  
  14.  
  15. local software = "DebiTurbineDisplay"
  16. local monitor
  17. local cfg = {}
  18. local tbs = {}
  19. local labels = {
  20.     tb1 = {text = "TB 1", x = 2, y = 25},
  21.     tb2 = {text = "TB 2", x = 8, y = 25},
  22.     tb3 = {text = "TB 3", x = 14, y = 25},
  23.     tb4 = {text = "TB 4", x = 20, y = 25},
  24.     tb5 = {text = "TB 5", x = 26, y = 25},
  25.     tb6 = {text = "TB 6", x = 32, y = 25},
  26.     tb7 = {text = "TB 7", x = 38, y = 25},
  27.     tb8 = {text = "TB 8", x = 44, y = 25},
  28.     tb9 = {text = "TB 9", x = 50, y = 25},
  29.     tb10 = {text = "TB 10", x = 56, y = 25}
  30. }
  31. local bar = {
  32.     tb1sp = {tb = "tb1", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 3, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  33.     tb2sp = {tb = "tb2", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 9, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  34.     tb3sp = {tb = "tb3", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 15, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  35.     tb4sp = {tb = "tb4", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 21, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  36.     tb5sp = {tb = "tb5", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 27, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  37.     tb6sp = {tb = "tb6", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 33, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  38.     tb7sp = {tb = "tb7", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 39, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  39.     tb8sp = {tb = "tb8", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 45, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  40.     tb9sp = {tb = "tb9", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 51, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  41.     tb10sp = {tb = "tb10", what = "speed", typ = "ver", maxVal = 2000, curVal = 2000, x = 57, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.lime},
  42.  
  43.     tb1en = {tb = "tb1", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 5, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  44.     tb2en = {tb = "tb2", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 11, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  45.     tb3en = {tb = "tb3", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 17, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  46.     tb4en = {tb = "tb4", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 23, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  47.     tb5en = {tb = "tb5", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 29, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  48.     tb6en = {tb = "tb6", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 35, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  49.     tb7en = {tb = "tb7", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 41, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  50.     tb8en = {tb = "tb8", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 47, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  51.     tb9en = {tb = "tb9", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 53, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  52.     tb10en = {tb = "tb10", what = "energy", typ = "ver", maxVal = 25000, curVal = 25000, x = 59, y = 3, w = 0, h = 21, clfill = colors.gray, clempty = colors.yellow},
  53. }
  54.  
  55.  
  56.  
  57. function connect_tb()
  58.     for name, data in pairs(tbs) do
  59.         data["tb"] = peripheral.wrap(data["name"])
  60.     end
  61. end
  62.  
  63. function addBars()
  64.     for name, data in pairs(bar) do
  65.         bars.add(name, data["typ"], data["maxVal"], data["curVal"], data["x"], data["y"], data["w"], data["h"], data["clfill"], data["clempty"])
  66.     end
  67.  
  68.     bars.screen()
  69. end
  70.  
  71. function addLabels()
  72.     for name, data in pairs(labels) do
  73.         lbl.add(name, data["text"], data["x"], data["y"])
  74.     end
  75.  
  76.     lbl.screen()
  77. end
  78.  
  79. function updateTurbineState()
  80.     for name, data in pairs(bar) do
  81.         if tbs[data["tb"]]["tb"].getActive() then
  82.             if data["what"] == "speed" then
  83.                 bars.set(name, "clfill", colors.gray)
  84.                 bars.set(name, "clempty", colors.lime)
  85.             elseif data["what"] == "energy" then
  86.                 bars.set(name, "clfill", colors.gray)
  87.                 bars.set(name, "clempty", colors.yellow)
  88.             end
  89.         else
  90.             bars.set(name, "clfill", colors.red)
  91.             bars.set(name, "clempty", colors.red)
  92.         end
  93.     end
  94. end
  95.  
  96. function updateSpeedBars()
  97.     local mytimer = os.startTimer(1)
  98.  
  99.     while true do
  100.         local event, args = os.pullEvent()
  101.  
  102.         if event == "timer" and args == mytimer then
  103.             for name, data in pairs(bar) do
  104.                 if data["what"] == "speed" then
  105.                     bars.set(name, "cur", monster010.round(2000 - tbs[data["tb"]]["tb"].getRotorSpeed()))
  106.                 end
  107.             end
  108.  
  109.             bars.screen()
  110.             break
  111.         end
  112.     end
  113. end
  114.  
  115. function updateEnergyBars()
  116.     for name, data in pairs(bar) do
  117.         if data["what"] == "energy" then
  118.             bars.set(name, "cur", monster010.round(25000 - tbs[data["tb"]]["tb"].getEnergyProducedLastTick()))
  119.         end
  120.     end
  121.  
  122.     bars.screen()
  123. end
  124.  
  125. function loadCFG()
  126.     tbs = config.get("tbs")
  127.  
  128.     for name, data in pairs(tbs) do
  129.         data["tb"] = {}
  130.     end
  131. end
  132.  
  133.  
  134. config.load("/debiturbinedisplay/cfg")
  135. cfg = config.getConfig()
  136.  
  137. monster010.construct(cfg["monSide"], software)
  138. monster010.startUp()
  139. monster010.heading(software)
  140. monitor = monster010.getMonitor()
  141. bars.construct(monitor)
  142. lbl.construct(monitor)
  143.  
  144. loadCFG()
  145. connect_tb()
  146. addBars()
  147. addLabels()
  148.  
  149. monster010.startUpDone()
  150.  
  151.  
  152.  
  153. while true do
  154.     updateTurbineState()
  155.     updateSpeedBars()
  156.     updateEnergyBars()
  157. end
Advertisement
Add Comment
Please, Sign In to add comment