Closed n8many closed 6 years ago
Just realized what you were doing with that xor operation, which achieves the same purpose but with an offset. Both work equally well when only dealing with relative values.
Take your pick on closing or merging.
Will take a look at this during this weekend.
@n8many I might reject this pull request because the library is supposed to be just an interface to the IC's protocol, not an implementation. That's up to each user. So, I'll think about it but I'll be glad to here any comments from you.
Sorry for the delay.
Yeah, looking back at it, I agree. Thanks for looking at it!
@n8many Your fix was actually necessary. I used a different approach cause I only saw this closed request just now. I didn't quite understand Two's Complement back when we talked. Sorry!
The sensor outputs 2's complement data according to the data sheet p.3 and it does not look like the library currently follows that.
To account for this, the code checks if the first bit is 1 (meaning a negative number). If so, it changes the most significant byte from 0x00 to 0xFF. It then tells numpy to interpret the array as an int32 rather than a uint32 so that we don't have to do any of the 2's complement math.
This replaces the line where you flip the most significant bit of the number.
*As a note, this is going to significantly change the output of the sensor going forward, so anyone who has hardcoded offset values from prior to this pull request will have to recalculate them using this equation:
new_offset = old_offset -8388608