28
28
#include " GATT.h"
29
29
30
30
GATTClass::GATTClass () :
31
- _genericAccessService(" 1800 " ),
32
- _deviceNameCharacteristic(" 2a00 " , BLERead, 20 ),
33
- _appearanceCharacteristic(" 2a01 " , BLERead, 2 ),
34
- _genericAttributeService(" 1801 " ),
35
- _servicesChangedCharacteristic(" 2a05 " , BLEIndicate, 4 )
31
+ _genericAccessService(NULL ),
32
+ _deviceNameCharacteristic(NULL ),
33
+ _appearanceCharacteristic(NULL ),
34
+ _genericAttributeService(NULL ),
35
+ _servicesChangedCharacteristic(NULL )
36
36
{
37
- _genericAccessService.retain ();
38
- _genericAttributeService.retain ();
39
-
40
- _genericAccessService.addCharacteristic (&_deviceNameCharacteristic);
41
- _genericAccessService.addCharacteristic (&_appearanceCharacteristic);
42
-
43
- _genericAttributeService.addCharacteristic (&_servicesChangedCharacteristic);
44
37
}
45
38
46
39
GATTClass::~GATTClass ()
@@ -50,13 +43,29 @@ GATTClass::~GATTClass()
50
43
51
44
void GATTClass::begin ()
52
45
{
46
+ _genericAccessService = new BLELocalService (" 1800" );
47
+ _deviceNameCharacteristic = new BLELocalCharacteristic (" 2a00" , BLERead, 20 );
48
+ _appearanceCharacteristic = new BLELocalCharacteristic (" 2a01" , BLERead, 2 );
49
+ _genericAttributeService = new BLELocalService (" 1801" );
50
+ _servicesChangedCharacteristic = new BLELocalCharacteristic (" 2a05" , BLEIndicate, 4 );
51
+
52
+ _genericAccessService->retain ();
53
+ _deviceNameCharacteristic->retain ();
54
+ _appearanceCharacteristic->retain ();
55
+ _genericAttributeService->retain ();
56
+ _servicesChangedCharacteristic->retain ();
57
+
58
+ _genericAccessService->addCharacteristic (_deviceNameCharacteristic);
59
+ _genericAccessService->addCharacteristic (_appearanceCharacteristic);
60
+ _genericAttributeService->addCharacteristic (_servicesChangedCharacteristic);
61
+
53
62
setDeviceName (" Arduino" );
54
63
setAppearance (0x000 );
55
64
56
65
clearAttributes ();
57
66
58
- addService (& _genericAccessService);
59
- addService (& _genericAttributeService);
67
+ addService (_genericAccessService);
68
+ addService (_genericAttributeService);
60
69
}
61
70
62
71
void GATTClass::end ()
@@ -66,12 +75,12 @@ void GATTClass::end()
66
75
67
76
void GATTClass::setDeviceName (const char * deviceName)
68
77
{
69
- _deviceNameCharacteristic. writeValue (deviceName);
78
+ _deviceNameCharacteristic-> writeValue (deviceName);
70
79
}
71
80
72
81
void GATTClass::setAppearance (uint16_t appearance)
73
82
{
74
- _appearanceCharacteristic. writeValue ((uint8_t *)&appearance, sizeof (appearance));
83
+ _appearanceCharacteristic-> writeValue ((uint8_t *)&appearance, sizeof (appearance));
75
84
}
76
85
77
86
void GATTClass::addService (BLEService& service)
0 commit comments