Advertisement
Nightmare129

ecran_testG

Feb 3rd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.76 KB | None | 0 0
  1. --config
  2. rednet.open("left")
  3. local ecran=peripheral.wrap("top")
  4. local ecranR=peripheral.wrap("monitor_8")
  5. local nbm = 8 --1 a 8
  6.  
  7. local data100={} --pour reactor
  8. local data={}    --pour les turbins
  9. data[1]={}
  10. data[2]={}
  11. data[3]={}
  12. data[4]={}
  13. data[5]={}
  14. data[6]={}
  15. data[7]={}
  16. data[8]={}
  17. windows = {}
  18. windows[1] = window.create(m, 1 , 2 , 5, 5, true)
  19. windows[2] = window.create(m, 50, 2 , 5, 5, true)
  20. windows[3] = window.create(m, 1 , 11, 5, 5, true)
  21. windows[4] = window.create(m, 50, 11, 5, 5, true)
  22. windows[5] = window.create(m, 1 , 21, 5, 5, true)
  23. windows[6] = window.create(m, 50, 21, 5, 5, true)
  24. windows[7] = window.create(m, 1 , 31, 5, 5, true)
  25. windows[2] = window.create(m, 50, 31, 5, 5, true)
  26.  
  27. local turb
  28. local k=0
  29.  
  30. -- function de recuperation des infos envoye en wifi
  31. function Ecoute()
  32.     while true do
  33.         local event, id, ID, TablData = os.pullEvent("rednet_message")
  34.   if ID>=1 and  ID<=8 then
  35.    --print(ID)
  36.             data[ID]=textutils.unserialize(TablData)  
  37.         elseif ID==100 then
  38.             data100=textutils.unserialize(TablData)
  39.         end
  40.     end
  41. end
  42.  
  43. function Affichage()
  44. --chargement
  45.     ecran.setBackgroundColor(colors.blue)
  46.     ecran.clear()
  47.     line(30 ,20,10 ,1, colors.black)
  48.     local cpt=1
  49.     for cpt=1, 10 do
  50.         line(30 ,20 ,cpt ,1, colors.green)
  51.         os.sleep(0.3)
  52.     end
  53.     os.sleep(0.5)
  54.     ecran.setBackgroundColor(colors.black)
  55.     ecran.clear()
  56.     AffichageTurbine()
  57.     AffichageReactor()
  58. end
  59.  
  60. -- function d'affichage les donners des turbines
  61. function AffichageTurbine()
  62.  
  63.     k=k+1
  64.     if k == 5 then k = 1 end
  65.         local i=1
  66.         for i=1,nbm do --data[1] a data[8]
  67.            --print(i)      
  68.             --chois de la position
  69.             local x=1 y=1
  70.             if i==1 then x=1 y=1
  71.             elseif i==2 then x=1  y=50
  72.             elseif i==3 then x=10 y=1          
  73.             elseif i==4 then x=10 y=50
  74.             elseif i==5 then x=20 y=1      
  75.             elseif i==6 then x=20 y=50
  76.             elseif i==7 then x=30 y=1
  77.             elseif i==8 then x=30 y=50
  78.             end
  79.                
  80.             --debut de l'affiche+5
  81.             ecran.setTextColor(colors.white)
  82.             ecran.setCursorPos(y,x)   --**--
  83.             ecran.write("Turbine "..i)
  84.             --l'activiter
  85.             if data[i]["gActive"]==true then
  86.                 turb = paintutils.loadImage("turb"..k)
  87.             else
  88.                 turb = paintutils.loadImage("turb0")
  89.             end
  90.             windows[i].setBackgroundColor(colors.black)
  91.             windows[i].setTextColor(colors.black)
  92.             windows[i].clear()
  93.             term.redirect(windows[i])
  94.             paintutils.drawImage(turb, 1, 1)
  95.            
  96.             --l'engagement
  97.             if data[i]["gInductor"]==true then
  98.                 line(y+10 ,x+1+5 ,7 ,1, colors.green)
  99.                 ecran.setCursorPos(y+10,x+1)
  100.                 ecran.write("Engager")
  101.                 ecran.setBackgroundColor(colors.black)
  102.                 ecran.write("   ")
  103.             else
  104.                 line(y+10 ,x+1+5 ,10 ,1, colors.red)
  105.                 ecran.setCursorPos(y+10,x+1)
  106.                 ecran.write("Desengager")
  107.                 ecran.setBackgroundColor(colors.black)
  108.             end
  109.             --la vitesse du Rotor
  110.             ecran.setTextColor(colors.white)
  111.             ecran.setCursorPos(y,x+2+5)  --**--
  112.             ecran.write("Rotor : ")
  113.                
  114.             if data[i]["gSpeed"]<800 then
  115.                 ecran.setTextColor(colors.red)
  116.             elseif data[i]["gSpeed"]<1000 then
  117.                 ecran.setTextColor(colors.blue)
  118.             elseif data[i]["gSpeed"]<1700 then
  119.                 ecran.setTextColor(colors.red)
  120.             elseif data[i]["gSpeed"]<1900 then
  121.                 ecran.setTextColor(colors.blue)
  122.             else
  123.                 ecran.setTextColor(colors.red)
  124.             end
  125.             ecran.setCursorPos(y+8,x+2+5)
  126.             ecran.write(number_format(data[i]["gSpeed"]).." RPM     ")
  127.                
  128.             ecran.setTextColor(colors.white)
  129.             ecran.setCursorPos(y,x+3+5)  --**--
  130.             ecran.write("Prod  : "..number_format(data[i]["gProductLastTick"]).." RF/t     ")
  131.                
  132.             ecran.setCursorPos(y,x+4+5)  --**--
  133.             ecran.write("Buffer : "..number_format(data[i]["gBuffer"]).." RF      ")
  134.             ecran.setCursorPos(y+20,x+4+5)
  135.             ecran.write(math.ceil(data[i]["gBuffer"]/10000).."%  ")
  136.                
  137.             os.sleep(0.5)
  138.         end
  139.     end
  140. end
  141.  
  142. -- function d'affichage des donners du rector
  143. function AffichageReactor()
  144.     local y=27 x=1
  145.     while true do
  146.         --affichage de l'activiter
  147.         ecran.setCursorPos(y,x)
  148.         ecran.write("Reactor")
  149.         if data100["gActive"]==true then
  150.             line(y ,x+1 ,6 ,1, colors.green)
  151.             ecran.setCursorPos(y,x+1)
  152.             ecran.write("Active")
  153.             ecran.setBackgroundColor(colors.black)
  154.             ecran.write("   ")
  155.         else
  156.             line(y+8 ,x+1 ,8 ,1, colors.red)
  157.             ecran.setCursorPos(y,x+1)
  158.             ecran.write("Desactive ")
  159.             ecran.setBackgroundColor(colors.black)
  160.         end
  161.        
  162.         --affichage des donnes
  163.         ecran.setTextColor(colors.white)
  164.         ecran.setCursorPos(y,x+2) --le stock de yell en ingot
  165.         ecran.write("Fuel   : "..number_format(data100["gFuelAmount"]/1000).." yell")
  166.         ecran.setCursorPos(y,x+3) --le stock de yell en %
  167.         ecran.write("Stock  : "..math.ceil(data100["gFuelAmount"]/data100["gFuelAmountMax"]*100).."%")
  168.         ecran.setCursorPos(y,x+4) --production en mb/t
  169.         ecran.write("Prod   : "..number_format(data100["gHotFluidProducedLastTick"]).." mb/t   ")
  170.         ecran.setCursorPos(y,x+5) --comsomation de yell en mb
  171.         ecran.write("Conso  : "..number_format(data100["gFuelConsumedLastTick"]))
  172.         ecran.setCursorPos(y+16,x+5)
  173.         ecran.write(" mb/t de yell")
  174.         ecran.setCursorPos(y,x+6) --temperature en C
  175.         ecran.write("temp   : "..number_format(data100["gCasingtemperature"]).." C  ")
  176.         ecran.setCursorPos(y,x+7) --reactiviter %
  177.         ecran.write("reacti : "..number_format(data100["gFuelReactivity"]).." %  ")
  178.        
  179.         -- affichage de l'etat des rods
  180.         for i=1,data["gNumberRods"] do
  181.             ecran.setCursorPos(y,x+i+7)
  182.             ecran.write("Rod "..i.." : ")
  183.             ecran.setCursorPos(y+8,x+i+7)
  184.             ecran.write(data100["gControlRodLevel"..i].."%")
  185.         end
  186.         os.sleep(0.5)
  187.     end
  188. end
  189.  
  190. function onoff()
  191. local type
  192. local a
  193.     while true do
  194.         local e, bt, xp, yp = os.pullEvent("monitor_touch")
  195.         if bt=="top" then
  196.         if (yp<8 and xp==2 ) then
  197.             type ="turbin 1" a="actif"
  198.         elseif xp>10 and xp<18 and yp==2 then
  199.             type ="turbin 1" a="engag"
  200.         elseif xp<8 and yp==9 then
  201.             type ="turbin 2" a="actif"
  202.         elseif xp>10 and xp<18 and yp==9 then
  203.             type ="turbin 1" a="engag"
  204.         --elseif xp<8 and yp==16 then
  205.         --  type ="turbin 3"
  206.         --elseif xp>27 and xp<35 and yp==2 then
  207.         --  type ="turbin 4"
  208.         --elseif xp>27 and xp<35 and yp==9 then
  209.         --  type ="turbin 5"
  210.         --elseif xp>27 and xp<35 and yp==16 then
  211.         --  type ="turbin 6"
  212.         end
  213.         rednet.broadcast(type,a)
  214.         os.sleep(0.5)
  215.         end
  216.     end
  217. end
  218.  
  219. function onoffR()
  220. local type
  221.     while true do
  222.         local e, bt, xp, yp = os.pullEvent("monitor_touch")
  223.         if bt=="monitor_8" then
  224.             if yp==2 then
  225.                 type ="reactor"
  226.             elseif yp==9  then
  227.                 type ="rod 1 +"
  228.             elseif yp==10 then
  229.                 type ="rod 2 +"
  230.             end
  231.             rednet.broadcast(type)
  232.             os.sleep(0.5)
  233.         end
  234.     end
  235. end
  236.  
  237. --crestion de rectangle de couleur
  238. function line(x ,y ,long ,larg, color_font)
  239.     ecran.setBackgroundColor(color_font)
  240.     for yp=y, y+larg-1 do
  241.         ecran.setCursorPos(x,yp)
  242.         ecran.write(string.rep(" ", long))
  243.     end
  244. end
  245.  
  246. --bar de progresion
  247. function prog(x ,y ,long ,larg, valmin, valmax ,color_bar ,color_font)
  248.     line(x ,y ,long ,larg, color_font)
  249.     local bar = math.floor((valmin/valmax)*long)
  250.     line(x ,y ,bar ,larg, color_bar)
  251. end
  252.  
  253. -- function pour transformer 9876543 en 9 876 543
  254. function number_format(n)
  255.   local test=mille(n)
  256.   if test.Mille==0 then
  257.     return math.floor(n)
  258.   else
  259.     test.Mille=mille(test.Mille)
  260.     if test.Mille.Mille==0 then
  261.       return test.Mille.Cent.." "..cent(test.Cent)
  262.     else
  263.       return test.Mille.Mille.." "..cent(test.Mille.Cent).." "..cent(test.Cent)
  264.     end
  265.   end
  266. end
  267.  
  268. -- function pour etre sur d'avoir trois chiffre (99 devient 099, 9 devient 009)
  269. function cent(n)
  270.   n=math.floor(n)
  271.   if n>99 then
  272.     return n
  273.    elseif n>9 then
  274.     return "0"..n
  275.    else
  276.     return "00"..n
  277.    end
  278. end
  279.  
  280. -- creer un objet avec les centaine d'un cotåA9 les millier de l'autre
  281. function mille(n)
  282.   if n<1000 then
  283.     return {Mille=0,Cent=n}
  284.   else
  285.     return {Mille=math.floor(n/1000),Cent=n%1000}
  286.   end
  287. end
  288.  
  289. parallel.waitForAll(Ecoute,Affichage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement