Working generator mode

This commit is contained in:
Jan Käberich 2020-09-13 18:01:32 +02:00
parent b7033a029e
commit aae01a602e
14 changed files with 172 additions and 39 deletions

Binary file not shown.

View file

@ -19,7 +19,9 @@ void Generator::updateDevice()
// can't updat if not connected
return;
}
auto status = central->getDeviceStatus();
// TODO comment in once status is filled with valid values
// window->getDevice()->SetManual(status);
Protocol::PacketInfo p;
p.type = Protocol::PacketType::Generator;
p.generator = central->getDeviceStatus();
window->getDevice()->SendPacket(p);
}

View file

@ -42,10 +42,18 @@ SignalgeneratorWidget::~SignalgeneratorWidget()
delete ui;
}
Protocol::ManualControl SignalgeneratorWidget::getDeviceStatus()
Protocol::GeneratorSettings SignalgeneratorWidget::getDeviceStatus()
{
// TODO
Protocol::ManualControl s = {};
Protocol::GeneratorSettings s = {};
s.frequency = ui->frequency->value();
s.cdbm_level = ui->levelSpin->value() * 100.0;
if(ui->EnablePort1->isChecked()) {
s.activePort = 1;
} else if(ui->EnablePort2->isChecked()) {
s.activePort = 2;
} else {
s.activePort = 0;
}
return s;
}

View file

@ -16,7 +16,7 @@ public:
explicit SignalgeneratorWidget(QWidget *parent = nullptr);
~SignalgeneratorWidget();
Protocol::ManualControl getDeviceStatus();
Protocol::GeneratorSettings getDeviceStatus();
signals:
void SettingsChanged();

View file

@ -126,21 +126,31 @@ VNA::VNA(AppWindow *window)
auto impedanceMatching = toolsMenu->addAction("Impedance Matching");
connect(impedanceMatching, &QAction::triggered, this, &VNA::StartImpedanceMatching);
connect(window->getUi()->actionAssignDefaultCal, &QAction::triggered, [=](){
defaultCalMenu = new QMenu("Default Calibration");
assignDefaultCal = defaultCalMenu->addAction("Assign...");
removeDefaultCal = defaultCalMenu->addAction("Remove");
removeDefaultCal->setEnabled(false);
defaultCalMenu->setEnabled(false);
actions.insert(window->getUi()->menuDevice->addSeparator());
window->getUi()->menuDevice->addMenu(defaultCalMenu);
actions.insert(defaultCalMenu->menuAction());
connect(assignDefaultCal, &QAction::triggered, [=](){
if(window->getDevice()) {
auto key = "DefaultCalibration"+window->getDevice()->serial();
QSettings settings;
auto filename = QFileDialog::getOpenFileName(nullptr, "Load calibration data", settings.value(key).toString(), "Calibration files (*.cal)", nullptr, QFileDialog::DontUseNativeDialog);
if(!filename.isEmpty()) {
settings.setValue(key, filename);
window->getUi()->actionRemoveDefaultCal->setEnabled(true);
removeDefaultCal->setEnabled(true);
}
}
});
connect(window->getUi()->actionRemoveDefaultCal, &QAction::triggered, [=](){
connect(removeDefaultCal, &QAction::triggered, [=](){
QSettings settings;
settings.remove("DefaultCalibration"+window->getDevice()->serial());
window->getUi()->actionRemoveDefaultCal->setEnabled(false);
removeDefaultCal->setEnabled(false);
});
@ -432,6 +442,7 @@ void VNA::deactivate()
void VNA::initializeDevice()
{
defaultCalMenu->setEnabled(true);
connect(window->getDevice(), &Device::DatapointReceived, this, &VNA::NewDatapoint, Qt::UniqueConnection);
// Check if default calibration exists and attempt to load it
QSettings s;
@ -443,15 +454,20 @@ void VNA::initializeDevice()
cal.openFromFile(filename);
ApplyCalibration(cal.getType());
}
window->getUi()->actionRemoveDefaultCal->setEnabled(true);
removeDefaultCal->setEnabled(true);
} else {
qDebug() << "No default calibration file set for this device";
window->getUi()->actionRemoveDefaultCal->setEnabled(false);
removeDefaultCal->setEnabled(false);
}
// Configure initial state of device
window->getDevice()->Configure(settings);
}
void VNA::deviceDisconnected()
{
defaultCalMenu->setEnabled(false);
}
using namespace std;
void VNA::NewDatapoint(Protocol::Datapoint d)

View file

@ -15,6 +15,7 @@ public:
void deactivate() override;
void initializeDevice() override;
void deviceDisconnected() override;
private slots:
void NewDatapoint(Protocol::Datapoint d);
void StartImpedanceMatching();
@ -63,6 +64,9 @@ private:
bool calWaitFirst;
QProgressDialog calDialog;
QMenu *defaultCalMenu;
QAction *assignDefaultCal, *removeDefaultCal;
// Status Labels
QLabel *lStart, *lCenter, *lStop, *lSpan, *lPoints, *lBandwidth;
QLabel *lCalibration;

View file

@ -168,11 +168,19 @@ void AppWindow::ConnectToDevice(QString serial)
});
ui->actionDisconnect->setEnabled(true);
ui->actionManual_Control->setEnabled(true);
ui->menuDefault_Calibration->setEnabled(true);
ui->actionFirmware_Update->setEnabled(true);
Mode::getActiveMode()->initializeDevice();
UpdateReference();
for(auto d : deviceActionGroup->actions()) {
if(d->text() == device->serial()) {
d->blockSignals(true);
d->setChecked(true);
d->blockSignals(false);
break;
}
}
} catch (const runtime_error e) {
DisconnectDevice();
UpdateDeviceList();
@ -187,13 +195,13 @@ void AppWindow::DisconnectDevice()
}
ui->actionDisconnect->setEnabled(false);
ui->actionManual_Control->setEnabled(false);
ui->menuDefault_Calibration->setEnabled(false);
ui->actionFirmware_Update->setEnabled(false);
if(deviceActionGroup->checkedAction()) {
deviceActionGroup->checkedAction()->setChecked(false);
}
lConnectionStatus.setText("No device connected");
lDeviceInfo.setText("No device information available yet");
Mode::getActiveMode()->deviceDisconnected();
}
void AppWindow::DeviceConnectionLost()

View file

@ -42,22 +42,11 @@
</property>
<addaction name="actionDummy"/>
</widget>
<widget class="QMenu" name="menuDefault_Calibration">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title">
<string>Default Calibration</string>
</property>
<addaction name="actionAssignDefaultCal"/>
<addaction name="actionRemoveDefaultCal"/>
</widget>
<addaction name="actionUpdate_Device_List"/>
<addaction name="menuConnect_to"/>
<addaction name="actionDisconnect"/>
<addaction name="separator"/>
<addaction name="actionManual_Control"/>
<addaction name="menuDefault_Calibration"/>
<addaction name="actionFirmware_Update"/>
</widget>
<widget class="QMenu" name="menuWindow">
@ -137,19 +126,6 @@
<string>Dummy</string>
</property>
</action>
<action name="actionAssignDefaultCal">
<property name="text">
<string>Assign...</string>
</property>
</action>
<action name="actionRemoveDefaultCal">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Remove</string>
</property>
</action>
<action name="actionFirmware_Update">
<property name="enabled">
<bool>false</bool>

View file

@ -19,6 +19,7 @@ public:
static Mode *getActiveMode();
virtual void initializeDevice() = 0;
virtual void deviceDisconnected(){};
protected:
// call once the derived class is fully initialized