diff --git a/src/utility/GATT.cpp b/src/utility/GATT.cpp index e1ee2c58..0c7ab4dd 100644 --- a/src/utility/GATT.cpp +++ b/src/utility/GATT.cpp @@ -28,19 +28,12 @@ #include "GATT.h" GATTClass::GATTClass() : - _genericAccessService("1800"), - _deviceNameCharacteristic("2a00", BLERead, 20), - _appearanceCharacteristic("2a01", BLERead, 2), - _genericAttributeService("1801"), - _servicesChangedCharacteristic("2a05", BLEIndicate, 4) + _genericAccessService(NULL), + _deviceNameCharacteristic(NULL), + _appearanceCharacteristic(NULL), + _genericAttributeService(NULL), + _servicesChangedCharacteristic(NULL) { - _genericAccessService.retain(); - _genericAttributeService.retain(); - - _genericAccessService.addCharacteristic(&_deviceNameCharacteristic); - _genericAccessService.addCharacteristic(&_appearanceCharacteristic); - - _genericAttributeService.addCharacteristic(&_servicesChangedCharacteristic); } GATTClass::~GATTClass() @@ -50,13 +43,29 @@ GATTClass::~GATTClass() void GATTClass::begin() { + _genericAccessService = new BLELocalService("1800"); + _deviceNameCharacteristic = new BLELocalCharacteristic("2a00", BLERead, 20); + _appearanceCharacteristic = new BLELocalCharacteristic("2a01", BLERead, 2); + _genericAttributeService = new BLELocalService("1801"); + _servicesChangedCharacteristic = new BLELocalCharacteristic("2a05", BLEIndicate, 4); + + _genericAccessService->retain(); + _deviceNameCharacteristic->retain(); + _appearanceCharacteristic->retain(); + _genericAttributeService->retain(); + _servicesChangedCharacteristic->retain(); + + _genericAccessService->addCharacteristic(_deviceNameCharacteristic); + _genericAccessService->addCharacteristic(_appearanceCharacteristic); + _genericAttributeService->addCharacteristic(_servicesChangedCharacteristic); + setDeviceName("Arduino"); setAppearance(0x000); clearAttributes(); - addService(&_genericAccessService); - addService(&_genericAttributeService); + addService(_genericAccessService); + addService(_genericAttributeService); } void GATTClass::end() @@ -66,12 +75,12 @@ void GATTClass::end() void GATTClass::setDeviceName(const char* deviceName) { - _deviceNameCharacteristic.writeValue(deviceName); + _deviceNameCharacteristic->writeValue(deviceName); } void GATTClass::setAppearance(uint16_t appearance) { - _appearanceCharacteristic.writeValue((uint8_t*)&appearance, sizeof(appearance)); + _appearanceCharacteristic->writeValue((uint8_t*)&appearance, sizeof(appearance)); } void GATTClass::addService(BLEService& service) diff --git a/src/utility/GATT.h b/src/utility/GATT.h index 5bc426d7..249d5728 100644 --- a/src/utility/GATT.h +++ b/src/utility/GATT.h @@ -60,11 +60,11 @@ class GATTClass { private: BLELinkedList _attributes; - BLELocalService _genericAccessService; - BLELocalCharacteristic _deviceNameCharacteristic; - BLELocalCharacteristic _appearanceCharacteristic; - BLELocalService _genericAttributeService; - BLELocalCharacteristic _servicesChangedCharacteristic; + BLELocalService* _genericAccessService; + BLELocalCharacteristic* _deviceNameCharacteristic; + BLELocalCharacteristic* _appearanceCharacteristic; + BLELocalService* _genericAttributeService; + BLELocalCharacteristic* _servicesChangedCharacteristic; }; extern GATTClass GATT; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy