adafruit / Adafruit_CircuitPython_AMG88xx

circuit python driver from AMG88xx GRID-EYE 8x8 IR sensor
MIT License
38 stars 26 forks source link

Handling of negative pixel temperature values is incorrect #15

Closed peterhinch closed 5 years ago

peterhinch commented 5 years ago

The _signed_12bit_to_float function is correct for thermistor temperature readings which are in sign bit/absolute data format (datasheet page 13).

However datasheet page 14 indicates that pixel values are in two's complement format. This requires different handling.

I have no hardware (yet) so am not in a position to offer a tested PR.

peterhinch commented 5 years ago

On further review there is also an error in _signed_12bit_to_float which will fail to handle negative thermistor temperatures. It should read

def _signed_12bit_to_float(val):
    #take first 11 bits as absolute val
    abs_val = (val & 0x7FF)
    if val & 0x800:
        return 0 - float(abs_val)
    return float(abs_val)

i.e. the test for negative should be 0x800 not 0x8000.

peterhinch commented 5 years ago

A further bug - which won't have effect because sleep mode is currently unused - is https://github.com/adafruit/Adafruit_CircuitPython_AMG88xx/blob/4f0eb5173416bff73076781f865d96395a50bc51/adafruit_amg88xx.py#L57 The value should be 0x10 (datasheet page 9).

ladyada commented 5 years ago

huzzah! thank you @peterhinch :)