mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-26 20:37:50 +02:00
Band plans alpha
This commit is contained in:
@ -4,6 +4,7 @@ namespace bandplan {
|
||||
std::map<std::string, BandPlan_t> bandplans;
|
||||
std::vector<std::string> bandplanNames;
|
||||
std::string bandplanNameTxt;
|
||||
std::map<std::string, BandPlanColor_t> colorTable;
|
||||
|
||||
void generateTxt() {
|
||||
bandplanNameTxt = "";
|
||||
@ -49,6 +50,24 @@ namespace bandplan {
|
||||
j.at("bands").get_to(b.bands);
|
||||
}
|
||||
|
||||
void to_json(json& j, const BandPlanColor_t& ct) {
|
||||
spdlog::error("ImGui color to JSON not implemented!!!");
|
||||
}
|
||||
|
||||
void from_json(const json& j, BandPlanColor_t& ct) {
|
||||
std::string col = j.get<std::string>();
|
||||
if (col[0] != '#' || !std::all_of(col.begin() + 1, col.end(), ::isxdigit)) {
|
||||
return;
|
||||
}
|
||||
uint8_t r, g, b, a;
|
||||
r = std::stoi(col.substr(1, 2), NULL, 16);
|
||||
g = std::stoi(col.substr(3, 2), NULL, 16);
|
||||
b = std::stoi(col.substr(5, 2), NULL, 16);
|
||||
a = std::stoi(col.substr(7, 2), NULL, 16);
|
||||
ct.colorValue = IM_COL32(r, g, b, a);
|
||||
ct.transColorValue = IM_COL32(r, g, b, 100);
|
||||
}
|
||||
|
||||
void loadBandPlan(std::string path) {
|
||||
std::ifstream file(path.c_str());
|
||||
json data;
|
||||
@ -83,4 +102,21 @@ namespace bandplan {
|
||||
loadBandPlan(path);
|
||||
}
|
||||
}
|
||||
|
||||
void loadColorTable(std::string path) {
|
||||
if (!std::filesystem::exists(path)) {
|
||||
spdlog::error("Band Plan Color Table file does not exist");
|
||||
return;
|
||||
}
|
||||
if (!std::filesystem::is_regular_file(path)) {
|
||||
spdlog::error("Band Plan Color Table file isn't a file...");
|
||||
return;
|
||||
}
|
||||
std::ifstream file(path.c_str());
|
||||
json data;
|
||||
data << file;
|
||||
file.close();
|
||||
|
||||
colorTable = data.get<std::map<std::string, BandPlanColor_t>>();
|
||||
}
|
||||
};
|
@ -3,6 +3,9 @@
|
||||
#include <fstream>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
@ -28,11 +31,21 @@ namespace bandplan {
|
||||
|
||||
void to_json(json& j, const BandPlan_t& b);
|
||||
void from_json(const json& j, BandPlan_t& b);
|
||||
|
||||
struct BandPlanColor_t {
|
||||
uint32_t colorValue;
|
||||
uint32_t transColorValue;
|
||||
};
|
||||
|
||||
void to_json(json& j, const BandPlanColor_t& ct);
|
||||
void from_json(const json& j, BandPlanColor_t& ct);
|
||||
|
||||
void loadBandPlan(std::string path);
|
||||
void loadFromDir(std::string path);
|
||||
void loadColorTable(std::string path);
|
||||
|
||||
extern std::map<std::string, BandPlan_t> bandplans;
|
||||
extern std::vector<std::string> bandplanNames;
|
||||
extern std::string bandplanNameTxt;
|
||||
extern std::map<std::string, BandPlanColor_t> colorTable;
|
||||
};
|
@ -69,6 +69,9 @@ int main() {
|
||||
spdlog::info("Loading band plans");
|
||||
bandplan::loadFromDir("bandplans");
|
||||
|
||||
spdlog::info("Loading band plans color table");
|
||||
bandplan::loadColorTable("band_colors.json");
|
||||
|
||||
spdlog::info("Ready.");
|
||||
|
||||
// Main loop
|
||||
|
@ -74,7 +74,7 @@ void windowInit() {
|
||||
|
||||
watcher<int> devId(0, true);
|
||||
watcher<int> srId(0, true);
|
||||
watcher<int> bandplanId(0);
|
||||
watcher<int> bandplanId(0, true);
|
||||
watcher<long> freq(90500000L);
|
||||
int demod = 1;
|
||||
watcher<float> vfoFreq(92000000.0f);
|
||||
@ -86,6 +86,7 @@ watcher<float> bw(8000000.0f, true);
|
||||
int sampleRate = 1000000;
|
||||
bool playing = false;
|
||||
watcher<bool> dcbias(false, false);
|
||||
watcher<bool> bandPlanEnabled(true, false);
|
||||
|
||||
void setVFO(float freq) {
|
||||
float currentOff = wtf.getVFOOfset();
|
||||
@ -226,8 +227,12 @@ void drawWindow() {
|
||||
sigPath.setDCBiasCorrection(dcbias.val);
|
||||
}
|
||||
|
||||
if (bandplanId.changed()) {
|
||||
spdlog::info("BANDPLAN CHANGED!!!!");
|
||||
if (bandplanId.changed() && bandPlanEnabled.val) {
|
||||
wtf.bandplan = &bandplan::bandplans[bandplan::bandplanNames[bandplanId.val]];
|
||||
}
|
||||
|
||||
if (bandPlanEnabled.changed()) {
|
||||
wtf.bandplan = bandPlanEnabled.val ? &bandplan::bandplans[bandplan::bandplanNames[bandplanId.val]] : NULL;
|
||||
}
|
||||
|
||||
ImVec2 vMin = ImGui::GetWindowContentRegionMin();
|
||||
@ -352,6 +357,10 @@ void drawWindow() {
|
||||
ImGui::PushItemWidth(ImGui::GetWindowSize().x);
|
||||
ImGui::Combo("##_4_", &bandplanId.val, bandplan::bandplanNameTxt.c_str());
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::Checkbox("Enabled", &bandPlanEnabled.val);
|
||||
bandplan::BandPlan_t plan = bandplan::bandplans[bandplan::bandplanNames[bandplanId.val]];
|
||||
ImGui::Text("Country: %s (%s)", plan.countryName, plan.countryCode);
|
||||
ImGui::Text("Author: %s", plan.authorName);
|
||||
}
|
||||
|
||||
ImGui::CollapsingHeader("Display");
|
||||
|
@ -289,6 +289,65 @@ namespace ImGui {
|
||||
waterfallUpdate = true;
|
||||
}
|
||||
|
||||
void WaterFall::drawBandPlan() {
|
||||
int count = bandplan->bands.size();
|
||||
float horizScale = (float)dataWidth / viewBandwidth;
|
||||
float start, end, center, aPos, bPos, cPos, width;
|
||||
ImVec2 txtSz;
|
||||
bool startVis, endVis;
|
||||
uint32_t color, colorTrans;
|
||||
for (int i = 0; i < count; i++) {
|
||||
start = bandplan->bands[i].start;
|
||||
end = bandplan->bands[i].end;
|
||||
if (start < lowerFreq && end < lowerFreq) {
|
||||
continue;
|
||||
}
|
||||
if (start > upperFreq && end > upperFreq) {
|
||||
continue;
|
||||
}
|
||||
startVis = (start > lowerFreq);
|
||||
endVis = (end < upperFreq);
|
||||
start = std::clamp<float>(start, lowerFreq, upperFreq);
|
||||
end = std::clamp<float>(end, lowerFreq, upperFreq);
|
||||
center = (start + end) / 2.0f;
|
||||
aPos = widgetPos.x + 50 + ((start - lowerFreq) * horizScale);
|
||||
bPos = widgetPos.x + 50 + ((end - lowerFreq) * horizScale);
|
||||
cPos = widgetPos.x + 50 + ((center - lowerFreq) * horizScale);
|
||||
width = bPos - aPos;
|
||||
txtSz = ImGui::CalcTextSize(bandplan->bands[i].name.c_str());
|
||||
if (bandplan::colorTable.find(bandplan->bands[i].type.c_str()) != bandplan::colorTable.end()) {
|
||||
color = bandplan::colorTable[bandplan->bands[i].type].colorValue;
|
||||
colorTrans = bandplan::colorTable[bandplan->bands[i].type].transColorValue;
|
||||
}
|
||||
else {
|
||||
color = IM_COL32(255, 255, 255, 255);
|
||||
colorTrans = IM_COL32(255, 255, 255, 100);
|
||||
}
|
||||
if (aPos <= widgetPos.x + 50) {
|
||||
aPos = widgetPos.x + 51;
|
||||
}
|
||||
if (bPos <= widgetPos.x + 50) {
|
||||
bPos = widgetPos.x + 51;
|
||||
}
|
||||
if (width >= 1.0f) {
|
||||
window->DrawList->AddRectFilled(ImVec2(roundf(aPos), widgetPos.y + fftHeight - 25),
|
||||
ImVec2(roundf(bPos), widgetPos.y + fftHeight + 10), colorTrans);
|
||||
if (startVis) {
|
||||
window->DrawList->AddLine(ImVec2(roundf(aPos), widgetPos.y + fftHeight - 26),
|
||||
ImVec2(roundf(aPos), widgetPos.y + fftHeight + 9), color);
|
||||
}
|
||||
if (endVis) {
|
||||
window->DrawList->AddLine(ImVec2(roundf(bPos), widgetPos.y + fftHeight - 26),
|
||||
ImVec2(roundf(bPos), widgetPos.y + fftHeight + 9), color);
|
||||
}
|
||||
}
|
||||
if (txtSz.x <= width) {
|
||||
window->DrawList->AddText(ImVec2(cPos - (txtSz.x / 2.0f), widgetPos.y + fftHeight - 17),
|
||||
IM_COL32(255, 255, 255, 255), bandplan->bands[i].name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WaterFall::updateWaterfallTexture() {
|
||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
@ -355,6 +414,9 @@ namespace ImGui {
|
||||
drawFFT();
|
||||
drawWaterfall();
|
||||
drawVFO();
|
||||
if (bandplan != NULL) {
|
||||
drawBandPlan();
|
||||
}
|
||||
|
||||
buf_mtx.unlock();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <mutex>
|
||||
#include <GL/glew.h>
|
||||
#include <imutils.h>
|
||||
#include <bandplan.h>
|
||||
|
||||
#define WATERFALL_RESOLUTION 1000000
|
||||
|
||||
@ -58,6 +59,8 @@ namespace ImGui {
|
||||
|
||||
bool centerFreqMoved = false;
|
||||
bool vfoFreqChanged = false;
|
||||
bool bandplanEnabled = false;
|
||||
bandplan::BandPlan_t* bandplan = NULL;
|
||||
|
||||
enum {
|
||||
REF_LOWER,
|
||||
@ -71,6 +74,7 @@ namespace ImGui {
|
||||
void drawWaterfall();
|
||||
void drawFFT();
|
||||
void drawVFO();
|
||||
void drawBandPlan();
|
||||
void onPositionChange();
|
||||
void onResize();
|
||||
void updateWaterfallFb();
|
||||
|
Reference in New Issue
Block a user