[SX128x] Add getRangingResultRaw method (#1605)

master
jgromes 2025-10-28 07:39:38 +00:00
rodzic 79187ce080
commit f6b007403d
3 zmienionych plików z 21 dodań i 3 usunięć

Wyświetl plik

@ -308,6 +308,7 @@ range KEYWORD2
startRanging KEYWORD2
finishRanging KEYWORD2
getRangingResult KEYWORD2
getRangingResultRaw KEYWORD2
# Hellschreiber
printGlyph KEYWORD2

Wyświetl plik

@ -152,7 +152,16 @@ int16_t SX1280::finishRanging() {
return(setPacketParamsLoRa(this->preambleLengthLoRa, this->headerType, this->payloadLen, this->crcLoRa));
}
int32_t SX1280::getRangingResultRaw() {
return(getRangingResultCommon(false));
}
float SX1280::getRangingResult() {
int32_t raw = getRangingResultCommon(true);
return((float)raw * 150.0f / (4.096f * this->bandwidthKhz));
}
int32_t SX1280::getRangingResultCommon(bool filtered) {
// set mode to standby XOSC
int16_t state = standby(RADIOLIB_SX128X_STANDBY_XOSC);
RADIOLIB_ASSERT(state);
@ -171,7 +180,7 @@ float SX1280::getRangingResult() {
RADIOLIB_ASSERT(state);
data[0] &= 0xCF;
data[0] |= (1 << 4);
data[0] |= ((uint8_t)filtered << 4);
state = writeRegister(RADIOLIB_SX128X_REG_RANGING_TYPE, data, 1);
RADIOLIB_ASSERT(state);
@ -187,10 +196,10 @@ float SX1280::getRangingResult() {
state = standby();
RADIOLIB_ASSERT(state);
// calculate the real result
// convert to signed
uint32_t uraw = ((uint32_t)data[0] << 16) | ((uint32_t)data[1] << 8) | data[2];
int32_t raw = (uraw & ((1UL << 23) - 1)) | (uraw >> 23 << 31);
return((float)raw * 150.0f / (4.096f * this->bandwidthKhz));
return(raw);
}
#endif

Wyświetl plik

@ -51,10 +51,18 @@ class SX1280: public SX1281 {
*/
float getRangingResult();
/*!
\brief Gets ranging result of the last ranging exchange.
\returns Ranging result in arbitrary raw units. For conversion to meters,
see SX1280 datasheet, or use the getRangingResult method.
*/
int32_t getRangingResultRaw();
#if !RADIOLIB_GODMODE
private:
#endif
int32_t getRangingResultCommon(bool filtered);
};
#endif