Skip to content

Commit

Permalink
add api for setting the fan speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmdelta committed Oct 27, 2024
1 parent 502665f commit d0e38db
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
36 changes: 36 additions & 0 deletions bambulabs_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,39 @@ 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)
60 changes: 60 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 Down

0 comments on commit d0e38db

Please sign in to comment.