Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- APIs
- local component = require("component")
- local term = require("term")
- -- Constants
- local name = "draconic_rf_storage"
- local debug = false;
- local step = 1;
- -- Variables
- local storageAddress = nil
- local proxy = nil
- local computer = component.computer
- -- Functions
- function printd(msg)
- if debug then
- print(msg)
- end
- end
- function loadStorage()
- for address, componentType in component.list() do
- if componentType == name then
- printd(componentType .. " found at address: " .. address)
- storageAddress = address
- end
- end
- if storageAddress ~= nil then
- proxy = component.proxy(storageAddress)
- end
- if proxy == nil then
- return false
- end
- return true
- end
- function getEnergy()
- if proxy ~= nil then
- return proxy.getEnergyStored()
- end
- return -1
- end
- function getMaxEnergy()
- if proxy ~= nil then
- return proxy.getMaxEnergyStored()
- end
- return -1
- end
- function formatNumber(number)
- local output = string.format("%.3f", number)
- local unitVal = {1000000000000000, 1000000000000, 1000000000, 1000000, 1000}
- local unit = {"P", "T", "G", "M", "k"}
- local units = 5
- local toConvert = math.abs(number)
- local sign = ""
- for i = 1, units do
- if toConvert >= unitVal[i] then
- local x = toConvert / unitVal[i]
- if number < 0 then
- sign = "-"
- end
- output = sign .. string.format("%.3f", x) .. unit[i]
- break
- end
- end
- return output
- end
- function showEnergy()
- local gpu = term.gpu()
- term.setCursor(1, 1)
- term.clearLine()
- term.setCursor(1, 1)
- gpu.setForeground(0xFFFFFF)
- term.write("Energy: "
- .. formatNumber(getEnergy())
- .. " RF / "
- .. formatNumber(getMaxEnergy())
- .. " RF")
- end
- function run()
- term.gpu().setResolution(30, 15)
- loadStorage()
- if proxy == nil then
- return 1
- end
- term.clear()
- os.sleep(step)
- while computer.isRunning() do
- showEnergy()
- os.sleep(step)
- end
- return 0
- end
- -- Main Program
- local exitCode = run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement