Advertisement
Guest User

Untitled

a guest
Dec 26th, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local colors = require("colors")
  5.  
  6. local gpu = component.gpu
  7. local screen = component.screen
  8. local reactor = component.br_reactor
  9. local turbine = component.br_turbine
  10. local bigbat = component.big_battery
  11. local rfm = component.rfmeter
  12.  
  13. local running = true
  14. local active = false
  15.  
  16. local function printXY(x, y, text)
  17.   term.setCursor(x, y)
  18.   print(text)
  19. end
  20.  
  21. local function round(num, idp)
  22.   local mult = 10 ^ (idp or 0)
  23.   return math.floor((num * mult) + 0.5) / mult
  24. end
  25.  
  26. local function shutdown()
  27.   event.ignore("touch")
  28.   setStatus(false)
  29.   active = false
  30.   running = false
  31. end
  32.  
  33. local function checkThreshold(value, threshold, method, param)
  34.   if value < threshold then do
  35.     method(param)
  36.   end
  37. end
  38.  
  39. local function percentage(max, value)
  40.   return (max / value) * 100
  41. end
  42.  
  43. local function getClick(_, x, y, _, _)
  44.   if x > 1 and x < 3 and y > 1 and y < 3 and active == false then do
  45.     setStatus(true)
  46.   end
  47.   else if x > 1 and x < 3 and y > 1 and y < 3 and active == true then do
  48.     setStatus(false)
  49.   end
  50.   else if x > 72 and x < 74 and y > 0 and y < 2 then do
  51.     shutdown()
  52.   end
  53. end
  54.  
  55. local function setStatus(bool)
  56.   reactor.setActive(bool)
  57.   for adress, componentType in component.list(br_turbine) do
  58.     component.invoke(adress, "setInductorEngaged(bool)")
  59.     engaged = bool
  60.   end
  61. end
  62.  
  63. event.listen("touch", getClick)
  64. setStatus(active)
  65. term.clear()
  66. term.setCursorBlink(false)
  67. screen.setTouchModeInverted(true)
  68. screen.setPrecise(true)
  69. gpu.setResolution(73, 50)
  70.  
  71. while running do
  72.   checkThreshold(percentage(bigbat.getMaxEnergyStored(), bigbat.getEnergyStored()), 5, setStatus, true)
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement