Fixed not being able to pair with Windows when using NimBLE
and, consideration for boards that don't implement the `LED_BUILTIN` constant
This commit is contained in:
parent
9b41d732ef
commit
ab02fbc108
|
|
@ -17,8 +17,10 @@ void setup()
|
|||
{
|
||||
MIDI.begin();
|
||||
|
||||
#ifdef LED_BUILTIN
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
#endif
|
||||
|
||||
BLEMIDI.setHandleConnected(OnConnected);
|
||||
BLEMIDI.setHandleDisconnected(OnDisconnected);
|
||||
|
|
@ -51,7 +53,9 @@ void loop()
|
|||
// -----------------------------------------------------------------------------
|
||||
void OnConnected() {
|
||||
isConnected = true;
|
||||
#ifdef LED_BUILTIN
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -59,7 +63,9 @@ void OnConnected() {
|
|||
// -----------------------------------------------------------------------------
|
||||
void OnDisconnected() {
|
||||
isConnected = false;
|
||||
#ifdef LED_BUILTIN
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -19,8 +19,10 @@ void setup()
|
|||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
#ifdef LED_BUILTIN
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
#endif
|
||||
|
||||
BLEMIDI.setHandleConnected(OnConnected);
|
||||
BLEMIDI.setHandleDisconnected(OnDisconnected);
|
||||
|
|
@ -49,7 +51,9 @@ void loop()
|
|||
// -----------------------------------------------------------------------------
|
||||
void OnConnected() {
|
||||
isConnected = true;
|
||||
#ifdef LED_BUILTIN
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -57,7 +61,9 @@ void OnConnected() {
|
|||
// -----------------------------------------------------------------------------
|
||||
void OnDisconnected() {
|
||||
isConnected = false;
|
||||
#ifdef LED_BUILTIN
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -41,8 +41,10 @@ bool isConnected = false;
|
|||
// -----------------------------------------------------------------------------
|
||||
void setup()
|
||||
{
|
||||
#ifdef LED_BUILTIN
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
#endif
|
||||
|
||||
BLEMIDI.setHandleConnected(OnConnected);
|
||||
BLEMIDI.setHandleDisconnected(OnDisconnected);
|
||||
|
|
@ -75,7 +77,9 @@ void loop()
|
|||
// -----------------------------------------------------------------------------
|
||||
void OnConnected() {
|
||||
isConnected = true;
|
||||
#ifdef LED_BUILTIN
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -83,5 +87,7 @@ void OnConnected() {
|
|||
// -----------------------------------------------------------------------------
|
||||
void OnDisconnected() {
|
||||
isConnected = false;
|
||||
#ifdef LED_BUILTIN
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,17 +128,17 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char* deviceName, BLEMIDI_Transport<class
|
|||
);
|
||||
|
||||
_characteristic->setCallbacks(new MyCharacteristicCallbacks(this));
|
||||
|
||||
auto _security = new NimBLESecurity();
|
||||
_security->setAuthenticationMode(ESP_LE_AUTH_BOND);
|
||||
|
||||
// Start the service
|
||||
service->start();
|
||||
|
||||
auto advertisementData = BLEAdvertisementData();
|
||||
advertisementData.setFlags(0x04);
|
||||
advertisementData.setCompleteServices(BLEUUID(SERVICE_UUID));
|
||||
advertisementData.setName(deviceName);
|
||||
|
||||
// Start advertising
|
||||
_advertising = _server->getAdvertising();
|
||||
_advertising->setAdvertisementData(advertisementData);
|
||||
_advertising->addServiceUUID(service->getUUID());
|
||||
_advertising->setAppearance(0x00);
|
||||
_advertising->start();
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue