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
- reactorFuel = "OK"
- manualToggled = 0
- 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
- status = on
- 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()
- 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)
- else
- trb[u].setInductorEngaged(true)
- 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(true)
- 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
- --Wait for auto
- end
- os.sleep(0.1)
- end
- end
- function test() --Check button funcionality
- print("test")
- end
- function changePage(changeTo) -- Change Page
- if t == tA or t == tM then
- if changeTo == tA then
- mode = auto
- elseif changeTo == tM then
- mode = manual
- end
- oldT = t
- t = changeTo
- if changeTo == tM and manualToggled == 0 then
- t:toggleButton("Manual")
- manualToggled = 1
- 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
- notRoundedRPMS = trb[i].getRotorSpeed()
- roundedRPMS = math.floor(notRoundedRPMS*10)*0.1
- if roundedRPMS ~= 1782 then
- uhohCount = uhohCount + 1
- turbineUhOh[uhohCount] = i+1
- --uhohCount = uhohCount + 1
- else
- okCount = okCount + 1
- turbineOk[okCount] = i+1
- --okCount = okCount + 1
- end
- end
- --uhohCount = uhohCount-1
- --okCount = okCount-1
- 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:")
- for i = 1, okCount do
- m.write(" #"..turbineOk[i])
- end
- m.setCursorPos(1,2)
- m.write("Problems:")
- for i = 1, uhohCount do
- m.write(" #"..turbineUhOh[i])
- end
- 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(info)
- status = info
- end
- function buttonToggles()
- t:toggleButton("Auto")
- end
- function buttonToggles2()
- if t == tA or t == tM then
- if trb[0].getActive() ~= t.buttonList["Turbine 1"].active then
- t:toggleButton("Turbine 1")
- end
- if trb[1].getActive() ~= t.buttonList["Turbine 2"].active then
- t:toggleButton("Turbine 2")
- end
- if trb[2].getActive() ~= t.buttonList["Turbine 3"].active then
- t:toggleButton("Turbine 3")
- end
- if trb[3].getActive() ~= t.buttonList["Turbine 4"].active then
- t:toggleButton("Turbine 4")
- end
- if trb[4].getActive() ~= t.buttonList["Turbine 5"].active then
- t:toggleButton("Turbine 5")
- end
- if trb[5].getActive() ~= t.buttonList["Turbine 6"].active then
- t:toggleButton("Turbine 6")
- end
- end
- if t == tM and turbine ~= all then
- if trb[turbine].getActive() ~= t.buttonList["Power"].active then
- t:toggleButton("Power")
- end
- if trb[turbine].getInductorEngaged() ~= t.buttonList["Coils"].active then
- t:toggleButton("Coils")
- end
- if reactor.getActive() ~= t.buttonList["Reactor"].active then
- t:toggleButton("Reactor")
- end
- end
- end
- --Things happen from here
- m.setTextScale(1)
- 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() changePage(tM) end, 59, 18, 69, 20)
- tA:add("Auto", function() end, 47, 18, 57, 20)
- tA:add("On", function() onoff(on) end, 2, 22, 12, 24)
- tA:add("Off", function() onoff(off) end, 14, 22, 24, 24)
- tA:add("Steam", function() onoff(steam) end, 26, 22, 36, 24)
- 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() end, 59, 18, 69, 20)
- tM:add("Auto", function() changePage(tA) end, 47, 18, 57, 20)
- tM:add("Power", function() turbinePower() end, 2, 22, 12, 24)
- tM:add("Coils", function() coilsPower() end, 14, 22, 24, 24)
- tM:add("Reactor", function() reactorPower() end, 26, 22, 36, 24)
- 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
- refreshTimer = os.startTimer(3)
- function mainLoop()
- while true do
- --m.clear() --Gets rid of old stuff
- t:draw()--draw buttons
- information()--RPMs, RF/t, etc.
- buttonToggles2()
- local event, p1 = t:handleEvents(os.pullEvent())
- if event == "button_click" then
- t.buttonList[p1].func()
- elseif event == "timer" and p1 == "refreshTimer01" then
- refreshTimer = os.startTimer(3)
- end
- end
- end
- parallel.waitForAny(mainLoop, auto)
Advertisement
Add Comment
Please, Sign In to add comment