Skip to content

Commit 9b96b7f

Browse files
committed
Fixes for temperature conversion bugs issue #15.
1 parent 4f0eb51 commit 9b96b7f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

adafruit_amg88xx.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# Operating Modes
5555
# pylint: disable=bad-whitespace
5656
_NORMAL_MODE = const(0x00)
57-
_SLEEP_MODE = const(0x01)
57+
_SLEEP_MODE = const(0x10)
5858
_STAND_BY_60 = const(0x20)
5959
_STAND_BY_10 = const(0x21)
6060

@@ -86,10 +86,16 @@
8686
def _signed_12bit_to_float(val):
8787
#take first 11 bits as absolute val
8888
abs_val = (val & 0x7FF)
89-
if val & 0x8000:
89+
if val & 0x800:
9090
return 0 - float(abs_val)
9191
return float(abs_val)
9292

93+
def _twos_comp_to_float(val):
94+
val &= 0xfff
95+
if val & 0x800:
96+
val -= 0x1000
97+
return float(val)
98+
9399
class AMG88XX:
94100
"""Driver for the AMG88xx GRID-Eye IR 8x8 thermal camera."""
95101

@@ -161,6 +167,6 @@ def pixels(self):
161167
i2c.readinto(buf, start=1)
162168

163169
raw = (buf[2] << 8) | buf[1]
164-
retbuf[row][col] = _signed_12bit_to_float(raw) * _PIXEL_TEMP_CONVERSION
170+
retbuf[row][col] = _twos_comp_to_float(raw) * _PIXEL_TEMP_CONVERSION
165171

166172
return retbuf

0 commit comments

Comments
 (0)