aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-02-01 10:34:08 -0500
committerKevin O'Connor <kevin@koconnor.net>2021-02-01 10:37:19 -0500
commit74244ab0eb43d4472c34eaf6decb95e9bc146641 (patch)
treeaf9e60d8fbbf22131d23c2bcddec97c63d0944c6
parent333f8c210fa70db53923660738dca118a3323064 (diff)
downloadkutter-74244ab0eb43d4472c34eaf6decb95e9bc146641.tar.gz
kutter-74244ab0eb43d4472c34eaf6decb95e9bc146641.tar.xz
kutter-74244ab0eb43d4472c34eaf6decb95e9bc146641.zip
spi_temperature: Improve handling of min_temp/max_temp overflows
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/extras/spi_temperature.py6
1 files 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