Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- COORDS = {
- {8, 5}, -- Engine 1
- {8, 13}, -- Engine 2
- {8, 21}, -- Engine 3
- {38, 5}, -- Engine 4
- {38, 13}, -- Engine 5
- {38, 21} -- Engine 6
- }
- ENGINE_STATUSES = {
- false,
- false,
- false,
- false,
- false,
- false
- }
- ALTERNATOR_STATUSES = {
- false,
- false,
- false,
- false,
- false,
- false
- }
- function printCentered(text)
- local maxw, maxh = monitor.getSize() --screen dimensions
- local curx, cury = monitor.getCursorPos() --cursor pos
- monitor.setCursorPos((maxw-#text)/2,cury) --set it to the point where write will make the text centred
- monitor.write(text) --write the text
- end
- function startingEngineMessage(nbEngine, isStarting)
- local onofftxt = ""
- if isStarting then
- onofftxt = "on"
- else
- onofftxt = "off"
- end
- monitor.setCursorPos(0, 26)
- monitor.setTextColor(colors.yellow)
- printCentered("Turning "..onofftxt.." Engine "..nbEngine.."...")
- end
- function processClick(x, y)
- print("Click at x :"..x.." and y : "..y)
- local maxw, maxh = monitor.getSize() --screen dimensions
- local ton = "Turn ON"
- local toff = "Turn OFF"
- -- Check if clicked for Engine 1
- if (y == COORDS[1][2] + 2 and x < maxw / 2) then
- print("Focused Engine 1 !")
- if (x >= COORDS[1][1] and x <= COORDS[1][1] + #ton + 1) then
- print("Turn ON")
- modem.transmit(3, 2, "turn_on")
- startingEngineMessage("1", true)
- else
- print("Turn OFF")
- modem.transmit(3, 2, "turn_off")
- startingEngineMessage("1", false)
- end
- end
- -- Check if clicked for Engine 2
- if (y == COORDS[2][2] + 2 and x < maxw / 2) then
- print("Focused Engine 2 !")
- if (x >= COORDS[2][1] and x <= COORDS[2][1] + #ton + 1) then
- print("Turn ON")
- modem.transmit(4, 2, "turn_on")
- startingEngineMessage("2", true)
- else
- print("Turn OFF")
- modem.transmit(4, 2, "turn_off")
- startingEngineMessage("2", false)
- end
- end
- -- Check if clicked for Engine 3
- if (y == COORDS[3][2] + 2 and x < maxw / 2) then
- print("Focused Engine 3 !")
- if (x >= COORDS[3][1] and x <= COORDS[3][1] + #ton + 1) then
- print("Turn ON")
- modem.transmit(5, 2, "turn_on")
- startingEngineMessage("3", true)
- else
- print("Turn OFF")
- modem.transmit(5, 2, "turn_off")
- startingEngineMessage("3", false)
- end
- end
- -- Check if clicked for Engine 4
- if (y == COORDS[4][2] + 2 and x > maxw / 2) then
- print("Focused Engine 4 !")
- if (x >= COORDS[4][1] and x <= COORDS[4][1] + #ton + 1) then
- print("Turn ON")
- modem.transmit(6, 2, "turn_on")
- startingEngineMessage("4", true)
- else
- print("Turn OFF")
- modem.transmit(6, 2, "turn_off")
- startingEngineMessage("4", false)
- end
- end
- -- Check if clicked for Engine 5
- if (y == COORDS[5][2] + 2 and x > maxw / 2) then
- print("Focused Engine 5 !")
- if (x >= COORDS[5][1] and x <= COORDS[5][1] + #ton + 1) then
- print("Turn ON")
- modem.transmit(7, 2, "turn_on")
- startingEngineMessage("5", true)
- else
- print("Turn OFF")
- modem.transmit(7, 2, "turn_off")
- startingEngineMessage("5", false)
- end
- end
- -- Check if clicked for Engine 6
- if (y == COORDS[6][2] + 2 and x > maxw / 2) then
- print("Focused Engine 6 !")
- if (x >= COORDS[6][1] and x <= COORDS[6][1] + #ton + 1) then
- print("Turn ON")
- modem.transmit(8, 2, "turn_on")
- startingEngineMessage("6", true)
- else
- print("Turn OFF")
- modem.transmit(8, 2, "turn_off")
- startingEngineMessage("6", false)
- end
- end
- end
- function shutdownMonitor()
- os.reboot()
- end
- function wait ( time )
- local timer = os.startTimer(time)
- while true do
- local event = {os.pullEvent()}
- if (event[1] == "timer" and event[2] == timer) then
- break
- elseif event[1] == "monitor_touch" then
- processClick(event[3], event[4]) -- a custom function in which you would deal with received events
- elseif event[1] == "modem_message" then
- local mess = event[5]
- print("Got modem message "..mess)
- if mess == "shutdown_monitor" then
- shutdownMonitor()
- break
- end
- end
- end
- end
- function displayWheel(switch, x, y, nb_engine)
- if ENGINE_STATUSES[nb_engine] then
- if ALTERNATOR_STATUSES[nb_engine] then
- monitor.setTextColor(colors.orange)
- else
- monitor.setTextColor(colors.green)
- end
- else
- monitor.setTextColor(colors.red)
- end
- monitor.setCursorPos(x - 6, y - 1)
- monitor.write(" ___ ")
- monitor.setCursorPos(x - 6, y)
- if (switch and ENGINE_STATUSES[nb_engine]) then
- monitor.write("\/ I \\")
- else
- monitor.write("\/\\ \/\\")
- end
- monitor.setCursorPos(x - 6, y + 1)
- if (switch and ENGINE_STATUSES[nb_engine]) then
- monitor.write("|-O-|")
- else
- monitor.write("| O |")
- end
- monitor.setCursorPos(x - 6, y + 2)
- if (switch and ENGINE_STATUSES[nb_engine]) then
- monitor.write("\\_I_\/")
- else
- monitor.write("\\\/_\\\/")
- end
- end
- function displayEngineSection(nbEngine, startX, startY)
- monitor.setCursorPos(startX, startY)
- monitor.setTextColor(colors.yellow)
- monitor.write("Engine #"..nbEngine)
- monitor.setCursorPos(startX, startY + 1)
- monitor.write("Status : ")
- monitor.setCursorPos(startX + 9, startY + 1)
- if(ENGINE_STATUSES[nbEngine]) then
- monitor.write("ON ")
- else
- monitor.write("OFF")
- end
- monitor.setCursorPos(startX, startY + 2)
- monitor.setTextColor(colors.green)
- monitor.write("Turn ON")
- monitor.setCursorPos(startX + 9, startY + 2)
- monitor.setTextColor(colors.red)
- monitor.write("Turn OFF")
- end
- function getEngineStatuses()
- -- Send request
- modem.transmit(9, 2, "get_engine_status_request")
- -- Wait for response
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if message[1]=="get_engine_status_response" then
- if ENGINE_STATUSES[1] ~= message[2] then
- monitor.setCursorPos(0, 26)
- monitor.clearLine()
- end
- ENGINE_STATUSES[1] = message[2]
- if ENGINE_STATUSES[2] ~= message[3] then
- monitor.setCursorPos(0, 26)
- monitor.clearLine()
- end
- ENGINE_STATUSES[2] = message[3]
- if ENGINE_STATUSES[3] ~= message[4] then
- monitor.setCursorPos(0, 26)
- monitor.clearLine()
- end
- ENGINE_STATUSES[3] = message[4]
- if ENGINE_STATUSES[4] ~= message[5] then
- monitor.setCursorPos(0, 26)
- monitor.clearLine()
- end
- ENGINE_STATUSES[4] = message[5]
- if ENGINE_STATUSES[5] ~= message[6] then
- monitor.setCursorPos(0, 26)
- monitor.clearLine()
- end
- ENGINE_STATUSES[5] = message[6]
- if ENGINE_STATUSES[6] ~= redstone.getInput("right") then
- monitor.setCursorPos(0, 26)
- monitor.clearLine()
- end
- ENGINE_STATUSES[6] = redstone.getInput("right")
- end
- end
- function getAlternatorStatuses()
- -- Send request
- modem.transmit(10, 2, "get_alternator_status_request")
- -- Wait for response
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if message[1]=="get_alternator_status_response" then
- ALTERNATOR_STATUSES[1] = message[2]
- ALTERNATOR_STATUSES[2] = message[3]
- ALTERNATOR_STATUSES[3] = message[4]
- ALTERNATOR_STATUSES[4] = message[5]
- ALTERNATOR_STATUSES[5] = message[6]
- ALTERNATOR_STATUSES[6] = redstone.getInput("top")
- end
- end
- function clearMonitor()
- monitor.setCursorPos(0, 0)
- monitor.clearLine()
- monitor.setCursorPos(0, 1)
- monitor.clearLine()
- monitor.setCursorPos(0, 2)
- monitor.clearLine()
- monitor.setCursorPos(0, 3)
- monitor.clearLine()
- monitor.setCursorPos(0, 4)
- monitor.clearLine()
- monitor.setCursorPos(0, 5)
- monitor.clearLine()
- monitor.setCursorPos(0, 6)
- monitor.clearLine()
- monitor.setCursorPos(0, 7)
- monitor.clearLine()
- monitor.setCursorPos(0, 8)
- monitor.clearLine()
- monitor.setCursorPos(0, 9)
- monitor.clearLine()
- monitor.setCursorPos(0, 10)
- monitor.clearLine()
- monitor.setCursorPos(0, 11)
- monitor.clearLine()
- monitor.setCursorPos(0, 12)
- monitor.clearLine()
- monitor.setCursorPos(0, 13)
- monitor.clearLine()
- monitor.setCursorPos(0, 14)
- monitor.clearLine()
- monitor.setCursorPos(0, 15)
- monitor.clearLine()
- monitor.setCursorPos(0, 16)
- monitor.clearLine()
- monitor.setCursorPos(0, 17)
- monitor.clearLine()
- monitor.setCursorPos(0, 18)
- monitor.clearLine()
- monitor.setCursorPos(0, 19)
- monitor.clearLine()
- monitor.setCursorPos(0, 20)
- monitor.clearLine()
- monitor.setCursorPos(0, 21)
- monitor.clearLine()
- monitor.setCursorPos(0, 22)
- monitor.clearLine()
- monitor.setCursorPos(0, 23)
- monitor.clearLine()
- monitor.setCursorPos(0, 24)
- monitor.clearLine()
- monitor.setCursorPos(0, 25)
- monitor.clearLine()
- end
- function mainTerminalDisplay()
- monitor.setTextScale(1.5)
- local maxw, maxh = monitor.getSize() --screen dimensions
- local switch = false
- while true do
- getEngineStatuses()
- getAlternatorStatuses()
- clearMonitor()
- -- Display Title
- monitor.setCursorPos(1, 2)
- monitor.setTextColor(colors.white)
- printCentered("ENGINE CONTROL SCREEN")
- -- Display Engine sections
- displayEngineSection(1, COORDS[1][1], COORDS[1][2])
- displayWheel(switch, COORDS[1][1], COORDS[1][2], 1)
- displayEngineSection(2, COORDS[2][1], COORDS[2][2])
- displayWheel(switch, COORDS[2][1], COORDS[2][2], 2)
- displayEngineSection(3, COORDS[3][1], COORDS[3][2])
- displayWheel(switch, COORDS[3][1], COORDS[3][2], 3)
- displayEngineSection(4, COORDS[4][1], COORDS[4][2])
- displayWheel(switch, COORDS[4][1], COORDS[4][2], 4)
- displayEngineSection(5, COORDS[5][1], COORDS[5][2])
- displayWheel(switch, COORDS[5][1], COORDS[5][2], 5)
- displayEngineSection(6, COORDS[6][1], COORDS[6][2])
- displayWheel(switch, COORDS[6][1], COORDS[6][2], 6)
- switch = not switch
- wait(0.2)
- end
- end
- function getEvent()
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- print("I just received a message on channel: "..senderChannel)
- print("I should apparently reply on channel: "..replyChannel)
- print("The message was: "..message)
- if message=="launch_monitor" then
- mainTerminalDisplay()
- end
- end
- modem = peripheral.wrap("left")
- monitor = peripheral.wrap("back")
- monitor.clear()
- modem.open(2)
- getEvent()
Advertisement
Add Comment
Please, Sign In to add comment