diff --git a/Software/PC_Application/LibreVNA-GUI/Generator/generator.cpp b/Software/PC_Application/LibreVNA-GUI/Generator/generator.cpp index b7bac7ec..9a19e56c 100644 --- a/Software/PC_Application/LibreVNA-GUI/Generator/generator.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Generator/generator.cpp @@ -46,6 +46,13 @@ void Generator::initializeDevice() updateDevice(); } +void Generator::resetSettings() +{ + central->setFrequency(1000000000); + central->setLevel(0); + central->setPort(0); +} + nlohmann::json Generator::toJSON() { return central->toJSON(); diff --git a/Software/PC_Application/LibreVNA-GUI/Generator/generator.h b/Software/PC_Application/LibreVNA-GUI/Generator/generator.h index 9df9a3cd..463dbb7b 100644 --- a/Software/PC_Application/LibreVNA-GUI/Generator/generator.h +++ b/Software/PC_Application/LibreVNA-GUI/Generator/generator.h @@ -15,6 +15,8 @@ class Generator : public Mode virtual Type getType() override { return Type::SG;} + virtual void resetSettings() override; + // Nothing to do for now virtual nlohmann::json toJSON() override; virtual void fromJSON(nlohmann::json j) override; diff --git a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp index feb0f63a..aee235c1 100644 --- a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp +++ b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.cpp @@ -366,6 +366,18 @@ void SpectrumAnalyzer::deviceDisconnected() emit sweepStopped(); } +void SpectrumAnalyzer::resetSettings() +{ + settings.freqStart = DeviceDriver::getInfo(window->getDevice()).Limits.SA.minFreq; + settings.freqStop = DeviceDriver::getInfo(window->getDevice()).Limits.SA.maxFreq; + ConstrainAndUpdateFrequencies(); + SetRBW(1000000); + SetAveraging(1); + SetWindow(DeviceDriver::SASettings::Window::FlatTop); + SetDetector(DeviceDriver::SASettings::Detector::PPeak); + Stop(); +} + nlohmann::json SpectrumAnalyzer::toJSON() { nlohmann::json j; diff --git a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.h b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.h index ee52ab8e..5960875b 100644 --- a/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.h +++ b/Software/PC_Application/LibreVNA-GUI/SpectrumAnalyzer/spectrumanalyzer.h @@ -25,6 +25,8 @@ class SpectrumAnalyzer : public Mode virtual Type getType() override { return Type::SA;} + virtual void resetSettings() override; + // Only save/load user changeable stuff, no need to save the widgets/mode name etc. virtual nlohmann::json toJSON() override; virtual void fromJSON(nlohmann::json j) override; diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp index 88c033a1..331d52f0 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp @@ -772,6 +772,23 @@ void VNA::shutdown() } } +void VNA::resetSettings() +{ + settings.Freq.start = DeviceDriver::getInfo(window->getDevice()).Limits.VNA.minFreq; + settings.Freq.stop = DeviceDriver::getInfo(window->getDevice()).Limits.VNA.maxFreq; + SetLogSweep(false); + SetSourceLevel(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.maxdBm); + ConstrainAndUpdateFrequencies(); + SetStartPower(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.mindBm); + SetStopPower(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.maxdBm); + SetPowerSweepFrequency(DeviceDriver::getInfo(window->getDevice()).Limits.VNA.maxFreq); + SetIFBandwidth(1000); + SetAveraging(1); + SetPoints(501); + SetSweepType(SweepType::Frequency); + Stop(); +} + nlohmann::json VNA::toJSON() { nlohmann::json j; diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h index 653b553d..f7285dac 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h @@ -27,6 +27,8 @@ class VNA : public Mode virtual Type getType() override { return Type::VNA;} + virtual void resetSettings() override; + // Only save/load user changeable stuff, no need to save the widgets/mode name etc. virtual nlohmann::json toJSON() override; virtual void fromJSON(nlohmann::json j) override; diff --git a/Software/PC_Application/LibreVNA-GUI/appwindow.cpp b/Software/PC_Application/LibreVNA-GUI/appwindow.cpp index 4235b9f2..452c71aa 100644 --- a/Software/PC_Application/LibreVNA-GUI/appwindow.cpp +++ b/Software/PC_Application/LibreVNA-GUI/appwindow.cpp @@ -324,6 +324,20 @@ void AppWindow::SetInitialState() } } +void AppWindow::SetResetState() +{ + modeHandler->closeModes(); + auto vnaIndex = modeHandler->createMode("Vector Network Analyzer", Mode::Type::VNA); + modeHandler->createMode("Signal Generator", Mode::Type::SG); + modeHandler->createMode("Spectrum Analyzer", Mode::Type::SA); + + for(auto m : modeHandler->getModes()) { + m->resetSettings(); + } + + modeHandler->setCurrentIndex(vnaIndex); +} + bool AppWindow::ConnectToDevice(QString serial, DeviceDriver *driver) { if(serial.isEmpty()) { @@ -487,15 +501,7 @@ void AppWindow::SetupSCPI() return "LibreVNA,LibreVNA-GUI,dummy_serial,"+appVersion; })); scpi.add(new SCPICommand("*RST", [=](QStringList){ - SetInitialState(); - auto vna = dynamic_cast(modeHandler->getActiveMode()); - if(vna) { - vna->Stop(); - } - auto sa = dynamic_cast(modeHandler->getActiveMode()); - if(sa) { - sa->Stop(); - } + SetResetState(); ResetReference(); return SCPI::getResultName(SCPI::Result::Empty); }, nullptr)); diff --git a/Software/PC_Application/LibreVNA-GUI/appwindow.h b/Software/PC_Application/LibreVNA-GUI/appwindow.h index 911390ee..6eb78fba 100644 --- a/Software/PC_Application/LibreVNA-GUI/appwindow.h +++ b/Software/PC_Application/LibreVNA-GUI/appwindow.h @@ -59,6 +59,7 @@ public slots: void closeEvent(QCloseEvent *event) override; private slots: void SetInitialState(); + void SetResetState(); bool ConnectToDevice(QString serial = QString(), DeviceDriver *driver = nullptr); void DisconnectDevice(); int UpdateDeviceList(); diff --git a/Software/PC_Application/LibreVNA-GUI/mode.h b/Software/PC_Application/LibreVNA-GUI/mode.h index 22a77a72..c5c8d073 100644 --- a/Software/PC_Application/LibreVNA-GUI/mode.h +++ b/Software/PC_Application/LibreVNA-GUI/mode.h @@ -36,6 +36,8 @@ class Mode : public QObject, public Savable, public SCPINode static Type TypeFromName(QString s); virtual Type getType() = 0; + virtual void resetSettings(){} + virtual void initializeDevice() = 0; virtual void deviceDisconnected(){}