Nike622000

MFSU NEW

Nov 16th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.17 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. local monSide = "back"
  4. local Rside   = "left"
  5. local Sensor  = "top"
  6. local OPD     = "front"
  7.  
  8. local Stat    = true
  9.  
  10. mon = peripheral.wrap(monSide)
  11. mon.setTextScale(.5)
  12.  
  13. local xMax,yMax = mon.getSize()
  14.  
  15. function Background(col)
  16.   mon.setBackgroundColor(col)
  17.   for xPos = 1,xMax do
  18.     for yPos = 1,yMax do
  19.       mon.setCursorPos(xPos,yPos)
  20.       mon.write(" ")
  21.     end
  22.   end
  23. end
  24.  
  25. function JoJa(xPos,yPos)
  26.   mon.setCursorPos(xPos,yPos)
  27.   mon.setBackgroundColor(colors.gray)
  28.   mon.setTextColor(colors.cyan)
  29.   mon.write("Jo")
  30.   mon.setTextColor(colors.orange)
  31.   mon.write("Ja ")
  32.   mon.setTextColor(colors.lightGray)
  33.   mon.write("Productions")
  34.   mon.setBackgroundColor(colors.gray)
  35.   mon.setTextColor(colors.white)
  36. end
  37.  
  38. function edge(startPosX,startPosY,endPosX,endPosY)
  39.   mon.setBackgroundColor(colors.gray)
  40.   for xPos = startPosX,endPosX do
  41.     mon.setCursorPos(xPos,startPosY)
  42.     mon.write(" ")
  43.     mon.setCursorPos(xPos,endPosY)
  44.     mon.write(" ")
  45.   end
  46.   for yPos = startPosY,endPosY do
  47.     mon.setCursorPos(startPosX,yPos)
  48.     mon.write(" ")
  49.     mon.setCursorPos(endPosX,yPos)
  50.     mon.write(" ")
  51.   end
  52. end
  53.  
  54. function overlay(xPos,yPos,text)
  55.   mon.setBackgroundColor(colors.black)
  56.   mon.setCursorPos(xPos,yPos)
  57.   mon.write(text)
  58. end
  59.  
  60. function checkMFSU()
  61.   Anzahl = 1
  62.   Speicher = {}
  63.   sen = sensor.wrap(Sensor)
  64.   for a,b in pairs(sen.getTargets()) do
  65.     for k,v in pairs(sen.getTargetDetails(a)) do
  66.       if type(v) == "table" then
  67.       else
  68.    
  69.         if k == "StoredPercentage" then
  70.           Speicher[Anzahl] = v
  71.           Anzahl = Anzahl+1
  72.         end
  73.       end
  74.     end
  75.   end
  76. end  
  77.  
  78. function graph(xStart,xEnd,yPos,Percentage,col1,col2)
  79.   for xPos = xStart,xEnd do
  80.     mon.setBackgroundColor(col1)
  81.     mon.setCursorPos(xPos,yPos)
  82.     mon.write(" ")
  83.   end
  84.   Width = ((xEnd-xStart)*Percentage)/100
  85.   for xPos = xStart,xStart+Width do
  86.     mon.setCursorPos(xPos,yPos)
  87.     mon.setBackgroundColor(col2)
  88.     mon.write(" ")
  89.   end    
  90. end
  91.  
  92. function Button(xP1,yP1,xP2,yP2,txt1,txt2,col)
  93.   mon.setBackgroundColor(col)
  94.   for xPos = xP1,xP2 do
  95.     for yPos = yP1,yP2 do
  96.       mon.setCursorPos(xPos,yPos)
  97.       mon.write(" ")
  98.     end
  99.   end
  100.   mon.setCursorPos((xP1+((xP2-xP1)/2))-#txt1/2,(yP1+(yP2-yP1)/2))
  101.   mon.write(txt1)
  102.   mon.setCursorPos((xP1+((xP2-xP1)/2))-#txt2/2,(yP1+1+(yP2-yP1)/2))
  103.   mon.write(txt2)
  104.   mon.setBackgroundColor(colors.black)
  105. end
  106.  
  107. function checkButton()
  108.   os.startTimer(10)
  109.   event,_,xPos,yPos = os.pullEvent()
  110.   if event == "monitor_touch"
  111.   and xPos >= 49 and xPos <= 61
  112.   and yPos >= 24 and yPos <= 29
  113.   then
  114.     Stat = true
  115.   elseif event == "monitor_touch"
  116.   and xPos >= 64 and xPos <= 79
  117.   and xPos >= 24 and yPos <= 29
  118.   then
  119.     Stat = false
  120.   end
  121.   print(Stat)
  122. end
  123.  
  124. while true do
  125.  
  126.   checkMFSU()
  127.  
  128.   MaxOutput = #Speicher * 512
  129.   Kapazitaet = #Speicher * 10000000
  130.   Background(colors.black)
  131.   JoJa(xMax/2-7,1)
  132.   edge(2,3,45,yMax-1)
  133.   edge(47,3,xMax-1,20)
  134.   edge(47,22,xMax-1,yMax-1)
  135.   overlay(4,3," Info ")
  136.   overlay(49,3," Data ")
  137.   overlay(49,22," Menu ")
  138.   overlay(50,5,"MaxOutput: "..MaxOutput.." Eu/t")
  139.   overlay(50,7,"Kapazitaet: "..Kapazitaet.." Eu")
  140.   overlay(50,11,"Stromfluss: ")
  141.   if Stat then
  142.     mon.setTextColor(colors.cyan)
  143.     mon.write("aktiviert")
  144.   else
  145.     mon.setTextColor(colors.orange)
  146.     mon.write("deaktiviert")
  147.   end
  148.   mon.setTextColor(colors.white)
  149.  
  150.   F = 0
  151.   for i = 1,#Speicher do
  152.     F = F+Speicher[i]  
  153.   end
  154.   F = math.floor(F/#Speicher)
  155.  
  156.   overlay(50,9,"Gefuellt: "..F.." %")
  157.  
  158.   A = #Speicher
  159.  
  160.   if A > 10 then
  161.     B = A-10
  162.     A = 10
  163.   end
  164. --print(B)
  165.  
  166.   for i = 1,A do
  167.     overlay(4,2+3*i,"MFSU "..i.." ")
  168.     graph(4,22,3+3*i,Speicher[i],colors.lightGray,colors.lime)
  169.   end
  170.   if B ~= nil then
  171.     for l = 1,B do
  172.       overlay(24,2+3*l,"MFSU "..10+l.." ")
  173.       graph(24,43,3+3*l,Speicher[10+l],colors.lightGray,colors.lime)
  174.     end
  175.   end
  176.  
  177.   Button(49,24,61,29,"Stromfluss","aktivieren",colors.cyan)
  178.   Button(64,24,76,29,"Stromfluss","deaktivieren",colors.orange)
  179.  
  180.   checkButton()
  181.   if Stat then
  182.     rs.setOutput(Rside,true)
  183.   else
  184.     rs.setOutput(Rside,false)
  185.   end
  186. end
Advertisement
Add Comment
Please, Sign In to add comment