95 lines
3.7 KiB
C++
95 lines
3.7 KiB
C++
#include <eismultiplexer.h>
|
|
#include <QMessageBox>
|
|
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
enumerateDevices();
|
|
|
|
connect(ui->actionQuit, &QAction::triggered, this, [this]()
|
|
{
|
|
close();
|
|
});
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::enumerateDevices()
|
|
{
|
|
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;
|
|
}
|
|
|
|
// 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();
|
|
|
|
// 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);
|
|
}
|
|
|