Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function iif(c,y,n)
- if c then return y end
- return n
- end
- local function nz(c,r,pfix)
- if c then
- return (pfix or "")..c
- else
- return r
- end
- end
- local function findPeripheral(name)
- local names=peripheral.getNames()
- for i,n in ipairs(name) do
- if n:find(name)==1 then
- return peripheral.wrap(n)
- end
- end
- error("could not find a peripheral of type '"..name..")
- return nil
- end
- local mon=findPeripheral("monitor_")
- local ae=findPeripheral("appeng_me_tilecontroller_")
- local mfe1=findPeripheral("mfe_")
- local mon_h,mon_v=mon.getSize()
- local fExit=false
- local TIMERINTERVAL=4
- local timer=os.startTimer(TIMERINTERVAL)
- local prevEUStored = 0
- local function setColors(foreground,background)
- if tonumber(foreground) then
- mon.setTextColor(foreground)
- end
- if tonumber(background) then
- mon.setBackgroundColor(background)
- end
- end
- local function printAt(x,y,txt,foreground,background)
- setColors(foreground,background)
- mon.setCursorPos(x,y)
- mon.write(txt)
- end
- local function printCenterAt(y,txt,foreground,background)
- printAt(1,y,string.rep(" ",mon_h),colours.black,background)
- printAt(math.floor((mon_h-string.len(txt))/2),y,txt,foreground,background)
- end
- local function drawHorizontalBar(x,y,w,h,percent)
- for j=1,h do
- for i=1,w do
- local percentOfBar= math.floor((i/w)*100)
- local colorIndex=iif(percentOfBar>percent, "gray",
- iif(percent>70,"white",
- iif(percent>50,"yellow",
- iif(percent>15,"orange",
- "red"))))
- printAt(x+i-1,y+j-1," ",colours.black,colors[colorIndex])
- end
- end
- end
- local function setupScreen()
- setColors(colours.white,colours.black)
- mon.clear()
- printCenterAt(1,"Vvenaya's Dashboard",colours.black,colours.green)
- printAt(1,3,"EU Power storage:",colours.white,colours.black)
- printAt(1,mon_v,string.rep(" ",mon_h),colours.black,colours.white)
- end
- local function getTotalMEBytes()
- return 0+ae.getTotalBytes()
- end
- local function getFreeMEBytes()
- -- return 0
- return 0+ae.getFreeBytes()
- end
- local function getFreeTypes()
- return 0+ae.getRemainingItemTypes()
- end
- local function getStoredTypes()
- return 0+ae.getStoredItemTypes()
- end
- local function isMEOnline()
- return getTotalMEBytes()~=0
- end
- local function updateME()
- local freeBytes = getFreeMEBytes()
- local totalBytes = getTotalMEBytes()
- local freeTypes = getFreeTypes()
- local totalTypes = getStoredTypes()+getFreeTypes()
- printAt(1,mon_v," ME ",colours.black,iif(isMEOnline(),colours.green,colours.red))
- if isMEOnline() then
- local txtColor = iif(freeBytes>totalBytes/2,colors.black,iif(freeBytes<1000,colors.red,colours.green))
- setColors(colours.black)
- printAt(6,,mon_v," M:",colours.black,colours.white)
- setColors(iif(freeBytes>totalBytes/2,colors.black,iif(freeBytes<1000,colors.red,colours.green)))
- write(ae.getFreeBytes().."/")
- setColors(colours.black)
- write(ae.getTotalBytes().." T:")
- setColors(freeTypes>totalTypes/2,colors.black,iif(freeTypes<10,colors.red,colours.green))
- write(freeTypes)
- setColors(colours.black)
- write("/"..totalTypes.." I:")
- mon.write(" I:"..ae.getStoredItemCount().." Items")
- else
- printAt(6,mon_v,"Offline"..string.rep(" ",mon_h-10),colours.red,colours.white)
- end
- end
- local function updateMFE()
- if not mfe1 then return end
- local capacity=mfe1.getEUCapacity()
- local EUStored=mfe1.getEUStored()
- local percentStored=math.floor((EUStored/capacity)*100)
- local deltaEUStored = math.floor(((EUStored - prevEUStored)/TIMERINTERVAL) / 20)
- local xPos=2
- local yPos=5
- printAt(xPos,yPos,"MFE 1 ",colours.black,colours.red)
- printAt(xPos+6,yPos,"|",colours.white,colours.black)
- printAt(mon_h-6,yPos,"| "..percentStored.."% ")
- drawHorizontalBar(xPos+7,yPos,mon_h-xPos-13,1, percentStored)
- printAt(3,yPos+2,"Total : " .. EUStored.." EU",colours.white, colours.black)
- local deltaAsString = ""..deltaEUStored
- printAt(3,yPos+3,"Delta : ")
- printAt(11,yPos+3,deltaAsString, iif(deltaEUStored<0,colours.red,colours.white))
- printAt(11+deltaAsString:len(),yPos+3," EU/t ",colours.white, colours.black)
- prevEUStored = EUStored
- end
- local function updateDashboard()
- updateME()
- updateMFE()
- end
- setupScreen()
- updateDashboard()
- while not fExit do
- local e,p1,p2,p3 = os.pullEvent()
- if e=="timer" and p1==timer then
- updateDashboard()
- timer=os.startTimer(TIMERINTERVAL)
- elseif e=="char" and p1=="x" then
- fExit=true
- else
- print(e.." "..nz(p1,"",":")..nz(p2,"",":")..nz(p3,"",":"))
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Monitoring application terminated.")
Advertisement
Add Comment
Please, Sign In to add comment