Last active
February 18, 2025 09:33
-
-
Save rootiest/b39fae412b8bd84c6a8acc872acff0aa to your computer and use it in GitHub Desktop.
Minimum Fan Speed Override
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------------------- # | |
# MINIMUM FAN SPEED OVERRIDE # | |
# -------------------------------------------------------------------------- # | |
# Override the default fan speed to set a minimum floor # | |
# and adjust the values to fit the new range. # | |
# Examples: (with min_fan_speed = 128) # | |
# M106 S255 ; set fan speed to 255 # | |
# M106 S25 ; set fan speed to 159 # | |
# M106 S0 ; set fan speed to 0 # | |
# M106 S50 ; set fan speed to 128 # | |
# M106 S75 ; set fan speed to 191 # | |
# -------------------------------------------------------------------------- # | |
[gcode_macro M106] | |
variable_min_fan_speed: 128 | |
rename_existing: M106.0 | |
description: Set fan speed | |
gcode: | |
{% set initial_speed = params.S|default(0)|float %} ; Get the initial speed value | |
{% if initial_speed < 0 %} ; If the initial speed is less than 0 | |
{% set initial_speed = 0 %} ; Set the initial speed to 0 | |
{% elif initial_speed > 255 %} ; If the initial speed is greater than 255 | |
{% set initial_speed = 255 %} ; Set the initial speed to 255 | |
{% endif %} | |
; Calculate the new speed value | |
{% set new_speed = (initial_speed / 255 * (255 - min_fan_speed)) + min_fan_speed %} | |
{% if new_speed > 255 %} ; If the new speed is greater than 255 | |
{% set new_speed = 255 %} ; Set the new speed to 255 | |
{% elif new_speed <= min_fan_speed %} ; If the new speed is less than or equal to the minimum fan speed | |
{% set new_speed = 0 %} ; Set the new speed to 0 | |
{% endif %} | |
M106.0 S{new_speed} ; Set the fan speed to the new speed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment