Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --t.buttonList.NameOfButton.active
- os.loadAPI("touchpoint")
- tM = touchpoint.new("back")
- tS = touchpoint.new("back")
- tA = touchpoint.new("back")
- m = peripheral.wrap("back")
- --Pages
- local t
- turbine = 0 --First turbine to see
- RF = {}
- RPM = {}
- trb = {}
- turbineUhOh = {}
- turbineOk = {}
- trb[0] = peripheral.wrap("BigReactors-Turbine_0")
- trb[1] = peripheral.wrap("BigReactors-Turbine_1")
- trb[2] = peripheral.wrap("BigReactors-Turbine_2")
- trb[3] = peripheral.wrap("BigReactors-Turbine_3")
- trb[4] = peripheral.wrap("BigReactors-Turbine_4")
- trb[5] = peripheral.wrap("BigReactors-Turbine_5")
- reactor = peripheral.wrap("BigReactors-Reactor_2")
- function mainPage()
- t = tA
- mode = Auto
- end
- function states()
- if turbine ~= all then
- coilState = trb[turbine].getInductorEngaged()
- turbineState = trb[turbine].getActive()
- if coilState == true then
- coilState = "ON"
- else
- coilState = "OFF"
- end
- if turbineState == true then
- turbineState = "ON"
- else
- turbineState = "OFF"
- end
- end
- reactorState = reactor.getActive()
- if reactorState == true then
- reactorState = "ON"
- else
- reactorState = "OFF"
- end
- end
- function auto()
- if turbine == all then
- turbine = 0
- end
- while true do
- if reactor.getFuelAmount < 158000 then --makes sure reactor is off if it doesnt have yellorite
- reactor.setActive(false)
- reactorOK = false
- reactorFuel = "Not OK"
- else
- reactorOK = true
- reactorFuel = "OK"
- end
- if mode == auto and status == on and reactorOK == true then--automatic and on
- for u=0,5 do --turbines on
- if RPM[u] < 1782 then --Actions below 1782 RPM
- trb[u].setActive(true)
- trb[u].setInductorEngaged(false)
- end
- if RPM[u] > 1783 and RPM[u] < 1784 then --Actions between 1783 RPM and 1784 RPM
- trb[u].setInductorEngaged(true)
- trb[u].setActive(true)
- end
- if RPM[u] > 1785 then --Actions above 1785 RPM
- trb[u].setInductorEngaged(false)
- trb[u].setActive = false
- end
- end
- reactor.setActive(true) --reactor on
- elseif mode == auto and status == off or reactorOK == false then --automatic and off
- for i=0,5 do --turbines off
- trb[i].setActive(false)
- end
- reactor.setActive(false) --reactor off
- elseif mode == auto and status == steam and reactorOK == true then --automatic and get steam
- for i=0,5 do --turbines off
- trb[i].setActive(false)
- end
- reactor.setActive(true) --reactor on
- elseif mode == manual then --manual
- break--Breaks loop to enter manual
- end
- end
- end
- function test() --Check button funcionality
- print("test")
- end
- function changePage(changeTo) -- Change Page
- if t == tA or t == tM then
- oldT = t --Makes sure to change back to correct page from overall
- t = changeTo
- if changeTo == tA then
- mode = Auto
- elseif changeTo == tM then
- mode = Manual
- end
- else
- t = oldT
- end
- end
- function getINFO() --Gets RF and RPM, rounds RPM
- allRF = 0
- for o=0, 5 do
- RPM[o] = trb[o].getRotorSpeed() --Gets RPM
- RF[o] = trb[o].getEnergyProducedLastTick() --Gets RF
- if RF[o] == nil then --Prevents errors
- RF[o] = "0"
- end
- if RPM[o] == nil then --Prevents errors
- RPM[o] = "0"
- end
- RPM[o] = math.floor(RPM[o]*10+0.5)*0.1 --Rounds RPM to 1 number after comma
- RF[o] = math.floor(RF[o]+0.5) --Rounds RF/t
- allRF = allRF + RF[o]
- end
- end
- function turbineThings()
- okCount = 0
- uhohCount = 0
- for i=0,5 do
- turbineUhOh[i] = nil
- turbineOk[i] = nil
- end
- for i=0,5 do
- if trb[i].getRPM ~= 1782 then
- turbineUhOh[uhohCount] = i
- uhohCount = uhohCount + 1
- else
- turbineOk[okCount] = i
- okCount = okCount + 1
- end
- end
- end
- function information() --Prints things
- getINFO() --Gets info
- states() --Gets states
- if t == tA or t == tM then --Main screen, auto or manual mode
- m.setCursorPos(1,1)
- m.setBackgroundColor(colors.gray) --Sets text background to gray
- if turbine ~= all then
- m.write("Turbine "..turbine+1) --Writes what turbine is selected
- m.setCursorPos(1,2)
- m.write("RPM: "..RPM[turbine]) --Writes turbine's RPM
- m.setCursorPos(1,3)
- m.write("Coils: "..coilState)
- m.setCursorPos(1,4)
- m.write("State: "..turbineState)
- m.setCursorPos(1,7)
- m.write("Reactor: "..reactorState)
- m.setCursorPos(1,8)
- m.write("Reactor Fuel: "..reactorFuel)
- elseif turbine == all then
- turbineThings()
- m.write("OK:")
- repeat
- m.write(" #"..turbineOk[okCount])
- okCount = okCount - 1
- until okCount == -1
- m.setCursorPos(1,2)
- m.write("Problems:")
- repeat
- m.write(" #"..turbineUhOh[uhohCount])
- uhohCount = uhohCount - 1
- until uhohCount == -1
- m.setCursorPos(1,4)
- m.write("Reactor: "..reactorState)
- m.setCursorPos(1,5)
- m.write("Total: "..allRF.." RF/t")
- end
- elseif t == tS then --Overall screen
- mY = 1
- for p=0, 5 do
- m.setCursorPos(1,mY) --Sets where to write
- m.setBackgroundColor(colors.gray) --Sets text background to gray
- m.write("Turbine "..p+1..": "..RPM[p].." RPM "..RF[p].." RF/t") --Turbine's stats
- mY = mY + 1 --Makes the next write next line
- end
- end
- end
- function turbinePower()
- if turbine ~= all then
- trb[turbine].setActive(not trb[turbine].getActive())
- else
- for i=0,5 do
- trb[i].setActive(not trb[i].getActive())
- end
- end
- end
- function coilsPower()
- if turbine ~= all then
- trb[turbine].setInductorEngaged(not trb[turbine].getInductorEngaged())
- else
- for i=0,5 do
- trb[i].setInductorEngaged(not trb[i].getInductorEngaged())
- end
- end
- end
- function reactorPower()
- reactor.setActive(not reactor.getActive())
- end
- function onoff()
- t:toggleButton("On")
- t:toggleButton("Off")
- end
- function automanual()
- t:toggleButton("Auto")
- t:toggleButton("Manual")
- end
- function buttonToggles()
- t:toggleButton("Auto")
- end
- function buttonToggles2()
- if trb[0].getActive == true and t.buttonList."Turbine 1".inactive then
- t:toggleButton("Turbine 1")
- end
- if trb[1].getActive == true and t.buttonList."Turbine 2".inactive then
- t:toggleButton("Turbine 2")
- end
- if trb[2].getActive == true and t.buttonList."Turbine 3".inactive then
- t:toggleButton("Turbine 3")
- end
- if trb[3].getActive == true and t.buttonList."Turbine 4".inactive then
- t:toggleButton("Turbine 4")
- end
- if trb[4].getActive == true and t.buttonList."Turbine 5".inactive then
- t:toggleButton("Turbine 5")
- end
- if trb[5].getActive == true and t.buttonList."Turbine 6".inactive then
- t:toggleButton("Turbine 6")
- end
- if trb[0].getActive == false and t.buttonList."Turbine 1".active then
- t:toggleButton("Turbine 1")
- end
- if trb[1].getActive == false and t.buttonList."Turbine 2".active then
- t:toggleButton("Turbine 2")
- end
- if trb[2].getActive == false and t.buttonList."Turbine 3".active then
- t:toggleButton("Turbine 3")
- end
- if trb[3].getActive == false and t.buttonList."Turbine 4".active then
- t:toggleButton("Turbine 4")
- end
- if trb[4].getActive == false and t.buttonList."Turbine 5".active then
- t:toggleButton("Turbine 5")
- end
- if trb[5].getActive == false and t.buttonList."Turbine 6".active then
- t:toggleButton("Turbine 6")
- end
- end
- --Things happen from here
- do --Buttons
- tA:add("All Turbines", function() turbine = all end, 52, 2, 65, 4, colors.yellow, colors.yellow)
- tA:add("Turbine 1", function() turbine = 0 end, 47, 6, 57, 8)
- tA:add("Turbine 2", function() turbine = 1 end, 59, 6, 69, 8)
- tA:add("Turbine 3", function() turbine = 2 end, 47, 10, 57, 12)
- tA:add("Turbine 4", function() turbine = 3 end, 59, 10, 69, 12)
- tA:add("Turbine 5", function() turbine = 4 end, 47, 14, 57, 16)
- tA:add("Turbine 6", function() turbine = 5 end, 59, 14, 69, 16)
- tA:add("Overall", function() t:flash("Overall") changePage(tS) end, 59, 23, 69, 25)
- tA:add("Manual", function() automanual() changePage(tA) end, 59, 18, 69, 20)
- tA:add("Auto", function() automanual() changePage(tM) end, 47, 18, 57, 20)
- --tA:add("On", function() onoff() status = on end,
- --tA:add("Off", function() onoff() status = off end,
- --tA:add("Steam", function() status = steam end,
- tM:add("All Turbines", function() turbine = all end, 52, 2, 65, 4, colors.yellow, colors.yellow)
- tM:add("Turbine 1", function() turbine = 0 () end, 47, 6, 57, 8)
- tM:add("Turbine 2", function() turbine = 1 end, 59, 6, 69, 8)
- tM:add("Turbine 3", function() turbine = 2 end, 47, 10, 57, 12)
- tM:add("Turbine 4", function() turbine = 3 end, 59, 10, 69, 12)
- tM:add("Turbine 5", function() turbine = 4 end, 47, 14, 57, 16)
- tM:add("Turbine 6", function() turbine = 5 end, 59, 14, 69, 16)
- tM:add("Overall", function() t:flash("Overall") changePage(tS) end, 59, 23, 69, 25)
- tM:add("Manual", function() changePage(tM) end, 59, 18, 69, 20)
- tM:add("Auto", function() changePage(tA) end, 47, 18, 57, 20)
- --tM:add("Power", function() turbinePower() end,
- --tM:add("Coils", function() coilsPower() end,
- --tM:add("Reactor", function() reactorPower() end,
- tS:add("Main", function() t:flash("Main") changePage(oldT) end, 59, 23, 69, 25)
- end
- mainPage() --set mode to auto on start
- t:draw() --to be able to do stuff with buttons outside loop
- buttonToggles() --toggle needed buttons
- while true do
- m.clear() --Gets rid of old stuff
- t:draw()--draw buttons
- information()--RPMs, RF/t, etc.
- buttonToggles2()
- refreshTimer = os.startTimer(3) --Restart loop
- local event, p1 = t:handleEvents(os.pullEvent())
- if event == "button_click" then
- t:run(p1)
- elseif event == "timer" and p1 == refreshTimer then
- --restart loop
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment