Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - --Mekanism Fission Reactor Remote Status Monitor
 - --v0.91 by SemlerPDX Aug27 2021
 - --Reactor Control & Monitor Scripts
 - -- Control PC: https://pastebin.com/2VrXwGNH
 - -- and
 - -- Emergency Monitor PC: https://pastebin.com/uxE2jE2B
 - -- and
 - -- Remote Status Monitor PC (this script): https://pastebin.com/59EWW86J
 - --
 - -- example image of setup: https://imgur.com/a/nrKeBcH
 - --Peripheral Sides
 - monitorSide = "back"
 - modemSide = "left"
 - --id of rednet protocols
 - protocol = "PowerSys"
 - protocolCMD = "PowerCMD"
 - controlPC = 20 --id of reactor control PC
 - remotePC = 21 --id of (this) remote display status monitor PC
 - hazardPC = 22 --id of critical shutdown monitor PC
 - --Remote Command Keywords
 - msgOpenComms = "opencomms"
 - msgConfirmed = "copycopy"
 - commandON = "on"
 - commandOFF = "off"
 - remoteClear = "clear"
 - sysOnline = "Systems Online"
 - sysOffline = "Systems Offline"
 - --Remote Command Receive Timeout (in seconds)
 - timeout = 5
 - --Init
 - online = false
 - monitor = peripheral.wrap(monitorSide)
 - modem = peripheral.wrap(modemSide)
 - rednet.open(modemSide)
 - local function fSet()
 - term.clear()
 - monitor.clear()
 - term.setCursorPos(1,1)
 - monitor.setCursorPos(1,1)
 - y = 1
 - end
 - local function fWrite(msg)
 - y = y + 1
 - term.write(msg)
 - monitor.write(msg)
 - term.setCursorPos(1,y)
 - monitor.setCursorPos(1,y)
 - end
 - local function fToggleTxt(state)
 - monitor.setCursorPos(1,5)
 - monitor.write(" ")
 - monitor.setCursorPos(1,5)
 - if state == commandON then
 - monitor.write(" -Tap to Disable- ")
 - online = true
 - elseif state == commandOFF then
 - monitor.write(" -Tap to Enable- ")
 - online = false
 - end
 - monitor.setCursorPos(1,y)
 - end
 - --Rednet Recieve Requested Message
 - local function fRcv(msg)
 - id,message = rednet.receive(protocolCMD,timeout)
 - if message ~= nil then
 - if msg == message then
 - return true
 - else
 - return false
 - end
 - end
 - end
 - --Rednet Send with Receipt Confirmation
 - local function fSend(toID,msg,rcv,ccode)
 - rednet.send(toID,msg,protocolCMD)
 - if rcv then
 - returnReceipt = fRcv(ccode)
 - if returnReceipt then
 - return true
 - else
 - return false
 - end
 - end
 - end
 - --Rednet Send Remote Toggle Command and Return Confirmation
 - local function fRemoteToggle(state)
 - while true do
 - commsOpen = fSend(controlPC,msgOpenComms,true,msgConfirmed)
 - if commsOpen then
 - commsOut = fSend(controlPC,state,true,msgConfirmed)
 - return commsOut
 - end
 - sleep(1)
 - end
 - end
 - --MAIN LOOP
 - while true do
 - --Rednet Remote System Status Update
 - local function fReactorStatus()
 - while true do
 - id,message = rednet.receive(protocol)
 - if stateNew and stateChange then
 - fToggleTxt(stateNew)
 - stateChange = nil
 - end
 - if id == controlPC then
 - if message == remoteClear then
 - fSet()
 - else
 - if message == commandON then
 - online = true
 - fToggleTxt(commandON)
 - elseif message == commandOFF then
 - online = false
 - fToggleTxt(commandOFF)
 - else
 - fWrite(message)
 - end
 - end
 - end
 - end
 - end
 - --Touchscreen Systems Online Toggle
 - local function fTouch()
 - while true do
 - sleep(6)
 - event,side,xPos,yPos = os.pullEvent("monitor_touch")
 - if not online then
 - stateNew = commandON
 - elseif online then
 - stateNew = commandOFF
 - end
 - stateChange = fRemoteToggle(stateNew)
 - end
 - end
 - --Main Function should loop indefinitely
 - monitorStatus = parallel.waitForAny(fReactorStatus,fTouch)
 - end
 
                    Add Comment                
                
                        Please, Sign In to add comment