Skip to content

Commit

Permalink
feat: adds _CLIENT_LINEAR_MOVE macro support (#1530)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas authored Nov 24, 2024
1 parent 1c4f673 commit be9b053
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/components/widgets/toolhead/ToolheadControlBarsAxis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export default class ToolheadControlBarsAxis extends Mixins(StateMixin, Toolhead
}
moveBy (distance: number) {
this.sendMoveGcode(`${this.axis}${distance}`, this.rate)
this.sendMoveGcode(
{
[this.axis]: distance
},
this.rate)
}
home () {
Expand Down
14 changes: 12 additions & 2 deletions src/components/widgets/toolhead/ToolheadControlCircle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,11 @@ export default class ToolheadControlCircle extends Mixins(StateMixin, ToolheadMi
: this.$store.state.printer.printer.toolhead.max_accel
this.sendGcode(`FORCE_MOVE STEPPER=stepper_${axis.toLowerCase()} DISTANCE=${distance} VELOCITY=${rate} ACCEL=${accel}`)
} else {
this.sendMoveGcode(`${axis}${distance}`, rate)
this.sendMoveGcode(
{
[axis]: distance
},
rate)
}
}
Expand Down Expand Up @@ -763,7 +767,13 @@ export default class ToolheadControlCircle extends Mixins(StateMixin, ToolheadMi
const bedCenter = this.bedCenter
const rate: number = this.$store.state.config.uiSettings.general.defaultToolheadXYSpeed
this.sendMoveGcode(`X${bedCenter.x} Y${bedCenter.y}`, rate, true)
this.sendMoveGcode(
{
X: bedCenter.x,
Y: bedCenter.y
},
rate,
true)
}
}
</script>
Expand Down
6 changes: 5 additions & 1 deletion src/components/widgets/toolhead/ToolheadControlCross.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ export default class ToolheadControlCross extends Mixins(StateMixin, ToolheadMix
: this.$store.state.printer.printer.toolhead.max_accel
this.sendGcode(`FORCE_MOVE STEPPER=stepper_${axis.toLowerCase()} DISTANCE=${distance} VELOCITY=${rate} ACCEL=${accel}`)
} else {
this.sendMoveGcode(`${axis}${distance}`, rate)
this.sendMoveGcode(
{
[axis]: distance
},
rate)
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/widgets/toolhead/ToolheadPosition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ export default class ToolheadPosition extends Mixins(StateMixin, ToolheadMixin)
: this.$store.state.printer.printer.toolhead.max_accel
this.sendGcode(`FORCE_MOVE STEPPER=stepper_${axis.toLowerCase()} DISTANCE=${pos} VELOCITY=${rate} ACCEL=${accel}`)
} else {
this.sendMoveGcode(`${axis}${pos}`, rate, true)
this.sendMoveGcode(
{
[axis]: pos
},
rate,
true)
}
}
}
Expand Down
22 changes: 19 additions & 3 deletions src/mixins/state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue'
import { SocketActions } from '@/api/socketActions'
import { Component } from 'vue-property-decorator'
import type { Macro } from '@/store/macros/types'

@Component
export default class StateMixin extends Vue {
Expand Down Expand Up @@ -103,8 +104,19 @@ export default class StateMixin extends Vue {
this.addConsoleEntry(gcode)
}

sendMoveGcode (movementGcode: string, rate: number, absolute = false, wait?: string) {
const gcode = `SAVE_GCODE_STATE NAME=_ui_movement
sendMoveGcode (movement: { X?: number, Y?: number, Z?: number }, rate: number, absolute = false, wait?: string) {
const macro = this.$store.getters['macros/getMacroByName']('_client_linear_move') as Macro | undefined

const paramSeparator = macro
? '='
: ''
const movementGcode = Object.entries(movement)
.map(([key, value]) => `${key}${paramSeparator}${value}`)
.join(' ')

const gcode = macro
? `${macro.name.toUpperCase()} ${movementGcode} F=${rate * 60}${absolute ? ' ABSOLUTE=1' : ''}`
: `SAVE_GCODE_STATE NAME=_ui_movement
G9${absolute ? 0 : 1}
G1 ${movementGcode} F${rate * 60}
RESTORE_GCODE_STATE NAME=_ui_movement`
Expand All @@ -113,7 +125,11 @@ RESTORE_GCODE_STATE NAME=_ui_movement`
}

sendExtrudeGcode (amount: number, rate: number, wait?: string) {
const gcode = `SAVE_GCODE_STATE NAME=_ui_retract
const macro = this.$store.getters['macros/getMacroByName']('_client_linear_move') as Macro | undefined

const gcode = macro
? `${macro.name.toUpperCase()} E=${amount} F=${rate * 60}`
: `SAVE_GCODE_STATE NAME=_ui_retract
M83
G1 E${amount} F${rate * 60}
RESTORE_GCODE_STATE NAME=_ui_retract`
Expand Down
7 changes: 5 additions & 2 deletions src/store/macros/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getters: GetterTree<MacrosState, RootState> = {
*/
getMacros: (state, getters, rootState) => {
const macros = Object.keys(rootState.printer.printer)
.filter(key => /^gcode_macro (?!_)/.test(key))
.filter(key => key.startsWith('gcode_macro '))
.map(key => {
const lowerCaseKey = key.toLocaleLowerCase()
const name = lowerCaseKey.split(' ', 2)[1]
Expand Down Expand Up @@ -97,7 +97,10 @@ export const getters: GetterTree<MacrosState, RootState> = {
const macros = getters.getMacros as Macro[]

return macros
.filter(macro => macro.categoryId === id)
.filter(macro => (
!macro.name.startsWith('_') &&
macro.categoryId === id
))
.sort((a: Macro, b: Macro) => {
// Sorts preferrentially by order, then by name
// This offers backward compatibility with macros that have no order
Expand Down

0 comments on commit be9b053

Please sign in to comment.