@@ -127,8 +127,10 @@ void qhookerMain::SerialInit()
127
127
128
128
bool qhookerMain::GameSearching (QString input)
129
129
{
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
+ }
132
134
// qDebug() << buffer;
133
135
while (!buffer.isEmpty ()) {
134
136
buffer[0 ] = buffer[0 ].trimmed ();
@@ -206,7 +208,7 @@ bool qhookerMain::GameSearching(QString input)
206
208
}
207
209
208
210
209
- void qhookerMain::GameStarted (QString input)
211
+ bool qhookerMain::GameStarted (QString input)
210
212
{
211
213
if (buffer.isEmpty ()) {
212
214
buffer = input.split (' \r ' , Qt::SkipEmptyParts);
@@ -222,23 +224,27 @@ void qhookerMain::GameStarted(QString input)
222
224
223
225
// purge the current game name if stop signal is sent
224
226
if (func == " mame_stop" ) {
227
+ qInfo () << " mame_stop signal received, disconnecting." ;
225
228
if (!gameName.isEmpty ()) {
226
229
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
+ }
238
242
}
239
243
}
240
244
}
241
245
}
246
+ buffer.clear ();
247
+ return true ;
242
248
// checking if a command for this input channel exists
243
249
} else if (!settingsMap[func].isEmpty ()) {
244
250
// qDebug() << "Hey, this one isn't empty!"; // testing
@@ -339,6 +345,7 @@ void qhookerMain::GameStarted(QString input)
339
345
// then finally:
340
346
buffer.removeFirst ();
341
347
}
348
+ return false ;
342
349
}
343
350
344
351
@@ -351,7 +358,9 @@ void qhookerMain::ReadyRead()
351
358
GameStarted (" " );
352
359
}
353
360
} else {
354
- GameStarted (tcpSocket.readLine ());
361
+ if (GameStarted (tcpSocket.readLine ())) {
362
+ GameSearching (" " );
363
+ }
355
364
}
356
365
}
357
366
0 commit comments