Skip to content

Commit

Permalink
Add settings option to set FSK shaping
Browse files Browse the repository at this point in the history
  • Loading branch information
sh123 committed Nov 20, 2023
1 parent 24fc0fc commit dc7b611
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <RadioLib.h>

// saved settings version, increment to load new settings
#define CFG_VERSION 4
#define CFG_VERSION 6

// Comment out for SX127X module usage
//#define USE_SX126X
Expand Down Expand Up @@ -68,6 +68,7 @@
#define CFG_FSK_BIT_RATE 4.8 // bit rate in Kbps from 0.6 to 300.0
#define CFG_FSK_FREQ_DEV 1.2 // frequency deviation in kHz from 0.6 to 200.0
#define CFG_FSK_RX_BW 9.7 // rx bandwidth in kHz discrete from 4.8 to 467.0
#define CFG_FSK_SHAPING RADIOLIB_SHAPING_NONE

// ptt button
#define CFG_PTT_BTN_PIN 39 // pin for ptt button
Expand Down
1 change: 1 addition & 0 deletions include/loradv_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Config {
float FskBitRate; // fsk bit rate, 0.6 - 300.0 Kbps
float FskFreqDev; // fsk frequency deviation 0.6 - 200 kHz
float FskRxBw; // fsk rx bandwidth, discrete from 4.8 to 467 kHz
byte FskShaping; // fsk gaussian shaping

// lora hardware pinouts and isr
byte LoraPinSs_; // lora ss pin
Expand Down
2 changes: 1 addition & 1 deletion include/radio_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RadioTask {

private:
void setupRig(long freq, long bw, int sf, int cr, int pwr, int sync, int crcBytes);
void setupRigFsk(long freq, float bitRate, float freqDev, float rxBw, int pwr);
void setupRigFsk(long freq, float bitRate, float freqDev, float rxBw, int pwr, byte shaping);

static IRAM_ATTR void onRigIsrRxPacket();

Expand Down
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef VERSION_H
#define VERSION_H

#define LORADV_VERSION "1.0.10"
#define LORADV_VERSION "1.0.11"

#endif // VERSION_H
7 changes: 7 additions & 0 deletions src/loradv_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void Config::InitializeDefault()
FskBitRate = CFG_FSK_BIT_RATE;
FskFreqDev = CFG_FSK_FREQ_DEV;
FskRxBw = CFG_FSK_RX_BW;
FskShaping = CFG_FSK_SHAPING;

// lora pinouts
LoraPinSs_ = CFG_LORA_PIN_SS;
Expand Down Expand Up @@ -186,6 +187,11 @@ void Config::Load()
} else {
prefs_.putFloat(N(FskRxBw), FskRxBw);
}
if (prefs_.isKey(N(FskShaping))) {
FskShaping = prefs_.getInt(N(FskShaping));
} else {
prefs_.putInt(N(FskShaping), FskShaping);
}
if (prefs_.isKey(N(ModType))) {
ModType = prefs_.getInt(N(ModType));
} else {
Expand Down Expand Up @@ -215,6 +221,7 @@ void Config::Save()
prefs_.putFloat(N(FskBitRate), FskBitRate);
prefs_.putFloat(N(FskFreqDev), FskFreqDev);
prefs_.putFloat(N(FskRxBw), FskRxBw);
prefs_.putInt(N(FskShaping), FskShaping);
prefs_.putInt(N(ModType), ModType);
prefs_.end();
LOG_INFO("Saved settings");
Expand Down
6 changes: 4 additions & 2 deletions src/radio_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,22 @@ void RadioTask::setupRig(long loraFreq, long bw, int sf, int cr, int pwr, int sy
LOG_INFO("LoRa initialized");
}

void RadioTask::setupRigFsk(long freq, float bitRate, float freqDev, float rxBw, int pwr)
void RadioTask::setupRigFsk(long freq, float bitRate, float freqDev, float rxBw, int pwr, byte shaping)
{
LOG_INFO("Initializing FSK");
LOG_INFO("Frequency:", freq, "Hz");
LOG_INFO("Bit rate:", bitRate, "kbps");
LOG_INFO("Deviation:", freqDev, "kHz");
LOG_INFO("Bandwidth:", rxBw, "kHz");
LOG_INFO("Power:", pwr, "dBm");
LOG_INFO("Shaping:", shaping);
rig_ = std::make_shared<MODULE_NAME>(new Module(config_->LoraPinSs_, config_->LoraPinA_, config_->LoraPinRst_, config_->LoraPinB_));
int state = rig_->beginFSK((float)freq / 1e6, bitRate, freqDev, rxBw, pwr);
if (state != RADIOLIB_ERR_NONE) {
LOG_ERROR("Radio start error:", state);
}
rig_->disableAddressFiltering();
rig_->setDataShaping(shaping);
#ifdef USE_SX126X
#pragma message("Using SX126X")
LOG_INFO("Using SX126X module");
Expand Down Expand Up @@ -198,7 +200,7 @@ void RadioTask::rigTask()
config_->LoraCodingRate, config_->LoraPower, config_->LoraSync_, config_->LoraCrc_);
} else {
setupRigFsk(config_->LoraFreqRx, config_->FskBitRate, config_->FskFreqDev,
config_->FskRxBw, config_->LoraPower);
config_->FskRxBw, config_->LoraPower, config_->FskShaping);
}

byte *packetBuf = new byte[CfgRadioPacketBufLen];
Expand Down
49 changes: 49 additions & 0 deletions src/settings_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,54 @@ class SettingsFskRxBw : public SettingsItem {
float items_[CfgItemsCount];
};

class SettingsFskShaping : public SettingsItem {
private:
static const int CfgItemsCount = 5;
public:
SettingsFskShaping(std::shared_ptr<Config> config, int index)
: SettingsItem(config, index)
, items_{
RADIOLIB_SHAPING_NONE,
RADIOLIB_SHAPING_0_3,
RADIOLIB_SHAPING_0_5,
RADIOLIB_SHAPING_0_7,
RADIOLIB_SHAPING_1_0
}
, map_{
{ RADIOLIB_SHAPING_NONE, "None" },
{ RADIOLIB_SHAPING_0_3, "0.3" },
{ RADIOLIB_SHAPING_0_5, "0.5" },
{ RADIOLIB_SHAPING_0_7, "0.7" },
{ RADIOLIB_SHAPING_1_0, "1.0" },
}
{
for (selIndex_ = 0; selIndex_ < CfgItemsCount; selIndex_++)
if (config_->FskShaping == items_[selIndex_])
break;
}
void changeValue(int delta) {
int newIndex = selIndex_ + delta;
if (newIndex >= 0 && newIndex < CfgItemsCount) selIndex_ = newIndex;
config_->FskShaping = items_[selIndex_];
}
void getName(std::stringstream &s) const { s << index_ << ".FSK Shaping"; }
void getValue(std::stringstream &s) const {
for (int i = 0; i < CfgItemsCount; i++)
if (config_->FskShaping == map_[i].k) {
s << map_[i].val;
break;
}
}
private:
int selIndex_;
int items_[CfgItemsCount];
struct MapItem {
int k;
const char *val;
} map_[CfgItemsCount];
};


class SettingsBatteryMonCalItem : public SettingsItem {
public:
SettingsBatteryMonCalItem(std::shared_ptr<Config> config, int index) : SettingsItem(config, index) {}
Expand Down Expand Up @@ -349,6 +397,7 @@ SettingsMenu::SettingsMenu(std::shared_ptr<Config> config)
items_.push_back(std::shared_ptr<SettingsItem>(new SettingsFskBitRate(config, ++i)));
items_.push_back(std::shared_ptr<SettingsItem>(new SettingsFskFreqDev(config, ++i)));
items_.push_back(std::shared_ptr<SettingsItem>(new SettingsFskRxBw(config, ++i)));
items_.push_back(std::shared_ptr<SettingsItem>(new SettingsFskShaping(config, ++i)));
items_.push_back(std::shared_ptr<SettingsItem>(new SettingsBatteryMonCalItem(config, ++i)));
items_.push_back(std::shared_ptr<SettingsItem>(new SettingsPmLightSleepAfterMsItem(config, ++i)));
items_.push_back(std::shared_ptr<SettingsItem>(new SettingsSaveItem(config, ++i)));
Expand Down

0 comments on commit dc7b611

Please sign in to comment.