Skip to content

Commit 6af3d65

Browse files
authored
Various fixes part deux
GameStarted will send any available buffer back to GameSearching just in case At this point, expect the worst lol.
1 parent aa66efa commit 6af3d65

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

qhookermain.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ void qhookerMain::SerialInit()
127127

128128
bool qhookerMain::GameSearching(QString input)
129129
{
130-
// Split the output in case of connecting mid-way.
131-
buffer = input.split('\r', Qt::SkipEmptyParts);
130+
if(buffer.isEmpty()) {
131+
// Split the output in case of connecting mid-way.
132+
buffer = input.split('\r', Qt::SkipEmptyParts);
133+
}
132134
//qDebug() << buffer;
133135
while(!buffer.isEmpty()) {
134136
buffer[0] = buffer[0].trimmed();
@@ -206,7 +208,7 @@ bool qhookerMain::GameSearching(QString input)
206208
}
207209

208210

209-
void qhookerMain::GameStarted(QString input)
211+
bool qhookerMain::GameStarted(QString input)
210212
{
211213
if(buffer.isEmpty()) {
212214
buffer = input.split('\r', Qt::SkipEmptyParts);
@@ -222,23 +224,27 @@ void qhookerMain::GameStarted(QString input)
222224

223225
// purge the current game name if stop signal is sent
224226
if(func == "mame_stop") {
227+
qInfo() << "mame_stop signal received, disconnecting.";
225228
if(!gameName.isEmpty()) {
226229
gameName.clear();
227-
delete settings;
228-
settingsMap.clear();
229-
qInfo() << "mame_stop signal received, disconnecting.";
230-
for(uint8_t i = 0; i < serialFoundList.count(); i++) {
231-
if(serialPort[i].isOpen()) {
232-
serialPort[i].write("E");
233-
if(serialPort[i].waitForBytesWritten(2000)) {
234-
qInfo() << "Closed port" << i+1;
235-
serialPort[i].close();
236-
} else {
237-
qInfo() << "Sent close signal to port" << i+1 << ", but wasn't sent in time apparently!?";
230+
if(settings) {
231+
delete settings;
232+
settingsMap.clear();
233+
for(uint8_t i = 0; i < serialFoundList.count(); i++) {
234+
if(serialPort[i].isOpen()) {
235+
serialPort[i].write("E");
236+
if(serialPort[i].waitForBytesWritten(2000)) {
237+
qInfo() << "Closed port" << i+1;
238+
serialPort[i].close();
239+
} else {
240+
qInfo() << "Sent close signal to port" << i+1 << ", but wasn't sent in time apparently!?";
241+
}
238242
}
239243
}
240244
}
241245
}
246+
buffer.clear();
247+
return true;
242248
// checking if a command for this input channel exists
243249
} else if(!settingsMap[func].isEmpty()) {
244250
//qDebug() << "Hey, this one isn't empty!"; // testing
@@ -339,6 +345,7 @@ void qhookerMain::GameStarted(QString input)
339345
// then finally:
340346
buffer.removeFirst();
341347
}
348+
return false;
342349
}
343350

344351

@@ -351,7 +358,9 @@ void qhookerMain::ReadyRead()
351358
GameStarted("");
352359
}
353360
} else {
354-
GameStarted(tcpSocket.readLine());
361+
if(GameStarted(tcpSocket.readLine())) {
362+
GameSearching("");
363+
}
355364
}
356365
}
357366

qhookermain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class qhookerMain : public QObject
3636

3737
bool GameSearching(QString input);
3838

39-
void GameStarted(QString input);
39+
bool GameStarted(QString input);
4040

4141
void ReadyRead();
4242

0 commit comments

Comments
 (0)