SDRPlusPlus/core/src/gui/menus/source.cpp

54 lines
2.1 KiB
C++
Raw Normal View History

#include <gui/menus/source.h>
2020-10-01 01:21:15 +02:00
#include <imgui.h>
#include <gui/gui.h>
#include <core.h>
#include <signal_path/signal_path.h>
namespace sourecmenu {
2020-10-01 01:21:15 +02:00
int sourceId = 0;
2020-10-20 14:59:42 +02:00
double freqOffset = 0.0;
2020-10-01 01:21:15 +02:00
void init() {
2020-11-30 05:51:33 +01:00
core::configManager.aquire();
std::string name = core::configManager.conf["source"];
auto it = std::find(sigpath::sourceManager.sourceNames.begin(), sigpath::sourceManager.sourceNames.end(), name);
if (it != sigpath::sourceManager.sourceNames.end()) {
sigpath::sourceManager.selectSource(name);
sourceId = std::distance(sigpath::sourceManager.sourceNames.begin(), it);
}
else if (sigpath::sourceManager.sourceNames.size() > 0) {
2020-10-01 01:21:15 +02:00
sigpath::sourceManager.selectSource(sigpath::sourceManager.sourceNames[0]);
}
2020-11-30 05:51:33 +01:00
else {
spdlog::warn("No source available...");
}
sigpath::sourceManager.setTuningOffset(core::configManager.conf["offset"]);
core::configManager.release();
}
void draw(void* ctx) {
2020-10-01 01:21:15 +02:00
std::string items = "";
for (std::string name : sigpath::sourceManager.sourceNames) {
items += name;
items += '\0';
}
float itemWidth = ImGui::GetContentRegionAvailWidth();
2020-10-01 01:21:15 +02:00
ImGui::SetNextItemWidth(itemWidth);
if (ImGui::Combo("##source", &sourceId, items.c_str())) {
sigpath::sourceManager.selectSource(sigpath::sourceManager.sourceNames[sourceId]);
2020-11-30 05:51:33 +01:00
core::configManager.aquire();
core::configManager.conf["source"] = sigpath::sourceManager.sourceNames[sourceId];
core::configManager.release(true);
2020-10-01 01:21:15 +02:00
}
sigpath::sourceManager.showSelectedMenu();
2020-10-20 14:59:42 +02:00
ImGui::SetNextItemWidth(itemWidth - ImGui::CalcTextSize("Offset (Hz)").x - 10);
if (ImGui::InputDouble("Offset (Hz)##freq_offset", &freqOffset, 1.0, 100.0)) {
sigpath::sourceManager.setTuningOffset(freqOffset);
2020-11-30 05:51:33 +01:00
core::configManager.aquire();
core::configManager.conf["offset"] = freqOffset;
core::configManager.release(true);
2020-10-20 14:59:42 +02:00
}
}
}