diff --git a/core/src/core.cpp b/core/src/core.cpp index ff090370..bbf3a57e 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -158,17 +158,28 @@ int sdrpp_main(int argc, char *argv[]) { defConfig["min"] = -120.0; // Module instances - defConfig["moduleInstances"]["Airspy Source"] = "airspy_source"; - defConfig["moduleInstances"]["AirspyHF+ Source"] = "airspyhf_source"; - defConfig["moduleInstances"]["BladeRF Source"] = "bladerf_source"; - defConfig["moduleInstances"]["File Source"] = "file_source"; - defConfig["moduleInstances"]["HackRF Source"] = "hackrf_source"; - defConfig["moduleInstances"]["LimeSDR Source"] = "limesdr_source"; - defConfig["moduleInstances"]["RTL-SDR Source"] = "rtl_sdr_source"; - defConfig["moduleInstances"]["RTL-TCP Source"] = "rtl_tcp_source"; - defConfig["moduleInstances"]["SDRplay Source"] = "sdrplay_source"; - defConfig["moduleInstances"]["SoapySDR Source"] = "soapy_source"; - defConfig["moduleInstances"]["PlutoSDR Source"] = "plutosdr_source"; + defConfig["moduleInstances"]["Airspy Source"]["module"] = "airspy_source"; + defConfig["moduleInstances"]["Airspy Source"]["enabled"] = true; + defConfig["moduleInstances"]["AirspyHF+ Source"]["module"] = "airspyhf_source"; + defConfig["moduleInstances"]["AirspyHF+ Source"]["enabled"] = true; + defConfig["moduleInstances"]["BladeRF Source"]["module"] = "bladerf_source"; + defConfig["moduleInstances"]["BladeRF Source"]["enabled"] = true; + defConfig["moduleInstances"]["File Source"]["module"] = "file_source"; + defConfig["moduleInstances"]["File Source"]["enabled"] = true; + defConfig["moduleInstances"]["HackRF Source"]["module"] = "hackrf_source"; + defConfig["moduleInstances"]["HackRF Source"]["enabled"] = true; + defConfig["moduleInstances"]["LimeSDR Source"]["module"] = "limesdr_source"; + defConfig["moduleInstances"]["LimeSDR Source"]["enabled"] = true; + defConfig["moduleInstances"]["RTL-SDR Source"]["module"] = "rtl_sdr_source"; + defConfig["moduleInstances"]["RTL-SDR Source"]["enabled"] = true; + defConfig["moduleInstances"]["RTL-TCP Source"]["module"] = "rtl_tcp_source"; + defConfig["moduleInstances"]["RTL-TCP Source"]["enabled"] = true; + defConfig["moduleInstances"]["SDRplay Source"]["module"] = "sdrplay_source"; + defConfig["moduleInstances"]["SDRplay Source"]["enabled"] = true; + defConfig["moduleInstances"]["SoapySDR Source"]["module"] = "soapy_source"; + defConfig["moduleInstances"]["SoapySDR Source"]["enabled"] = true; + defConfig["moduleInstances"]["PlutoSDR Source"]["module"] = "plutosdr_source"; + defConfig["moduleInstances"]["PlutoSDR Source"]["enabled"] = true; defConfig["moduleInstances"]["Audio Sink"] = "audio_sink"; @@ -232,6 +243,16 @@ int sdrpp_main(int argc, char *argv[]) { } } + // Update to new module representation in config if needed + for (auto [_name, inst] : core::configManager.conf["moduleInstances"].items()) { + if (!inst.is_string()) { continue; } + std::string mod = inst; + json newMod; + newMod["module"] = mod; + newMod["enabled"] = true; + core::configManager.conf["moduleInstances"][_name] = newMod; + } + core::configManager.release(true); // Setup window diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index 6ef0072d..eafcbb94 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -111,7 +111,7 @@ void MainWindow::init() { // Read module config core::configManager.acquire(); std::vector modules = core::configManager.conf["modules"]; - std::map modList = core::configManager.conf["moduleInstances"]; + auto modList = core::configManager.conf["moduleInstances"].items(); core::configManager.release(); // Load additional modules specified through config @@ -122,10 +122,13 @@ void MainWindow::init() { } // Create module instances - for (auto const& [name, module] : modList) { - spdlog::info("Initializing {0} ({1})", name, module); - LoadingScreen::show("Initializing " + name + " (" + module + ")"); - core::moduleManager.createInstance(name, module); + for (auto const& [name, _module] : modList) { + std::string mod = _module["module"]; + bool enabled = _module["enabled"]; + spdlog::info("Initializing {0} ({1})", name, mod); + LoadingScreen::show("Initializing " + name + " (" + mod + ")"); + core::moduleManager.createInstance(name, mod); + if (!enabled) { core::moduleManager.disableInstance(name); } } // Load color maps @@ -446,6 +449,12 @@ void MainWindow::draw() { arr[i]["open"] = gui::menu.order[i].open; } core::configManager.conf["menuElements"] = arr; + + // Update enabled and disabled modules + for (auto [_name, inst] : core::moduleManager.instances) { + core::configManager.conf["moduleInstances"][_name]["enabled"] = inst.instance->isEnabled(); + } + core::configManager.release(true); } if (startedWithMenuClosed) { diff --git a/core/src/gui/widgets/menu.cpp b/core/src/gui/widgets/menu.cpp index 667312c4..a839f346 100644 --- a/core/src/gui/widgets/menu.cpp +++ b/core/src/gui/widgets/menu.cpp @@ -106,6 +106,7 @@ bool Menu::draw(bool updateStates) { bool enabled = item.inst->isEnabled(); if (ImGui::Checkbox(("##_menu_checkbox_" + opt.name).c_str(), &enabled)) { enabled ? item.inst->enable() : item.inst->disable(); + changed = true; } ImGui::SetCursorPos(pos); } @@ -127,6 +128,7 @@ bool Menu::draw(bool updateStates) { bool enabled = item.inst->isEnabled(); if (ImGui::Checkbox(("##_menu_checkbox_" + opt.name).c_str(), &enabled)) { enabled ? item.inst->enable() : item.inst->disable(); + changed = true; } ImGui::SetCursorPos(pos);