PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BLESerial.h 1.5KB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef _BLE_SERIAL_H_
  2. #define _BLE_SERIAL_H_
  3. #include <Arduino.h>
  4. #include <BLEPeripheral.h>
  5. class BLESerial : public BLEPeripheral, public Stream
  6. {
  7. public:
  8. BLESerial(unsigned char req, unsigned char rdy, unsigned char rst);
  9. void begin(...);
  10. void poll();
  11. void end();
  12. virtual int available(void);
  13. virtual int peek(void);
  14. virtual int read(void);
  15. virtual void flush(void);
  16. virtual size_t write(uint8_t byte);
  17. using Print::write;
  18. virtual operator bool();
  19. private:
  20. unsigned long _flushed;
  21. static BLESerial* _instance;
  22. size_t _rxHead;
  23. size_t _rxTail;
  24. size_t _rxCount() const;
  25. uint8_t _rxBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
  26. size_t _txCount;
  27. uint8_t _txBuffer[BLE_ATTRIBUTE_MAX_VALUE_LENGTH];
  28. BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
  29. BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART");
  30. BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
  31. BLEDescriptor _rxNameDescriptor = BLEDescriptor("2901", "RX - Receive Data (Write)");
  32. BLECharacteristic _txCharacteristic = BLECharacteristic("6E400003-B5A3-F393-E0A9-E50E24DCCA9E", BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH);
  33. BLEDescriptor _txNameDescriptor = BLEDescriptor("2901", "TX - Transfer Data (Notify)");
  34. void _received(const uint8_t* data, size_t size);
  35. static void _received(BLECentral& /*central*/, BLECharacteristic& rxCharacteristic);
  36. };
  37. #endif