diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2021-03-26 11:37:40 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-03-26 11:37:40 -0400 |
commit | d02c80ef08167522a8b9b94e725afff0c680b12b (patch) | |
tree | fd3b2b032fe3edef73fef60ea90ff65fd733c0c3 | |
parent | 861144d8845bb6ea43591d8e2c10c342fef5596c (diff) | |
download | kutter-d02c80ef08167522a8b9b94e725afff0c680b12b.tar.gz kutter-d02c80ef08167522a8b9b94e725afff0c680b12b.tar.xz kutter-d02c80ef08167522a8b9b94e725afff0c680b12b.zip |
output_pin: Make sure to not use a cycle_time or max_duration over 5 seconds
Times longer than 5 seconds may result in a 32bit ticks overflow in
the micro-controller (for fast micro-controllers).
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | klippy/extras/output_pin.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/klippy/extras/output_pin.py b/klippy/extras/output_pin.py index 74e5c1b1..3d6a6772 100644 --- a/klippy/extras/output_pin.py +++ b/klippy/extras/output_pin.py @@ -1,11 +1,12 @@ # Code to configure miscellaneous chips # -# Copyright (C) 2017-2020 Kevin O'Connor <kevin@koconnor.net> +# Copyright (C) 2017-2021 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. PIN_MIN_TIME = 0.100 RESEND_HOST_TIME = 0.300 + PIN_MIN_TIME +MAX_SCHEDULE_TIME = 5.0 class PrinterOutputPin: def __init__(self, config): @@ -14,7 +15,8 @@ class PrinterOutputPin: self.is_pwm = config.getboolean('pwm', False) if self.is_pwm: self.mcu_pin = ppins.setup_pin('pwm', config.get('pin')) - cycle_time = config.getfloat('cycle_time', 0.100, above=0.) + cycle_time = config.getfloat('cycle_time', 0.100, above=0., + maxval=MAX_SCHEDULE_TIME) hardware_pwm = config.getboolean('hardware_pwm', False) self.mcu_pin.setup_cycle_time(cycle_time, hardware_pwm) self.scale = config.getfloat('scale', 1., above=0.) @@ -35,8 +37,9 @@ class PrinterOutputPin: self.mcu_pin.setup_start_value( self.last_value, self.last_value, True) else: - max_mcu_duration = config.getfloat('maximum_mcu_duration', - 0., minval=0.500) + max_mcu_duration = config.getfloat('maximum_mcu_duration', 0., + minval=0.500, + maxval=MAX_SCHEDULE_TIME) self.mcu_pin.setup_max_duration(max_mcu_duration) self.resend_interval = max_mcu_duration - RESEND_HOST_TIME @@ -72,7 +75,7 @@ class PrinterOutputPin: value = gcmd.get_float('VALUE', minval=0., maxval=self.scale) value /= self.scale cycle_time = gcmd.get_float('CYCLE_TIME', self.default_cycle_time, - above=0.) + above=0., maxval=MAX_SCHEDULE_TIME) if not self.is_pwm and value not in [0., 1.]: raise gcmd.error("Invalid pin value") toolhead = self.printer.lookup_object('toolhead') |