mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-23 22:54:10 -06:00
heater: Support max_power setting for heaters
Change the mcu PWM value from an integer (0-255) to a float (0. - 1.). Add support for limiting the maximum power (as measured over a sufficiently long duration) to a particular heater. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
54002c4391
commit
f53897758d
4 changed files with 40 additions and 29 deletions
|
@ -245,11 +245,12 @@ class MCU_digital_out:
|
|||
return self._last_value
|
||||
def set_pwm(self, mcu_time, value):
|
||||
dval = 0
|
||||
if value > 127:
|
||||
if value >= 0.5:
|
||||
dval = 1
|
||||
self.set_digital(mcu_time, dval)
|
||||
|
||||
class MCU_pwm:
|
||||
PWM_MAX = 255.
|
||||
def __init__(self, mcu, pin, cycle_ticks, max_duration, hard_pwm=True):
|
||||
self._mcu = mcu
|
||||
self._oid = mcu.create_oid()
|
||||
|
@ -272,6 +273,7 @@ class MCU_pwm:
|
|||
self.print_to_mcu_time = mcu.print_to_mcu_time
|
||||
def set_pwm(self, mcu_time, value):
|
||||
clock = int(mcu_time * self._mcu_freq)
|
||||
value = int(value * self.PWM_MAX + 0.5)
|
||||
msg = self._set_cmd.encode(self._oid, clock, value)
|
||||
self._mcu.send(msg, minclock=self._last_clock, reqclock=clock
|
||||
, cq=self._cmd_queue)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue