live plot example and screenToPlot helper
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// Live-Maus: Jeder Klick schickt eine Zielposition. Der Plotter
|
||||
// fährt erst dorthin (moveTo wartet auf Bewegungsende). Der nächste Klick wird
|
||||
// erst danach ausgeführt.
|
||||
// waitUntilArrived: true = Klicks während der Fahrt ignorieren.
|
||||
// false = Klicks dürfen sich stapeln (send-Kette in der Library).
|
||||
|
||||
let wp;
|
||||
let live = false;
|
||||
let busy = false;
|
||||
const waitUntilArrived = true;
|
||||
|
||||
function setup() {
|
||||
const canvas = createCanvas(windowWidth, windowHeight);
|
||||
canvas.parent('sketch-host');
|
||||
|
||||
wp = new WallPlotter({
|
||||
penUpGcode: 'M280 P0 S120',
|
||||
penDownGcode: 'M280 P0 S30',
|
||||
penUpDelayMs: 250,
|
||||
penDownDelayMs: 150,
|
||||
});
|
||||
wp.setSpeed(3000, 3000);
|
||||
wp.enableKeyInputs();
|
||||
wp.enablePlotButtons();
|
||||
}
|
||||
|
||||
// Jeden Frame: Overlay zeichnen und die Maus umranden.
|
||||
function draw() {
|
||||
background(28, 28, 32);
|
||||
wp.showInfos();
|
||||
|
||||
noFill();
|
||||
stroke(live ? color(230, 50, 50) : color(220));
|
||||
strokeWeight(2);
|
||||
circle(mouseX, mouseY, 16);
|
||||
|
||||
if (live) {
|
||||
noStroke();
|
||||
fill(230, 50, 50);
|
||||
textSize(12);
|
||||
textAlign(LEFT, CENTER);
|
||||
text(busy ? 'LIVE BUSY' : 'LIVE', mouseX + 14, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
// Fenstergrösse geändert: Canvas anpassen.
|
||||
function windowResized() {
|
||||
resizeCanvas(windowWidth, windowHeight);
|
||||
}
|
||||
|
||||
// Taste L: Live-Modus ein- oder ausschalten.
|
||||
function keyPressed() {
|
||||
if (key !== 'l' && key !== 'L') return;
|
||||
live = !live;
|
||||
}
|
||||
|
||||
// Klick (nur im Live-Modus): Gondel fährt zu dieser Millimeter-Position, Stift oben.n
|
||||
async function mousePressed() {
|
||||
if (!live || !wp.connected || !wp.homeSet) return;
|
||||
if (waitUntilArrived && busy) return;
|
||||
|
||||
busy = true;
|
||||
try {
|
||||
// Maus-Pixel auf dem Overlay -> Plotter-Koordinaten
|
||||
// Die Library nutzt den aktuellen Overlay-Layout-Massstab und begrenzt
|
||||
// standardmässig auf die Maschinen-Grenzen (inkl. korrekter Y-Ausrichtung).
|
||||
const p = wp.screenToPlot(mouseX, mouseY);
|
||||
await wp.moveTo(p.x, p.y);
|
||||
|
||||
console.log('moveTo', p.x, p.y);
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Von den Plot-Buttons erwartet; hier ungenutzt (kein gepufferter Pfad).
|
||||
async function plot() {}
|
||||
|
||||
async function test() {}
|
||||
Reference in New Issue
Block a user