diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index aba95566..970388ef 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -322,6 +322,7 @@ namespace ImGui { } hzDist = std::clamp(hzDist, relatedVfo->minBandwidth, relatedVfo->maxBandwidth); relatedVfo->setBandwidth(hzDist); + relatedVfo->onUserChangedBandwidth.emit(hzDist); return; } diff --git a/core/src/gui/widgets/waterfall.h b/core/src/gui/widgets/waterfall.h index 43622811..55e4c798 100644 --- a/core/src/gui/widgets/waterfall.h +++ b/core/src/gui/widgets/waterfall.h @@ -67,6 +67,8 @@ namespace ImGui { bool bandwidthLocked; ImU32 color = IM_COL32(255, 255, 255, 50); + + Event onUserChangedBandwidth; }; class WaterFall { diff --git a/core/src/signal_path/vfo_manager.h b/core/src/signal_path/vfo_manager.h index bd4e452b..e932eb1f 100644 --- a/core/src/signal_path/vfo_manager.h +++ b/core/src/signal_path/vfo_manager.h @@ -30,10 +30,11 @@ public: friend class VFOManager; - private: - std::string name; dsp::VFO* dspVFO; ImGui::WaterfallVFO* wtfVFO; + + private: + std::string name; }; diff --git a/radio/src/am_demod.h b/radio/src/am_demod.h index 4144a2ff..56152e99 100644 --- a/radio/src/am_demod.h +++ b/radio/src/am_demod.h @@ -55,6 +55,11 @@ public: resamp.updateWindow(&win); m2s.init(&resamp.out); + + onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler; + onUserChangedBandwidthHandler.ctx = this; + + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } void start() { @@ -89,6 +94,7 @@ public: void setVFO(VFOManager::VFO* vfo) { _vfo = vfo; squelch.setInput(_vfo->output); + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } VFOManager::VFO* getVFO() { @@ -130,15 +136,6 @@ public: _config->conf[uiPrefix]["AM"]["bandwidth"] = bw; _config->release(true); } - if (running) { - if (_vfo->getBandwidthChanged()) { - bw = _vfo->getBandwidth(); - setBandwidth(bw, false); - _config->acquire(); - _config->conf[uiPrefix]["AM"]["bandwidth"] = bw; - _config->release(true); - } - } ImGui::Text("Snap Interval"); ImGui::SameLine(); @@ -160,7 +157,18 @@ public: _config->conf[uiPrefix]["AM"]["squelchLevel"] = squelchLevel; _config->release(true); } - } + } + + static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) { + AMDemodulator* _this = (AMDemodulator*)ctx; + if (_this->running) { + _this->bw = newBw; + _this->setBandwidth(_this->bw, false); + _this->_config->acquire(); + _this->_config->conf[_this->uiPrefix]["AM"]["bandwidth"] = _this->bw; + _this->_config->release(true); + } + } void setBandwidth(float bandWidth, bool updateWaterfall = true) { bandWidth = std::clamp(bandWidth, bwMin, bwMax); @@ -175,9 +183,9 @@ public: void saveParameters(bool lock = true) { if (lock) { _config->acquire(); } - _config->conf[uiPrefix]["WFM"]["bandwidth"] = bw; - _config->conf[uiPrefix]["WFM"]["snapInterval"] = snapInterval; - _config->conf[uiPrefix]["WFM"]["squelchLevel"] = squelchLevel; + _config->conf[uiPrefix]["AM"]["bandwidth"] = bw; + _config->conf[uiPrefix]["AM"]["snapInterval"] = snapInterval; + _config->conf[uiPrefix]["AM"]["squelchLevel"] = squelchLevel; if (lock) { _config->release(true); } } @@ -208,4 +216,6 @@ private: ConfigManager* _config; + EventHandler onUserChangedBandwidthHandler; + }; \ No newline at end of file diff --git a/radio/src/cw_demod.h b/radio/src/cw_demod.h index 93c3bc4f..79a01b05 100644 --- a/radio/src/cw_demod.h +++ b/radio/src/cw_demod.h @@ -57,6 +57,11 @@ public: resamp.updateWindow(&win); m2s.init(&resamp.out); + + onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler; + onUserChangedBandwidthHandler.ctx = this; + + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } void start() { @@ -93,6 +98,7 @@ public: void setVFO(VFOManager::VFO* vfo) { _vfo = vfo; squelch.setInput(_vfo->output); + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } VFOManager::VFO* getVFO() { @@ -133,14 +139,6 @@ public: _config->acquire(); _config->conf[uiPrefix]["CW"]["bandwidth"] = bw; _config->release(true); - }if (running) { - if (_vfo->getBandwidthChanged()) { - bw = _vfo->getBandwidth(); - setBandwidth(bw, false); - _config->acquire(); - _config->conf[uiPrefix]["CW"]["bandwidth"] = bw; - _config->release(true); - } } ImGui::Text("Snap Interval"); @@ -163,7 +161,18 @@ public: _config->conf[uiPrefix]["CW"]["squelchLevel"] = squelchLevel; _config->release(true); } - } + } + + static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) { + CWDemodulator* _this = (CWDemodulator*)ctx; + if (_this->running) { + _this->bw = newBw; + _this->setBandwidth(_this->bw, false); + _this->_config->acquire(); + _this->_config->conf[_this->uiPrefix]["CW"]["bandwidth"] = _this->bw; + _this->_config->release(true); + } + } void setBandwidth(float bandWidth, bool updateWaterfall = true) { bandWidth = std::clamp(bandWidth, bwMin, bwMax); @@ -178,9 +187,9 @@ public: void saveParameters(bool lock = true) { if (lock) { _config->acquire(); } - _config->conf[uiPrefix]["WFM"]["bandwidth"] = bw; - _config->conf[uiPrefix]["WFM"]["snapInterval"] = snapInterval; - _config->conf[uiPrefix]["WFM"]["squelchLevel"] = squelchLevel; + _config->conf[uiPrefix]["CW"]["bandwidth"] = bw; + _config->conf[uiPrefix]["CW"]["snapInterval"] = snapInterval; + _config->conf[uiPrefix]["CW"]["squelchLevel"] = squelchLevel; if (lock) { _config->release(true); } } @@ -212,4 +221,6 @@ private: ConfigManager* _config; + EventHandler onUserChangedBandwidthHandler; + }; \ No newline at end of file diff --git a/radio/src/dsb_demod.h b/radio/src/dsb_demod.h index aa686570..bd9e880e 100644 --- a/radio/src/dsb_demod.h +++ b/radio/src/dsb_demod.h @@ -55,6 +55,11 @@ public: resamp.updateWindow(&win); m2s.init(&resamp.out); + + onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler; + onUserChangedBandwidthHandler.ctx = this; + + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } void start() { @@ -89,6 +94,7 @@ public: void setVFO(VFOManager::VFO* vfo) { _vfo = vfo; squelch.setInput(_vfo->output); + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } VFOManager::VFO* getVFO() { @@ -130,15 +136,6 @@ public: _config->conf[uiPrefix]["DSB"]["bandwidth"] = bw; _config->release(true); } - if (running) { - if (_vfo->getBandwidthChanged()) { - bw = _vfo->getBandwidth(); - setBandwidth(bw, false); - _config->acquire(); - _config->conf[uiPrefix]["DSB"]["bandwidth"] = bw; - _config->release(true); - } - } ImGui::Text("Snap Interval"); ImGui::SameLine(); @@ -160,7 +157,18 @@ public: _config->conf[uiPrefix]["DSB"]["squelchLevel"] = squelchLevel; _config->release(true); } - } + } + + static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) { + DSBDemodulator* _this = (DSBDemodulator*)ctx; + if (_this->running) { + _this->bw = newBw; + _this->setBandwidth(_this->bw, false); + _this->_config->acquire(); + _this->_config->conf[_this->uiPrefix]["DSB"]["bandwidth"] = _this->bw; + _this->_config->release(true); + } + } void setBandwidth(float bandWidth, bool updateWaterfall = true) { bandWidth = std::clamp(bandWidth, bwMin, bwMax); @@ -170,9 +178,9 @@ public: void saveParameters(bool lock = true) { if (lock) { _config->acquire(); } - _config->conf[uiPrefix]["WFM"]["bandwidth"] = bw; - _config->conf[uiPrefix]["WFM"]["snapInterval"] = snapInterval; - _config->conf[uiPrefix]["WFM"]["squelchLevel"] = squelchLevel; + _config->conf[uiPrefix]["DSB"]["bandwidth"] = bw; + _config->conf[uiPrefix]["DSB"]["snapInterval"] = snapInterval; + _config->conf[uiPrefix]["DSB"]["squelchLevel"] = squelchLevel; if (lock) { _config->release(true); } } @@ -203,4 +211,6 @@ private: ConfigManager* _config; + EventHandler onUserChangedBandwidthHandler; + }; \ No newline at end of file diff --git a/radio/src/fm_demod.h b/radio/src/fm_demod.h index 7d7cfe53..1bea3520 100644 --- a/radio/src/fm_demod.h +++ b/radio/src/fm_demod.h @@ -51,6 +51,11 @@ public: resamp.init(&demod.out, &win, bbSampRate, audioSampRate); win.setSampleRate(bbSampRate * resamp.getInterpolation()); resamp.updateWindow(&win); + + onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler; + onUserChangedBandwidthHandler.ctx = this; + + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } void start() { @@ -81,6 +86,7 @@ public: void setVFO(VFOManager::VFO* vfo) { _vfo = vfo; squelch.setInput(_vfo->output); + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } VFOManager::VFO* getVFO() { @@ -122,15 +128,6 @@ public: _config->conf[uiPrefix]["FM"]["bandwidth"] = bw; _config->release(true); } - if (running) { - if (_vfo->getBandwidthChanged()) { - bw = _vfo->getBandwidth(); - setBandwidth(bw, false); - _config->acquire(); - _config->conf[uiPrefix]["FM"]["bandwidth"] = bw; - _config->release(true); - } - } ImGui::Text("Snap Interval"); ImGui::SameLine(); @@ -152,7 +149,18 @@ public: _config->conf[uiPrefix]["FM"]["squelchLevel"] = squelchLevel; _config->release(true); } - } + } + + static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) { + FMDemodulator* _this = (FMDemodulator*)ctx; + if (_this->running) { + _this->bw = newBw; + _this->setBandwidth(_this->bw, false); + _this->_config->acquire(); + _this->_config->conf[_this->uiPrefix]["FM"]["bandwidth"] = _this->bw; + _this->_config->release(true); + } + } void setBandwidth(float bandWidth, bool updateWaterfall = true) { bandWidth = std::clamp(bandWidth, bwMin, bwMax); @@ -164,9 +172,9 @@ public: void saveParameters(bool lock = true) { if (lock) { _config->acquire(); } - _config->conf[uiPrefix]["WFM"]["bandwidth"] = bw; - _config->conf[uiPrefix]["WFM"]["snapInterval"] = snapInterval; - _config->conf[uiPrefix]["WFM"]["squelchLevel"] = squelchLevel; + _config->conf[uiPrefix]["FM"]["bandwidth"] = bw; + _config->conf[uiPrefix]["FM"]["snapInterval"] = snapInterval; + _config->conf[uiPrefix]["FM"]["squelchLevel"] = squelchLevel; if (lock) { _config->release(true); } } @@ -195,4 +203,6 @@ private: ConfigManager* _config; + EventHandler onUserChangedBandwidthHandler; + }; \ No newline at end of file diff --git a/radio/src/lsb_demod.h b/radio/src/lsb_demod.h index 0d68b1ff..563d0ef8 100644 --- a/radio/src/lsb_demod.h +++ b/radio/src/lsb_demod.h @@ -55,6 +55,11 @@ public: resamp.updateWindow(&win); m2s.init(&resamp.out); + + onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler; + onUserChangedBandwidthHandler.ctx = this; + + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } void start() { @@ -89,6 +94,7 @@ public: void setVFO(VFOManager::VFO* vfo) { _vfo = vfo; squelch.setInput(_vfo->output); + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } VFOManager::VFO* getVFO() { @@ -129,14 +135,6 @@ public: _config->acquire(); _config->conf[uiPrefix]["LSB"]["bandwidth"] = bw; _config->release(true); - }if (running) { - if (_vfo->getBandwidthChanged()) { - bw = _vfo->getBandwidth(); - setBandwidth(bw, false); - _config->acquire(); - _config->conf[uiPrefix]["LSB"]["bandwidth"] = bw; - _config->release(true); - } } ImGui::Text("Snap Interval"); @@ -159,7 +157,18 @@ public: _config->conf[uiPrefix]["LSB"]["squelchLevel"] = squelchLevel; _config->release(true); } - } + } + + static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) { + LSBDemodulator* _this = (LSBDemodulator*)ctx; + if (_this->running) { + _this->bw = newBw; + _this->setBandwidth(_this->bw, false); + _this->_config->acquire(); + _this->_config->conf[_this->uiPrefix]["LSB"]["bandwidth"] = _this->bw; + _this->_config->release(true); + } + } void setBandwidth(float bandWidth, bool updateWaterfall = true) { bandWidth = std::clamp(bandWidth, bwMin, bwMax); @@ -175,9 +184,9 @@ public: void saveParameters(bool lock = true) { if (lock) { _config->acquire(); } - _config->conf[uiPrefix]["WFM"]["bandwidth"] = bw; - _config->conf[uiPrefix]["WFM"]["snapInterval"] = snapInterval; - _config->conf[uiPrefix]["WFM"]["squelchLevel"] = squelchLevel; + _config->conf[uiPrefix]["LSB"]["bandwidth"] = bw; + _config->conf[uiPrefix]["LSB"]["snapInterval"] = snapInterval; + _config->conf[uiPrefix]["LSB"]["squelchLevel"] = squelchLevel; if (lock) { _config->release(true); } } @@ -208,4 +217,6 @@ private: ConfigManager* _config; + EventHandler onUserChangedBandwidthHandler; + }; \ No newline at end of file diff --git a/radio/src/raw_demod.h b/radio/src/raw_demod.h index 057a4e92..53602df8 100644 --- a/radio/src/raw_demod.h +++ b/radio/src/raw_demod.h @@ -120,8 +120,8 @@ public: void saveParameters(bool lock = true) { if (lock) { _config->acquire(); } - _config->conf[uiPrefix]["WFM"]["snapInterval"] = snapInterval; - _config->conf[uiPrefix]["WFM"]["squelchLevel"] = squelchLevel; + _config->conf[uiPrefix]["RAW"]["snapInterval"] = snapInterval; + _config->conf[uiPrefix]["RAW"]["squelchLevel"] = squelchLevel; if (lock) { _config->release(true); } } diff --git a/radio/src/usb_demod.h b/radio/src/usb_demod.h index 4347643e..205ba845 100644 --- a/radio/src/usb_demod.h +++ b/radio/src/usb_demod.h @@ -55,6 +55,11 @@ public: resamp.updateWindow(&win); m2s.init(&resamp.out); + + onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler; + onUserChangedBandwidthHandler.ctx = this; + + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } void start() { @@ -89,6 +94,7 @@ public: void setVFO(VFOManager::VFO* vfo) { _vfo = vfo; squelch.setInput(_vfo->output); + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } VFOManager::VFO* getVFO() { @@ -129,14 +135,6 @@ public: _config->acquire(); _config->conf[uiPrefix]["USB"]["bandwidth"] = bw; _config->release(true); - }if (running) { - if (_vfo->getBandwidthChanged()) { - bw = _vfo->getBandwidth(); - setBandwidth(bw, false); - _config->acquire(); - _config->conf[uiPrefix]["USB"]["bandwidth"] = bw; - _config->release(true); - } } ImGui::Text("Snap Interval"); @@ -159,7 +157,18 @@ public: _config->conf[uiPrefix]["USB"]["squelchLevel"] = squelchLevel; _config->release(true); } - } + } + + static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) { + USBDemodulator* _this = (USBDemodulator*)ctx; + if (_this->running) { + _this->bw = newBw; + _this->setBandwidth(_this->bw, false); + _this->_config->acquire(); + _this->_config->conf[_this->uiPrefix]["USB"]["bandwidth"] = _this->bw; + _this->_config->release(true); + } + } void setBandwidth(float bandWidth, bool updateWaterfall = true) { bandWidth = std::clamp(bandWidth, bwMin, bwMax); @@ -175,9 +184,9 @@ public: void saveParameters(bool lock = true) { if (lock) { _config->acquire(); } - _config->conf[uiPrefix]["WFM"]["bandwidth"] = bw; - _config->conf[uiPrefix]["WFM"]["snapInterval"] = snapInterval; - _config->conf[uiPrefix]["WFM"]["squelchLevel"] = squelchLevel; + _config->conf[uiPrefix]["USB"]["bandwidth"] = bw; + _config->conf[uiPrefix]["USB"]["snapInterval"] = snapInterval; + _config->conf[uiPrefix]["USB"]["squelchLevel"] = squelchLevel; if (lock) { _config->release(true); } } @@ -208,4 +217,6 @@ private: ConfigManager* _config; + EventHandler onUserChangedBandwidthHandler; + }; \ No newline at end of file diff --git a/radio/src/wfm_demod.h b/radio/src/wfm_demod.h index 9047a99f..bd5d67c7 100644 --- a/radio/src/wfm_demod.h +++ b/radio/src/wfm_demod.h @@ -72,6 +72,10 @@ public: if (deempId == 2) { deemp.bypass = true; } + onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler; + onUserChangedBandwidthHandler.ctx = this; + + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } void start() { @@ -114,6 +118,7 @@ public: void setVFO(VFOManager::VFO* vfo) { _vfo = vfo; squelch.setInput(_vfo->output); + _vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler); } VFOManager::VFO* getVFO() { @@ -158,15 +163,6 @@ public: _config->conf[uiPrefix]["WFM"]["bandwidth"] = bw; _config->release(true); } - if (running) { - if (_vfo->getBandwidthChanged()) { - bw = _vfo->getBandwidth(); - setBandwidth(bw, false); - _config->acquire(); - _config->conf[uiPrefix]["WFM"]["bandwidth"] = bw; - _config->release(true); - } - } ImGui::Text("Snap Interval"); ImGui::SameLine(); @@ -208,6 +204,17 @@ public: } } + static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) { + WFMDemodulator* _this = (WFMDemodulator*)ctx; + if (_this->running) { + _this->bw = newBw; + _this->setBandwidth(_this->bw, false); + _this->_config->acquire(); + _this->_config->conf[_this->uiPrefix]["WFM"]["bandwidth"] = _this->bw; + _this->_config->release(true); + } + } + void setDeempIndex(int id) { if (id >= 2 || id < 0) { deemp.bypass = true; @@ -286,4 +293,6 @@ private: ConfigManager* _config; + EventHandler onUserChangedBandwidthHandler; + }; \ No newline at end of file