Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("helper")
- local tArgs = {...}
- local version = "0.1"
- local func
- local redstoneside = "left"
- local rednetside = "back"
- local boilerside = "right"
- local monitorside = "bottom"
- local defColor = colors.white
- -- init peripheral and rednet
- local highPressureBoiler = peripheral.wrap(boilerside)
- local monitor = peripheral.wrap(monitorside)
- rednet.open(rednetside)
- monitor.setTextScale(0.5)
- term.redirect(monitor)
- -- equivalent to "condition ? true : false"
- function fif(condition, if_true, if_false)
- if condition then return if_true else return if_false end
- end
- function powerStatus()
- return redstone.testBundledInput(redstoneside, colors.white)
- end
- function getStatus()
- local boilerTemperature = highPressureBoiler.getTemperature()
- local boilerTanks = highPressureBoiler.getTanks("")
- -- Remove information from Tank-Table that is not needed.
- tanks = { }
- for i, tank in pairs(boilerTanks) do
- if tank["name"] ~= nil then
- tankname = tank["name"]
- tanks[tankname] = { }
- tanks[tankname]["amount"] = tank["amount"]
- tanks[tankname]["capacity"] = tank["capacity"]
- end
- end
- local boilerInfo = { }
- boilerInfo["boilerTemp"] = boilerTemperature
- boilerInfo["boilerTanks"] = tanks
- local status = { }
- status["computerID"] = os.computerID()
- status["computerName"] = os.getComputerLabel()
- status["powerStatus"] = powerStatus()
- status["boilerInfo"] = boilerInfo
- return status
- end
- function updateComputerStatusText(status)
- if status == nil then
- return
- end
- term.clear()
- term.setCursorPos(1,1)
- print(status["computerName"] .. " (id:" .. status["computerID"] .. ")")
- print("PowerStatus:\t" .. fif(status["powerStatus"],"ON","OFF"))
- print("Boiler Temperature:\t" .. status["boilerInfo"]["boilerTemp"])
- print("Boiler Tanks:\t")
- local tmp
- header = { "" , "Amount", "Capacity", "%"}
- tmp = status["boilerInfo"]["boilerTanks"]["Steam"]
- steam = { "Steam:", "" .. tmp["amount"], "" .. tmp["capacity"], "" .. math.floor(tmp["amount"]/tmp["capacity"]*100)}
- tmp = status["boilerInfo"]["boilerTanks"]["Fuel"]
- fuel = { "Fuel:", "" .. tmp["amount"], "" .. tmp["capacity"], "" .. math.floor(tmp["amount"]/tmp["capacity"]*100)}
- tmp = status["boilerInfo"]["boilerTanks"]["Water"]
- water = { "Water:", "" .. tmp["amount"], "" .. tmp["capacity"], "" .. math.floor(tmp["amount"]/tmp["capacity"]*100)}
- textutils.tabulate(header, steam, fuel, water)
- end
- function togglePower(id)
- if powerStatus() then
- turnOff(id)
- else
- turnOn(id)
- end
- updateComputerStatusText(getStatus())
- return powerStatus()
- end
- function turnOn(id)
- redstone.setBundledOutput(redstoneside, colors.white)
- return true
- end
- function turnOff(id)
- redstone.setBundledOutput(redstoneside, 0)
- return true
- end
- function coreStatus(id)
- local status = getStatus()
- updateComputerStatusText(status)
- rednet.send(id, status)
- return true
- end
- updateComputerStatusText(getStatus())
- while true do
- local id,msg,dist = rednet.receive()
- func = loadstring("return " .. msg.. "(...)")
- setfenv(func, getfenv())
- isSuccess = func(id)
- if isSuccess == nil then
- rednet.send(id,"nil")
- elseif isSuccess then
- rednet.send(id,"Done")
- else
- rednet.send(id,"Failed")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement