mirror of
https://github.com/esphome/esphome.git
synced 2026-06-02 19:18:20 +08:00
[sensirion_common] Fix incorrect Big Endian conversion (#13492)
This commit is contained in:
@@ -57,24 +57,14 @@ bool SensirionI2CDevice::write_command_(uint16_t command, CommandLen command_len
|
|||||||
temp[raw_idx++] = command & 0xFF;
|
temp[raw_idx++] = command & 0xFF;
|
||||||
} else {
|
} else {
|
||||||
// command is 2 bytes
|
// command is 2 bytes
|
||||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
||||||
temp[raw_idx++] = command >> 8;
|
temp[raw_idx++] = command >> 8;
|
||||||
temp[raw_idx++] = command & 0xFF;
|
temp[raw_idx++] = command & 0xFF;
|
||||||
#else
|
|
||||||
temp[raw_idx++] = command & 0xFF;
|
|
||||||
temp[raw_idx++] = command >> 8;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
// add parameters followed by crc
|
// add parameters followed by crc
|
||||||
// skipped if len == 0
|
// skipped if len == 0
|
||||||
for (size_t i = 0; i < data_len; i++) {
|
for (size_t i = 0; i < data_len; i++) {
|
||||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
||||||
temp[raw_idx++] = data[i] >> 8;
|
temp[raw_idx++] = data[i] >> 8;
|
||||||
temp[raw_idx++] = data[i] & 0xFF;
|
temp[raw_idx++] = data[i] & 0xFF;
|
||||||
#else
|
|
||||||
temp[raw_idx++] = data[i] & 0xFF;
|
|
||||||
temp[raw_idx++] = data[i] >> 8;
|
|
||||||
#endif
|
|
||||||
// Use MSB first since Sensirion devices use CRC-8 with MSB first
|
// Use MSB first since Sensirion devices use CRC-8 with MSB first
|
||||||
uint8_t crc = crc8(&temp[raw_idx - 2], 2, 0xFF, CRC_POLYNOMIAL, true);
|
uint8_t crc = crc8(&temp[raw_idx - 2], 2, 0xFF, CRC_POLYNOMIAL, true);
|
||||||
temp[raw_idx++] = crc;
|
temp[raw_idx++] = crc;
|
||||||
|
|||||||
Reference in New Issue
Block a user