@@ -27,7 +27,7 @@ String controllerManufacturerDataSearching = "0600030080";
2727
2828enum class ConnectionState : uint8_t {
2929 Connected = 0 ,
30- WaitingFirstNotification = 1 ,
30+ WaitingForFirstNotification = 1 ,
3131 Found = 2 ,
3232 Scanning = 3 ,
3333};
@@ -43,7 +43,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
4343#ifdef XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL
4444 XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL.println (" Connected" );
4545#endif
46- *pConnectionState = ConnectionState::WaitingFirstNotification ;
46+ *pConnectionState = ConnectionState::WaitingForFirstNotification ;
4747 // pClient->updateConnParams(120,120,0,60);
4848 };
4949
@@ -209,8 +209,11 @@ class Core {
209209 const size_t notifByteLen = XboxControllerNotificationParser::expectedDataLen;
210210 uint8_t notifByteArr[XboxControllerNotificationParser::expectedDataLen];
211211
212+ bool isWaitingForFirstNotification () {
213+ return connectionState == ConnectionState::WaitingForFirstNotification;
214+ }
212215 bool isConnected () {
213- return connectionState == ConnectionState::WaitingFirstNotification ||
216+ return connectionState == ConnectionState::WaitingForFirstNotification ||
214217 connectionState == ConnectionState::Connected;
215218 }
216219 unsigned long getReceiveNotificationAt () { return receivedNotificationAt; }
@@ -376,23 +379,34 @@ class Core {
376379 charaPrintId (pChara);
377380 XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL.println (" canNotify " );
378381#endif
379- // Serial.println("can notify");
380382 if (pChara->subscribe (
381383 true ,
382384 std::bind (&Core::notifyCB, this , std::placeholders::_1,
383385 std::placeholders::_2, std::placeholders::_3,
384386 std::placeholders::_4),
385387 true )) {
386- // Serial.println("set notifyCb");
388+ #ifdef XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL
389+ XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL.println (
390+ " succeeded in subscribing" );
391+ #endif
387392 } else {
388- // Serial.println("failed to subscribe");
393+ #ifdef XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL
394+ XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL.println (" failed subscribing" );
395+ #endif
389396 }
390397 }
391398 }
392399
393400 void notifyCB (NimBLERemoteCharacteristic* pRemoteCharacteristic,
394401 uint8_t * pData, size_t length, bool isNotify) {
395402 auto sUuid = pRemoteCharacteristic->getRemoteService ()->getUUID ();
403+ if (connectionState != ConnectionState::Connected) {
404+ #ifdef XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL
405+ XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL.println (
406+ " Received first notification" );
407+ #endif
408+ connectionState = ConnectionState::Connected;
409+ }
396410 if (sUuid .equals (uuidServiceHid)) {
397411#ifdef XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL
398412 static bool isPrinting = false ;
@@ -417,7 +431,6 @@ class Core {
417431 }
418432 XBOX_SERIES_X_CONTROLLER_DEBUG_SERIAL.println (" " );
419433#endif
420- connectionState = ConnectionState::Connected;
421434 xboxNotif.update (pData, length);
422435 memcpy (notifByteArr, pData,
423436 length < notifByteLen ? length : notifByteLen);
0 commit comments