-- pocket_startup.lua -- Pocket controller for CC:Tweaked. REPL to drive miners via the base controller. -- Requires: pocket with Ender (wireless) modem upgrade. -- Protocols (match your controller) local PROTOCOL = "minesys:v1" -- miner heartbeats (read-only here) local CTL_PROTO = "minesys:ctl" -- controller RPC (goto, clear, face, fwd, up, dn) -- ---- init ---- local modem = peripheral.find("modem", function(_,p) return p.isWireless() end) if not modem then error("No wireless modem on pocket") end rednet.open(peripheral.getName(modem)) pcall(function() rednet.host("minesys:pocket", "pocket_"..(os.getComputerLabel() or os.getComputerID())) end) -- ---- state ---- local function now() return os.epoch("utc") end local turtles = {} -- by label or id: {id,label,pos,fuel,freePct,status,seen} local function upsertStatus(m) local key = m.label or m.id if not key then return end local t = turtles[key] or {} t.id = m.id or t.id t.label = m.label or t.label or ("t"..tostring(m.id or "")) t.pos = m.pos or t.pos t.fuel = m.fuel or t.fuel t.status = m.status or t.status if m.extra and m.extra.inv then t.freePct = m.extra.inv.freePct end t.seen = now() turtles[key] = t end -- ---- UI helpers ---- local function listTurtles() term.clear(); term.setCursorPos(1,1) print("Turtles (label fuel free% x,y,z status):") for _,t in pairs(turtles) do local pos = t.pos and (t.pos.x..","..t.pos.y..","..t.pos.z) or "?, ?, ?" local free = t.freePct and string.format("%d", math.floor(t.freePct+0.5)) or "--" print(string.format("%-14s %-6s %-4s %s [%s]", t.label or "?", tostring(t.fuel or "?"), free, pos, t.status or "?")) end end local function help() print("list") print("fac