Skip to content

Commit

Permalink
fix(gcodepreview): retraction values
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas committed Apr 17, 2024
1 parent d2d3724 commit 2970a11
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/workers/parseGcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const parseLine = (line: string) => {
}

const [, macroCommand, macroCommandArgs = ''] = clearedLine
.split(/^(SET_PRINT_STATS_INFO|EXCLUDE_OBJECT_DEFINE)\s+/i)
.split(/^(SET_PRINT_STATS_INFO|EXCLUDE_OBJECT_DEFINE|SET_RETRACTION)\s+/i)

if (macroCommand) {
return {
Expand Down Expand Up @@ -116,31 +116,41 @@ const parseGcode = (gcode: string, sendProgress: (filePosition: number) => void)
parts.push(Object.freeze(part))
}
break
case 'SET_RETRACTION':
if ('retract_length' in args) {
fwretraction.length = +args.retract_length
}
if ('unretract_extra_length' in args) {
fwretraction.extrudeExtra = +args.unretract_extra_length
}
break
}
} else if (type === 'gcode') {
switch (command) {
case 'G0':
case 'G1': {
const values = pick(args, [
const params = [
'x', 'y', 'z', 'e'
])
if (Object.keys(values).length) {
]

if (params.some(param => param in args)) {
move = {
...values,
...pick(args, params),
filePosition: toolhead.filePosition
} satisfies LinearMove
}
break
}
case 'G2':
case 'G3': {
const values = pick(args, [
const params = [
'x', 'y', 'z', 'e',
'i', 'j', 'k', 'r'
])
if (Object.keys(values).length) {
]

if (params.some(param => param in args)) {
move = {
...values,
...pick(args, params),
direction: command === 'G2'
? 'clockwise'
: 'counter-clockwise',
Expand All @@ -152,7 +162,7 @@ const parseGcode = (gcode: string, sendProgress: (filePosition: number) => void)
case 'G10':
move = {
e: -fwretraction.length,
filePosition: 0
filePosition: toolhead.filePosition
} satisfies LinearMove

if (fwretraction.z !== 0) {
Expand Down Expand Up @@ -193,7 +203,6 @@ const parseGcode = (gcode: string, sendProgress: (filePosition: number) => void)
break
case 'M207':
fwretraction.length = args.s ?? fwretraction.length
fwretraction.extrudeExtra = args.s ?? fwretraction.extrudeExtra
fwretraction.z = args.z ?? fwretraction.z
break
}
Expand Down

0 comments on commit 2970a11

Please sign in to comment.