Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(z-tilt): Fix z_tilt check for older Klipper versions #2102

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/components/mixins/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,24 @@ export default class ControlMixin extends Vue {
}

get toolchangeMacros(): string[] {
return Object.keys(this.$store.state.printer.gcode?.commands ?? {})
.filter((gcode) => gcode.match(/^T\d+/))
.sort((a: string, b: string) => {
const numberA = parseInt(a.slice(1))
const numberB = parseInt(b.slice(1))

return numberA - numberB
})
const sortToolchangeMacros = (a: string, b: string) => {
const numberA = parseInt(a.slice(1))
const numberB = parseInt(b.slice(1))

return numberA - numberB
}

const commands = this.$store.state.printer.gcode?.commands ?? null
if (commands) {
return Object.keys(commands)
.filter((gcode) => gcode.match(/^T\d+/))
.sort(sortToolchangeMacros)
}

return Object.keys(this.$store.state.printer)
.filter((gcode) => gcode.toLowerCase().match(/^gcode_macro t\d+/))
.map((gcode) => gcode.slice(gcode.indexOf(' ') + 1))
.sort(sortToolchangeMacros)
}

get existsClientLinearMoveMacro() {
Expand Down
14 changes: 12 additions & 2 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,19 @@ export const getters: GetterTree<PrinterState, RootState> = {
},

existsZtilt: (state) => {
if (!state.gcode) return false
// check for new Klipper gcode.commands for Z_TILT_ADJUST command
const commands = state.gcode?.commands ?? null
if (commands) {
return 'Z_TILT_ADJUST' in commands
}

return 'Z_TILT_ADJUST' in state.gcode.commands
// fallback for older Klipper versions
const settings = state.configfile?.settings ?? null
if (settings) {
return 'z_tilt' in settings
}

return false
},

existsBedTilt: (state) => {
Expand Down
Loading