diff --git a/avrrfm.c b/avrrfm.c index 0efbdf2..482b012 100644 --- a/avrrfm.c +++ b/avrrfm.c @@ -194,7 +194,7 @@ if (len > 0) { // receiver RSSI int8_t rssi = divRoundNearest(response[0], 2); - printUint(rssi); + setOutputPower(rssi); } } diff --git a/rfm69.c b/rfm69.c index 5ad3515..b317136 100644 --- a/rfm69.c +++ b/rfm69.c @@ -183,6 +183,16 @@ printString("Radio init done\r\n"); } +void setOutputPower(uint8_t rssi) { + uint8_t pa = 0x40; // -18 dBm with PA1 + if (rssi > 0 && rssi <= 40) pa += 16; + if (rssi > 40 && rssi <= 60) pa += 21; + if (rssi > 60 && rssi <= 90) pa += 26; + if (rssi > 90) pa += 31; + + regWrite(PA_LEVEL, pa); +} + void timeoutRadio(void) { irqFlags1 |= (1 << 2); } diff --git a/rfm69.h b/rfm69.h index e6b2d96..8a128df 100644 --- a/rfm69.h +++ b/rfm69.h @@ -84,6 +84,13 @@ void initRadio(uint64_t freq, uint8_t node); /** + * Sets the output power based on the given receiver RSSI. + * + * @param rssi + */ +void setOutputPower(uint8_t rssi); + +/** * Indicates a timeout. */ void timeoutRadio(void);