From e9ec79f6ef47ae3558cfb090c9d1c6e16fd8dbb1 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Sat, 27 Jan 2024 21:29:44 +0100 Subject: [PATCH] modernise gain mode selection for plutosdr --- source_modules/plutosdr_source/src/main.cpp | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/source_modules/plutosdr_source/src/main.cpp b/source_modules/plutosdr_source/src/main.cpp index 14887dbe..713c1ca0 100644 --- a/source_modules/plutosdr_source/src/main.cpp +++ b/source_modules/plutosdr_source/src/main.cpp @@ -19,12 +19,6 @@ SDRPP_MOD_INFO{ /* Max instances */ 1 }; -const char* gainModes[] = { - "manual", "fast_attack", "slow_attack", "hybrid" -}; - -const char* gainModesTxt = "Manual\0Fast Attack\0Slow Attack\0Hybrid\0"; - ConfigManager config; class PlutoSDRSourceModule : public ModuleManager::Instance { @@ -56,6 +50,12 @@ public: sampleRate = samplerates.value(srId); } + // Define gain modes + gainModes.define(0, "Manual", "manual"); + gainModes.define(1, "Fast Attack", "fast_attack"); + gainModes.define(2, "Slow Attack", "slow_attack"); + gainModes.define(3, "Hybrid", "hybrid"); + // Register source handler.ctx = this; handler.selectHandler = menuSelected; @@ -142,10 +142,10 @@ private: // Configure RX channel iio_channel_attr_write(iio_device_find_channel(_this->phy, "voltage0", false), "rf_port_select", "A_BALANCED"); - iio_channel_attr_write_longlong(iio_device_find_channel(_this->phy, "altvoltage0", true), "frequency", round(_this->freq)); // Freq - iio_channel_attr_write_longlong(iio_device_find_channel(_this->phy, "voltage0", false), "sampling_frequency", round(_this->sampleRate)); // Sample rate - iio_channel_attr_write(iio_device_find_channel(_this->phy, "voltage0", false), "gain_control_mode", gainModes[_this->gainMode]); // manual gain - iio_channel_attr_write_longlong(iio_device_find_channel(_this->phy, "voltage0", false), "hardwaregain", round(_this->gain)); // gain + iio_channel_attr_write_longlong(iio_device_find_channel(_this->phy, "altvoltage0", true), "frequency", round(_this->freq)); // Freq + iio_channel_attr_write_longlong(iio_device_find_channel(_this->phy, "voltage0", false), "sampling_frequency", round(_this->sampleRate)); // Sample rate + iio_channel_attr_write(iio_device_find_channel(_this->phy, "voltage0", false), "gain_control_mode", _this->gainModes.value(_this->gainMode).c_str()); // Gain mode + iio_channel_attr_write_longlong(iio_device_find_channel(_this->phy, "voltage0", false), "hardwaregain", round(_this->gain)); // gain ad9361_set_bb_rate(_this->phy, round(_this->sampleRate)); // Start worker thread @@ -209,9 +209,9 @@ private: SmGui::LeftLabel("Gain Mode"); SmGui::FillWidth(); SmGui::ForceSync(); - if (SmGui::Combo(CONCAT("##_gainmode_select_", _this->name), &_this->gainMode, gainModesTxt)) { + if (SmGui::Combo(CONCAT("##_gainmode_select_", _this->name), &_this->gainMode, _this->gainModes.txt)) { if (_this->running) { - iio_channel_attr_write(iio_device_find_channel(_this->phy, "voltage0", false), "gain_control_mode", gainModes[_this->gainMode]); + iio_channel_attr_write(iio_device_find_channel(_this->phy, "voltage0", false), "gain_control_mode", _this->gainModes.value(_this->gainMode).c_str()); } config.acquire(); config.conf["gainMode"] = _this->gainMode; @@ -292,6 +292,7 @@ private: int srId = 0; OptionList samplerates; + OptionList gainModes; }; MOD_EXPORT void _INIT_() {