jgromes / RadioLib

Universal wireless communication library for embedded devices
https://jgromes.github.io/RadioLib/
MIT License
1.56k stars 389 forks source link

SX1261 uses incorrect PA config by default #599

Closed matthijskooijman closed 2 years ago

matthijskooijman commented 2 years ago

Describe the bug This is a bug that I noticed while reading code. I haven't actually reproduced this bug (I do not have applicable hardware read), but I'm pretty confident it exists.

The problem is that SX1261 (which extends SX1262) overrides setOutputPower with its own version that applies the 1261 PA config instead of the 1262 PA config. When the sketch explicitely calls setOutputPower on the SX1261 object, the right version is used and everything is ok. But on startup, SX1262::begin() applies the default output power by calling setOutputPower(). Since that is not a virtual method, this means that call is statically resolved to call SX1262::setOutputPower(), not SX1261::setOutputPower(), applying the wrong values.

A fix could be to make this method virtual in SX1262, or to override the begin() method in SX1261 to call the right method (after the incorrect method), or maybe pass the right settings from SX1261 to SX1262 in some other way.

jgromes commented 2 years ago

Well spotted, thanks! You're correct, this is indeed not behaving correctly.

I think having SX1262::setOutputPower() virtual is the easiest solution.