diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 24556c1..468a147 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -287,9 +287,6 @@ AppFrame::AppFrame() : this->SetSizer(vbox); - // waterfallCanvas->SetFocusFromKbd(); -// waterfallCanvas->SetFocus(); - // SetIcon(wxICON(sample)); // Make a menubar @@ -1196,16 +1193,6 @@ void AppFrame::OnIdle(wxIdleEvent& event) { } } -// if (demodTuner->getMouseTracker()->mouseInView()) { -// if (!demodTuner->HasFocus()) { -// demodTuner->SetFocus(); -// } -// } else if (!wxGetApp().isDeviceSelectorOpen() && (!modemProps || !modemProps->isMouseInView())) { -// if (!waterfallCanvas->HasFocus()) { -// waterfallCanvas->SetFocus(); -// } -// } - scopeCanvas->setPPMMode(demodTuner->isAltDown()); scopeCanvas->setShowDb(spectrumCanvas->getShowDb()); @@ -1543,6 +1530,13 @@ void AppFrame::setMainWaterfallFFTSize(int fftSize) { waterfallCanvas->setFFTSize(fftSize); } + +void AppFrame::refreshGainUI() { + gainCanvas->updateGainUI(); + gainCanvas->Refresh(); +} + + FrequencyDialog::FrequencyDialogTarget AppFrame::getFrequencyDialogTarget() { FrequencyDialog::FrequencyDialogTarget target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_DEFAULT; @@ -1551,7 +1545,8 @@ FrequencyDialog::FrequencyDialogTarget AppFrame::getFrequencyDialogTarget() { } else if (spectrumAvgMeter->getMouseTracker()->mouseInView()) { target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_SPECTRUM_AVG; - } else if (demodTuner->getMouseTracker()->mouseInView()) { + } + else if (demodTuner->getMouseTracker()->mouseInView()) { switch (demodTuner->getHoverState()) { case TuningCanvas::ActiveState::TUNING_HOVER_BW: target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_BANDWIDTH; @@ -1566,6 +1561,9 @@ FrequencyDialog::FrequencyDialogTarget AppFrame::getFrequencyDialogTarget() { } } + else if (gainCanvas->getMouseTracker()->mouseInView()) { + target = FrequencyDialog::FrequencyDialogTarget::FDIALOG_TARGET_GAIN; + } return target; } diff --git a/src/AppFrame.h b/src/AppFrame.h index afd1f0e..df38196 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -83,6 +83,7 @@ public: void setSpectrumAvgSpeed(double avg); FrequencyDialog::FrequencyDialogTarget getFrequencyDialogTarget(); + void refreshGainUI(); private: void OnMenu(wxCommandEvent& event); diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index 5320cfe..836f41a 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -650,23 +650,16 @@ int CubicSDR::getPPM() { return ppm; } -void CubicSDR::setFrequencyInputTarget(FrequencyDialog::FrequencyDialogTarget targetMode) { - fdlgTarget = targetMode; -} - void CubicSDR::showFrequencyInput(FrequencyDialog::FrequencyDialogTarget targetMode, wxString initString) { const wxString demodTitle("Set Demodulator Frequency"); const wxString freqTitle("Set Center Frequency"); const wxString bwTitle("Modem Bandwidth (150Hz - 500KHz)"); const wxString lpsTitle("Lines-Per-Second (1-1024)"); const wxString avgTitle("Average Rate (0.1 - 0.99)"); + const wxString gainTitle("Gain Entry: "+wxGetApp().getActiveGainEntry()); wxString title; -// if (targetMode == FrequencyDialog::FDIALOG_TARGET_DEFAULT && fdlgTarget != FrequencyDialog::FDIALOG_TARGET_DEFAULT) { -// targetMode = fdlgTarget; -// } - switch (targetMode) { case FrequencyDialog::FDIALOG_TARGET_DEFAULT: title = demodMgr.getActiveDemodulator()?demodTitle:freqTitle; @@ -680,6 +673,12 @@ void CubicSDR::showFrequencyInput(FrequencyDialog::FrequencyDialogTarget targetM case FrequencyDialog::FDIALOG_TARGET_SPECTRUM_AVG: title = avgTitle; break; + case FrequencyDialog::FDIALOG_TARGET_GAIN: + title = gainTitle; + if (wxGetApp().getActiveGainEntry() == "") { + return; + } + break; default: break; } @@ -765,6 +764,14 @@ std::string CubicSDR::getModulePath() { return modulePath; } +void CubicSDR::setActiveGainEntry(std::string gainName) { + activeGain = gainName; +} + +std::string CubicSDR::getActiveGainEntry() { + return activeGain; +} + int CubicSDR::FilterEvent(wxEvent& event) { if (!appframe) { return -1; diff --git a/src/CubicSDR.h b/src/CubicSDR.h index c96f18a..4cc4f7e 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -125,7 +125,6 @@ public: void setPPM(int ppm_in); int getPPM(); - void setFrequencyInputTarget(FrequencyDialog::FrequencyDialogTarget targetMode); void showFrequencyInput(FrequencyDialog::FrequencyDialogTarget targetMode = FrequencyDialog::FDIALOG_TARGET_DEFAULT, wxString initString = ""); AppFrame *getAppFrame(); @@ -154,6 +153,9 @@ public: bool getUseLocalMod(); std::string getModulePath(); + void setActiveGainEntry(std::string gainName); + std::string getActiveGainEntry(); + #ifdef USE_HAMLIB RigThread *getRigThread(); void initRig(int rigModel, std::string rigPort, int rigSerialRate); @@ -209,6 +211,7 @@ private: std::atomic_bool frequency_locked; std::atomic_llong lock_freq; FrequencyDialog::FrequencyDialogTarget fdlgTarget; + std::string activeGain; #ifdef USE_HAMLIB RigThread *rigThread; std::thread *t_Rig; diff --git a/src/FrequencyDialog.cpp b/src/FrequencyDialog.cpp index 09b0f19..d36918b 100644 --- a/src/FrequencyDialog.cpp +++ b/src/FrequencyDialog.cpp @@ -39,6 +39,12 @@ FrequencyDialog::FrequencyDialog(wxWindow * parent, wxWindowID id, const wxStrin if (targetMode == FDIALOG_TARGET_SPECTRUM_AVG) { freqStr = std::to_string(wxGetApp().getSpectrumProcessor()->getFFTAverageRate()); } + + if (targetMode == FDIALOG_TARGET_GAIN) { + if (wxGetApp().getActiveGainEntry() != "") { + freqStr = std::to_string((int)wxGetApp().getGain(wxGetApp().getActiveGainEntry())); + } + } dialogText = new wxTextCtrl(this, wxID_FREQ_INPUT, freqStr, wxPoint(6, 1), wxSize(size.GetWidth() - 20, size.GetHeight() - 70), wxTE_PROCESS_ENTER); @@ -123,6 +129,29 @@ void FrequencyDialog::OnChar(wxKeyEvent& event) { } wxGetApp().getAppFrame()->setSpectrumAvgSpeed(dblval); } + + if (targetMode == FDIALOG_TARGET_GAIN) { + try { + freq = std::stoi(strValue); + } catch (exception e) { + break; + } + SDRDeviceInfo *devInfo = wxGetApp().getDevice(); + std::string gainName = wxGetApp().getActiveGainEntry(); + if (gainName == "") { + break; + } + SDRRangeMap gains = devInfo->getGains(SOAPY_SDR_RX, 0); + if (freq > gains[gainName].maximum()) { + freq = gains[gainName].maximum(); + } + if (freq < gains[gainName].minimum()) { + freq = gains[gainName].minimum(); + } + wxGetApp().setGain(gainName, freq); + wxGetApp().getAppFrame()->refreshGainUI(); + } + Close(); break; case WXK_ESCAPE: diff --git a/src/FrequencyDialog.h b/src/FrequencyDialog.h index 768401a..681b4aa 100644 --- a/src/FrequencyDialog.h +++ b/src/FrequencyDialog.h @@ -17,7 +17,8 @@ public: FDIALOG_TARGET_FREQ, FDIALOG_TARGET_BANDWIDTH, FDIALOG_TARGET_WATERFALL_LPS, - FDIALOG_TARGET_SPECTRUM_AVG + FDIALOG_TARGET_SPECTRUM_AVG, + FDIALOG_TARGET_GAIN } FrequencyDialogTarget; FrequencyDialog ( wxWindow * parent, wxWindowID id, const wxString & title, DemodulatorInstance *demod = NULL, diff --git a/src/visual/GainCanvas.cpp b/src/visual/GainCanvas.cpp index 3b82e82..33badba 100644 --- a/src/visual/GainCanvas.cpp +++ b/src/visual/GainCanvas.cpp @@ -132,6 +132,9 @@ void GainCanvas::OnMouseMoved(wxMouseEvent& event) { int i = 0; for (std::vector::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { (*gi)->highlightPanel.visible = (i==panelHit); + if (i==panelHit) { + wxGetApp().setActiveGainEntry((*gi)->name); + } i++; }