The enabled state of all modules is now preserved

This commit is contained in:
Ryzerth 2021-07-10 00:28:56 +02:00
parent fd9f4ebdc3
commit 73bbd69e3f
3 changed files with 48 additions and 16 deletions

View File

@ -158,17 +158,28 @@ int sdrpp_main(int argc, char *argv[]) {
defConfig["min"] = -120.0; defConfig["min"] = -120.0;
// Module instances // Module instances
defConfig["moduleInstances"]["Airspy Source"] = "airspy_source"; defConfig["moduleInstances"]["Airspy Source"]["module"] = "airspy_source";
defConfig["moduleInstances"]["AirspyHF+ Source"] = "airspyhf_source"; defConfig["moduleInstances"]["Airspy Source"]["enabled"] = true;
defConfig["moduleInstances"]["BladeRF Source"] = "bladerf_source"; defConfig["moduleInstances"]["AirspyHF+ Source"]["module"] = "airspyhf_source";
defConfig["moduleInstances"]["File Source"] = "file_source"; defConfig["moduleInstances"]["AirspyHF+ Source"]["enabled"] = true;
defConfig["moduleInstances"]["HackRF Source"] = "hackrf_source"; defConfig["moduleInstances"]["BladeRF Source"]["module"] = "bladerf_source";
defConfig["moduleInstances"]["LimeSDR Source"] = "limesdr_source"; defConfig["moduleInstances"]["BladeRF Source"]["enabled"] = true;
defConfig["moduleInstances"]["RTL-SDR Source"] = "rtl_sdr_source"; defConfig["moduleInstances"]["File Source"]["module"] = "file_source";
defConfig["moduleInstances"]["RTL-TCP Source"] = "rtl_tcp_source"; defConfig["moduleInstances"]["File Source"]["enabled"] = true;
defConfig["moduleInstances"]["SDRplay Source"] = "sdrplay_source"; defConfig["moduleInstances"]["HackRF Source"]["module"] = "hackrf_source";
defConfig["moduleInstances"]["SoapySDR Source"] = "soapy_source"; defConfig["moduleInstances"]["HackRF Source"]["enabled"] = true;
defConfig["moduleInstances"]["PlutoSDR Source"] = "plutosdr_source"; 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"; 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); core::configManager.release(true);
// Setup window // Setup window

View File

@ -111,7 +111,7 @@ void MainWindow::init() {
// Read module config // Read module config
core::configManager.acquire(); core::configManager.acquire();
std::vector<std::string> modules = core::configManager.conf["modules"]; std::vector<std::string> modules = core::configManager.conf["modules"];
std::map<std::string, std::string> modList = core::configManager.conf["moduleInstances"]; auto modList = core::configManager.conf["moduleInstances"].items();
core::configManager.release(); core::configManager.release();
// Load additional modules specified through config // Load additional modules specified through config
@ -122,10 +122,13 @@ void MainWindow::init() {
} }
// Create module instances // Create module instances
for (auto const& [name, module] : modList) { for (auto const& [name, _module] : modList) {
spdlog::info("Initializing {0} ({1})", name, module); std::string mod = _module["module"];
LoadingScreen::show("Initializing " + name + " (" + module + ")"); bool enabled = _module["enabled"];
core::moduleManager.createInstance(name, module); 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 // Load color maps
@ -446,6 +449,12 @@ void MainWindow::draw() {
arr[i]["open"] = gui::menu.order[i].open; arr[i]["open"] = gui::menu.order[i].open;
} }
core::configManager.conf["menuElements"] = arr; 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); core::configManager.release(true);
} }
if (startedWithMenuClosed) { if (startedWithMenuClosed) {

View File

@ -106,6 +106,7 @@ bool Menu::draw(bool updateStates) {
bool enabled = item.inst->isEnabled(); bool enabled = item.inst->isEnabled();
if (ImGui::Checkbox(("##_menu_checkbox_" + opt.name).c_str(), &enabled)) { if (ImGui::Checkbox(("##_menu_checkbox_" + opt.name).c_str(), &enabled)) {
enabled ? item.inst->enable() : item.inst->disable(); enabled ? item.inst->enable() : item.inst->disable();
changed = true;
} }
ImGui::SetCursorPos(pos); ImGui::SetCursorPos(pos);
} }
@ -127,6 +128,7 @@ bool Menu::draw(bool updateStates) {
bool enabled = item.inst->isEnabled(); bool enabled = item.inst->isEnabled();
if (ImGui::Checkbox(("##_menu_checkbox_" + opt.name).c_str(), &enabled)) { if (ImGui::Checkbox(("##_menu_checkbox_" + opt.name).c_str(), &enabled)) {
enabled ? item.inst->enable() : item.inst->disable(); enabled ? item.inst->enable() : item.inst->disable();
changed = true;
} }
ImGui::SetCursorPos(pos); ImGui::SetCursorPos(pos);