Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local auxChannelID = 6
- local emergencyChannelID = 7
- local statusChannelID = 5
- local auxPercentage = 95
- local emergencyPercentage = 75
- -- Find Modem
- local modem = peripheral.find("modem", function(n, o) return o.isWireless() end)
- -- Find Induction Matrix
- local matrix = peripheral.find("Induction Matrix")
- if matrix == nil then
- error("Could not bind to Induction Matrix. Is one attached?")
- end
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- term.write("Waiting for Matrix to form...")
- while matrix.getMaxEnergy() == "Unformed." do
- term.write(".")
- os.sleep(1)
- end
- local maxEnergy = matrix.getMaxEnergy()/2.5
- local curEnergy = matrix.getEnergy()/2.5
- local curInput = matrix.getInput()/2.5
- local curOutput = matrix.getOutput()/2.5
- local function prettyAmt(num)
- if num >= 1000000000000 then
- return (tostring(round(num/1000000000000, 2)) .. "T")
- elseif num >= 1000000000 then
- return (tostring(round(num/1000000000, 2)) .. "B")
- elseif num >= 1000000 then
- return (tostring(round(num/1000000, 2)) .. "M")
- elseif num >= 1000 then
- return (tostring(round(num/1000, 2)) .. "t")
- else
- return tostring(num)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Monitoring Induction Matrix")
- print()
- print("Maximum stored energy: " .. maxEnergy .. " RF")
- print("Current stored energy: " .. string.format("%u", curEnergy) .. " RF")
- print()
- print("Auxiliary power status: Disabled")
- print("Emergency power status: Disabled")
- print()
- print("Press 'a' to toggle auxiliary power.")
- print("Press 'q' to quit.")
- print()
- local aux = false
- local emergency = false
- local status = {}
- status["Power Storage Max"] = prettyAmt(maxEnergy) .. " RF"
- status["Power Storage"] = "0%"
- status["Power Auxiliary"] = "Disabled"
- status["Power Emergency"] = "Disabled"
- status["Power Input"] = tostring(round(curInput, 1)) .. " RF/t"
- status["Power Output"] = tostring(round(curOutput, 1)) .. " RF/t"
- local pollTimer = os.startTimer(0)
- while true do
- local event, p1, p2, p3, p4 = os.pullEvent()
- if event == "key" then
- if p1 == keys.q then
- term.setCursorPos(1,11)
- return
- elseif p1 == keys.a then
- if aux then aux = false else aux = true end
- end
- elseif event == "timer" and p1 == pollTimer then
- curEnergy = round(matrix.getEnergy())/2.5
- curInput = round(matrix.getInput())/2.5
- curOutput = matrix.getOutput()/2.5
- local fillP = math.floor((curEnergy / maxEnergy) * 100)
- if fillP <= auxPercentage and aux == false then
- aux = true
- end
- if fillP <= emergencyPercentage and emergency == false then
- emergency = true
- end
- if fillP >= 99 and (aux == true or emergency == true) then
- aux = false
- emergency = false
- end
- term.setCursorPos(1,6)
- status["Power Storage"] = fillP .. "%"
- if aux == true then
- if modem ~= nil then modem.transmit(auxChannelID, 0, "enabled") end
- term.write("Auxiliary power status: Enabled ")
- status["Power Auxiliary"] = "Enabled "
- else
- if modem ~= nil then modem.transmit(auxChannelID, 0, "disabled") end
- term.write("Auxiliary power status: Disabled ")
- status["Power Auxiliary"] = "Disabled "
- end
- term.setCursorPos(1,7)
- if emergency == true then
- if modem ~= nil then modem.transmit(emergencyChannelID, 0, "enabled") end
- term.write("Emergency power status: Enabled ")
- status["Power Emergency"] = "Enabled "
- else
- if modem ~= nil then modem.transmit(emergencyChannelID, 0, "disabled") end
- term.write("Emergency power status: Disabled ")
- status["Power Emergency"] = "Disabled "
- end
- status["Power Input"] = tostring(round(curInput, 1)) .. " RF/t"
- status["Power Output"] = tostring(round(curOutput, 1)) .. " RF/t"
- if modem ~= nil then modem.transmit(statusChannelID, 0, textutils.serialize(status)) end
- term.setCursorPos(1,4)
- term.write("Current stored energy: " .. string.format("%u", curEnergy) .. " RF ")
- pollTimer = os.startTimer(5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement