#include "BluetoothSerial.h" #include "HardwareSerial.h" #include "mString.h" /* Check the ESP configuration */ #if not defined(CONFIG_BT_ENABLED) || not defined(CONFIG_BLUEDROID_ENABLED) #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif #if not defined(CONFIG_BT_SPP_ENABLED) #error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip. #endif #if not defined(CONFIG_BT_SSP_ENABLED) #error Simple Secure Pairing for Bluetooth is not available or not enabled. #endif /* ************************* */ typedef std::function DeviceConnectedCb; class BluetoothDispatcher { public: BluetoothDispatcher(BluetoothSerial *controller, const char *device_name = "Helicopter", HardwareSerial *serial = &Serial); bool initialize(); void tick(); ~BluetoothDispatcher(); private: void _confirmRequestCallback(uint16_t pin); void _authCompleteCallback(boolean success); void _deviceConnectedCallback(esp_bd_addr_t bt_addr); const char *_device_name = nullptr; bool _confirmRequestDone = false; BluetoothSerial *_controller = nullptr; HardwareSerial *_serial = nullptr; static constexpr uint16_t _buffer_size = 256; mString<_buffer_size> _buffer; };