-
-
Notifications
You must be signed in to change notification settings - Fork 601
Expand file tree
/
Copy pathOutputFan.vue
More file actions
101 lines (88 loc) · 2.54 KB
/
Copy pathOutputFan.vue
File metadata and controls
101 lines (88 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<template>
<div>
<app-named-slider
v-if="fan.controllable"
suffix="%"
:value="value"
:reset-value="0"
:label="label"
:rules="[
customRules.minFan
]"
:disabled="!klippyReady || fan.disconnected"
:locked="isMobileUserAgent"
:loading="hasWait(`${$waits.onSetFanSpeed}${fan.name}`)"
@submit="handleChange"
/>
<v-layout
v-else
align-center
justify-space-between
:class="{ 'text--disabled': !klippyReady || fan.disconnected }"
>
<div class="text-body-1">
{{ fan.prettyName }}
</div>
<div class="ml-auto">
<small
v-if="rpm"
class="mr-2"
>{{ rpm }}</small>
<span
v-safe-html="prettyValue"
class="focus--text"
/>
</div>
</v-layout>
</div>
</template>
<script lang="ts">
import { Component, Mixins, Prop } from 'vue-property-decorator'
import type { Fan } from '@/store/printer/types'
import StateMixin from '@/mixins/state'
import BrowserMixin from '@/mixins/browser'
import buildOutputLabel from '@/util/build-output-label'
import { buildFanSpeedGcode } from '@/util/output-gcode'
@Component({})
export default class OutputFan extends Mixins(StateMixin, BrowserMixin) {
@Prop({ type: Object, required: true })
readonly fan!: Fan
// prettyName may be a user-supplied alias; the label is rendered as HTML
// (v-safe-html) so escape it before composing the optional <small> rpm markup.
get label () {
return buildOutputLabel(this.fan.prettyName, this.rpm)
}
get prettyValue () {
return (this.value === 0)
? this.$t('app.general.label.off')
: `${this.value} %`
}
get value () {
if (!this.fan.speed) return 0
const speed = this.fan.speed / (this.fan.config?.max_power || 1)
return Math.round(speed * 100)
}
handleChange (target: number) {
// Display-only: the command is keyed by the raw Klipper name, never the alias.
const gcode = buildFanSpeedGcode(this.fan, target)
if (gcode) {
this.sendGcode(gcode, `${this.$waits.onSetFanSpeed}${this.fan.name}`)
}
}
get rpm () {
return (this.fan.rpm)
? this.fan.rpm.toFixed() + ' rpm'
: undefined
}
get customRules () {
return {
minFan: (v: string | number) => {
const off_below = (this.fan.config?.off_below || 0) * 100
if (!off_below) return true
v = +v
return (v >= off_below || v === 0) || this.$t('app.general.simple_form.error.min_or_0', { min: off_below })
}
}
}
}
</script>