Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Settings
- monitorSide = "back"
- consoleMonitor = "top"
- modemSide = "bottom"
- redstoneSide = "left"
- energylow = 10 -- When the motors should be turned on (percent)
- energyhigh = 95 -- When the motors should be turned off (percent)
- energyCellLow = 0 -- Lowest energy cell id
- energyCellHigh = 63 -- Highest energy cell id
- sleepCycle = 60 -- Seconds to sleep between each loop
- -- Variables
- mon = peripheral.wrap(monitorSide)
- monX, monY = mon.getSize()
- cmon = peripheral.wrap(consoleMonitor)
- -- initialization
- redstone.setOutput(redstoneSide,false) -- Disabled by default
- if(rednet.isOpen(modemSide) == "False") then -- Rednet
- rednet.open(modemSide)
- end
- -- Functions
- function clear() -- Clear screen
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- function drawText(x, y, text, color_txt, color_bg) -- Write text on monitor
- mon.setBackgroundColor(color_bg)
- mon.setTextColor(color_txt)
- mon.setCursorPos(x,y)
- mon.write(text)
- end
- function drawLine(x, y, length, size, color_bar) -- Write progress bar on monitor
- for yPos = y, y+size-1 do
- mon.setBackgroundColor(color_bar)
- mon.setCursorPos(x, yPos)
- mon.write(string.rep(" ", length))
- end
- end
- function drawProg(x, y, name, length, size, minVal, maxVal, color_bar, color_bg) -- Draw actual progress bar
- drawLine(x, y, length, size, color_bg)
- local barSize = math.floor((minVal/maxVal)*length)
- drawLine(x, y, barSize, size, color_bar)
- local text = name.." "..math.floor((minVal/maxVal)*100).."%"
- drawText(monX/2-#text/2+1, y+size/2, text, colors.black, color_bar)
- end
- function drawConsoleMon(cells, energyPercent, energyColor, invalidCells, redstoneSignal)
- cmon.clear()
- cmon.setBackgroundColor(colors.black)
- cmon.setCursorPos(1,1)
- cmon.setTextColor(colors.white)
- cmon.write("C: "..cells)
- cmon.setCursorPos(1,2)
- cmon.write("E: ")
- cmon.setTextColor(energyColor)
- cmon.write(energyPercent.."%")
- cmon.setTextColor(colors.white)
- cmon.setCursorPos(1,3)
- cmon.write("I: "..invalidCells)
- cmon.setCursorPos(1,4)
- cmon.write("R: ")
- cmon.setTextColor(colors.black)
- if redstoneSignal == "On" then
- cmon.setTextColor(colors.green)
- elseif redstoneSignal == "Off" then
- cmon.setTextColor(colors.red)
- end
- cmon.write(redstoneSignal)
- end
- -- Doing stuff!
- while true do
- -- Check stored energy on all nodes
- storedEnergy = 0
- maxEnergy = 0
- i = energyCellLow
- invalidCells = 0
- while i <= energyCellHigh do
- local cellid = "tile_thermalexpansion_cell_resonant_name_"..math.floor(i)
- if peripheral.isPresent(cellid) == true then
- local lES = peripheral.call(cellid,"getEnergyStored","south")
- local lMES = peripheral.call(cellid,"getMaxEnergyStored","south")
- storedEnergy = storedEnergy + lES
- maxEnergy = maxEnergy + lMES
- else
- invalidCells = invalidCells + 1
- end
- i = i + 1
- end
- cellCount = i
- -- Energy controller
- energyPercent = math.floor((storedEnergy/maxEnergy)*100)
- if energyPercent < energylow then
- redstone.setOutput(redstoneSide,true)
- elseif energyPercent >= energyhigh then
- redstone.setOutput(redstoneSide,false)
- end
- -- Progress bar colour
- if energyPercent <= 10 then
- progColor = colors.red
- elseif energyPercent <= 30 then
- progColor = colors.orange
- else
- progColor = colors.green
- end
- -- vars
- if redstone.getOutput(redstoneSide) == true then
- redstoneSignal = "On"
- else
- redstoneSignal = "Off"
- end
- clear() -- Draw progress time!
- drawConsoleMon(cellCount, energyPercent, progColor, invalidCells, redstoneSignal)
- drawProg(2, 2, "Battery charge", monX-2, 3, storedEnergy, maxEnergy, progColor, colors.gray)
- datestamp = "Day: "..os.day().." - Time: "..os.time()
- term.clear()
- term.setCursorPos(1,1)
- term.write(datestamp)
- term.setCursorPos(1,2)
- term.write("Energy: "..energyPercent.."% - Invalid cells: "..math.floor(invalidCells))
- term.setCursorPos(1,3)
- term.write("Redstone signal ("..redstoneSide.."): "..redstoneSignal)
- term.setCursorPos(1,4)
- term.write("Press and hold Ctrl+T to terminate script.")
- term.setCursorPos(1,6)
- term.write("Next update in")
- i = 0
- while i <= (sleepCycle - 1) do
- term.setCursorPos(15,6)
- term.write(" ")
- term.setCursorPos(15,6)
- term.write(" "..math.floor(sleepCycle-i).." Second(s)")
- i = i + 1
- sleep(1)
- end
- term.setCursorPos(1,7)
- term.write("Updating status...")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement