Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: microbit-dal microbit-dal microbit-ble-open microbit-dal ... more
Fork of BLE_API by
Diff: public/GapScanningParams.h
- Revision:
- 710:b2e1a2660ec2
- Parent:
- 674:923c47bd1547
diff -r 77f6fc6999cd -r b2e1a2660ec2 public/GapScanningParams.h
--- a/public/GapScanningParams.h Fri Jun 19 15:53:06 2015 +0100
+++ b/public/GapScanningParams.h Fri Jun 19 15:53:28 2015 +0100
@@ -17,6 +17,8 @@
#ifndef __GAP_SCANNING_PARAMS_H__
#define __GAP_SCANNING_PARAMS_H__
+#include "Gap.h"
+
class GapScanningParams {
public:
static const unsigned SCAN_INTERVAL_MIN = 0x0004; /**< Minimum Scan interval in 625 us units, i.e. 2.5 ms. */
@@ -27,20 +29,58 @@
static const unsigned SCAN_TIMEOUT_MAX = 0xFFFF; /**< Maximum Scan timeout in seconds. */
public:
- GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX,
- uint16_t window = SCAN_WINDOW_MAX,
- uint16_t timeout = 0,
- bool activeScanning = false);
-
- ble_error_t setInterval(uint16_t newIntervalInMS);
+ GapScanningParams(uint16_t interval = SCAN_INTERVAL_MAX,
+ uint16_t window = SCAN_WINDOW_MAX,
+ uint16_t timeout = 0,
+ bool activeScanning = false) : _interval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)),
+ _window(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(window)),
+ _timeout(timeout),
+ _activeScanning(activeScanning) {
+ /* stay within limits */
+ if (_interval < SCAN_INTERVAL_MIN) {
+ _interval = SCAN_INTERVAL_MIN;
+ }
+ if (_interval > SCAN_INTERVAL_MAX) {
+ _interval = SCAN_INTERVAL_MAX;
+ }
+ if (_window < SCAN_WINDOW_MIN) {
+ _window = SCAN_WINDOW_MIN;
+ }
+ if (_window > SCAN_WINDOW_MAX) {
+ _window = SCAN_WINDOW_MAX;
+ }
+ }
- ble_error_t setWindow(uint16_t newWindowInMS);
+ ble_error_t setInterval(uint16_t newIntervalInMS) {
+ uint16_t newInterval = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newIntervalInMS);
+ if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
+ _interval = newInterval;
+ return BLE_ERROR_NONE;
+ }
- ble_error_t setTimeout(uint16_t newTimeout);
+ return BLE_ERROR_PARAM_OUT_OF_RANGE;
+ }
- void setActiveScanning(bool activeScanning);
+ ble_error_t setWindow(uint16_t newWindowInMS) {
+ uint16_t newWindow = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newWindowInMS);
+ if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
+ _window = newWindow;
+ return BLE_ERROR_NONE;
+ }
+
+ return BLE_ERROR_PARAM_OUT_OF_RANGE;
+ }
-public:
+ ble_error_t setTimeout(uint16_t newTimeout) {
+ _timeout = newTimeout;
+ return BLE_ERROR_NONE;
+ }
+
+ void setActiveScanning(bool activeScanning) {
+ _activeScanning = activeScanning;
+ }
+
+
/* @Note: The following return durations in units of 0.625 ms */
uint16_t getInterval(void) const {return _interval;}
uint16_t getWindow(void) const {return _window; }
