SHOW:
|
|
- or go back to the newest paste.
| 1 | -- MERDOR (FIH) & ARC (CFG) | |
| 2 | -- Variabili di MERDOR | |
| 3 | pc1 = 4685 | |
| 4 | pc2 = 3838 | |
| 5 | pc3 = 3829 | |
| 6 | pc4 = 9883 | |
| 7 | rednetPos = "top" | |
| 8 | ||
| 9 | -- MERDOR di [[1]] | |
| 10 | ||
| 11 | rednet.open("top")
| |
| 12 | ||
| 13 | --Inizializzo le funzioni | |
| 14 | function getAPI(API, computer) | |
| 15 | risposta = http.get("https://arc.rgbcraft.com/api/get/switch?token="..token.."&computer="..computer)
| |
| 16 | if risposta ~= nil and ris ~= "" then | |
| 17 | a = http.get("https://arc.rgbcraft.com/api/get/switch?token="..token.."&computer="..computer).readAll()
| |
| 18 | b = textutils.unserialize(a) | |
| 19 | end | |
| 20 | return b | |
| 21 | end | |
| 22 | ||
| 23 | function header(text) | |
| 24 | term.setCursorPos(18, 1) | |
| 25 | print(text) | |
| 26 | end | |
| 27 | ||
| 28 | function interfacciaNonConfigurata() | |
| 29 | term.clear() | |
| 30 | header("MERDOR - Installazione")
| |
| 31 | print("\n\nInserisci il token di Arc")
| |
| 32 | local tokenArc = read() | |
| 33 | print("\nPerfetto! Ora inserisci il numero del Computer di Arc!")
| |
| 34 | print("RICORDA che Computer1 su arc e' 0 e Computer2 e' 1")
| |
| 35 | local pcArc = read() | |
| 36 | ||
| 37 | -- Sistemo tutto nel file di configurazione | |
| 38 | file = fs.open(".settings", "w")
| |
| 39 | file.writeLine("token = '"..tokenArc.."'")
| |
| 40 | file.writeLine("computer = '"..pcArc.."'")
| |
| 41 | file.close() | |
| 42 | -- Restarto il programma | |
| 43 | shell.run("startup")
| |
| 44 | end | |
| 45 | ||
| 46 | function interfacciaUtente() | |
| 47 | term.clear() | |
| 48 | header("MERDOR & ARC")
| |
| 49 | print("\n\nMERDOR e Arc stanno lavorando correttamente su questo computer")
| |
| 50 | print("\nPer fermare il programma fai CTRL + T per 5 secondi")
| |
| 51 | end | |
| 52 | ||
| 53 | function apiElaborateToken(pc1, api, computer, rep) | |
| 54 | local api = getAPI(api, computer) | |
| 55 | me1 = api.left | |
| 56 | me2 = api.right | |
| 57 | me3 = api.bottom | |
| 58 | me4 = api.back | |
| 59 | ||
| 60 | if me1 == 2 and rep ~= 2 then | |
| 61 | -- Merdor1 | |
| 62 | rednet.send(pc1, "ON") | |
| 63 | print("MERDOR 1 [ OFF -> ON ]")
| |
| 64 | elseif me1 == 0 and rep ~= 0 then | |
| 65 | rednet.send(pc1, "OFF") | |
| 66 | print("MERDOR 1 [ ON -> OFF ]")
| |
| 67 | end | |
| 68 | if me2 == 2 and rep ~= 2 then | |
| 69 | -- Merdor2 | |
| 70 | rednet.send(pc2, "ON") | |
| 71 | print("MERDOR 2 [ OFF -> ON ]")
| |
| 72 | elseif me2 == 0 and rep ~= 0 then | |
| 73 | rednet.send(pc2, "OFF") | |
| 74 | print("MERDOR 2 [ ON -> OFF ]")
| |
| 75 | end | |
| 76 | if me3 == 2 and rep ~= 2 then | |
| 77 | -- Merdor3 | |
| 78 | rednet.send(pc3, "ON") | |
| 79 | print("MERDOR 3 [ OFF -> ON ]")
| |
| 80 | elseif me3 == 0 and rep ~= 0 then | |
| 81 | rednet.send(pc3, "OFF") | |
| 82 | print("MERDOR 3 [ ON -> OFF ]")
| |
| 83 | end | |
| 84 | if me4 == 2 and rep ~= 2 then | |
| 85 | -- Merdor4 | |
| 86 | rednet.send(pc4, "ON") | |
| 87 | print("MERDOR 4 [ OFF -> ON ]")
| |
| 88 | elseif me4 == 0 and rep ~= 0 then | |
| 89 | rednet.send(pc4, "OFF") | |
| 90 | print("MERDOR 4 [ ON -> OFF ]")
| |
| 91 | end | |
| 92 | return me1 | |
| 93 | end | |
| 94 | ||
| 95 | ||
| 96 | -- Inizio il programma | |
| 97 | term.clear() | |
| 98 | if fs.exists(".settings") == false then
| |
| 99 | interfacciaNonConfigurata() | |
| 100 | else | |
| 101 | shell.run(".settings")
| |
| 102 | interfacciaUtente() | |
| 103 | while true do | |
| 104 | rep = apiElaborateToken(pc1, token, computer, rep) | |
| 105 | sleep(0.5) | |
| 106 | end | |
| 107 | end | |
| 108 | ||
| 109 | ||
| 110 | ||
| 111 | ||
| 112 |