Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function send(ch,msg)
- local modems = {peripheral.find("modem")}
- local ch = tonumber(ch)
- for k,v in pairs(modems) do
- v.open(ch)
- end
- for k,v in pairs(modems) do
- v.transmit(ch,ch,msg)
- end
- end
- local function close(ch)
- ch = tonumber(ch)
- local modems = {peripheral.find("modem")}
- for k,v in pairs(modems) do
- v.close(ch)
- end
- end
- local function selectProfile()
- local profiles = fs.list("/rrp")
- for i=1,#profiles do
- print(i .. ") " .. profiles[i])
- end
- print("Select")
- local sel = tonumber(read())
- local prof = {}
- local handle = fs.open("/rrp/" .. profiles[sel],"r")
- prof.ch = handle.readLine()
- prof.head = handle.readLine()
- handle.close()
- return prof
- end
- local function add()
- print("Sync key?")
- local key = read()
- print("Profile name?")
- local name = read()
- --send(65000,key)
- local function wait()
- sleep(5)
- error("Synchronisation failed!")
- end
- local function sync()
- local modems = {peripheral.find("modem")}
- for k,v in pairs(modems) do v.open(65000) end
- send(65000,key)
- while true do
- local r = {os.pullEvent("modem_message")}
- local data = textutils.unserialise(r[5])
- if data.identify then
- if data.identify == key then
- print("Received signal")
- local handle = fs.open("/rrp/" .. name,"w")
- handle.writeLine(data.channel)
- handle.writeLine(data.header)
- handle.close()
- close(65000)
- break
- end
- end
- end
- end
- parallel.waitForAny(sync,wait)
- sleep(2)
- end
- local function on()
- local prof = selectProfile()
- send(prof.ch,prof.head .. "on")
- print("Done")
- sleep(1)
- close(prof.ch)
- end
- local function off()
- local prof = selectProfile()
- send(prof.ch,prof.head .. "off")
- print("Done")
- sleep(1)
- close(prof.ch)
- end
- local function click()
- local prof = selectProfile()
- send(prof.ch,prof.head .. "on")
- sleep(1)
- send(prof.ch,prof.head .. "off")
- print("Done")
- sleep(1)
- close(prof.ch)
- end
- local function main()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("RemoteRedstone Client by Rahph")
- print("")
- print("1) Add profile")
- print("2) Enable signal on profile")
- print("3) Disable signal on profile")
- print("4) Simulate button press on profile\n")
- print("9) Exit")
- local sel = read()
- if sel == "1" then
- add()
- elseif sel == "2" then
- on()
- elseif sel == "3" then
- off()
- elseif sel == "4" then
- click()
- elseif sel == "9" then
- break
- else
- print("Uhhhh... no!")
- sleep(2)
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment