Loading...
Searching...
No Matches
BindOverBLE.h
1#ifndef BINDOVERBLE_H
2#define BINDOVERBLE_H
3#ifdef ARDUINO_ARCH_ESP32
4#ifndef WIFI_ONLY_BIND
5#include "Bind.h"
6#include <BLEDevice.h>
7#include <BLEServer.h>
8#include <BLEUtils.h>
9#include <BLE2902.h>
10#include <Arduino.h>
11#include "Stream.h"
12
13 class BleCallbacks : public BLEServerCallbacks
14{
15 private:
16 bool *_deviceConnected;
17 public:
18 // Get _deviceConnected pointer
19 BleCallbacks(bool &deviceConnected) : _deviceConnected(&deviceConnected){}
20
21 void onConnect(BLEServer *pServer)
22 {
23 *this->_deviceConnected = true;
24 }
25
26 void onDisconnect(BLEServer *pServer)
27 {
28 *this->_deviceConnected = false;
29 delay(500); // give the bluetooth stack the chance to get things ready
30 pServer->startAdvertising(); // restart advertising
31 }
32};
33
34 class BleRXCallbacks : public BLECharacteristicCallbacks
35{
36 private:
37 Bind *_bind;
38
39 public:
40 BleRXCallbacks(Bind &bind)
41 {
42 this->_bind = &bind;
43 }
44
45 void onWrite(BLECharacteristic *pCharacteristic) override;
46};
47
54 class BleStream : public Stream
55{
56 private:
57 BLEServer *pServer = NULL;
58 BLECharacteristic *pTxCharacteristic;
59 bool deviceConnected = false;
60 bool oldDeviceConnected = false;
61 BleRXCallbacks *rxCallbacks = NULL;
62 BleCallbacks *bleCallbacks = NULL;
63
64 public:
76 bool begin(const char *deviceName, Bind &bind);
77
78 // Same as above but with different order of arguments
79 bool begin(Bind &bind, const char *deviceName);
80 size_t write(const uint8_t *buffer, size_t size) override;
81 int available() override { return 0; }
82 int read() override { return 0; }
83 int peek() override { return 0; }
84 void flush() override {}
85 size_t write(uint8_t) override { return 0; }
86};
87#endif // WIFI_ONLY_BIND
88#endif // ARDUINO_ARCH_ESP32
89#endif // BINDOVERBLE_H
Bind
The Bind class provides a framework for creating interactive applications with BindCanvas.
Definition Bind.h:62