Skip to content

Commit 9909688

Browse files
author
Ryzerth
committed
Changed to a better way of selecting sample rate on the plutosdr
1 parent f16c296 commit 9909688

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

plutosdr_source/src/main.cpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,27 @@ class PlutoSDRSourceModule : public ModuleManager::Instance {
3939
sampleRate = config.conf["sampleRate"];
4040
gainMode = config.conf["gainMode"];
4141
gain = config.conf["gain"];
42-
config.release();
42+
config.release();
43+
44+
// Generate the samplerate list and find srId
45+
bool found = false;
46+
int id = 0;
47+
for (double sr = 1000000; sr <= 20000000; sr += 500000) {
48+
sampleRates.push_back(sr);
49+
sampleRatesTxt += getBandwdithScaled(sr);
50+
sampleRatesTxt += '\0';
51+
52+
if (sr == sampleRate) {
53+
found = true;
54+
srId = id;
55+
}
56+
57+
id++;
58+
}
59+
if (!found) {
60+
srId = 0;
61+
sampleRate = sampleRates[0];
62+
}
4363

4464
handler.ctx = this;
4565
handler.selectHandler = menuSelected;
@@ -72,6 +92,20 @@ class PlutoSDRSourceModule : public ModuleManager::Instance {
7292
}
7393

7494
private:
95+
std::string getBandwdithScaled(double bw) {
96+
char buf[1024];
97+
if (bw >= 1000000.0) {
98+
sprintf(buf, "%.1lfMHz", bw / 1000000.0);
99+
}
100+
else if (bw >= 1000.0) {
101+
sprintf(buf, "%.1lfKHz", bw / 1000.0);
102+
}
103+
else {
104+
sprintf(buf, "%.1lfHz", bw);
105+
}
106+
return std::string(buf);
107+
}
108+
75109
static void menuSelected(void* ctx) {
76110
PlutoSDRSourceModule* _this = (PlutoSDRSourceModule*)ctx;
77111
core::setInputSampleRate(_this->sampleRate);
@@ -153,6 +187,7 @@ class PlutoSDRSourceModule : public ModuleManager::Instance {
153187
PlutoSDRSourceModule* _this = (PlutoSDRSourceModule*)ctx;
154188
float menuWidth = ImGui::GetContentRegionAvailWidth();
155189

190+
if (_this->running) { style::beginDisabled(); }
156191
ImGui::Text("IP");
157192
ImGui::SameLine();
158193
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
@@ -165,9 +200,9 @@ class PlutoSDRSourceModule : public ModuleManager::Instance {
165200
ImGui::Text("Samplerate");
166201
ImGui::SameLine();
167202
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
168-
if (_this->running) { style::beginDisabled(); }
169-
if (ImGui::InputFloat(CONCAT("##_samplerate_select_", _this->name), &_this->sampleRate, 1, 1000, 0)) {
170-
_this->sampleRate = std::clamp<float>(_this->sampleRate, 500000, 61000000);
203+
204+
if (ImGui::Combo(CONCAT("##_pluto_sr_", _this->name), &_this->srId, _this->sampleRatesTxt.c_str())) {
205+
_this->sampleRate = _this->sampleRates[_this->srId];
171206
core::setInputSampleRate(_this->sampleRate);
172207
config.acquire();
173208
config.conf["sampleRate"] = _this->sampleRate;
@@ -256,6 +291,10 @@ class PlutoSDRSourceModule : public ModuleManager::Instance {
256291
char ip[1024] = "ip:192.168.2.1";
257292
int gainMode = 0;
258293
float gain = 0;
294+
int srId = 0;
295+
296+
std::vector<double> sampleRates;
297+
std::string sampleRatesTxt;
259298
};
260299

261300
MOD_EXPORT void _INIT_() {

0 commit comments

Comments
 (0)