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

feat: add option to change the save z-offset method #1631

Merged
Merged
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
69 changes: 69 additions & 0 deletions src/components/mixins/zoffset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import Vue from 'vue'
import Component from 'vue-class-component'
import { CommandHelp } from '@/store/printer/types'

@Component
export default class ZoffsetMixin extends Vue {
get homing_origin() {
return this.$store.state.printer?.gcode_move?.homing_origin ?? []
}

get z_gcode_offset() {
return this.homing_origin.length > 1 ? Math.round(this.homing_origin[2] * 1000) / 1000 : 0
}
get helplist() {
return this.$store.state.printer.helplist ?? []
}

get settings() {
return this.$store.state.printer.configfile?.settings ?? {}
}

get kinematics() {
return this.settings.printer?.kinematics ?? 'cartesian'
}

get stepper_name() {
if (this.kinematics === 'delta') return 'stepper_a'

return 'stepper_z'
}

get endstop_pin() {
const stepperConfig = this.settings[this.stepper_name] ?? {}

return stepperConfig?.endstop_pin
}

get zOffset(): number {
return this.$store.state.printer?.gcode_move?.homing_origin[2].toFixed(3)
}
get isEndstopProbe() {
return this.endstop_pin.search('probe:z_virtual_endstop') !== -1
}

get existZOffsetApplyProbe() {
return this.helplist.findIndex((gcode: CommandHelp) => gcode.commandLow === 'z_offset_apply_probe') !== -1
}

get existZOffsetApplyEndstop() {
return this.helplist.findIndex((gcode: CommandHelp) => gcode.commandLow === 'z_offset_apply_endstop') !== -1
}

get showSaveButton() {
// hide button when offset is 0
if (this.z_gcode_offset === 0) return false

// show button when z endstop is probe and probe gcode exists
if (this.isEndstopProbe && this.existZOffsetApplyProbe) return true

// show button when z endstop is endstop and endstop gcode exists
return !this.isEndstopProbe && this.existZOffsetApplyEndstop
}

get autoSaveZOffsetOption() {
if (this.isEndstopProbe && this.existZOffsetApplyProbe) return 'Z_OFFSET_APPLY_PROBE'

return 'Z_OFFSET_APPLY_ENDSTOP'
}
}
81 changes: 6 additions & 75 deletions src/components/panels/ToolheadControls/ZoffsetControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@

<script lang="ts">
import { Component, Mixins } from 'vue-property-decorator'
import { CommandHelp } from '@/store/printer/types'
import BaseMixin from '@/components/mixins/base'
import Panel from '@/components/ui/Panel.vue'
import Responsive from '@/components/ui/Responsive.vue'
Expand All @@ -137,10 +136,11 @@ import {
mdiArrowExpandUp,
mdiLayersOutline,
} from '@mdi/js'
import ZoffsetMixin from '@/components/mixins/zoffset'
@Component({
components: { Panel, Responsive },
})
export default class ZoffsetControl extends Mixins(BaseMixin) {
export default class ZoffsetControl extends Mixins(BaseMixin, ZoffsetMixin) {
mdiBroom = mdiBroom
mdiContentSave = mdiContentSave
mdiArrowCollapseDown = mdiArrowCollapseDown
Expand All @@ -150,14 +150,6 @@ export default class ZoffsetControl extends Mixins(BaseMixin) {

saveOffsetDialog = false

get homing_origin() {
return this.$store.state.printer?.gcode_move?.homing_origin ?? []
}

get z_gcode_offset() {
return this.homing_origin.length > 1 ? Math.round(this.homing_origin[2] * 1000) / 1000 : 0
}

get offsetsZ() {
return this.$store.state.gui.control.offsetsZ
}
Expand All @@ -166,55 +158,8 @@ export default class ZoffsetControl extends Mixins(BaseMixin) {
return this.$store.state.printer.toolhead?.homed_axes ?? ''
}

get helplist() {
return this.$store.state.printer.helplist ?? []
}

get settings() {
return this.$store.state.printer.configfile?.settings ?? {}
}

get kinematics() {
return this.settings.printer?.kinematics ?? 'cartesian'
}

get stepper_name() {
if (this.kinematics === 'delta') return 'stepper_a'

return 'stepper_z'
}

get endstop_pin() {
const stepperConfig = this.settings[this.stepper_name] ?? {}

return stepperConfig?.endstop_pin
}

get isEndstopProbe() {
return this.endstop_pin.search('probe:z_virtual_endstop') !== -1
}

get existZOffsetApplyProbe() {
return this.helplist.findIndex((gcode: CommandHelp) => gcode.commandLow === 'z_offset_apply_probe') !== -1
}

get existZOffsetApplyEndstop() {
return this.helplist.findIndex((gcode: CommandHelp) => gcode.commandLow === 'z_offset_apply_endstop') !== -1
}

get zOffset(): number {
return this.$store.state.printer?.gcode_move?.homing_origin[2].toFixed(3)
}

get showSaveButton() {
// hide button when offset is 0
if (this.z_gcode_offset === 0) return false

// show button when z endstop is probe and probe gcode exists
if (this.isEndstopProbe && this.existZOffsetApplyProbe) return true

// show button when z endstop is endstop and endstop gcode exists
return !this.isEndstopProbe && this.existZOffsetApplyEndstop
get offsetZSaveOption() {
return this.$store.state.gui.control.offsetZSaveOption ?? null
}

sendBabyStepDown(offset: number): void {
Expand All @@ -236,23 +181,9 @@ export default class ZoffsetControl extends Mixins(BaseMixin) {
}

saveZOffset(): void {
if (this.isEndstopProbe && this.existZOffsetApplyProbe) {
this.saveZOffsetToProbe()
return
}

this.saveZOffsetToEndstop()
}

saveZOffsetToEndstop(): void {
const gcode = 'Z_OFFSET_APPLY_ENDSTOP'
this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' })
this.$socket.emit('printer.gcode.script', { script: gcode })
this.saveOffsetDialog = true
}
let gcode = this.offsetZSaveOption
if (gcode === null) gcode = this.autoSaveZOffsetOption

saveZOffsetToProbe(): void {
const gcode = 'Z_OFFSET_APPLY_PROBE'
this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' })
this.$socket.emit('printer.gcode.script', { script: gcode })
this.saveOffsetDialog = true
Expand Down
Loading
Loading