update scanner

This commit is contained in:
hathach committed 2017-07-12 21:55:51 +07:00
1 parent a3aef999cc
commit 6061482e80
5 files changed
+33 -18

No files matched your search

@@ -55,8 +55,6 @@ class AdafruitBluefruit;
class BLECentral
{
public:
typedef void (*scan_callback_t ) (ble_gap_evt_adv_report_t*);
BLECentral(void); // Constructor
void begin(void);
+5 -2
View File
@@ -35,12 +35,15 @@
/**************************************************************************/
#include "bluefruit.h"
#include "utility/AdaCallback.h"
BLEScanner::BLEScanner(void)
{
_runnning = false;
_start_if_disconnect = true;
_rx_cb = NULL;
_rx_cb = NULL;
_stop_cb = NULL;
_scan_param = (ble_gap_scan_params_t) {
.active = 1,
@@ -137,7 +140,7 @@ void BLEScanner::_eventHandler(ble_evt_t* evt)
case BLE_GAP_EVT_TIMEOUT:
if (evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
{
if (_stop_cb) ada_callback(NULL, _stop_cb);
}
break;
+9 -3
View File
@@ -42,11 +42,11 @@
class BLEScanner
{
public:
typedef void (*rx_callback_t) (ble_gap_evt_adv_report_t*);
typedef void (*rx_callback_t ) (ble_gap_evt_adv_report_t*);
typedef void (*stop_callback_t) (void);
BLEScanner(void);
void setRxCallback(rx_callback_t fp);
ble_gap_scan_params_t* getParams(void);
@@ -56,6 +56,10 @@ public:
bool start(uint16_t timeout = 0);
bool stop(void);
/*------------- Callbacks -------------*/
void setRxCallback(rx_callback_t fp);
void setStopCallback(stop_callback_t fp);
/*------------------------------------------------------------------*/
/* INTERNAL USAGE ONLY
* Although declare as public, it is meant to be invoked by internal
@@ -66,7 +70,9 @@ public:
private:
bool _runnning;
bool _start_if_disconnect;
rx_callback_t _rx_cb;
rx_callback_t _rx_cb;
stop_callback_t _stop_cb;
ble_gap_scan_params_t _scan_param;
};
@@ -67,9 +67,14 @@ void adafruit_callback_task(void* arg)
break;
case BLEAdvertising_stop_callback_t:
// case BLEScanner_stop_callback_t:
((BLEAdvertising::stop_callback_t) func)();
break;
// case BLEScanner_rx_callback_t:
// ((BLEScanner::BLEScanner_rx_callback_t) func)();
// break;
/*------------- Bluefruit -------------*/
/*------------- Central -------------*/
@@ -58,19 +58,22 @@ static_assert(sizeof(ada_callback_t) == 16, "Incorrect Size");
/*------------------------------------------------------------------*/
/* X Macros expansion
/* X Macros expansion for callback function
* If callbacks from separated classes share the same prototype, only
* one instance is enough (mandatory)
*------------------------------------------------------------------*/
#define ADA_CB_LOOKUP(XPAND) \
/* BLEGap */ \
XPAND(BLEGap , connect_callback_t ) \
XPAND(BLEGap , disconnect_callback_t ) \
XPAND(BLEAdvertising , stop_callback_t ) \
/* Bluefruit */ \
/* Central */ \
XPAND(BLECentral , scan_callback_t ) \
/* Client Characteristic */ \
XPAND(BLEClientCharacteristic , notify_cb_t ) \
/*XPAND(BLEClientCharacteristic , indicate_cb_t )*/ \
/* BLEGap */ \
XPAND(BLEGap , connect_callback_t ) \
XPAND(BLEGap , disconnect_callback_t ) \
XPAND(BLEAdvertising , stop_callback_t ) \
/*BLEScanner::stop_callback_t is same as BLEAdvertising::stop_callback_t */\
XPAND(BLEScanner , rx_callback_t ) \
/* Bluefruit */ \
/* Central */ \
/* Client Characteristic */ \
XPAND(BLEClientCharacteristic , notify_cb_t ) \
/*XPAND(BLEClientCharacteristic , indicate_cb_t)*/ \
#define ADA_CB_ENUM_XPAND(_class, _cbname) \
_class##_##_cbname,