adafruit/Adafruit_CircuitPython_AMG88xx

Handling of negative pixel temperature values is incorrect

peterhinch opened this issue · 3 comments

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.

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.

A further bug - which won't have effect because sleep mode is currently unused - is

_SLEEP_MODE = const(0x01)

The value should be 0x10 (datasheet page 9).

huzzah! thank you @peterhinch :)