Skip to content

Commit 941c35d

Browse files
committed
feat: adds _CLIENT_LINEAR_MOVE macro support
Signed-off-by: Pedro Lamas <[email protected]>
1 parent c27822d commit 941c35d

File tree

6 files changed

+52
-10
lines changed

6 files changed

+52
-10
lines changed

src/components/widgets/toolhead/ToolheadControlBarsAxis.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ export default class ToolheadControlBarsAxis extends Mixins(StateMixin, Toolhead
7878
}
7979
8080
moveBy (distance: number) {
81-
this.sendMoveGcode(`${this.axis}${distance}`, this.rate)
81+
this.sendMoveGcode(
82+
{
83+
[this.axis]: distance
84+
},
85+
this.rate)
8286
}
8387
8488
home () {

src/components/widgets/toolhead/ToolheadControlCircle.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,11 @@ export default class ToolheadControlCircle extends Mixins(StateMixin, ToolheadMi
735735
: this.$store.state.printer.printer.toolhead.max_accel
736736
this.sendGcode(`FORCE_MOVE STEPPER=stepper_${axis.toLowerCase()} DISTANCE=${distance} VELOCITY=${rate} ACCEL=${accel}`)
737737
} else {
738-
this.sendMoveGcode(`${axis}${distance}`, rate)
738+
this.sendMoveGcode(
739+
{
740+
[axis]: distance
741+
},
742+
rate)
739743
}
740744
}
741745
@@ -763,7 +767,13 @@ export default class ToolheadControlCircle extends Mixins(StateMixin, ToolheadMi
763767
const bedCenter = this.bedCenter
764768
const rate: number = this.$store.state.config.uiSettings.general.defaultToolheadXYSpeed
765769
766-
this.sendMoveGcode(`X${bedCenter.x} Y${bedCenter.y}`, rate, true)
770+
this.sendMoveGcode(
771+
{
772+
X: bedCenter.x,
773+
Y: bedCenter.y
774+
},
775+
rate,
776+
true)
767777
}
768778
}
769779
</script>

src/components/widgets/toolhead/ToolheadControlCross.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ export default class ToolheadControlCross extends Mixins(StateMixin, ToolheadMix
258258
: this.$store.state.printer.printer.toolhead.max_accel
259259
this.sendGcode(`FORCE_MOVE STEPPER=stepper_${axis.toLowerCase()} DISTANCE=${distance} VELOCITY=${rate} ACCEL=${accel}`)
260260
} else {
261-
this.sendMoveGcode(`${axis}${distance}`, rate)
261+
this.sendMoveGcode(
262+
{
263+
[axis]: distance
264+
},
265+
rate)
262266
}
263267
}
264268
}

src/components/widgets/toolhead/ToolheadPosition.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ export default class ToolheadPosition extends Mixins(StateMixin, ToolheadMixin)
196196
: this.$store.state.printer.printer.toolhead.max_accel
197197
this.sendGcode(`FORCE_MOVE STEPPER=stepper_${axis.toLowerCase()} DISTANCE=${pos} VELOCITY=${rate} ACCEL=${accel}`)
198198
} else {
199-
this.sendMoveGcode(`${axis}${pos}`, rate, true)
199+
this.sendMoveGcode(
200+
{
201+
[axis]: pos
202+
},
203+
rate,
204+
true)
200205
}
201206
}
202207
}

src/mixins/state.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue'
22
import { SocketActions } from '@/api/socketActions'
33
import { Component } from 'vue-property-decorator'
4+
import type { Macro } from '@/store/macros/types'
45

56
@Component
67
export default class StateMixin extends Vue {
@@ -103,8 +104,19 @@ export default class StateMixin extends Vue {
103104
this.addConsoleEntry(gcode)
104105
}
105106

106-
sendMoveGcode (movementGcode: string, rate: number, absolute = false, wait?: string) {
107-
const gcode = `SAVE_GCODE_STATE NAME=_ui_movement
107+
sendMoveGcode (movement: { X?: number, Y?: number, Z?: number }, rate: number, absolute = false, wait?: string) {
108+
const macro = this.$store.getters['macros/getMacroByName']('_client_linear_move') as Macro | undefined
109+
110+
const paramSeparator = macro
111+
? '='
112+
: ''
113+
const movementGcode = Object.entries(movement)
114+
.map(([key, value]) => `${key}${paramSeparator}${value}`)
115+
.join(' ')
116+
117+
const gcode = macro
118+
? `${macro.name.toUpperCase()} ${movementGcode} F=${rate * 60}${absolute ? ' ABSOLUTE=1' : ''}`
119+
: `SAVE_GCODE_STATE NAME=_ui_movement
108120
G9${absolute ? 0 : 1}
109121
G1 ${movementGcode} F${rate * 60}
110122
RESTORE_GCODE_STATE NAME=_ui_movement`
@@ -113,7 +125,11 @@ RESTORE_GCODE_STATE NAME=_ui_movement`
113125
}
114126

115127
sendExtrudeGcode (amount: number, rate: number, wait?: string) {
116-
const gcode = `SAVE_GCODE_STATE NAME=_ui_retract
128+
const macro = this.$store.getters['macros/getMacroByName']('_client_linear_move') as Macro | undefined
129+
130+
const gcode = macro
131+
? `${macro.name.toUpperCase()} E=${amount} F=${rate * 60}`
132+
: `SAVE_GCODE_STATE NAME=_ui_retract
117133
M83
118134
G1 E${amount} F${rate * 60}
119135
RESTORE_GCODE_STATE NAME=_ui_retract`

src/store/macros/getters.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const getters: GetterTree<MacrosState, RootState> = {
1919
*/
2020
getMacros: (state, getters, rootState) => {
2121
const macros = Object.keys(rootState.printer.printer)
22-
.filter(key => /^gcode_macro (?!_)/.test(key))
22+
.filter(key => key.startsWith('gcode_macro '))
2323
.map(key => {
2424
const lowerCaseKey = key.toLocaleLowerCase()
2525
const name = lowerCaseKey.split(' ', 2)[1]
@@ -97,7 +97,10 @@ export const getters: GetterTree<MacrosState, RootState> = {
9797
const macros = getters.getMacros as Macro[]
9898

9999
return macros
100-
.filter(macro => macro.categoryId === id)
100+
.filter(macro => (
101+
!macro.name.startsWith('_') &&
102+
macro.categoryId === id
103+
))
101104
.sort((a: Macro, b: Macro) => {
102105
// Sorts preferrentially by order, then by name
103106
// This offers backward compatibility with macros that have no order

0 commit comments

Comments
 (0)