diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index dfa6b2a4..5f54e059 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -494,6 +494,15 @@ void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) { #endif } +void XBOXRECV::disconnect(uint8_t controller) { + writeBuf[0] = 0x00; + writeBuf[1] = 0x00; + writeBuf[2] = 0x08; + writeBuf[3] = 0xC0; + + XboxCommand(controller, writeBuf, 4); +} + void XBOXRECV::setLedRaw(uint8_t value, uint8_t controller) { writeBuf[0] = 0x00; writeBuf[1] = 0x00; diff --git a/XBOXRECV.h b/XBOXRECV.h index bb0b53d7..eee75cda 100644 --- a/XBOXRECV.h +++ b/XBOXRECV.h @@ -144,6 +144,12 @@ public: */ int16_t getAnalogHat(AnalogHat a, uint8_t controller = 0); + /** + * Used to disconnect any of the controllers. + * @param controller The controller to disconnect. Default to 0. + */ + void disconnect(uint8_t controller = 0); + /** * Turn rumble off and all the LEDs on the specific controller. * @param controller The controller to write to. Default to 0. diff --git a/examples/Xbox/XBOXRECV/XBOXRECV.ino b/examples/Xbox/XBOXRECV/XBOXRECV.ino index 2143098e..512e176e 100644 --- a/examples/Xbox/XBOXRECV/XBOXRECV.ino +++ b/examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -94,8 +94,10 @@ void loop() { Serial.print(Xbox.getBatteryLevel(i)); // The battery level in the range 0-3 Serial.println(F(")")); } - if(Xbox.getButtonClick(SYNC,i)) + if (Xbox.getButtonClick(SYNC, i)) { Serial.println(F("Sync")); + Xbox.disconnect(i); + } if (Xbox.getButtonClick(A, i)) Serial.println(F("A"));