Skip to content

Commit 599230b

Browse files
committed
Fix back compatible build issue
1 parent c46f904 commit 599230b

8 files changed

+116
-55
lines changed

libraries/BLE/src/ArduinoBLE.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define ARDUINO_BLE_API_VERSION 10000 // version 1.0.0
2424

2525
class BLEDevice;
26+
class BLECentral;
2627
class BLECharacteristic;
2728
class BLEDescriptor;
2829
class BLEService;

libraries/BLE/src/BLECentral.h

+45-44
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
1-
/*
2-
BLE Central API (deprecated)
3-
Copyright (c) 2016 Arduino LLC. All right reserved.
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
9-
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
14-
15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
19-
20-
#ifndef ARDUINO_CENTRAL_H
21-
#define ARDUINO_CENTRAL_H
22-
23-
class BLECentral {
24-
public:
25-
bool connected(void); // is the central connected
26-
27-
const char* address(void) const; // address of the Central in string form
28-
29-
bool disconnect(void); // Disconnect the central if it is connected
30-
void poll(void); // Poll the central for events
31-
32-
operator bool(void) const;
33-
bool operator==(const BLECentral& rhs) const;
34-
bool operator!=(const BLECentral& rhs) const;
35-
protected:
36-
friend void bleBackCompatiblePeripheralConnectHandler(BLEDevice central);
37-
friend void bleBackCompatiblePeripheralDisconnectHandler(BLEDevice central);
38-
friend class BLEPeripheral;
39-
BLECentral(BLEDevice& device);
40-
private:
41-
42-
BLEDevice _device;
43-
};
44-
1+
/*
2+
BLE Central API (deprecated)
3+
Copyright (c) 2016 Arduino LLC. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef ARDUINO_CENTRAL_H
21+
#define ARDUINO_CENTRAL_H
22+
23+
class BLECentral {
24+
public:
25+
bool connected(void); // is the central connected
26+
27+
const char* address(void) const; // address of the Central in string form
28+
29+
bool disconnect(void); // Disconnect the central if it is connected
30+
void poll(void); // Poll the central for events
31+
32+
operator bool(void) const;
33+
bool operator==(const BLECentral& rhs) const;
34+
bool operator!=(const BLECentral& rhs) const;
35+
protected:
36+
friend class BLECharacteristicImp;
37+
friend void bleBackCompatiblePeripheralConnectHandler(BLEDevice central);
38+
friend void bleBackCompatiblePeripheralDisconnectHandler(BLEDevice central);
39+
friend class BLEPeripheral;
40+
BLECentral(BLEDevice& device);
41+
private:
42+
43+
BLEDevice _device;
44+
};
45+
4546
#endif

libraries/BLE/src/BLECharacteristic.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,25 @@ void BLECharacteristic::setEventHandler(BLECharacteristicEvent event,
550550
}
551551
}
552552

553+
void BLECharacteristic::setEventHandler(BLECharacteristicEvent event,
554+
BLECharacteristicEventHandlerOld eventHandler)
555+
{
556+
BLECharacteristicImp *characteristicImp = getImplementation();
557+
if (event >= BLECharacteristicEventLast)
558+
{
559+
return;
560+
}
561+
562+
if (NULL != characteristicImp)
563+
{
564+
characteristicImp->setEventHandler(event, eventHandler);
565+
}
566+
else
567+
{
568+
_oldevent_handlers[event] = eventHandler;
569+
}
570+
}
571+
553572

554573
void
555574
BLECharacteristic::_setValue(const uint8_t value[], uint16_t length)

libraries/BLE/src/BLECharacteristic.h

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ enum BLEProperty {
4343

4444
typedef void (*BLECharacteristicEventHandler)(BLEDevice bledev, BLECharacteristic characteristic);
4545

46+
typedef void (*BLECharacteristicEventHandlerOld)(BLECentral &central, BLECharacteristic &characteristic);
47+
4648
//#include "BLECharacteristicImp.h"
4749

4850
class BLECharacteristic: public BLEAttributeWithValue
@@ -462,6 +464,8 @@ class BLECharacteristic: public BLEAttributeWithValue
462464
*/
463465
void setEventHandler(BLECharacteristicEvent event,
464466
BLECharacteristicEventHandler eventHandler);
467+
void setEventHandler(BLECharacteristicEvent event,
468+
BLECharacteristicEventHandlerOld eventHandler);
465469

466470
protected:
467471
friend class BLEDevice;
@@ -525,6 +529,8 @@ class BLECharacteristic: public BLEAttributeWithValue
525529
unsigned char* _value; // The value. Will delete after create the _internal
526530

527531
BLECharacteristicEventHandler _event_handlers[BLECharacteristicEventLast]; // Sid. Define the arr as in BLECharacteristicImp.h
532+
533+
BLECharacteristicEventHandlerOld _oldevent_handlers[BLECharacteristicEventLast];
528534
};
529535

530536
#endif

libraries/BLE/src/BLEDevice.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ BLEDevice::BLEDevice(const BLEDevice* bledevice)
5959
memcpy(&_conn_param, &bledevice->_conn_param, sizeof (ble_conn_param_t));
6060
}
6161

62+
BLEDevice::BLEDevice(const BLEDevice& bledevice)
63+
{
64+
memcpy(&_bt_addr, bledevice.bt_le_address(), sizeof(bt_addr_le_t));
65+
memcpy(&_conn_param, &bledevice._conn_param, sizeof (ble_conn_param_t));
66+
}
67+
6268
BLEDevice::~BLEDevice()
6369
{
6470
//pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__);
@@ -190,15 +196,15 @@ BLEDevice::operator bool() const
190196
return BLEUtils::macAddressValid(_bt_addr);
191197
}
192198

193-
//BLEDevice& BLEDevice::operator=(const BLEDevice& device)
194-
//{
195-
// if (*this != device)
196-
// {
197-
// memcpy(&(this->_bt_addr), &(device._bt_addr), sizeof (bt_addr_le_t));
198-
// memcpy(*this->_conn_param, &device._conn_param, sizeof (bt_le_conn_param));
199-
// }
200-
// return *this;
201-
//}
199+
BLEDevice& BLEDevice::operator=(const BLEDevice& device)
200+
{
201+
if (*this != device)
202+
{
203+
memcpy(&(this->_bt_addr), &(device._bt_addr), sizeof (bt_addr_le_t));
204+
memcpy(&this->_conn_param, &device._conn_param, sizeof (bt_le_conn_param));
205+
}
206+
return *this;
207+
}
202208

203209
bool BLEDevice::operator==(const BLEDevice& device) const
204210
{

libraries/BLE/src/BLEDevice.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class BLEDevice
5858
* @note none
5959
*/
6060
BLEDevice(const BLEDevice* bledevice);
61-
61+
BLEDevice(const BLEDevice& bledevice);
6262
virtual ~BLEDevice();
6363

6464

@@ -340,7 +340,7 @@ class BLEDevice
340340
operator bool() const;
341341
bool operator==(const BLEDevice& device) const;
342342
bool operator!=(const BLEDevice& device) const;
343-
343+
BLEDevice& operator=(const BLEDevice& device);
344344
// central mode
345345

346346
//void scanForAddress(String address); // Not include in baseline. Add here as feature for feature release.

libraries/BLE/src/internal/BLECharacteristicImp.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ BLECharacteristicImp::BLECharacteristicImp(const bt_uuid_t* uuid,
8686
}
8787
_gatt_chrc.uuid = (bt_uuid_t*)this->bt_uuid();//&_characteristic_uuid;//this->uuid();
8888
memset(_event_handlers, 0, sizeof(_event_handlers));
89+
memset(_oldevent_handlers, 0, sizeof(_oldevent_handlers));
8990

9091
_sub_params.notify = profile_notify_process;
9192

@@ -149,6 +150,7 @@ BLECharacteristicImp::BLECharacteristicImp(BLECharacteristic& characteristic,
149150
_gatt_chrc.uuid = (bt_uuid_t*)this->bt_uuid();//&_characteristic_uuid;//this->uuid();
150151

151152
memcpy(_event_handlers, characteristic._event_handlers, sizeof(_event_handlers));
153+
memcpy(_oldevent_handlers, characteristic._oldevent_handlers, sizeof(_oldevent_handlers));
152154

153155
_sub_params.notify = profile_notify_process;
154156

@@ -251,6 +253,13 @@ BLECharacteristicImp::setValue(const unsigned char value[], uint16_t length)
251253
BLECharacteristic chrcTmp(this, &_ble_device);
252254
_event_handlers[BLEWritten](_ble_device, chrcTmp);
253255
}
256+
257+
if (_oldevent_handlers[BLEWritten])
258+
{
259+
BLECharacteristic chrcTmp(this, &_ble_device);
260+
BLECentral central(_ble_device);
261+
_oldevent_handlers[BLEWritten](central, chrcTmp);
262+
}
254263
}
255264
else
256265
{
@@ -262,6 +271,13 @@ BLECharacteristicImp::setValue(const unsigned char value[], uint16_t length)
262271
BLECharacteristic chrcTmp(this, &_ble_device);
263272
_event_handlers[BLEValueUpdated](_ble_device, chrcTmp);
264273
}
274+
275+
if (_oldevent_handlers[BLEValueUpdated])
276+
{
277+
BLECharacteristic chrcTmp(this, &_ble_device);
278+
BLECentral central(_ble_device);
279+
_oldevent_handlers[BLEValueUpdated](central, chrcTmp);
280+
}
265281
}
266282

267283
return true;
@@ -456,6 +472,16 @@ BLECharacteristicImp::setEventHandler(BLECharacteristicEvent event, BLECharacter
456472
interrupts();
457473
}
458474

475+
void
476+
BLECharacteristicImp::setEventHandler(BLECharacteristicEvent event, BLECharacteristicEventHandlerOld callback)
477+
{
478+
noInterrupts();
479+
if (event < BLECharacteristicEventLast) {
480+
_oldevent_handlers[event] = callback;
481+
}
482+
interrupts();
483+
}
484+
459485
void
460486
BLECharacteristicImp::setHandle(uint16_t handle)
461487
{

libraries/BLE/src/internal/BLECharacteristicImp.h

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class BLECharacteristicImp: public BLEAttribute{
141141
* @param[in] callback Pointer to callback function to invoke when the event occurs.
142142
*/
143143
void setEventHandler(BLECharacteristicEvent event, BLECharacteristicEventHandler callback);
144+
void setEventHandler(BLECharacteristicEvent event, BLECharacteristicEventHandlerOld callback);
144145

145146
/**
146147
* @brief Schedule the read request to read the characteristic in peripheral
@@ -331,6 +332,7 @@ class BLECharacteristicImp: public BLEAttribute{
331332
typedef LinkNode<BLEDescriptorImp *> BLEDescriptorNode;
332333

333334
BLECharacteristicEventHandler _event_handlers[BLECharacteristicEventLast];
335+
BLECharacteristicEventHandlerOld _oldevent_handlers[BLECharacteristicEventLast];
334336
BLEDescriptorLinkNodeHeader _descriptors_header;
335337
BLEDevice _ble_device;
336338
};

0 commit comments

Comments
 (0)