mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-14 20:27:11 +01:00
finish custom offset definitions and fix bug in source selection
This commit is contained in:
parent
69161253e8
commit
b835d07573
@ -232,22 +232,15 @@ int sdrpp_main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
defConfig["modules"] = json::array();
|
defConfig["modules"] = json::array();
|
||||||
|
|
||||||
defConfig["offsets"] = json::array();
|
defConfig["offsets"]["SpyVerter"] = 120000000.0;
|
||||||
defConfig["offsets"][0]["name"] = "SpyVerter";
|
defConfig["offsets"]["Ham-It-Up"] = 125000000.0;
|
||||||
defConfig["offsets"][0]["offset"] = 120000000;
|
defConfig["offsets"]["MMDS S-band (1998MHz)"] = -1998000000.0;
|
||||||
defConfig["offsets"][1]["name"] = "Ham-It-Up";
|
defConfig["offsets"]["DK5AV X-Band"] = -6800000000.0;
|
||||||
defConfig["offsets"][1]["offset"] = 125000000;
|
defConfig["offsets"]["Ku LNB (9750MHz)"] = -9750000000.0;
|
||||||
defConfig["offsets"][2]["name"] = "MMDS S-band (1998MHz)";
|
defConfig["offsets"]["Ku LNB (10700MHz)"] = -10700000000.0;
|
||||||
defConfig["offsets"][2]["offset"] = -1998000000;
|
|
||||||
defConfig["offsets"][3]["name"] = "DK5AV X-Band";
|
|
||||||
defConfig["offsets"][3]["offset"] = -6800000000;
|
|
||||||
defConfig["offsets"][4]["name"] = "Ku LNB (9750MHz)";
|
|
||||||
defConfig["offsets"][4]["offset"] = -9750000000;
|
|
||||||
defConfig["offsets"][5]["name"] = "Ku LNB (10700MHz)";
|
|
||||||
defConfig["offsets"][5]["offset"] = -10700000000;
|
|
||||||
|
|
||||||
defConfig["offsetMode"] = (int)0; // Off
|
defConfig["selectedOffset"] = "None";
|
||||||
defConfig["offset"] = 0.0;
|
defConfig["manualOffset"] = 0.0;
|
||||||
defConfig["showMenu"] = true;
|
defConfig["showMenu"] = true;
|
||||||
defConfig["showWaterfall"] = true;
|
defConfig["showWaterfall"] = true;
|
||||||
defConfig["source"] = "";
|
defConfig["source"] = "";
|
||||||
@ -332,12 +325,18 @@ int sdrpp_main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
// Remove unused elements
|
// Remove unused elements
|
||||||
auto items = core::configManager.conf.items();
|
auto items = core::configManager.conf.items();
|
||||||
|
auto newConf = core::configManager.conf;
|
||||||
|
bool configCorrected = false;
|
||||||
for (auto const& item : items) {
|
for (auto const& item : items) {
|
||||||
if (!defConfig.contains(item.key())) {
|
if (!defConfig.contains(item.key())) {
|
||||||
flog::info("Unused key in config {0}, repairing", item.key());
|
flog::info("Unused key in config {0}, repairing", item.key());
|
||||||
core::configManager.conf.erase(item.key());
|
newConf.erase(item.key());
|
||||||
|
configCorrected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (configCorrected) {
|
||||||
|
core::configManager.conf = newConf;
|
||||||
|
}
|
||||||
|
|
||||||
// Update to new module representation in config if needed
|
// Update to new module representation in config if needed
|
||||||
for (auto [_name, inst] : core::configManager.conf["moduleInstances"].items()) {
|
for (auto [_name, inst] : core::configManager.conf["moduleInstances"].items()) {
|
||||||
|
@ -9,22 +9,24 @@
|
|||||||
#include <gui/dialogs/dialog_box.h>
|
#include <gui/dialogs/dialog_box.h>
|
||||||
|
|
||||||
namespace sourcemenu {
|
namespace sourcemenu {
|
||||||
int offsetMode = 0;
|
|
||||||
int sourceId = 0;
|
int sourceId = 0;
|
||||||
double customOffset = 0.0;
|
EventHandler<std::string> sourcesChangedHandler;
|
||||||
double effectiveOffset = 0.0;
|
EventHandler<std::string> sourceUnregisterHandler;
|
||||||
|
OptionList<std::string, std::string> sources;
|
||||||
|
std::string selectedSource;
|
||||||
|
|
||||||
int decimId = 0;
|
int decimId = 0;
|
||||||
|
OptionList<int, int> decimations;
|
||||||
|
|
||||||
bool iqCorrection = false;
|
bool iqCorrection = false;
|
||||||
bool invertIQ = false;
|
bool invertIQ = false;
|
||||||
|
|
||||||
EventHandler<std::string> sourcesChangedHandler;
|
int offsetId = 0;
|
||||||
EventHandler<std::string> sourceUnregisterHandler;
|
double manualOffset = 0.0;
|
||||||
|
std::string selectedOffset;
|
||||||
OptionList<std::string, std::string> sources;
|
double effectiveOffset = 0.0;
|
||||||
std::string selectedSource;
|
OptionList<std::string, double> offsets;
|
||||||
OptionList<std::string, int> offsets;
|
std::map<std::string, double> namedOffsets;
|
||||||
std::vector<double> customOffsets;
|
|
||||||
OptionList<int, int> decimations;
|
|
||||||
|
|
||||||
bool showAddOffsetDialog = false;
|
bool showAddOffsetDialog = false;
|
||||||
char newOffsetName[1024];
|
char newOffsetName[1024];
|
||||||
@ -33,23 +35,24 @@ namespace sourcemenu {
|
|||||||
bool showDelOffsetDialog = false;
|
bool showDelOffsetDialog = false;
|
||||||
std::string delOffsetName = "";
|
std::string delOffsetName = "";
|
||||||
|
|
||||||
|
// Offset IDs
|
||||||
enum {
|
enum {
|
||||||
OFFSET_MODE_NONE,
|
OFFSET_ID_NONE,
|
||||||
OFFSET_MODE_MANUAL,
|
OFFSET_ID_MANUAL,
|
||||||
OFFSET_MODE_CUSTOM_BASE
|
OFFSET_ID_CUSTOM_BASE
|
||||||
};
|
};
|
||||||
|
|
||||||
void updateOffset() {
|
void updateOffset() {
|
||||||
// Compute the effective offset
|
// Compute the effective offset
|
||||||
switch (offsetMode) {
|
switch (offsetId) {
|
||||||
case OFFSET_MODE_NONE:
|
case OFFSET_ID_NONE:
|
||||||
effectiveOffset = 0;
|
effectiveOffset = 0;
|
||||||
break;
|
break;
|
||||||
case OFFSET_MODE_MANUAL:
|
case OFFSET_ID_MANUAL:
|
||||||
effectiveOffset = customOffset;
|
effectiveOffset = manualOffset;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
effectiveOffset = customOffsets[offsetMode - OFFSET_MODE_CUSTOM_BASE];
|
effectiveOffset = namedOffsets[offsets.name(offsetId)];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +60,26 @@ namespace sourcemenu {
|
|||||||
sigpath::sourceManager.setTuningOffset(effectiveOffset);
|
sigpath::sourceManager.setTuningOffset(effectiveOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void selectOffsetById(int id) {
|
||||||
|
// Update the offset mode
|
||||||
|
offsetId = id;
|
||||||
|
selectedOffset = offsets.name(id);
|
||||||
|
|
||||||
|
// Update the offset
|
||||||
|
updateOffset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void selectOffsetByName(const std::string& name) {
|
||||||
|
// If the name doesn't exist, select 'None'
|
||||||
|
if (!offsets.nameExists(name)) {
|
||||||
|
selectOffsetById(OFFSET_ID_NONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select using the ID associated with the name
|
||||||
|
selectOffsetById(offsets.nameId(name));
|
||||||
|
}
|
||||||
|
|
||||||
void refreshSources() {
|
void refreshSources() {
|
||||||
// Get sources
|
// Get sources
|
||||||
auto sourceNames = sigpath::sourceManager.getSourceNames();
|
auto sourceNames = sigpath::sourceManager.getSourceNames();
|
||||||
@ -83,7 +106,7 @@ namespace sourcemenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the GUI variables
|
// Update the GUI variables
|
||||||
sourceId = sources.valueExists(name);
|
sourceId = sources.valueId(name);
|
||||||
selectedSource = name;
|
selectedSource = name;
|
||||||
|
|
||||||
// Select the source module
|
// Select the source module
|
||||||
@ -104,23 +127,22 @@ namespace sourcemenu {
|
|||||||
// TODO: Stop everything
|
// TODO: Stop everything
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadOffsets() {
|
void reloadOffsets() {
|
||||||
// Clear list
|
// Clear list
|
||||||
offsets.clear();
|
offsets.clear();
|
||||||
customOffsets.clear();
|
namedOffsets.clear();
|
||||||
|
|
||||||
// Define special offset modes
|
// Define special offset modes
|
||||||
offsets.define("None", 0);
|
offsets.define("None", OFFSET_ID_NONE);
|
||||||
offsets.define("Manual", 1);
|
offsets.define("Manual", OFFSET_ID_MANUAL);
|
||||||
|
|
||||||
// Acquire the config file
|
// Acquire the config file
|
||||||
core::configManager.acquire();
|
core::configManager.acquire();
|
||||||
|
|
||||||
// Load custom offsets
|
// Load custom offsets
|
||||||
std::vector<json> offsetList = core::configManager.conf["offsets"];
|
namedOffsets = (std::map<std::string, double>)core::configManager.conf["offsets"];
|
||||||
for (auto& o : offsetList) {
|
for (auto& [name, offset] : namedOffsets) {
|
||||||
customOffsets.push_back(o["offset"]);
|
offsets.define(name, offsets.size());
|
||||||
offsets.define(o["name"], offsets.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release the config file
|
// Release the config file
|
||||||
@ -129,7 +151,7 @@ namespace sourcemenu {
|
|||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
// Load offset modes
|
// Load offset modes
|
||||||
loadOffsets();
|
reloadOffsets();
|
||||||
|
|
||||||
// Define decimation values
|
// Define decimation values
|
||||||
decimations.define(1, "None", 1);
|
decimations.define(1, "None", 1);
|
||||||
@ -144,9 +166,9 @@ namespace sourcemenu {
|
|||||||
core::configManager.acquire();
|
core::configManager.acquire();
|
||||||
|
|
||||||
// Load other settings
|
// Load other settings
|
||||||
std::string selected = core::configManager.conf["source"];
|
std::string selectedSource = core::configManager.conf["source"];
|
||||||
customOffset = core::configManager.conf["offset"];
|
manualOffset = core::configManager.conf["manualOffset"];
|
||||||
offsetMode = core::configManager.conf["offsetMode"];
|
std::string selectedOffset = core::configManager.conf["selectedOffset"];
|
||||||
iqCorrection = core::configManager.conf["iqCorrection"];
|
iqCorrection = core::configManager.conf["iqCorrection"];
|
||||||
invertIQ = core::configManager.conf["invertIQ"];
|
invertIQ = core::configManager.conf["invertIQ"];
|
||||||
int decimation = core::configManager.conf["decimation"];
|
int decimation = core::configManager.conf["decimation"];
|
||||||
@ -159,13 +181,13 @@ namespace sourcemenu {
|
|||||||
|
|
||||||
// Select the source module
|
// Select the source module
|
||||||
refreshSources();
|
refreshSources();
|
||||||
selectSource(selected);
|
selectSource(selectedSource);
|
||||||
|
|
||||||
// Update frontend settings
|
// Update frontend settings
|
||||||
sigpath::iqFrontEnd.setDCBlocking(iqCorrection);
|
sigpath::iqFrontEnd.setDCBlocking(iqCorrection);
|
||||||
sigpath::iqFrontEnd.setInvertIQ(invertIQ);
|
sigpath::iqFrontEnd.setInvertIQ(invertIQ);
|
||||||
updateOffset();
|
|
||||||
sigpath::iqFrontEnd.setDecimation(decimations.value(decimId));
|
sigpath::iqFrontEnd.setDecimation(decimations.value(decimId));
|
||||||
|
selectOffsetByName(selectedOffset);
|
||||||
|
|
||||||
// Register handlers
|
// Register handlers
|
||||||
sourcesChangedHandler.handler = onSourcesChanged;
|
sourcesChangedHandler.handler = onSourcesChanged;
|
||||||
@ -180,23 +202,33 @@ namespace sourcemenu {
|
|||||||
core::configManager.acquire();
|
core::configManager.acquire();
|
||||||
|
|
||||||
// Define a new offset
|
// Define a new offset
|
||||||
auto newOffsetObj = json::object();
|
core::configManager.conf["offsets"][name] = offset;
|
||||||
newOffsetObj["name"] = newOffsetName;
|
|
||||||
newOffsetObj["offset"] = newOffset;
|
|
||||||
core::configManager.conf["offsets"].push_back(newOffsetObj);
|
|
||||||
|
|
||||||
// Acquire the config file
|
// Acquire the config file
|
||||||
core::configManager.release(true);
|
core::configManager.release(true);
|
||||||
|
|
||||||
// Reload the offsets
|
// Reload the offsets
|
||||||
loadOffsets();
|
reloadOffsets();
|
||||||
|
|
||||||
// Re-select the same one
|
// Attempt to re-select the same one
|
||||||
// TODO: Switch from an array to a map, because two can't have the same name anyway and it'll just make things easier...+
|
selectOffsetByName(selectedOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delOffset(const std::string& name) {
|
void delOffset(const std::string& name) {
|
||||||
|
// Acquire the config file
|
||||||
|
core::configManager.acquire();
|
||||||
|
|
||||||
|
// Define a new offset
|
||||||
|
core::configManager.conf["offsets"].erase(name);
|
||||||
|
|
||||||
|
// Acquire the config file
|
||||||
|
core::configManager.release(true);
|
||||||
|
|
||||||
|
// Reload the offsets
|
||||||
|
reloadOffsets();
|
||||||
|
|
||||||
|
// Attempt to re-select the same one
|
||||||
|
selectOffsetByName(selectedOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool addOffsetDialog() {
|
bool addOffsetDialog() {
|
||||||
@ -217,7 +249,16 @@ namespace sourcemenu {
|
|||||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||||
ImGui::InputDouble("##sdrpp_add_offset_offset", &newOffset);
|
ImGui::InputDouble("##sdrpp_add_offset_offset", &newOffset);
|
||||||
|
|
||||||
bool denyApply = !newOffsetName[0] || offsets.nameExists(newOffsetName);
|
bool nameExists = offsets.nameExists(newOffsetName);
|
||||||
|
bool reservedName = !strcmp(newOffsetName, "None") || !strcmp(newOffsetName, "Manual");
|
||||||
|
bool denyApply = !newOffsetName[0] || nameExists || reservedName;
|
||||||
|
|
||||||
|
if (nameExists) {
|
||||||
|
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "An offset with the given name already exists.");
|
||||||
|
}
|
||||||
|
else if (reservedName) {
|
||||||
|
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "The given name is reserved.");
|
||||||
|
}
|
||||||
|
|
||||||
if (denyApply) { style::beginDisabled(); }
|
if (denyApply) { style::beginDisabled(); }
|
||||||
if (ImGui::Button("Apply")) {
|
if (ImGui::Button("Apply")) {
|
||||||
@ -271,20 +312,20 @@ namespace sourcemenu {
|
|||||||
|
|
||||||
ImGui::LeftLabel("Offset mode");
|
ImGui::LeftLabel("Offset mode");
|
||||||
ImGui::SetNextItemWidth(itemWidth - ImGui::GetCursorPosX() - 2.0f*(lineHeight + 1.5f*spacing));
|
ImGui::SetNextItemWidth(itemWidth - ImGui::GetCursorPosX() - 2.0f*(lineHeight + 1.5f*spacing));
|
||||||
if (ImGui::Combo("##_sdrpp_offset_mode", &offsetMode, offsets.txt)) {
|
if (ImGui::Combo("##_sdrpp_offset", &offsetId, offsets.txt)) {
|
||||||
updateOffset();
|
selectOffsetById(offsetId);
|
||||||
core::configManager.acquire();
|
core::configManager.acquire();
|
||||||
core::configManager.conf["offsetMode"] = offsetMode;
|
core::configManager.conf["selectedOffset"] = offsets.key(offsetId);
|
||||||
core::configManager.release(true);
|
core::configManager.release(true);
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - spacing);
|
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - spacing);
|
||||||
if (offsetMode < OFFSET_MODE_CUSTOM_BASE) { ImGui::BeginDisabled(); }
|
if (offsetId < OFFSET_ID_CUSTOM_BASE) { ImGui::BeginDisabled(); }
|
||||||
if (ImGui::Button("-##_sdrpp_offset_del_", ImVec2(lineHeight + 0.5f*spacing, 0))) {
|
if (ImGui::Button("-##_sdrpp_offset_del_", ImVec2(lineHeight + 0.5f*spacing, 0))) {
|
||||||
delOffsetName = "TEST";
|
delOffsetName = selectedOffset;
|
||||||
showDelOffsetDialog = true;
|
showDelOffsetDialog = true;
|
||||||
}
|
}
|
||||||
if (offsetMode < OFFSET_MODE_CUSTOM_BASE) { ImGui::EndDisabled(); }
|
if (offsetId < OFFSET_ID_CUSTOM_BASE) { ImGui::EndDisabled(); }
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - spacing);
|
ImGui::SetCursorPosX(ImGui::GetCursorPosX() - spacing);
|
||||||
if (ImGui::Button("+##_sdrpp_offset_add_", ImVec2(lineHeight + 0.5f*spacing, 0))) {
|
if (ImGui::Button("+##_sdrpp_offset_add_", ImVec2(lineHeight + 0.5f*spacing, 0))) {
|
||||||
@ -294,7 +335,7 @@ namespace sourcemenu {
|
|||||||
|
|
||||||
// Offset delete confirmation
|
// Offset delete confirmation
|
||||||
if (ImGui::GenericDialog("sdrpp_del_offset_confirm", showDelOffsetDialog, GENERIC_DIALOG_BUTTONS_YES_NO, []() {
|
if (ImGui::GenericDialog("sdrpp_del_offset_confirm", showDelOffsetDialog, GENERIC_DIALOG_BUTTONS_YES_NO, []() {
|
||||||
ImGui::Text("Deleting offset named \"%s\". Are you sure?", delOffsetName);
|
ImGui::Text("Deleting offset named \"%s\". Are you sure?", delOffsetName.c_str());
|
||||||
}) == GENERIC_DIALOG_BUTTON_YES) {
|
}) == GENERIC_DIALOG_BUTTON_YES) {
|
||||||
delOffset(delOffsetName);
|
delOffset(delOffsetName);
|
||||||
}
|
}
|
||||||
@ -304,11 +345,11 @@ namespace sourcemenu {
|
|||||||
|
|
||||||
ImGui::LeftLabel("Offset");
|
ImGui::LeftLabel("Offset");
|
||||||
ImGui::FillWidth();
|
ImGui::FillWidth();
|
||||||
if (offsetMode == OFFSET_MODE_MANUAL) {
|
if (offsetId == OFFSET_ID_MANUAL) {
|
||||||
if (ImGui::InputDouble("##freq_offset", &customOffset, 1.0, 100.0)) {
|
if (ImGui::InputDouble("##freq_offset", &manualOffset, 1.0, 100.0)) {
|
||||||
updateOffset();
|
updateOffset();
|
||||||
core::configManager.acquire();
|
core::configManager.acquire();
|
||||||
core::configManager.conf["offset"] = customOffset;
|
core::configManager.conf["offset"] = manualOffset;
|
||||||
core::configManager.release(true);
|
core::configManager.release(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user