mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 10:36:01 +00:00
[bmp581_base][bl0906] Fix 24-bit sign extension bugs (#14558)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
0469612d07
commit
4f4b2bfdec
@@ -10,7 +10,9 @@ static const char *const TAG = "bl0906";
|
||||
|
||||
constexpr uint32_t to_uint32_t(ube24_t input) { return input.h << 16 | input.m << 8 | input.l; }
|
||||
|
||||
constexpr int32_t to_int32_t(sbe24_t input) { return input.h << 16 | input.m << 8 | input.l; }
|
||||
constexpr int32_t to_int32_t(sbe24_t input) {
|
||||
return static_cast<int32_t>(encode_uint32((uint8_t) input.h, input.m, input.l, 0)) >> 8;
|
||||
}
|
||||
|
||||
// The SUM byte is (Addr+Data_L+Data_M+Data_H)&0xFF negated;
|
||||
constexpr uint8_t bl0906_checksum(const uint8_t address, const DataPacket *data) {
|
||||
|
||||
@@ -429,7 +429,7 @@ bool BMP581Component::read_temperature_(float &temperature) {
|
||||
}
|
||||
|
||||
// temperature MSB is in data[2], LSB is in data[1], XLSB in data[0]
|
||||
int32_t raw_temp = (int32_t) data[2] << 16 | (int32_t) data[1] << 8 | (int32_t) data[0];
|
||||
int32_t raw_temp = static_cast<int32_t>(encode_uint32(data[2], data[1], data[0], 0)) >> 8;
|
||||
temperature = (float) (raw_temp / 65536.0); // convert measurement to degrees Celsius (page 22 of datasheet)
|
||||
|
||||
return true;
|
||||
@@ -458,7 +458,7 @@ bool BMP581Component::read_temperature_and_pressure_(float &temperature, float &
|
||||
}
|
||||
|
||||
// temperature MSB is in data[2], LSB is in data[1], XLSB in data[0]
|
||||
int32_t raw_temp = (int32_t) data[2] << 16 | (int32_t) data[1] << 8 | (int32_t) data[0];
|
||||
int32_t raw_temp = static_cast<int32_t>(encode_uint32(data[2], data[1], data[0], 0)) >> 8;
|
||||
temperature = (float) (raw_temp / 65536.0); // convert measurement to degrees Celsius (page 22 of datasheet)
|
||||
|
||||
// pressure MSB is in data[5], LSB is in data[4], XLSB in data[3]
|
||||
|
||||
Reference in New Issue
Block a user