import { router } from "@inertiajs/react"; import clsx from "clsx"; import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, Check, ChevronDown, ChevronsDown, ChevronsUp, ChevronUp, Home, Lock, } from "lucide-react"; import { useState, type FormEvent, type ReactNode } from "react"; import type { PageProps, PrinterState } from "@/types"; import { isBusy } from "./bed-view"; import { act, Button, Field, Instruction, inputClass } from "./ui"; type StepStatus = "done" | "current" | "locked"; function Step({ n, title, status, summary, open, onToggle, children, }: { n: number; title: string; status: StepStatus; summary?: ReactNode; open: boolean; onToggle: () => void; children: ReactNode; }) { return (
{open && status !== "locked" &&
{children}
}
); } export function SetupSteps({ props }: { props: PageProps }) { const { printer } = props; const paperMarked = Boolean(printer.paper_top_left && printer.paper_bottom_right); const done = [printer.connected, printer.xy_homed, printer.z_zeroed, paperMarked]; const current = done.indexOf(false); // -1 when everything's ready const status = (i: number): StepStatus => done[i] ? "done" : i === current ? "current" : current !== -1 && i > current ? "locked" : "current"; // Steps open on their own as you reach them; you can also reopen done ones. const [manual, setManual] = useState>({}); const isOpen = (i: number) => manual[i] ?? i === current; const toggle = (i: number) => setManual((m) => ({ ...m, [i]: !isOpen(i) })); return (
toggle(0)} summary={printer.connected ? `Connected to ${props.connection.ip}` : undefined} > toggle(1)} summary="The printer knows where the pen is" > {printer.saved_calibration && (

Picking up where you left off? If the printer has stayed on and nobody has moved the head or released the motors, you can keep the previous position {printer.saved_calibration.z_zeroed && " and pen height"}.

)} Pen: leave it out for now. Clear the bed, then press Home. The head lifts 10 mm, finds its corner and comes back to the middle of the bed, so from now on the app knows exactly where it is.
toggle(2)} summary={`Pen lifts ${printer.pen_up} mm between lines`} >
  1. Tape your paper to the bed. Its top edge should face the back of the printer.
  2. Move the pen over the paper: click on the paper in the bed picture.
  3. Now put the pen in the holder, with its tip a few millimetres above the paper.
  4. Lower the head until the tip just touches the paper. Go slowly at the end.

This becomes the paper height. The pen then lifts {printer.pen_up} mm, and will only come down to draw.

toggle(3)} summary={paperMarked ? paperSummary(printer) : undefined} >
); } function paperSummary(p: PrinterState) { const w = Math.abs(p.paper_bottom_right!.x - p.paper_top_left!.x); const h = Math.abs(p.paper_bottom_right!.y - p.paper_top_left!.y); return `${w.toFixed(0)} × ${h.toFixed(0)} mm`; } function ConnectForm({ props }: { props: PageProps }) { const { printer, connection } = props; const [form, setForm] = useState({ ip: connection.ip, serial: connection.serial, access_code: "", model: printer.bed.model, }); const [submitting, setSubmitting] = useState(false); function submit(e: FormEvent) { e.preventDefault(); setSubmitting(true); router.post("/connect", form, { preserveScroll: true, preserveState: true, onFinish: () => setSubmitting(false), }); } if (printer.connected) { return (
Connected to {connection.ip}
); } return (
On the printer, turn on LAN Only mode and Developer mode (Settings → Network). The IP address and access code are shown on the same screen.
setForm({ ...form, ip: e.target.value })} placeholder="192.168.1.50" required />
setForm({ ...form, serial: e.target.value })} required /> setForm({ ...form, access_code: e.target.value })} placeholder={connection.has_access_code ? "••••••••" : ""} required={!connection.has_access_code} />
); } function ZJog({ printer }: { printer: PrinterState }) { const disabled = !printer.connected || isBusy(printer); const z = (d: number) => act("/jog", { axis: "z", distance: d }); return (
Lower the pen
Raise the pen
); } export function XYJog({ printer }: { printer: PrinterState }) { const [step, setStep] = useState(10); const disabled = !printer.connected || !printer.xy_homed || isBusy(printer); const jog = (axis: "x" | "y", sign: number) => act("/jog", { axis, distance: sign * step }); return (
{step}mm
Step
{[0.5, 1, 10, 50].map((s) => ( ))}
); } function MarkPaper({ props }: { props: PageProps }) { const { printer } = props; const tl = printer.paper_top_left; const br = printer.paper_bottom_right; const busy = isBusy(printer); const goTo = (p: { x: number; y: number }) => act("/move", p); return (
The pen stays lifted. Move it so the tip is right above a corner of the paper, using the arrows or by clicking the bed picture, then save that corner.
act("/paper/corner", { corner: "top_left" })} onGo={goTo} disabled={busy} /> act("/paper/corner", { corner: "bottom_right" })} onGo={goTo} disabled={busy || !tl} />
{tl && (
…or skip the bottom-right corner and pick the paper size
{Object.entries(props.paper_sizes).map(([name, [w, h]]) => ( ))}
)} {tl && br && ( )}
); } function CornerButton({ label, point, onSet, onGo, disabled, }: { label: string; point: { x: number; y: number } | null; onSet: () => void; onGo: (p: { x: number; y: number }) => void; disabled: boolean; }) { return (
{label} {point && }
{point ? `${point.x.toFixed(1)}, ${point.y.toFixed(1)}` : "not set"}
{point && ( )}
); }