From 4dd4fa3b5117ae70fa901a0a9f84da8ee1f44e09 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 9 Oct 2020 12:31:39 +0200 Subject: [PATCH] added some example code --- qbluetoothleuart.h | 66 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/qbluetoothleuart.h b/qbluetoothleuart.h index aa88d7e..8d2f344 100644 --- a/qbluetoothleuart.h +++ b/qbluetoothleuart.h @@ -39,6 +39,70 @@ /*! * \brief The QBluetoothLeUart class can be used to talk to BluetoothLE devices via UART effordlessly. * It can be used via C++ and QML. + * + * C++ example: + * \code{.cpp} + * #include + * class MyBluetoothLeClass : QObject { + * public: + * MyBluetoothLeClass(QObject* parent = nullptr) : QObject(parent) { + * this->ble = new QBluetoothLeUart(); + * + * connect(this->ble, &QBluetoothLeUart::foundNewDevice, this, &MyBluetoothLeClass::handleFoundNewDevice); + * connect(this->ble, &QBluetoothLeUart::connectedToDevice, this, &MyBluetoothLeClass::handleBluetoothDeviceConected); + * connect(this->ble, &QBluetoothLeUart::dataReceived, this, &MyBluetoothLeClass::handleDataReceived); + * + * this->ble->startScanningForDevices(); + * } + * + * private: + * QBluetoothLeUart *ble; + * + * private slots: + * void handleFoundNewDevice(QBluetoothLeUartDevice* device) { + * qDebug() << "Found a device: name: " << device->getName() << " address: " << device->getAddress(); + * + * if(device->getName() == "My device name"){ + * this->ble->stopScanningForDevices(); + * this->ble->connectToDevice(device); + * } + * } + * + * void handleBluetoothDeviceConected() { + * this->ble->sendData("This is my test message"); + * } + * + * void handleDataReceived(const QString &s) { + * qDebug() << "Data received: " << s; + * } + * }; + * \endcode + * + * QML example: + * \code{.qml} + * QBluetoothLeUart { + * id: ble + * Component.onCompleted: { + * ble.startScanningForDevices() + * } + * + * onFoundNewDevice: { + * console.log("Found a device: name: " + device.name + " address: " + device.address) + * if(device.name === "ESP32 Chat Test") { + * ble.stopScanningForDevices() + * ble.connectToDevice(device) + * } + * } + * + * onConnectedToDevice: { + * ble.sendData("This is my test message") + * } + * + * onDataReceived: { + * console.log("Data received: " + data) + * } + * } + * \endcode */ class QBluetoothLeUart : public QObject { @@ -246,7 +310,7 @@ signals: void connectedToDevice(); - void dataReceived(QString s); + void dataReceived(QString data); };