LoRa: Enable LowDataRateOptimize for symbol length >16ms

This commit is contained in:
tomelec 2019-10-14 23:16:30 +02:00
parent 1275c5876d
commit 7f2663366e
2 changed files with 18 additions and 0 deletions

View File

@ -418,6 +418,8 @@ void LoRaClass::setSpreadingFactor(int sf)
}
writeRegister(REG_MODEM_CONFIG_2, (readRegister(REG_MODEM_CONFIG_2) & 0x0f) | ((sf << 4) & 0xf0));
handleLowDataRate();
}
long LoRaClass::getSignalBandwidth()
@ -437,6 +439,18 @@ long LoRaClass::getSignalBandwidth()
}
}
void LoRaClass::handleLowDataRate(){
int sf = (readRegister(REG_MODEM_CONFIG_2) >> 4);
if ( long( (1<<sf) / (getSignalBandwidth()/1000)) > 16) {
// set auto AGC and LowDataRateOptimize
writeRegister(REG_MODEM_CONFIG_3, (1<<3)|(1<<2));
}
else {
// set auto AGC
writeRegister(REG_MODEM_CONFIG_3, (1<<2));
}
}
void LoRaClass::setSignalBandwidth(long sbw)
{
int bw;
@ -464,6 +478,8 @@ void LoRaClass::setSignalBandwidth(long sbw)
}
writeRegister(REG_MODEM_CONFIG_1, (readRegister(REG_MODEM_CONFIG_1) & 0x0f) | (bw << 4));
handleLowDataRate();
}
void LoRaClass::setCodingRate4(int denominator)

2
LoRa.h
View File

@ -82,6 +82,8 @@ private:
static void onDio0Rise();
void handleLowDataRate();
private:
SPISettings _spiSettings;
int _ss;