Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arg = { ... }
- currentControlID = 0
- prtc = "hv"
- name = os.getComputerLabel()
- criticalValue = 20
- loading = false
- if #arg ~= 5 then
- error("not 5 prog arguments its " .. #arg)
- end
- modemside = arg[1]
- sensorside = arg[2]
- storagepos = arg[3]
- currentside = arg[4]
- switchside = arg[5]
- os.loadAPI("ocs/apis/sensor")
- mySensor = sensor.wrap(sensorside)
- rednet.open(modemside)
- rednet.host(prtc,name)
- --wait for currentcontrol to initialize
- sleep(1)
- currentControlID = rednet.lookup(prtc,"currentControl")
- if not currentControlID or currentControlID <= 0 then
- error("currentControl not found")
- end
- while true do
- details = mySensor.getTargetDetails(storagepos)
- stored = details["StoredPercentage"]
- if loading == true and stored > criticalValue and not redstone.getInput(currentside) then
- redstone.setOutput(switchside,true)
- loading = false
- elseif loading == false and redstone.getInput(currentside) then
- loading = true
- end
- if stored < criticalValue then
- rednet.send(currentControlID,"request power",prtc)
- redstone.setOutput(switchside,false)
- end
- id,msg = rednet.receive(prtc,3)
- if id then
- if msg == "get status" then
- loading = true
- rednet.send(id,name .. " " .. stored .. " " .. tostring(loading) .. " " .. tostring(redstone.getInput(currentside)),prtc)
- end
- if msg == "reboot" then
- os.reboot()
- end
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement