forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 7
/
BLEPeripheral.h
82 lines (59 loc) · 2.81 KB
/
BLEPeripheral.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
78
79
80
81
82
#ifndef _BLE_PERIPHERAL_H_
#define _BLE_PERIPHERAL_H_
#include "Arduino.h"
#include "nRF8001.h"
#include "BLEAttribute.h"
#include "BLECentral.h"
#include "BLEDescriptor.h"
#include "BLEService.h"
#include "BLETypedCharacteristics.h"
enum BLEPeripheralEvent {
BLEConnected = 0,
BLEDisconnected = 1
};
typedef void (*BLEPeripheralEventHandler)(BLECentral& central);
class BLEPeripheral : public nRF8001EventListener, public BLECharacteristicValueChangeListener
{
public:
BLEPeripheral(unsigned char req, unsigned char rdy, unsigned char rst);
virtual ~BLEPeripheral();
void begin();
void poll();
void setAdvertisedServiceUuid(const char* advertisedServiceUuid);
void setManufacturerData(const unsigned char manufacturerData[], unsigned char manufacturerDataLength);
void setLocalName(const char *localName);
void setDeviceName(const char* deviceName);
void setAppearance(unsigned short appearance);
void addAttribute(BLEAttribute& attribute);
void disconnect();
BLECentral central();
bool connected();
void setEventHandler(BLEPeripheralEvent event, BLEPeripheralEventHandler eventHandler);
protected:
bool characteristicValueChanged(BLECharacteristic& characteristic);
bool canNotifyCharacteristic(BLECharacteristic& characteristic);
bool canIndicateCharacteristic(BLECharacteristic& characteristic);
virtual void nRF8001Connected(nRF8001& nRF8001, const unsigned char* address);
virtual void nRF8001Disconnected(nRF8001& nRF8001);
virtual void nRF8001CharacteristicValueChanged(nRF8001& nRF8001, BLECharacteristic& characteristic, const unsigned char* value, unsigned char valueLength);
virtual void nRF8001CharacteristicSubscribedChanged(nRF8001& nRF8001, BLECharacteristic& characteristic, bool subscribed);
virtual void nRF8001AddressReceived(nRF8001& nRF8001, const unsigned char* address);
virtual void nRF8001TemperatureReceived(nRF8001& nRF8001, float temperature);
virtual void nRF8001BatteryLevelReceived(nRF8001& nRF8001, float batteryLevel);
private:
nRF8001 _nRF8001;
const char* _advertisedServiceUuid;
const unsigned char* _manufacturerData;
unsigned char _manufacturerDataLength;
const char* _localName;
BLEAttribute** _attributes;
unsigned char _numAttributes;
BLEService _genericAccessService;
BLECharacteristic _deviceNameCharacteristic;
BLECharacteristic _appearanceCharacteristic;
BLEService _genericAttributeService;
BLECharacteristic _servicesChangedCharacteristic;
BLECentral _central;
BLEPeripheralEventHandler _eventHandlers[2];
};
#endif