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.
source/BleDevicePeripheral.cpp
- Committer:
- kris@kris-X682X
- Date:
- 2019-06-14
- Revision:
- 10:d845189d146e
- Parent:
- 7:9cda1b0f25ae
- Child:
- 11:d6ed1437c2ee
File content as of revision 10:d845189d146e:
#include "BleDevicePeripheral.h"
void ledStuff(){
MyStripSingleton::getInstance()->connectionFlash();
MyStripSingleton::getInstance()->resetColor();
}
void BleDevicePeripheral::onConnectionComplete(const ble::ConnectionCompleteEvent &event) {
// ble_error_t error;
/* remember the device that connects to us now so we can connect to it
* during the next demonstration */
// memcpy(_peer_address, event.getPeerAddress().data(), sizeof(_peer_address));
//TODO: Connecting to the device breaks the event queue; it should. BUT there should start some new stuff
printf("[PERIPHERAL]\t Connected to peer: ");
print_address(event.getPeerAddress().data());
_handle = event.getConnectionHandle();
printf("[PERIPHERAL]\t I'm connected to someone, what should i do now?");
//Dispatch forever makes sure that we stay in this state until explicitly told otherwise (on disconnect).
// MyStripSingleton::getInstance()->connectionFlash();
// MyStripSingleton::getInstance()->resetColor();
// _event_queue.call(callback(ledStuff));
_event_queue.dispatch_forever();
}
void BleDevicePeripheral::stop() {
printf("[PERIPHERAL]\t Stopping \r\n");
_ble.gap().stopAdvertising(ble::LEGACY_ADVERTISING_HANDLE);
delete cs;
delete is;
MyStripSingleton::getInstance()->resetColor();
if (_ble.hasInitialized()) {
_ble.shutdown();
}
}
BleDevicePeripheral::~BleDevicePeripheral() {
printf("[PERIPHERAL]\t Destructing the peripheral\r\n");
}
void BleDevicePeripheral::start() {
ble_error_t error;
/* Set up and start advertising */
uint8_t adv_buffer[ble::LEGACY_ADVERTISING_MAX_SIZE];
/* use the helper to build the payload */
ble::AdvertisingDataBuilder adv_data_builder(
adv_buffer
);
adv_data_builder.setFlags();
adv_data_builder.setName("SSS BLE", true);
ble::AdvertisingParameters adv_parameters(
ble::advertising_type_t::CONNECTABLE_UNDIRECTED,
ble::adv_interval_t(ble::millisecond_t(50))
);
error = _ble.gap().setAdvertisingParameters(
ble::LEGACY_ADVERTISING_HANDLE,
adv_parameters
);
if (error) {
print_error(error, "[PERIPHERAL]\t Gap::setAdvertisingParameters() failed");
return;
}
/* Set payload for the set */
error = _ble.gap().setAdvertisingPayload(
ble::LEGACY_ADVERTISING_HANDLE,
adv_data_builder.getAdvertisingData()
);
if (error) {
print_error(error, "Gap::setAdvertisingPayload() failed");
_event_queue.break_dispatch();
return;
}
cs = new ColorService(_ble);
is = new InterestService(_ble);
printf("[PERIPHERAL]\t Starting advertising \r\n");
error = _ble.gap().startAdvertising(ble::LEGACY_ADVERTISING_HANDLE);
if (error) {
print_error(error, "[PERIPHERAL]\t Gap::startAdvertising() failed");
return;
}
printf("[PERIPHERAL]\t Set up BLE. I should now be advertising \r\n");
printf("[PERIPHERAL]\t Please connect a device\r\n");
}
BleDevicePeripheral::BleDevicePeripheral(const BLE &ble, EventQueue &eventQueue)
: BleDevice(ble, eventQueue){
}