diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index 8b7d9f112..5a1cce32a 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -67,7 +67,7 @@ bool RF95Interface::init() #endif setTransmitEnable(false); - int res = lora->begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength); + int res = lora->begin(getFreq(), bw, sf, cr, syncWord, power, currentLimit, preambleLength); DEBUG_MSG("RF95 init result %d\n", res); // current limit was removed from module' ctor @@ -119,7 +119,7 @@ bool RF95Interface::reconfigure() err = lora->setPreambleLength(preambleLength); assert(err == ERR_NONE); - err = lora->setFrequency(freq); + err = lora->setFrequency(getFreq()); if (err != ERR_NONE) RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 7551473c8..4bd352559 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -318,14 +318,14 @@ void RadioInterface::applyModemConfig() // If user has manually specified a channel num, then use that, otherwise generate one by hashing the name const char *channelName = channels.getName(channels.getPrimaryIndex()); int channel_num = channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelName) % myRegion->numChannels; - freq = myRegion->freq + radioConfig.preferences.frequency_offset + myRegion->spacing * channel_num; + float freq = myRegion->freq + radioConfig.preferences.frequency_offset + myRegion->spacing * channel_num; DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelName, channelSettings.modem_config, channel_num, power); DEBUG_MSG("Radio myRegion->freq: %f\n", myRegion->freq); DEBUG_MSG("Radio myRegion->spacing: %f\n", myRegion->spacing); DEBUG_MSG("Radio myRegion->numChannels: %d\n", myRegion->numChannels); DEBUG_MSG("Radio channel_num: %d\n", channel_num); - DEBUG_MSG("Radio frequency: %f\n", freq); + DEBUG_MSG("Radio frequency: %f\n", getFreq()); // the frequency could be overridden in RadioInterface::getFreq() for some modules DEBUG_MSG("Short packet time: %u msec\n", shortPacketMsec); saveChannelNum(channel_num); diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index c0d7ec2d1..542b575da 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -78,8 +78,6 @@ class RadioInterface void deliverToReceiver(MeshPacket *p); public: - float freq = 915.0; - /** pool is the pool we will alloc our rx packets from */ RadioInterface(); @@ -149,7 +147,7 @@ class RadioInterface /** * Get the frequency we saved. */ - float getFreq(); + virtual float getFreq(); /// Some boards (1st gen Pinetab Lora module) have broken IRQ wires, so we need to poll via i2c registers virtual bool isIRQPending() { return false; } diff --git a/src/mesh/SX1268Interface.h b/src/mesh/SX1268Interface.h index c4c98da0a..fb2239041 100644 --- a/src/mesh/SX1268Interface.h +++ b/src/mesh/SX1268Interface.h @@ -8,8 +8,8 @@ class SX1268Interface : public SX126xInterface { public: - /// Initializing the frequency of the SX1268 module regardless of the region - float freq = 433.0; + /// override frequency of the SX1268 module regardless of the region + virtual float getFreq() { return 433.0; } SX1268Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi); }; \ No newline at end of file diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index d4deef0f1..b0c48d55a 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -52,7 +52,7 @@ bool SX126xInterface::init() limitPower(); - int res = lora.begin(freq, bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage, useRegulatorLDO); + int res = lora.begin(getFreq(), bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage, useRegulatorLDO); // \todo Display actual typename of the adapter, not just `SX126x` DEBUG_MSG("SX126x init result %d\n", res); @@ -135,7 +135,7 @@ bool SX126xInterface::reconfigure() err = lora.setPreambleLength(preambleLength); assert(err == ERR_NONE); - err = lora.setFrequency(freq); + err = lora.setFrequency(getFreq()); if (err != ERR_NONE) RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting);