Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local settings = {state = "", fueltemp = "", casingtemp = "", fuelmix = "", fuelamount = "" , energyamount = "", redstone = ""}
- local values = {state = false, fueltemp = false, casingtemp = false, fuelmix = false, fuelamount = false , energyamount = false, redstone = false}
- local monitors = {}
- local modem
- local messages = {}
- local turnonSetting = {}
- function bindSetting(setting, side, invert)
- for key, value in pairs(settings) do
- if(value == side) then
- print("Side already Bound!")
- shell.exit()
- end
- end
- if(settings[setting] == nil) then
- print("Setting not Found!")
- print("Available Settings:")
- for key, value in pairs(settings) do
- print(tostring(key .. "."))
- end
- shell.exit()
- else
- settings[setting] = {side, invert}
- print("Setting " .. setting .. " to the " .. side .. "side!");
- end
- end
- function bindModem(side)
- type = peripheral.getType(side)
- if(type == "modem") then
- modem = side
- else
- print("No Modem Found at the " .. side .. " side!")
- shell.exit()
- end
- end
- function bindMonitor(name, setting)
- if(settings[setting] == nil) then
- print("Setting not Found!")
- print("Available Settings:")
- for key, value in pairs(settings) do
- print(tostring(key .. "."))
- end
- shell.exit()
- else
- mon = peripheral.wrap(name)
- if(mon == nil) then
- print("Failed to find monitor: " .. name)
- else
- table.insert(monitors, {setting, mon})
- end
- end
- end
- function setTurnOnSetting(setting, value)
- turnonSetting = {setting , value}
- end
- function getSetting(setting)
- return settings[setting][1]
- end
- function getInvert(setting)
- return settings[setting][2]
- end
- function setValue(set, value)
- values[set] = value
- end
- function getValue(set)
- return values[set]
- end
- function canMonitorSetting(setting)
- return settings[setting] ~= ""
- end
- function run()
- for key, value in pairs(settings) do
- if(canMonitorSetting(key) and key ~= "state") then
- values[key] = rs.getInput(tostring(value[1]))
- end
- end
- turnOn()
- sendUpdates()
- end
- function turnOn()
- if(values[turnonSetting[1]] == turnonSetting[2]) then
- values["state"] = true;
- rs.setOutput(settings["state"][1], true)
- else
- values["state"] = false;
- rs.setOutput(settings["state"][1], false)
- end
- end
- function sendUpdates()
- rednet.open(modem)
- for key, value in pairs(values) do
- if(settings[key] ~= "") then
- rednet.broadcast({key, value})
- end
- end
- rednet.close(modem)
- end
- function receiveUpdates()
- rednet.open(modem)
- senderid, message = rednet.receive()
- print("Message Received! {" .. message[1] .. ", " .. tostring(message[2]) .. "}")
- rednet.close(modem)
- table.insert(messages, message)
- end
- function decodeUpdates()
- for i=1, #messages do
- print("Decoding message {" .. messages[i][1] .. ", " .. tostring(messages[i][2]) .. "}")
- values[messages[i][1]] = messages[i][2]
- end
- messages = {}
- end
- function updateMonitors()
- for i=1,#monitors do
- if(values[monitors[i][1]]) then
- monitors[i][2].setBackgroundColor(colors.green)
- monitors[i][2].write("0")
- monitors[i][2].clear()
- monitors[i][2].clear()
- else
- monitors[i][2].setBackgroundColor(colors.red)
- monitors[i][2].write("0")
- monitors[i][2].clear()
- monitors[i][2].clear()
- end
- end
- end
- function statemonitor()
- while true do
- receiveUpdates()
- decodeUpdates()
- updateMonitors()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement