-
-
Notifications
You must be signed in to change notification settings - Fork 226
Added the ability to set heater_fan speed #729
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
|
|
||
|
|
||
| class PrinterHeaterFan: | ||
| cmd_SET_FAN_SPEED_help = "Sets the speed of a fan" | ||
|
|
||
| def __init__(self, config): | ||
| self.printer = config.get_printer() | ||
| self.printer.load_object(config, "heaters") | ||
|
|
@@ -17,10 +19,23 @@ def __init__(self, config): | |
| self.heater_temp = config.getfloat("heater_temp", 50.0) | ||
| self.heaters = [] | ||
| self.fan = fan.Fan(config, default_shutdown_speed=1.0) | ||
| self.fan_speed = config.getfloat( | ||
| self.enabled_fan_speed = config.getfloat( | ||
| "fan_speed", 1.0, minval=0.0, maxval=1.0 | ||
| ) | ||
| self.last_speed = 0.0 | ||
| self.last_gcode_speed = 0.0 | ||
|
|
||
| # register SET_FAN_SPEED mux command so users can override this fan | ||
| self.fan_name = config.get_name().split()[-1] | ||
| gcode = self.printer.lookup_object("gcode") | ||
| gcode.register_mux_command( | ||
| "SET_FAN_SPEED", | ||
| "FAN", | ||
| self.fan_name, | ||
| self.cmd_SET_FAN_SPEED, | ||
| desc=self.cmd_SET_FAN_SPEED_help, | ||
| ) | ||
|
|
||
|
|
||
| def handle_ready(self): | ||
| pheaters = self.printer.lookup_object("heaters") | ||
|
|
@@ -34,18 +49,24 @@ def get_status(self, eventtime): | |
| return self.fan.get_status(eventtime) | ||
|
|
||
| def callback(self, eventtime): | ||
| speed = 0.0 | ||
| speed = self.last_gcode_speed | ||
| for heater in self.heaters: | ||
| current_temp, target_temp = heater.get_temp(eventtime) | ||
| if target_temp or current_temp > self.heater_temp: | ||
| speed = self.fan_speed | ||
| if (target_temp or current_temp > self.heater_temp) and self.enabled_fan_speed > speed: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic here is a bit hard to follow, could we split it over multiple statements or something? I'm having a hard time understanding the interaction between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, I'm going to follow up on this as I use this feature all the time and would love moonraker to not freak out about a dirty repo. Having just read through it, In the callback function, the Happy to split it up into multiple statements, but it would just be the same statement on the second line. |
||
| speed = self.enabled_fan_speed | ||
| if speed != self.last_speed: | ||
| self.last_speed = speed | ||
| curtime = self.printer.get_reactor().monotonic() | ||
| print_time = self.fan.get_mcu().estimated_print_time(curtime) | ||
| self.fan.set_speed(print_time + PIN_MIN_TIME, speed) | ||
| return eventtime + 1.0 | ||
|
|
||
| # SET_FAN_SPEED can only override this fan speed to a speed higher than the minimum one set by the heater | ||
| def cmd_SET_FAN_SPEED(self, gcmd): | ||
| self.last_gcode_speed = gcmd.get_float("SPEED", 0.0) | ||
| speed = max(self.last_speed, self.last_gcode_speed) | ||
| self.fan.set_speed_from_command(speed) | ||
|
|
||
|
|
||
| def load_config_prefix(config): | ||
| return PrinterHeaterFan(config) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably needs to be reflowed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by reflowed here? (apologies for the ignorance)