forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnRF8001.h
93 lines (66 loc) · 2.59 KB
/
nRF8001.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
83
84
85
86
87
88
89
90
91
92
93
#ifndef _NRF_8001_H_
#define _NRF_8001_H_
#include "Arduino.h"
#include <utility/lib_aci.h>
#include <utility/aci_setup.h>
#include "BLEAttribute.h"
#include "BLECharacteristic.h"
class nRF8001;
class nRF8001EventListener
{
public:
virtual void nRF8001Connected(nRF8001& nRF8001, const unsigned char* address) = 0;
virtual void nRF8001Disconnected(nRF8001& nRF8001) = 0;
virtual void nRF8001CharacteristicValueChanged(nRF8001& nRF8001, BLECharacteristic& characteristic, const unsigned char* value, unsigned char valueLength) = 0;
virtual void nRF8001CharacteristicSubscribedChanged(nRF8001& nRF8001, BLECharacteristic& characteristic, bool subscribed) = 0;
virtual void nRF8001AddressReceived(nRF8001& nRF8001, const unsigned char* address) = 0;
virtual void nRF8001TemperatureReceived(nRF8001& nRF8001, float temperature) = 0;
virtual void nRF8001BatteryLevelReceived(nRF8001& nRF8001, float batteryLevel) = 0;
};
class nRF8001
{
friend class BLEPeripheral;
protected:
struct pipeInfo {
BLECharacteristic* characteristic;
unsigned short valueHandle;
unsigned short configHandle;
unsigned char startPipe;
unsigned char txPipe;
unsigned char txAckPipe;
unsigned char rxPipe;
unsigned char rxAckPipe;
unsigned char setPipe;
bool txPipeOpen;
bool txAckPipeOpen;
};
nRF8001(unsigned char req, unsigned char rdy, unsigned char rst);
virtual ~nRF8001();
void setEventListener(nRF8001EventListener* eventListener);
void begin(const unsigned char* advertisementData,
unsigned char advertisementDataLength,
const unsigned char* scanData,
unsigned char scanDataLength,
BLEAttribute** attributes,
unsigned char numAttributes);
void poll();
void disconnect();
bool updateCharacteristicValue(BLECharacteristic& characteristic);
bool canNotifyCharacteristic(BLECharacteristic& characteristic);
bool canIndicateCharacteristic(BLECharacteristic& characteristic);
void requestAddress();
void requestTemperature();
void requestBatteryLevel();
private:
void waitForSetupMode();
void sendSetupMessage(hal_aci_data_t* data);
void sendCrc();
private:
struct aci_state_t _aciState;
hal_aci_evt_t _aciData;
struct pipeInfo* _pipeInfo;
unsigned char _numPipeInfo;
unsigned short _crcSeed;
nRF8001EventListener* _eventListener;
};
#endif