
prova
Dependencies: BLE_API X_NUCLEO_IDB0XA1 X_NUCLEO_IKS01A2 mbed
Fork of BLE_HeartRate_IDB0XA1 by
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2015 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 #include "XNucleoIKS01A2.h" 00020 00021 /* Instantiate the expansion board */ 00022 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); 00023 00024 /* Retrieve the composing elements of the expansion board */ 00025 /* 00026 static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer; 00027 static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; 00028 static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; 00029 static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; 00030 static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer; 00031 */ 00032 uint8_t id=0; 00033 00034 /* Optional: Device Name, add for human read-ability */ 00035 const static char DEVICE_NAME[] = "myDevice"; 00036 00037 /* You have up to 26 bytes of advertising data to use. */ 00038 const static uint8_t AdvData[] = {0x01,0x02,0x03,0x04,0x05}; /* Example of hex data */ 00039 //const static uint8_t AdvData[] = {"ChangeThisData"}; /* Example of character data */ 00040 00041 /* Optional: Restart advertising when peer disconnects */ 00042 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) 00043 { 00044 BLE::Instance().gap().startAdvertising(); 00045 } 00046 /** 00047 * This function is called when the ble initialization process has failed 00048 */ 00049 void onBleInitError(BLE &ble, ble_error_t error) 00050 { 00051 /* Avoid compiler warnings */ 00052 (void) ble; 00053 (void) error; 00054 00055 /* Initialization error handling should go here */ 00056 } 00057 00058 /** 00059 * Callback triggered when the ble initialization process has finished 00060 */ 00061 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) 00062 { 00063 BLE& ble = params->ble; 00064 ble_error_t error = params->error; 00065 00066 if (error != BLE_ERROR_NONE) { 00067 /* In case of error, forward the error handling to onBleInitError */ 00068 onBleInitError(ble, error); 00069 return; 00070 } 00071 00072 /* Ensure that it is the default instance of BLE */ 00073 if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { 00074 return; 00075 } 00076 00077 /* Set device name characteristic data */ 00078 ble.gap().setDeviceName((const uint8_t *) DEVICE_NAME); 00079 00080 /* Optional: add callback for disconnection */ 00081 ble.gap().onDisconnection(disconnectionCallback); 00082 00083 /* Sacrifice 3B of 31B to Advertising Flags */ 00084 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE ); 00085 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); 00086 00087 /* Sacrifice 2B of 31B to AdvType overhead, rest goes to AdvData array you define */ 00088 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData)); 00089 //ble.gattServer().write(Temperatura.getValueHandle(), id); 00090 00091 /* Optional: Add name to device */ 00092 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); 00093 00094 /* Set advertising interval. Longer interval == longer battery life */ 00095 ble.gap().setAdvertisingInterval(100); /* 100ms */ 00096 00097 /* Start advertising */ 00098 ble.gap().startAdvertising(); 00099 } 00100 00101 int main(void) 00102 { 00103 BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); 00104 /* hum_temp->enable(); 00105 press_temp->enable(); 00106 magnetometer->enable(); 00107 accelerometer->enable(); 00108 acc_gyro->enable_x(); 00109 acc_gyro->enable_g();*/ 00110 00111 //ReadOnlyGattCharacteristic<uint8_t> Temperatura; 00112 /* Initialize BLE baselayer, always do this first! */ 00113 ble.init(bleInitComplete); 00114 00115 /* Infinite loop waiting for BLE events */ 00116 while (true) { 00117 /* Save power while waiting for callback events */ 00118 ble.waitForEvent(); 00119 } 00120 } 00121
Generated on Tue Jul 12 2022 20:58:57 by
