Skip to content

Commit aff1f50

Browse files
committed
feat(GcodePreview): adds G28 support
Signed-off-by: Pedro Lamas <[email protected]>
1 parent 834d633 commit aff1f50

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/workers/parseGcode.ts

+26-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { pick } from 'lodash-es'
55
import shlex from 'shlex'
66

77
const getArgsFromGcodeCommandArgs = (gcodeCommandArgs: string) => {
8-
const args: Record<string, number> = {}
8+
const args: Record<string, number | undefined> = {}
99

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
1212
}
1313

1414
return args
@@ -131,7 +131,7 @@ const parseGcode = (gcode: string, sendProgress: (filePosition: number) => void)
131131
case 'G1': {
132132
const params = [
133133
'x', 'y', 'z', 'e'
134-
]
134+
] satisfies (keyof LinearMove)[]
135135

136136
if (params.some(param => param in args)) {
137137
move = {
@@ -146,7 +146,7 @@ const parseGcode = (gcode: string, sendProgress: (filePosition: number) => void)
146146
const params = [
147147
'x', 'y', 'z', 'e',
148148
'i', 'j', 'k', 'r'
149-
]
149+
] satisfies (keyof ArcMove)[]
150150

151151
if (params.some(param => param in args)) {
152152
move = {
@@ -179,6 +179,27 @@ const parseGcode = (gcode: string, sendProgress: (filePosition: number) => void)
179179
move.z = decimalRound(toolhead.z - fwretraction.z)
180180
}
181181
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+
}
182203
case 'G90':
183204
positioningMode = 'absolute'
184205
case 'M82':

0 commit comments

Comments
 (0)