Implement ganged switches
This commit is contained in:
parent
7a6e674756
commit
81e7e1a5b3
3 changed files with 251 additions and 133 deletions
125
mainwindow.cpp
125
mainwindow.cpp
|
|
@ -1,69 +1,96 @@
|
|||
|
||||
|
||||
#include <eismultiplexer.h>
|
||||
#include <QMessageBox>
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
enumerateDevices();
|
||||
ui->setupUi(this);
|
||||
enumerateDevices();
|
||||
|
||||
connect(ui->actionQuit, &QAction::triggered, this, [this]()
|
||||
{
|
||||
close();
|
||||
});
|
||||
connect(ui->actionQuit, &QAction::triggered, this, [this]()
|
||||
{
|
||||
close();
|
||||
});
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::enumerateDevices()
|
||||
{
|
||||
size_t count = 0;
|
||||
uint16_t* serials = eismultiplexer_list_available_devices(&count);
|
||||
size_t count = 0;
|
||||
uint16_t* serials = eismultiplexer_list_available_devices(&count);
|
||||
|
||||
if (!serials || count == 0)
|
||||
{
|
||||
QMessageBox::warning(nullptr, tr("No Devices Found"),
|
||||
tr("No EIS multiplexer devices were found. Please connect a device and try again."));
|
||||
qWarning() << "No EIS multiplexer devices found";
|
||||
exit(0);
|
||||
return;
|
||||
}
|
||||
if (!serials || count == 0)
|
||||
{
|
||||
QMessageBox::warning(nullptr, tr("No Devices Found"),
|
||||
tr("No EIS multiplexer devices were found. Please connect a device and try again."));
|
||||
qWarning() << "No EIS multiplexer devices found";
|
||||
exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
uint16_t serial = serials[i];
|
||||
std::shared_ptr<struct eismultiplexer> multiplexer(new struct eismultiplexer);
|
||||
int ret = eismultiplexer_connect(multiplexer.get(), serial);
|
||||
if (ret == 0)
|
||||
{
|
||||
uint16_t channelCount = 0;
|
||||
qDebug()<<"Adding channels from device "<<serial;
|
||||
if (eismultiplexer_get_channel_count(multiplexer.get(), &channelCount) >= 0)
|
||||
{
|
||||
for (uint16_t channel = 0; channel < channelCount; channel++)
|
||||
{
|
||||
std::shared_ptr<ChannelWidget> widget(new ChannelWidget(serial, channel, multiplexer));
|
||||
qDebug()<<"Added widget from device "<<serial<<" channel "<<channel;
|
||||
channels.push_back(widget);
|
||||
ui->channelLayout->addWidget(widget.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Connection Failed"),
|
||||
tr("Failed to connect to device with serial %1").arg(serial));
|
||||
qWarning()<<"Failed to connect to device with serial"<<serial<<"eismultiplexer_connect returned"<<ret;
|
||||
}
|
||||
ui->channelLayout->addStretch();
|
||||
}
|
||||
ui->statusbar->showMessage("Ready");
|
||||
// First pass: create all widgets without connecting signals
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
uint16_t serial = serials[i];
|
||||
std::shared_ptr<struct eismultiplexer> multiplexer(new struct eismultiplexer);
|
||||
int ret = eismultiplexer_connect(multiplexer.get(), serial);
|
||||
if (ret == 0)
|
||||
{
|
||||
uint16_t channelCount = 0;
|
||||
qDebug()<<"Adding channels from device "<<serial;
|
||||
if (eismultiplexer_get_channel_count(multiplexer.get(), &channelCount) >= 0)
|
||||
{
|
||||
for (uint16_t channel = 0; channel < channelCount; channel++)
|
||||
{
|
||||
std::shared_ptr<ChannelWidget> widget(new ChannelWidget(serial, channel, multiplexer));
|
||||
qDebug()<<"Added widget from device "<<serial<<" channel "<<channel;
|
||||
channels.push_back(widget);
|
||||
ui->channelLayout->addWidget(widget.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Connection Failed"),
|
||||
tr("Failed to connect to device with serial %1").arg(serial));
|
||||
qWarning()<<"Failed to connect to device with serial"<<serial<<"eismultiplexer_connect returned"<<ret;
|
||||
}
|
||||
}
|
||||
ui->channelLayout->addStretch();
|
||||
|
||||
free(serials);
|
||||
// Second pass: populate gang combos and connect signals
|
||||
for (const auto& widget : channels) {
|
||||
// Populate gang combo with all other channels
|
||||
for (const auto& otherWidget : channels) {
|
||||
if (widget->getDeviceSerial() != otherWidget->getDeviceSerial() ||
|
||||
widget->getChannelNumber() != otherWidget->getChannelNumber()) {
|
||||
QString channelText = QString::asprintf("%04u, %u",
|
||||
otherWidget->getDeviceSerial(),
|
||||
otherWidget->getChannelNumber());
|
||||
widget->getGangCombo()->addItem(channelText);
|
||||
}
|
||||
}
|
||||
|
||||
// Connect state change signals
|
||||
for (const auto& otherWidget : channels) {
|
||||
if (widget.get() != otherWidget.get()) {
|
||||
connect(otherWidget.get(), &ChannelWidget::channelStateChanged,
|
||||
widget.get(), &ChannelWidget::onOtherChannelStateChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui->statusbar->showMessage("Ready");
|
||||
|
||||
free(serials);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue