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
pretty_printer.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include <mbed.h> 00018 #include "ble/BLE.h" 00019 00020 inline void print_error(ble_error_t error, const char* msg) 00021 { 00022 printf("%s: ", msg); 00023 switch(error) { 00024 case BLE_ERROR_NONE: 00025 printf("BLE_ERROR_NONE: No error"); 00026 break; 00027 case BLE_ERROR_BUFFER_OVERFLOW: 00028 printf("BLE_ERROR_BUFFER_OVERFLOW: The requested action would cause a buffer overflow and has been aborted"); 00029 break; 00030 case BLE_ERROR_NOT_IMPLEMENTED: 00031 printf("BLE_ERROR_NOT_IMPLEMENTED: Requested a feature that isn't yet implement or isn't supported by the target HW"); 00032 break; 00033 case BLE_ERROR_PARAM_OUT_OF_RANGE: 00034 printf("BLE_ERROR_PARAM_OUT_OF_RANGE: One of the supplied parameters is outside the valid range"); 00035 break; 00036 case BLE_ERROR_INVALID_PARAM: 00037 printf("BLE_ERROR_INVALID_PARAM: One of the supplied parameters is invalid"); 00038 break; 00039 case BLE_STACK_BUSY: 00040 printf("BLE_STACK_BUSY: The stack is busy"); 00041 break; 00042 case BLE_ERROR_INVALID_STATE: 00043 printf("BLE_ERROR_INVALID_STATE: Invalid state"); 00044 break; 00045 case BLE_ERROR_NO_MEM: 00046 printf("BLE_ERROR_NO_MEM: Out of Memory"); 00047 break; 00048 case BLE_ERROR_OPERATION_NOT_PERMITTED: 00049 printf("BLE_ERROR_OPERATION_NOT_PERMITTED"); 00050 break; 00051 case BLE_ERROR_INITIALIZATION_INCOMPLETE: 00052 printf("BLE_ERROR_INITIALIZATION_INCOMPLETE"); 00053 break; 00054 case BLE_ERROR_ALREADY_INITIALIZED: 00055 printf("BLE_ERROR_ALREADY_INITIALIZED"); 00056 break; 00057 case BLE_ERROR_UNSPECIFIED: 00058 printf("BLE_ERROR_UNSPECIFIED: Unknown error"); 00059 break; 00060 case BLE_ERROR_INTERNAL_STACK_FAILURE: 00061 printf("BLE_ERROR_INTERNAL_STACK_FAILURE: internal stack faillure"); 00062 break; 00063 } 00064 printf("\r\n"); 00065 } 00066 00067 /** print device address to the terminal */ 00068 inline void print_address(const Gap::Address_t &addr) 00069 { 00070 printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n", 00071 addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]); 00072 } 00073 00074 inline void print_mac_address() 00075 { 00076 /* Print out device MAC address to the console*/ 00077 Gap::AddressType_t addr_type; 00078 Gap::Address_t address; 00079 BLE::Instance().gap().getAddress(&addr_type, address); 00080 printf("DEVICE MAC ADDRESS: "); 00081 print_address(address); 00082 } 00083 00084 inline const char* phy_to_string(Gap::Phy_t phy) { 00085 switch(phy.value()) { 00086 case Gap::Phy_t::LE_1M: 00087 return "LE 1M"; 00088 case Gap::Phy_t::LE_2M: 00089 return "LE 2M"; 00090 case Gap::Phy_t::LE_CODED: 00091 return "LE coded"; 00092 default: 00093 return "invalid PHY"; 00094 } 00095 }
Generated on Thu Jul 14 2022 02:33:58 by 1.7.2