Skip to content

Commit 8514697

Browse files
committed
Implement G21
1 parent ac93091 commit 8514697

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/__tests__/interpreter.ts

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

183+
test('.G21 sets the units to millimeters', () => {
184+
const command = new GCodeCommand('G21', 'g21', {});
185+
const interpreter = new Interpreter();
186+
const job = new Job();
187+
188+
interpreter.G21(command, job);
189+
190+
expect(job.state.units).toEqual('mm');
191+
});
192+
183193
test('.g28 moves the state to the origin', () => {
184194
const command = new GCodeCommand('G28', 'g28', {});
185195
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
G28 = 'G28',
6667
T0 = 'T0',
6768
T1 = 'T1',
@@ -99,6 +100,8 @@ export class GCodeCommand {
99100
return Code.G3;
100101
case 'g20':
101102
return Code.G20;
103+
case 'g21':
104+
return Code.G21;
102105
case 'g28':
103106
return Code.G28;
104107
case 't0':

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
G28(command: GCodeCommand, job: Job): void {
138142
job.state.x = 0;
139143
job.state.y = 0;

0 commit comments

Comments
 (0)