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

add api for setting fan speeds & auto step recovery #56

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions bambulabs_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,53 @@ def skip_objects(self, obj_list: list[int]) -> bool:
bool: if publish command is successful
"""
return self.__printerMQTTClient.skip_objects(obj_list=obj_list)

def set_part_fan_speed(self, speed: int | float) -> bool:
"""
Set the fan speed of the part fan

Args:
speed (int | float): The speed to set the part fan

Returns:
bool: success of setting the fan speed
"""
return self.__printerMQTTClient.set_part_fan_speed(speed)

def set_aux_fan_speed(self, speed: int | float) -> bool:
"""
Set the fan speed of the aux part fan

Args:
speed (int | float): The speed to set the part fan

Returns:
bool: success of setting the fan speed
"""
return self.__printerMQTTClient.set_aux_fan_speed(speed)

def set_chamber_fan_speed(self, speed: int | float) -> bool:
"""
Set the fan speed of the chamber fan

Args:
speed (int | float): The speed to set the part fan

Returns:
bool: success of setting the fan speed
"""
return self.__printerMQTTClient.set_chamber_fan_speed(speed)

def set_auto_step_recovery(self, auto_step_recovery: bool = True) -> bool:
"""
Set whether or not to set auto step recovery

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Args

Args:
auto_step_recovery (bool): flag to set auto step recovery.
Default True.

Returns:
bool: success of the auto step recovery command command
"""
return self.__printerMQTTClient.set_auto_step_recovery(
auto_step_recovery)
75 changes: 75 additions & 0 deletions bambulabs_api/mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,66 @@ def set_bed_temperature(self, temperature: int) -> bool:
"""
return self.__send_gcode_line(f"M140 S{temperature}\n")

def set_part_fan_speed(self, speed: int | float) -> bool:
"""
Set the fan speed of the part fan

Args:
speed (int | float): The speed to set the part fan

Returns:
bool: success of setting the fan speed
"""
return self._set_fan_speed(speed, 1)

def set_aux_fan_speed(self, speed: int | float) -> bool:
"""
Set the fan speed of the aux part fan

Args:
speed (int | float): The speed to set the part fan

Returns:
bool: success of setting the fan speed
"""
return self._set_fan_speed(speed, 2)

def set_chamber_fan_speed(self, speed: int | float) -> bool:
"""
Set the fan speed of the chamber fan

Args:
speed (int | float): The speed to set the part fan

Returns:
bool: success of setting the fan speed
"""
return self._set_fan_speed(speed, 3)

def _set_fan_speed(self, speed: int | float, fan_num: int) -> bool:
"""
Set the fan speed of a fan

Args:
speed (int | float): The speed to set the fan to
fan_num (int): Id of the fan to be set

Returns:
bool: success of setting the fan speed
"""
if isinstance(speed, int):
if speed > 255 or speed < 0:
raise ValueError(f"Fan Speed {speed} is not between 0 and 255")
return self.__send_gcode_line(f"M106 P{fan_num} S{speed}\n")

elif isinstance(speed, float):
if speed < 0 or speed > 1:
raise ValueError(f"Fan Speed {speed} is not between 0 and 1")
speed = round(255 / speed)
return self.__send_gcode_line(f"M106 P{fan_num} S{speed}\n")

raise ValueError("Fan Speed is not float or int")

def set_bed_height(self, height: int) -> bool:
"""
Set the absolute height of the bed (Z-axis).
Expand All @@ -353,6 +413,21 @@ def auto_home(self) -> bool:
"""
return self.__send_gcode_line("G28\n")

def set_auto_step_recovery(self, auto_step_recovery: bool = True) -> bool:
"""
Set whether or not to set auto step recovery

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Args

Args:
auto_step_recovery (bool): flag to set auto step recovery.
Default True.

Returns:
bool: success of the auto step recovery command command
"""
return self.__publish_command({"print": {
"command": "gcode_line", "auto_recovery": auto_step_recovery
}})

def set_print_speed_lvl(self, speed_lvl: int = 1) -> bool:
"""
Set the print speed
Expand Down