added some example code
This commit is contained in:
parent
e332e41bf3
commit
4dd4fa3b51
1 changed files with 65 additions and 1 deletions
|
@ -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 <qbluetoothleuart.h>
|
||||
* 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);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue