Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This is a development version of Umaroth's Power Monitor. I upload testing versions here for easy migration into CC terminals for testing.
- You're free to use development versions but they may not work properly.
- --]]
- --You can change these:
- local upper = 0.98 --Upper limit for computer to stop transmitting redstone signal. 0.98=98% full.
- local lower = 0.05 --Lower limit for computer to start transmitting redstone signal.
- local redstoneSide = "none" -- Change this to the side you want to output the redstone signal to. ["left","right","top","bottom","front","back","none"]
- --Don't change these:
- cellCount = 0
- connectedCells = {}
- monitorCount = 0
- connectedMonitors = {}
- TE4Cell = 0 EIOCell = 0
- periList = peripheral.getNames()
- --Get all peripherals
- for i = 1, #periList do
- validPeripherals = {["powered_tile"]=true,["capacitor_bank"]=true,["monitor"]=true,["BigReactors_Turbine"]=true,["BigReactors-Reactor"]=true}
- periFunctions = {
- ["powered_tile"] = function()
- cellCount = cellCount + 1
- TE4Cell= TE4Cell + 1
- connectedCells[cellCount] = periList[i]
- end,
- ["capacitor_bank"] = function()
- cellCount = cellCount + 1
- EIOCell = EIOCell + 1
- connectedCells[cellCount] = periList[i]
- end,
- ["monitor"] = function()
- monitorCount = monitorCount + 1
- connectedMonitors[monitorCount] = periList[i]
- end,
- ["BigReactors_Turbine"] = function()
- turbine = peripheral.wrap(periList[i])
- end,
- ["BigReactors-Reactor"] = function()
- reactor = peripheral.wrap(periList[i])
- end
- }
- if validPeripherals[peripheral.getType(periList[i])] then periFunctions[peripheral.getType(periList[i])]() end
- end
- --Check for storage cells and monitors before continuing
- if cellCount == 0 then
- print("No RF storage found. Exiting script!")
- return
- end
- if monitorCount == 0 then
- print ("No Monitor found. Exiting script!")
- return
- end
- --Function to set monitor sizes
- function getMonitorSize(x, y)
- if x == 18 and y == 5 then
- return "small"
- elseif x == 29 and y == 12 then
- return "large"
- else
- print("Invalid monitor size detected. Exiting script!")
- return
- end
- end
- --Check monitor sizes before continuing
- for i = 1, #connectedMonitors do
- monitor = peripheral.wrap(connectedMonitors[i])
- if getMonitorSize(monitor.getSize()) == nil then
- return
- end
- end
- --Print connected peripherals
- print("Peripherals connected:")
- if monitorCount > 1 then print(monitorCount.." Monitors") else print(monitorCount.." Monitor") end
- if TE4Cell == 0 or TE4Cell > 1 then print(TE4Cell.." TE Energy Cells") else print(TE4Cell.." TE Energy Cell") end
- if EIOCell == 0 or EIOCell > 1 then print(EIOCell.." Capacitor Banks") else print(EIOCell.." Capacitor Bank") end
- if turbine ~= nil then print ("1 Turbine") else print ("0 Turbines") end
- if reactor ~= nil then print ("1 Reactor") else print ("0 Reactors") end
- --Main code
- --Set default output states to off
- if redstoneSide ~= "none" then redstone.setOutput(redstoneSide, false) end
- if turbine ~= nil then turbine.setActive(false) end
- if reactor ~= nil then reactor.setActive(false) end
- --Write default engine status to all attached monitors
- for i = 1, #connectedMonitors do
- monitor = peripheral.wrap(connectedMonitors[i])
- if getMonitorSize(monitor.getSize()) == "large" then
- monitor.clear()
- monitor.setBackgroundColour((colours.grey))
- monitor.setCursorPos(11,4)
- monitor.write(" ON ")
- monitor.setBackgroundColour((colours.green))
- monitor.setCursorPos(15,4)
- monitor.write(" OFF ")
- monitor.setBackgroundColour((colours.black))
- else
- monitor.clear()
- monitor.setBackgroundColour((colours.grey))
- monitor.setCursorPos(1,4)
- monitor.write(" ON ")
- monitor.setBackgroundColour((colours.green))
- monitor.setCursorPos(5,4)
- monitor.write(" OFF ")
- monitor.setBackgroundColour((colours.black))
- end
- end
- --Main loop
- while true do
- --Get all dynamic values
- --Get storage values
- eNow = 0 eMax = 0
- for i = 1, #connectedCells do
- cell=peripheral.wrap(connectedCells[i])
- eNow = eNow + cell.getEnergyStored()
- eMax = eMax + cell.getMaxEnergyStored()
- end
- --Compute engine activation ratio
- fill = eNow / eMax
- --Set storage scale
- if eNow >= 1000000000 then eNowScale = "billion"
- elseif eNow >= 1000000 then eNowScale = "million"
- else eNowScale = "none" end
- if eMax >= 1000000000 then eMaxScale = "billion"
- elseif eMax >= 1000000 then eMaxScale = "million"
- else eMaxScale = "none" end
- --Adjust number to scale
- if eNowScale == "billion" then eNowValue = math.ceil(eNow / 1000000)
- elseif eNowScale == "million" then eNowValue = math.ceil(eNow / 1000)
- else eNowValue = math.ceil(eNow) end
- if eMaxScale == "billion" then eMaxValue = math.ceil(eMax / 1000000)
- elseif eMaxScale == "million" then eMaxValue = math.ceil(eMax / 1000)
- else eMaxValue = math.ceil(eMax) end
- --Adjust suffix to scale
- if eNowScale == "billion" then eNowSuffixLarge = "m RF"
- elseif eNowScale == "million" then eNowSuffixLarge = "k RF"
- else eNowSuffixLarge = " RF" end
- if eNowScale == "billion" then eNowSuffixSmall = "mRF"
- elseif eNowScale == "million" then eNowSuffixSmall = "kRF"
- else eNowSuffixSmall = " RF" end
- if eMaxScale == "billion" then eMaxSuffixLarge = "m RF"
- elseif eMaxScale == "million" then eMaxSuffixLarge = "k RF"
- else eMaxSuffixLarge = " RF" end
- if eMaxScale == "billion" then eMaxSuffixSmall = "mRF"
- elseif eMaxScale == "million" then eMaxSuffixSmall = "kRF"
- else eMaxSuffixSmall = " RF" end
- --Get number of digits to write
- eNowDigitCount = 0 eMaxDigitCount = 0
- for digit in string.gmatch(eNowValue, "%d") do eNowDigitCount = eNowDigitCount + 1 end
- for digit in string.gmatch(eMaxValue, "%d") do eMaxDigitCount = eMaxDigitCount + 1 end
- --Get location to write
- if eNowSuffixLarge == "m RF" or eNowSuffixLarge == "k RF" then eNowXLarge = 17 - eNowDigitCount
- else eNowXLarge = 18 - eNowDigitCount end
- eNowXSmall = 16 - eNowDigitCount
- if eMaxSuffixLarge == "m RF" or eMaxSuffixLarge == "k RF" then eMaxXLarge = 17 - eMaxDigitCount
- else eMaxXLarge = 18 - eMaxDigitCount end
- eMaxXSmall = 16 - eMaxDigitCount
- --Loop for every monitor
- for i = 1, #connectedMonitors do
- monitor=peripheral.wrap(connectedMonitors[i])
- --Write data to all attached monitors
- monitor=peripheral.wrap(connectedMonitors[i])
- if getMonitorSize(monitor.getSize()) == "large" then
- --Erase old data
- monitor.setCursorPos(10,9)
- monitor.write(" ")
- monitor.setCursorPos(10,11)
- monitor.write(" ")
- --Write constant/new data
- monitor.setCursorPos(12,2)
- monitor.write("Engines:")
- monitor.setCursorPos(12,7)
- monitor.write("Storage:")
- monitor.setCursorPos(eNowXLarge,9)
- monitor.write(eNowValue..eNowSuffixLarge)
- monitor.setCursorPos(eMaxXLarge,10)
- monitor.write("of:")
- monitor.setCursorPos(eMaxXLarge,11)
- monitor.write(eMaxValue..eMaxSuffixLarge)
- if fill > upper then
- --Energy level is over upper level, turning redstone/reactors off
- if redstoneSide ~= "none" then redstone.setOutput(redstoneSide, false) end
- if turbine ~= nil then turbine.setActive(false) end
- if reactor ~= nil then reactor.setActive(false) end
- monitor.setBackgroundColour((colours.grey))
- monitor.setCursorPos(11,4)
- monitor.write(" ON ")
- monitor.setBackgroundColour((colours.green))
- monitor.setCursorPos(15,4)
- monitor.write(" OFF ")
- monitor.setBackgroundColour((colours.black))
- elseif fill < lower then
- --Energy level is below lower limit, turning redstone/reactors on
- if redstoneSide ~= "none" then redstone.setOutput(redstoneSide, true) end
- if turbine ~= nil then turbine.setActive(true) end
- if reactor ~= nil then reactor.setActive(true) end
- monitor.setBackgroundColour((colours.green))
- monitor.setCursorPos(11,4)
- monitor.write(" ON ")
- monitor.setBackgroundColour((colours.grey))
- monitor.setCursorPos(15,4)
- monitor.write(" OFF ")
- monitor.setBackgroundColour((colours.black))
- end
- elseif getMonitorSize(monitor.getSize()) == "small" then
- --erase old data
- monitor.setCursorPos(10,3)
- monitor.write(" ")
- monitor.setCursorPos(10,5)
- monitor.write(" ")
- --write constant/new data
- monitor.setCursorPos(2,2)
- monitor.write("Engines:")
- monitor.setCursorPos(11,2)
- monitor.write("Storage:")
- monitor.setCursorPos(eNowXSmall,3)
- monitor.write(eNowValue..eNowSuffixSmall)
- monitor.setCursorPos(eMaxXSmall,4)
- monitor.write("of:")
- monitor.setCursorPos(eMaxXSmall,5)
- monitor.write(eMaxValue..eMaxSuffixSmall)
- if fill > upper then
- --Energy level is over upper level, turning redstone/reactors off
- if redstoneSide ~= "none" then redstone.setOutput(redstoneSide, false) end
- if turbine ~= nil then turbine.setActive(false) end
- if reactor ~= nil then reactor.setActive(false) end
- monitor.setBackgroundColour((colours.grey))
- monitor.setCursorPos(1,4)
- monitor.write(" ON ")
- monitor.setBackgroundColour((colours.green))
- monitor.setCursorPos(5,4)
- monitor.write(" OFF ")
- monitor.setBackgroundColour((colours.black))
- elseif fill < lower then
- --Energy level is below lower limit, turning redstone/reactors on
- if redstoneSide ~= "none" then redstone.setOutput(redstoneSide, true) end
- if turbine ~= nil then turbine.setActive(true) end
- if reactor ~= nil then reactor.setActive(true) end
- monitor.setBackgroundColour((colours.green))
- monitor.setCursorPos(1,4)
- monitor.write(" ON ")
- monitor.setBackgroundColour((colours.grey))
- monitor.setCursorPos(5,4)
- monitor.write(" OFF ")
- monitor.setBackgroundColour((colours.black))
- end
- end
- end
- sleep(1)
- end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement