Fix bug, local BT client name
The local BT name was set to the remote server as well by mistake
This commit is contained in:
parent
89731d5def
commit
7187d1f82a
|
|
@ -30,8 +30,8 @@ static void scanCompleteCB(BLEScanResults scanResults)
|
||||||
{
|
{
|
||||||
scanResults.dump();
|
scanResults.dump();
|
||||||
if (doScan)
|
if (doScan)
|
||||||
{
|
|
||||||
pBLEScan->start(10, scanCompleteCB);
|
pBLEScan->start(10, scanCompleteCB);
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,12 +54,13 @@ public:
|
||||||
void * p = heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
|
void * p = heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
void(*_connectedCallback)() = NULL;
|
void(*_connectedCallback)() = NULL;
|
||||||
void(*_disconnectedCallback)() = NULL;
|
void(*_disconnectedCallback)() = NULL;
|
||||||
char _deviceName[32];
|
char _deviceName[32];
|
||||||
bool _doConnect;
|
bool _doConnect;
|
||||||
BLEAdvertisedDevice * _advertising;
|
BLEAdvertisedDevice * _advertising = NULL;
|
||||||
BLERemoteService* pRemoteService;
|
BLERemoteService* pRemoteService;
|
||||||
BLERemoteCharacteristic* pRemoteCharacteristic;
|
BLERemoteCharacteristic* pRemoteCharacteristic;
|
||||||
bool _connected;
|
bool _connected;
|
||||||
|
|
@ -158,6 +159,7 @@ protected:
|
||||||
|
|
||||||
bool connectToServer()
|
bool connectToServer()
|
||||||
{
|
{
|
||||||
|
const uint8_t bothOn[] = {0x3, 0x0};
|
||||||
// Connect to the remote BLE Server.
|
// Connect to the remote BLE Server.
|
||||||
pClient->connect(_advertising); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
|
pClient->connect(_advertising); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
|
||||||
|
|
||||||
|
|
@ -177,6 +179,7 @@ protected:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pRemoteCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)bothOn, 2, true);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -192,7 +195,7 @@ public:
|
||||||
|
|
||||||
// TODO why must these functions be inline??
|
// TODO why must these functions be inline??
|
||||||
|
|
||||||
inline bool begin(const char* deviceName);
|
inline bool begin(const char* thisDeviceName, const char *remoteDeviceName);
|
||||||
|
|
||||||
inline void read()
|
inline void read()
|
||||||
{
|
{
|
||||||
|
|
@ -311,10 +314,18 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// We have found a device, let us now see if it contains the service we are looking for.
|
// We have found a device, let us now see if it contains the service we are looking for.
|
||||||
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(BLEUUID(SERVICE_UUID)))
|
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(BLEUUID(SERVICE_UUID)))
|
||||||
{
|
{
|
||||||
|
|
||||||
BLEDevice::getScan()->stop();
|
BLEDevice::getScan()->stop();
|
||||||
|
|
||||||
|
if (_BleMidiInterfaceClient->_advertising != NULL)
|
||||||
|
{
|
||||||
|
delete(_BleMidiInterfaceClient->_advertising);
|
||||||
|
_BleMidiInterfaceClient->_advertising = NULL;
|
||||||
|
}
|
||||||
_BleMidiInterfaceClient->_advertising = new BLEAdvertisedDevice(advertisedDevice);
|
_BleMidiInterfaceClient->_advertising = new BLEAdvertisedDevice(advertisedDevice);
|
||||||
_BleMidiInterfaceClient->_doConnect = true;
|
_BleMidiInterfaceClient->_doConnect = true;
|
||||||
doScan = false;
|
doScan = false;
|
||||||
|
|
@ -327,11 +338,11 @@ protected:
|
||||||
|
|
||||||
}; // MyAdvertisedDeviceCallbacks
|
}; // MyAdvertisedDeviceCallbacks
|
||||||
|
|
||||||
bool BleMidiInterfaceClient::begin(const char* deviceName)
|
bool BleMidiInterfaceClient::begin(const char* thisDeviceName, const char *remoteDeviceName)
|
||||||
{
|
{
|
||||||
BLEDevice::init(deviceName);
|
BLEDevice::init(thisDeviceName);
|
||||||
|
|
||||||
strncpy(_deviceName, deviceName, 32);
|
strncpy(_deviceName, remoteDeviceName, 32);
|
||||||
|
|
||||||
pClient = BLEDevice::createClient();
|
pClient = BLEDevice::createClient();
|
||||||
pClient->setClientCallbacks(new MyClientCallbacks(this));
|
pClient->setClientCallbacks(new MyClientCallbacks(this));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue