max31855: temperatures can be negative

This commit is contained in:
Andrey Gusakov 2024-03-10 11:42:19 +03:00 committed by rusefillc
parent 59cb0db66a
commit 8b63ff269e
1 changed files with 10 additions and 2 deletions

View File

@ -215,12 +215,20 @@ private:
float packetGetTemperature(uint32_t packet) {
// bits 31:18, 0.25C resolution (1/4 C)
return ((float)(packet >> 18) / 4.0);
int16_t tmp = (packet >> 18) & 0x3fff;
/* extend sign */
tmp = tmp << 2;
tmp = tmp >> 2; /* shifting right signed is not a good idea */
return (float) tmp * 0.25;
}
float packetGetRefTemperature(uint32_t packet) {
// bits 15:4, 0.0625C resolution (1/16 C)
return ((float)((packet & 0xFFF0) >> 4) / 16.0);
int16_t tmp = (packet >> 4) & 0xfff;
/* extend sign */
tmp = tmp << 4;
tmp = tmp >> 4; /* shifting right signed is not a good idea */
return (float)tmp * 0.0625;
}
max_31855_code getMax31855EgtValue(size_t egtChannel, float *temp, float *refTemp) {