SHARE
TWEET

genv2

MiStAWaFFlEZZ Apr 25th, 2019 (edited) 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --btn = require("buttonAPI")
  2. local component = require("component")
  3. local keyboard = require("keyboard")
  4. local event = require("event")
  5. local gpu = component.gpu
  6. local sides = require("sides")
  7. local sysinfo = {}
  8.  
  9. local g = component.ie_diesel_generator
  10. local f = component.ie_fermenter
  11. local s = component.ie_squeezer
  12. local r = component.ie_refinery
  13. local red = component.redstone
  14.  
  15. local colours = {black = 0x000000, white = 0xFFFFFF, yellow = 0xFFFF55, blue = 0x0000AA, green = 0x00AA00, grey = 0xAAAAAA, red = 0xAA0000}
  16. local sections = {}
  17. local graphs = {}
  18. local info = {}
  19. local applications = {}
  20.  
  21. local currentDiesel = 0
  22. local currentFEthanol = 0
  23. local currentPotato = 0
  24. local currentSPlantOil = 0
  25. local currnetPumpkin = 0
  26. local currentREthanol=0
  27. local currentRPlantOil = 0
  28. local currentRDiesel = 0
  29.  
  30. gpu.setResolution(132,38)
  31. local w,h = gpu.getResolution() -- lol
  32.  
  33. -- define sections
  34. function setSections()
  35.   sections["graph"] = { x = 5, y = 26, width = 123, height = 6, title = "[ Graphs ]"}
  36.   sections["controls"] = { x = 88, y = 4, width = 40, height = 20, title = "[ Controls ]"}
  37.   sections["info"] = { x = 5, y = 4, width = 78, height = 20, title = "[ Numbers and shit ]"}
  38. end
  39. -- define graphs to display
  40. function setGraphs()
  41.   graphs["stored"] = { x = 8, y = 29, width = 118, height = 2, title = "Stored Energy"}
  42. end
  43. -- define info to display
  44. function setInfo()
  45.   info["diesel"]      = { x = 8, y = 6, width = 73, height= 1, title  = "Generator Diesel: ", unit = " mB"}
  46.   info["fethanol"]    = { x = 8, y = 8, width = 73, height = 1, title = "Ethanol: ", unit = " mB"}
  47.   info["potato"]      = { x = 8, y = 10, width = 73, height= 1, title = "Potatoes: ", unit = "%"}
  48.   info["splantoil"]   = { x = 8, y = 12, width = 73, height= 1, title = "Plant Oil: ", unit = " mB"}
  49.   info["pumpkin"]     = { x = 8, y = 14, width = 73, height= 1, title = "Pumpkins: ", unit = " mB"}
  50.   info["rethanol"]    = { x = 8, y = 16, width = 73, height= 1, title = "Refinery Ethanol: ", unit = " mB"}
  51.   info["rplantoil"]   = { x = 8, y = 18, width = 73, height= 1, title = "Refinery Plant Oil: ", unit = " mB"}
  52.   info["rdiesel"]     = { x = 8, y = 20, width = 73, height= 1, title = "Refinery Diesel: ", unit = " mB"}
  53. end
  54. -- define applications
  55. function setApplications()
  56.   applications["main"] = {x = 3, y = 2, width = 128, height = 32, title = "[ Power Generation Control Panel ]"}
  57. end
  58.  
  59.  
  60. ------------------------ Button Stuff -------------------------------------------
  61. local btn = {}
  62. local button = {}
  63. function btn.clearTable()
  64.   button = {}
  65. end
  66.  
  67. function btn.setTable(name, func, xmin, ymin, xmax, ymax, text, colors, active) -- color is an object { on : 0x000000, off 0xAAAAAA}
  68.   button[name] = {}
  69.   button[name]["text"] = text
  70.   button[name]["func"] = func
  71.   button[name]["active"] = active
  72.   button[name]["xmin"] = xmin
  73.   button[name]["ymin"] = ymin
  74.   button[name]["xmax"] = xmax
  75.   button[name]["ymax"] = ymax
  76.   button[name]["colors"] = colors
  77. end
  78.  
  79. function btn.fill(bData)
  80.  
  81.   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  82.   local xspot = math.floor((bData["xmin"] + bData["xmax"]) /2) - math.floor((string.len(bData["text"])/2))
  83.   local oldColor = gpu.getBackground()
  84.   local curColor = bData["colors"].on
  85.  
  86.   if bData["active"] then
  87.     curColor = bData["colors"].on
  88.   else
  89.     curColor = bData["colors"].off
  90.   end
  91.   gpu.setBackground(curColor)
  92.   gpu.fill(bData["xmin"], bData["ymin"], bData["xmax"] - bData["xmin"] + 1, bData["ymax"] - bData["ymin"] + 1, " ")
  93.   gpu.set(xspot, yspot, bData["text"])
  94.   gpu.setBackground(oldColor)
  95. end
  96.  
  97. function btn.screen()
  98.   for name,data in pairs(button) do
  99.      btn.fill(data)
  100.   end
  101. end
  102.  
  103. function btn.toggleButton(name)
  104.   button[name]["active"] = not button[name]["active"]
  105.   btn.screen() -- not sure about this one here
  106.   return button[name]["active"]
  107. end
  108.  
  109. function btn.flash(name)
  110.   _ = btn.toggleButton(name)
  111.   btn.screen() -- or here
  112.   os.sleep(0.1)
  113.   _ = btn.toggleButton(name)
  114.   btn.screen()
  115. end
  116.  
  117. function btn.checkxy(_, _, x, y, _, _)
  118.   os.sleep(0)
  119.   for name, data in pairs(button) do
  120.     if y >= data["ymin"] and y <= data["ymax"] then
  121.       if x >= data["xmin"] and x <= data["xmax"] then
  122.         data["func"]()
  123.         return true
  124.       end
  125.     end
  126.   end
  127.   return false
  128. end
  129.  
  130. ----------------------------------------------------------------------------------
  131.  
  132. function setButtons()
  133.   btn.setTable("power", power, 91, 6, 106, 8, "power", {on = colours.green, off = colours.red},false)
  134.   btn.setTable("test", testBtn, 108, 6, 123, 8, "test", {on = colours.green, off = colours.red},false)
  135.   --btn.setTable("OFF", powerOff, 109, 6, 125, 8,"OFF", {on = colours.red, off = colours.red})
  136.  
  137.   --btn.setTable("lowerMinLimit", lowerMinLimit, 91, 15, 106, 17,"-10", {on = colours.blue, off = colours.blue})
  138.   --btn.setTable("lowerMaxLimit", lowerMaxLimit, 109, 15, 125, 17,"-10", {on = colours.purple, off = colours.purple})
  139.  
  140.   --btn.setTable("augmentMinLimit", augmentMinLimit, 91, 19, 106, 21,"+10", {on = colours.blue, off = colours.blue})
  141.   --btn.setTable("augmentMaxLimit", augmentMaxLimit, 109, 19, 125, 21,"+10", {on = colours.purple, off = colours.purple})
  142. end
  143.  
  144. function printBG()
  145.   gpu.setBackground(colours.black)
  146.   gpu.fill(1,1,w,h," ")
  147.   gpu.setBackground(colours.grey)
  148.   gpu.fill(1,h,w,1," ")
  149.   gpu.setForeground(colours.white)
  150.   local bottomText = "Copyright (c) 1996 - 2009 New DPKR Tech. Inc. All Rights Reserved."
  151.   gpu.set(w/2 - string.len(bottomText)/2,h,bottomText)
  152. end
  153. -- application + borders
  154. function printApplication(appName)
  155.   local a = applications[appName]
  156.  
  157.   --gpu.setBackground(colours.black)
  158.   --gpu.fill(a.x-2,a.y-1,a.width-2,a.height-1, " ")
  159.   gpu.setBackground(colours.blue)
  160.   gpu.fill(a.x,a.y,a.width,a.height," ")
  161.  
  162.   -- fill borders
  163.   gpu.setBackground(colours.blue)
  164.   gpu.setForeground(colours.white)
  165.   gpu.fill(a.x, a.y, a.width, 1, "─")
  166.   gpu.fill(a.x, a.y, 1, a.height, "β”‚")
  167.   gpu.fill(a.x, a.y + a.height, a.width, 1, "─")
  168.   gpu.fill(a.x + a.width, a.y, 1, a.height + 1, "β”‚")
  169.    -- fill corners
  170.   gpu.set(a.x,a.y,"β”Œ")
  171.   gpu.set(a.x + a.width,a.y,"┐")
  172.   gpu.set(a.x,a.y + a.height,"β””")
  173.   gpu.set(a.x + a.width,a.y + a.height,"β”˜")
  174.   -- set title
  175.   gpu.setBackground(colours.blue)
  176.   gpu.setForeground(colours.white)
  177.   gpu.set(a.x + a.width/2 - string.len(a.title)/2, a.y, a.title)
  178.   gpu.setForeground(colours.white)
  179.  
  180. end
  181. -- section borders
  182. function printBorders(sectionName)
  183.   local s = sections[sectionName]
  184.   -- ─ β”‚ β•‘ ═
  185.   -- ┐ β”” β”΄ ┬ β”œ ─ β”Ό β”‚ ─ β”˜ β”Œ
  186.   -- set border
  187.   gpu.setBackground(colours.blue)
  188.   gpu.fill(s.x, s.y, s.width, 1, "─")
  189.   gpu.fill(s.x, s.y, 1, s.height, "β”‚")
  190.   gpu.fill(s.x, s.y + s.height, s.width, 1, "─")
  191.   gpu.fill(s.x + s.width, s.y, 1, s.height + 1, "β”‚")
  192.  
  193.   gpu.set(s.x,s.y,"β”Œ")
  194.   gpu.set(s.x + s.width,s.y,"┐")
  195.   gpu.set(s.x,s.y + s.height,"β””")
  196.   gpu.set(s.x + s.width,s.y + s.height,"β”˜")
  197.  
  198.   -- set title
  199.   gpu.setBackground(colours.blue)
  200.   gpu.setForeground(colours.white)
  201.   gpu.set(s.x + s.width/2 - string.len(s.title)/2, s.y, s.title)
  202. end
  203.  
  204. function power()
  205.   buttonStatus = btn.toggleButton("power",buttonStatus)
  206.   if buttonStatus == true then
  207.     print("On!")
  208.   else
  209.     print("Off!")
  210.   end
  211. end
  212.  
  213. function testBtn()
  214.   buttonStatus = btn.flash("test")
  215. end
  216.  
  217. function startup()
  218.   print("Enabling computer control...")
  219.   g.enableComputerControl(true)
  220.   f.enableComputerControl(true)
  221.   s.enableComputerControl(true)
  222.   r.enableComputerControl(true)
  223.   g.setEnabled(false)
  224.   f.setEnabled(false)
  225.   s.setEnabled(false)
  226.   r.setEnabled(false)
  227. end
  228.  
  229. function getSysInfo()
  230.   -- check how much diesel we have
  231.   dTank = g.getTankInfo()
  232.   -- reset input count
  233.   fInputSize = 0
  234.   sInputSize = 0
  235.   -- get size of each stack in fermenter and squeezer
  236.   for i = 1,6 do
  237.     fInputSize = fInputSize + f.getInputStack(i)["size"]
  238.     sInputSize = sInputSize + s.getInputStack(i)["size"]
  239.   end
  240.   -- fermenter and squeezer fluid output
  241.   fTank = f.getFluid()
  242.   sTank = s.getFluid()
  243.   -- refinery io
  244.   rInTank = r.getInputFluidTanks()
  245.   rOutTank = r.getOutputTank()
  246.  
  247.   sysinfo["diesel"]       = dTank["amount"]
  248.   sysinfo["dieselCap"]    = dTank["capacity"]
  249.   sysinfo["fethanol"]     = fTank["amount"]
  250.   sysinfo["fethanolCap"]  = fTank["capacity"]
  251.   sysinfo["potato"]       = fInputSize
  252.   sysinfo["potatoCap"]    = 384
  253.   sysinfo["splantoil"]    = sTank["amount"]
  254.   sysinfo["splantoilCap"] = sTank["capacity"]
  255.   sysinfo["pumpkin"]      = sInputSize
  256.   sysinfo["pumpkinCap"]   = 384
  257.   sysinfo["rethanol"]     = rInTank["input1"]["amount"]
  258.   sysinfo["rethanolCap"]  = rInTank["input1"]["capacity"]
  259.   sysinfo["rplantoil"]    = rInTank["input2"]["amount"]
  260.   sysinfo["rplantoilCap"] = rInTank["input2"]["capacity"]
  261.   sysinfo["rdiesel"]      = rOutTank["amount"]
  262.   sysinfo["rdieselCap"]   = rOutTank["capacity"]
  263. end
  264.  
  265. function logicCheck()
  266.   -- if filled by >50% activate the squeezer/fermenter
  267.   if fTank["amount"]/fTank["capacity"] <= 0.5 then
  268.     f.setEnabled(true)
  269.   else
  270.     f.setEnabled(false)
  271.   end
  272.   -- if filled by >50% activate the squeezer/fermenter
  273.   if sTank["amount"]/sTank["capacity"] <= 0.5 then
  274.     s.setEnabled(true)
  275.   else
  276.     s.setEnabled(false)
  277.   end
  278.  
  279.   if rOutTank["amount"]/rOutTank["capacity"] < 0.5 then
  280.     r.setEnabled(true)
  281.     s.setEnabled(true)
  282.     f.setEnabled(true)
  283.   else
  284.     r.setEnabled(false)
  285.   end
  286.  
  287.   if red.getBundledInput(sides.left)[0] > 0 then
  288.   --if dTank["amount"]/dTank["capacity"] > 0.5 then
  289.     g.setEnabled(true)
  290.   else
  291.     g.setEnabled(false)
  292.   end
  293. end
  294.  
  295. -- progress bar bg
  296. function printGraphs(graphName)
  297.   local g = graphs[graphName]
  298.  
  299.   -- set graph
  300.   gpu.setBackground(colours.grey)
  301.   gpu.fill(g.x, g.y, g.width, g.height, " ")
  302.  
  303.   -- set title
  304.   gpu.setBackground(colours.blue)
  305.   gpu.setForeground(colours.yellow)
  306.   gpu.set(g.x, g.y - 1, g.title)
  307. end
  308. -- progressbar
  309. function printGraphBar(activeGraph)
  310.   local g = activeGraph
  311.  
  312.   -- set graph
  313.   gpu.setBackground(colours.green)
  314.   gpu.fill(g.x, g.y, g.width, g.height, " ")
  315.   --gpu.setBackground(colours.black)
  316. end
  317. -- info to display
  318. function printInfo(infoName)
  319.   local maxLength = 15
  320.   local i = info[infoName]
  321.   local spaces = string.rep(" ", maxLength - string.len(sysinfo[infoName] .. i.unit))
  322.   gpu.setForeground(colours.yellow)
  323.   gpu.setBackground(colours.blue)
  324.   gpu.set(i.x, i.y , i.title .. sysinfo[infoName] .. i.unit .. spaces)
  325. end
  326.  
  327. setApplications()
  328. setSections()
  329. setGraphs()
  330. setInfo()
  331. setButtons()
  332.  
  333. printBG()
  334. printApplication("main")
  335. printBorders("graph")
  336. printBorders("controls")
  337. printBorders("info")
  338. printGraphs("stored")
  339.  
  340. function draw()
  341.  
  342.   if currentDiesel ~= sysinfo["diesel"] then
  343.     currentDiesel = sysinfo["diesel"]
  344.     printInfo("diesel")
  345.   end
  346.   if currentFEthanol ~= sysinfo["fethanol"] then
  347.     currentFEthanol = sysinfo["fethanol"]
  348.     printInfo("fethanol")
  349.   end
  350.   if currentPotato ~= sysinfo["potato"] then
  351.     currentPotato = sysinfo["potato"]
  352.     printInfo("potato")
  353.   end
  354.   if currentSPlantOil ~= sysinfo["splantoil"] then
  355.     currentSPlantOil = sysinfo["splantoil"]
  356.     printInfo("splantoil")
  357.   end
  358.   if currnetPumpkin ~= sysinfo["pumpkin"] then
  359.     currentPumpkin = sysinfo["pumpkin"]
  360.     printInfo("pumpkin")
  361.   end
  362.   if currentREthanol ~= sysinfo["rethanol"] then
  363.     currentREthanol = sysinfo["rethanol"]
  364.     printInfo("rethanol")
  365.   end
  366.   if currentRPlantOil ~= sysinfo["rplantoil"] then
  367.     currentRPlantOil = sysinfo["rplantoil"]
  368.     printInfo("rplantoil")
  369.   end
  370.   if currentRDiesel ~= sysinfo["rdiesel"] then
  371.     currentRDiesel = sysinfo["rdiesel"]
  372.     printInfo("rdiesel")
  373.   end
  374.   local currentRfTick = 27
  375.   local maxRF = 100
  376.   local max = math.ceil(graphs["stored"].width * (currentRfTick/maxRF))
  377.   local graphUpdate = {x = graphs["stored"].x, y = graphs["stored"].y, width = max, height = graphs["stored"].height}
  378.   printGraphs("stored")
  379.   printGraphBar(graphUpdate)
  380.   os.sleep(0)
  381. end
  382.  
  383. btn.screen()
  384.  
  385. while event.pull(0.1, "interrupted") == nil do
  386.   -- get info
  387.   event.listen("touch", btn.checkxy)
  388.   getSysInfo()
  389.   draw()
  390.   os.sleep(0)
  391.   local event, address, arg1, arg2, arg3 = event.pull(1)
  392.   if type(address) == "string" and component.isPrimary(address) then
  393.     if event == "key_down" and arg2 == keyboard.keys.q then
  394.       os.exit()
  395.     end
  396.   end
  397. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top