MouseScroll example from BLE_HID

Dependencies:   BLE_API BLE_HID mbed nRF51822

This example is currently copied as-is from the github development repo.

Committer:
Jean-Philippe Brucker
Date:
Sun Apr 03 22:06:47 2016 +0100
Revision:
4:8fb54802ba2b
Parent:
3:acfb913bff6b
v0.4 - small change to enable Win10 support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jean-Philippe Brucker 1:0a97297327eb 1 /* mbed Microcontroller Library
Jean-Philippe Brucker 1:0a97297327eb 2 * Copyright (c) 2015 ARM Limited
Jean-Philippe Brucker 1:0a97297327eb 3 *
Jean-Philippe Brucker 1:0a97297327eb 4 * Licensed under the Apache License, Version 2.0 (the "License");
Jean-Philippe Brucker 1:0a97297327eb 5 * you may not use this file except in compliance with the License.
Jean-Philippe Brucker 1:0a97297327eb 6 * You may obtain a copy of the License at
Jean-Philippe Brucker 1:0a97297327eb 7 *
Jean-Philippe Brucker 1:0a97297327eb 8 * http://www.apache.org/licenses/LICENSE-2.0
Jean-Philippe Brucker 1:0a97297327eb 9 *
Jean-Philippe Brucker 1:0a97297327eb 10 * Unless required by applicable law or agreed to in writing, software
Jean-Philippe Brucker 1:0a97297327eb 11 * distributed under the License is distributed on an "AS IS" BASIS,
Jean-Philippe Brucker 1:0a97297327eb 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Jean-Philippe Brucker 1:0a97297327eb 13 * See the License for the specific language governing permissions and
Jean-Philippe Brucker 1:0a97297327eb 14 * limitations under the License.
Jean-Philippe Brucker 1:0a97297327eb 15 */
Jean-Philippe Brucker 1:0a97297327eb 16
Jean-Philippe Brucker 1:0a97297327eb 17 #include "ble/services/BatteryService.h"
Jean-Philippe Brucker 3:acfb913bff6b 18 #include "ble/services/DeviceInformationService.h"
Jean-Philippe Brucker 1:0a97297327eb 19
Jean-Philippe Brucker 1:0a97297327eb 20 #include "examples_common.h"
Jean-Philippe Brucker 1:0a97297327eb 21
Jean-Philippe Brucker 1:0a97297327eb 22 static void passkeyDisplayCallback(Gap::Handle_t handle, const SecurityManager::Passkey_t passkey)
Jean-Philippe Brucker 1:0a97297327eb 23 {
Jean-Philippe Brucker 1:0a97297327eb 24 printf("Input passKey: ");
Jean-Philippe Brucker 1:0a97297327eb 25 for (unsigned i = 0; i < Gap::ADDR_LEN; i++) {
Jean-Philippe Brucker 1:0a97297327eb 26 printf("%c", passkey[i]);
Jean-Philippe Brucker 1:0a97297327eb 27 }
Jean-Philippe Brucker 1:0a97297327eb 28 printf("\r\n");
Jean-Philippe Brucker 1:0a97297327eb 29 }
Jean-Philippe Brucker 1:0a97297327eb 30
Jean-Philippe Brucker 1:0a97297327eb 31 static void securitySetupCompletedCallback(Gap::Handle_t handle, SecurityManager::SecurityCompletionStatus_t status)
Jean-Philippe Brucker 1:0a97297327eb 32 {
Jean-Philippe Brucker 1:0a97297327eb 33 if (status == SecurityManager::SEC_STATUS_SUCCESS) {
Jean-Philippe Brucker 1:0a97297327eb 34 printf("Security success %d\r\n", status);
Jean-Philippe Brucker 1:0a97297327eb 35 } else {
Jean-Philippe Brucker 1:0a97297327eb 36 printf("Security failed %d\r\n", status);
Jean-Philippe Brucker 1:0a97297327eb 37 }
Jean-Philippe Brucker 1:0a97297327eb 38 }
Jean-Philippe Brucker 1:0a97297327eb 39
Jean-Philippe Brucker 1:0a97297327eb 40 static void securitySetupInitiatedCallback(Gap::Handle_t, bool allowBonding, bool requireMITM, SecurityManager::SecurityIOCapabilities_t iocaps)
Jean-Philippe Brucker 1:0a97297327eb 41 {
Jean-Philippe Brucker 1:0a97297327eb 42 printf("Security setup initiated\r\n");
Jean-Philippe Brucker 1:0a97297327eb 43 }
Jean-Philippe Brucker 1:0a97297327eb 44
Jean-Philippe Brucker 1:0a97297327eb 45 void initializeSecurity(BLE &ble)
Jean-Philippe Brucker 1:0a97297327eb 46 {
Jean-Philippe Brucker 1:0a97297327eb 47 bool enableBonding = true;
Jean-Philippe Brucker 1:0a97297327eb 48 bool requireMITM = HID_SECURITY_REQUIRE_MITM;
Jean-Philippe Brucker 1:0a97297327eb 49
Jean-Philippe Brucker 1:0a97297327eb 50 ble.securityManager().onSecuritySetupInitiated(securitySetupInitiatedCallback);
Jean-Philippe Brucker 1:0a97297327eb 51 ble.securityManager().onPasskeyDisplay(passkeyDisplayCallback);
Jean-Philippe Brucker 1:0a97297327eb 52 ble.securityManager().onSecuritySetupCompleted(securitySetupCompletedCallback);
Jean-Philippe Brucker 1:0a97297327eb 53
Jean-Philippe Brucker 1:0a97297327eb 54 ble.securityManager().init(enableBonding, requireMITM, HID_SECURITY_IOCAPS);
Jean-Philippe Brucker 1:0a97297327eb 55 }
Jean-Philippe Brucker 1:0a97297327eb 56
Jean-Philippe Brucker 1:0a97297327eb 57 void initializeHOGP(BLE &ble)
Jean-Philippe Brucker 1:0a97297327eb 58 {
Jean-Philippe Brucker 1:0a97297327eb 59 static const uint16_t uuid16_list[] = {GattService::UUID_HUMAN_INTERFACE_DEVICE_SERVICE,
Jean-Philippe Brucker 1:0a97297327eb 60 GattService::UUID_DEVICE_INFORMATION_SERVICE,
Jean-Philippe Brucker 1:0a97297327eb 61 GattService::UUID_BATTERY_SERVICE};
Jean-Philippe Brucker 1:0a97297327eb 62
Jean-Philippe Brucker 3:acfb913bff6b 63 DeviceInformationService deviceInfo(ble, "ARM", "m1", "abc", "def", "ghi", "jkl");
Jean-Philippe Brucker 1:0a97297327eb 64
Jean-Philippe Brucker 1:0a97297327eb 65 BatteryService batteryInfo(ble, 80);
Jean-Philippe Brucker 1:0a97297327eb 66
Jean-Philippe Brucker 1:0a97297327eb 67 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED |
Jean-Philippe Brucker 1:0a97297327eb 68 GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
Jean-Philippe Brucker 1:0a97297327eb 69 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS,
Jean-Philippe Brucker 1:0a97297327eb 70 (uint8_t *)uuid16_list, sizeof(uuid16_list));
Jean-Philippe Brucker 1:0a97297327eb 71
Jean-Philippe Brucker 1:0a97297327eb 72 // see 5.1.2: HID over GATT Specification (pg. 25)
Jean-Philippe Brucker 1:0a97297327eb 73 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
Jean-Philippe Brucker 1:0a97297327eb 74 // 30ms to 50ms is recommended (5.1.2)
Jean-Philippe Brucker 1:0a97297327eb 75 ble.gap().setAdvertisingInterval(50);
Jean-Philippe Brucker 1:0a97297327eb 76 }