Skip to content

Commit

Permalink
fix: allow applying z-offset to endstop or probe
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas committed Apr 19, 2023
1 parent 7bd82a1 commit 536ebb6
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 30 deletions.
113 changes: 83 additions & 30 deletions src/components/widgets/toolhead/ZHeightAdjust.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
:class="{ 'text--disabled': !klippyReady }"
>
<span class="secondary--text">{{ $t('app.general.label.z_offset') }}&nbsp;</span>
<span>{{ ZHomingOrigin }}mm</span>
<span>{{ zHomingOrigin.toFixed(3) }}mm</span>
</div>
</v-col>
<v-col cols="6">
Expand Down Expand Up @@ -76,15 +76,63 @@
class="pr-1"
>
<app-btn
:disabled="!klippyReady || printerPrinting || (ZHomingOrigin == 0)"
v-if="hasZOffsetApplyEndstop !== hasZOffsetApplyProbe"
:disabled="!klippyReady || printerPrinting || zHomingOrigin === 0"
small
block
@click="handleZApplyDialog"
@click="handleZOffsetApply"
>
<v-icon small>
$save
</v-icon>
</app-btn>

<v-menu
v-else
left
offset-y
transition="slide-y-transition"
>
<template #activator="{ on, attrs, value }">
<app-btn
v-bind="attrs"
:disabled="!klippyReady || printerPrinting || zHomingOrigin === 0"
small
block
v-on="on"
>
<v-icon small>
$save
</v-icon>
<v-icon
small
class="ml-1"
:class="{ 'rotate-180': value }"
>
$chevronDown
</v-icon>
</app-btn>
</template>
<v-list dense>
<template v-for="command of ['Z_OFFSET_APPLY_ENDSTOP', 'Z_OFFSET_APPLY_PROBE']">
<v-list-item
:key="command"
@click="sendGcode(command)"
>
<v-list-item-icon>
<v-icon>
$expandVertical
</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>
{{ command }}
</v-list-item-title>
</v-list-item-content>
</v-list-item>
</template>
</v-list>
</v-menu>
</v-col>
</v-row>
</v-col>
Expand All @@ -94,19 +142,22 @@
<script lang="ts">
import { Component, Mixins } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import { GcodeCommands } from '@/store/console/types'
@Component({})
export default class ZHeightAdjust extends Mixins(StateMixin) {
moveDistanceValue: number | null = null
get ZHomingOrigin () {
get zHomingOrigin (): number {
// This is an array of 4 values, representing the homing origin.
// It should be in the order of; X, Y, Z, E.
const { homing_origin } = this.$store.state.printer.printer.gcode_move
return homing_origin && homing_origin.length >= 4
? homing_origin[2].toFixed(3)
: null
const zHomingOrigin: number = homing_origin && homing_origin.length >= 4
? +homing_origin[2]
: 0
return zHomingOrigin
}
get zAdjustValues () {
Expand All @@ -121,6 +172,25 @@ export default class ZHeightAdjust extends Mixins(StateMixin) {
this.moveDistanceValue = value
}
get availableCommands (): GcodeCommands {
return this.$store.state.console.availableCommands as GcodeCommands
}
get availableCommandNames (): Set<string> {
const availableCommandNames = new Set(Object.keys(this.availableCommands)
.map(commandName => commandName.toUpperCase()))
return availableCommandNames
}
get hasZOffsetApplyProbe (): boolean {
return this.availableCommandNames.has('Z_OFFSET_APPLY_PROBE')
}
get hasZOffsetApplyEndstop (): boolean {
return this.availableCommandNames.has('Z_OFFSET_APPLY_ENDSTOP')
}
/**
* Send a Z adjust gcode script.
*/
Expand All @@ -130,30 +200,13 @@ export default class ZHeightAdjust extends Mixins(StateMixin) {
this.sendGcode(gcode, this.$waits.onZAdjust)
}
get printerUsesProbeAsEndstop (): boolean {
const stepper = this.$store.getters['printer/getPrinterSettings']('stepper_z')
return !stepper || stepper.endstop_pin === 'probe:z_virtual_endstop'
}
handleZOffsetApply () {
if (this.hasZOffsetApplyProbe && !this.hasZOffsetApplyEndstop) {
this.sendGcode('Z_OFFSET_APPLY_PROBE')
}
async handleZApplyDialog () {
const [gcode, msg] = this.printerUsesProbeAsEndstop
? ['Z_OFFSET_APPLY_PROBE', this.$tc('app.general.simple_form.msg.apply_z_offset_probe')]
: ['Z_OFFSET_APPLY_ENDSTOP', this.$tc('app.general.simple_form.msg.apply_z_offset_endstop')]
const res = await this.$confirm(
msg,
{
title: this.$tc('app.general.label.apply_z_offset'),
color: 'card-heading',
icon: '$error',
buttonTrueText: this.$tc('app.general.btn.save_restart'),
buttonFalseText: this.$tc('app.general.btn.cancel')
})
if (res) {
this.sendGcode(gcode, this.$waits.onZApply)
this.sendGcode('SAVE_CONFIG', this.$waits.onSaveConfig)
if (this.hasZOffsetApplyEndstop && !this.hasZOffsetApplyProbe) {
this.sendGcode('Z_OFFSET_APPLY_ENDSTOP')
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
mdiArrowCollapseDown,
mdiViewGridOutline,
mdiArrowExpandHorizontal,
mdiArrowExpandVertical,
mdiRefresh,
mdiCheckCircleOutline,
mdiCheckboxBlankCircleOutline,
Expand Down Expand Up @@ -271,6 +272,7 @@ export const Icons = Object.freeze({
zUp: mdiArrowExpandUp,
zDown: mdiArrowCollapseDown,
expandHorizontal: mdiArrowExpandHorizontal,
expandVertical: mdiArrowExpandVertical,
cog: mdiCog,
cogs: mdiCogs,
save: mdiContentSaveOutline,
Expand Down

0 comments on commit 536ebb6

Please sign in to comment.