Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --btn = require("buttonAPI")
- local component = require("component")
- local keyboard = require("keyboard")
- local event = require("event")
- local gpu = component.gpu
- local sides = require("sides")
- local sysinfo = {}
- local g = component.ie_diesel_generator
- local f = component.ie_fermenter
- local s = component.ie_squeezer
- local r = component.ie_refinery
- local red = component.redstone
- local colours = {black = 0x000000, white = 0xFFFFFF, yellow = 0xFFFF55, blue = 0x0000AA, green = 0x00AA00, grey = 0xAAAAAA, red = 0xAA0000}
- local sections = {}
- local graphs = {}
- local info = {}
- local applications = {}
- local currentDiesel = 0
- local currentFEthanol = 0
- local currentPotato = 0
- local currentSPlantOil = 0
- local currnetPumpkin = 0
- local currentREthanol=0
- local currentRPlantOil = 0
- local currentRDiesel = 0
- local currentenaFer = false
- local currentenaGen = false
- local currentenaRef = false
- local currentenaSqu = false
- gpu.setResolution(132,38)
- --gpu.setResolution(98,32)
- local w,h = gpu.getResolution() -- lol
- -- define sections
- function setSections()
- sections["tanks"] = { x = 5, y = 26, width = 123, height = 6, title = "[ Tanks ]"}
- sections["status"] = { x = 88, y = 4, width = 40, height = 20, title = "[ Status ]"}
- sections["details"] = { x = 5, y = 4, width = 78, height = 20, title = "[ Details ]"}
- end
- -- define graphs to display
- function setGraphs()
- graphs["diesel"] = { x = 8, y = 29, width = 118, height = 2, title = "Diesel"}
- end
- -- define info to display
- function setInfo()
- info["diesel"] = { x = 8, y = 6, width = 73, height= 1, title = "Generator Diesel: ", unit = " mB"}
- info["fethanol"] = { x = 8, y = 8, width = 73, height = 1, title = "Ethanol: ", unit = " mB"}
- info["potato"] = { x = 8, y = 10, width = 73, height= 1, title = "Potatoes: ", unit = " potatoes"}
- info["splantoil"] = { x = 8, y = 12, width = 73, height= 1, title = "Plant Oil: ", unit = " mB"}
- info["pumpkin"] = { x = 8, y = 14, width = 73, height= 1, title = "Pumpkin: ", unit = " seeds"}
- info["rethanol"] = { x = 8, y = 16, width = 73, height= 1, title = "Refinery Ethanol: ", unit = " mB"}
- info["rplantoil"] = { x = 8, y = 18, width = 73, height= 1, title = "Refinery Plant Oil: ", unit = " mB"}
- info["rdiesel"] = { x = 8, y = 20, width = 73, height= 1, title = "Refinery Diesel: ", unit = " mB"}
- info["enaGen"] = { x = 91, y = 6, width = 73, height= 1, title = "Generator Enabled: ", unit = ""}
- info["enaFer"] = { x = 91, y = 6, width = 73, height= 1, title = "Fermenter Enabled: ", unit = ""}
- info["enaSqu"] = { x = 91, y = 6, width = 73, height= 1, title = "Squeezer Enabled: ", unit = ""}
- info["enaRef"] = { x = 91, y = 6, width = 73, height= 1, title = "Refinery Enabled: ", unit = ""}
- end
- -- define applications
- function setApplications()
- applications["main"] = {x = 3, y = 2, width = 128, height = 32, title = "[ Power Generation Control Panel ]"}
- end
- ------------------------ Button Stuff -------------------------------------------
- local btn = {}
- local button = {}
- function btn.clearTable()
- button = {}
- end
- function btn.setTable(name, func, xmin, ymin, xmax, ymax, text, colors, active) -- color is an object { on : 0x000000, off 0xAAAAAA}
- button[name] = {}
- button[name]["text"] = text
- button[name]["func"] = func
- button[name]["active"] = active
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- button[name]["colors"] = colors
- end
- function btn.fill(bData)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmin"] + bData["xmax"]) /2) - math.floor((string.len(bData["text"])/2))
- local oldColor = gpu.getBackground()
- local curColor = bData["colors"].on
- if bData["active"] then
- curColor = bData["colors"].on
- else
- curColor = bData["colors"].off
- end
- gpu.setBackground(curColor)
- gpu.fill(bData["xmin"], bData["ymin"], bData["xmax"] - bData["xmin"] + 1, bData["ymax"] - bData["ymin"] + 1, " ")
- gpu.set(xspot, yspot, bData["text"])
- gpu.setBackground(oldColor)
- end
- function btn.screen()
- for name,data in pairs(button) do
- btn.fill(data)
- end
- end
- function btn.toggleButton(name)
- button[name]["active"] = not button[name]["active"]
- btn.screen() -- not sure about this one here
- return button[name]["active"]
- end
- function btn.flash(name)
- _ = btn.toggleButton(name)
- btn.screen() -- or here
- os.sleep(0.1)
- _ = btn.toggleButton(name)
- btn.screen()
- end
- function btn.checkxy(_, _, x, y, _, _)
- os.sleep(0)
- for name, data in pairs(button) do
- if y >= data["ymin"] and y <= data["ymax"] then
- if x >= data["xmin"] and x <= data["xmax"] then
- data["func"]()
- return true
- end
- end
- end
- return false
- end
- ----------------------------------------------------------------------------------
- function setButtons()
- -- btn.setTable("power", power, 91, 6, 106, 8, "power", {on = colours.green, off = colours.red},false)
- -- btn.setTable("test", testBtn, 108, 6, 123, 8, "test", {on = colours.green, off = colours.red},false)
- --btn.setTable("OFF", powerOff, 109, 6, 125, 8,"OFF", {on = colours.red, off = colours.red})
- --btn.setTable("lowerMinLimit", lowerMinLimit, 91, 15, 106, 17,"-10", {on = colours.blue, off = colours.blue})
- --btn.setTable("lowerMaxLimit", lowerMaxLimit, 109, 15, 125, 17,"-10", {on = colours.purple, off = colours.purple})
- --btn.setTable("augmentMinLimit", augmentMinLimit, 91, 19, 106, 21,"+10", {on = colours.blue, off = colours.blue})
- --btn.setTable("augmentMaxLimit", augmentMaxLimit, 109, 19, 125, 21,"+10", {on = colours.purple, off = colours.purple})
- end
- function printBG()
- gpu.setBackground(colours.black)
- gpu.fill(1,1,w,h," ")
- gpu.setBackground(colours.grey)
- gpu.fill(1,h,w,1," ")
- gpu.setForeground(colours.white)
- local bottomText = "Copyright (c) 1996 - 2009 New DPKR Tech. Inc. All Rights Reserved."
- gpu.set(w/2 - string.len(bottomText)/2,h,bottomText)
- end
- -- application + borders
- function printApplication(appName)
- local a = applications[appName]
- --gpu.setBackground(colours.black)
- --gpu.fill(a.x-2,a.y-1,a.width-2,a.height-1, " ")
- gpu.setBackground(colours.blue)
- gpu.fill(a.x,a.y,a.width,a.height," ")
- -- fill borders
- gpu.setBackground(colours.blue)
- gpu.setForeground(colours.white)
- gpu.fill(a.x, a.y, a.width, 1, "─")
- gpu.fill(a.x, a.y, 1, a.height, "│")
- gpu.fill(a.x, a.y + a.height, a.width, 1, "─")
- gpu.fill(a.x + a.width, a.y, 1, a.height + 1, "│")
- -- fill corners
- gpu.set(a.x,a.y,"┌")
- gpu.set(a.x + a.width,a.y,"┐")
- gpu.set(a.x,a.y + a.height,"└")
- gpu.set(a.x + a.width,a.y + a.height,"┘")
- -- set title
- gpu.setBackground(colours.blue)
- gpu.setForeground(colours.white)
- gpu.set(a.x + a.width/2 - string.len(a.title)/2, a.y, a.title)
- gpu.setForeground(colours.white)
- end
- -- section borders
- function printBorders(sectionName)
- local s = sections[sectionName]
- -- ─ │ ║ ═
- -- ┐ └ ┴ ┬ ├ ─ ┼ │ ┤ ┘ ┌
- -- set border
- gpu.setBackground(colours.blue)
- gpu.fill(s.x, s.y, s.width, 1, "─")
- gpu.fill(s.x, s.y, 1, s.height, "│")
- gpu.fill(s.x, s.y + s.height, s.width, 1, "─")
- gpu.fill(s.x + s.width, s.y, 1, s.height + 1, "│")
- gpu.set(s.x,s.y,"┌")
- gpu.set(s.x + s.width,s.y,"┐")
- gpu.set(s.x,s.y + s.height,"└")
- gpu.set(s.x + s.width,s.y + s.height,"┘")
- -- set title
- gpu.setBackground(colours.blue)
- gpu.setForeground(colours.white)
- gpu.set(s.x + s.width/2 - string.len(s.title)/2, s.y, s.title)
- end
- function power()
- buttonStatus = btn.toggleButton("power",buttonStatus)
- if buttonStatus == true then
- print("On!")
- else
- print("Off!")
- end
- end
- function testBtn()
- buttonStatus = btn.flash("test")
- end
- function startup()
- -- print("Enabling computer control...")
- g.enableComputerControl(true)
- f.enableComputerControl(true)
- s.enableComputerControl(true)
- r.enableComputerControl(true)
- g.setEnabled(false)
- f.setEnabled(false)
- s.setEnabled(false)
- r.setEnabled(false)
- end
- function getSysInfo()
- -- check how much diesel we have
- dTank = g.getTankInfo()
- -- reset input count
- fInputSize = 0
- sInputSize = 0
- -- get size of each stack in fermenter and squeezer
- for i = 1,6 do
- fInputSize = fInputSize + f.getInputStack(i)["size"]
- sInputSize = sInputSize + s.getInputStack(i)["size"]
- end
- -- fermenter and squeezer fluid output
- fTank = f.getFluid()
- sTank = s.getFluid()
- -- refinery io
- rInTank = r.getInputFluidTanks()
- rOutTank = r.getOutputTank()
- sysinfo["diesel"] = dTank["amount"]
- sysinfo["dieselCap"] = dTank["capacity"]
- sysinfo["fethanol"] = fTank["amount"]
- sysinfo["fethanolCap"] = fTank["capacity"]
- sysinfo["potato"] = fInputSize
- sysinfo["potatoCap"] = 384
- sysinfo["splantoil"] = sTank["amount"]
- sysinfo["splantoilCap"] = sTank["capacity"]
- sysinfo["pumpkin"] = sInputSize
- sysinfo["pumpkinCap"] = 384
- sysinfo["rethanol"] = rInTank["input1"]["amount"]
- sysinfo["rethanolCap"] = rInTank["input1"]["capacity"]
- sysinfo["rplantoil"] = rInTank["input2"]["amount"]
- sysinfo["rplantoilCap"] = rInTank["input2"]["capacity"]
- sysinfo["rdiesel"] = rOutTank["amount"]
- sysinfo["rdieselCap"] = rOutTank["capacity"]
- sysinfo["enaGen"] = tostring(g.isActive())
- sysinfo["enaFer"] = tostring(f.isActive())
- sysinfo["enaSqu"] = tostring(s.isActive())
- --sysinfo["enaRef"] = "NYE"
- end
- function logicCheck()
- -- print("checking logic")
- -- if filled by >50% activate the squeezer/fermenter
- if fTank["amount"]/fTank["capacity"] <= 0.5 then
- f.setEnabled(true)
- else
- f.setEnabled(false)
- end
- -- if filled by >50% activate the squeezer/fermenter
- if sTank["amount"]/sTank["capacity"] <= 0.5 then
- s.setEnabled(true)
- else
- s.setEnabled(false)
- end
- if rOutTank["amount"]/rOutTank["capacity"] < 0.5 then
- r.setEnabled(true)
- sysinfo["enaRef"] = "true"
- s.setEnabled(true)
- f.setEnabled(true)
- else
- r.setEnabled(false)
- sysinfo["enaRef"] = "false"
- end
- if red.getBundledInput(sides.left)[0] > 0 then
- --if dTank["amount"]/dTank["capacity"] > 0.5 then
- g.setEnabled(true)
- else
- g.setEnabled(false)
- end
- end
- -- progress bar bg
- function printGraphs(graphName)
- local g = graphs[graphName]
- -- set graph
- gpu.setBackground(colours.grey)
- gpu.fill(g.x, g.y, g.width, g.height, " ")
- -- set title
- gpu.setBackground(colours.blue)
- gpu.setForeground(colours.yellow)
- gpu.set(g.x, g.y - 1, g.title)
- end
- -- progressbar
- function printGraphBar(activeGraph)
- local g = activeGraph
- -- set graph
- gpu.setBackground(colours.green)
- gpu.fill(g.x, g.y, g.width, g.height, " ")
- --gpu.setBackground(colours.black)
- end
- -- info to display
- function printInfo(infoName)
- local maxLength = 15
- local i = info[infoName]
- local spaces = string.rep(" ", maxLength - string.len(sysinfo[infoName] .. i.unit))
- gpu.setForeground(colours.yellow)
- gpu.setBackground(colours.blue)
- gpu.set(i.x, i.y , i.title .. sysinfo[infoName] .. i.unit .. spaces)
- end
- setApplications()
- setSections()
- setGraphs()
- setInfo()
- setButtons()
- printBG()
- printApplication("main")
- printBorders("status")
- printBorders("details")
- printBorders("tanks")
- printGraphs("diesel")
- function draw()
- if currentDiesel ~= sysinfo["diesel"] then
- currentDiesel = sysinfo["diesel"]
- maxDiesel = sysinfo["dieselCap"]
- local dieselFrac = math.ceil(graphs["diesel"].width * (currentDiesel/maxDiesel))
- local dGraphUpdate = {x = graphs["diesel"].x, y = graphs["diesel"].y, width = dieselFrac, height = graphs["diesel"].height}
- printGraphs("diesel")
- printGraphBar(dGraphUpdate)
- printInfo("diesel")
- end
- if currentFEthanol ~= sysinfo["fethanol"] then
- currentFEthanol = sysinfo["fethanol"]
- printInfo("fethanol")
- end
- if currentPotato ~= sysinfo["potato"] then
- currentPotato = sysinfo["potato"]
- printInfo("potato")
- end
- if currentSPlantOil ~= sysinfo["splantoil"] then
- currentSPlantOil = sysinfo["splantoil"]
- printInfo("splantoil")
- end
- if currnetPumpkin ~= sysinfo["pumpkin"] then
- currentPumpkin = sysinfo["pumpkin"]
- printInfo("pumpkin")
- end
- if currentREthanol ~= sysinfo["rethanol"] then
- currentREthanol = sysinfo["rethanol"]
- printInfo("rethanol")
- end
- if currentRPlantOil ~= sysinfo["rplantoil"] then
- currentRPlantOil = sysinfo["rplantoil"]
- printInfo("rplantoil")
- end
- if currentRDiesel ~= sysinfo["rdiesel"] then
- currentRDiesel = sysinfo["rdiesel"]
- printInfo("rdiesel")
- end
- if currentenaFer ~= sysinfo["enaFer"] then
- currentenaFer = sysinfo["enaFer"]
- printInfo("enaFer")
- end
- if currentenaGen ~= sysinfo["enaGen"] then
- currentenaGen = sysinfo["enaGen"]
- printInfo("enaGen")
- end
- if currentenaSqu ~= sysinfo["enaSqu"] then
- currentenaSqu = sysinfo["enaSqu"]
- printInfo("enaSqu")
- end
- if currentenaRef ~= sysinfo["enaRef"] then
- currentenaRef = sysinfo["enaRef"]
- printInfo("enaRef")
- end
- os.sleep(0)
- end
- btn.screen()
- startup()
- while event.pull(0.1, "interrupted") == nil do
- -- get info
- event.listen("touch", btn.checkxy)
- getSysInfo()
- logicCheck()
- draw()
- os.sleep(0)
- local event, address, arg1, arg2, arg3 = event.pull(1)
- if type(address) == "string" and component.isPrimary(address) then
- if event == "key_down" and arg2 == keyboard.keys.q then
- os.exit()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment