add codes for data reading and PCA

Dependencies:   mpu9250_i2c Eigen

Committer:
shiyaozhanag
Date:
Wed Nov 20 01:37:11 2019 +0000
Revision:
2:145ba8262ed2
Parent:
0:dbcc46819a5e
import libraries

Who changed what in which revision?

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