xiao sun / BLE_API

Fork of BLE_API by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

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__