Advertisement
Guest User

Factory Simple monitor

a guest
Apr 4th, 2020
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.91 KB | None | 0 0
  1. local component = require( "component" )
  2. local math = require("math")
  3. local gpu = component.gpu
  4. local event = require("event")
  5. local ref = component.ie_refinery
  6. local squ = component.ie_squeezer
  7. local fer = component.ie_fermenter
  8. local gen = component.ie_diesel_generator
  9. local red = component.redstone
  10. local lowcap = component.ie_lv_capacitor
  11. local excav = component.ie_excavator
  12. local crusher1 = component.proxy("e16d28e5-8ceb-47ad-af31-25f2437de491")
  13. local crusher2 = component.proxy("e16d28e5-8ceb-47ad-af31-25f2437de491")
  14. local capacitor1 = component.proxy("96a19d23-86ab-4f97-a21e-1d8f6c1906f0")
  15. local capacitor2 = component.proxy("429ee133-1889-4fdc-912c-680998dbf300")
  16. local computer = component.computer
  17.  
  18. computer.beep()
  19. gpu.fill(1,1,130,30," ")
  20.  
  21. -- Functions
  22. local function getClick(_, _, x, y, _, _)
  23. if (x > 104) and (y > 9) and (x < 112) and (y < 13) then os.execute("/home/power.lua")
  24. elseif (x > 116) and (y > 9) and (x < 122) and (y < 13) then os.execute("/home/panel.lua") end
  25. end
  26.  
  27. local function mathround(number)
  28.    decimals = 10^(0)
  29.    return math.floor(number * decimals + (0.5))/ decimals
  30. end
  31.  
  32. --Passive Titles
  33. --these first two is the virtual buttons being drawn on screen which the function getClick will check if the touch is inside them
  34. gpu.setBackground(0xFF0000)
  35. gpu.fill(105,10,4,2," ")
  36. gpu.setBackground(0x008000)
  37. gpu.fill(117,10,4,2," ")
  38. gpu.setBackground(0x000000)
  39. gpu.set(113,8,"Control Panel")
  40. gpu.setResolution(130,30)
  41. gpu.set(111,1,"WIP fratty75")
  42. gpu.set(106,2,"Redstone Signal Strength")
  43. gpu.set(104,8,"Reboot")
  44.  
  45. -- Panel Titles
  46. gpu.setForeground(0xFF00FF)
  47. gpu.set(5,12,"Crusher Panel")
  48. gpu.set(77,24,"Refinery Panel")
  49. gpu.set(1,24,"Squeezer Panel")
  50. gpu.set(26,24,"Fermenter Panel")
  51. gpu.set(109,17,"Capacitor Panel")
  52. gpu.set(1,1,"Generator Panel")
  53. gpu.set(52,24,"Excavator Panel")
  54. gpu.setForeground(0xFFFFFF)
  55.  
  56. -- Machine Titles
  57. gpu.setForeground(0xF8F8FF)
  58. gpu.set(1,14,"Crusher 1")
  59. gpu.set(14,14,"Crusher 2")
  60. gpu.setForeground(0xFF4500)
  61. gpu.set(103,21,"Medium Voltage")
  62. gpu.set(103,25,"Medium Voltage")
  63. gpu.setForeground(0x00FFFF)
  64. gpu.set(103,29,"Low Volatage")
  65.  
  66. --Max Titles
  67. gpu.setForeground(0xFF0000)
  68. gpu.set(77,26,"Max Power:")
  69. gpu.set(1,16,"Max:")
  70. gpu.set(14,16,"Max:")
  71. gpu.set(1,26,"Max Power:")
  72. gpu.set(26,26,"Max Power:")
  73. gpu.set(52,26,"Max Power:")
  74.  
  75. --More passive Titles
  76. gpu.setForeground(0xF8F8FF)
  77. gpu.set(1,19,"Current:")
  78. gpu.set(14,19,"Current:")
  79. gpu.set(1,29,"Current Power:")
  80. gpu.set(26,29,"Current Power:")
  81. gpu.set(77,29,"Current Power:")
  82. gpu.set(52,29,"Current Power:")
  83. gpu.set(103,20,"Current Power in Capacitor 1")
  84. gpu.set(103,24,"Current Power in Capacitor 2")
  85. gpu.set(103,28,"Current Power in Capacitor 3")  
  86. gpu.setForeground(0x00FF00)
  87. gpu.set(42,29,"Active:")  
  88. gpu.set(17,29,"Active:")
  89. gpu.set(68,29,"Active:")
  90. gpu.set(18,6,"Active")
  91. gpu.setForeground(0x8B4513)
  92. gpu.set(1,3,"Internal Tank")
  93. gpu.set(1,5,"Capacity:")
  94. gpu.set(1,7,"Current:")
  95.  
  96. event.listen("touch", getClick)
  97.  
  98. while true do    
  99.    
  100.  
  101.     --Calls
  102.     local squeezermax = tostring(squ.getMaxEnergyStored())
  103.     local squeezercurrent = tostring(squ.getEnergyStored())
  104.     local fermentermax = tostring(fer.getMaxEnergyStored())
  105.     local fermentercurrent = tostring(fer.getEnergyStored())
  106.     local excavatormax = tostring(excav.getMaxEnergyStored())
  107.     local excavatorcurrent = tostring(excav.getEnergyStored())    
  108.     local crushMS = tostring(crusher1.getMaxEnergyStored())    
  109.     local crushCS = tostring(crusher1.getEnergyStored())
  110.     local refinerymax = tostring(ref.getMaxEnergyStored())
  111.     local refinerycurrent = tostring(ref.getEnergyStored())
  112.     local crushM2S = tostring(crusher2.getMaxEnergyStored())
  113.     local crushC2S = tostring(crusher2.getEnergyStored())
  114.     local statusgenerator = tostring(gen.isActive())
  115.     local statussqueezer = tostring(squ.isActive())
  116.     local statusfermenter = tostring(fer.isActive())
  117.     local statusexcavator = tostring(excav.isActive())
  118.     local cap1P = capacitor1.getEnergyStored()
  119.     local cap1M = capacitor1.getMaxEnergyStored()
  120.     local cap2M = capacitor2.getMaxEnergyStored()
  121.     local cap1PS = tostring(cap1P)
  122.     local cap2P = capacitor2.getEnergyStored()
  123.     local cap2PS = tostring(cap2P)
  124.     local lowcapP = tostring(lowcap.getEnergyStored())
  125.     local generatortankCapacity = gen.getTankInfo()["capacity"]
  126.     local generatortankCapacityS = tostring(generatortankCapacity)
  127.     local generatortankAmount = gen.getTankInfo()["amount"]
  128.     local generatortankAmountS = tostring(generatortankAmount)
  129.     local red1 = component.proxy("e99223fa-90e2-4287-913d-9bb93e56c837").getInput(5)
  130.     local red2 = tostring(red1)
  131.  
  132.     --Graph 1
  133.     gpu.setBackground(0x808080)
  134.     local setx = 29
  135.     local sety = 3
  136.     local setextx = 30
  137.     local setexty = 3
  138.     gpu.fill(setx,sety,setextx,setexty," ")    
  139.     local graphx = (setx + 1)
  140.     local graphy = (sety + 1)
  141.     local graphextx = (setextx - 2)
  142.     local graphexty = (setexty - 2)
  143.     local yom = ((graphextx*generatortankAmount/generatortankCapacity))
  144.     local generatorpercent = mathround(((generatortankAmount/generatortankCapacity)*100))
  145.     gpu.set(29,7,"Tank is " ..generatorpercent.. "% full")
  146.     gpu.setBackground(0x8B4513)
  147.     gpu.fill(graphx, graphy, yom, graphexty," ")
  148.     gpu.setBackground(0x000000)
  149.    
  150.     --Graph 2
  151.     gpu.setBackground(0xFFFFFF)
  152.     local setx2 = 29
  153.     local sety2 = 13
  154.     local setextx2 = 30
  155.     local setexty2 = 3
  156.     gpu.set(59,14," ")
  157.     gpu.fill(setx2,sety2,setextx2,setexty2," ")
  158.     local graphx2 = setx2 + 1
  159.     local graphy2 = sety2 + 1
  160.     local graphextx2 = setextx2 - 2
  161.     local graphexty2 = setexty2 - 2
  162.     local yom2 = ((graphextx2*cap1P)/cap1M)
  163.     local capacitor1percent = mathround(((cap1P/cap1M)*100))
  164.     gpu.setBackground(0x00FF00)
  165.     gpu.fill(graphx2, graphy2, yom2, graphexty2, " ")
  166.     gpu.setBackground(0x000000)
  167.     gpu.set(29,17,"Capacitor 1 is " ..capacitor1percent.. "% full")
  168.  
  169.     --Graph 3
  170.     gpu.setBackground(0xFFFFFF)
  171.     local setx3 = 69
  172.     local sety3 =  13
  173.     local setextx3 = 30
  174.     local setexty3 = 3
  175.     gpu.set(99,14," ")
  176.     gpu.fill(setx3,sety3,setextx3,setexty3," ")
  177.     local graphx3 = setx3 + 1
  178.     local graphy3 =  sety3 + 1
  179.     local graphextx3 = setextx3 - 2
  180.     local graphexty3 = setexty3 - 2
  181.     local yom3 = ((graphextx3*cap2P)/cap2M)
  182.     local capacitor2percent = mathround(((cap2P/cap2M)*100))
  183.     gpu.setBackground(0x00FF00)
  184.     gpu.fill(graphx3,graphy3,yom3,graphexty3," ")
  185.     gpu.setBackground(0x000000)
  186.     gpu.set(69,17,"Capacitor 2 is " ..capacitor2percent.. "% full")
  187.     gpu.setBackground(0x000000)
  188.    
  189.     -- Active Max Titles  
  190.     gpu.setForeground(0xFF0000)  
  191.     gpu.set(1,17,crushMS)
  192.     gpu.set(14,17,crushM2S)
  193.     gpu.set(1,27,squeezermax)
  194.     gpu.set(26,27,fermentermax)
  195.     gpu.set(52,27,excavatormax)
  196.     gpu.set(77,27,refinerymax)
  197.     gpu.setForeground(0xFFFFFF)
  198.  
  199.     -- Active Current Power Titles
  200.     gpu.setForeground(0xF8F8FF)
  201.     gpu.set(1,20,crushCS)
  202.     gpu.set(14,20,crushC2S)
  203.     gpu.set(1,30,squeezercurrent)
  204.     gpu.set(26,30,fermentercurrent)  
  205.     gpu.set(52,30,excavatorcurrent)
  206.     gpu.set(77,30,refinerycurrent)    
  207.     gpu.set(103,22,cap1PS)
  208.     gpu.set(103,26,cap2PS)
  209.     gpu.set(103,30,lowcapP)
  210.     gpu.setForeground(0xFFFFFF)
  211.  
  212.     -- Active Activity Title
  213.     gpu.setForeground(0x00FF00)
  214.     gpu.set(42,30,statusfermenter)
  215.     gpu.set(17,30,statussqueezer)
  216.     gpu.set(68,30,statusexcavator)
  217.     gpu.set(18,7,statusgenerator)
  218.     gpu.setForeground(0x8B4513)
  219.     gpu.set(10,5,generatortankCapacityS)
  220.     gpu.set(9,7,generatortankAmountS)
  221.     gpu.set(111,3,red2)
  222.  
  223.    --Monitoring
  224.     if (cap1P < 100000) then  
  225.     fer.setEnabled(false)
  226.     squ.setEnabled(false)
  227.     elseif (cap1P < 800000) then
  228.     red.setOutput(5,15)
  229.     elseif (cap1P > 800000) and (cap2P > 800000) then
  230.     red.setOutput(5,0)
  231.     fer.setEnabled(true)
  232.     squ.setEnabled(true)
  233.     end
  234.    
  235. os.sleep(0)
  236. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement