Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Calafrica Group System
- -- Dione approva
- local monitor = peripheral.wrap( "right" ) -- Monitor
- local nir = peripheral.wrap( "top" ) -- Sensori
- local eme = "bottom"
- local maxw, maxh = term.getSize()
- rs.setOutput(eme, false)
- -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
- local function drawPixelInternal(xPos, yPos)
- monitor.setCursorPos(xPos, yPos)
- monitor.write(" ")
- end
- local tColourLookup = {}
- for n = 1, 16 do
- tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
- end
- function drawFilledBox(startX, startY, endX, endY, nColour)
- if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
- "number" or type(endY) ~= "number" or
- (nColour ~= nil and type(nColour) ~= "number") then
- error("Expected startX, startY, endX, endY, colour", 2)
- end
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- if nColour then term.setBackgroundColor(nColour) end
- if startX == endX and startY == endY then
- drawPixelInternal(startX, startY)
- return
- end
- local minX = math.min(startX, endX)
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
- end
- function colore(nome) monitor.setTextColor(nome) end
- function sfondo(nome) monitor.setBackgroundColor(nome) end
- function fineColore() monitor.setTextColour(colours.white) end
- function fineSfondo() monitor.setBackgroundColour(colours.black) end
- function titolo(testo)
- drawFilledBox(1, 1, maxw, 1, colors.yellow)
- monitor.setCursorPos((maxw - #testo) / 2, 1)
- colore(colors.black)
- monitor.write(testo)
- sfondo(colors.blue)
- end
- function clear()
- sfondo(colors.blue)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- end
- function errore(errori)
- sfondo(colors.red)
- colore(colors.white)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- titolo("Errore irreversibile")
- monitor.setCursorPos(1, 3)
- sfondo(colors.red)
- colore(colors.white)
- monitor.write(errori)
- monitor.write("\n\n\nAttendere qualche secondo...")
- os.sleep(5)
- os.reboot()
- end
- function toogleEmergenza()
- if rs.getOutput(eme) == false then
- rs.setOutput(eme, true)
- else
- rs.setOutput(eme, false)
- end
- end
- function emergenza()
- clear()
- sfondo(colors.yellow)
- colore(colors.white)
- monitor.setCursorPos(1, 1)
- titolo("EMERGENZA EPCO")
- sfondo(colors.red)
- colore(colors.white)
- monitor.setCursorPos(1, 3)
- monitor.setCursorPos(1, 13)
- monitor.write("EPCO Senza corrente o in modalità di TEST")
- monitor.setCursorPos(1, 20)
- sfondo(colors.green)
- colore(colors.black)
- monitor.write("Emergenza EPCO: ON")
- while true do
- os.startTimer(5)
- event, side, xPos, yPos = os.pullEvent()
- if event == "monitor_touch" and xPos >= 16 and xPos <= 18 and yPos >= 20 and yPos <= 22 then
- toogleEmergenza()
- sleep(0.2)
- os.reboot()
- end
- if rs.getInput(eme) then
- else
- os.reboot()
- end
- end
- end
- function ora()
- a = http.get("http://172.16.20.220/luanet/servlets/ora.php")
- b = textutils.unserialize(a.readAll())
- a.close()
- return b
- end
- function immisione()
- a,b,c,info = nir.get(1)
- for system, status in pairs(info) do
- status = tostring(status)
- return math.floor(status/1000000)
- end
- end
- function consumo()
- a,b,c,info = nir.get(2)
- for system, status in pairs(info) do
- status = tostring(status)
- return math.floor(status/1000000)
- end
- end
- function reattore(richiesto)
- stato = richiesto
- a,b,c,info = nir.get(5)
- for system, status in pairs(info) do
- status = tostring(status)
- if(system == stato) then
- return status
- end
- end
- end
- function check()
- if rs.getInput(eme) then
- emergenza()
- return "ON"
- end
- a,b,c,info = nir.get(4)
- for system, status in pairs(info) do
- status = tostring(status)
- if(status == "0") then
- emergenza()
- return "ON"
- else
- return "OFF"
- end
- end
- end
- function promemoria()
- local h = fs.open("prom", "r")
- end
- function consumokw()
- a,b,c,info = nir.get(9)
- for system, status in pairs(info) do
- status = tostring(status)
- return status
- end
- end
- function immissionekw()
- a,b,c,info = nir.get(8)
- for system, status in pairs(info) do
- status = tostring(status)
- return status
- end
- end
- while true do
- term.clear()
- clear()
- sfondo(colors.yellow)
- colore(colors.white)
- titolo("Monitor Gestione EPCO")
- monitor.setCursorPos(1, 5)
- sfondo(colors.blue)
- colore(colors.white)
- monitor.write("Benvenuto, alla sede della EPCO (Rom non ammessi)")
- monitor.setCursorPos(1, 7)
- monitor.write("Consumi Generali: ")
- monitor.setCursorPos(1, 10)
- monitor.write("Consumo: " .. consumo() .. " IC")
- monitor.setCursorPos(22, 10)
- monitor.write("Consumo istantaneo: " .. consumokw() .. " kW")
- monitor.setCursorPos(1, 12)
- monitor.write("Immisione: " .. immisione() .. " IC")
- monitor.setCursorPos(22, 12)
- monitor.write("Immisione istantanea: " .. immissionekw() .. " kW")
- monitor.setCursorPos(1, 14)
- if(reattore("reactorPoweredB") == "true") then
- sfondo(colors.green)
- colore(colors.black)
- monitor.write("Reattore: ON")
- else
- sfondo(colors.red)
- colore(colors.black)
- monitor.write("Reattore: OFF")
- end
- monitor.setCursorPos(1, 20)
- sfondo(colors.red)
- colore(colors.white)
- monitor.write("Emergenza EPCO: " .. check())
- monitor.setCursorPos(1, 26)
- sfondo(colors.white)
- colore(colors.black)
- monitor.write("v2.9 by CFG")
- reattore()
- os.startTimer(7)
- event, side, xPos, yPos = os.pullEvent()
- if event == "monitor_touch" and xPos >= 17 and xPos <= 18 and yPos >= 20 and yPos <= 22 then
- toogleEmergenza()
- emergenza()
- end
- os.sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement