-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe.ts
More file actions
112 lines (99 loc) · 2.57 KB
/
pipe.ts
File metadata and controls
112 lines (99 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { GCode, GCommand } from './gcode';
/**
* Abstract Pipe class.
* Provides basic functionality to allow for connecting pipes sequentially.
*
* @export
* @abstract
* @class Pipe
*/
export abstract class Pipe {
/**
* Set of commands supported by this pipe
*
* @private
* @type {Set<GCommand>}
*/
private _SUPPORTED_COMMANDS: Set<GCommand> = new Set();
/**
* List of commands supported by this pipe
*
* @public
* @readonly
* @type {GCommand[]}
*/
public get SUPPORTED_COMMANDS(): GCommand[] {
return Array.from(this._SUPPORTED_COMMANDS);
}
/**
* Adds provided commands to this pipe's supported commands.
* Child classes should call this function from their constructor
*
* @protected
* @param {GCommand[]} commands
*/
protected addSupportedGcodes(commands: GCommand[]) {
commands.forEach((gcode) => this._SUPPORTED_COMMANDS.add(gcode));
}
/**
* Next pipe
*
* @type {?Pipe}
*/
nextPipe?: Pipe;
/**
* This hook is called prior the pipe destroy
*/
protected onCooldown(): void {}
/**
* This hook is called before the first input
*/
protected onWarmup(): void {}
/**
* This function must be called before the first input.
* Recursively calls `warmup` of all connected pipes
*/
public warmup(): void {
this.onWarmup();
if (this.nextPipe) this.nextPipe.warmup();
}
/**
* This function must be called prior pipe destroy.
* Recursively calls `cooldown` of all connected pipes
*/
public cooldown(): void {
this.onCooldown();
if (this.nextPipe) this.nextPipe.cooldown();
}
/**
* Should be overridden by child class to process incoming data
*
* @public
* @abstract
* @param {GCode} gcode
*/
public abstract input(gcode: GCode): void;
/**
* Can be called by child class to check whether the given gcode command in supported
*
* @param gcode gcode to test against
* @param supportedCommands optionally can specify list of commands to test with. Defaults to pipe's supported commands
* @returns {boolean} whether the given gcode command is the supported one
*/
protected supportsCommand(
gcode: GCode,
supportedCommands: GCommand[] = this.SUPPORTED_COMMANDS
): boolean {
return supportedCommands.includes(gcode.command as GCommand);
}
/**
* Child class can call this function to forward processed data to the next pipe
*
* @protected
* @param {GCode} gcode data to forward
*/
protected output(gcode: GCode): void {
if (!this.nextPipe) return;
this.nextPipe.input(gcode);
}
}