introduce BLEGatt class
This commit is contained in:
1 parent
bd013738b9
commit
3c0f3e84f1
7 files changed
+135
-21
No files matched your search
@@ -1,2 +1,3 @@
|
||||
# Adafruit_nRF52_Arduino_Helpers
|
||||
Helper libraries and classes for the Adafruit_nRF52_Arduino repository
|
||||
# Adafruit Feather nRF52 Bluefruit Libraries
|
||||
|
||||
Peripherals & Central library
|
||||
@@ -278,7 +278,7 @@ err_t BLECharacteristic::begin(void)
|
||||
if ( !_is_temp &&
|
||||
(_rd_authorize_cb || _wr_authorize_cb || _wr_cb || _cccd_wr_cb) )
|
||||
{
|
||||
(void) Bluefruit._registerCharacteristic(this);
|
||||
(void) Bluefruit.Gatt._registerCharacteristic(this);
|
||||
}
|
||||
|
||||
return ERROR_NONE;
|
||||
|
||||
@@ -163,8 +163,7 @@ class BLECharacteristic
|
||||
err_t notify(uint16_t num);
|
||||
err_t notify(uint8_t num);
|
||||
|
||||
|
||||
friend class AdafruitBluefruit;
|
||||
friend class BLEGatt;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file BLEGatt.cpp
|
||||
@author hathach
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2017, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "bluefruit.h"
|
||||
|
||||
|
||||
BLEGatt::BLEGatt(void)
|
||||
{
|
||||
_chars_count = 0;
|
||||
for(uint8_t i=0; i<BLE_MAX_CHARS; i++) _chars_list[i] = NULL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void BLEGatt::_eventHandler(ble_evt_t* evt)
|
||||
{
|
||||
// Server Characteristics
|
||||
for(int i=0; i<_chars_count; i++) _chars_list[i]->_eventHandler(evt);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool BLEGatt::_registerCharacteristic(BLECharacteristic* chars)
|
||||
{
|
||||
if ( _chars_count == BLE_MAX_CHARS ) return false;
|
||||
_chars_list[ _chars_count++ ] = chars;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file BLEGatt.h
|
||||
@author hathach
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2017, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#ifndef BLEGATT_H_
|
||||
#define BLEGATT_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "bluefruit_common.h"
|
||||
|
||||
#include "BLEUuid.h"
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
#include "BLECentralCharacteristic.h"
|
||||
#include "BLECentralService.h"
|
||||
|
||||
#define BLE_MAX_CHARS 40
|
||||
|
||||
class BLEGatt
|
||||
{
|
||||
public:
|
||||
BLEGatt(void);
|
||||
|
||||
bool _registerCharacteristic(BLECharacteristic* chars);
|
||||
void _eventHandler(ble_evt_t* evt);
|
||||
|
||||
private:
|
||||
BLECharacteristic* _chars_list[BLE_MAX_CHARS];
|
||||
uint8_t _chars_count;
|
||||
};
|
||||
|
||||
#endif /* BLEGATT_H_ */
|
||||
@@ -116,9 +116,6 @@ COMMENT_OUT(
|
||||
varclr(_pin);
|
||||
)
|
||||
|
||||
_chars_count = 0;
|
||||
for(uint8_t i=0; i<BLE_MAX_CHARS; i++) _chars_list[i] = NULL;
|
||||
|
||||
varclr(&_bond_data);
|
||||
_bond_data.own_enc.master_id.ediv = 0xFFFF; // invalid value for ediv
|
||||
|
||||
@@ -331,14 +328,6 @@ void AdafruitBluefruit::setDisconnectCallback( disconnect_callback_t fp )
|
||||
_discconnect_cb = fp;
|
||||
}
|
||||
|
||||
bool AdafruitBluefruit::_registerCharacteristic(BLECharacteristic* chars)
|
||||
{
|
||||
if ( _chars_count == BLE_MAX_CHARS ) return false;
|
||||
_chars_list[ _chars_count++ ] = chars;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t AdafruitBluefruit::connHandle(void)
|
||||
{
|
||||
return _conn_hdl;
|
||||
@@ -691,10 +680,7 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
if ( Discovery.begun() ) Discovery._event_handler(evt);
|
||||
|
||||
// GATTs characteristics event handler
|
||||
for(int i=0; i<_chars_count; i++)
|
||||
{
|
||||
_chars_list[i]->_eventHandler(evt);
|
||||
}
|
||||
Gatt._eventHandler(evt);
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Bonds
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "BLECentralCharacteristic.h"
|
||||
#include "BLECentralService.h"
|
||||
#include "BLEDiscovery.h"
|
||||
#include "BLEGatt.h"
|
||||
|
||||
// Services
|
||||
#include "services/BLEDis.h"
|
||||
@@ -60,7 +61,6 @@
|
||||
|
||||
#include "central_services/BLECentralUart.h"
|
||||
|
||||
#define BLE_MAX_CHARS 50
|
||||
#define BLE_MAX_DATA_PER_MTU (GATT_MTU_SIZE_DEFAULT - 3)
|
||||
|
||||
extern "C"
|
||||
@@ -84,6 +84,8 @@ class AdafruitBluefruit
|
||||
BLECentral Central;
|
||||
BLEDiscovery Discovery;
|
||||
|
||||
BLEGatt Gatt;
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* General Purpose Functions
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
Reference in new issue
Block a user