From 74244ab0eb43d4472c34eaf6decb95e9bc146641 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 1 Feb 2021 10:34:08 -0500 Subject: [PATCH] spi_temperature: Improve handling of min_temp/max_temp overflows Signed-off-by: Kevin O'Connor --- klippy/extras/spi_temperature.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/klippy/extras/spi_temperature.py b/klippy/extras/spi_temperature.py index b6f33a9a..31efea58 100644 --- a/klippy/extras/spi_temperature.py +++ b/klippy/extras/spi_temperature.py @@ -145,7 +145,7 @@ class MAX31856(SensorBase): return temp def calc_adc(self, temp): adc = int( ( temp / MAX31856_MULT ) + 0.5 ) # convert to ADC value - adc = adc << MAX31856_SCALE + adc = max(0, min(0x3FFFF, adc)) << MAX31856_SCALE return adc def build_spi_init(self, config): cmds = [] @@ -207,7 +207,7 @@ class MAX31855(SensorBase): return temp def calc_adc(self, temp): adc = int( ( temp / MAX31855_MULT ) + 0.5 ) # convert to ADC value - adc = adc << MAX31855_SCALE + adc = max(0, min(0x1FFF, adc)) << MAX31855_SCALE return adc @@ -234,7 +234,7 @@ class MAX6675(SensorBase): return temp def calc_adc(self, temp): adc = int( ( temp / MAX6675_MULT ) + 0.5 ) # convert to ADC value - adc = adc << MAX6675_SCALE + adc = max(0, min(0x1FFF, adc)) << MAX6675_SCALE return adc