@thi.ng/axidraw
Version:
Minimal AxiDraw plotter/drawing machine controller for Node.js
128 lines • 4.42 kB
TypeScript
import type { IReset } from "@thi.ng/api";
import { type ReadonlyVec, type Vec, type VecPair } from "@thi.ng/vectors/api";
import { type AxiDrawOpts, type DrawCommand, type ISerial, type Metrics } from "./api.js";
export declare const DEFAULT_OPTS: AxiDrawOpts;
export declare class AxiDraw implements IReset {
serial: ISerial;
opts: AxiDrawOpts;
isConnected: boolean;
isPenDown: boolean;
penLimits: [number, number];
penState: [number, number][];
pos: Vec;
targetPos: Vec;
homePos: ReadonlyVec;
scale: number;
bounds?: VecPair;
constructor(opts?: Partial<AxiDrawOpts>);
reset(): this;
/**
* Async function. Attempts to connect to the drawing machine via given
* (partial) serial port path/name, returns true if successful.
*
* @remarks
* First matching port will be used. If `path` is a sting, a port name must
* only start with it in order to be considered a match.
*
* An error is thrown if no matching port could be found.
*
* @param path
*/
connect(path?: string | RegExp): Promise<void>;
disconnect(): void;
/**
* Async function. Converts sequence of {@link DrawCommand}s into actual EBB
* commands and sends them via configured serial port to the AxiDraw. If
* `wrap` is enabled (default), the given commands will be automatically
* wrapped with start/stop commands via {@link complete}. Returns object of
* collected {@link Metrics}. If `showMetrics` is enabled (default), the
* metrics will also be written to the configured logger.
*
* @remarks
* This function is async and if using `await` will only return once all
* commands have been processed or cancelled.
*
* The `control` implementation/ provided as part of {@link AxiDrawOpts} can
* be used to pause, resume or cancel the drawing (see
* {@link AxiDrawOpts.control} for details).
*
* Reference:
* http://evil-mad.github.io/EggBot/ebb.html
*
* Also see {@link complete}.
*
* @example
* ```ts tangle:../export/draw.ts
* import { AxiDraw, polyline, START, STOP } from "@thi.ng/axidraw";
*
* const axi = new AxiDraw();
*
* // execute start sequence, draw a triangle, then exec stop sequence
* axi.draw([
* START,
* ...polyline([[50, 50], [100, 50], [75, 100], [50, 50]]),
* STOP
* ]);
* ```
*
* @param commands
* @param wrap
* @param showMetrics
*/
draw(commands: Iterable<DrawCommand>, wrap?: boolean, showMetrics?: boolean): Promise<Metrics>;
/**
* Syntax sugar for drawing a **single** command only, otherwise same as
* {@link AxiDraw.draw}.
*
* @param cmd
*/
draw1(cmd: DrawCommand): Promise<Metrics>;
motorsOn(): void;
motorsOff(): void;
save(): void;
restore(): void;
penConfig(down?: number, up?: number): void;
penUp(delay?: number, level?: number): number;
penDown(delay?: number, level?: number): number;
/**
* Sends a "moveto" command (absolute coords). Returns tuple of `[duration,
* distance]` (distance in original/configured units)
*
* @remarks
* Even though this method accepts absolute coords, all AxiDraw movements
* are relative. Depending on pen up/down state, movement speed will be
* either the configured {@link AxiDrawOpts.speedDown} or
* {@link AxiDrawOpts.speedUp}.
*
* @param p
* @param tempo
*/
moveTo(p: ReadonlyVec, tempo?: number): number[];
/**
* Similar to {@link AxiDraw.moveTo}, but using **relative** coordinates.
*
* @param delta
* @param tempo
*/
moveRelative(delta: ReadonlyVec, tempo?: number): number[];
/**
* Syntax sugar for {@link AxiDraw.moveTo} position `[0,0]`.
*/
home(): number[];
setHome(pos: ReadonlyVec): void;
protected onSignal(): Promise<void>;
protected send(msg: string): void;
protected sendMove(tempo?: number): number[];
/**
* Sends pen up/down config
*
* @remarks
* Reference:
* https://github.com/evil-mad/AxiDraw-Processing/blob/80d81a8c897b8a1872b0555af52a8d1b5b13cec4/AxiGen1/AxiGen1.pde#L213
*
* @param id
* @param x
*/
protected sendPenConfig(id: number, x: number): void;
}
//# sourceMappingURL=axidraw.d.ts.map