Advertisement
MrDionesalvi

Monitor EPCO

Oct 1st, 2020 (edited)
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.49 KB | None | 0 0
  1. -- Calafrica Group System
  2. -- Dione approva
  3.  
  4. local monitor = peripheral.wrap( "right" ) -- Monitor
  5.  
  6. local nir = peripheral.wrap( "top" ) -- Sensori
  7.  
  8. local eme = "bottom"
  9.  
  10. local maxw, maxh = term.getSize()
  11.  
  12. rs.setOutput(eme, false)
  13.  
  14. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  15. local function drawPixelInternal(xPos, yPos)
  16.     monitor.setCursorPos(xPos, yPos)
  17.     monitor.write(" ")
  18. end
  19.  
  20. local tColourLookup = {}
  21. for n = 1, 16 do
  22.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  23. end
  24.  
  25. function drawFilledBox(startX, startY, endX, endY, nColour)
  26.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  27.         "number" or type(endY) ~= "number" or
  28.         (nColour ~= nil and type(nColour) ~= "number") then
  29.         error("Expected startX, startY, endX, endY, colour", 2)
  30.     end
  31.  
  32.     startX = math.floor(startX)
  33.     startY = math.floor(startY)
  34.     endX = math.floor(endX)
  35.     endY = math.floor(endY)
  36.  
  37.     if nColour then term.setBackgroundColor(nColour) end
  38.     if startX == endX and startY == endY then
  39.         drawPixelInternal(startX, startY)
  40.         return
  41.     end
  42.  
  43.     local minX = math.min(startX, endX)
  44.     if minX == startX then
  45.         minY = startY
  46.         maxX = endX
  47.         maxY = endY
  48.     else
  49.         minY = endY
  50.         maxX = startX
  51.         maxY = startY
  52.     end
  53.  
  54.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  55. end
  56.  
  57. function colore(nome) monitor.setTextColor(nome) end
  58.  
  59. function sfondo(nome) monitor.setBackgroundColor(nome) end
  60.  
  61. function fineColore() monitor.setTextColour(colours.white) end
  62.  
  63. function fineSfondo() monitor.setBackgroundColour(colours.black) end
  64.  
  65. function titolo(testo)
  66.     drawFilledBox(1, 1, maxw, 1, colors.yellow)
  67.     monitor.setCursorPos((maxw - #testo) / 2, 1)
  68.     colore(colors.black)
  69.     monitor.write(testo)
  70.     sfondo(colors.blue)
  71. end
  72.  
  73. function clear()
  74.     sfondo(colors.blue)
  75.     monitor.clear()
  76.     monitor.setCursorPos(1, 1)
  77. end
  78.  
  79. function errore(errori)
  80.     sfondo(colors.red)
  81.     colore(colors.white)
  82.     monitor.clear()
  83.     monitor.setCursorPos(1, 1)
  84.     titolo("Errore irreversibile")
  85.     monitor.setCursorPos(1, 3)
  86.     sfondo(colors.red)
  87.     colore(colors.white)
  88.     monitor.write(errori)
  89.     monitor.write("\n\n\nAttendere qualche secondo...")
  90.     os.sleep(5)
  91.     os.reboot()
  92. end
  93.  
  94. function toogleEmergenza()
  95.  
  96.     if rs.getOutput(eme) == false then
  97.         rs.setOutput(eme, true)
  98.     else
  99.         rs.setOutput(eme, false)
  100.     end
  101.  
  102. end
  103.  
  104.  
  105. function emergenza()
  106.     clear()
  107.  
  108.     sfondo(colors.yellow)
  109.     colore(colors.white)
  110.     monitor.setCursorPos(1, 1)
  111.     titolo("EMERGENZA EPCO")
  112.     sfondo(colors.red)
  113.     colore(colors.white)
  114.     monitor.setCursorPos(1, 3)
  115.  
  116.     monitor.setCursorPos(1, 13)
  117.     monitor.write("EPCO Senza corrente o in modalità di TEST")
  118.     monitor.setCursorPos(1, 20)
  119.     sfondo(colors.green)
  120.     colore(colors.black)
  121.     monitor.write("Emergenza EPCO: ON")
  122.  
  123.     while true do
  124.            
  125.         os.startTimer(5)
  126.         event, side, xPos, yPos = os.pullEvent()
  127.         if event == "monitor_touch" and xPos >= 16 and xPos <= 18 and yPos >= 20 and yPos <= 22 then
  128.             toogleEmergenza()
  129.             sleep(0.2)
  130.             os.reboot()
  131.         end
  132.  
  133.  
  134.         if rs.getInput(eme) then
  135.         else
  136.             os.reboot()
  137.         end
  138.     end
  139. end
  140.  
  141. function ora()
  142.  
  143.     a = http.get("http://172.16.20.220/luanet/servlets/ora.php")
  144.     b = textutils.unserialize(a.readAll())
  145.    
  146.     a.close()  
  147.    return b
  148.  
  149.  
  150. end
  151.  
  152. function immisione()
  153.     a,b,c,info = nir.get(1)
  154.     for system, status in pairs(info) do
  155.         status = tostring(status)
  156.         return math.floor(status/1000000)
  157.       end
  158. end
  159.  
  160. function consumo()
  161.     a,b,c,info = nir.get(2)
  162.     for system, status in pairs(info) do
  163.         status = tostring(status)
  164.         return math.floor(status/1000000)
  165.       end
  166. end
  167.  
  168.  
  169.  
  170. function reattore(richiesto)
  171.     stato = richiesto
  172.     a,b,c,info = nir.get(5)
  173.     for system, status in pairs(info) do
  174.         status = tostring(status)
  175.         if(system == stato) then
  176.            return status
  177.         end
  178.       end
  179. end
  180.  
  181. function check()
  182.     if rs.getInput(eme) then
  183.         emergenza()
  184.         return "ON"
  185.     end
  186.     a,b,c,info = nir.get(4)
  187.     for system, status in pairs(info) do
  188.         status = tostring(status)
  189.         if(status == "0") then
  190.             emergenza()
  191.             return "ON"
  192.         else
  193.             return "OFF"
  194.         end
  195.       end
  196.  
  197.  
  198. end
  199.  
  200. function promemoria()
  201.  
  202.     local h = fs.open("prom", "r")
  203.    
  204.  
  205.  
  206. end
  207.  
  208. function consumokw()
  209.     a,b,c,info = nir.get(9)
  210.     for system, status in pairs(info) do
  211.         status = tostring(status)
  212.         return status
  213.       end
  214.  
  215. end
  216.  
  217. function immissionekw()
  218.     a,b,c,info = nir.get(8)
  219.     for system, status in pairs(info) do
  220.         status = tostring(status)
  221.         return status
  222.       end
  223.  
  224. end
  225.  
  226.  
  227.  
  228.  
  229.  
  230. while true do
  231.     term.clear()
  232.  
  233.     clear()
  234.  
  235.     sfondo(colors.yellow)
  236.     colore(colors.white)
  237.     titolo("Monitor Gestione EPCO")
  238.     monitor.setCursorPos(1, 5)
  239.     sfondo(colors.blue)
  240.     colore(colors.white)
  241.     monitor.write("Benvenuto, alla sede della EPCO (Rom non ammessi)")
  242.     monitor.setCursorPos(1, 7)
  243.     monitor.write("Consumi Generali: ")
  244.     monitor.setCursorPos(1, 10)
  245.     monitor.write("Consumo: " .. consumo() .. " IC")
  246.     monitor.setCursorPos(22, 10)
  247.     monitor.write("Consumo istantaneo: " .. consumokw() .. " kW")
  248.     monitor.setCursorPos(1, 12)
  249.     monitor.write("Immisione: " .. immisione() .. " IC")
  250.     monitor.setCursorPos(22, 12)
  251.     monitor.write("Immisione istantanea: " .. immissionekw() .. " kW")
  252.     monitor.setCursorPos(1, 14)
  253.     if(reattore("reactorPoweredB") == "true") then
  254.         sfondo(colors.green)
  255.         colore(colors.black)
  256.         monitor.write("Reattore: ON")
  257.     else
  258.         sfondo(colors.red)
  259.         colore(colors.black)
  260.         monitor.write("Reattore: OFF")
  261.     end
  262.     monitor.setCursorPos(1, 20)
  263.     sfondo(colors.red)
  264.     colore(colors.white)
  265.     monitor.write("Emergenza EPCO: " .. check())
  266.     monitor.setCursorPos(1, 26)
  267.     sfondo(colors.white)
  268.     colore(colors.black)
  269.     monitor.write("v2.9 by CFG")
  270.     reattore()
  271.  
  272.     os.startTimer(7)
  273.     event, side, xPos, yPos = os.pullEvent()
  274.     if event == "monitor_touch" and xPos >= 17 and xPos <= 18 and yPos >= 20 and yPos <= 22 then
  275.         toogleEmergenza()
  276.         emergenza()
  277.     end
  278.     os.sleep(0.5)
  279.  
  280. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement