Handling of negative pixel temperature values is incorrect
peterhinch opened this issue · 3 comments
peterhinch commented
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
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
A further bug - which won't have effect because sleep mode is currently unused - is
The value should be 0x10 (datasheet page 9).
ladyada commented
huzzah! thank you @peterhinch :)