From a030151fc007bd561081db9fab1754a69a300cdb Mon Sep 17 00:00:00 2001 From: Sam Ballantyne <43810437+samuelballantyne@users.noreply.github.com> Date: Thu, 2 Jan 2025 10:49:13 +1300 Subject: [PATCH] Add close on Exit --- qhookermain.cpp | 26 ++++++++++++++++++++++++++ qhookermain.h | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/qhookermain.cpp b/qhookermain.cpp index a7b0eca..2129032 100644 --- a/qhookermain.cpp +++ b/qhookermain.cpp @@ -56,6 +56,13 @@ void qhookerMain::run() settingsMap.clear(); } } + + if (closeOnDisconnect) { + qInfo() << "Application closing due to -c argument."; + quit(); + return; + } + // in case we exit without connecting to a game (*coughFLYCASTcough*) for(uint8_t i = 0; i < serialFoundList.count(); i++) { if(serialPort[i].isOpen()) { @@ -151,7 +158,11 @@ void qhookerMain::SerialInit() if (info.vendorIdentifier() == 0xF143) { // For devices with Vendor ID 0xF143, use (Product ID - 1) as index int productId = info.productIdentifier(); + if (productId = 1998){ + index = 0; + }else{ index = productId - 1; // Subtract 1 for zero-based indexing + } if (assignedIndices.contains(index)) { duplicateProductIds = true; @@ -188,6 +199,8 @@ void qhookerMain::SerialInit() + + bool qhookerMain::GameSearching(QString input) { if(buffer.isEmpty()) { @@ -235,6 +248,7 @@ bool qhookerMain::GameSearching(QString input) uint8_t portNum = tempBuffer[0].at(4).digitValue()-1; if(portNum >= 0 && portNum < serialFoundList.count()) { if(!serialPort[portNum].isOpen()) { + qWarning() << "Failed to open port" << portNum; serialPort[portNum].open(QIODevice::WriteOnly); // Just in case Wendies complains: serialPort[portNum].setDataTerminalReady(true); @@ -431,3 +445,15 @@ void qhookerMain::LoadConfig(QString path) } settings->endGroup(); } + +void qhookerMain::PrintDeviceInfo() +{ + QList allPorts = QSerialPortInfo::availablePorts(); + for(const QSerialPortInfo &info : allPorts) { + qInfo() << "========================================"; + qInfo() << "Port Name: " << info.portName(); + qInfo() << "Vendor Identifier: " << (info.hasVendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : "N/A"); + qInfo() << "Product Identifier: " << (info.hasProductIdentifier() ? QString::number(info.productIdentifier(), 16) : "N/A"); + qInfo() << "========================================"; + } +} diff --git a/qhookermain.h b/qhookermain.h index 4f33893..d3c278e 100644 --- a/qhookermain.h +++ b/qhookermain.h @@ -34,12 +34,16 @@ class qhookerMain : public QObject void SerialInit(); + void PrintDeviceInfo(); + bool GameSearching(QString input); bool GameStarted(QString input); void ReadyRead(); + QMap serialPortMap; + public: explicit qhookerMain(QObject *parent = 0); @@ -47,6 +51,8 @@ class qhookerMain : public QObject bool customPathSet = false; + bool closeOnDisconnect = false; + QString customPath; void quit();