enable <object,callbackMember> context for startScan.
This commit is contained in:
parent
aebfbce3f5
commit
bee91cabe5
2 changed files with 43 additions and 1 deletions
|
@ -271,6 +271,18 @@ public:
|
|||
*/
|
||||
ble_error_t startScan(void (*callback)(const Gap::AdvertisementCallbackParams_t *params));
|
||||
|
||||
/**
|
||||
* Start scanning (Observer Procedure) based on the scan-params currently
|
||||
* in effect.
|
||||
*
|
||||
* @param[in] object
|
||||
* @param[in] callbackMember
|
||||
* The above pair of parameters define the callback object
|
||||
* and member function to receive the advertisement params.
|
||||
*/
|
||||
template<typename T>
|
||||
ble_error_t startScan(T *object, void (T::*memberCallback)(const Gap::AdvertisementCallbackParams_t *params));
|
||||
|
||||
/**
|
||||
* Stop scanning. The current scanning parameters remain in effect.
|
||||
*
|
||||
|
@ -787,6 +799,12 @@ BLEDevice::startScan(void (*callback)(const Gap::AdvertisementCallbackParams_t *
|
|||
return transport->getGap().startScan(scanningParams, callback);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ble_error_t
|
||||
BLEDevice::startScan(T *object, void (T::*memberCallback)(const Gap::AdvertisementCallbackParams_t *params)) {
|
||||
return transport->getGap().startScan(scanningParams, object, memberCallback);
|
||||
}
|
||||
|
||||
inline ble_error_t
|
||||
BLEDevice::stopScan(void) {
|
||||
return transport->getGap().stopScan();
|
||||
|
|
26
public/Gap.h
26
public/Gap.h
|
@ -172,7 +172,6 @@ private:
|
|||
virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0;
|
||||
virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0;
|
||||
virtual ble_error_t stopAdvertising(void) = 0;
|
||||
virtual ble_error_t startScan(const GapScanningParams &scanningParams, void (*callback)(const AdvertisementCallbackParams_t *params)) = 0;
|
||||
virtual ble_error_t stopScan() = 0;
|
||||
virtual uint16_t getMinAdvertisingInterval(void) const = 0;
|
||||
virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const = 0;
|
||||
|
@ -190,7 +189,32 @@ private:
|
|||
virtual ble_error_t setAppearance(uint16_t appearance) = 0;
|
||||
virtual ble_error_t getAppearance(uint16_t *appearanceP) = 0;
|
||||
|
||||
ble_error_t startScan(const GapScanningParams &scanningParams, void (*callback)(const AdvertisementCallbackParams_t *params)) {
|
||||
ble_error_t err = BLE_ERROR_NONE;
|
||||
if (callback) {
|
||||
if ((err = startRadioScan(scanningParams)) == BLE_ERROR_NONE) {
|
||||
onAdvertisementReport.attach(callback);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ble_error_t startScan(const GapScanningParams &scanningParams, T *object, void (T::*callbackMember)(const AdvertisementCallbackParams_t *params)) {
|
||||
ble_error_t err = BLE_ERROR_NONE;
|
||||
if (object && callbackMember) {
|
||||
if ((err = startRadioScan(scanningParams)) == BLE_ERROR_NONE) {
|
||||
onAdvertisementReport.attach(object, callbackMember);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) = 0;
|
||||
|
||||
/* Event callback handlers */
|
||||
void setOnTimeout(EventCallback_t callback) {onTimeout = callback;}
|
||||
void setOnConnection(ConnectionEventCallback_t callback) {onConnection = callback;}
|
||||
|
|
Loading…
Reference in a new issue