From cb879ea97f1302543a8156f0cbda972f6a9b15b6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 13 Jun 2023 23:25:44 +0200 Subject: [PATCH] tmp sign bugfix --- mission/tcs/Tmp1075Handler.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mission/tcs/Tmp1075Handler.cpp b/mission/tcs/Tmp1075Handler.cpp index df57aa8a..054b2118 100644 --- a/mission/tcs/Tmp1075Handler.cpp +++ b/mission/tcs/Tmp1075Handler.cpp @@ -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((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(tempValueRaw)) * 0.0625); #if OBSW_DEBUG_TMP1075 == 1 sif::info << "Tmp1075 with object id: 0x" << std::hex << getObjectId()