Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Fontion text
- function putValue (line, text, color)
- local align = 30 - string.len(text)
- term.setCursorPos(align, line)
- term.setTextColor(color)
- print(text)
- end
- --Fonction nombre
- function putNumber (number)
- local round = 0
- local texts = ""
- if number >= 1000000000000000000 then
- round = (number / 1000000000000000000)
- texts = string.sub(round, 0, 5) .. " ERF"
- else
- if number >= 1000000000000000 then
- round = (number / 1000000000000000)
- texts = string.sub(round, 0, 5) .. " PRF"
- else
- if number >= 1000000000000 then
- round = (number / 1000000000000)
- texts = string.sub(round, 0, 5) .. " TRF"
- else
- if number >= 1000000000 then
- round = (number / 1000000000)
- texts = string.sub(round, 0, 5) .. " GRF"
- else
- if number >= 1000000 then
- round = (number / 1000000)
- texts = string.sub(round, 0, 5) .. " MRF"
- else
- if number >= 1000 then
- round = (number / 1000)
- texts = string.sub(round, 0, 5) .. " kRF"
- else
- texts = string.sub(number, 0, 5) .. " RF"
- end
- end
- end
- end
- end
- end
- return texts
- end
- --Initialisation periphérique
- monitor = peripheral.wrap("top")
- battery = peripheral.find("inductionPort")
- --Check periphérique
- if monitor == nil then
- error("ER: Pas d'ecran trouvé")
- else
- monitor.clear()
- term.redirect(monitor)
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.black)
- end
- if battery == nil then
- error("ER: Pas de batterie trouvé")
- end
- --Creation de l'interface
- term.setCursorPos(11, 2);
- print("Max RF:")
- term.setCursorPos(11, 3);
- print("Max Thru:")
- term.setCursorPos(11, 5);
- print("Cur In:")
- term.setCursorPos(11, 6);
- print("Cur Out:")
- term.setCursorPos(11, 7);
- print("Cur Bal:")
- term.setCursorPos(11, 9);
- print("Stored:")
- term.setCursorPos(11, 10);
- print("Filled:")
- --Actualisaiton des données
- while true do
- --donnees fixes I/O
- batteryMaxCharge = battery.getMaxEnergy()
- batteryMaxInOuts = battery.getTransferCap()
- putValue(2, putNumber(batteryMaxCharge), colors.lightBlue)
- putValue(3, putNumber(batteryMaxInOuts), colors.lightBlue)
- --Delta I/O
- batteryCurrentIn = battery.getLastInput()
- batteryCurrentOut = battery.getLastOutput()
- putValue(5, putNumber(batteryCurrentIn), colors.lightBlue)
- putValue(6, putNumber(batteryCurrentOut), colors.lightBlue)
- --Couleur et Signe I/O
- batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
- batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
- batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
- putValue(7, batteryCurrentSign .. putNumber(batteryCurrentBalance), batteryCurrentColor)
- --Donnees fixes charge
- batteryCurrentCharge = battery.getEnergy()
- putValue(9, putNumber(batteryCurrentCharge), colors.lightBlue)
- --Pourcentage de charge
- batteryCurrentColor = colors.red
- batteryCurrentPercentage = ((batteryCurrentCharge / batteryMaxCharge) * 100)
- 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)
- --Temps d'Actualisaiton
- os.sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement