Skip to content

Commit

Permalink
decouple RST settings from startup settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed May 1, 2024
1 parent 77efc4d commit 5692356
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/Generator/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/Generator/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/VNA/vna.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 15 additions & 9 deletions Software/PC_Application/LibreVNA-GUI/appwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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<VNA*>(modeHandler->getActiveMode());
if(vna) {
vna->Stop();
}
auto sa = dynamic_cast<SpectrumAnalyzer*>(modeHandler->getActiveMode());
if(sa) {
sa->Stop();
}
SetResetState();
ResetReference();
return SCPI::getResultName(SCPI::Result::Empty);
}, nullptr));
Expand Down
1 change: 1 addition & 0 deletions Software/PC_Application/LibreVNA-GUI/appwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(){}

Expand Down

0 comments on commit 5692356

Please sign in to comment.