Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function pastebinDownload(id, name, fileName)
- local code, err = http.get(
- "https://pastebin.com/raw/" .. id,
- {["User-Agent"] = "ComputerCraft HTTP API"}
- )
- if not code then
- print("Download failed: " .. tostring(err))
- return false
- end
- local file = fs.open(fileName, "w")
- file.write(code.readAll())
- file.close()
- code.close()
- return true
- end
- local apiDownload = {name = "CGI Core Library", file = "API/CGICoreLib", id = "xuMVS2GP"}
- if not fs.exists("API/CGICoreLib") then
- print("Installing CGB Core Library...")
- fs.makeDir("API")
- pastebinDownload(
- apiDownload.id,
- apiDownload.name,
- apiDownload.file
- )
- end
- local api = dofile("API/CGICoreLib")
- api.greeting("Power Storage Monitor V2")
- while true do
- local monitorsStandard = {}
- local monitorsAdvanced = {}
- --gets all monitors then detects standard monitors vs advanced monitors and splits them into their relevant tables
- local monitorsAll = api.cataloguePeripherals("write","setTextScale")
- for _ , name in ipairs(monitorsAll) do
- if peripheral.call(name,"isColor") then
- table.insert(monitorsAdvanced,name)
- else
- table.insert(monitorsStandard,name)
- end
- end
- --detects all energy storage, keep in mind that ALL listed methods must match for it to qualify per list
- local batteries1 = api.cataloguePeripherals("getEnergy","getMaxEnergy")
- local batteries2 = api.cataloguePeripherals("getEnergyStored","getMaxEnergyStored")
- --adds up all energy
- local energy = 0
- local energyMax = 0
- for _ , name in ipairs(batteries1) do
- energy = energy + peripheral.call(name,"getEnergy")
- energyMax = energyMax + peripheral.call(name,"getMaxEnergy")
- end
- for _ , name in ipairs(batteries2) do
- energy = energy + peripheral.call(name,"getEnergyStored")
- energyMax = energyMax + peripheral.call(name,"getMaxEnergyStored")
- end
- --creates 2 new strings which simplify the energy readings. Note: as RF
- local energyString = api.simplifyReading("RF",energy,1)
- local energyMaxString = api.simplifyReading("RF",energyMax,1)
- local percentage = 0
- if (energy > 0) and (energyMax > 0) then
- percentage = (energy / energyMax) * 100
- end
- local basicText = api.round(percentage,2) .. "%"
- for _, name in ipairs(monitorsStandard) do
- peripheral.call(name,"clear")
- peripheral.call(name,"setCursorPos",1,1)
- peripheral.call(name,"write",basicText)
- peripheral.call(name,"setCursorPos",1,2)
- peripheral.call(name,"write",energyString)
- peripheral.call(name,"setCursorPos",1,3)
- peripheral.call(name,"write", "OF:")
- peripheral.call(name,"setCursorPos",1,4)
- peripheral.call(name,"write",energyMaxString)
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment