Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PERIPHERIE LOKALISIEREN --
- local matrix = peripheral.find("inductionPort")
- local mon = peripheral.find("monitor")
- local avgAr = {}
- --DEBUG--
- --[[if matrix==nil then
- print("Matrix is nil")
- else
- print("Matrix found")
- end
- ]]--
- -- ALLE WICHTIGEN DATEN AUS DER MATRIX ZIEHEN (LOOP) --
- while true do
- local monX, monY = mon.getSize()
- local rawEnergy = matrix.getEnergy() or error("No Matrix found") -- INT
- local rawEnergyMax = matrix.getMaxEnergy() or error("No Matrix found") -- INT
- local rawEnergyPercentage = matrix.getEnergyFilledPercentage() or error("No Matrix found") -- INT
- local rawFormed = matrix.isFormed() -- BOOLEAN
- if rawFormed==true then
- --print("formed is true") --DEBUG
- rawHeight = matrix.getHeight() or error("No Matrix found") -- INT
- rawLength = matrix.getLength() or error("No Matrix found") -- INT
- rawWidth = matrix.getWidth() or error("No Matrix found") -- INT
- rawCells = matrix.getInstalledCells() or error("No Matrix found") -- INT
- rawProviders = matrix.getInstalledProviders() or error("No Matrix found") -- INT
- rawInput = matrix.getLastInput() or error("No Matrix found") -- INT
- rawOutput = matrix.getLastOutput() or error("No Matrix found") -- INT
- else
- --print("formed is false") --DEBUG
- rawHeight = 0 -- INT
- rawLength =0 -- INT
- rawWidth = 0 -- INT
- rawCells = 0 -- INT
- rawProviders = 0 -- INT
- rawInput = 0 -- INT
- rawOutput = 0 -- INT
- end
- --DEBUG--
- --[[print(rawEnergy)
- print(rawEnergyMax)
- print(rawEnergyPercentage)
- print(rawFormed)
- print(rawHeight)
- print(rawLength)
- print(rawWidth)
- print(rawCells)
- print(rawProviders)
- print(rawInput)
- print(rawOutput)]]--
- -- ENERGYWERTE UMRECHNEN --
- local energyFE = (rawEnergy / 10)*4
- local energyMaxFE = (rawEnergyMax / 10)*4
- local energyPercentage = rawEnergyPercentage*100
- local inputFE = (rawInput / 10)*4
- local outputFE = (rawOutput / 10)*4
- if table.getn(avgAr) >= 20 then
- table.remove(avgAr,1)
- table.insert(avgAr,outputFE)
- else
- table.insert(avgAr,outputFE)
- end
- local avg = 0
- --DEBUG--
- --print("Avg=0: "..avg)
- for i=1,#avgAr do
- avg = avg + avgAr[i]
- end
- --DEBUG--
- --print("Avg Neu: "..avg)
- --DEBUG--
- --[[
- print("Aktuelle Anzahl Werte in Array: "..table.getn(avg))
- ]]--
- local secs = energyFE / ((avg*20)/20)
- --DEBUG--
- --print("Secs: "..secs)
- function calc(param)
- if param<1000 then
- param = math.floor(param)
- result = tostring(param.." FE")
- return result
- elseif param<1000000 then
- param = param/1000
- local X = math.pow(10, 2)
- param = math.floor(param * X) / X
- result = string.format("%0.2f kFE",param)
- return result
- elseif param<1000000000 then
- param = param/1000000
- local X = math.pow(10, 2)
- param = math.floor(param * X) / X
- result = string.format("%0.2f MFE",param)
- return result
- elseif param<1000000000000 then
- param = param/1000000000
- local X = math.pow(10, 2)
- param = math.floor(param * X) / X
- result = string.format("%0.2f GFE",param)
- return result
- elseif param<1000000000000000 then
- param = param/1000000000000
- local X = math.pow(10, 2)
- param = math.floor(param * X) / X
- result = string.format("%0.2f TFE",param)
- return result
- end
- end
- function timeleft(secs)
- secs = math.floor(secs)
- -- Days
- local weeks = math.floor(secs / 604800)
- secs = secs - (604800 * weeks)
- -- Days
- local days = math.floor(secs / 86400)
- secs = secs - (86400 * days)
- -- Hours
- local hours = math.floor(secs / 3600)
- secs = secs - (3600 * hours)
- -- Minutes
- local mins = math.floor(secs / 60)
- secs = secs - (60 * mins)
- -- If we have more than 72h worth of storage, switch to week, day, hour format
- if weeks > 0 then
- return string.format('%dwk %dd %dh', weeks, days, hours)
- elseif days >= 3 then
- return string.format('%dd %dh', days, hours)
- end
- -- Formatting to have trailing zeros on H:MM:SS
- return string.format('%d:%02d:%02d', hours, mins, secs)
- end
- -- SCREEN INITIALISIEREN --
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setTextScale(1)
- mon.setBackgroundColor(colors.blue)
- for i = 1,monX do
- mon.write(" ")
- end
- mon.setCursorPos(1,2)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- local title = "Induction Matrix"
- local len = string.len(title)
- mon.setCursorPos((monX - len+1) / 2, 2)
- mon.write(title)
- mon.setCursorPos(monX, 2)
- mon.setBackgroundColor(colors.blue)
- mon.write(" ")
- mon.setCursorPos(1,3)
- for i = 1,monX do
- mon.write(" ")
- end
- mon.setCursorPos(1,4)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.write("Online: ")
- if rawFormed==true then
- mon.setBackgroundColor(colors.lime)
- mon.write(" ")
- else
- mon.setBackgroundColor(colors.red)
- mon.write(" ")
- end
- mon.setCursorPos(monX, 4)
- mon.setBackgroundColor(colors.blue)
- mon.write(" ")
- mon.setCursorPos(1,5)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.write("Cells: "..rawCells.." | Providers: "..rawProviders)
- pertemp = string.format(" | %02.02f",energyPercentage)
- mon.write(pertemp.." %")
- mon.setCursorPos(monX, 5)
- mon.setBackgroundColor(colors.blue)
- mon.write(" ")
- mon.setCursorPos(1,6)
- mon.setBackgroundColor(colors.blue)
- for i = 1,monX do
- mon.write(" ")
- end
- mon.setCursorPos(1,7)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.write("Current: "..calc(energyFE).." / "..calc(energyMaxFE))
- mon.setBackgroundColor(colors.blue)
- mon.setCursorPos(monX,7)
- mon.write(" ")
- mon.setCursorPos(1,8)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.write("Input : "..calc(inputFE).."/t")
- mon.setBackgroundColor(colors.blue)
- mon.setCursorPos(monX,8)
- mon.write(" ")
- mon.setCursorPos(1,9)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.write("Output : "..calc(outputFE).."/t")
- mon.setBackgroundColor(colors.blue)
- mon.setCursorPos(monX,9)
- mon.write(" ")
- mon.setCursorPos(1,10)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- --
- mon.setCursorPos(monX, 10)
- mon.setBackgroundColor(colors.blue)
- mon.write(" ")
- mon.setCursorPos(1,11)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- --TIME LEFT--
- if inputFE >= outputFE then
- mon.write("Time Left: Charging...")
- elseif outputFE >= inputFE then
- mon.write("Time Left: "..timeleft(secs))
- else
- mon.write("Idle...")
- end
- mon.setCursorPos(monX, 11)
- mon.setBackgroundColor(colors.blue)
- mon.write(" ")
- --ABSCHLUSS--
- mon.setCursorPos(1,monY)
- mon.setBackgroundColor(colors.blue)
- for i = 1,monX do
- mon.write(" ")
- end
- os.sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement