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 104:6ef5abef5714, committed 2014-07-10
- Comitter:
- Rohit Grover
- Date:
- Thu Jul 10 12:12:06 2014 +0100
- Parent:
- 103:8890715aaf55
- Child:
- 105:f29ab9f74d7e
- Commit message:
- connection and disconnection callbacks need to take a connection handle
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 Wed Jul 09 09:08:53 2014 +0100
+++ b/hw/BLEDevice.h Thu Jul 10 12:12:06 2014 +0100
@@ -208,12 +208,13 @@
ble_error_t disconnect(void);
/* APIs to set GAP callbacks. */
- void onTimeout(Gap::EventCallback_t timeoutCallback);
- void onConnection(Gap::EventCallback_t connectionCallback);
+ void onTimeout(Gap::EventCallback_t timeoutCallback);
+
+ void onConnection(Gap::HandleSpecificEventCallback_t connectionCallback);
/**
* Used to setup a callback for GAP disconnection.
*/
- void onDisconnection(Gap::EventCallback_t disconnectionCallback);
+ void onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback);
/**
* Setup a callback for the GATT event DATA_SENT.
@@ -417,13 +418,13 @@
}
inline void
-BLEDevice::onConnection(Gap::EventCallback_t connectionCallback)
+BLEDevice::onConnection(Gap::HandleSpecificEventCallback_t connectionCallback)
{
transport->getGap().setOnConnection(connectionCallback);
}
inline void
-BLEDevice::onDisconnection(Gap::EventCallback_t disconnectionCallback)
+BLEDevice::onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback)
{
transport->getGap().setOnDisconnection(disconnectionCallback);
}
--- a/hw/Gap.h Wed Jul 09 09:08:53 2014 +0100
+++ b/hw/Gap.h Thu Jul 10 12:12:06 2014 +0100
@@ -54,19 +54,39 @@
unsigned connected : 1; /**< peripheral is connected to a central */
} GapState_t;
+ typedef void (*EventCallback_t)(void);
+ typedef uint16_t Handle_t;
+ typedef void (*HandleSpecificEventCallback_t)(Handle_t);
+
/* Event callback handlers */
- typedef void (*EventCallback_t)(void);
void setOnTimeout(EventCallback_t callback) {
onTimeout = callback;
}
- void setOnConnection(EventCallback_t callback) {
+ void setOnConnection(HandleSpecificEventCallback_t callback) {
onConnection = callback;
}
- void setOnDisconnection(EventCallback_t callback) {
+ void setOnDisconnection(HandleSpecificEventCallback_t callback) {
onDisconnection = callback;
}
- void handleEvent(GapEvents::gapEvent_e type) {
+ void processHandleSpecificEvent(GapEvents::gapEvent_e type, Handle_t handle) {
+ switch (type) {
+ case GapEvents::GAP_EVENT_CONNECTED:
+ state.connected = 1;
+ if (onConnection) {
+ onConnection(handle);
+ }
+ break;
+ case GapEvents::GAP_EVENT_DISCONNECTED:
+ state.connected = 0;
+ if (onDisconnection) {
+ onDisconnection(handle);
+ }
+ break;
+ }
+ }
+
+ void processEvent(GapEvents::gapEvent_e type) {
switch (type) {
case GapEvents::GAP_EVENT_TIMEOUT:
state.advertising = 0;
@@ -74,18 +94,6 @@
onTimeout();
}
break;
- case GapEvents::GAP_EVENT_CONNECTED:
- state.connected = 1;
- if (onConnection) {
- onConnection();
- }
- break;
- case GapEvents::GAP_EVENT_DISCONNECTED:
- state.connected = 0;
- if (onDisconnection) {
- onDisconnection();
- }
- break;
}
}
@@ -102,9 +110,9 @@
GapState_t state;
private:
- EventCallback_t onTimeout;
- EventCallback_t onConnection;
- EventCallback_t onDisconnection;
+ EventCallback_t onTimeout;
+ HandleSpecificEventCallback_t onConnection;
+ HandleSpecificEventCallback_t onDisconnection;
};
#endif // ifndef __GAP_H__
