HID-over-GATT implementation with the BLE API. This library allows to create devices such as mouse, keyboard or joystick, over Bluetooth Low Energy.

Dependents:   MtConnect04S_Gesture_HID

Fork of BLE_HID by Jean-Philippe Brucker

Revision:
1:7a6c2e2c9371
Parent:
0:cfd70fa91663
Child:
5:dc4e6dbcb79b
--- a/HIDServiceBase.cpp	Tue Sep 15 20:16:58 2015 +0100
+++ b/HIDServiceBase.cpp	Wed Oct 07 11:29:52 2015 +0100
@@ -1,3 +1,19 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #include "mbed.h"
 #include "HIDServiceBase.h"
 
@@ -106,9 +122,12 @@
     GattService service(GattService::UUID_HUMAN_INTERFACE_DEVICE_SERVICE,
                         characteristics, charIndex);
 
-    ble.addService(service);
+    ble.gattServer().addService(service);
 
-    ble.onDataSent(this, &HIDServiceBase::onDataSent);
+    ble.gap().onConnection(this, &HIDServiceBase::onConnection);
+    ble.gap().onDisconnection(this, &HIDServiceBase::onDisconnection);
+
+    ble.gattServer().onDataSent(this, &HIDServiceBase::onDataSent);
 
     /*
      * Change preferred connection params, in order to optimize the notification frequency. Most
@@ -197,3 +216,12 @@
     return BLE_ERROR_NOT_IMPLEMENTED;
 }
 
+void HIDServiceBase::onConnection(const Gap::ConnectionCallbackParams_t *params)
+{
+    this->connected = true;
+}
+
+void HIDServiceBase::onDisconnection(const Gap::DisconnectionCallbackParams_t *params)
+{
+    this->connected = false;
+}