forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BLECharacteristic.h
77 lines (55 loc) · 2.38 KB
/
BLECharacteristic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef _BLE_CHARACTERISTIC_H_
#define _BLE_CHARACTERISTIC_H_
#include "BLELocalAttribute.h"
enum BLECharacteristicEvent {
BLEWritten = 0,
BLESubscribed = 1,
BLEUnsubscribed = 2
};
class BLECentral;
class BLECharacteristic;
typedef void (*BLECharacteristicEventHandler)(BLECentral& central, BLECharacteristic& characteristic);
class BLECharacteristicValueChangeListener
{
public:
virtual bool characteristicValueChanged(BLECharacteristic& /*characteristic*/) { return false; }
virtual bool broadcastCharacteristic(BLECharacteristic& /*characteristic*/) { return false; }
virtual bool canNotifyCharacteristic(BLECharacteristic& /*characteristic*/) { return false; }
virtual bool canIndicateCharacteristic(BLECharacteristic& /*characteristic*/) { return false; }
};
class BLECharacteristic : public BLELocalAttribute
{
friend class BLEPeripheral;
public:
BLECharacteristic(const char* uuid, unsigned char properties, unsigned char valueSize);
BLECharacteristic(const char* uuid, unsigned char properties, const char* value);
virtual ~BLECharacteristic();
unsigned char properties() const;
virtual unsigned char valueSize() const;
virtual const unsigned char* value() const;
virtual unsigned char valueLength() const;
virtual unsigned char operator[] (int offset) const;
virtual bool fixedLength() const;
virtual bool setValue(const unsigned char value[], unsigned char length);
virtual bool setValue(const char* value);
bool broadcast();
bool written();
bool subscribed();
bool canNotify();
bool canIndicate();
void setEventHandler(BLECharacteristicEvent event, BLECharacteristicEventHandler eventHandler);
protected:
virtual void setValue(BLECentral& central, const unsigned char value[], unsigned char length);
void setSubscribed(BLECentral& central, bool written);
void setValueChangeListener(BLECharacteristicValueChangeListener& listener);
unsigned char _valueSize;
unsigned char* _value;
unsigned char _valueLength;
private:
unsigned char _properties;
bool _written;
bool _subscribed;
BLECharacteristicValueChangeListener* _listener;
BLECharacteristicEventHandler _eventHandlers[3];
};
#endif