Kris Scholte Lubberink
/
SSS_Ble
Ble for smart sOlutions
Diff: source/BleDevicePeripheral.cpp
- Revision:
- 10:d845189d146e
- Parent:
- 7:9cda1b0f25ae
- Child:
- 11:d6ed1437c2ee
diff -r 92d861703f96 -r d845189d146e source/BleDevicePeripheral.cpp --- a/source/BleDevicePeripheral.cpp Tue Jun 11 11:16:55 2019 +0200 +++ b/source/BleDevicePeripheral.cpp Fri Jun 14 10:24:57 2019 +0200 @@ -1,9 +1,12 @@ #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)); @@ -13,7 +16,13 @@ _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() { @@ -21,6 +30,7 @@ _ble.gap().stopAdvertising(ble::LEGACY_ADVERTISING_HANDLE); delete cs; delete is; + MyStripSingleton::getInstance()->resetColor(); if (_ble.hasInitialized()) { _ble.shutdown(); } @@ -33,44 +43,44 @@ 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 - ); + /* 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)) - ); + 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() - ); + 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; - } + if (error) { + print_error(error, "Gap::setAdvertisingPayload() failed"); + _event_queue.break_dispatch(); + return; + } - cs = new ColorService(_ble); - is = new InterestService(_ble); + cs = new ColorService(_ble); + is = new InterestService(_ble); printf("[PERIPHERAL]\t Starting advertising \r\n"); error = _ble.gap().startAdvertising(ble::LEGACY_ADVERTISING_HANDLE);