-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathBleNUS.h
60 lines (46 loc) · 1.71 KB
/
BleNUS.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
#ifndef BleNUS_h
#define BleNUS_h
#include <NimBLEDevice.h>
#define NUS_SERVICE_UUID "6e400001-b5a3-f393-e0a9-e50e24dcca9e"
#define NUS_RX_CHARACTERISTIC_UUID "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
#define NUS_TX_CHARACTERISTIC_UUID "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
class BleNUS : public NimBLECharacteristicCallbacks {
public:
BleNUS(NimBLEServer* existingServer);
~BleNUS();
void begin();
void end();
void sendData(const uint8_t* data, size_t length);
void setDataReceivedCallback(void (*callback)(const uint8_t* data, size_t length));
size_t available();
int read();
void flush();
int peek(); // Add peek method
void print(const char* str);
void print(const String& str);
void print(int i);
void print(long l);
void print(unsigned long ul);
void print(float f, int digits = 2);
void print(double d, int digits = 2);
void print(char c);
void println(const char* str);
void println(const String& str);
void println(int i);
void println(long l);
void println(unsigned long ul);
void println(float f, int digits = 2);
void println(double d, int digits = 2);
void println(char c);
void write(uint8_t byte);
void write(const uint8_t *buffer, size_t size);
void onWrite(NimBLECharacteristic* pCharacteristic, NimBLEConnInfo& connInfo) override;
private:
NimBLEServer* pServer;
NimBLEService* pService;
NimBLECharacteristic* pTxCharacteristic;
NimBLECharacteristic* pRxCharacteristic;
void (*dataReceivedCallback)(const uint8_t* data, size_t length);
std::string buffer; // For storing received data
};
#endif