[RF69] Replaced RSSI member variable with getRSSI method

This commit is contained in:
jgromes 2020-04-14 15:02:33 +02:00
parent e9f879aea6
commit 9f8ec689dd
4 changed files with 25 additions and 10 deletions

View file

@ -68,6 +68,12 @@ void loop() {
Serial.print(F("[RF69] Data:\t\t")); Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str); Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[RF69] RSSI:\t\t"));
Serial.print(rf.getRSSI());
Serial.println(F(" dBm"));
} else if (state == ERR_RX_TIMEOUT) { } else if (state == ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet // timeout occurred while waiting for a packet
Serial.println(F("timeout!")); Serial.println(F("timeout!"));

View file

@ -112,9 +112,15 @@ void loop() {
Serial.println(F("[RF69] Received packet!")); Serial.println(F("[RF69] Received packet!"));
// print data of the packet // print data of the packet
Serial.print(F("[RF69] Data:\t\t\t")); Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str); Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[RF69] RSSI:\t\t"));
Serial.print(rf.getRSSI());
Serial.println(F(" dBm"));
} else if (state == ERR_CRC_MISMATCH) { } else if (state == ERR_CRC_MISMATCH) {
// packet was received, but is malformed // packet was received, but is malformed
Serial.println(F("CRC error!")); Serial.println(F("CRC error!"));

View file

@ -147,7 +147,7 @@ int16_t RF69::receive(uint8_t* data, size_t len) {
uint32_t start = micros(); uint32_t start = micros();
while(!digitalRead(_mod->getIrq())) { while(!digitalRead(_mod->getIrq())) {
yield(); yield();
if(micros() - start > timeout) { if(micros() - start > timeout) {
standby(); standby();
clearIRQFlags(); clearIRQFlags();
@ -330,9 +330,6 @@ int16_t RF69::readData(uint8_t* data, size_t len) {
// read packet data // read packet data
_mod->SPIreadRegisterBurst(RF69_REG_FIFO, length, data); _mod->SPIreadRegisterBurst(RF69_REG_FIFO, length, data);
// update RSSI
lastPacketRSSI = -1.0 * (_mod->SPIgetRegValue(RF69_REG_RSSI_VALUE)/2.0);
// clear internal flag so getPacketLength can return the new packet length // clear internal flag so getPacketLength can return the new packet length
_packetLengthQueried = false; _packetLengthQueried = false;
@ -701,6 +698,10 @@ int16_t RF69::setEncoding(uint8_t encoding) {
} }
} }
float RF69::getRSSI() {
return(-1.0 * (_mod->SPIgetRegValue(RF69_REG_RSSI_VALUE)/2.0));
}
int16_t RF69::config() { int16_t RF69::config() {
int16_t state = ERR_NONE; int16_t state = ERR_NONE;

View file

@ -441,11 +441,6 @@ class RF69: public PhysicalLayer {
*/ */
RF69(Module* module); RF69(Module* module);
/*!
\brief RSSI value of the last received packet.
*/
float lastPacketRSSI;
// basic methods // basic methods
/*! /*!
@ -791,6 +786,13 @@ class RF69: public PhysicalLayer {
*/ */
int16_t setEncoding(uint8_t encoding); int16_t setEncoding(uint8_t encoding);
/*!
\brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
\returns Last packet RSSI in dBm.
*/
float getRSSI();
#ifndef RADIOLIB_GODMODE #ifndef RADIOLIB_GODMODE
protected: protected:
#endif #endif