Skip to content

Commit

Permalink
Add close on Exit
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelballantyne authored Jan 1, 2025
1 parent a2cedb5 commit a030151
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
26 changes: 26 additions & 0 deletions qhookermain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -188,6 +199,8 @@ void qhookerMain::SerialInit()





bool qhookerMain::GameSearching(QString input)
{
if(buffer.isEmpty()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -431,3 +445,15 @@ void qhookerMain::LoadConfig(QString path)
}
settings->endGroup();
}

void qhookerMain::PrintDeviceInfo()
{
QList<QSerialPortInfo> 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() << "========================================";
}
}
6 changes: 6 additions & 0 deletions qhookermain.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,25 @@ class qhookerMain : public QObject

void SerialInit();

void PrintDeviceInfo();

bool GameSearching(QString input);

bool GameStarted(QString input);

void ReadyRead();

QMap<int, QSerialPort*> serialPortMap;

public:
explicit qhookerMain(QObject *parent = 0);

bool verbosity = false;

bool customPathSet = false;

bool closeOnDisconnect = false;

QString customPath;

void quit();
Expand Down

0 comments on commit a030151

Please sign in to comment.