Skip to content

Commit

Permalink
feat: use _CLIENT_LINEAR_MOVE macros instead of multi-line gcodes (#2043
Browse files Browse the repository at this point in the history
)

* feat: use _CLIENT_MOVE macros instead of multi-line gcodes

Signed-off-by: Stefan Dej <[email protected]>

* refactor: change from 2 macros to 1 macro (_CLIENT_LINEAR_MOVE)

Signed-off-by: Stefan Dej <[email protected]>

---------

Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou authored Dec 3, 2024
1 parent 6011887 commit 1c722c4
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 28 deletions.
24 changes: 22 additions & 2 deletions src/components/mixins/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ export default class ControlMixin extends Vue {
})
}

get existsClientLinearMoveMacro() {
const macros = this.$store.state.printer?.gcode?.commands ?? {}

return '_CLIENT_LINEAR_MOVE' in macros
}

doHome() {
this.$store.dispatch('server/addEvent', { message: 'G28', type: 'command' })
this.$socket.emit('printer.gcode.script', { script: 'G28' }, { loading: 'homeAll' })
Expand Down Expand Up @@ -148,13 +154,27 @@ export default class ControlMixin extends Vue {
}

doSendMove(gcode: string, feedrate: number) {
gcode =
let command =
`SAVE_GCODE_STATE NAME=_ui_movement\n` +
`G91\n` +
`G1 ${gcode} F${feedrate * 60}\n` +
`RESTORE_GCODE_STATE NAME=_ui_movement`

this.doSend(gcode)
if (this.existsClientLinearMoveMacro) {
gcode = gcode
.split(' ')
.map((part) => {
const axis = part.slice(0, 1)
const value = parseFloat(part.slice(1))

return `${axis}=${value}`
})
.join(' ')

command = `_CLIENT_LINEAR_MOVE ${gcode} F=${feedrate * 60}`
}

this.doSend(command)
}

doSend(gcode: string) {
Expand Down
12 changes: 11 additions & 1 deletion src/components/panels/Extruder/ExtruderControlPanelControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ export default class ExtruderControlPanel extends Mixins(BaseMixin, ExtruderMixi
return this.feedamount * this.extrudeFactor > this.maxExtrudeOnlyDistance
}
get existsClientLinearMoveMacro() {
const macros = this.$store.state.printer?.gcode?.commands ?? {}
return '_CLIENT_LINEAR_MOVE' in macros
}
@Watch('maxExtrudeOnlyDistance', { immediate: true })
onMaxExtrudeOnlyDistanceChange(): void {
/**
Expand All @@ -271,12 +277,16 @@ export default class ExtruderControlPanel extends Mixins(BaseMixin, ExtruderMixi
}
sendCommand(length: number, loading: string): void {
const gcode =
let gcode =
`SAVE_GCODE_STATE NAME=_ui_extrude\n` +
`M83\n` +
`G1 E${length} F${this.feedrate * 60}\n` +
`RESTORE_GCODE_STATE NAME=_ui_extrude`
if (this.existsClientLinearMoveMacro) {
gcode = `_CLIENT_LINEAR_MOVE E=${length} F=${this.feedrate * 60}`
}
this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' })
this.$socket.emit('printer.gcode.script', { script: gcode }, { loading })
}
Expand Down
64 changes: 39 additions & 25 deletions src/components/panels/ToolheadControls/MoveToControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
'col-3': el.is.large,
}"
class="v-subheader text--secondary mr-2">
<v-icon small class="mr-1">
{{ mdiCrosshairsGps }}
</v-icon>
<v-icon small class="mr-1">{{ mdiCrosshairsGps }}</v-icon>
<span v-if="!el.is.xsmall" class="text-no-wrap">
{{ $t('Panels.ToolheadControlPanel.Position') }}:&nbsp;
</span>
Expand All @@ -27,12 +25,8 @@
<v-col
v-if="currentProfileName"
class="v-subheader text--secondary pl-2 justify-end text-no-wrap text-truncate">
<v-icon small class="mr-1">
{{ mdiGrid }}
</v-icon>
<span class="text-no-wrap text-truncate">
{{ currentProfileName }}
</span>
<v-icon small class="mr-1">{{ mdiGrid }}</v-icon>
<span class="text-no-wrap text-truncate">{{ currentProfileName }}</span>
</v-col>
</v-row>
<v-row v-if="showCoordinates" dense>
Expand All @@ -45,7 +39,7 @@
:current-pos="gcodePositions.x"
:readonly="['printing'].includes(printer_state)"
:disabled="!xAxisHomed"
@submit="sendCmd"></move-to-input>
@submit="sendCmd" />
</v-col>
<v-col :class="el.is.xsmall ? 'col-12' : 'col-4'">
<move-to-input
Expand All @@ -56,7 +50,7 @@
:current-pos="gcodePositions.y"
:readonly="['printing'].includes(printer_state)"
:disabled="!yAxisHomed"
@submit="sendCmd"></move-to-input>
@submit="sendCmd" />
</v-col>
<v-col :class="el.is.xsmall ? 'col-12' : 'col-4'">
<move-to-input
Expand All @@ -67,7 +61,7 @@
:current-pos="gcodePositions.z"
:readonly="['printing'].includes(printer_state)"
:disabled="!zAxisHomed"
@submit="sendCmd"></move-to-input>
@submit="sendCmd" />
</v-col>
</v-row>
</template>
Expand Down Expand Up @@ -170,24 +164,44 @@ export default class MoveToControl extends Mixins(BaseMixin, ControlMixin) {
}
sendCmd(): void {
const xPos = this.input.x.pos !== this.gcodePositions.x ? ` X${this.input.x.pos}` : ''
const yPos = this.input.y.pos !== this.gcodePositions.y ? ` Y${this.input.y.pos}` : ''
const zPos = this.input.z.pos !== this.gcodePositions.z ? ` Z${this.input.z.pos}` : ''
let gcode: string[] = []
if (!this.existsClientLinearMoveMacro) {
gcode.push('SAVE_GCODE_STATE NAME=_ui_movement')
gcode.push('G90')
}
let gcode = ''
if (!this.positionAbsolute) {
gcode += 'G90\n'
if (this.input.z.pos !== this.gcodePositions.z) {
if (this.existsClientLinearMoveMacro)
gcode.push(`_CLIENT_LINEAR_MOVE Z=${this.input.z.pos} F=${this.feedrateZ * 60} ABSOLUTE=1`)
else gcode.push(`G1 Z${this.input.z.pos} F${this.feedrateZ * 60}`)
}
if (zPos !== '') {
gcode += `G1${zPos} F${this.feedrateZ * 60}\n`
if (this.input.x.pos !== this.gcodePositions.x || this.input.y.pos !== this.gcodePositions.y) {
let xPos = ''
let yPos = ''
if (this.existsClientLinearMoveMacro) {
if (this.input.x.pos !== this.gcodePositions.x) xPos = ` X=${this.input.x.pos}`
if (this.input.y.pos !== this.gcodePositions.y) yPos = ` Y=${this.input.y.pos}`
gcode.push(`_CLIENT_LINEAR_MOVE${xPos}${yPos} F=${this.feedrateXY * 60} ABSOLUTE=1`)
} else {
if (this.input.x.pos !== this.gcodePositions.x) xPos = ` X${this.input.x.pos}`
if (this.input.y.pos !== this.gcodePositions.y) yPos = ` Y${this.input.y.pos}`
gcode.push(`G1${xPos}${yPos} F${this.feedrateXY * 60}`)
}
}
if (xPos !== '' || yPos !== '') {
gcode += `G1${xPos}${yPos} F${this.feedrateXY * 60}`
if (!this.existsClientLinearMoveMacro) {
gcode.push('RESTORE_GCODE_STATE NAME=_ui_movement')
}
if (gcode !== '' && this.input.x.valid && this.input.y.valid && this.input.z.valid) {
this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' })
this.$socket.emit('printer.gcode.script', { script: gcode })
const gcodeStr = gcode.join('\n')
if (this.input.x.valid && this.input.y.valid && this.input.z.valid) {
this.$store.dispatch('server/addEvent', { message: gcodeStr, type: 'command' })
this.$socket.emit('printer.gcode.script', { script: gcodeStr })
}
return
Expand Down

0 comments on commit 1c722c4

Please sign in to comment.