8000 move m_bleAdvertising to BLEDevice · twellocity/esp32-snippets@874ce79 · GitHub
[go: up one dir, main page]

Skip to content

Commit 874ce79

Browse files
committed
move m_bleAdvertising to BLEDevice
1 parent ade8bcd commit 874ce79

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

cpp_utils/BLEDevice.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ bool initialized = false; // Have we been initialized?
4545
esp_ble_sec_act_t BLEDevice::m_securityLevel = (esp_ble_sec_act_t)0;
4646
BLESecurityCallbacks* BLEDevice::m_securityCallbacks = nullptr;
4747
uint16_t BLEDevice::m_localMTU = 23;
48+
BLEAdvertising* BLEDevice::m_bleAdvertising = nullptr;
4849

4950
/**
5051
* @brief Create a new instance of a client.
@@ -545,4 +546,21 @@ uint16_t BLEDevice::getMTU() {
545546
bool BLEDevice::getInitialized() {
546547
return initialized;
547548
}
549+
550+
BLEAdvertising* BLEDevice::getAdvertising() {
551+
if(m_bleAdvertising == nullptr)
552+
{
553+
m_bleAdvertising = new BLEAdvertising();
554+
ESP_LOGI(LOG_TAG, "create advertising");
555+
}
556+
ESP_LOGD(LOG_TAG, "get advertising");
557+
return m_bleAdvertising;
558+
}
559+
560+
void BLEDevice::startAdvertising() {
561+
ESP_LOGD(LOG_TAG, ">> startAdvertising");
562+
getAdvertising()->start();
563+
ESP_LOGD(LOG_TAG, "<< startAdvertising");
564+
} // startAdvertising
565+
548566
#endif // CONFIG_BT_ENABLED

cpp_utils/BLEDevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class BLEDevice {
4343
static esp_err_t setMTU(uint16_t mtu);
4444
static uint16_t getMTU();
4545
static bool getInitialized(); // Returns the state of the device, is it initialized or not?
46+
static BLEAdvertising* getAdvertising();
47+
static void startAdvertising();
4648

4749
private:
4850
static BLEServer *m_pServer;
@@ -51,6 +53,7 @@ class BLEDevice {
5153
static esp_ble_sec_act_t m_securityLevel;
5254
static BLESecurityCallbacks* m_securityCallbacks;
5355
static uint16_t m_localMTU;
56+
static BLEAdvertising *m_bleAdvertising;
5457

5558
static esp_gatt_if_t getGattcIF();
5659

cpp_utils/BLEServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ BLEService* BLEServer::getServiceByUUID(BLEUUID uuid) {
120120
* @return An advertising object.
121121
*/
122122
BLEAdvertising* BLEServer::getAdvertising() {
123-
return &m_bleAdvertising;
123+
return BLEDevice::getAdvertising();
124124
}
125125

126126
uint16_t BLEServer::getConnId() {
@@ -359,7 +359,7 @@ void BLEServer::removeService(BLEService *service) {
359359
*/
360360
void BLEServer::startAdvertising() {
361361
ESP_LOGD(LOG_TAG, ">> startAdvertising");
362-
m_bleAdvertising.start();
362+
BLEDevice::startAdvertising();
363363
ESP_LOGD(LOG_TAG, "<< startAdvertising");
364364
} // startAdvertising
365365

cpp_utils/BLEServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BLEServer {
7373
friend class BLEDevice;
7474
esp_ble_adv_data_t m_adv_data;
7575
uint16_t m_appId;
76-
BLEAdvertising m_bleAdvertising;
76+
// BLEAdvertising m_bleAdvertising;
7777
uint16_t m_connId;
7878
uint32_t m_connectedCount;
7979
uint16_t m_gatts_if;

0 commit comments

Comments
 (0)
0