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
@@ -653,16 +663,6 @@ class BLEDevice
653663 void setAddress (const bt_addr_le_t & addr);
654664
655665 void setAdvertiseData (const uint8_t * adv_data, uint8_t len);
656- /* *
657- * @brief The BLE device constructure
658- *
659- * @param[in] bleaddress BLE device address
660- *
661- * @return none
662- *
663- * @note none
664- */
665- BLEDevice (const bt_addr_le_t * bleaddress);
666666private:
667667 void preCheckProfile ();
668668
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 @@ -97,11 +97,11 @@ BLEDeviceManager::~BLEDeviceManager()
9797
9898bool BLEDeviceManager::begin (BLEDevice *device)
9999{
100- if (NULL == _local_ble && false == *device )
100+ if (NULL == _local_ble)
101101 {
102102 _local_ble = device;
103- _local_ble->setAddress (_local_bda);
104103 bt_le_set_mac_address (_local_bda);
104+
105105 // Set device name
106106 setDeviceName ();
107107 _state = BLE_PERIPH_STATE_READY;
@@ -133,7 +133,8 @@ void BLEDeviceManager::poll()
133133}
134134
135135void BLEDeviceManager::end ()
136- {}
136+ {
137+ }
137138
138139bool BLEDeviceManager::connected (const BLEDevice *device) const
139140{
@@ -287,7 +288,10 @@ void BLEDeviceManager::setDeviceName(const char* deviceName)
287288 if (len > BLE_MAX_DEVICE_NAME)
288289 len = BLE_MAX_DEVICE_NAME;
289290 memcpy (_device_name, deviceName, len);
290- setDeviceName ();
291+ if (NULL != _local_ble)
292+ {
293+ setDeviceName ();
294+ }
291295 }
292296}
293297
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