geremy44

Monitor V3

Feb 10th, 2022 (edited)
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.99 KB | None | 0 0
  1. --ID : 2
  2. local Prod = 0                --Variable qui recois la production du reacteur
  3. local Stoc = 0                --Variable qui recois l'energie stoquee dans le reacteur
  4. local GRST = 0                --Expression du stoquage en pour 10
  5. local Temp = 0                --Variable qui recois la temperature du reacteur
  6. local IDre = 1                --Variable qui definit l'ID du PC branché au reacteur
  7. local IDbu = 4                --Variable qui definit l'ID du PC branché au moniteur
  8. local Fuel = 0                --Remplissage du reacteur en pour 10
  9. local Temp = 0                --Temperature du reacteur en °C
  10. local Etat = 'Na'             --Variable qui recois l'etat (On ou Off) du reacteur
  11. local Log = 'Reboot'
  12. local ID, Message, Protocole  --Creation des variables pour le messages rednet
  13. local event, side, xPos, yPos --Creation des variables pour un pullEvent()
  14. local timer = os.startTimer(1)--On cree un timer qui envoi un event toutes les 0.1 secondes
  15. local rebot = os.startTimer(600)
  16.  
  17. --je set xPos et yPos pour le demarrage--
  18. xPos = 0
  19. yPos = 0
  20.  
  21.  
  22. rednet.open("right")                --On active le reseau rednet avec le modem a droite
  23. local mon = peripheral.wrap("back") --On definit le moniteur avec le nom 'mon' deriere le PC
  24.  
  25.  
  26. function CurentState()
  27.     --Pour l'etat du reacteur--
  28.     rednet.broadcast("Etat?") --On difuse le message 'Etat?' a tous les PC connectés au reseau
  29.  
  30.     --On attend la reception d'une reponce du PC du reacteur--
  31.     ID, Message, Protocole = rednet.receive()
  32.     if (ID == IDre) and (Protocole == "Etat") then
  33.         Etat = Message
  34.     end
  35.  
  36. end
  37.  
  38. function Curent_Prod()
  39.  
  40.     rednet.broadcast("Prod?")
  41.  
  42.     ID, Message, Protocole = rednet.receive()
  43.     if (ID == IDre) and (Protocole == "Prod") then
  44.         Prod = Message
  45.     end
  46.  
  47. end
  48.  
  49. function Curent_Stor()
  50.     rednet.broadcast("Stor?")
  51.  
  52.     ID, Message, Protocole = rednet.receive()
  53.     if (ID == IDre) and (Protocole == "Stor") then
  54.         Stoc = Message
  55.     end
  56.  
  57. end
  58.  
  59. function Fuel_Amount()
  60.  
  61.     rednet.broadcast("Fuel?")
  62.  
  63.     ID, Message, Protocole = rednet.receive()
  64.     if (ID == IDre) and (Protocole == "Fuel") then
  65.         Fuel = (Message / 60000) * 10
  66.     end
  67.  
  68. end
  69.  
  70. function Curent_Temp()
  71.  
  72.     rednet.broadcast("Temp?")
  73.  
  74.     ID, Message, Protocole = rednet.receive()
  75.     if (ID == IDre) and (Protocole == "Temp") then
  76.         Temp = Message
  77.     end
  78.  
  79. end
  80.  
  81. function DrawButton()
  82.     mon.setTextColor(colors.black)
  83.     mon.setCursorPos(2,7)
  84.     mon.setBackgroundColor(colors.green)
  85.     mon.write("        ")
  86.     mon.setCursorPos(2,8)
  87.     mon.setBackgroundColor(colors.green)
  88.     mon.write("   On   ")
  89.     mon.setCursorPos(2,9)
  90.     mon.setBackgroundColor(colors.green)
  91.     mon.write("        ")
  92.     mon.setCursorPos(12,7)
  93.     mon.setBackgroundColor(colors.red)
  94.     mon.write("        ")
  95.     mon.setCursorPos(12,8)
  96.     mon.setBackgroundColor(colors.red)
  97.     mon.write("  STOP  ")
  98.     mon.setCursorPos(12,9)
  99.     mon.setBackgroundColor(colors.red)
  100.     mon.write("        ")
  101.     mon.setCursorPos(2,11)
  102.     mon.setBackgroundColor(colors.orange)
  103.     mon.write("        ")
  104.     mon.setCursorPos(2,12)
  105.     mon.setBackgroundColor(colors.orange)
  106.     mon.write("  Auto  ")
  107.     mon.setCursorPos(2,13)
  108.     mon.setBackgroundColor(colors.orange)
  109.     mon.write("        ")
  110.     mon.setCursorPos(12,11)
  111.     mon.setBackgroundColor(colors.magenta)
  112.     mon.write("        ")
  113.     mon.setCursorPos(12,12)
  114.     mon.setBackgroundColor(colors.magenta)
  115.     mon.write("  REBT  ")
  116.     mon.setCursorPos(12,13)
  117.     mon.setBackgroundColor(colors.magenta)
  118.     mon.write("        ")
  119.     mon.setBackgroundColor(colors.black)
  120. end
  121.  
  122. function Affichage()
  123.     mon.clear()
  124.     mon.setTextScale(1)
  125.     mon.setCursorPos(1,1)
  126.     if Etat == "On" then
  127.         mon.setTextColor(colors.green)
  128.     elseif Etat == "Off" then
  129.         mon.setTextColor(colors.red)
  130.     else
  131.         mon.setTextColor(colors.gray)
  132.     end
  133.     mon.write("Reactor "..Etat)
  134.     mon.setCursorPos(1,3)
  135.     mon.setTextColor(colors.orange)
  136.     mon.write("Prod : "..Prod.." RF/t")
  137.  
  138.     mon.setCursorPos(1,5)
  139.  
  140.     if Temp >= 2000 then
  141.         mon.setTextColor(colors.red)
  142.     elseif Temp >= 1500 then
  143.         mon.setTextColor(colors.orange)
  144.     elseif Temp >= 1000 then
  145.         mon.setTextColor(colors.yellow)
  146.     elseif Temp >= 500 then
  147.         mon.setTextColor(colors.green)
  148.     elseif Temp < 500 then
  149.         mon.setTextColor(colors.blue)
  150.     end
  151.  
  152.     mon.write("Temp : "..Temp.." C")
  153.     DrawButton()
  154.     DrawBargraph()
  155.  
  156.     mon.setCursorPos(1,15)
  157.     mon.setBackgroundColor(colors.black)
  158.     mon.setTextColor(colors.white)
  159.     mon.write("Log :")
  160.     mon.setCursorPos(2,17)
  161.     mon.write(">Etat precedant : "..Log)
  162.  
  163. end
  164.  
  165. function CliqueBouton()
  166.    
  167.     if (xPos >= 2 and xPos <= 10) and (yPos >= 7 and yPos <= 9) then
  168.         rednet.send(1,"On")
  169.         Log = 'On'
  170.     elseif (xPos >= 12 and xPos <= 20) and (yPos >= 7 and yPos <= 9) then
  171.         rednet.send(1,"Off")
  172.         Log = 'Off'
  173.     elseif (xPos >= 2 and xPos <= 10) and (yPos >= 11 and yPos <= 13) then
  174.         rednet.send(1,"Auto")
  175.         Log = 'Auto'
  176.     elseif (xPos >= 12 and xPos <= 20) and (yPos >= 11 and yPos <= 13) then
  177.         rednet.send(1,"REBT")
  178.         sleep(1)
  179.         os.reboot()
  180.     end
  181.  
  182. end
  183.  
  184. function Main()
  185.  
  186.     CurentState()
  187.     Curent_Prod()
  188.     Curent_Stor()
  189.     Curent_Temp()
  190.     Fuel_Amount()
  191.     Affichage()
  192.     sleep(0.1)
  193.     timer = os.startTimer(1)
  194.  
  195. end
  196.  
  197. function DrawBargraph()
  198.     mon.setCursorPos(24,1)
  199.     mon.setTextColor(colors.red)
  200.     mon.write("Stoc")
  201.     mon.setCursorPos(33,1)
  202.     mon.setTextColor(colors.yellow)
  203.     mon.write("Fuel")
  204.     mon.setCursorPos(24,2)
  205.     mon.setBackgroundColor(colors.white)
  206.     mon.write("     ")
  207.     mon.setCursorPos(33,2)
  208.     mon.setBackgroundColor(colors.white)
  209.     mon.write("     ")
  210.     mon.setCursorPos(24,3)
  211.     mon.setBackgroundColor(colors.white)
  212.     mon.write(" ")
  213.     mon.setCursorPos(33,3)
  214.     mon.setBackgroundColor(colors.white)
  215.     mon.write(" ")
  216.     mon.setCursorPos(28,3)
  217.     mon.setBackgroundColor(colors.white)
  218.     mon.write(" ")
  219.     mon.setCursorPos(37,3)
  220.     mon.setBackgroundColor(colors.white)
  221.     mon.write(" ")
  222.     mon.setCursorPos(29,3)
  223.     mon.setBackgroundColor(colors.black)
  224.     mon.setTextColor(colors.white)
  225.     mon.write("100%")
  226.     mon.setCursorPos(24,4)
  227.     mon.setBackgroundColor(colors.white)
  228.     mon.write(" ")
  229.     mon.setCursorPos(33,4)
  230.     mon.setBackgroundColor(colors.white)
  231.     mon.write(" ")
  232.     mon.setCursorPos(28,4)
  233.     mon.setBackgroundColor(colors.white)
  234.     mon.write(" ")
  235.     mon.setCursorPos(37,4)
  236.     mon.setBackgroundColor(colors.white)
  237.     mon.write(" ")
  238.     mon.setCursorPos(24,5)
  239.     mon.setBackgroundColor(colors.white)
  240.     mon.write(" ")
  241.     mon.setCursorPos(33,5)
  242.     mon.setBackgroundColor(colors.white)
  243.     mon.write(" ")
  244.     mon.setCursorPos(28,5)
  245.     mon.setBackgroundColor(colors.white)
  246.     mon.write(" ")
  247.     mon.setCursorPos(37,5)
  248.     mon.setBackgroundColor(colors.white)
  249.     mon.write(" ")
  250.     mon.setCursorPos(24,6)
  251.     mon.setBackgroundColor(colors.white)
  252.     mon.write(" ")
  253.     mon.setCursorPos(33,6)
  254.     mon.setBackgroundColor(colors.white)
  255.     mon.write(" ")
  256.     mon.setCursorPos(28,6)
  257.     mon.setBackgroundColor(colors.white)
  258.     mon.write(" ")
  259.     mon.setCursorPos(37,6)
  260.     mon.setBackgroundColor(colors.white)
  261.     mon.write(" ")
  262.     mon.setCursorPos(24,7)
  263.     mon.setBackgroundColor(colors.white)
  264.     mon.write(" ")
  265.     mon.setCursorPos(33,7)
  266.     mon.setBackgroundColor(colors.white)
  267.     mon.write(" ")
  268.     mon.setCursorPos(28,7)
  269.     mon.setBackgroundColor(colors.white)
  270.     mon.write(" ")
  271.     mon.setCursorPos(37,7)
  272.     mon.setBackgroundColor(colors.white)
  273.     mon.write(" ")
  274.     mon.setCursorPos(29,8)
  275.     mon.setBackgroundColor(colors.black)
  276.     mon.setTextColor(colors.white)
  277.     mon.write("50%")
  278.     mon.setCursorPos(24,8)
  279.     mon.setBackgroundColor(colors.white)
  280.     mon.write(" ")
  281.     mon.setCursorPos(33,8)
  282.     mon.setBackgroundColor(colors.white)
  283.     mon.write(" ")
  284.     mon.setCursorPos(28,8)
  285.     mon.setBackgroundColor(colors.white)
  286.     mon.write(" ")
  287.     mon.setCursorPos(37,8)
  288.     mon.setBackgroundColor(colors.white)
  289.     mon.write(" ")
  290.     mon.setCursorPos(24,9)
  291.     mon.setBackgroundColor(colors.white)
  292.     mon.write(" ")
  293.     mon.setCursorPos(33,9)
  294.     mon.setBackgroundColor(colors.white)
  295.     mon.write(" ")
  296.     mon.setCursorPos(28,9)
  297.     mon.setBackgroundColor(colors.white)
  298.     mon.write(" ")
  299.     mon.setCursorPos(37,9)
  300.     mon.setBackgroundColor(colors.white)
  301.     mon.write(" ")
  302.     mon.setCursorPos(24,10)
  303.     mon.setBackgroundColor(colors.white)
  304.     mon.write(" ")
  305.     mon.setCursorPos(33,10)
  306.     mon.setBackgroundColor(colors.white)
  307.     mon.write(" ")
  308.     mon.setCursorPos(28,10)
  309.     mon.setBackgroundColor(colors.white)
  310.     mon.write(" ")
  311.     mon.setCursorPos(37,10)
  312.     mon.setBackgroundColor(colors.white)
  313.     mon.write(" ")
  314.     mon.setCursorPos(24,11)
  315.     mon.setBackgroundColor(colors.white)
  316.     mon.write(" ")
  317.     mon.setCursorPos(33,11)
  318.     mon.setBackgroundColor(colors.white)
  319.     mon.write(" ")
  320.     mon.setCursorPos(28,11)
  321.     mon.setBackgroundColor(colors.white)
  322.     mon.write(" ")
  323.     mon.setCursorPos(37,11)
  324.     mon.setBackgroundColor(colors.white)
  325.     mon.write(" ")
  326.     mon.setCursorPos(24,12)
  327.     mon.setBackgroundColor(colors.white)
  328.     mon.write(" ")
  329.     mon.setCursorPos(33,12)
  330.     mon.setBackgroundColor(colors.white)
  331.     mon.write(" ")
  332.     mon.setCursorPos(28,12)
  333.     mon.setBackgroundColor(colors.white)
  334.     mon.write(" ")
  335.     mon.setCursorPos(37,12)
  336.     mon.setBackgroundColor(colors.white)
  337.     mon.write(" ")
  338.     mon.setCursorPos(29,12)
  339.     mon.setBackgroundColor(colors.black)
  340.     mon.setTextColor(colors.white)
  341.     mon.write("10%")
  342.     mon.setCursorPos(24,13)
  343.     mon.setBackgroundColor(colors.white)
  344.     mon.write("     ")
  345.     mon.setCursorPos(33,13)
  346.     mon.setBackgroundColor(colors.white)
  347.     mon.write("     ")
  348.  
  349.     GRST = (Stoc / 10000000) * 10
  350.     if GRST >= 1 then
  351.         mon.setCursorPos(25,12)
  352.         mon.setBackgroundColor(colors.red)
  353.         mon.write("   ")
  354.     end
  355.     if GRST >= 2 then
  356.         mon.setCursorPos(25,11)
  357.         mon.setBackgroundColor(colors.red)
  358.         mon.write("   ")
  359.     end
  360.     if GRST >= 3 then
  361.         mon.setCursorPos(25,10)
  362.         mon.setBackgroundColor(colors.red)
  363.         mon.write("   ")
  364.     end
  365.     if GRST >= 4 then
  366.         mon.setCursorPos(25,9)
  367.         mon.setBackgroundColor(colors.red)
  368.         mon.write("   ")
  369.     end
  370.     if GRST >= 5 then
  371.         mon.setCursorPos(25,8)
  372.         mon.setBackgroundColor(colors.red)
  373.         mon.write("   ")
  374.     end
  375.     if GRST >= 6 then
  376.         mon.setCursorPos(25,7)
  377.         mon.setBackgroundColor(colors.red)
  378.         mon.write("   ")
  379.     end
  380.     if GRST >= 7 then
  381.         mon.setCursorPos(25,6)
  382.         mon.setBackgroundColor(colors.red)
  383.         mon.write("   ")
  384.     end
  385.     if GRST >= 8 then
  386.         mon.setCursorPos(25,5)
  387.         mon.setBackgroundColor(colors.red)
  388.         mon.write("   ")
  389.     end
  390.     if GRST >= 9 then
  391.         mon.setCursorPos(25,4)
  392.         mon.setBackgroundColor(colors.red)
  393.         mon.write("   ")
  394.     end
  395.     if GRST >= 10 then
  396.         mon.setCursorPos(25,3)
  397.         mon.setBackgroundColor(colors.red)
  398.         mon.write("   ")
  399.     end
  400.  
  401.     if Fuel >= 1 then
  402.         mon.setCursorPos(34,12)
  403.         mon.setBackgroundColor(colors.yellow)
  404.         mon.write("   ")
  405.     end
  406.     if Fuel >= 2 then
  407.         mon.setCursorPos(34,11)
  408.         mon.setBackgroundColor(colors.yellow)
  409.         mon.write("   ")
  410.     end
  411.     if Fuel >= 3 then
  412.         mon.setCursorPos(34,10)
  413.         mon.setBackgroundColor(colors.yellow)
  414.         mon.write("   ")
  415.     end
  416.     if Fuel >= 4 then
  417.         mon.setCursorPos(34,9)
  418.         mon.setBackgroundColor(colors.yellow)
  419.         mon.write("   ")
  420.     end
  421.     if Fuel >= 5 then
  422.         mon.setCursorPos(34,8)
  423.         mon.setBackgroundColor(colors.yellow)
  424.         mon.write("   ")
  425.     end
  426.     if Fuel >= 6 then
  427.         mon.setCursorPos(34,7)
  428.         mon.setBackgroundColor(colors.yellow)
  429.         mon.write("   ")
  430.     end
  431.     if Fuel >= 7 then
  432.         mon.setCursorPos(34,6)
  433.         mon.setBackgroundColor(colors.yellow)
  434.         mon.write("   ")
  435.     end
  436.     if Fuel >= 8 then
  437.         mon.setCursorPos(34,5)
  438.         mon.setBackgroundColor(colors.yellow)
  439.         mon.write("   ")
  440.     end
  441.     if Fuel >= 9 then
  442.         mon.setCursorPos(34,4)
  443.         mon.setBackgroundColor(colors.yellow)
  444.         mon.write("   ")
  445.     end
  446.     if Fuel >= 10 then
  447.         mon.setCursorPos(34,3)
  448.         mon.setBackgroundColor(colors.yellow)
  449.         mon.write("   ")
  450.     end
  451.     mon.setBackgroundColor(colors.black)
  452. end
  453.  
  454. while true do
  455.  
  456.     event, button, xPos, yPos = os.pullEvent()
  457.     if event == "monitor_touch" then
  458.         CliqueBouton()
  459.     elseif event == "timer" and button == timer then
  460.         Main()
  461.         xPos = 0
  462.         yPos = 0
  463.     elseif event == "timer" and button == rebot then
  464.         os.reboot()
  465.     end
  466.  
  467. end
  468.  
Add Comment
Please, Sign In to add comment