Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- component = require("component")
- gui = require("gui")
- event = require("event")
- m = component.modem
- nics = {}
- ic = {"56c", "616", "8f3", "2ce"}
- mc = {"ed0", "d76", "c27", "22b"}
- function unknownEvent()
- -- do nothing if the event wasn't relevant
- end
- -- table that holds all event handlers
- -- in case no match can be found returns the dummy function unknownEvent
- myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end })
- -- The main event handler as function to separate eventID from the remaining arguments
- function handleEvent(eventID, ...)
- if (eventID) then -- can be nil if no event was pulled for some time
- myEventHandlers[eventID](...) -- call the appropriate event handler with all remaining arguments
- end
- end
- function myEventHandlers.modem_message(localAddress, remoteAddress, port, distance, id, message)
- id = text.trim(id)
- if message == "MC id" then
- nics[id] = remoteAddress
- end
- list_msg.insertList(mainGui, list_msg, "Message from " .. id .. ": " .. tostring(message))
- end
- function exitButtonCallback(guiID, id)
- local result = gui.getYesNo("", "Do you really want to exit?", "")
- if result == true then
- gui.exit()
- end
- gui.displayGui(mainGui)
- refresh()
- end
- function startReactor(i)
- p = component.proxy(component.get(mc[i]))
- if ~p.isRunning() then
- p.start()
- end
- m.send(nics["Reactor " .. i], 100, "on")
- end
- function stopReactor(i)
- m.send(nics["Reactor " .. i], 100, "off")
- p = component.proxy(component.get(mc[i]))
- p.stop()
- end
- function list_msg_callback(guiID, listID, selected, text)
- end
- -- Begin: Menu definitions
- mainGui = gui.newGui(1, 2, 159, 48, true)
- list_msg = gui.newList(mainGui, 1, 45, 157, 4, {}, list_msg_callback, list_msg)
- exitButton = gui.newButton(mainGui, 73, 23, "exit", exitButtonCallback)
- -- End: Menu definitions
- gui.clearScreen()
- gui.setTop("IC2 Reactor Control")
- gui.setBottom("")
- m.broadcast(100, "id")
- -- Main loop
- while true do
- gui.runGui(mainGui)
- handleEvent(event.pull(0.5))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement