Skip to content

Commit

Permalink
feat: show all fan and pin values as percentages (#1418)
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 18, 2024
1 parent 3febd1e commit 192ee19
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/components/ui/AppNamedSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
v-model="inputValue"
class="mt-0"
:disabled="disabled || loading"
:true-value="trueValue"
:false-value="falseValue"
hide-details
v-on="$listeners"
/>
Expand All @@ -34,5 +36,11 @@ export default class AppNamedSwitch extends Vue {
@Prop({ type: Boolean })
readonly loading?: boolean
@Prop({ })
readonly trueValue?: unknown
@Prop({ })
readonly falseValue?: unknown
}
</script>
2 changes: 1 addition & 1 deletion src/components/widgets/outputs/OutputFan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class OutputFan extends Mixins(StateMixin, BrowserMixin) {
get prettyValue () {
return (this.value === 0)
? this.$t('app.general.label.off')
: this.$t('app.general.label.on')
: `${this.value} %`
}
get value () {
Expand Down
18 changes: 12 additions & 6 deletions src/components/widgets/outputs/OutputPin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<div>
<app-named-slider
v-if="pwm"
suffix="%"
:label="pin.prettyName"
:min="0"
:max="pin.scale"
:step="0.01"
:max="100"
:value="value"
:reset-value="pin.config.value || 0"
:reset-value="resetValue"
:disabled="!klippyReady"
:locked="isMobileViewport"
:loading="hasWait(`${$waits.onSetOutputPin}${pin.name}`)"
Expand Down Expand Up @@ -51,14 +51,20 @@ export default class OutputPin extends Mixins(StateMixin, BrowserMixin) {
}
get value () {
return Math.round(this.pin.value * this.pin.scale * 100) / 100
return Math.round(this.pin.value * 100)
}
handleChange (target: number) {
if (!this.pwm) {
get resetValue () {
return Math.round(this.pin.resetValue / this.pin.scale * 100)
}
handleChange (target: number | boolean) {
if (typeof target === 'boolean') {
target = target
? this.pin.scale
: 0
} else {
target = Math.round(target * this.pin.scale) / 100
}
this.sendGcode(`SET_PIN PIN=${this.pin.name} VALUE=${target}`, `${this.$waits.onSetOutputPin}${this.pin.name}`)
Expand Down
7 changes: 4 additions & 3 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,10 @@ export const getters: GetterTree<PrinterState, RootState> = {
if (outputPins.includes(type)) {
output = {
...output,
pwm: (config && config.pwm) ? config.pwm : false,
scale: (config && config.scale) ? config.scale : 1,
controllable: (config && config.static_value) ? false : (controllable.includes(type))
pwm: config?.pwm ?? false,
scale: config?.scale ?? 1,
resetValue: config?.value ?? 0,
controllable: config?.static_value ? false : controllable.includes(type)
}
}

Expand Down
17 changes: 9 additions & 8 deletions src/store/printer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,18 @@ export interface OutputPin extends OutputType<OutputPinConfig> {
scale: number;
static: number;
value: number;
resetValue: number;
}

export interface OutputPinConfig {
[index: string]: string | undefined;
pwm?: string;
static_value?: string;
value?: string;
shutdown_value?: string;
cycle_time?: string;
hardware_pwm?: string;
scale?: string;
[index: string]: string | number | boolean | undefined;
pwm?: boolean;
static_value?: number;
value?: number;
shutdown_value?: number;
cycle_time?: number;
hardware_pwm?: boolean;
scale?: number;
}

export interface Sensor {
Expand Down

0 comments on commit 192ee19

Please sign in to comment.