Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local gpu = component.gpu
- local unicode = require("unicode")
- local event = require("event")
- local term = require("term")
- local computer = require("computer")
- computer.addUser("bogatyr4ik")
- computer.addUser("kudrin")
- if false == component.isAvailable("redstone") then
- print("Redstone not connected!")
- os.exit()
- end
- if false == component.isAvailable("extrautils_generatorsolar") then
- print("SolarPanel not connected!")
- os.exit()
- end
- local rs = component.redstone
- local panel = component.extrautils_generatorsolar
- local EnergyStep = 425000 -- шаг для батарейки
- local colorBack = 0x151515
- local colorText = 0xBC8F8F --0xFFFFFF --
- local colorRed = 0xFF0000
- local colorBlack = 0x000000
- local colorBlue = 0x4682B4
- local colorGreen = 0x00FF00
- local colorBattery = 0xFFFFFF
- local l, v = 4, 3 -- для основного текста l - отступ с лева v - отступ с верху
- local w, h = 64, 20
- local a = 100 -- Ёмкость в % для начала отдачи энергии
- local b = 70 -- Ёмкость в % для начала зарядки панелей
- local step = 5
- gpu.setResolution(w, h) -- Заданное розрешение экрана
- gpu.setBackground(colorBack)
- gpu.setForeground(colorText)
- gpu.fill(1,1,w,h, " ") -- Очистка экрана перед запуском программы
- -- Обводка экрана
- gpu.fill(1, 1, 1, 1, "┌")
- gpu.fill(1, h, 1, 1, "└")
- gpu.fill(1, 2 ,1, h-2, "│") -- левая пололса
- gpu.fill(w, 2, 1, h-2, "│") -- правая полоса
- gpu.fill(2, 1, w-2, 1, "─") --верхняя полоса
- gpu.fill(2, h, w-2, 1, "─") -- нижняя полоса
- gpu.fill(w, 1, 1, 1, "┐")
- gpu.fill(w, h, 1, 1, "┘")
- gpu.set(l,v, "SolarPanel Control Ready!!")
- gpu.set(l+unicode.len("Status: "),v+2, "Expectation")
- function buttom()
- gpu.setBackground(0xFFFFFF)
- gpu.setForeground(0x000000)
- gpu.set(l+13, v+5, " + ")
- gpu.set(l+17, v+5, " - ")
- gpu.set(l+13, v+7, " + ")
- gpu.set(l+17, v+7, " - ")
- gpu.setBackground(colorBack)
- gpu.setForeground(colorText)
- end
- --[[gpu.fill(l+10, v+5, 2, 1, " ")
- gpu.fill(l+10, v+7, 2, 1, " ")]]--
- function touch(w, h)
- if w >= l+13 and w <= l+15 and h == v+5 and a + step <= 100 then
- a = a + step
- gpu.setBackground(0x00FF00)
- gpu.set(l+13, v+5, " + ")
- os.sleep(0.1)
- gpu.setBackground(colorBack)
- elseif w >= l+17 and w <= l+19 and h == v+5 and a - step > b then
- a = a - step
- gpu.setBackground(0xFF0000)
- gpu.set(l+17, v+5, " - ")
- os.sleep(0.1)
- gpu.setBackground(colorBack)
- elseif w >= l+13 and w <= l+15 and h == v+7 and b + step < a then
- b = b + step
- gpu.setBackground(0x00FF00)
- gpu.set(l+13, v+7, " + ")
- os.sleep(0.1)
- gpu.setBackground(colorBack)
- elseif w >= l+17 and w <= l+19 and h == v+7 and b - step >= 0 then
- b = b - step
- gpu.setBackground(0xFF0000)
- gpu.set(l+17, v+7, " - ")
- os.sleep(0.1)
- gpu.setBackground(colorBack)
- end
- end
- function turn(i)
- for j = 0,5 do
- rs.setOutput(j,i)
- end
- end
- while true do
- stored = panel.getEnergyStored()
- MaxStored = panel.getMaxEnergyStored()
- EnergyUP = MaxStored/100*a
- EnergyDown = MaxStored/100*b
- MaxLevelEnergy = EnergyUP -- Уровени при котором начинает отдавать энергию
- MinLevelEnergy = EnergyDown -- Уровень при котором начинает заряд
- PercentStorage = math.ceil(stored*100/MaxStored)
- if stored >= MaxLevelEnergy then
- turn(1)
- gpu.setForeground(colorBlue)
- gpu.set(l+unicode.len("Status: "),v+2, "▼ Transmition")
- gpu.setForeground(colorText)
- end
- if stored < MinLevelEnergy then
- turn(0)
- gpu.setForeground(colorGreen)
- gpu.set(l+unicode.len("Status: "),v+2, "▲ Charging ")
- gpu.setForeground(colorText)
- end
- -- Вывод строк данных
- gpu.set(l, v+1, "Energy in Generator: ["..stored.."] RF "..PercentStorage.."% ")
- gpu.set(l, v+2, "Status: ")
- gpu.set(l, v+3, "Curent control:")
- gpu.set(l, h-2, "by Bogatyr4ik")
- gpu.set(l+2, v+5, "Max:")
- gpu.set(l+2, v+7, "Min:")
- if a < 100 then
- gpu.fill(l+10, v+5, 2, 1, " ")
- end
- if b < 10 then
- gpu.fill(l+9, v+7, 2, 1, " ")
- end
- gpu.setForeground(colorRed) -- красный
- gpu.set(l+7, v+5, ""..a.."%")
- gpu.setForeground(colorGreen) -- зелёный
- gpu.set(l+7, v+7, ""..b.."%")
- -- Виз батарейки
- verticalpos = 1 -- вертикаль gz
- horizontalpos = 15 -- горизонталь vk
- gpu.setForeground(colorText)
- gpu.fill(w/2+5+horizontalpos, h/2-9+verticalpos, 6, 1, "█") -- контакт
- gpu.fill(w/2+horizontalpos, h/2-8+verticalpos, 16, 17, "█") -- основа
- gpu.setForeground(colorGreen)
- gpu.fill(w/2+2+horizontalpos, h/2-7+verticalpos,12, 15, "█") -- заливка пустоты чёрная
- -- Вывод энергиии в батарейке
- gpu.setForeground(colorBlack)
- gpu.fill(w/2+2+horizontalpos, h/2-7+verticalpos, 12, (100-PercentStorage)*(15/100), "█") -- Ёмкость Энергии Зелёная
- gpu.setForeground(colorText)
- buttom()
- term.setCursor(1,1)
- local e,_,w,h,_,_ = event.pull(0.1, "touch")
- if e == "touch" then
- touch(w, h)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement