File tree Expand file tree Collapse file tree 4 files changed +20
-51
lines changed Expand file tree Collapse file tree 4 files changed +20
-51
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,16 @@ class BLEDevice
5959 */
6060 BLEDevice (const BLEDevice* bledevice);
6161 BLEDevice (const BLEDevice& bledevice);
62+ /* *
63+ * @brief The BLE device constructure
64+ *
65+ * @param[in] bleaddress BLE device address
66+ *
67+ * @return none
68+ *
69+ * @note none
70+ */
71+ BLEDevice (const bt_addr_le_t * bleaddress);
6272 virtual ~BLEDevice ();
6373
6474
@@ -654,16 +664,6 @@ class BLEDevice
654664 void setAddress (const bt_addr_le_t & addr);
655665
656666 void setAdvertiseData (const uint8_t * adv_data, uint8_t len);
657- /* *
658- * @brief The BLE device constructure
659- *
660- * @param[in] bleaddress BLE device address
661- *
662- * @return none
663- *
664- * @note none
665- */
666- BLEDevice (const bt_addr_le_t * bleaddress);
667667private:
668668 void preCheckProfile ();
669669
Original file line number Diff line number Diff line change @@ -55,67 +55,37 @@ BLEPeripheral::~BLEPeripheral(void)
5555
5656void BLEPeripheral::setAdvertisedServiceUuid (const char * advertisedServiceUuid)
5757{
58- if (!_initCalled) {
59- init ();
60- }
61-
6258 BLE.setAdvertisedServiceUuid (advertisedServiceUuid);
6359}
60+
6461void BLEPeripheral::setLocalName (const char * localName)
6562{
66- if (!_initCalled) {
67- init ();
68- }
69-
7063 BLE.setLocalName (localName);
7164}
7265
73-
7466void BLEPeripheral::setDeviceName (const char *deviceName)
7567{
76- if (!_initCalled) {
77- init ();
78- }
79-
8068 BLE.setDeviceName (deviceName);
8169}
8270
8371void BLEPeripheral::setAppearance (const unsigned short appearance)
8472{
85- if (!_initCalled) {
86- init ();
87- }
88-
8973 BLE.setAppearance (appearance);
9074}
9175
9276void BLEPeripheral::setConnectionInterval (const unsigned short minConnInterval, const unsigned short maxConnInterval)
9377{
94- if (!_initCalled) {
95- init ();
96- }
97-
9878 BLE.setConnectionInterval (minConnInterval, maxConnInterval);
9979}
10080
10181void BLEPeripheral::addAttribute (BLEService& service)
10282{
103- if (!_initCalled)
104- {
105- init ();
106- }
107-
10883 BLE.addService (service);
10984 _lastService = &service;
11085}
11186
11287void BLEPeripheral::addAttribute (BLECharacteristic& characteristic)
11388{
114- if (!_initCalled)
115- {
116- init ();
117- }
118-
11989 if (_lastService)
12090 {
12191 _lastService->addCharacteristic (characteristic);
@@ -125,11 +95,6 @@ void BLEPeripheral::addAttribute(BLECharacteristic& characteristic)
12595
12696void BLEPeripheral::addAttribute (BLEDescriptor& descriptor)
12797{
128- if (!_initCalled)
129- {
130- init ();
131- }
132-
13398 if (_lastCharacteristic)
13499 {
135100 _lastCharacteristic->addDescriptor (descriptor);
Original file line number Diff line number Diff line change @@ -98,11 +98,11 @@ BLEDeviceManager::~BLEDeviceManager()
9898
9999bool BLEDeviceManager::begin (BLEDevice *device)
100100{
101- if (NULL == _local_ble && false == *device )
101+ if (NULL == _local_ble)
102102 {
103103 _local_ble = device;
104- _local_ble->setAddress (_local_bda);
105104 bt_le_set_mac_address (_local_bda);
105+
106106 // Set device name
107107 setDeviceName ();
108108 _state = BLE_PERIPH_STATE_READY;
@@ -134,7 +134,8 @@ void BLEDeviceManager::poll()
134134}
135135
136136void BLEDeviceManager::end ()
137- {}
137+ {
138+ }
138139
139140bool BLEDeviceManager::connected (const BLEDevice *device) const
140141{
@@ -288,7 +289,10 @@ void BLEDeviceManager::setDeviceName(const char* deviceName)
288289 if (len > BLE_MAX_DEVICE_NAME)
289290 len = BLE_MAX_DEVICE_NAME;
290291 memcpy (_device_name, deviceName, len);
291- setDeviceName ();
292+ if (NULL != _local_ble)
293+ {
294+ setDeviceName ();
295+ }
292296 }
293297}
294298
Original file line number Diff line number Diff line change 2525#include " BLECallbacks.h"
2626#include " BLEUtils.h"
2727
28- BLEDevice BLE;
28+ BLEDevice BLE (BLEUtils::bleGetLoalAddress()) ;
2929
3030BLEProfileManager* BLEProfileManager::_instance = NULL ;
3131
You can’t perform that action at this time.
0 commit comments