Skip to content

Commit

Permalink
When cancelling, move pen to up position
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Dahan authored and alexrudd2 committed Oct 26, 2023
1 parent ee42357 commit 388e1fe
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 388e1fe

Please sign in to comment.