Support windows

This commit is contained in:
Carl Philipp Klemm 2025-08-25 17:00:16 +02:00
parent 9e0d7a5d9d
commit 5c5efb5029
8 changed files with 215 additions and 144 deletions

View file

@ -1,36 +1,50 @@
cmake_minimum_required(VERSION 3.14)
# Set the project name
project(eismultiplexer-qt)
project(eismuliplexer-qt)
set(CMAKE_PROJECT_VERSION_MAJOR 0)
set(CMAKE_PROJECT_VERSION_MINOR 9)
set(CMAKE_PROJECT_VERSION_PATCH 0)
add_compile_definitions(VERSION_MAJOR=${CMAKE_PROJECT_VERSION_MAJOR})
add_compile_definitions(VERSION_MINOR=${CMAKE_PROJECT_VERSION_MINOR})
add_compile_definitions(VERSION_PATCH=${CMAKE_PROJECT_VERSION_PATCH})
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
message(FATAL_ERROR "Windows builds have to be cross compiled on UNIX")
endif()
message("Platform " ${CMAKE_SYSTEM_NAME})
if(WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/release-win.sh ${CMAKE_CURRENT_BINARY_DIR}/release.sh @ONLY)
add_custom_target(package
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/release.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Createing release archive"
VERBATIM)
endif(WIN32)
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Find Qt6
find_package(PkgConfig REQUIRED)
pkg_check_modules(EISMULIPLEXER REQUIRED eismuliplexer)
find_package(Qt6 REQUIRED COMPONENTS Widgets)
find_package(Qt6 REQUIRED COMPONENTS Core)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
# Include the libeismultiplexer library
include_directories(/workspace/libeismultiplexer)
link_directories(/workspace/libeismultiplexer/build)
# Add the application executable
add_executable(eismultiplexer-qt
add_executable(${PROJECT_NAME}
main.cpp
channelwidget.cpp
channelwidget.h
mainwindow.h
mainwindow.cpp
mainwindow.ui
multiplexer.h
multiplexer.cpp
)
target_compile_options(eismultiplexer-qt PUBLIC "-Wall")
# Link Qt Widgets
target_link_libraries(eismultiplexer-qt Qt6::Widgets eismultiplexer)
# Include directories
target_include_directories(eismultiplexer-qt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(${PROJECT_NAME} PUBLIC "-Wall")
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets Qt6::Core ${EISMULIPLEXER_LIBRARIES})
#target_include_directories(${PROJECT_NAME} PUBLIC ${EISMULIPLEXER_INCLUDE_DIRS})

View file

@ -2,7 +2,8 @@
#include <QDebug>
#include <QMessageBox>
ChannelWidget::ChannelWidget(uint16_t deviceSerial, uint16_t channelNumber, std::shared_ptr<struct eismultiplexer> multiplexer,
ChannelWidget::ChannelWidget(uint16_t deviceSerial, uint16_t channelNumber,
std::shared_ptr<struct eismultiplexer> multiplexer,
QWidget *parent)
:
QWidget(parent),
@ -61,14 +62,17 @@ bool ChannelWidget::isChecked() const
void ChannelWidget::onChannelToggled(bool checked)
{
if (checked) {
if (checked)
{
// Emit signal before actually turning on the channel
emit channelAboutToBeTurnedOn(deviceSerial, channelNumber);
}
channel_t channelFlag = static_cast<channel_t>(1 << channelNumber);
if (checked) {
if (eismultiplexer_connect_channel(multiplexer.get(), channelFlag) < 0) {
if (checked)
{
if (eismultiplexer_connect_channel(multiplexer.get(), channelFlag) < 0)
{
QMessageBox::warning(this, tr("Connection Failed"),
tr("Failed to connect channel %1 on device %2").arg(channelNumber).arg(deviceSerial));
qWarning() << "Failed to connect channel" << channelNumber << "on device" << deviceSerial;
@ -76,8 +80,11 @@ void ChannelWidget::onChannelToggled(bool checked)
checkbox.setChecked(false);
setEnabled(false); // Gray out the widget
}
} else {
if (eismultiplexer_disconnect_channel(multiplexer.get(), channelFlag) < 0) {
}
else
{
if (eismultiplexer_disconnect_channel(multiplexer.get(), channelFlag) < 0)
{
QMessageBox::warning(this, tr("Disconnection Failed"),
tr("Failed to disconnect channel %1 on device %2").arg(channelNumber).arg(deviceSerial));
qWarning() << "Failed to disconnect channel" << channelNumber << "on device" << deviceSerial;

View file

@ -14,7 +14,8 @@ class ChannelWidget : public QWidget
Q_OBJECT
public:
explicit ChannelWidget(uint16_t deviceSerial, uint16_t channelNumber, std::shared_ptr<struct eismultiplexer> multiplexer,
explicit ChannelWidget(uint16_t deviceSerial, uint16_t channelNumber,
std::shared_ptr<struct eismultiplexer> multiplexer,
QWidget *parent = nullptr);
~ChannelWidget() override;

View file

@ -10,7 +10,10 @@ MainWindow::MainWindow(QWidget *parent)
ui->setupUi(this);
enumerateDevices();
connect(ui->actionQuit, &QAction::triggered, this, [this](){close();});
connect(ui->actionQuit, &QAction::triggered, this, [this]()
{
close();
});
}
MainWindow::~MainWindow()
@ -23,29 +26,36 @@ void MainWindow::enumerateDevices()
size_t count = 0;
uint16_t* serials = eismultiplexer_list_available_devices(&count);
if (!serials || count == 0) {
QMessageBox::warning(this, tr("No Devices Found"),
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";
close();
exit(0);
return;
}
for (size_t i = 0; i < count; i++) {
for (size_t i = 0; i < count; i++)
{
uint16_t serial = serials[i];
std::shared_ptr<struct eismultiplexer> multiplexer(new struct eismultiplexer);
if (eismultiplexer_connect(multiplexer.get(), serial) >= 0) {
if (eismultiplexer_connect(multiplexer.get(), serial) >= 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++) {
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 {
}
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;

View file

@ -6,7 +6,8 @@
#include "channelwidget.h"
namespace Ui {
namespace Ui
{
class MainWindow;
}

16
multiplexer.cpp Normal file
View file

@ -0,0 +1,16 @@
#include "multiplexer.h"
Multiplexer::Multiplexer(QObject *parent)
: QObject{parent}
{}
Multiplexer::~Multiplexer()
{
for(auto& multiplexer : multiplexers)
eismultiplexer_disconnect(multiplexer.get());
}
void Multiplexer::probe()
{
}

22
multiplexer.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef MULTIPLEXER_H
#define MULTIPLEXER_H
#include <QObject>
#include "eismultiplexer.h"
class Multiplexer : public QObject
{
Q_OBJECT
std::vector<std::shared_ptr<struct eismultiplexer>> multiplexers;
std::vector<channel_t> channelStates;
public:
explicit Multiplexer(QObject *parent = nullptr);
~Multiplexer();
void probe();
signals:
void foundDevice(std::shared_ptr<struct eismultiplexer>);
};
#endif // MULTIPLEXER_H