add parent service for central
This commit is contained in:
1 parent
9f40cbfb1e
commit
be42b0a360
8 files changed
+29
-9
No files matched your search
@@ -248,11 +248,6 @@ bool BLECentral::discoverService(BLEUuid uuid, uint16_t start_handle)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BLECentral::discoverService(BLECentralService& svc, uint16_t start_handle)
|
||||
{
|
||||
return svc.discover(start_handle);
|
||||
}
|
||||
|
||||
bool BLECentral::discoverCharacteristic(BLECentralCharacteristic& chr)
|
||||
{
|
||||
ble_gattc_evt_char_disc_rsp_t disc_chr;
|
||||
|
||||
@@ -90,8 +90,6 @@ class BLECentral
|
||||
/* GATTC Discovery
|
||||
*------------------------------------------------------------------*/
|
||||
bool discoverService(BLEUuid uuid, uint16_t start_handle = 1);
|
||||
bool discoverService(BLECentralService& svc, uint16_t start_handle = 1);
|
||||
|
||||
bool discoverCharacteristic(BLECentralCharacteristic& chr);
|
||||
|
||||
|
||||
|
||||
@@ -64,6 +64,11 @@ uint16_t BLECentralCharacteristic::valueHandle()
|
||||
return _chr.handle_value;
|
||||
}
|
||||
|
||||
BLECentralService& BLECentralCharacteristic::parentService (void)
|
||||
{
|
||||
return *_service;
|
||||
}
|
||||
|
||||
bool BLECentralCharacteristic::discoverDescriptor(void)
|
||||
{
|
||||
struct {
|
||||
@@ -89,6 +94,8 @@ bool BLECentralCharacteristic::discoverDescriptor(void)
|
||||
|
||||
void BLECentralCharacteristic::begin(void)
|
||||
{
|
||||
_service = BLECentralService::lastService;
|
||||
|
||||
// Currently Only register to Bluefruit if callback is installed
|
||||
if ( _notify_cb )
|
||||
{
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
#include "BLEUuid.h"
|
||||
#include "BLECharacteristic.h"
|
||||
|
||||
// forward declaration
|
||||
class BLECentralService;
|
||||
|
||||
class BLECentralCharacteristic
|
||||
{
|
||||
public:
|
||||
@@ -52,6 +55,7 @@ class BLECentralCharacteristic
|
||||
void begin(void);
|
||||
|
||||
uint16_t valueHandle();
|
||||
BLECentralService& parentService(void);
|
||||
|
||||
/*------------- Read -------------*/
|
||||
uint16_t read(void* buffer, int bufsize, uint16_t offset = 0);
|
||||
@@ -72,6 +76,7 @@ class BLECentralCharacteristic
|
||||
ble_gattc_char_t _chr;
|
||||
uint16_t _cccd_handle;
|
||||
|
||||
BLECentralService* _service;
|
||||
notify_cb_t _notify_cb;
|
||||
|
||||
void _init(void);
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
|
||||
#include "bluefruit.h"
|
||||
|
||||
// Last service that is discovered
|
||||
BLECentralService* BLECentralService::lastService = NULL;
|
||||
|
||||
void BLECentralService::_init(void)
|
||||
{
|
||||
}
|
||||
@@ -63,5 +66,9 @@ err_t BLECentralService::begin(void)
|
||||
|
||||
bool BLECentralService::discover(uint16_t start_handle)
|
||||
{
|
||||
return Bluefruit.Central.discoverService(uuid, start_handle);
|
||||
VERIFY( Bluefruit.Central.discoverService(uuid, start_handle) );
|
||||
|
||||
lastService = this;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -45,6 +45,8 @@ class BLECentralService
|
||||
void _init(void);
|
||||
|
||||
public:
|
||||
static BLECentralService* lastService;
|
||||
|
||||
BLEUuid uuid;
|
||||
|
||||
BLECentralService(void);
|
||||
|
||||
@@ -82,6 +82,11 @@ void BLECharacteristic::setUuid(BLEUuid bleuuid)
|
||||
uuid = bleuuid;
|
||||
}
|
||||
|
||||
BLEService& BLECharacteristic::parentService (void)
|
||||
{
|
||||
return *_service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be set when Charactertistic is declared locally (e.g insdie function)
|
||||
* and is not last throughout programs. Useful for one-shot set-and-forget
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "bluefruit_common.h"
|
||||
#include "BLEUuid.h"
|
||||
|
||||
// Forward declaration
|
||||
class AdafruitBluefruit;
|
||||
class BLEService;
|
||||
|
||||
@@ -115,7 +116,7 @@ class BLECharacteristic
|
||||
BLECharacteristic(void);
|
||||
BLECharacteristic(BLEUuid bleuuid);
|
||||
|
||||
BLEService& parentService() { return *_service; }
|
||||
BLEService& parentService(void);
|
||||
|
||||
void setTempMemory(void);
|
||||
|
||||
|
||||
Reference in new issue
Block a user