Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ae_cpu_dashboard.lua
- -- Zeigt grafisch alle Crafting-CPUs (CPU-Kerne) von AE2 an.
- -- Holt Daten per rednet vom Client (mit meBridge).
- -----------------------------------------
- -- 1) KONFIG
- -----------------------------------------
- local modemSide = "top" -- Wo dein Modem ist
- local monSide = "right" -- Wo dein Monitor ist
- local clientID = 5 -- ID des Computers, der am meBridge steht
- local refreshInterval = 5 -- Sekunden pro Update
- -----------------------------------------
- -- 2) INIT
- -----------------------------------------
- local modem = peripheral.wrap(modemSide)
- if not modem then
- error("Modem an Seite '"..modemSide.."' nicht gefunden!")
- end
- rednet.open(modemSide)
- local mon = peripheral.wrap(monSide)
- if not mon then
- error("Monitor an Seite '"..monSide.."' nicht gefunden!")
- end
- mon.setTextScale(0.5)
- local w, h = mon.getSize()
- -----------------------------------------
- -- 3) GLOBALE VARS
- -----------------------------------------
- local currentScreen = "main" -- "main" oder "detail"
- local cpus = {} -- Liste der CPUs: { {name, coProcessors, storage, busy}, ... }
- local selectedCPU = 1 -- Index in cpus
- -----------------------------------------
- -- 4) HILFSFUNKTIONEN
- -----------------------------------------
- local function clear()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- local function centerText(y, text, color)
- color = color or colors.white
- mon.setTextColor(color)
- local x = math.floor((w - #text)/2)
- mon.setCursorPos(x+1, y)
- mon.write(text)
- end
- -- Hole CPU-Liste vom Client
- local function fetchCPUs()
- rednet.send(clientID, {cmd="GET_CPUS"}, "ae2_cpus")
- local sender, resp, proto = rednet.receive("ae2_cpus", 3)
- if sender == clientID and type(resp)=="table" and resp.cpus then
- cpus = resp.cpus
- else
- cpus = {}
- end
- end
- -----------------------------------------
- -- 5) MAIN-SCREEN (Grafische Kaestchen)
- -----------------------------------------
- local function drawMainScreen()
- clear()
- centerText(1, "AE2 CPU Overview", colors.cyan)
- mon.setTextColor(colors.white)
- if #cpus == 0 then
- centerText(math.floor(h/2), "Keine CPUs gefunden", colors.red)
- return
- end
- -- Wir zeichnen pro CPU ein Rechteck, z.B. 3 Spalten a 10x5
- local boxW, boxH = 14, 5
- local cols = math.floor(w / (boxW+1))
- local startY = 3
- local i=1
- for row=0,10 do
- for col=0,cols-1 do
- local c = cpus[i]
- if not c then return end
- local x = col*(boxW+1)+2
- local y = row*(boxH+1)+startY
- -- Rahmen
- mon.setCursorPos(x, y)
- mon.write("+"..string.rep("-", boxW-2).."+")
- for rrow=1, boxH-2 do
- mon.setCursorPos(x, y+rrow)
- mon.write("|"..string.rep(" ", boxW-2).."|")
- end
- mon.setCursorPos(x, y+boxH-1)
- mon.write("+"..string.rep("-", boxW-2).."+")
- -- Name
- mon.setCursorPos(x+2, y+1)
- mon.setTextColor(colors.white)
- if c.name then
- mon.write(c.name)
- else
- mon.write("CPU #"..i)
- end
- -- Info: Busy / Not Busy
- mon.setCursorPos(x+2, y+2)
- if c.busy then
- mon.setTextColor(colors.red)
- mon.write("Crafting...")
- else
- mon.setTextColor(colors.lime)
- mon.write("Idle")
- end
- -- Co-Proz
- mon.setCursorPos(x+2, y+3)
- mon.setTextColor(colors.white)
- local co = c.coProcessors or 0
- local sto = c.storage or 0
- mon.write("Co: "..co..", "..sto.."k")
- i=i+1
- if i>#cpus then return end
- end
- end
- end
- -----------------------------------------
- -- 6) DETAIL-SCREEN
- -----------------------------------------
- local function drawDetailScreen(idx)
- clear()
- centerText(1, "AE2 CPU Detail", colors.cyan)
- local c = cpus[idx]
- if not c then
- centerText(math.floor(h/2), "CPU nicht gefunden", colors.red)
- return
- end
- mon.setCursorPos(2,3)
- mon.setTextColor(colors.white)
- mon.write("Name: "..(c.name or ("CPU #"..idx)))
- mon.setCursorPos(2,4)
- mon.write("Busy: ")
- if c.busy then
- mon.setTextColor(colors.red)
- mon.write("Ja")
- else
- mon.setTextColor(colors.lime)
- mon.write("Nein")
- end
- mon.setCursorPos(2,5)
- mon.setTextColor(colors.white)
- mon.write("Co-Prozessoren: "..(c.coProcessors or 0))
- mon.setCursorPos(2,6)
- mon.write("Storage: "..(c.storage or 0).."k")
- -- Evtl. mehr Felder, falls deine Version mehr Infos hat (z.B. "processingJob", "cpuIndex", etc.)
- mon.setCursorPos(2,h)
- mon.setTextColor(colors.yellow)
- mon.write("[ Zurueck ]")
- end
- -----------------------------------------
- -- 7) TOUCH-HANDLER
- -----------------------------------------
- local function clickMain(x,y)
- local boxW, boxH = 14,5
- local cols = math.floor(w / (boxW+1))
- local startY=3
- local i=1
- for row=0,10 do
- for col=0,cols-1 do
- local rx = col*(boxW+1)+2
- local ry = row*(boxH+1)+startY
- if x>=rx and x<=rx+boxW-1 and y>=ry and y<=ry+boxH-1 then
- -- CPU i geklickt
- if cpus[i] then
- selectedCPU = i
- currentScreen = "detail"
- drawDetailScreen(i)
- end
- return
- end
- i=i+1
- if i>#cpus then return end
- end
- end
- end
- local function clickDetail(x,y)
- if y==h then
- -- [ Zurueck ]
- currentScreen = "main"
- drawMainScreen()
- end
- end
- -----------------------------------------
- -- 8) UPDATE-SCHRITTE
- -----------------------------------------
- local function updateAll()
- fetchCPUs()
- end
- -----------------------------------------
- -- 9) HAUPT-LOOP
- -----------------------------------------
- local function main()
- updateAll()
- drawMainScreen()
- local timerID = os.startTimer(refreshInterval)
- while true do
- local e,p1,p2,p3 = os.pullEvent()
- if e=="timer" and p1==timerID then
- updateAll()
- if currentScreen=="main" then
- drawMainScreen()
- else
- drawDetailScreen(selectedCPU)
- end
- timerID = os.startTimer(refreshInterval)
- elseif e=="monitor_touch" then
- local x,y = p2,p3
- if currentScreen=="main" then
- clickMain(x,y)
- else
- clickDetail(x,y)
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement