diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-04-20 21:41:13 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-04-20 22:24:36 -0400 |
commit | d5dc6b785d27572cee09c087417fef0ff2836af9 (patch) | |
tree | 80c90022f29ea237c57f005c63cdc36c5ec25cbd /klippy/extras | |
parent | 8f4f5da11c1a6a1a80e4b02c9775b9154cb688a2 (diff) | |
download | kutter-d5dc6b785d27572cee09c087417fef0ff2836af9.tar.gz kutter-d5dc6b785d27572cee09c087417fef0ff2836af9.tar.xz kutter-d5dc6b785d27572cee09c087417fef0ff2836af9.zip |
gcode: Add minval/maxval/above/below options to get_X parsers
Add value checking to gcode parameter parsing code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras')
-rw-r--r-- | klippy/extras/output_pin.py | 5 | ||||
-rw-r--r-- | klippy/extras/virtual_sdcard.py | 2 |
2 files changed, 3 insertions, 4 deletions
diff --git a/klippy/extras/output_pin.py b/klippy/extras/output_pin.py index eda2ad2b..302e90e8 100644 --- a/klippy/extras/output_pin.py +++ b/klippy/extras/output_pin.py @@ -49,14 +49,13 @@ class PrinterOutputPin: return pin.cmd_SET_PIN(params) if self.is_static: raise self.gcode.error("Static pin can not be changed at run-time") - value = self.gcode.get_float('VALUE', params) / self.scale + value = self.gcode.get_float('VALUE', params, minval=0., maxval=1.) + value /= self.scale if value == self.last_value: return print_time = self.printer.lookup_object('toolhead').get_last_move_time() print_time = max(print_time, self.last_value_time + PIN_MIN_TIME) if self.is_pwm: - if value < 0. or value > 1.: - raise self.gcode.error("Invalid pin value") self.mcu_pin.set_pwm(print_time, value) else: if value not in [0., 1.]: diff --git a/klippy/extras/virtual_sdcard.py b/klippy/extras/virtual_sdcard.py index dd4b686d..1d0eaf15 100644 --- a/klippy/extras/virtual_sdcard.py +++ b/klippy/extras/virtual_sdcard.py @@ -102,7 +102,7 @@ class VirtualSD: # Set SD position if self.work_timer is not None: raise self.gcode.error("SD busy") - pos = self.gcode.get_int('S', params) + pos = self.gcode.get_int('S', params, minval=0) self.file_position = pos def cmd_M27(self, params): # Report SD print status |