Advertisement
Guest User

startup

a guest
Aug 21st, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.39 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=25
  17. --find and wrap the cell
  18. function getPeripheral(thing)
  19.         local Sides = {
  20.         "left","right",
  21.         "top","bottom",
  22.         "front","back",
  23.     }
  24.      
  25.     for i,v in pairs(Sides) do
  26.         if (peripheral.isPresent(v) and peripheral.getType(v) == thing) then
  27.             print("'"..thing.."' found on side '"..v.."'.")
  28.             return peripheral.wrap(v), v
  29.         end
  30.     end
  31.  
  32.     print("ERROR: '"..thing.."' not found!")
  33.     return nil, nil
  34. end
  35. --calculate % energy level
  36. function calculateLevel(currentEnergy, maxEnergy)
  37. local level=0
  38. local fraction=0
  39.     fraction=currentEnergy/maxEnergy
  40.     level=fraction*100
  41.     return level
  42. end
  43. ---MAIN--
  44. charging=false
  45. redstone.setOutput(output,false)
  46. cell1=getPeripheral("cofh_thermalexpansion_energycell_14")
  47. cell2=getPeripheral("cofh_thermalexpansion_energycell_15")
  48. cell3=getPeripheral("cofh_thermalexpansion_energycell_16")
  49. maxEnergy1=cell1.getMaxEnergyStored("back")
  50. maxEnergy2=cell2.getMaxEnergyStored("back")
  51. maxEnergy3=cell3.getMaxEnergyStored("back")
  52. currentEnergy1=cell1.getEnergyStored("back")
  53. currentEnergy2=cell2.getEnergyStored("back")
  54. currentEnergy3=cell3.getEnergyStored("back")
  55. term.clear()
  56. term.setCursorPos(1,1)
  57. maxEnergyall=maxEnergy1 + maxEnergy2 + maxEnergy3
  58. currentEnergyall=currentEnergy1 + currenEnergy2 + currentEnergy3
  59. print ("Current energy: "..currentEnergyall.."RF")
  60. print ("Max energy: "..maxEnergyall.."RF")
  61.  
  62. --if (args[1] == nil) then
  63. --  print ("No arguments set, using default low power: 25%, redstone signal: back.")
  64. --  print ("Use [cellmanager help] for more info.")
  65. --  output="back"
  66. --  turnOnLevel=25
  67. --elseif (args[1] == "help") then
  68. --  print ("Cellmanger help:- Use cellmanager <xxxx> <yyyy>.")
  69. --  print ("")
  70. --  print ("xxxx=redstone output side on computer for RF generator 'left','right','top','bottom','front','back'. Default is back side.")
  71. --  print ("")
  72. --  print ("yyyy=low charge percentage to start charging at (no percent sign). Default 25%.")
  73. --  print ("")
  74. --  print ("Add cellmanger to computer startup file to restart cellmanger on server restart.")
  75. --else
  76. --  output = args[2]
  77. --  turnOnLevel = tonumber(args[2])
  78. --  if (turnOnLevel == nil or turnOnLevel <=-1 or turnOnLevel >= 101) then
  79. --  print ("Invalid low power setting, using default, 25%.")
  80. --  turnOnLevel=25
  81. --  else
  82. --  print("Low power set to "..turnOnLevel.."%")
  83. --  end
  84. --  side = args[1]
  85. --  if string.match(side, "back") then
  86. --      print ("Redstone signal on back.")
  87. --      output=side
  88. --  elseif string.match(side, "left") then
  89. --      print ("Redstone signal on left.")
  90. --      output=side
  91. --  elseif string.match(side, "right") then
  92. --      print ("Redstone signal on right.")
  93. --      output=side
  94. --  elseif string.match(side, "front") then
  95. --      print ("Redstone signal on front.")
  96. --      output=side
  97. --  elseif string.match(side, "top") then
  98. --      print ("Redstone signal on top.")
  99. --      output=side
  100. --  elseif string.match(side, "bottom") then
  101. --      print ("Redstone signal on bottom.")
  102. --      output=side
  103. --  else
  104. --  print ("Redstone side incorrectly set, check your spelling, only 'left','right','top','bottom','front','back' permitted. Using default, back")
  105. --  output="back"
  106. --  end
  107. --end
  108.  
  109. print("")
  110. getLevelX,getLevelY = term.getCursorPos()
  111. while true do
  112.     currentEnergy=cell.getEnergyStored("back")
  113.     currentLevel=calculateLevel(currentEnergy,maxEnergy)
  114.     term.setCursorPos(1,getLevelY)
  115.     term.clearLine()
  116.     --print("Current energy is "..currentLevel)
  117.     if (currentLevel <= turnOnLevel and charging == false) then
  118.         redstone.setOutput(output,true)
  119.         charging=true
  120.         term.setCursorPos(1,getLevelY+1)
  121.         term.clearLine()
  122.         --print("Cell low power, starting charge")
  123.     elseif (currentLevel >= 99 and charging==true) then
  124.         redstone.setOutput(output,false)
  125.         charging=false
  126.         term.setCursorPos(1,getLevelY+1)
  127.         term.clearLine()
  128.         --print("Cell full, stopping charge")
  129.     end
  130.     sleep(2)
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement