Advertisement
Nightmare129

ecran_testT

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