Reworked driver code.
This commit is contained in:
@@ -4,6 +4,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
|||||||
|
|
||||||
CONFIG += c++23
|
CONFIG += c++23
|
||||||
|
|
||||||
|
QMAKE_CXXFLAGS += -std=c++23
|
||||||
|
|
||||||
# You can make your code fail to compile if it uses deprecated APIs.
|
# You can make your code fail to compile if it uses deprecated APIs.
|
||||||
# In order to do so, uncomment the following line.
|
# In order to do so, uncomment the following line.
|
||||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|||||||
34
bcdriver.cpp
34
bcdriver.cpp
@@ -48,12 +48,6 @@ BCDriver::DriverState BCDriver::getState() const
|
|||||||
return _driverState;
|
return _driverState;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCDriver::setState( DriverState newState )
|
|
||||||
{
|
|
||||||
_driverState = newState;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @brief Der Slot, der das Initialisieren des Treibers auslöst.
|
* @brief Der Slot, der das Initialisieren des Treibers auslöst.
|
||||||
@@ -65,34 +59,33 @@ void BCDriver::setState( DriverState newState )
|
|||||||
* aber die Console noch nicht eingeschaltet war.
|
* aber die Console noch nicht eingeschaltet war.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void BCDriver::onStartDriver()
|
void BCDriverDummy::onStartDriver()
|
||||||
{
|
{
|
||||||
|
_driverState = DriverState::Ready;
|
||||||
|
emit driverStateChanged( DriverState::Ready, "Driver Ready." );
|
||||||
|
}
|
||||||
|
/*
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
// erstmal die Dll Laden: State::sIdle -> State::sLoaded
|
// erstmal die Dll Laden: State::sIdle -> State::sLoaded
|
||||||
if( _driverState == DriverState::NotPresent)
|
if( _driverState == DriverState::NotPresent)
|
||||||
_driverState = loadDriver();
|
_driverState = loadAndInitDriver();
|
||||||
|
|
||||||
emit stateChanged( _driverState );
|
emit stateChanged( _driverState );
|
||||||
|
|
||||||
// DLL geladen, Verbindungsversuch
|
|
||||||
_driverState = initDriver();
|
|
||||||
|
|
||||||
// Wir haben was erreicht
|
|
||||||
emit stateChanged( _driverState );
|
|
||||||
}
|
}
|
||||||
catch( std::exception& except )
|
catch( std::exception& except )
|
||||||
{
|
{
|
||||||
//::CanDownDriver();
|
//::CanDownDriver();
|
||||||
//::UnloadDriver();
|
//::UnloadAndInitDriver();
|
||||||
|
|
||||||
emit errorOccured( except.what() );
|
emit statusHint( except.what() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// -----------------------------------------------------------------------------------
|
/// -----------------------------------------------------------------------------------
|
||||||
/// -----------------------------------------------------------------------------------
|
/// -----------------------------------------------------------------------------------
|
||||||
@@ -107,14 +100,11 @@ BCDriverDummy::BCDriverDummy( QObject* parent )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BCDriver::DriverState BCDriverDummy::loadDriver()
|
BCDriver::DriverState BCDriverDummy::loadAndInitDriver()
|
||||||
{
|
{
|
||||||
return BCDriver::DriverState::Ready;
|
return BCDriver::DriverState::Ready;
|
||||||
}
|
}
|
||||||
BCDriver::DriverState BCDriverDummy::initDriver()
|
|
||||||
{
|
|
||||||
return DriverState::Ready;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t BCDriverDummy::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
uint32_t BCDriverDummy::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
||||||
{
|
{
|
||||||
|
|||||||
30
bcdriver.h
30
bcdriver.h
@@ -96,8 +96,8 @@ public:
|
|||||||
Error,
|
Error,
|
||||||
Loaded,
|
Loaded,
|
||||||
Initialized,
|
Initialized,
|
||||||
Connected,
|
Opended, // bis hierher: dll vorhanden, Treiber geladen
|
||||||
Ready
|
Ready // hier: devices connectable
|
||||||
};
|
};
|
||||||
Q_ENUM(DriverState)
|
Q_ENUM(DriverState)
|
||||||
|
|
||||||
@@ -106,28 +106,19 @@ public:
|
|||||||
|
|
||||||
DriverState getState() const;
|
DriverState getState() const;
|
||||||
|
|
||||||
virtual DriverState loadDriver() = 0;
|
|
||||||
virtual DriverState initDriver() = 0;
|
|
||||||
|
|
||||||
virtual uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const = 0;
|
virtual uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const = 0;
|
||||||
virtual void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const = 0;
|
virtual void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const = 0;
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
// __fix wird das gebraucht?
|
|
||||||
void errorOccured( const QString& errMsg );
|
|
||||||
void statusHint( const QString& msg ) const;
|
|
||||||
|
|
||||||
void stateChanged( DriverState state );
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void onStartDriver();
|
virtual void onStartDriver() = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void driverStateChanged( DriverState state, const QString& message="" );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void setState( DriverState newState );
|
|
||||||
|
|
||||||
DriverState _driverState{DriverState::NotPresent};
|
DriverState _driverState{DriverState::NotPresent};
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -139,15 +130,14 @@ class BCDriverDummy : public BCDriver
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
explicit BCDriverDummy( QObject* parent = nullptr );
|
explicit BCDriverDummy( QObject* parent = nullptr );
|
||||||
|
|
||||||
DriverState loadDriver() override;
|
|
||||||
DriverState initDriver() override;
|
|
||||||
|
|
||||||
uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const override;
|
uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const override;
|
||||||
void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override;
|
void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
virtual void onStartDriver() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BCDRIVER_H
|
#endif // BCDRIVER_H
|
||||||
|
|||||||
@@ -32,10 +32,12 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
#include <bcdrivertinycan.h>
|
#include <bcdrivertinycan.h>
|
||||||
#include <can_drv.h>
|
#include <can_drv.h>
|
||||||
|
|
||||||
|
#include <expected>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BCDriverTinyCan::BCDriverTinyCan( QObject* parent )
|
BCDriverTinyCan::BCDriverTinyCan( QObject* parent )
|
||||||
: BCDriver(parent )
|
: BCDriver(parent )
|
||||||
@@ -44,42 +46,72 @@ BCDriverTinyCan::BCDriverTinyCan( QObject* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BCDriver::DriverState BCDriverTinyCan::loadDriver()
|
void BCDriverTinyCan::loadDriver()
|
||||||
{
|
{
|
||||||
|
|
||||||
//qDebug() << "CanBusControl " << cbc::Version << '\n' << "based on BigXionFlasher (c) 2011-2013 by Thomas Koenig <info@bigxionflasher.org> - www.bigxionflasher.org";
|
using Result=std::expected<DriverState,QString>;
|
||||||
|
|
||||||
struct ::TDeviceStatus canDevicestatus;
|
auto callLoadDriver = []() -> Result
|
||||||
|
|
||||||
if( ::LoadDriver( NULL ) < 0 )
|
|
||||||
throw BCException( "Driver Error: 'LoadDriver'" );
|
|
||||||
|
|
||||||
setState(BCDriver::DriverState::Loaded);
|
|
||||||
|
|
||||||
if( ::CanInitDriver( NULL ) < 0 )
|
|
||||||
throw BCException( "Driver Error: 'InitDriver'" );
|
|
||||||
|
|
||||||
if( ::CanDeviceOpen( 0, NULL ) < 0 )
|
|
||||||
throw std::runtime_error( "Driver Error: 'DeviceOpen'" );
|
|
||||||
|
|
||||||
::CanSetSpeed( 0, CAN_125K_BIT );
|
|
||||||
::CanSetMode( 0, OP_CAN_START, CAN_CMD_ALL_CLEAR );
|
|
||||||
::CanGetDeviceStatus( 0, &canDevicestatus );
|
|
||||||
|
|
||||||
setState(BCDriver::DriverState::Initialized);
|
|
||||||
|
|
||||||
if( canDevicestatus.DrvStatus < DRV_STATUS_CAN_OPEN )
|
|
||||||
throw BCException( "Driver Error: could not open device." );
|
|
||||||
|
|
||||||
if( canDevicestatus.CanStatus == CAN_STATUS_BUS_OFF )
|
|
||||||
{
|
{
|
||||||
::CanSetMode( 0, OP_CAN_RESET, CAN_CMD_NONE );
|
if( ::LoadDriver( NULL ) < 0 )
|
||||||
throw BCException( "Driver Error: CAN Status 'BusOff'" );
|
return std::unexpected(QString("Driver Error: 'LoadDriver'"));
|
||||||
}
|
return DriverState::Loaded;
|
||||||
|
};
|
||||||
|
|
||||||
setState(BCDriver::DriverState::Ready);
|
auto callInitDriver = [](DriverState state) -> Result
|
||||||
|
{
|
||||||
|
Q_UNUSED(state)
|
||||||
|
if( ::CanInitDriver( NULL ) < 0 )
|
||||||
|
return std::unexpected(QString("Driver Error: 'InitDriver'"));
|
||||||
|
return DriverState::Initialized;
|
||||||
|
};
|
||||||
|
|
||||||
return BCDriver::DriverState::Ready;
|
auto callOpenDevice = [](DriverState state) -> Result
|
||||||
|
{
|
||||||
|
Q_UNUSED(state)
|
||||||
|
if( ::CanDeviceOpen( 0, NULL ) < 0 )
|
||||||
|
return std::unexpected(QString("Driver Error: 'DeviceOpen'"));
|
||||||
|
return DriverState::Opended;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto callSetDeviceMode = [](DriverState state) -> Result
|
||||||
|
{
|
||||||
|
Q_UNUSED(state)
|
||||||
|
::TDeviceStatus deviceStatus;
|
||||||
|
|
||||||
|
::CanSetSpeed( 0, CAN_125K_BIT );
|
||||||
|
::CanSetMode( 0, OP_CAN_START, CAN_CMD_ALL_CLEAR );
|
||||||
|
::CanGetDeviceStatus( 0, &deviceStatus );
|
||||||
|
|
||||||
|
if( deviceStatus.DrvStatus < DRV_STATUS_CAN_OPEN )
|
||||||
|
std::unexpected(QString("Driver Error: could not open device." ));
|
||||||
|
|
||||||
|
if( deviceStatus.CanStatus == CAN_STATUS_BUS_OFF )
|
||||||
|
{
|
||||||
|
::CanSetMode( 0, OP_CAN_RESET, CAN_CMD_NONE );
|
||||||
|
std::unexpected(QString("Driver Error: CAN Status 'BusOff'" ));
|
||||||
|
}
|
||||||
|
return BCDriver::DriverState::Ready;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto newDriverState = callLoadDriver()
|
||||||
|
.and_then( callInitDriver )
|
||||||
|
.and_then( callOpenDevice )
|
||||||
|
.and_then( callSetDeviceMode );
|
||||||
|
|
||||||
|
_driverState = DriverState::Error;
|
||||||
|
QString message("Driver Ready.");
|
||||||
|
|
||||||
|
if(newDriverState)
|
||||||
|
_driverState = *newDriverState;
|
||||||
|
else
|
||||||
|
message = newDriverState.error();
|
||||||
|
|
||||||
|
emit driverStateChanged( _driverState, message );
|
||||||
|
}
|
||||||
|
|
||||||
|
void BCDriverTinyCan::initDriver()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,21 +119,21 @@ BCDriver::DriverState BCDriverTinyCan::loadDriver()
|
|||||||
/*
|
/*
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
loadDriver();
|
loadAndInitDriver();
|
||||||
initBCDevice::ID::Console();
|
initBCDevice::ID::Console();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch( std::exception& except )
|
catch( std::exception& except )
|
||||||
{
|
{
|
||||||
::CanDownDriver();
|
::CanDownDriver();
|
||||||
::UnloadDriver();
|
::UnloadAndInitDriver();
|
||||||
|
|
||||||
// re-throw
|
// re-throw
|
||||||
throw BCException( except.what() );
|
throw BCException( except.what() );
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
BCDriver::DriverState BCDriverTinyCan::initDriver()
|
BCDriver::DriverState BCDriverTinyCan::initDriver()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -138,7 +170,7 @@ BCDriver::DriverState BCDriverTinyCan::initDriver()
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
uint32_t BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
uint32_t BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,9 +44,6 @@ public:
|
|||||||
explicit BCDriverTinyCan( QObject* parent=nullptr );
|
explicit BCDriverTinyCan( QObject* parent=nullptr );
|
||||||
virtual ~BCDriverTinyCan() = default;
|
virtual ~BCDriverTinyCan() = default;
|
||||||
|
|
||||||
DriverState loadDriver() override;
|
|
||||||
DriverState initDriver() override;
|
|
||||||
|
|
||||||
uint32_t readRawByte ( uint32_t deviceID, uint8_t registerID ) const override;
|
uint32_t readRawByte ( uint32_t deviceID, uint8_t registerID ) const override;
|
||||||
void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override;
|
void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override;
|
||||||
|
|
||||||
@@ -54,26 +51,26 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
void loadDriver();
|
||||||
|
void initDriver();
|
||||||
|
|
||||||
// typen?
|
// typen?
|
||||||
//void setValue( unsigned char receipient, unsigned char reg, unsigned char value );
|
//void setValue( unsigned char receipient, unsigned char reg, unsigned char value );
|
||||||
//unsigned int getValue( unsigned char receipient, unsigned char reg );
|
//unsigned int getValue( unsigned char receipient, unsigned char reg );
|
||||||
|
|
||||||
void awaitReceiveBuf( int timeout );
|
|
||||||
void awaitSendBuf(int timeout );
|
|
||||||
|
|
||||||
const char* CBCDLL_LIN = "libmhstcan.so";
|
//const char* CBCDLL_LIN = "libmhstcan.so";
|
||||||
const char* CBCDLL_WIN = "mhstcan.dll";
|
//const char* CBCDLL_WIN = "mhstcan.dll";
|
||||||
|
|
||||||
|
|
||||||
static constexpr int cRetries = 5;
|
static constexpr int cRetries = 5;
|
||||||
static constexpr int cTimeOuts = 20;
|
static constexpr int cTimeOuts = 20;
|
||||||
|
static constexpr int cTIMEOUT_MS = 10; // 10ms
|
||||||
static constexpr int cTIMEOUT_MS = 10; // 10ms
|
static constexpr int cTIMEOUT_COUNT = 10;
|
||||||
static constexpr int cTIMEOUT_COUNT = 10;
|
|
||||||
|
|
||||||
|
|
||||||
const unsigned int BATTERY = 0x010;
|
//const unsigned int BATTERY = 0x010;
|
||||||
const unsigned int MOTOR = 0x020;
|
//const unsigned int MOTOR = 0x020;
|
||||||
const unsigned int BIB = 0x048;
|
const unsigned int BIB = 0x048;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
96
bclegacy.cpp
96
bclegacy.cpp
@@ -185,6 +185,102 @@ double gSetSpeedLimit = -1, gSetMinSpeedLimit = -1, gSetThrottleSpeedLimit = -1;
|
|||||||
#define BATTERY 3
|
#define BATTERY 3
|
||||||
#define BIB 4
|
#define BIB 4
|
||||||
|
|
||||||
|
/*
|
||||||
|
class ThemeSwitchButton : public QPushButton {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ThemeSwitchButton(QWidget *parent = nullptr)
|
||||||
|
: QPushButton(parent), m_isDarkMode(true)
|
||||||
|
{
|
||||||
|
// 1. Visuelles Setup: Flach, keine Ränder, Hand-Cursor
|
||||||
|
setFlat(true);
|
||||||
|
setCursor(Qt::PointingHandCursor);
|
||||||
|
setFixedSize(32, 24); // Kleiner Footprint im StatusBar
|
||||||
|
|
||||||
|
// CSS: Transparent, damit es sich nahtlos in den StatusBar einfügt
|
||||||
|
// Schriftgröße etwas erhöhen, damit die Emojis gut erkennbar sind
|
||||||
|
setStyleSheet(R"(
|
||||||
|
QPushButton {
|
||||||
|
border: none;
|
||||||
|
background-color: transparent;
|
||||||
|
font-size: 14pt;
|
||||||
|
}
|
||||||
|
QPushButton:hover {
|
||||||
|
background-color: rgba(128, 128, 128, 30); // Leichter Hover-Effekt
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
)");
|
||||||
|
|
||||||
|
// 2. Initialer Status (Startet im Dark Mode -> zeigt Mond)
|
||||||
|
updateIcon();
|
||||||
|
|
||||||
|
// 3. Klick verbinden
|
||||||
|
connect(this, &QPushButton::clicked, this, &ThemeSwitchButton::toggle);
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void themeChanged(bool isDark);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void toggle() {
|
||||||
|
m_isDarkMode = !m_isDarkMode;
|
||||||
|
updateIcon();
|
||||||
|
emit themeChanged(m_isDarkMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateIcon() {
|
||||||
|
// Logik:
|
||||||
|
// Ist Dark Mode an? Zeige Mond (oder Sonne, je nach Geschmack).
|
||||||
|
// Hier: Zeige das Symbol des AKTUELLEN Modus.
|
||||||
|
setText(m_isDarkMode ? "🌙" : "☀️");
|
||||||
|
setToolTip(m_isDarkMode ? "Switch to Light Mode" : "Switch to Dark Mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool m_isDarkMode;
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
class MainWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MainWindow(QWidget *parent = nullptr)
|
||||||
|
: QMainWindow(parent)
|
||||||
|
{
|
||||||
|
setWindowTitle("Fluent Theme Switcher");
|
||||||
|
resize(800, 600);
|
||||||
|
|
||||||
|
// --- STATUSBAR SETUP ---
|
||||||
|
QStatusBar *statBar = statusBar();
|
||||||
|
|
||||||
|
// Optional: Normale Nachricht links
|
||||||
|
statBar->showMessage("Ready");
|
||||||
|
|
||||||
|
// 1. Unseren Switcher erstellen
|
||||||
|
ThemeSwitchButton *themeBtn = new ThemeSwitchButton(this);
|
||||||
|
|
||||||
|
// 2. WICHTIG: Rechts hinzufügen
|
||||||
|
statBar->addPermanentWidget(themeBtn);
|
||||||
|
|
||||||
|
// 3. Signal verbinden: Button klick -> Theme ändern
|
||||||
|
connect(themeBtn, &ThemeSwitchButton::themeChanged, this, [this](bool isDark){
|
||||||
|
if (isDark) {
|
||||||
|
applyFluentDarkTheme(*qApp); // Funktion von vorhin
|
||||||
|
statusBar()->showMessage("Dark Mode Activated", 3000);
|
||||||
|
} else {
|
||||||
|
applyFluentLightTheme(*qApp); // Funktion von vorhin
|
||||||
|
statusBar()->showMessage("Light Mode Activated", 3000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initiale Anwendung (Dark Mode)
|
||||||
|
applyFluentDarkTheme(*qApp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
char *getNodeName(unsigned char id)
|
char *getNodeName(unsigned char id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -156,38 +156,14 @@ void BCMainWindow::initMainWindow()
|
|||||||
_transmitter.moveToThread(&_worker);
|
_transmitter.moveToThread(&_worker);
|
||||||
|
|
||||||
connect(this, &BCMainWindow::requestValueUpdate, &_transmitter, &BCTransmitter::enqueueValueOp);
|
connect(this, &BCMainWindow::requestValueUpdate, &_transmitter, &BCTransmitter::enqueueValueOp);
|
||||||
|
|
||||||
// B) Ergebnisse empfangen (Runner -> Manager)
|
|
||||||
//connect(&_transmitter, &BCTransmitter::valueStateChanged, this, &BCXmlLoader::onvalueStateChanged);
|
|
||||||
//connect(&_transmitter, &BCTransmitter::messageLogged, this, &BCXmlLoader::onRunnerMessage);
|
|
||||||
|
|
||||||
// C) Aufräumen: Wenn Thread endet, lösche den Runner
|
|
||||||
connect(&_worker, &QThread::finished, &_transmitter, &QObject::deleteLater);
|
connect(&_worker, &QThread::finished, &_transmitter, &QObject::deleteLater);
|
||||||
// 5. Thread starten
|
|
||||||
_worker.start();
|
_worker.start();
|
||||||
|
|
||||||
_consoleAction->trigger();
|
_consoleAction->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
void BCMainWindow::onValueListReady( BCDevice::ID deviceID )
|
|
||||||
{
|
|
||||||
qDebug() << " --- onValueListReady!" << deviceID;
|
|
||||||
if( _devicePanels.contains( deviceID ) )
|
|
||||||
{
|
|
||||||
BCDeviceView& panel = *_devicePanels[deviceID];
|
|
||||||
BCValueList& victim = panel.exposeValueList();
|
|
||||||
BCValueList& newValueList = _dataManager.getCurrentValueList();
|
|
||||||
qDebug() << " --- Before: " << victim.size() << " orig:" << newValueList.size();
|
|
||||||
victim = std::exchange(newValueList, BCValueList());
|
|
||||||
//_devicePanels[deviceID]->exchangeValueList( newValueList );
|
|
||||||
qDebug() << " ---After: " << victim.size() << " orig:" << newValueList.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
|
void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
|
||||||
{
|
{
|
||||||
qDebug() << " --- onShowDevicePanel:" << deviceID;
|
qDebug() << " --- onShowDevicePanel:" << deviceID;
|
||||||
@@ -207,8 +183,6 @@ void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BCMainWindow::onConnectButtonToggled(bool checked )
|
void BCMainWindow::onConnectButtonToggled(bool checked )
|
||||||
{
|
{
|
||||||
//_dataManager.setDriverConnectionState( checked );
|
//_dataManager.setDriverConnectionState( checked );
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
#include <bcvalue.h>
|
#include <bcvalue.h>
|
||||||
#include <bcdrivertinycan.h>
|
#include <bcdrivertinycan.h>
|
||||||
|
|
||||||
// template ...
|
// template ... ?
|
||||||
class BCTransmitter : public QObject, public BCAbstractTransmitter
|
class BCTransmitter : public QObject, public BCAbstractTransmitter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -62,7 +62,7 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
|
|
||||||
void valueUpdated(BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" );
|
void valueUpdated(BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" );
|
||||||
void messageLogged(const QString& msg);
|
void driverStateChanged( BCDriver::DriverState state, const QString& message="" );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
96
main.cpp
96
main.cpp
@@ -39,102 +39,11 @@
|
|||||||
|
|
||||||
#include <bcmainwindow.h>
|
#include <bcmainwindow.h>
|
||||||
|
|
||||||
|
#include <expected>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
class ThemeSwitchButton : public QPushButton {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ThemeSwitchButton(QWidget *parent = nullptr)
|
|
||||||
: QPushButton(parent), m_isDarkMode(true)
|
|
||||||
{
|
|
||||||
// 1. Visuelles Setup: Flach, keine Ränder, Hand-Cursor
|
|
||||||
setFlat(true);
|
|
||||||
setCursor(Qt::PointingHandCursor);
|
|
||||||
setFixedSize(32, 24); // Kleiner Footprint im StatusBar
|
|
||||||
|
|
||||||
// CSS: Transparent, damit es sich nahtlos in den StatusBar einfügt
|
|
||||||
// Schriftgröße etwas erhöhen, damit die Emojis gut erkennbar sind
|
|
||||||
setStyleSheet(R"(
|
|
||||||
QPushButton {
|
|
||||||
border: none;
|
|
||||||
background-color: transparent;
|
|
||||||
font-size: 14pt;
|
|
||||||
}
|
|
||||||
QPushButton:hover {
|
|
||||||
background-color: rgba(128, 128, 128, 30); /* Leichter Hover-Effekt */
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
// 2. Initialer Status (Startet im Dark Mode -> zeigt Mond)
|
|
||||||
updateIcon();
|
|
||||||
|
|
||||||
// 3. Klick verbinden
|
|
||||||
connect(this, &QPushButton::clicked, this, &ThemeSwitchButton::toggle);
|
|
||||||
}
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void themeChanged(bool isDark);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void toggle() {
|
|
||||||
m_isDarkMode = !m_isDarkMode;
|
|
||||||
updateIcon();
|
|
||||||
emit themeChanged(m_isDarkMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void updateIcon() {
|
|
||||||
// Logik:
|
|
||||||
// Ist Dark Mode an? Zeige Mond (oder Sonne, je nach Geschmack).
|
|
||||||
// Hier: Zeige das Symbol des AKTUELLEN Modus.
|
|
||||||
setText(m_isDarkMode ? "🌙" : "☀️");
|
|
||||||
setToolTip(m_isDarkMode ? "Switch to Light Mode" : "Switch to Dark Mode");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool m_isDarkMode;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
class MainWindow : public QMainWindow
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
MainWindow(QWidget *parent = nullptr)
|
|
||||||
: QMainWindow(parent)
|
|
||||||
{
|
|
||||||
setWindowTitle("Fluent Theme Switcher");
|
|
||||||
resize(800, 600);
|
|
||||||
|
|
||||||
// --- STATUSBAR SETUP ---
|
|
||||||
QStatusBar *statBar = statusBar();
|
|
||||||
|
|
||||||
// Optional: Normale Nachricht links
|
|
||||||
statBar->showMessage("Ready");
|
|
||||||
|
|
||||||
// 1. Unseren Switcher erstellen
|
|
||||||
ThemeSwitchButton *themeBtn = new ThemeSwitchButton(this);
|
|
||||||
|
|
||||||
// 2. WICHTIG: Rechts hinzufügen
|
|
||||||
statBar->addPermanentWidget(themeBtn);
|
|
||||||
|
|
||||||
// 3. Signal verbinden: Button klick -> Theme ändern
|
|
||||||
connect(themeBtn, &ThemeSwitchButton::themeChanged, this, [this](bool isDark){
|
|
||||||
if (isDark) {
|
|
||||||
applyFluentDarkTheme(*qApp); // Funktion von vorhin
|
|
||||||
statusBar()->showMessage("Dark Mode Activated", 3000);
|
|
||||||
} else {
|
|
||||||
applyFluentLightTheme(*qApp); // Funktion von vorhin
|
|
||||||
statusBar()->showMessage("Light Mode Activated", 3000);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Initiale Anwendung (Dark Mode)
|
|
||||||
applyFluentDarkTheme(*qApp);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool setApplicationStyleSheet( QAnyStringView path )
|
bool setApplicationStyleSheet( QAnyStringView path )
|
||||||
{
|
{
|
||||||
@@ -153,7 +62,6 @@ bool setApplicationStyleSheet( QAnyStringView path )
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
//setApplicationStyleSheet( ":/claude_light_mode.qss"_L1 );
|
//setApplicationStyleSheet( ":/claude_light_mode.qss"_L1 );
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user