Advertisement
Guest User

cell

a guest
Jul 26th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.45 KB | None | 0 0
  1. --Thermal expansion energy cell charge controller--
  2. --Place your TE cell on any side of the computer and it will find it automatically--
  3. --Outputs redstone signal when cell power level drops below certain percentage--
  4. --Use <cellmanager help> to find out about program options--
  5. --Examples:-
  6.  
  7. --<cellmanger left 50>  (output signal on left of computer at 50%
  8.  
  9. --create startup file <edit startup> containing
  10. --<shell.run("cellmanager front 20")>
  11.  
  12. --to restart cell manager at server restart, with signal from front at 20%
  13.  
  14. args={...}
  15. output="back"
  16. turnOnLevel=75
  17. --find and wrap the cell
  18. peripheral.wrap("bottom")
  19. --calculate % energy level
  20. function calculateLevel(currentEnergy, maxEnergy)
  21. local level=0
  22. local fraction=0
  23.     fraction=currentEnergy/maxEnergy
  24.     level=fraction*100
  25.     return level
  26. end
  27. ---MAIN--
  28. charging=false
  29. redstone.setOutput(output,false)
  30. cell=getPeripheral("cofh_thermalexpansion_energycell")
  31. maxEnergy=cell.getMaxEnergyStored("back")
  32. currentEnergy=cell.getEnergyStored("back")
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. print ("Current energy:- "..currentEnergy.."RF")
  36. print ("Max energy:- "..maxEnergy.."RF")
  37. if (args[1] == nil) then
  38.     print ("No arguments set, using default low power:- 25%, redstone signal:- back.")
  39.     print ("Use [cellmanager help] for more info.")
  40.     output="back"
  41.     turnOnLevel=25
  42. elseif (args[1] == "help") then
  43.     print ("Cellmanger help:- Use cellmanager <xxxx> <yyyy>.")
  44.     print ("")
  45.     print ("xxxx=redstone output side on computer for RF generator 'left','right','top','bottom','front','back'. Default is back side.")
  46.     print ("")
  47.     print ("yyyy=low charge percentage to start charging at (no percent sign). Default 25%.")
  48.     print ("")
  49.     print ("Add cellmanger to computer startup file to restart cellmanger on server restart.")
  50. else
  51.     output = args[2]
  52.     turnOnLevel = tonumber(args[2])
  53.     if (turnOnLevel == nil or turnOnLevel <=-1 or turnOnLevel >= 101) then
  54.     print ("Invalid low power setting, using default, 25%.")
  55.     turnOnLevel=25
  56.     else
  57.     print("Low power set to "..turnOnLevel.."%")
  58.     end
  59.     side = args[1]
  60.     if string.match(side, "back") then
  61.         print ("Redstone signal on back.")
  62.         output=side
  63.     elseif string.match(side, "left") then
  64.         print ("Redstone signal on left.")
  65.         output=side
  66.     elseif string.match(side, "right") then
  67.         print ("Redstone signal on right.")
  68.         output=side
  69.     elseif string.match(side, "front") then
  70.         print ("Redstone signal on front.")
  71.         output=side
  72.     elseif string.match(side, "top") then
  73.         print ("Redstone signal on top.")
  74.         output=side
  75.     elseif string.match(side, "bottom") then
  76.         print ("Redstone signal on bottom.")
  77.         output=side
  78.     else
  79.     print ("Redstone side incorrectly set, check your spelling, only 'left','right','top','bottom','front','back' permitted. Using default, back")
  80.     output="back"
  81.     end
  82. end
  83. print("")
  84. getLevelX,getLevelY = term.getCursorPos()
  85. while true do
  86.     currentEnergy=cell.getEnergyStored("back")
  87.     currentLevel=calculateLevel(currentEnergy,maxEnergy)
  88.     term.setCursorPos(1,getLevelY)
  89.     term.clearLine()
  90.     print("Current energy is "..currentLevel)
  91.     if (currentLevel <= turnOnLevel and charging == false) then
  92.         redstone.setOutput(output,true)
  93.         charging=true
  94.         term.setCursorPos(1,getLevelY+1)
  95.         term.clearLine()
  96.         print("Cell low power, starting charge")
  97.     elseif (currentLevel >= 99 and charging==true) then
  98.         redstone.setOutput(output,false)
  99.         charging=false
  100.         term.setCursorPos(1,getLevelY+1)
  101.         term.clearLine()
  102.         print("Cell full, stopping charge")
  103.     end
  104.     sleep(2)
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement