Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function putValue(line, text, color)
- local align = 30 - string.len(text)
- term.setCursorPos(align, line)
- term.setTextColor(color)
- print(text)
- end
- function DrawBox(xMin, xMax, yMin, yMax, title)
- term.setBackgroundColor(colors.gray)
- for xPos = xMin, xMax, 1 do
- term.setCursorPos(xPos, yMin)
- term.write(" ")
- end
- for yPos = yMin, yMax, 1 do
- term.setCursorPos(xMin, yPos)
- term.write(" ")
- term.setCursorPos(xMax, yPos)
- term.write(" ")
- end
- for xPos = xMin, xMax, 1 do
- term.setCursorPos(xPos, yMax)
- term.write(" ")
- end
- term.setCursorPos(xMin + 4, yMin)
- term.setBackgroundColor(colors.black)
- term.write(" ")
- term.write(title)
- term.write(" ")
- end
- function DrawProgress(xMin, xMax, yMin, yMax, percentage)
- yTotal = yMax - yMin
- for xPos = xMin, xMax, 1 do
- term.setCursorPos(xPos, yMin)
- for yPos = yMin, yMax, 1 do
- yProgress = 1 - ((yPos - yMin) / yTotal)
- if yProgress <= percentage then
- term.setPaletteColour(colors.green, 0x5cd65c)
- term.setBackgroundColor(colors.green)
- else
- term.setPaletteColour(colors.red, 0xFF6666)
- term.setBackgroundColor(colors.red)
- end
- term.setCursorPos(xPos, yPos)
- term.write(" ")
- end
- end
- term.setBackgroundColor(colors.black)
- end
- function putNumber(number)
- local round = 0
- local texts = ""
- if number >= 1000000000000000000 then
- round = (number / 1000000000000000000)
- texts = string.sub(round, 0, 3) .. "ERF"
- else
- if number >= 1000000000000000 then
- round = (number / 1000000000000000)
- texts = string.sub(round, 0, 3) .. "PRF"
- else
- if number >= 1000000000000 then
- round = (number / 1000000000000)
- texts = string.sub(round, 0, 3) .. "TRF"
- else
- if number >= 1000000000 then
- round = (number / 1000000000)
- texts = string.sub(round, 0, 3) .. "GRF"
- else
- if number >= 1000000 then
- round = (number / 1000000)
- texts = string.sub(round, 0, 4) .. "MRF"
- else
- if number >= 1000 then
- round = (number / 1000)
- texts = string.sub(round, 0, 4) .. "kRF"
- else
- texts = string.sub(number, 0, 3) .. " RF"
- end
- end
- end
- end
- end
- end
- return texts
- end
- -- Initialize our interface!
- -- Find all of our peripherals
- monitor = peripheral.find("monitor")
- battery = peripheral.find("inductionMatrix")
- -- Check and bind monitor
- if monitor == nil then
- error("ER: No screen found to display!")
- else
- monitor.clear()
- term.redirect(monitor)
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.black)
- DrawBox(2, 17, 2, 25, "ENERGY")
- end
- -- Check if we have a battery
- if battery == nil then
- error("ER: No battery connected to computer")
- end
- -- -- Draw our static interface text
- -- term.setCursorPos(1, 2);
- -- print("Max RF:")
- -- term.setCursorPos(1, 3);
- -- print("Max Thru:")
- term.setCursorPos(1, 1)
- DrawBox(2, 17, 20, 25, "CURRENT")
- term.setTextColor(colors.green)
- term.setCursorPos(5, 22);
- print("In:")
- term.setTextColor(colors.red)
- term.setCursorPos(12, 22);
- print("Out:")
- -- term.setCursorPos(1, 7);
- -- print("Cur Bal:")
- -- term.setCursorPos(1, 9);
- -- print("Stored:")
- -- term.setCursorPos(1, 10);
- -- print("Filled:")
- -- term.setCursorPos(1, 11);
- -- print("Critical:")
- -- Entering our infinite loop of checking the battery
- -- This will refresh all information every 2 seconds
- alarmIsRinging = false
- alarmIsActive = false
- alarmCounter = 0
- while true do
- -- batteryMaxCharge = battery.getMaxEnergy()
- -- batteryMaxInOuts = battery.getTransferCap()
- -- -- putValue(2, putNumber(batteryMaxCharge), colors.lightBlue)
- -- -- putValue(3, putNumber(batteryMaxInOuts), colors.lightBlue)
- -- -- Get our input/output/balance battery values
- batteryCurrentIn = battery.getLastInput()
- batteryCurrentOut = battery.getLastOutput()
- term.setTextColor(colors.green)
- term.setCursorPos(4, 23);
- print(putNumber(batteryCurrentIn))
- term.setTextColor(colors.red)
- term.setCursorPos(11, 23);
- print(putNumber(batteryCurrentOut))
- -- batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
- -- batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
- -- batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
- -- putValue(7, batteryCurrentSign .. putNumber(batteryCurrentBalance), batteryCurrentColor)
- -- -- Get our statistical values
- -- batteryCurrentCharge = battery.getEnergy()
- -- putValue(9, putNumber(batteryCurrentCharge), colors.lightBlue)
- batteryCurrentColor = colors.red
- batteryCurrentPercentage = battery.getEnergyFilledPercentage() * 100
- batteryCurrent = battery.getEnergyFilledPercentage()
- if batteryCurrentPercentage > 30 then
- batteryCurrentColor = colors.orange
- end
- if batteryCurrentPercentage > 60 then
- batteryCurrentColor = colors.green
- end
- -- putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
- term.setCursorPos(1, 1)
- DrawProgress(5, 14, 4, 16, batteryCurrent)
- term.setCursorPos(1, 1)
- term.setTextColor(batteryCurrentColor)
- term.setCursorPos(7, 18);
- print(string.sub(batteryCurrentPercentage, 0, 5) .. "%")
- term.setBackgroundColor(colors.black)
- -- Hey, ring the alarm!
- if batteryCurrentPercentage > 10 then
- alarmIsRinging = false
- alarmIsActive = false
- end
- if batteryCurrentPercentage < 10 and alarmIsActive == false then
- alarmIsRinging = true
- alarmIsActive = true
- alarmCounter = 0
- redstone.setOutput("back", true)
- end
- if alarmIsRinging == true then
- alarmCounter = alarmCounter + 1
- if alarmCounter >= 10 then
- redstone.setOutput("back", false)
- alarmIsRinging = false
- end
- end
- -- Wait 2s until next iteration
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement