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 support for heaters/set_target_temperature api call #1967

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
52 changes: 42 additions & 10 deletions src/components/inputs/TemperatureInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
</template>
<v-list dense class="py-0">
<v-list-item
v-for="preset of presets"
:key="preset.index"
v-for="(preset, index) of presets"
:key="index"
link
style="min-height: 32px"
@click="doSend(`${command} ${attributeName}=${name} TARGET=${preset.value}`)">
@click="sendCommand(preset.value)">
<div class="_preset">
<v-icon v-if="preset.value === 0" else color="primary" small class="_preset-icon">
{{ mdiSnowflake }}
Expand All @@ -60,35 +60,67 @@ export default class TemperatureInput extends Mixins(BaseMixin, ControlMixin) {
mdiFire = mdiFire
mdiMenuDown = mdiMenuDown

private value: any = 0
value: any = 0

@Prop({ type: String, required: true }) declare readonly name: string
@Prop({ type: Number, required: true, default: 0 }) declare readonly target: number
@Prop({ type: Number, required: true }) declare readonly min_temp: number
@Prop({ type: Number, required: true }) declare readonly max_temp: number
@Prop({ type: String, required: true }) declare readonly command: string
@Prop({ type: String, required: true }) declare readonly attributeName: string
@Prop({ type: Array, default: [] }) declare presets: number[]
@Prop({ type: Array, default: [] }) declare presets: { value: number; text: string }[]

get temperatureWait() {
return this.$store.state.printer.heaters?.temperature_wait ?? null
}

setTemps(): void {
if (typeof this.value === 'object') this.value = this.value.value ?? 0
if (this.value === null) this.value = 0
if (typeof this.value !== 'number') this.value = parseFloat(this.value)

// break if target temp is identical to input temp
if (this.target === this.value) {
return
}

// break when input temp is higher ten max_temp
if (this.value > this.max_temp) {
this.value = { value: this.target, text: this.target }
this.$toast.error(
this.$t('Panels.TemperaturePanel.TempTooHigh', { name: this.name, max: this.max_temp }) + ''
)
} else if (this.value < this.min_temp && this.value != 0) {

return
}

if (this.value < this.min_temp && this.value != 0) {
this.value = { value: this.target, text: this.target }
this.$toast.error(
this.$t('Panels.TemperaturePanel.TempTooLow', { name: this.name, min: this.min_temp }) + ''
)
} else if (this.target !== parseFloat(this.value)) {
const gcode = this.command + ' ' + this.attributeName + '=' + this.name + ' TARGET=' + this.value
this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' })
this.$socket.emit('printer.gcode.script', { script: gcode })

return
}

this.sendCommand(this.value)
}

sendCommand(newTemp: number) {
// send api call to interrupt wait command
if (this.temperatureWait !== null && this.command === 'SET_HEATER_TEMPERATURE') {
this.$socket.emit('printer.heaters.set_target_temperature', {
heater: this.name,
target: newTemp,
})

return
}

// send gcode to set target temperature
const gcode = this.command + ' ' + this.attributeName + '=' + this.name + ' TARGET=' + newTemp
this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' })
this.$socket.emit('printer.gcode.script', { script: gcode })
}

mounted() {
Expand Down
19 changes: 19 additions & 0 deletions src/components/panels/Temperature/TemperaturePanelListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
</td>
<td class="name">
<span class="cursor-pointer" @click="showEditDialog = true">{{ formatName }}</span>
<v-tooltip v-if="isWait" top>
<template #activator="{ on, attrs }">
<v-icon class="ml-2 text--disabled" small v-bind="attrs" v-on="on">{{ mdiFireAlert }}</v-icon>
</template>
<span>{{ $t('Panels.TemperaturePanel.WaitForTemperature') }}</span>
</v-tooltip>
</td>
<td v-if="!isResponsiveMobile" class="state">
<v-tooltip v-if="state !== null" top>
Expand Down Expand Up @@ -68,6 +74,7 @@ import { convertName } from '@/plugins/helpers'
import {
mdiFan,
mdiFire,
mdiFireAlert,
mdiMemory,
mdiPrinter3dNozzle,
mdiPrinter3dNozzleAlert,
Expand All @@ -79,6 +86,8 @@ import { additionalSensors, opacityHeaterActive, opacityHeaterInactive } from '@

@Component
export default class TemperaturePanelListItem extends Mixins(BaseMixin) {
mdiFireAlert = mdiFireAlert

@Prop({ type: String, required: true }) readonly objectName!: string
@Prop({ type: Boolean, required: true }) readonly isResponsiveMobile!: boolean

Expand Down Expand Up @@ -270,6 +279,16 @@ export default class TemperaturePanelListItem extends Mixins(BaseMixin) {

return ''
}

get temperatureWait() {
return this.$store.state.printer.heaters?.temperature_wait ?? null
}

get isWait() {
if (this.temperatureWait === null) return false

return this.temperatureWait.includes(this.name)
}
}
</script>

Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,8 @@
"Target": "Target",
"TemperaturesInChart": "Temperature [°C]",
"TempTooHigh": "Temperature too high for {name}! (max: {max})",
"TempTooLow": "Temperature too low for {name}! (min: {min})"
"TempTooLow": "Temperature too low for {name}! (min: {min})",
"WaitForTemperature": "Wait for temperature"
},
"ToolheadControlPanel": {
"Absolute": "absolute",
Expand Down
Loading