add isAdvertising()

This commit is contained in:
hathach committed 2017-07-12 17:44:49 +07:00
1 parent 307795482c
commit 7b92f86714
2 files changed
+15

No files matched your search

@@ -175,6 +175,7 @@ BLEAdvertising::BLEAdvertising(void)
{
_type = BLE_GAP_ADV_TYPE_ADV_IND;
_start_if_disconnect = true;
_is_advertising = false;
_fast_interval = BLE_ADV_INTERVAL_FAST_DFLT;
_slow_interval = BLE_ADV_INTERVAL_SLOW_DFLT;
@@ -211,6 +212,11 @@ void BLEAdvertising::setStopCallback(stop_callback_t fp)
_stop_cb = fp;
}
bool BLEAdvertising::isAdvertising(void)
{
return _is_advertising;
}
bool BLEAdvertising::setBeacon(BLEBeacon& beacon)
{
return beacon.start(*this);
@@ -235,7 +241,9 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
};
VERIFY_STATUS( sd_ble_gap_adv_start(&adv_para), false );
Bluefruit._startConnLed(); // start blinking
_is_advertising = true;
_left_timeout -= min16(_left_timeout, timeout);
@@ -275,6 +283,8 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
if ( para->role == BLE_GAP_ROLE_PERIPH)
{
_is_advertising = false;
// Turn on Conn LED
Bluefruit._stopConnLed();
Bluefruit._setConnLed(true);
@@ -296,6 +306,8 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
case BLE_GAP_EVT_TIMEOUT:
if (evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING)
{
_is_advertising = false;
if ( _stop_timeout == 0 )
{
// if stop_timeout is 0 --> no timeout
@@ -106,6 +106,8 @@ public:
bool setBeacon(BLEBeacon& beacon);
bool isAdvertising(void);
bool start(uint16_t timeout = 0);
bool startIfDisconnect(bool enable);
bool stop (void);
@@ -120,6 +122,7 @@ public:
private:
uint8_t _type;
bool _start_if_disconnect;
bool _is_advertising;
uint16_t _fast_interval; // in 0.625 ms
uint16_t _slow_interval; // in 0.625 ms