Skip to content

Commit

Permalink
feat(Heaters): adds MPC_CALIBRATE support (#1559)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas authored Dec 29, 2024
1 parent efe4771 commit fa254a7
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 4 deletions.
35 changes: 33 additions & 2 deletions src/components/widgets/thermals/HeaterContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
</v-list-item-content>
</v-list-item>

<v-divider />
<v-divider v-if="supportsPidCalibrate || supportsMpcCalibrate" />

<v-list-item
v-if="supportsPidCalibrate"
:disabled="!klippyReady || printerPrinting"
@click="$emit('pid-calibrate', heater)"
>
Expand All @@ -38,14 +39,29 @@
<v-list-item-title>PID_CALIBRATE</v-list-item-title>
</v-list-item-content>
</v-list-item>

<v-list-item
v-if="supportsMpcCalibrate"
:disabled="!klippyReady || printerPrinting"
@click="$emit('mpc-calibrate', heater)"
>
<v-list-item-icon>
<v-icon>
$tools
</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>MPC_CALIBRATE</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>
</template>

<script lang="ts">
import { Component, Prop, VModel, Mixins } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import type { Heater } from '@/store/printer/types'
import type { Heater, KlippyApp } from '@/store/printer/types'
@Component({})
export default class HeaterContextMenu extends Mixins(StateMixin) {
Expand All @@ -60,5 +76,20 @@ export default class HeaterContextMenu extends Mixins(StateMixin) {
@Prop({ type: Object, required: true })
readonly heater!: Heater
get klippyApp (): KlippyApp {
return this.$store.getters['printer/getKlippyApp'] as KlippyApp
}
get supportsPidCalibrate () {
return ['pid', 'pid_v'].includes(this.heater.config?.control)
}
get supportsMpcCalibrate () {
return (
this.klippyApp.isKalicoOrDangerKlipper &&
this.heater.config?.control === 'mpc'
)
}
}
</script>
72 changes: 72 additions & 0 deletions src/components/widgets/thermals/HeaterMpcCalibrateDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<app-dialog
v-model="open"
:title="$t('app.chart.title.mpc_calibrate', { name: heater.prettyName })"
max-width="480"
@save="handleSave"
>
<v-card-text class="pa-0">
<app-setting :title="$t('app.chart.label.target_temperature')">
<v-text-field
v-model.number="targetTemperature"
type="number"
filled
dense
single-line
hide-details="auto"
:rules="[
$rules.required,
$rules.numberValid,
$rules.numberGreaterThan(0)
]"
suffix="°C"
/>
</app-setting>

<v-divider />

<app-setting :title="$t('app.chart.label.fan_breakpoints')">
<v-text-field
v-model.number="fanBreakpoints"
type="number"
filled
dense
single-line
hide-details="auto"
:rules="[
$rules.numberValid,
$rules.numberGreaterThan(0)
]"
/>
</app-setting>
</v-card-text>
</app-dialog>
</template>

<script lang="ts">
import type { Heater } from '@/store/printer/types'
import type { NullableOrEmpty } from '@/util/is-null-or-empty'
import { Component, Vue, VModel, Prop, Watch } from 'vue-property-decorator'
@Component({})
export default class HeaterMpcCalibrateDialog extends Vue {
targetTemperature = 100
fanBreakpoints: NullableOrEmpty<number> = null
@Watch('fanBreakpoints')
onfanBreakpoints (value: string) {
console.log({ value })
}
@VModel({ type: Boolean })
open?: boolean
@Prop({ type: Object, required: true })
readonly heater!: Heater
handleSave () {
this.$emit('save', this.heater, this.targetTemperature, this.fanBreakpoints)
this.open = false
}
}
</script>
29 changes: 28 additions & 1 deletion src/components/widgets/thermals/TemperatureTargets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
:position-x="contextMenuState.x"
:position-y="contextMenuState.y"
@pid-calibrate="handlePidCalibrateDialog"
@mpc-calibrate="handleMpcCalibrateDialog"
@turn-off="handleTurnOff"
/>

Expand All @@ -311,6 +312,13 @@
:heater="heaterPidCalibrateDialog.heater"
@save="handlePidCalibrate"
/>

<heater-mpc-calibrate-dialog
v-if="heaterMpcCalibrateDialog.open"
v-model="heaterMpcCalibrateDialog.open"
:heater="heaterMpcCalibrateDialog.heater"
@save="handleMpcCalibrate"
/>
</div>
</template>

Expand All @@ -319,17 +327,20 @@ import { Component, Mixins } from 'vue-property-decorator'
import TemperaturePresetsMenu from './TemperaturePresetsMenu.vue'
import HeaterContextMenu from './HeaterContextMenu.vue'
import HeaterPidCalibrateDialog from './HeaterPidCalibrateDialog.vue'
import HeaterMpcCalibrateDialog from './HeaterMpcCalibrateDialog.vue'
import StateMixin from '@/mixins/state'
import type { Fan, Heater, Sensor } from '@/store/printer/types'
import { takeRightWhile } from 'lodash-es'
import type { ChartData, ChartSelectedLegends } from '@/store/charts/types'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
import isNullOrEmpty, { type NullableOrEmpty } from '@/util/is-null-or-empty'
@Component({
components: {
TemperaturePresetsMenu,
HeaterContextMenu,
HeaterPidCalibrateDialog
HeaterPidCalibrateDialog,
HeaterMpcCalibrateDialog
}
})
export default class TemperatureTargets extends Mixins(StateMixin) {
Expand All @@ -345,6 +356,11 @@ export default class TemperatureTargets extends Mixins(StateMixin) {
open: false
}
heaterMpcCalibrateDialog: any = {
heater: null,
open: false
}
get heaters (): Heater[] {
return this.$store.getters['printer/getHeaters'] as Heater[]
}
Expand Down Expand Up @@ -531,6 +547,17 @@ export default class TemperatureTargets extends Mixins(StateMixin) {
handlePidCalibrate (heater: Heater, targetTemperature: number) {
this.sendGcode(`PID_CALIBRATE HEATER=${encodeGcodeParamValue(heater.name)} TARGET=${targetTemperature}`)
}
handleMpcCalibrateDialog (heater: Heater) {
this.heaterMpcCalibrateDialog = {
heater,
open: true
}
}
handleMpcCalibrate (heater: Heater, targetTemperature: number, fanBreakpoints: NullableOrEmpty<number>) {
this.sendGcode(`MPC_CALIBRATE HEATER=${encodeGcodeParamValue(heater.name)} TARGET=${targetTemperature}${!isNullOrEmpty(fanBreakpoints) ? ` FAN_BREAKPOINTS=${fanBreakpoints}` : ''}`)
}
}
</script>

Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ app:
chart:
label:
current: Actual
fan_breakpoints: Fan Breakpoints
item: Name
power: Power
rate_of_change: Change
target_temperature: Target Temperature
target: Target
turn_off: Turn Off
title:
mpc_calibrate: MPC Calibrate {name}
pid_calibrate: PID Calibrate {name}
tooltip:
help: >-
Expand Down
3 changes: 2 additions & 1 deletion src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ export const getters: GetterTree<PrinterState, RootState> = {
prettyName,
key: e,
minTemp: config?.min_temp ?? 0,
maxTemp: config?.max_temp ?? 500
maxTemp: config?.max_temp ?? 500,
config: { ...config }
})
}
})
Expand Down

0 comments on commit fa254a7

Please sign in to comment.