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

Issue with output_pin #1869

Closed
Guilouz opened this issue May 2, 2024 · 3 comments · Fixed by #1870
Closed

Issue with output_pin #1869

Guilouz opened this issue May 2, 2024 · 3 comments · Fixed by #1870
Labels
⚡ Type: Bug Something isn't working

Comments

@Guilouz
Copy link

Guilouz commented May 2, 2024

Mainsail Version:

2.11.1

Browser:

Chrome

Device:

Desktop PC

Operating System:

Linux

What happened?

Sliders on Web UI only set 0 or 1 when output_pin is used with scale.

What did you expect to happen instead?

Slider set the correct value in range 0-255 and not 0 or 1.

How to reproduce this bug?

I use this config:

[output_pin soc_fan]
pin: PB2
pwm: True
cycle_time: 0.0100
hardware_pwm: false
value: 0.00
scale: 255
shutdown_value: 0.0

When using slider to 100% this is the sending command:

SET_PIN PIN=soc_fan VALUE=1.00

While it should send this command:

SET_PIN PIN=soc_fan VALUE=255

Additional information:

On Fluidd it's working as expected.

@Guilouz Guilouz added the ⚡ Type: Bug Something isn't working label May 2, 2024
Copy link

dosubot bot commented May 2, 2024

Hey @Guilouz! 👋 I'm Dosu, your friendly neighborhood bot here to help you tackle bugs, answer your questions, and guide you on your way to becoming a contributor. While we wait for a human maintainer to chime in, I'll be diving into your issue to lend a hand. Hang tight, I'll get back to you with more insights soon! 🤖

@rackrick
Copy link
Member

rackrick commented May 3, 2024

Hey @Guilouz ,
you're right... the output pin is currently fixed to a value of 1. We look further into it. There were some changes of the output_pin module at the begining of the year. Looks like we did not address all those changes.

If you don't want to wait for a fix you could use fan_generic Klipper Config Ref to controll a fan the same way.

Copy link

dosubot bot commented May 3, 2024

The issue you're encountering with the output_pin configuration in Mainsail, where the slider only sets values of 0 or 1 instead of the full 0-255 range, is due to how the slider's value is processed before sending the G-code command. The slider operates within a 0.0 to 1.0 range, and this value is directly used without conversion to the expected 0-255 range for PWM control.

To address this, the value sent by the slider needs to be adjusted to the 0-255 range before being formatted into the G-code command. This can be achieved by modifying the method that handles the slider's value, specifically by multiplying the slider's value (0.0 to 1.0) by 255 to convert it to the full range before sending the command. Here's a simplified adjustment you could make:

sendCmd(newVal: number): void {
    // Convert newVal to a 0-255 range
    newVal = newVal * 255;
    let gcode = `SET_PIN PIN=${this.name} VALUE=${newVal.toFixed(0)}`;

    // Send the G-code command
    this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' });
    this.$socket.emit('printer.gcode.script', { script: gcode });
}

This change ensures that the slider's value is correctly scaled to the 0-255 range expected for PWM control before the G-code command is generated and sent. It's important to thoroughly test any modifications to confirm they work as expected and don't introduce new issues.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants