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-11
- Revision:
- 26:ab05e85743a9
- Parent:
- 25:f3b44a34cf5d
- Child:
- 27:09ec26511db8
File content as of revision 26:ab05e85743a9:
/* 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 *advertise = "x xxx "; // 'advertise' blinking sequence
const char *action = "x x x x x "; // 'action' blinking sequence
const char *faulty = "x x xxx "; // 'fault' blinking sequence
// Add a device name for human readability
const static char DEVICE_NAME[] = "T05P_Advertising";
// You have up to 26 bytes of advertising data to use.
// Hex data example: {0x01,0x02,0x03,0x04,0x05}
// Char data example: {"ChangeThisData"}
const static uint8_t AdvData[] = {0x01,0x02,0x03,0x04,0x05};
//==============================================================================
// Some Callbacks
//==============================================================================
void onDisconnect(Blob &blob) // Disconnection Callback
{
blob.start(); // start advertising
blinking("advertise");
}
void onError(Blob &blob) // Error Reporting Callback
{
(void) blob; // Avoid compiler warnings
/* Initialization error handling should go here */
}
void onSetup(Blob &blob) // Immediately After Initializing BLE
{
if (blob.error != BLE_ERROR_NONE)
{
onError(blob);
return;
}
blob.device(DEVICE_NAME); // setup device name
blob.disconnect(onDisconnect); // setup disconnect callback
blob.discoverable();
blob.type("cu"); // connectable unidirected
blob.data(AdvData,sizeof(AdvData));
blob.name("Humbo"); // add name to device
blob.start(100); // start advertising @ 100 msec interval
blinking("advertise");
}
int main(void)
{
Blob blob;
blinking(idle); // idle blinking - everything is OK!
blob.init(onSetup); // init BLE base layer, always do first
blinking(advertise); // idle blinking - everything is OK!
while (true) // Infinite loop waiting for BLE events */
{
blob.sleep(); // low power waiting for BLE events
}
}
