Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon=peripheral.wrap("monitor_2")
- local ae=peripheral.wrap("appeng_me_tilecontroller_0")
- local mfe1=peripheral.wrap("mfe_0")
- local mon_h,mon_v=mon.getSize()
- local fExit=false
- local TIMERINTERVAL=4
- local timer=os.startTimer(TIMERINTERVAL)
- local prevEUStored = 0
- 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 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 isAEOnline()
- return ae.getTotalBytes()~=0
- end
- local function updateME()
- local freeBytes = 0 + ae.getFreeBytes()
- local totalBytes = 0 + ae.getTotalBytes()
- printAt(1,mon_v," ME ",nil,iif(isMEOnline(),colours.green,colours.red))
- if isMEOnline() then
- local txtColor = iif(freeBytes>totalBytes/2,colors.black,iif(freeBytes<1000,colors.red,colours.green))
- printAt(5,mon_v,ae.getFreeBytes(),txtColor,colours.white)
- setColors(colours.black)
- mon.write("/"..ae.getTotalBytes().." Bytes ")
- mon.write(" "..ae.getStoredItemCount().." Items")
- else
- printAt(5,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 yPos=5
- printAt(1,yPos,"MFE 1 ",colours.black,colours.red)
- printAt(7,yPos,"|",colours.white,colours.black)
- printAt(mon_h-7,yPos,"| "..percentStored.."% ")
- drawHorizontalBar(8,yPos,mon_h-15,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