From 388e1fe08ea7aaa1868235a78d1e6767d63d29ef Mon Sep 17 00:00:00 2001 From: Jonathan Dahan Date: Wed, 11 Oct 2023 19:10:51 -0400 Subject: [PATCH] When cancelling, move pen to up position --- src/ui.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ui.tsx b/src/ui.tsx index bc033f8..8f0dbab 100644 --- a/src/ui.tsx +++ b/src/ui.tsx @@ -179,7 +179,12 @@ class WebSerialDriver implements Driver { if (this._cancelRequested) { const device = Device(this.ebb.hardware); - await this.ebb.setPenHeight(device.penPctToPos(0), 1000); + if (!penIsUp) { + // Move to the pen up position, or 50% if no position was found + const penMotion = plan.motions.find((motion): motion is PenMotion => motion instanceof PenMotion) + const penUpPosition = penMotion ? Math.max(penMotion.initialPos, penMotion.finalPos) : device.penPctToPos(50) + await this.ebb.setPenHeight(penUpPosition, 1000); + } if (this.oncancelled) this.oncancelled() } else { if (this.onfinished) this.onfinished()