[SX128x] Merge pull request from Jorropo/fix-signed-ranging-result

fix getRangingResult to properly account for signed numbers
This commit is contained in:
Jan Gromeš 2024-09-07 08:46:52 +02:00 committed by GitHub
commit 885a921ea3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -176,7 +176,8 @@ float SX1280::getRangingResult() {
RADIOLIB_ASSERT(state);
// calculate the real result
uint32_t raw = ((uint32_t)data[0] << 16) | ((uint32_t)data[1] << 8) | data[2];
uint32_t uraw = ((uint32_t)data[0] << 16) | ((uint32_t)data[1] << 8) | data[2];
int32_t raw = (uraw & ((1<<23) - 1)) | (uraw >> 23 << 31);
return((float)raw * 150.0 / (4.096 * this->bandwidthKhz));
}