Skip to content

Commit

Permalink
feat(axidraw): add command fns, add COMMENT cmd
Browse files Browse the repository at this point in the history
- add MOVE(), WAIT(), COMMENT()
- add CommentCommand
- update AxiDraw.draw() to log comments
  • Loading branch information
postspectacular committed Mar 17, 2023
1 parent 2c17115 commit 0d64b55
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 31 additions & 1 deletion packages/axidraw/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export type MoveXYCommand = ["m", ReadonlyVec, number?];
/** Explicit delay (in ms) */
export type WaitCommand = ["w", number];

/** Ignored, but will be logged (if logging enabled) */
export type CommentCommand = ["comment", string];

export type DrawCommand =
| StartCommand
| StopCommand
Expand All @@ -45,7 +48,8 @@ export type DrawCommand =
| PenConfigCommand
| PenUpDownCommand
| MoveXYCommand
| WaitCommand;
| WaitCommand
| CommentCommand;

/**
* Global plotter drawing configuration. Also see {@link DEFAULT_OPTS}.
Expand Down Expand Up @@ -176,6 +180,32 @@ export const ON: MotorCommand = ["on"];

export const OFF: MotorCommand = ["off"];

/**
* Creates a {@link MoveXYCommand} command.
*
* @param pos
* @param speed
*/
export const MOVE = (pos: ReadonlyVec, speed = 1): MoveXYCommand => [
"m",
pos,
speed,
];

/**
* Creates a {@link WaitCommand}.
*
* @param delay
*/
export const WAIT = (delay = 1000): WaitCommand => ["w", delay];

/**
* Creates a {@link CommentCommand}.
*
* @param msg
*/
export const COMMENT = (msg = ""): CommentCommand => ["comment", msg];

/**
* FSM state enum for (interactive) control for processing of drawing commands.
* See {@link AxiDraw.draw} and {@link AxiDrawControl} for details.
Expand Down
3 changes: 3 additions & 0 deletions packages/axidraw/src/axidraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ export class AxiDraw implements IReset {
[wait, dist] = this.moveTo(a, b);
$recordDist(dist);
break;
case "comment":
logger.info(`comment: ${a}`);
break;
default:
unsupported(`unknown command: ${$cmd}`);
}
Expand Down

0 comments on commit 0d64b55

Please sign in to comment.