Skip to content

Commit a9d2fc4

Browse files
committed
Implement G21 (#218)
1 parent eeab525 commit a9d2fc4

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/__tests__/interpreter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ test('.G20 sets the units to inches', () => {
197197
expect(job.state.units).toEqual('in');
198198
});
199199

200+
test('.G21 sets the units to millimeters', () => {
201+
const command = new GCodeCommand('G21', 'g21', {});
202+
const interpreter = new Interpreter();
203+
const job = new Job();
204+
205+
interpreter.G21(command, job);
206+
207+
expect(job.state.units).toEqual('mm');
208+
});
209+
200210
test('.t0 sets the tool to 0', () => {
201211
const command = new GCodeCommand('T0', 't0', {});
202212
const interpreter = new Interpreter();

src/gcode-parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export enum Code {
6262
G2 = 'G2',
6363
G3 = 'G3',
6464
G20 = 'G20',
65+
G21 = 'G21',
6566
T0 = 'T0',
6667
T1 = 'T1',
6768
T2 = 'T2',
@@ -98,6 +99,8 @@ export class GCodeCommand {
9899
return Code.G3;
99100
case 'g20':
100101
return Code.G20;
102+
case 'g21':
103+
return Code.G21;
101104
case 't0':
102105
return Code.T0;
103106
case 't1':

src/interpreter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export class Interpreter {
134134
job.state.units = 'in';
135135
}
136136

137+
G21(command: GCodeCommand, job: Job): void {
138+
job.state.units = 'mm';
139+
}
140+
137141
T0(command: GCodeCommand, job: Job): void {
138142
job.state.tool = 0;
139143
}

0 commit comments

Comments
 (0)