Advertisement
Nightmare129

ecran_testT+R

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