@@ -5,10 +5,10 @@ import { pick } from 'lodash-es'
5
5
import shlex from 'shlex'
6
6
7
7
const getArgsFromGcodeCommandArgs = ( gcodeCommandArgs : string ) => {
8
- const args : Record < string , number > = { }
8
+ const args : Record < string , number | undefined > = { }
9
9
10
- for ( const [ , key , value ] of gcodeCommandArgs . matchAll ( / ( [ a - z ] ) [ \t ] * ( - ? (?: \d + (?: \. \d + ) ? | \. \d + ) ) / gi) ) {
11
- args [ key . toLowerCase ( ) ] = + value
10
+ for ( const [ , key , value ] of gcodeCommandArgs . matchAll ( / ( [ a - z ] ) [ \t ] * ( - ? (?: \d + (?: \. \d + ) ? | \. \d + ) ) ? / gi) ) {
11
+ args [ key . toLowerCase ( ) ] = value ? + value : undefined
12
12
}
13
13
14
14
return args
@@ -131,7 +131,7 @@ const parseGcode = (gcode: string, sendProgress: (filePosition: number) => void)
131
131
case 'G1' : {
132
132
const params = [
133
133
'x' , 'y' , 'z' , 'e'
134
- ]
134
+ ] satisfies ( keyof LinearMove ) [ ]
135
135
136
136
if ( params . some ( param => param in args ) ) {
137
137
move = {
@@ -146,7 +146,7 @@ const parseGcode = (gcode: string, sendProgress: (filePosition: number) => void)
146
146
const params = [
147
147
'x' , 'y' , 'z' , 'e' ,
148
148
'i' , 'j' , 'k' , 'r'
149
- ]
149
+ ] satisfies ( keyof ArcMove ) [ ]
150
150
151
151
if ( params . some ( param => param in args ) ) {
152
152
move = {
@@ -179,6 +179,27 @@ const parseGcode = (gcode: string, sendProgress: (filePosition: number) => void)
179
179
move . z = decimalRound ( toolhead . z - fwretraction . z )
180
180
}
181
181
break
182
+ case 'G28' : {
183
+ const hasX = 'x' in args
184
+ const hasY = 'y' in args
185
+ const hasZ = 'z' in args
186
+ const noXYZ = ! hasX && ! hasY && ! hasZ
187
+
188
+ move = {
189
+ filePosition : toolhead . filePosition
190
+ } satisfies LinearMove
191
+
192
+ if ( hasX || noXYZ ) {
193
+ move . x = 0
194
+ }
195
+ if ( hasY || noXYZ ) {
196
+ move . y = 0
197
+ }
198
+ if ( hasZ || noXYZ ) {
199
+ move . z = 0
200
+ }
201
+ break
202
+ }
182
203
case 'G90' :
183
204
positioningMode = 'absolute'
184
205
case 'M82' :
0 commit comments