Guest User

c

a guest
Feb 28th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. -- Double Buffer
  2. --
  3. -- Originally by etopsirhc
  4. -- Improved by IndianaX
  5. --
  6. -- Don't waste energy of your big power plant
  7.  
  8. -- Configure default on start and input/output side
  9. local allowBufferFlow = false
  10. local sideI = "right"
  11. local sideO = "left"
  12.  
  13. -- Internal variables
  14. local gateI = peripheral.wrap(sideI)
  15. local gateO = peripheral.wrap(sideO)
  16. local monitor = peripheral.wrap("top")
  17. local monitorW, monitorH = monitor.getSize()
  18. local checkI, checkO
  19.  
  20. -- The animations on the TOP monitor
  21. local animation = { {
  22. "      <",
  23. "     <<",
  24. "    <<<",
  25. "   <<< ",
  26. "  <<<  ",
  27. " <<<   ",
  28. "<<<    ",
  29. "<<     ",
  30. "<      " }, {
  31. "  ---  ",
  32. "  - -  ",
  33. "  ---  ",
  34. "   --  ",
  35. "  ---  ",
  36. "  --   ",
  37. "  ---  ",
  38. "   -   " } }
  39. local animationPos = 1
  40.  
  41. function writeTerm(text)
  42.   term.clear()
  43.   term.setCursorPos(1, 1)
  44.   term.write(text)
  45. end
  46.  
  47. function writeMon(status)
  48.   -- Clear monitor and set position
  49.   monitor.clear()
  50.   monitor.setCursorPos(1, monitorH/2 +1)
  51.  
  52.   -- Check existing animation position else go to first
  53.   if animationPos > # animation[status] then animationPos = 1 end
  54.   monitor.write(animation[status][animationPos])
  55.   animationPos = animationPos + 1
  56. end
  57.  
  58. -- Initial Settings
  59. rs.setOutput(sideI, allowBufferFlow)
  60. if allowBufferFlow then
  61.   writeTerm("Discharging Front Buffer.")
  62. else
  63.   writeTerm("Charging Front Buffer.")
  64. end
  65.  
  66. while true do
  67.   -- Get Status
  68.   --checkI = gateI.get()
  69.   checkO = gateO.get()
  70.  
  71.   -- Check whats todo
  72.   if checkO["No Energy"] and allowBufferFlow == false then
  73.     allowBufferFlow = true
  74.     rs.setOutput(sideI, allowBufferFlow)
  75.     writeTerm("Discharging Front Buffer.")
  76.   elseif checkO["Full Energy"] and allowBufferFlow == true then
  77.     allowBufferFlow = false
  78.     rs.setOutput(sideI, allowBufferFlow)
  79.     writeTerm("Charging Front Buffer.")
  80.   else
  81.     -- Wait to save CPU / do Animation
  82.     sleep(0.9)
  83.   end
  84.  
  85.   -- Output Status
  86.   if allowBufferFlow then
  87.     writeMon(1)
  88.   else
  89.     writeMon(2)
  90.   end
  91. end
Advertisement
Add Comment
Please, Sign In to add comment