Skip to content

Commit

Permalink
feat: Pressure Advance per extruder stepper (#1022)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas authored Feb 2, 2023
1 parent 643c204 commit aa7007a
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 14 deletions.
4 changes: 0 additions & 4 deletions src/components/widgets/toolhead/ExtruderStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ import ToolheadMixin from '@/mixins/toolhead'
@Component({})
export default class ExtruderMoves extends Mixins(StateMixin, ToolheadMixin) {
get maxExtrudeLength (): number {
return this.activeExtruder?.max_extrude_only_distance || 50
}
get filamentDiameter (): number {
return this.activeExtruder?.filament_diameter || 1.75
}
Expand Down
35 changes: 26 additions & 9 deletions src/components/widgets/toolhead/PressureAdvanceAdjust.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<app-slider
:label="$t('app.general.label.pressure_advance')"
suffix="s"
:value="activeExtruder.pressure_advance || 0"
:value="selectedExtruderStepper.pressure_advance || 0"
:overridable="true"
:reset-value="activeExtruder.config_pressure_advance || 0"
:reset-value="selectedExtruderStepper.config_pressure_advance || 0"
:disabled="!klippyReady"
:locked="(!klippyReady || isMobile)"
:loading="hasWait($waits.onSetPressureAdvance)"
:loading="hasWait(`${$waits.onSetPressureAdvance}${selectedExtruderStepper.name ?? ''}`)"
:min="0"
:max="2"
:step="0.0001"
Expand All @@ -26,12 +26,12 @@
<app-slider
:label="$t('app.general.label.smooth_time')"
suffix="s"
:value="activeExtruder.smooth_time || 0"
:value="selectedExtruderStepper.smooth_time || 0"
:overridable="false"
:reset-value="activeExtruder.config_smooth_time || 0"
:reset-value="selectedExtruderStepper.config_smooth_time || 0"
:disabled="!klippyReady"
:locked="(!klippyReady || isMobile)"
:loading="hasWait($waits.onSetPressureAdvance)"
:loading="hasWait(`${$waits.onSetPressureAdvance}${selectedExtruderStepper.name ?? ''}`)"
:min="0"
:max="0.2"
:step="0.001"
Expand All @@ -42,18 +42,35 @@
</template>
<script lang="ts">
import { Component, Mixins } from 'vue-property-decorator'
import { Component, Mixins, Prop } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import ToolheadMixin from '@/mixins/toolhead'
import { ExtruderStepper } from '@/store/printer/types'
@Component({})
export default class PressureAdvanceAdjust extends Mixins(StateMixin, ToolheadMixin) {
@Prop({ type: Object, required: false })
readonly extruderStepper?: ExtruderStepper
get selectedExtruderStepper (): ExtruderStepper {
return this.extruderStepper ?? this.activeExtruder
}
handleSetPressureAdvance (val: number) {
this.sendGcode('SET_PRESSURE_ADVANCE ADVANCE=' + val, this.$waits.onSetPressureAdvance)
this.sendSetPressureAdvance('ADVANCE', val)
}
handleSetSmoothTime (val: number) {
this.sendGcode('SET_PRESSURE_ADVANCE SMOOTH_TIME=' + val, this.$waits.onSetPressureAdvance)
this.sendSetPressureAdvance('SMOOTH_TIME', val)
}
sendSetPressureAdvance (arg: string, val: number) {
if (this.extruderStepper) {
const { name } = this.extruderStepper
this.sendGcode(`SET_PRESSURE_ADVANCE ${arg}=${val} EXTRUDER=${name}`, `${this.$waits.onSetPressureAdvance}${name}`)
} else {
this.sendGcode(`SET_PRESSURE_ADVANCE ${arg}=${val}`, this.$waits.onSetPressureAdvance)
}
}
get isMobile () {
Expand Down
36 changes: 36 additions & 0 deletions src/components/widgets/toolhead/Toolhead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@
<speed-and-flow-adjust />
<pressure-advance-adjust v-if="showPressureAdvance" />
</v-card-text>

<v-expansion-panels
accordion
multiple
flat
>
<v-expansion-panel
v-for="extruderStepper in extruderSteppers"
:key="`extruderStepper-${extruderStepper.name}`"
>
<v-divider />
<v-expansion-panel-header>
<template #actions>
<v-icon
small
class="my-1 mr-2"
>
$expand
</v-icon>
</template>
{{ $filters.startCase(extruderStepper.name) }}
</v-expansion-panel-header>
<v-expansion-panel-content>
<pressure-advance-adjust
:extruder-stepper="extruderStepper"
/>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>
</div>
</template>

Expand All @@ -45,6 +74,7 @@ import ZHeightAdjust from '@/components/widgets/toolhead/ZHeightAdjust.vue'
import SpeedAndFlowAdjust from '@/components/widgets/toolhead/SpeedAndFlowAdjust.vue'
import PressureAdvanceAdjust from '@/components/widgets/toolhead/PressureAdvanceAdjust.vue'
import ExtruderStats from '@/components/widgets/toolhead/ExtruderStats.vue'
import { ExtruderStepper } from '@/store/printer/types'
@Component({
components: {
Expand All @@ -63,6 +93,12 @@ export default class Toolhead extends Mixins(StateMixin) {
return this.$store.getters['printer/getExtruders'].length > 1
}
get extruderSteppers () {
const extruderSteppers = this.$store.getters['printer/getExtruderSteppers'] as ExtruderStepper[]
return extruderSteppers
.filter(x => x.pressure_advance !== undefined)
}
get showPressureAdvance () {
const extruder = this.$store.getters['printer/getActiveExtruder']
return extruder?.pressure_advance !== undefined
Expand Down
22 changes: 21 additions & 1 deletion src/store/printer/getters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from 'vue'
import { GetterTree } from 'vuex'
import { RootState } from '../types'
import { PrinterState, Heater, Fan, Led, OutputPin, Sensor, RunoutSensor, Extruder, MCU, Endstop, Probe } from './types'
import { PrinterState, Heater, Fan, Led, OutputPin, Sensor, RunoutSensor, Extruder, MCU, Endstop, Probe, ExtruderStepper } from './types'
import { get } from 'lodash-es'
import getKlipperType from '@/util/get-klipper-type'

Expand Down Expand Up @@ -290,6 +290,26 @@ export const getters: GetterTree<PrinterState, RootState> = {
}
},

getExtruderSteppers: (state, getters) => {
const extruderSteppers: ExtruderStepper[] = []
for (const item in state.printer) {
const [type, name] = item.split(' ')

if (type === 'extruder_stepper') {
const e = state.printer[item]
const c = getters.getPrinterSettings(item)

extruderSteppers.push({
name,
...e,
config_pressure_advance: c.pressure_advance,
config_smooth_time: c.pressure_advance_smooth_time
})
}
}
return extruderSteppers.sort((a, b) => a.name.localeCompare(b.name))
},

/**
* Given axes, returns a boolean indicating if the axes are homed.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/store/printer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export interface Extruder {
key: string;
}

export interface ExtruderStepper {
name: string;
pressure_advance: number;
smooth_time: number;
config_pressure_advance: number;
config_smooth_time: number;
}

export interface MCU {
name: string;
last_stats: MCUData;
Expand Down

0 comments on commit aa7007a

Please sign in to comment.