This is a fork of mbed-os-example-ble-HeartRate maintained for Sequana compatibility. This application transmits a heart rate value using the Bluetooth SIG Heart Rate Profile. The heart rate value is provided by the application itself, not by a sensor, so that you don't have to get a sensor just to run the example. The canonical source for this example lives at https://github.com/ARMmbed/mbed-os-example-ble/tree/master/BLE_HeartRate

Committer:
lru
Date:
Tue Feb 12 14:03:29 2019 +0000
Revision:
0:b283842072f8
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lru 0:b283842072f8 1 /* mbed Microcontroller Library
lru 0:b283842072f8 2 * Copyright (c) 2018 ARM Limited
lru 0:b283842072f8 3 *
lru 0:b283842072f8 4 * Licensed under the Apache License, Version 2.0 (the "License");
lru 0:b283842072f8 5 * you may not use this file except in compliance with the License.
lru 0:b283842072f8 6 * You may obtain a copy of the License at
lru 0:b283842072f8 7 *
lru 0:b283842072f8 8 * http://www.apache.org/licenses/LICENSE-2.0
lru 0:b283842072f8 9 *
lru 0:b283842072f8 10 * Unless required by applicable law or agreed to in writing, software
lru 0:b283842072f8 11 * distributed under the License is distributed on an "AS IS" BASIS,
lru 0:b283842072f8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
lru 0:b283842072f8 13 * See the License for the specific language governing permissions and
lru 0:b283842072f8 14 * limitations under the License.
lru 0:b283842072f8 15 */
lru 0:b283842072f8 16
lru 0:b283842072f8 17 #include <mbed.h>
lru 0:b283842072f8 18 #include "ble/BLE.h"
lru 0:b283842072f8 19
lru 0:b283842072f8 20 inline void print_error(ble_error_t error, const char* msg)
lru 0:b283842072f8 21 {
lru 0:b283842072f8 22 printf("%s: ", msg);
lru 0:b283842072f8 23 switch(error) {
lru 0:b283842072f8 24 case BLE_ERROR_NONE:
lru 0:b283842072f8 25 printf("BLE_ERROR_NONE: No error");
lru 0:b283842072f8 26 break;
lru 0:b283842072f8 27 case BLE_ERROR_BUFFER_OVERFLOW:
lru 0:b283842072f8 28 printf("BLE_ERROR_BUFFER_OVERFLOW: The requested action would cause a buffer overflow and has been aborted");
lru 0:b283842072f8 29 break;
lru 0:b283842072f8 30 case BLE_ERROR_NOT_IMPLEMENTED:
lru 0:b283842072f8 31 printf("BLE_ERROR_NOT_IMPLEMENTED: Requested a feature that isn't yet implement or isn't supported by the target HW");
lru 0:b283842072f8 32 break;
lru 0:b283842072f8 33 case BLE_ERROR_PARAM_OUT_OF_RANGE:
lru 0:b283842072f8 34 printf("BLE_ERROR_PARAM_OUT_OF_RANGE: One of the supplied parameters is outside the valid range");
lru 0:b283842072f8 35 break;
lru 0:b283842072f8 36 case BLE_ERROR_INVALID_PARAM:
lru 0:b283842072f8 37 printf("BLE_ERROR_INVALID_PARAM: One of the supplied parameters is invalid");
lru 0:b283842072f8 38 break;
lru 0:b283842072f8 39 case BLE_STACK_BUSY:
lru 0:b283842072f8 40 printf("BLE_STACK_BUSY: The stack is busy");
lru 0:b283842072f8 41 break;
lru 0:b283842072f8 42 case BLE_ERROR_INVALID_STATE:
lru 0:b283842072f8 43 printf("BLE_ERROR_INVALID_STATE: Invalid state");
lru 0:b283842072f8 44 break;
lru 0:b283842072f8 45 case BLE_ERROR_NO_MEM:
lru 0:b283842072f8 46 printf("BLE_ERROR_NO_MEM: Out of Memory");
lru 0:b283842072f8 47 break;
lru 0:b283842072f8 48 case BLE_ERROR_OPERATION_NOT_PERMITTED:
lru 0:b283842072f8 49 printf("BLE_ERROR_OPERATION_NOT_PERMITTED");
lru 0:b283842072f8 50 break;
lru 0:b283842072f8 51 case BLE_ERROR_INITIALIZATION_INCOMPLETE:
lru 0:b283842072f8 52 printf("BLE_ERROR_INITIALIZATION_INCOMPLETE");
lru 0:b283842072f8 53 break;
lru 0:b283842072f8 54 case BLE_ERROR_ALREADY_INITIALIZED:
lru 0:b283842072f8 55 printf("BLE_ERROR_ALREADY_INITIALIZED");
lru 0:b283842072f8 56 break;
lru 0:b283842072f8 57 case BLE_ERROR_UNSPECIFIED:
lru 0:b283842072f8 58 printf("BLE_ERROR_UNSPECIFIED: Unknown error");
lru 0:b283842072f8 59 break;
lru 0:b283842072f8 60 case BLE_ERROR_INTERNAL_STACK_FAILURE:
lru 0:b283842072f8 61 printf("BLE_ERROR_INTERNAL_STACK_FAILURE: internal stack faillure");
lru 0:b283842072f8 62 break;
lru 0:b283842072f8 63 }
lru 0:b283842072f8 64 printf("\r\n");
lru 0:b283842072f8 65 }
lru 0:b283842072f8 66
lru 0:b283842072f8 67 /** print device address to the terminal */
lru 0:b283842072f8 68 inline void print_address(const Gap::Address_t &addr)
lru 0:b283842072f8 69 {
lru 0:b283842072f8 70 printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
lru 0:b283842072f8 71 addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
lru 0:b283842072f8 72 }
lru 0:b283842072f8 73
lru 0:b283842072f8 74 inline void print_mac_address()
lru 0:b283842072f8 75 {
lru 0:b283842072f8 76 /* Print out device MAC address to the console*/
lru 0:b283842072f8 77 Gap::AddressType_t addr_type;
lru 0:b283842072f8 78 Gap::Address_t address;
lru 0:b283842072f8 79 BLE::Instance().gap().getAddress(&addr_type, address);
lru 0:b283842072f8 80 printf("DEVICE MAC ADDRESS: ");
lru 0:b283842072f8 81 print_address(address);
lru 0:b283842072f8 82 }
lru 0:b283842072f8 83
lru 0:b283842072f8 84 inline const char* phy_to_string(Gap::Phy_t phy) {
lru 0:b283842072f8 85 switch(phy.value()) {
lru 0:b283842072f8 86 case Gap::Phy_t::LE_1M:
lru 0:b283842072f8 87 return "LE 1M";
lru 0:b283842072f8 88 case Gap::Phy_t::LE_2M:
lru 0:b283842072f8 89 return "LE 2M";
lru 0:b283842072f8 90 case Gap::Phy_t::LE_CODED:
lru 0:b283842072f8 91 return "LE coded";
lru 0:b283842072f8 92 default:
lru 0:b283842072f8 93 return "invalid PHY";
lru 0:b283842072f8 94 }
lru 0:b283842072f8 95 }