chandrawi / LoRaRF-Arduino

Arduino library for basic transmitting and receiving data using LoRa and FSK modulation
MIT License
53 stars 15 forks source link

setTxPower fails for low power values on SX1262 #16

Open boletbo opened 1 year ago

boletbo commented 1 year ago

I've been testing your library on a SX1262 and I've seen that method 'setTxPower' fails for values lower than 14dBm. I'm new at programming but I think that, on file "SX126x.cpp" -> void SX126x::setTxPower(uint8_t txPower, uint8_t version), there is a problem: ... } else if (txPower >= 14 && version == SX126X_TX_POWER_SX1261) { paDutyCycle = 0x04; hpMax = 0x00; power = 0x0E; } else if (txPower >= 14 && version == SX126X_TX_POWER_SX1262) { paDutyCycle = 0x02; hpMax = 0x02; power = 0x16; } else if (txPower >= 14 && version == SX126X_TX_POWER_SX1268) { paDutyCycle = 0x04; hpMax = 0x06; power = 0x0F; } else if (txPower >= 10 && version == SX126X_TX_POWER_SX1261) { paDutyCycle = 0x01; hpMax = 0x00; power = 0x0D; } else if (txPower >= 10 && version == SX126X_TX_POWER_SX1268) { paDutyCycle = 0x00; hpMax = 0x03; power = 0x0F; } else { return; } ... If txPower < 14 && version == SX126X_TX_POWER_SX1262, the method 'returns' and doesn't set de PAConfig values correctly.

chandrawi commented 1 year ago

Yeah, you are correct. It must be no immediate return. Delete the else block will fix the issue. Feel free to fix this bug and open pull request. I will accept immediately and include the fix in the next release.