Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by User.
- --- DateTime: 08.05.2019 15:06
- ---
- ---▁▂▃▄▅▆▇█▒
- local comp = require("component")
- local event = require("event")
- local gtBattBuf = comp.gt_batterybuffer
- local sides = require("sides")
- local computer = require("computer")
- local rs = comp.redstone
- local gpu = comp.gpu
- local w, h = gpu.maxResolution()
- local colors = {
- white = 0xffffff,
- orange = 0xff9200,
- magenta = 0xff00ff,
- lightblue = 0x99dbff,
- yellow = 0xffff00,
- lime = 0x00ff00,
- pink = 0xffb6bf,
- gray = 0x787878,
- silver = 0xc3c3c3,
- cyan = 0x00ffff,
- purple = 0x990080,
- blue = 0x0000ff,
- brown = 0x992440,
- green = 0x009200,
- red = 0xff0000,
- black = 0x000000
- }
- --CONFIG BEGIN
- local backgroundColor = 0x26261b
- local mainTextColor = 0x7f1ae5
- local storageColor = colors.red
- local inputColor = colors.green
- local outputColor = colors.blue
- local runningIndicatorColor = 0xbfff00
- local numderLineStorageColor = colors.red
- local numderLineIOColor = colors.cyan
- local backgroundDiagramColor = colors.black
- local redstoneIOControlGenerationSide = sides.bottom
- local startGenerationLim = 0.05
- local stopGenerationLim = 0.98
- local maxEnergyOutput = 8192 * 16
- local ioGraphSpeedDiv = 5 -- also input averaging coefficient, value 1 = 0.05s def 20 = 1sec
- local storageGraphSpeedDiv = 120 -- div from ioGraphSpeedDiv def 30 = 30sec
- local head = "MAIN POWER SYSTEM" -- 32 chars max
- --CONFIG END
- local headOffSet = math.modf((32 - string.len(head)) / 2)
- local clear = " "
- local diagramPosX = 1
- local diagramSizeX = w - 4
- local diagramPosY = 11
- local diagramSizeY = h - 11
- local sensInform
- local capacity
- local stepSizeCap
- local stepSizeIO
- local int_stepSizeCap
- local int_stepSizeIO
- local partsChar = { " ", "▁", "▂", "▃", "▄", "▅", "▆", "▇" }
- function numPoints(s)
- local x = string.len(s)
- local r = ""
- if (x <= 3) then
- return s
- end
- if (x % 3 == 0) then
- for i = 1, x, 3 do
- r = r .. string.sub(s, i, i + 2) .. "."
- end
- else
- r = r .. string.sub(s, 1, x % 3) .. "."
- for i = 1 + x % 3, x, 3 do
- r = r .. string.sub(s, i, i + 2) .. "."
- end
- end
- return string.sub(r, 1, string.len(r) - 1)
- end
- function mark(n)
- local s = string.sub(numPoints(tostring(n)), 1, 3)
- if n < 1000 and n > 0 then
- s = s .. " "
- elseif n < 1000000 then
- --k
- s = s .. "K"
- elseif n < 1000000000 then
- --m
- s = s .. "M"
- elseif n < 1000000000000 then
- --b
- s = s .. "B"
- elseif n < 1000000000000000 then
- --t
- s = s .. "T"
- else
- s = "err"
- end
- return s
- end
- local m = 0
- function drawGraphNext(storage, input, output)
- if input > maxEnergyOutput then
- input = maxEnergyOutput
- end
- if output > maxEnergyOutput then
- output = maxEnergyOutput
- end
- local i = math.modf(input / stepSizeIO)
- local o = math.modf(output / stepSizeIO)
- gpu.copy(diagramPosX + 1, diagramPosY, diagramSizeX - 1, diagramSizeY, -1, 0)
- gpu.setBackground(backgroundDiagramColor)
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY, 1, diagramSizeY, " ")
- if (i >= o) then
- gpu.setBackground(inputColor)
- gpu.setForeground(outputColor)
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY + diagramSizeY - o, 1, o, "▒")
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY + diagramSizeY - i, 1, i - o, " ")
- gpu.setBackground(backgroundColor)
- gpu.setForeground(mainTextColor)
- else
- gpu.setBackground(inputColor)
- gpu.setForeground(outputColor)
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY + diagramSizeY - i, 1, i, "▒")
- gpu.setBackground(backgroundDiagramColor)
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY + diagramSizeY - o, 1, o - i, "▒")
- gpu.setBackground(backgroundColor)
- gpu.setForeground(mainTextColor)
- end
- if m % storageGraphSpeedDiv == 0 then
- gpu.setForeground(storageColor)
- local st = math.modf(storage / stepSizeCap)
- local p = math.modf((storage - stepSizeCap * st) / (stepSizeCap / 8))
- gpu.copy(34, 1, 160 - 33 - 4, 10, -1, 0)
- gpu.fill(160 - 4, 1, 1, 10, " ")
- gpu.fill(160 - 4, 10 - st + 1, 1, st, "█")
- gpu.set(160 - 4, 10 - st, partsChar[p + 1])
- gpu.setForeground(mainTextColor)
- end
- m = m + 1
- end
- function init()
- local temp
- sensInform = gtBattBuf.getSensorInformation()
- gpu.setForeground(mainTextColor)
- gpu.setBackground(backgroundColor)
- gpu.fill(1, 1, w, h, ' ')
- gpu.set(headOffSet, 1, head)
- temp = string.sub(sensInform[1],4,#sensInform[1]-3)
- gpu.set(1,2,temp)
- temp = string.gsub(sensInform[4], "([^0-9]+)", "") -- storage capacity
- capacity = tonumber(temp)
- stepSizeCap = capacity / 10
- stepSizeIO = maxEnergyOutput / diagramSizeY
- int_stepSizeCap = math.modf(stepSizeCap)
- int_stepSizeIO = math.modf(stepSizeIO)
- gpu.set(1, 4, string.sub("EU energy max " .. numPoints(tostring(capacity)) .. clear, 1, 32))
- gpu.setForeground(storageColor)
- gpu.set(1, 3, "EU energy store ")
- gpu.setForeground(inputColor)
- gpu.set(1, 5, "EU energy in ")
- gpu.setForeground(outputColor)
- gpu.set(1, 6, "EU energy out ")
- gpu.setForeground(mainTextColor)
- gpu.setBackground(backgroundDiagramColor)
- gpu.fill(diagramPosX, diagramPosY, diagramSizeX, diagramSizeY, " ")
- gpu.setForeground(numderLineStorageColor)
- temp = int_stepSizeCap
- for i = 10, 1, -1 do
- gpu.set(160 - 3, i, mark(temp))
- temp = temp + int_stepSizeCap
- end
- gpu.setBackground(backgroundColor)
- gpu.setForeground(numderLineIOColor)
- temp = int_stepSizeIO
- for i = diagramPosY + diagramSizeY - 1, diagramPosY, -1 do
- gpu.set(diagramSizeX + 1, i, mark(temp))
- temp = temp + int_stepSizeIO
- end
- gpu.setForeground(mainTextColor)
- end
- function blink(flag)
- if flag then
- color = gpu.setBackground(runningIndicatorColor)
- gpu.set(1, 1, " ")
- gpu.setBackground(backgroundColor)
- else
- gpu.set(1, 1, " ")
- end
- return not flag
- end
- function loop()
- local preCapacity = capacity
- local temp = 0
- local flag = true
- local input = 0
- local output = 0
- local n = 0
- local energyStored = 0
- local time
- local filter = function(name, ...)
- if name == "touch" then
- return true
- else
- return false
- end
- end
- while true do
- --time = computer.uptime()
- if event.pullFiltered(0.05, filter) == "touch" then
- w, h = gpu.maxResolution()
- if gpu.getViewport() ~= w then
- gpu.setViewport(w, h)
- gpu.set(1, 10, " ")
- else
- gpu.setViewport(32, 10)
- w, h = 32, 10;
- end
- end
- sensInform = gtBattBuf.getSensorInformation()
- temp = string.gsub(sensInform[4], "([^0-9]+)", "") -- storage capacity
- capacity = tonumber(temp)
- if capacity ~= preCapacity then
- preCapacity = capacity
- stepSizeCap = capacity / 10
- int_stepSizeCap = math.modf(stepSizeCap)
- gpu.setForeground(numderLineStorageColor)
- temp = int_stepSizeCap
- for i = 10, 1, -1 do
- gpu.set(160 - 3, i, mark(temp))
- temp = temp + int_stepSizeCap
- end
- gpu.setForeground(mainTextColor)
- temp = string.sub(sensInform[1],4,#sensInform[1]-3)
- gpu.set(1,2,temp)
- gpu.set(17, 4, string.sub(numPoints(tostring(capacity)) .. clear, 1, 32 - 17))
- end
- temp = string.gsub(sensInform[6], "([^0-9]+)", "") -- storage input
- temp = string.sub(temp, 2)
- input = input + tonumber(temp)
- temp = string.gsub(sensInform[8], "([^0-9]+)", "") -- storage output
- output = math.max(output, tonumber(temp))
- if n ~= 0 and n % ioGraphSpeedDiv == 0 then
- temp = string.gsub(sensInform[3], "([^0-9]+)", "") -- storage energy
- energyStored = tonumber(temp)
- gpu.setForeground(storageColor)
- gpu.set(17, 3, string.sub(numPoints(tostring(energyStored)) .. clear, 1, 32 - 17))
- gpu.setForeground(mainTextColor)
- if energyStored / capacity <= startGenerationLim then
- rs.setOutput(redstoneIOControlGenerationSide, 15)
- elseif energyStored / capacity >= stopGenerationLim then
- rs.setOutput(redstoneIOControlGenerationSide, 0)
- end
- if rs.getOutput(redstoneIOControlGenerationSide) == 0 then
- gpu.set(1, h, "Energy Generation Disable")
- else
- gpu.set(1, h, "Energy Generation Enable ")
- end
- input = math.modf(input / ioGraphSpeedDiv)
- output = math.modf(output)
- gpu.setForeground(inputColor)
- gpu.set(17, 5, string.sub(numPoints(tostring(input)) .. clear, 1, 32 - 17))
- gpu.setForeground(outputColor)
- gpu.set(17, 6, string.sub(numPoints(tostring(output)) .. clear, 1, 32 - 17))
- gpu.setForeground(mainTextColor)
- drawGraphNext(energyStored, input, output)
- input = 0
- output = 0
- flag = blink(flag)
- end
- n = n + 1
- --gpu.set(1,6, tostring(computer.uptime()-time))
- end
- end
- init()
- loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement