tmp sign bugfix
This commit is contained in:
parent
20e920cde2
commit
cb879ea97f
@ -86,8 +86,15 @@ ReturnValue_t Tmp1075Handler::scanForReply(const uint8_t *start, size_t remainin
|
||||
ReturnValue_t Tmp1075Handler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||
switch (id) {
|
||||
case TMP1075::GET_TEMP: {
|
||||
int16_t tempValueRaw = 0;
|
||||
tempValueRaw = packet[0] << 4 | packet[1] >> 4;
|
||||
// Ignore the sign bit, subtract it later when applicable.
|
||||
int16_t tempValueRaw = static_cast<uint16_t>((packet[0] << 8) | packet[1]) & 0x7fff;
|
||||
// 12 bit value, so perform the shift for correct values.
|
||||
tempValueRaw >>= 4;
|
||||
if(((packet[0] >> 7) & 0b1) == 0b1) {
|
||||
// Perform two's complement by subtracting the sign
|
||||
tempValueRaw -= 0x800;
|
||||
}
|
||||
// 0.0625 is the sensor sensitivity.
|
||||
float tempValue = ((static_cast<float>(tempValueRaw)) * 0.0625);
|
||||
#if OBSW_DEBUG_TMP1075 == 1
|
||||
sif::info << "Tmp1075 with object id: 0x" << std::hex << getObjectId()
|
||||
|
Loading…
Reference in New Issue
Block a user