Skip to content

Instantly share code, notes, and snippets.

@ShaneDelmore
Last active March 11, 2025 23:46
Show Gist options
  • Select an option

  • Save ShaneDelmore/fe4f68d3a1a0c643ca43f5a1b29d8774 to your computer and use it in GitHub Desktop.

Select an option

Save ShaneDelmore/fe4f68d3a1a0c643ca43f5a1b29d8774 to your computer and use it in GitHub Desktop.
Add fan and accel multipliers to Klipper/Mainsail

Install klipper-virtual-pins

bash
cd ~
git clone https://github.com/pedrolamas/klipper-virtual-pins.git
./klipper-virtual-pins/install.sh

Add virtual pins to printer.cfg

[virtual_pins]

[output_pin fan_factor]
pin: virtual_pin:fan_factor
pwm: True
value: 1.0

[output_pin accel_factor]
pin: virtual_pin:accel_factor
pwm: True
value: 1.0

Configure M106 to use fan_factor

[gcode_macro M106]
rename_existing: M106.1
gcode:
  {% set S = params.S|default(0)|int %}
  {% set P = params.P|default(0)|int %}
  {% set FACTOR = printer['output_pin fan_factor'].value %}
  {% set ADJUSTED_S = (S * FACTOR)|round(0)|int %}
  M106.1 P{P} S{ADJUSTED_S}

Configure SET_VELOCITY_LIMIT to use accel_factor

[gcode_macro SET_VELOCITY_LIMIT]
rename_existing: SET_VELOCITY_LIMIT_ORIG
gcode:
    {% set accel = params.ACCEL|default(None) %}
    {% set accel_to_decel = params.ACCEL_TO_DECEL|default(None) %}
    {% set velocity = params.VELOCITY|default(None) %}
    {% set factor = printer['output_pin accel_factor'].value %}

    {% if accel is not none %}
        {% set adjusted_accel = accel|float * factor %}
    {% else %}
        {% set adjusted_accel = None %}
    {% endif %}

    {% if accel_to_decel is not none %}
        {% set adjusted_accel_to_decel = accel_to_decel|float * factor %}
    {% else %}
        {% set adjusted_accel_to_decel = None %}
    {% endif %}

    SET_VELOCITY_LIMIT_ORIG {% if velocity is not none %}VELOCITY={velocity|float}{% endif %} {% if adjusted_accel is not none %}ACCEL={adjusted_accel|float}{% endif %} {% if adjusted_accel_to_decel is not none %}ACCEL_TO_DECEL={adjusted_accel_to_decel|float}{% endif %}
@ShaneDelmore
Copy link
Author

If you want to get fancy you could add a moonraker hook to listen to changes to the factor pins and immediately recalculate fan speed and accel but I only use these when my sliced file is changing them rapidly so they get recalculated when those change pretty quickly anyway.

@ShaneDelmore
Copy link
Author

This was tested on an FLSun T1 Pro running klipper 10. You may need slight changes on different versions of klipper or other printers but hopefully the idea is still helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment