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