tmp sign bugfix

This commit is contained in:
Robin Müller 2023-06-13 23:25:44 +02:00
parent 20e920cde2
commit cb879ea97f
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814

View File

@ -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) { ReturnValue_t Tmp1075Handler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
switch (id) { switch (id) {
case TMP1075::GET_TEMP: { case TMP1075::GET_TEMP: {
int16_t tempValueRaw = 0; // Ignore the sign bit, subtract it later when applicable.
tempValueRaw = packet[0] << 4 | packet[1] >> 4; 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); float tempValue = ((static_cast<float>(tempValueRaw)) * 0.0625);
#if OBSW_DEBUG_TMP1075 == 1 #if OBSW_DEBUG_TMP1075 == 1
sif::info << "Tmp1075 with object id: 0x" << std::hex << getObjectId() sif::info << "Tmp1075 with object id: 0x" << std::hex << getObjectId()