@@ -90,9 +90,9 @@ void BleGamepad::begin(BleGamepadConfiguration *config)
9090 firmwareRevision = configuration.getFirmwareRevision ();
9191 hardwareRevision = configuration.getHardwareRevision ();
9292
93- vid = configuration.getVid ();
94- pid = configuration.getPid ();
95- guidVersion = configuration.getGuidVersion ();
93+ vid = configuration.getVid ();
94+ pid = configuration.getPid ();
95+ guidVersion = configuration.getGuidVersion ();
9696
9797 enableOutputReport = configuration.getEnableOutputReport ();
9898 outputReportLength = configuration.getOutputReportLength ();
@@ -156,7 +156,6 @@ void BleGamepad::begin(BleGamepadConfiguration *config)
156156
157157 if (configuration.getButtonCount () > 0 )
158158 {
159-
160159 // USAGE_PAGE (Button)
161160 tempHidReportDescriptor[hidReportDescriptorSize++] = 0x05 ;
162161 tempHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
@@ -346,7 +345,7 @@ void BleGamepad::begin(BleGamepadConfiguration *config)
346345 tempHidReportDescriptor[hidReportDescriptorSize++] = highByte (configuration.getAxesMin ());
347346 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x00; // Use these two lines for 0 min
348347 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x00;
349- // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x01; // Use these two lines for -32767 min
348+ // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x01; // Use these two lines for -32767 min
350349 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x80;
351350
352351 // LOGICAL_MAXIMUM (+32767)
@@ -355,7 +354,7 @@ void BleGamepad::begin(BleGamepadConfiguration *config)
355354 tempHidReportDescriptor[hidReportDescriptorSize++] = highByte (configuration.getAxesMax ());
356355 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0xFF; // Use these two lines for 255 max
357356 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x00;
358- // tempHidReportDescriptor[hidReportDescriptorSize++] = 0xFF; // Use these two lines for +32767 max
357+ // tempHidReportDescriptor[hidReportDescriptorSize++] = 0xFF; // Use these two lines for +32767 max
359358 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x7F;
360359
361360 // REPORT_SIZE (16)
@@ -446,9 +445,9 @@ void BleGamepad::begin(BleGamepadConfiguration *config)
446445 tempHidReportDescriptor[hidReportDescriptorSize++] = 0x16 ;
447446 tempHidReportDescriptor[hidReportDescriptorSize++] = lowByte (configuration.getSimulationMin ());
448447 tempHidReportDescriptor[hidReportDescriptorSize++] = highByte (configuration.getSimulationMin ());
449- // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x00; // Use these two lines for 0 min
448+ // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x00; // Use these two lines for 0 min
450449 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x00;
451- // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x01; // Use these two lines for -32767 min
450+ // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x01; // Use these two lines for -32767 min
452451 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x80;
453452
454453 // LOGICAL_MAXIMUM (+32767)
@@ -457,7 +456,7 @@ void BleGamepad::begin(BleGamepadConfiguration *config)
457456 tempHidReportDescriptor[hidReportDescriptorSize++] = highByte (configuration.getSimulationMax ());
458457 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0xFF; // Use these two lines for 255 max
459458 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x00;
460- // tempHidReportDescriptor[hidReportDescriptorSize++] = 0xFF; // Use these two lines for +32767 max
459+ // tempHidReportDescriptor[hidReportDescriptorSize++] = 0xFF; // Use these two lines for +32767 max
461460 // tempHidReportDescriptor[hidReportDescriptorSize++] = 0x7F;
462461
463462 // REPORT_SIZE (16)
@@ -1444,7 +1443,7 @@ bool BleGamepad::deleteBond(bool resetBoard)
14441443
14451444 NimBLEServer* server = NimBLEDevice::getServer ();
14461445
1447- if (server)
1446+ if (server)
14481447 {
14491448 NimBLEConnInfo info = server->getPeerInfo (0 );
14501449 NimBLEAddress address = info.getAddress ();
@@ -1457,66 +1456,66 @@ bool BleGamepad::deleteBond(bool resetBoard)
14571456 {
14581457 ESP.restart ();
14591458 }
1460- }
1459+ }
14611460 return success; // Returns false if current bond is not deleted
14621461}
14631462
14641463bool BleGamepad::enterPairingMode ()
14651464{
1466- NimBLEServer* server = NimBLEDevice::getServer ();
1465+ NimBLEServer* server = NimBLEDevice::getServer ();
14671466
14681467 if (server)
1469- {
1470- // Serial.println("Entered pairing mode");
1471-
1472- // Get current connection information and address
1473- NimBLEConnInfo currentConnInfo = server->getPeerInfo (0 );
1474- NimBLEAddress currentAddress = currentConnInfo.getAddress ();
1475- // Serial.print("Current Address is: ");
1476- // Serial.println(currentAddress.toString().c_str());
1468+ {
1469+ // Serial.println("Entered pairing mode");
14771470
1478- // Disconnect from current connection
1479- for (uint16_t connHandle : server->getPeerDevices ())
1480- {
1471+ // Get current connection information and address
1472+ NimBLEConnInfo currentConnInfo = server->getPeerInfo (0 );
1473+ NimBLEAddress currentAddress = currentConnInfo.getAddress ();
1474+ // Serial.print("Current Address is: ");
1475+ // Serial.println(currentAddress.toString().c_str());
1476+
1477+ // Disconnect from current connection
1478+ for (uint16_t connHandle : server->getPeerDevices ())
1479+ {
14811480 server->disconnect (connHandle); // Disconnect the client
1482- // Serial.println("Disconnected from client");
1483- delay (1000 );
1481+ // Serial.println("Disconnected from client");
1482+ delay (1000 );
14841483 }
14851484
1486- bool connectedToOldDevice = true ;
1485+ bool connectedToOldDevice = true ;
14871486
1488- // While connected to old device, keep allowing to connect new new devices
1489- while (connectedToOldDevice)
1490- {
1491- // Serial.println("While loop entered");
1492- delay (10 ); // Needs a delay to work - do not remove!
1493-
1494- if (this ->isConnected ())
1495- {
1496- NimBLEConnInfo newConnInfo = server->getPeerInfo (0 );
1497- NimBLEAddress newAddress = newConnInfo.getAddress ();
1487+ // While connected to old device, keep allowing to connect new new devices
1488+ while (connectedToOldDevice)
1489+ {
1490+ // Serial.println("While loop entered");
1491+ delay (10 ); // Needs a delay to work - do not remove!
1492+
1493+ if (this ->isConnected ())
1494+ {
1495+ NimBLEConnInfo newConnInfo = server->getPeerInfo (0 );
1496+ NimBLEAddress newAddress = newConnInfo.getAddress ();
14981497
1499- // Serial.print("Current Address is: ");
1500- // Serial.println(newAddress.toString().c_str());
1498+ // Serial.print("Current Address is: ");
1499+ // Serial.println(newAddress.toString().c_str());
15011500
1502- // Block specific MAC address
1503- if (newAddress == currentAddress)
1504- {
1505- // Serial.println("Addresses match - blocking");
1506- server->disconnect (newConnInfo.getConnHandle ());
1507- delay (500 );
1508- }
1509- else
1510- {
1511- // Serial.println("New device connected");
1512- connectedToOldDevice = false ;
1513- return true ;
1514- }
1515- }
1501+ // Block specific MAC address
1502+ if (newAddress == currentAddress)
1503+ {
1504+ // Serial.println("Addresses match - blocking");
1505+ server->disconnect (newConnInfo.getConnHandle ());
1506+ delay (500 );
15161507 }
1517- return false ; // Might want to adjust this function to stay in pairing mode for a while, and then return false after a while if no other device pairs with it
1508+ else
1509+ {
1510+ // Serial.println("New device connected");
1511+ connectedToOldDevice = false ;
1512+ return true ;
1513+ }
1514+ }
1515+ }
1516+ return false ; // Might want to adjust this function to stay in pairing mode for a while, and then return false after a while if no other device pairs with it
15181517 }
1519- return false ;
1518+ return false ;
15201519}
15211520
15221521
@@ -1544,31 +1543,31 @@ void BleGamepad::taskServer(void *pvParameter)
15441543
15451544 NimBLEService *pService = pServer->getServiceByUUID (SERVICE_UUID_DEVICE_INFORMATION);
15461545
1547- BLECharacteristic* pCharacteristic_Model_Number = pService->createCharacteristic (
1546+ BLECharacteristic* pCharacteristic_Model_Number = pService->createCharacteristic (
15481547 CHARACTERISTIC_UUID_MODEL_NUMBER,
15491548 NIMBLE_PROPERTY::READ
15501549 );
15511550 pCharacteristic_Model_Number->setValue (modelNumber);
15521551
1553- BLECharacteristic* pCharacteristic_Software_Revision = pService->createCharacteristic (
1552+ BLECharacteristic* pCharacteristic_Software_Revision = pService->createCharacteristic (
15541553 CHARACTERISTIC_UUID_SOFTWARE_REVISION,
15551554 NIMBLE_PROPERTY::READ
15561555 );
15571556 pCharacteristic_Software_Revision->setValue (softwareRevision);
15581557
1559- BLECharacteristic* pCharacteristic_Serial_Number = pService->createCharacteristic (
1558+ BLECharacteristic* pCharacteristic_Serial_Number = pService->createCharacteristic (
15601559 CHARACTERISTIC_UUID_SERIAL_NUMBER,
15611560 NIMBLE_PROPERTY::READ
15621561 );
15631562 pCharacteristic_Serial_Number->setValue (serialNumber);
15641563
1565- BLECharacteristic* pCharacteristic_Firmware_Revision = pService->createCharacteristic (
1564+ BLECharacteristic* pCharacteristic_Firmware_Revision = pService->createCharacteristic (
15661565 CHARACTERISTIC_UUID_FIRMWARE_REVISION,
15671566 NIMBLE_PROPERTY::READ
15681567 );
15691568 pCharacteristic_Firmware_Revision->setValue (firmwareRevision);
15701569
1571- BLECharacteristic* pCharacteristic_Hardware_Revision = pService->createCharacteristic (
1570+ BLECharacteristic* pCharacteristic_Hardware_Revision = pService->createCharacteristic (
15721571 CHARACTERISTIC_UUID_HARDWARE_REVISION,
15731572 NIMBLE_PROPERTY::READ
15741573 );
@@ -1577,8 +1576,8 @@ void BleGamepad::taskServer(void *pvParameter)
15771576 BleGamepadInstance->hid ->setPnp (0x01 , vid, pid, guidVersion);
15781577 BleGamepadInstance->hid ->setHidInfo (0x00 , 0x01 );
15791578
1580- // NimBLEDevice::setSecurityAuth(BLE_SM_PAIR_AUTHREQ_BOND);
1581- NimBLEDevice::setSecurityAuth (true , false , false ); // enable bonding, no MITM, no SC
1579+ // NimBLEDevice::setSecurityAuth(BLE_SM_PAIR_AUTHREQ_BOND);
1580+ NimBLEDevice::setSecurityAuth (true , false , false ); // enable bonding, no MITM, no SC
15821581
15831582
15841583 uint8_t *customHidReportDescriptor = new uint8_t [hidReportDescriptorSize];
0 commit comments