aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/mcu.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-09-05 18:19:36 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-09-05 18:22:21 -0400
commit36de6118c159638c5f1e77ad554d3488884ebb48 (patch)
treefeb2d6379553316c6d6dc5115652126163cb0721 /klippy/mcu.py
parent7083a33ecd1cdcf5402cccbdb53f56cdfaf80f5e (diff)
downloadkutter-36de6118c159638c5f1e77ad554d3488884ebb48.tar.gz
kutter-36de6118c159638c5f1e77ad554d3488884ebb48.tar.xz
kutter-36de6118c159638c5f1e77ad554d3488884ebb48.zip
mcu: Limit ADC min/max range to a 16bit integer
Make sure the ADC range sent to the MCU can be encoded into a 16bit integer. Otherwise, if the provided min_temp/max_temp was outside the range of possible values it could result in a spurious mcu shutdown. In particular, the AD595 could not properly encode a min_temp of zero. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/mcu.py')
-rw-r--r--klippy/mcu.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/klippy/mcu.py b/klippy/mcu.py
index c72b4ee8..7724e63e 100644
--- a/klippy/mcu.py
+++ b/klippy/mcu.py
@@ -396,8 +396,9 @@ class MCU_adc:
max_adc = self._sample_count * mcu_adc_max
self._inv_max_adc = 1.0 / max_adc
self._report_clock = int(self._report_time * self._mcu_freq)
- min_sample = int(self._min_sample * max_adc)
- max_sample = min(0xffff, int(math.ceil(self._max_sample * max_adc)))
+ min_sample = max(0, min(0xffff, int(self._min_sample * max_adc)))
+ max_sample = max(0, min(0xffff, int(
+ math.ceil(self._max_sample * max_adc))))
self._mcu.add_config_cmd(
"query_analog_in oid=%d clock=%d sample_ticks=%d sample_count=%d"
" rest_ticks=%d min_value=%d max_value=%d" % (