Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
main.cpp
- Committer:
- hux
- Date:
- 2016-12-10
- Revision:
- 23:f06c9851c72c
- Parent:
- 22:e82c7b8a6072
- Child:
- 24:7bd093ad7d63
File content as of revision 23:f06c9851c72c:
/* mbed Microcontroller Library
* Copyright (c) 2006-2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "ble/BLE.h"
#include "bricks/blob.h"
#include "bricks/blink.h"
const char *idle = "x "; // 'idle' blinking sequence
const char *action = "x x x x x "; // 'action' blinking sequence
/* Optional: Device Name, add for human read-ability */
const static char DEVICE_NAME[] = "T05H_Advertising";
/* You have up to 26 bytes of advertising data to use. */
const static uint8_t AdvData[] = {0x01,0x02,0x03,0x04,0x05}; /* Example of hex data */
//const static uint8_t AdvData[] = {"ChangeThisData"}; /* Example of character data */
/* Optional: Restart advertising when peer disconnects */
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
BLE::Instance().gap().startAdvertising();
}
/**
* This function is called when the ble initialization process has failed
*/
void onBleInitError(Blob &blob)
{
/* Avoid compiler warnings */
(void) blob;
/* Initialization error handling should go here */
}
/**
* Callback triggered when the ble initialization process has finished
*/
void setup(Blob &blob)
{
if (blob.error != BLE_ERROR_NONE)
{
onBleInitError(blob);
return;
}
/* Set device name characteristic data */
blob.pble->gap().setDeviceName((const uint8_t *) DEVICE_NAME);
/* Optional: add callback for disconnection */
blob.pble->gap().onDisconnection(disconnectionCallback);
/* Sacrifice 3B of 31B to Advertising Flags */
blob.pble->gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
blob.pble->gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
/* Sacrifice 2B of 31B to AdvType overhead, rest goes to AdvData array you define */
blob.pble->gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));
/* Optional: Add name to device */
blob.pble->gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
/* Set advertising interval. Longer interval == longer battery life */
blob.pble->gap().setAdvertisingInterval(100); /* 100ms */
/* Start advertising */
blob.pble->gap().startAdvertising();
}
int main(void)
{
blinking(idle);
wait(3.0);
blinking(action,idle);
Blob blob;
//BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
/* Initialize BLE baselayer, always do this first! */
//blob.pble->init(bleInitComplete);
blob.init(setup);
/* Infinite loop waiting for BLE events */
while (true)
{
/* Save power while waiting for callback events */
//blob.pble->waitForEvent();
blob.sleep(); // low power waiting
}
}
