Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------ PARAMS ------
- MODEM_SIDE='bottom'
- ENGINE_SIDE='top'
- CHECK_PERIOD = 5 -- (seconds)
- ------ END PARAMS --
- timerId = nil
- remainToCheck = 0
- processing = false
- function mainScreen(isProcessing)
- if(not isProcessing) then
- term.setBackgroundColor(colors.lime)
- term.setCursorPos(18, 6)
- term.write(" ")
- term.setCursorPos(18, 7)
- term.write(" Initiate process ")
- term.setCursorPos(18, 8)
- term.write(" ")
- else
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(18, 6)
- term.write(" ")
- term.setCursorPos(18, 7)
- term.write(" Processing... ")
- term.setCursorPos(18, 8)
- term.write(" ")
- end
- end
- function main()
- rednet.open(MODEM_SIDE)
- checkers = { rednet.lookup('switch_check','checker') }
- remainToCheck = #checkers
- term.clear()
- mainScreen(false)
- timerId = os.startTimer(CHECK_PERIOD)
- while true do
- data = { os.pullEvent() }
- evt = data[1]
- if(evt == 'rednet_message') then
- mess = data[3]
- if(mess.type == 'status' and mess.status == false) then
- remainToCheck = remainToCheck - 1
- if(remainToCheck == 0) then
- processing = false
- mainScreen(false)
- redstone.setOutput(ENGINE_SIDE, false)
- end
- end
- elseif(evt == 'timer' and data[2] == timerId) then
- if(processing) then
- remainToCheck = #checkers
- for _,checker in pairs(checkers) do
- rednet.send(checker, {type = 'check'})
- end
- timerId = os.startTimer(CHECK_PERIOD)
- end
- elseif(evt == 'mouse_click' and processing == false) then
- x = data[3]
- y = data[4]
- if(x >= 18 and x <= 36 and y >= 6 and y <= 8) then
- mainScreen(true)
- redstone.setOutput(ENGINE_SIDE, true)
- processing = true
- timerId = os.startTimer(CHECK_PERIOD)
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement