Skip to content

Commit

Permalink
Various fixes part deux
Browse files Browse the repository at this point in the history
GameStarted will send any available buffer back to GameSearching just in case

At this point, expect the worst lol.
  • Loading branch information
SeongGino committed Mar 26, 2024
1 parent aa66efa commit 6af3d65
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
39 changes: 24 additions & 15 deletions qhookermain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ void qhookerMain::SerialInit()

bool qhookerMain::GameSearching(QString input)
{
// Split the output in case of connecting mid-way.
buffer = input.split('\r', Qt::SkipEmptyParts);
if(buffer.isEmpty()) {
// Split the output in case of connecting mid-way.
buffer = input.split('\r', Qt::SkipEmptyParts);
}
//qDebug() << buffer;
while(!buffer.isEmpty()) {
buffer[0] = buffer[0].trimmed();
Expand Down Expand Up @@ -206,7 +208,7 @@ bool qhookerMain::GameSearching(QString input)
}


void qhookerMain::GameStarted(QString input)
bool qhookerMain::GameStarted(QString input)
{
if(buffer.isEmpty()) {
buffer = input.split('\r', Qt::SkipEmptyParts);
Expand All @@ -222,23 +224,27 @@ void qhookerMain::GameStarted(QString input)

// purge the current game name if stop signal is sent
if(func == "mame_stop") {
qInfo() << "mame_stop signal received, disconnecting.";
if(!gameName.isEmpty()) {
gameName.clear();
delete settings;
settingsMap.clear();
qInfo() << "mame_stop signal received, disconnecting.";
for(uint8_t i = 0; i < serialFoundList.count(); i++) {
if(serialPort[i].isOpen()) {
serialPort[i].write("E");
if(serialPort[i].waitForBytesWritten(2000)) {
qInfo() << "Closed port" << i+1;
serialPort[i].close();
} else {
qInfo() << "Sent close signal to port" << i+1 << ", but wasn't sent in time apparently!?";
if(settings) {
delete settings;
settingsMap.clear();
for(uint8_t i = 0; i < serialFoundList.count(); i++) {
if(serialPort[i].isOpen()) {
serialPort[i].write("E");
if(serialPort[i].waitForBytesWritten(2000)) {
qInfo() << "Closed port" << i+1;
serialPort[i].close();
} else {
qInfo() << "Sent close signal to port" << i+1 << ", but wasn't sent in time apparently!?";
}
}
}
}
}
buffer.clear();
return true;
// checking if a command for this input channel exists
} else if(!settingsMap[func].isEmpty()) {
//qDebug() << "Hey, this one isn't empty!"; // testing
Expand Down Expand Up @@ -339,6 +345,7 @@ void qhookerMain::GameStarted(QString input)
// then finally:
buffer.removeFirst();
}
return false;
}


Expand All @@ -351,7 +358,9 @@ void qhookerMain::ReadyRead()
GameStarted("");
}
} else {
GameStarted(tcpSocket.readLine());
if(GameStarted(tcpSocket.readLine())) {
GameSearching("");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion qhookermain.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class qhookerMain : public QObject

bool GameSearching(QString input);

void GameStarted(QString input);
bool GameStarted(QString input);

void ReadyRead();

Expand Down

0 comments on commit 6af3d65

Please sign in to comment.