Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- version="Reactor control ver.1.0.3 by San"
- configFile="reactor.conf"
- local function saveConfig(table, file)
- local fConfig = fs.open(file, "w") or error("Cannot open file "..file, 2)
- fConfig.write(textutils.serialize(table))
- fConfig.close()
- end
- local function loadConfig(file)
- local fConfig = fs.open(file, "r")
- local ret = textutils.unserialize(fConfig.readAll())
- fConfig.close()
- return ret
- end
- if fs.exists(configFile) then
- cfg=loadConfig(configFile)
- else
- cfg={}
- cfg["SideReactor"] = "back"
- cfg["SideMFSU"] = "bottom"
- cfg["SideMonitor"] = "top"
- cfg["RebootStatus"] = 1
- saveConfig(cfg, configFile)
- end
- if cfg["invertSignal"]==nil then
- cfg["invertSignal"] = false
- saveConfig(cfg, configFile)
- end
- if not(fs.exists("startup")) then
- local fStartup = fs.open("startup", "w") or error("Cannot open file startup", 2)
- fStartup.write("shell.run(\"reactor\")")
- fStartup.close()
- end
- if cfg["RebootStatus"]==nil then
- cfg["RebootStatus"]=1
- end
- if (peripheral.getType(cfg["SideMonitor"])=="monitor") then
- mon=peripheral.wrap(cfg["SideMonitor"])
- end
- function showStatus()
- term.clear()
- term.setCursorPos(1,1)
- print(version)
- if STATUS==1 then
- print("Press ''S'' to shut down reactor")
- else
- print("Press ''S'' to switch reactor on")
- end
- print("Press ''R'' to reboot")
- print("Press ''U'' to update software and reboot")
- end
- STATUS=cfg["RebootStatus"] -- 0 - ON HOLD 1 - RUNNING
- showStatus()
- function pullEvents()
- while true do
- local sEvent, param = os.pullEvent("key")
- if sEvent == "key" then
- if param == 16 then
- error()
- end
- if param == 31 or param == 19 or param == 22 then
- if param == 31 then
- if STATUS~=1 then
- STATUS=1
- else
- STATUS=0
- end
- cfg["RebootStatus"] = STATUS
- saveConfig(cfg,configFile)
- end
- if param == 22 or param == 19 then
- redstone.setOutput(cfg["SideReactor"], false)
- if (STATUS) then
- print("Reactor shutted down")
- end
- if (mon ~= nil) then
- mon.setBackgroundColor(colors.lightBlue)
- mon.clear()
- end
- if param == 22 then
- shell.run("san","update reactor")
- end
- term.setTextColor(colors.red)
- print("REBOOTING")
- sleep(1)
- os.reboot()
- end
- showStatus()
- end
- end
- end
- end
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function setMon(color)
- if (mon ~= nil) then
- mon.setBackgroundColor(color)
- mon.clear()
- end
- end
- shutdownTime = -1
- sleepTime=0.3
- function main()
- while true do
- local FullMFSU = redstone.getInput(cfg["SideMFSU"])
- local ReactorOn = cfg["invertSignal"]
- if STATUS==0 then
- setMon(colors.lightBlue)
- else
- if FullMFSU then
- setMon(colors.red)
- shutdownTime = os.time()
- else
- now = os.time()
- if now<shutdownTime then
- now=now+24
- end
- if now-sleepTime > shutdownTime then
- setMon(colors.lime)
- ReactorOn=not(cfg["invertSignal"])
- else
- mon.setCursorPos(1,1)
- mon.write( "Start in "..tostring(math.floor((sleepTime-(now-shutdownTime))*100)).." ")
- --mon.write(round(round((-0.1)-shutdownTime,2)*-100))
- end
- end
- end
- redstone.setOutput(cfg["SideReactor"], ReactorOn)
- os.queueEvent("randomEvent")
- os.pullEvent()
- end
- end
- parallel.waitForAny(pullEvents, main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement