Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Thermal expansion energy cell charge controller--
- --Place your TE cell on any side of the computer and it will find it automatically--
- --Outputs redstone signal when cell power level drops below certain percentage--
- --Use <cellmanager help> to find out about program options--
- --Examples:-
- --<cellmanger left 50> (output signal on left of computer at 50%
- --create startup file <edit startup> containing
- --<shell.run("cellmanager front 20")>
- --to restart cell manager at server restart, with signal from front at 20%
- args={...}
- output="back"
- turnOnLevel=80
- --find and wrap the cell
- function getPeripheral(thing)
- local Sides = {
- "left","right",
- "top","bottom",
- "front","back",
- }
- for i,v in pairs(Sides) do
- if (peripheral.isPresent(v) and peripheral.getType(v) == thing) then
- print("'"..thing.."' found on side '"..v.."'.")
- return peripheral.wrap(v), v
- end
- end
- print("ERROR: '"..thing.."' not found!")
- return nil, nil
- end
- --calculate % energy level
- function calculateLevel(currentEnergy, maxEnergy)
- local level=0
- local fraction=0
- fraction=currentEnergy/maxEnergy
- level=fraction*100
- return level
- end
- ---MAIN--
- charging=false
- redstone.setOutput(output,false)
- cell=getPeripheral("cofh_thermalexpansion_energycell")
- maxEnergy=cell.getMaxEnergyStored("back")
- currentEnergy=cell.getEnergyStored("back")
- term.clear()
- term.setCursorPos(1,1)
- print ("Current energy:- "..currentEnergy.."RF")
- print ("Max energy:- "..maxEnergy.."RF")
- if (args[1] == nil) then
- print ("No arguments set, using default low power:- 80%, redstone signal:- back.")
- print ("Use [cellmanager help] for more info.")
- output="back"
- turnOnLevel=80
- elseif (args[1] == "help") then
- print ("Cellmanger help:- Use cellmanager <xxxx> <yyyy>.")
- print ("")
- print ("xxxx=redstone output side on computer for RF generator 'left','right','top','bottom','front','back'. Default is back side.")
- print ("")
- print ("yyyy=low charge percentage to start charging at (no percent sign). Default 80%.")
- print ("")
- print ("Add cellmanger to computer startup file to restart cellmanger on server restart.")
- else
- output = args[2]
- turnOnLevel = tonumber(args[2])
- if (turnOnLevel == nil or turnOnLevel <=-1 or turnOnLevel >= 101) then
- print ("Invalid low power setting, using default, 80%.")
- turnOnLevel=80
- else
- print("Low power set to "..turnOnLevel.."%")
- end
- side = args[1]
- if string.match(side, "back") then
- print ("Redstone signal on back.")
- output=side
- elseif string.match(side, "left") then
- print ("Redstone signal on left.")
- output=side
- elseif string.match(side, "right") then
- print ("Redstone signal on right.")
- output=side
- elseif string.match(side, "front") then
- print ("Redstone signal on front.")
- output=side
- elseif string.match(side, "top") then
- print ("Redstone signal on top.")
- output=side
- elseif string.match(side, "bottom") then
- print ("Redstone signal on bottom.")
- output=side
- else
- print ("Redstone side incorrectly set, check your spelling, only 'left','right','top','bottom','front','back' permitted. Using default, back")
- output="back"
- end
- end
- print("")
- getLevelX,getLevelY = term.getCursorPos()
- while true do
- currentEnergy=cell.getEnergyStored("back")
- currentLevel=calculateLevel(currentEnergy,maxEnergy)
- term.setCursorPos(1,getLevelY)
- term.clearLine()
- print("Current energy is "..currentLevel)
- if (currentLevel <= turnOnLevel and charging == false) then
- redstone.setOutput(output,true)
- charging=true
- term.setCursorPos(1,getLevelY+1)
- term.clearLine()
- print("Cell low power, starting charge")
- elseif (currentLevel >= 99 and charging==true) then
- redstone.setOutput(output,false)
- charging=false
- term.setCursorPos(1,getLevelY+1)
- term.clearLine()
- print("Cell full, stopping charge")
- end
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement