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.
Fork of BLE_API by
Revision 63:653378e782ea, committed 2014-06-04
- Comitter:
- Rohit Grover
- Date:
- Wed Jun 04 09:36:31 2014 +0100
- Parent:
- 62:3dc0dc3a0451
- Child:
- 64:95529f47b782
- Commit message:
- add Gap Callbacks
Changed in this revision
| hw/BLEDevice.h | Show annotated file Show diff for this revision Revisions of this file |
| hw/Gap.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/hw/BLEDevice.h Mon Jun 02 14:58:56 2014 +0100
+++ b/hw/BLEDevice.h Wed Jun 04 09:36:31 2014 +0100
@@ -129,6 +129,10 @@
ble_error_t disconnect(void);
+ void onTimeout(Gap::EventCallback_t timeoutCallback);
+ void onConnection(Gap::EventCallback_t connectionCallback);
+ void onDisconnection(Gap::EventCallback_t disconnectionCallback);
+
private:
/**
* Internal helper to udpate the transport backend with advertising data
@@ -300,4 +304,20 @@
return transport->getGap().startAdvertising(_advParams);
}
+inline void
+BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback) {
+ transport->getGap().setOnTimeout(timeoutCallback);
+}
+
+inline void
+BLEDevice::onConnection(Gap::EventCallback_t connectionCallback) {
+ transport->getGap().setOnConnection(connectionCallback);
+}
+
+inline void
+BLEDevice::onDisconnection(Gap::EventCallback_t disconnectionCallback) {
+ transport->getGap().setOnDisconnection(disconnectionCallback);
+}
+
+
#endif // ifndef __BLE_DEVICE_H__
--- a/hw/Gap.h Mon Jun 02 14:58:56 2014 +0100
+++ b/hw/Gap.h Wed Jun 04 09:36:31 2014 +0100
@@ -32,9 +32,6 @@
/**************************************************************************/
class Gap
{
-private:
- GapEvents *m_pEventHandler;
-
public:
typedef enum addr_type_e {
ADDR_TYPE_PUBLIC = 0,
@@ -53,41 +50,62 @@
/* Describes the current state of the device (more than one bit can be
*set) */
- typedef struct GapState_s
- {
- unsigned advertising : 1; /**< The device is current
- *advertising */
- unsigned connected : 1; /**< The peripheral is
- *connected to a central
- *device */
+ typedef struct GapState_s {
+ unsigned advertising : 1; /**< peripheral is currently advertising */
+ unsigned connected : 1; /**< peripheral is connected to a central */
} GapState_t;
/* Event callback handlers */
- void setEventHandler(GapEvents *pEventHandler) {
- m_pEventHandler = pEventHandler;
+ typedef void (*EventCallback_t)(void);
+ void setOnTimeout(EventCallback_t callback) {
+ onTimeout = callback;
+ }
+ void setOnConnection(EventCallback_t callback) {
+ onConnection = callback;
+ }
+ void setOnDisconnection(EventCallback_t callback) {
+ onDisconnection = callback;
}
void handleEvent(GapEvents::gapEvent_e type) {
- if (NULL == m_pEventHandler) {
- return;
- }
switch (type) {
case GapEvents::GAP_EVENT_TIMEOUT:
state.advertising = 0;
- m_pEventHandler->onTimeout();
+ if (onTimeout) {
+ onTimeout();
+ }
break;
case GapEvents::GAP_EVENT_CONNECTED:
state.connected = 1;
- m_pEventHandler->onConnected();
+ if (onConnection) {
+ onConnection();
+ }
break;
case GapEvents::GAP_EVENT_DISCONNECTED:
state.connected = 0;
- m_pEventHandler->onDisconnected();
+ if (onDisconnection) {
+ onDisconnection();
+ }
break;
}
}
+protected:
+ Gap() :
+ state(),
+ onTimeout(NULL),
+ onConnection(NULL),
+ onDisconnection(NULL) {
+ /* empty */
+ }
+
+protected:
GapState_t state;
+
+private:
+ EventCallback_t onTimeout;
+ EventCallback_t onConnection;
+ EventCallback_t onDisconnection;
};
#endif // ifndef __GAP_H__
