Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Power Monitoring Program
- --Version 13
- --Center Text Function
- function centerText(text,yVal)
- length = string.len(text)
- minus = math.floor(monX-length)
- x = math.floor(minus/2)
- mon.setCursorPos(x+1,yVal)
- mon.write(text)
- end
- --Sets the BackGround to White (Cleaner than before)
- function clearScreen()
- mon.clear()
- mon.setBackgroundColour(colors.white)
- for i=1,monY do
- mon.setCursorPos(1,i)
- mon.write(string.rep(" ",monX))
- end
- end
- --PreFace
- --Set Variables and load settings
- config = fs.open("config/monitor","r")
- mon = config.readAll()
- config.close()
- config = fs.open("config/cube","r")
- cube = config.readAll()
- config.close()
- config = fs.open("config/title","r")
- title = config.readAll()
- config.close()
- config = fs.open("config/mekanism","r")
- mekanism = config.readAll()
- config.close()
- config = fs.open("config/IC2","r")
- IC2 = config.readAll()
- config.close()
- config = fs.open("config/rate","r")
- rate = config.readAll()
- config.close()
- --Shows Settings inside control computer
- term.setTextColour(colors.red)
- print("Final Settings")
- term.setTextColour(colors.blue)
- print("Monitor: "..mon)
- print("Battery: "..cube)
- print("Title: "..title)
- print("Mekanism: "..mekanism)
- print("IC2: "..IC2)
- print("Rate: "..rate.." fast/slow")
- term.setTextColour(colors.red)
- print("If settings are incorrect. Run setup again")
- print("Hold CTRL+T to stop program")
- --RF/EU label
- if IC2 == "y" then energyAPI = " EU" else energyAPI = " RF" end
- --Wraps the Peripherals
- cube = peripheral.wrap(cube)
- mon = peripheral.wrap(mon)
- while true do
- --mon.setTextScale(scale)
- monX,monY = mon.getSize()
- width = monX-2 height1 = monY-1 height2 = monY-2
- --Main Program
- --Variables for Calculations
- if mekanism == "y" then maxE = cube.getMaxEnergy() or 1
- elseif IC2 == "y" then maxE = cube.getEUCapacity() or 1
- else maxE = cube.getMaxEnergyStored() or 1
- end
- if mekanism == "y" then curE = cube.getStored() or 6.66
- elseif IC2 == "y" then curE = cube.getEUStored() or 6.66
- else curE = cube.getEnergyStored() or 6.66
- end
- if mekanism == "y" then maxE = maxE/2.5 end
- if mekanism == "y" then curE = curE/2.5 end
- rawPer = curE/maxE
- percent = math.floor((rawPer*100)+0.5)
- bar = math.floor((rawPer*width)+0.5)
- stats = curE
- --Variable for Dynamic Screen Size ( in the loop so you can change the screen size while the program is running)
- mon.setTextScale(0.5)
- monX,monY = mon.getSize()
- if monX <= 16 or monY <= 11 then mon.setTextScale(0.5) elseif
- monX <= 37 or monY <= 25 then mon.setTextScale(1) elseif
- monX <= 58 or monY <= 39 then mon.setTextScale(1.5) elseif
- monX <= 80 or monY <= 53 then mon.setTextScale(2) elseif
- monX <= 101 or monY <= 68 then mon.setTextScale(2.5) else
- mon.setTextScale(3)
- end
- monX,monY = mon.getSize()
- width = monX-2
- height1 = monY-1
- height2 = monY-2
- --Centers and Displays Title On Monitor
- clearScreen()
- mon.setBackgroundColour(colors.black)
- mon.setTextColour(colors.lightGray)
- mon.setCursorPos(1,1)
- centerText(string.rep(" ",string.len(title)+2),1)
- centerText(title,1)
- --Monitor Statistics
- mon.setBackgroundColour(colors.white)
- mon.setTextColour(colors.blue)
- if monX >= math.floor(string.len(stats)+18)
- then
- centerText("Current Energy:"..curE..energyAPI,3)
- else
- centerText("Current Energy:",3)
- centerText(" "..curE..energyAPI,4)
- end
- if percent == 666
- then
- mon.setTextColour(colors.red)
- centerText("Connect Cell!",6)
- else
- mon.setTextColour(colors.green)
- centerText(percent.."% Full",6)
- end
- --Loading Bar Code Re-Written Much MUCH simpler than before
- mon.setCursorPos(2,height2)
- mon.setBackgroundColour(colors.gray)
- mon.write(string.rep(" ",width))
- mon.setCursorPos(2,height2)
- if percent == 666 then mon.setBackgroundColour(colors.red) else
- mon.setBackgroundColour(colors.lime) end
- mon.write(string.rep(" ",bar))
- mon.setCursorPos(2,height1)
- mon.setBackgroundColour(colors.gray)
- mon.write(string.rep(" ",width))
- mon.setCursorPos(2,height1)
- if percent == 666 then mon.setBackgroundColour(colors.red) else
- mon.setBackgroundColour(colors.lime) end
- mon.write(string.rep(" ",bar))
- if rate == "f" then os.sleep(1)
- elseif rate == "s" then os.sleep(5)
- else os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement