[ld2410/ld2412] Fix two_byte_to_int using signed char causing incorrect values

The two_byte_to_int() function used `char` parameters instead of
`uint8_t`, causing sign extension for byte values >= 0x80. This
produced incorrect sensor values for distances where value % 256 >= 128
(e.g. 128cm reported as -128, 200cm reported as -56).

Also removed the unnecessary `(int16_t)` cast and switched from `+` to
`|` for proper bitwise assembly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
J. Nick Koston
2026-02-28 08:48:18 -10:00
co-authored by Claude Opus 4.6
parent 757e8d90e6
commit 76690e6900
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -173,7 +173,7 @@ static constexpr uint8_t DATA_FRAME_FOOTER[HEADER_FOOTER_SIZE] = {0xF8, 0xF7, 0x
// MAC address the module uses when Bluetooth is disabled
static constexpr uint8_t NO_MAC[] = {0x08, 0x05, 0x04, 0x03, 0x02, 0x01};
static inline int two_byte_to_int(char firstbyte, char secondbyte) { return (int16_t) (secondbyte << 8) + firstbyte; }
static inline int two_byte_to_int(uint8_t firstbyte, uint8_t secondbyte) { return (secondbyte << 8) | firstbyte; }
static inline bool validate_header_footer(const uint8_t *header_footer, const uint8_t *buffer) {
return std::memcmp(header_footer, buffer, HEADER_FOOTER_SIZE) == 0;
+1 -1
View File
@@ -192,7 +192,7 @@ static constexpr uint8_t DATA_FRAME_FOOTER[HEADER_FOOTER_SIZE] = {0xF8, 0xF7, 0x
// MAC address the module uses when Bluetooth is disabled
static constexpr uint8_t NO_MAC[] = {0x08, 0x05, 0x04, 0x03, 0x02, 0x01};
static inline int two_byte_to_int(char firstbyte, char secondbyte) { return (int16_t) (secondbyte << 8) + firstbyte; }
static inline int two_byte_to_int(uint8_t firstbyte, uint8_t secondbyte) { return (secondbyte << 8) | firstbyte; }
static inline bool validate_header_footer(const uint8_t *header_footer, const uint8_t *buffer) {
return std::memcmp(header_footer, buffer, HEADER_FOOTER_SIZE) == 0;