change BLECharacteristic callback signature BLECharacteristic& to BLECharacteristic*
This commit is contained in:
15 files changed
+35
-35
No files matched your search
@@ -7,6 +7,7 @@
|
||||
- Remove Gap.connected(), Gap.getRole() in prefer to BLEConnection API
|
||||
- Added setRssiCallback(), monitorRssi(), getRssi(), stopRssi() for tracking rssi of a connection
|
||||
- rssi_poll and rssi_callback example sketches are added
|
||||
- Change BLECharacteristic callback signature BLECharacteristic& to BLECharacteristic*
|
||||
|
||||
# 0.9.3
|
||||
|
||||
|
||||
@@ -556,7 +556,7 @@ void HAPCharacteristic::_eventHandler(ble_evt_t* event)
|
||||
{
|
||||
uint16_t value;
|
||||
memcpy(&value, request->data, 2);
|
||||
_cccd_wr_cb(*this, value);
|
||||
_cccd_wr_cb(this, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
|
||||
Serial.println("Advertising!");
|
||||
}
|
||||
|
||||
void cccd_callback(BLECharacteristic& chr, uint16_t cccd_value)
|
||||
void cccd_callback(BLECharacteristic* chr, uint16_t cccd_value)
|
||||
{
|
||||
// Display the raw request packet
|
||||
Serial.print("CCCD Updated: ");
|
||||
@@ -193,8 +193,8 @@ void cccd_callback(BLECharacteristic& chr, uint16_t cccd_value)
|
||||
|
||||
// Check the characteristic this CCCD update is associated with in case
|
||||
// this handler is used for multiple CCCD records.
|
||||
if (chr.uuid == hrmc.uuid) {
|
||||
if (chr.notifyEnabled()) {
|
||||
if (chr->uuid == hrmc.uuid) {
|
||||
if (chr->notifyEnabled()) {
|
||||
Serial.println("Heart Rate Measurement 'Notify' enabled");
|
||||
} else {
|
||||
Serial.println("Heart Rate Measurement 'Notify' disabled");
|
||||
|
||||
@@ -173,7 +173,7 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
|
||||
Serial.println("Advertising!");
|
||||
}
|
||||
|
||||
void cccd_callback(BLECharacteristic& chr, uint16_t cccd_value)
|
||||
void cccd_callback(BLECharacteristic* chr, uint16_t cccd_value)
|
||||
{
|
||||
// Display the raw request packet
|
||||
Serial.print("CCCD Updated: ");
|
||||
@@ -183,8 +183,8 @@ void cccd_callback(BLECharacteristic& chr, uint16_t cccd_value)
|
||||
|
||||
// Check the characteristic this CCCD update is associated with in case
|
||||
// this handler is used for multiple CCCD records.
|
||||
if (chr.uuid == htmc.uuid) {
|
||||
if (chr.indicateEnabled()) {
|
||||
if (chr->uuid == htmc.uuid) {
|
||||
if (chr->indicateEnabled()) {
|
||||
Serial.println("Temperature Measurement 'Indicate' enabled");
|
||||
} else {
|
||||
Serial.println("Temperature Measurement 'Indicate' disabled");
|
||||
|
||||
@@ -345,12 +345,12 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
|
||||
|
||||
if ( (request->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) && (_wr_authorize_cb != NULL))
|
||||
{
|
||||
_wr_authorize_cb(*this, &request->request.write);
|
||||
_wr_authorize_cb(this, &request->request.write);
|
||||
}
|
||||
|
||||
if ( (request->type == BLE_GATTS_AUTHORIZE_TYPE_READ) && (_rd_authorize_cb != NULL))
|
||||
{
|
||||
_rd_authorize_cb(*this, &request->request.read);
|
||||
_rd_authorize_cb(this, &request->request.read);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -376,7 +376,7 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
|
||||
// }else
|
||||
{
|
||||
// invoke directly if cannot allocate memory for data
|
||||
_wr_cb(*this, request->data, request->len, request->offset);
|
||||
_wr_cb(this, request->data, request->len, request->offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -392,7 +392,7 @@ void BLECharacteristic::_eventHandler(ble_evt_t* event)
|
||||
{
|
||||
uint16_t value;
|
||||
memcpy(&value, request->data, 2);
|
||||
_cccd_wr_cb(*this, value);
|
||||
_cccd_wr_cb(this, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +74,10 @@ class BLECharacteristic
|
||||
{
|
||||
public:
|
||||
/*--------- Callback Signatures ----------*/
|
||||
typedef void (*read_authorize_cb_t) (BLECharacteristic& chr, ble_gatts_evt_read_t * request);
|
||||
typedef void (*write_authorize_cb_t) (BLECharacteristic& chr, ble_gatts_evt_write_t* request);
|
||||
typedef void (*write_cb_t) (BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
typedef void (*write_cccd_cb_t) (BLECharacteristic& chr, uint16_t value);
|
||||
typedef void (*read_authorize_cb_t) (BLECharacteristic* chr, ble_gatts_evt_read_t * request);
|
||||
typedef void (*write_authorize_cb_t) (BLECharacteristic* chr, ble_gatts_evt_write_t* request);
|
||||
typedef void (*write_cb_t) (BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
typedef void (*write_cccd_cb_t) (BLECharacteristic* chr, uint16_t value);
|
||||
|
||||
BLEUuid uuid;
|
||||
|
||||
@@ -126,7 +126,6 @@ class BLECharacteristic
|
||||
uint16_t write32 (uint32_t num);
|
||||
uint16_t write32 (int num);
|
||||
|
||||
|
||||
/*------------- Read -------------*/
|
||||
uint16_t read(void* buffer, uint16_t bufsize, uint16_t offset = 0);
|
||||
|
||||
|
||||
@@ -85,9 +85,9 @@ static uint16_t crc16(const uint8_t* data_p, uint8_t length)
|
||||
return crc;
|
||||
}
|
||||
|
||||
static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt_write_t* request)
|
||||
static void bledfu_control_wr_authorize_cb(BLECharacteristic* chr, ble_gatts_evt_write_t* request)
|
||||
{
|
||||
if ( (request->handle == chr.handles().value_handle) &&
|
||||
if ( (request->handle == chr->handles().value_handle) &&
|
||||
(request->op != BLE_GATTS_OP_PREP_WRITE_REQ) &&
|
||||
(request->op != BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) &&
|
||||
(request->op != BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL))
|
||||
@@ -97,7 +97,7 @@ static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt
|
||||
|
||||
ble_gatts_rw_authorize_reply_params_t reply = { .type = BLE_GATTS_AUTHORIZE_TYPE_WRITE };
|
||||
|
||||
if ( !chr.notifyEnabled() )
|
||||
if ( !chr->notifyEnabled() )
|
||||
{
|
||||
reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR;
|
||||
sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
|
||||
|
||||
@@ -222,12 +222,12 @@ err_t BLEHidAdafruit::begin(void)
|
||||
/* Keyboard
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
void blehid_ada_keyboard_output_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset)
|
||||
void blehid_ada_keyboard_output_cb(BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset)
|
||||
{
|
||||
LOG_LV2("HID", "Keyboard LED : 0x%02X", data[0]);
|
||||
VERIFY(len == 1, );
|
||||
|
||||
BLEHidAdafruit& svc = (BLEHidAdafruit&) chr.parentService();
|
||||
BLEHidAdafruit& svc = (BLEHidAdafruit&) chr->parentService();
|
||||
if ( svc._kbd_led_cb ) svc._kbd_led_cb(data[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class BLEHidAdafruit : public BLEHidGeneric
|
||||
uint8_t _mse_buttons;
|
||||
kbd_led_cb_t _kbd_led_cb;
|
||||
|
||||
friend void blehid_ada_keyboard_output_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
friend void blehid_ada_keyboard_output_cb(BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
};
|
||||
|
||||
#endif /* BLEHIDADAFRUIT_H_ */
|
||||
@@ -130,9 +130,9 @@ void BLEHidGeneric::setOutputReportCallback(uint8_t reportID, BLECharacteristic:
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Callbacks
|
||||
*------------------------------------------------------------------*/
|
||||
void blehid_generic_protocol_mode_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset)
|
||||
void blehid_generic_protocol_mode_cb(BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset)
|
||||
{
|
||||
BLEHidGeneric& svc = (BLEHidGeneric&) chr.parentService();
|
||||
BLEHidGeneric& svc = (BLEHidGeneric&) chr->parentService();
|
||||
svc._protocol_mode = *data;
|
||||
|
||||
LOG_LV2("HID", "Protocol Mode : %d (0 Boot, 1 Report)", *data);
|
||||
|
||||
@@ -149,7 +149,7 @@ class BLEHidGeneric : public BLEService
|
||||
|
||||
BLECharacteristic _chr_control;
|
||||
|
||||
friend void blehid_generic_protocol_mode_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
friend void blehid_generic_protocol_mode_cb(BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@@ -106,7 +106,7 @@ typedef struct ATTR_PACKED
|
||||
|
||||
VERIFY_STATIC ( sizeof(midi_split_packet_t) == (BLE_MIDI_TX_BUFFER_SIZE + 1) );
|
||||
|
||||
void blemidi_write_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
void blemidi_write_cb(BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* IMPLEMENTATION
|
||||
@@ -161,12 +161,12 @@ err_t BLEMidi::begin(void)
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Callbacks
|
||||
*------------------------------------------------------------------*/
|
||||
void blemidi_write_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset)
|
||||
void blemidi_write_cb(BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset)
|
||||
{
|
||||
(void) offset;
|
||||
if ( len < 3 ) return;
|
||||
|
||||
BLEMidi& midi_svc = (BLEMidi&) chr.parentService();
|
||||
BLEMidi& midi_svc = (BLEMidi&) chr->parentService();
|
||||
midi_svc._write_handler(data, len);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ class BLEMidi: public BLEService, public Stream
|
||||
|
||||
void _write_handler(uint8_t* data, uint16_t len);
|
||||
|
||||
friend void blemidi_write_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
friend void blemidi_write_cb(BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -90,11 +90,11 @@ BLEUart::~BLEUart()
|
||||
* @param len
|
||||
* @param offset
|
||||
*/
|
||||
void bleuart_rxd_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset)
|
||||
void bleuart_rxd_cb(BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset)
|
||||
{
|
||||
(void) offset;
|
||||
|
||||
BLEUart& svc = (BLEUart&) chr.parentService();
|
||||
BLEUart& svc = (BLEUart&) chr->parentService();
|
||||
svc._rx_fifo->write(data, len);
|
||||
|
||||
#if CFG_DEBUG >= 2
|
||||
@@ -121,9 +121,9 @@ void bleuart_txd_buffered_hdlr(TimerHandle_t timer)
|
||||
(void) svc->flush_tx_buffered();
|
||||
}
|
||||
|
||||
void bleuart_txd_cccd_cb(BLECharacteristic& chr, uint16_t value)
|
||||
void bleuart_txd_cccd_cb(BLECharacteristic* chr, uint16_t value)
|
||||
{
|
||||
BLEUart& svc = (BLEUart&) chr.parentService();
|
||||
BLEUart& svc = (BLEUart&) chr->parentService();
|
||||
|
||||
if ( svc._buffered_th == NULL) return;
|
||||
|
||||
|
||||
@@ -95,8 +95,8 @@ class BLEUart : public BLEService, public Stream
|
||||
virtual void _disconnect_cb(void);
|
||||
virtual void _connect_cb(void);
|
||||
|
||||
friend void bleuart_rxd_cb(BLECharacteristic& chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
friend void bleuart_txd_cccd_cb(BLECharacteristic& chr, uint16_t value);
|
||||
friend void bleuart_rxd_cb(BLECharacteristic* chr, uint8_t* data, uint16_t len, uint16_t offset);
|
||||
friend void bleuart_txd_cccd_cb(BLECharacteristic* chr, uint16_t value);
|
||||
friend void bleuart_txd_buffered_hdlr(TimerHandle_t timer);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user