added some basic controls
This commit is contained in:
parent
9d5790533d
commit
1cd6884e7f
5 changed files with 64 additions and 42 deletions
|
@ -1,5 +1,5 @@
|
||||||
QT += quick bluetooth
|
QT += quick bluetooth
|
||||||
CONFIG += c++11 console
|
CONFIG += c++11
|
||||||
|
|
||||||
TARGET = OmobiDisplayApp
|
TARGET = OmobiDisplayApp
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <qbluetoothleuart.h>
|
||||||
|
|
||||||
#include "omobidisplaybackend.h"
|
#include "omobidisplaybackend.h"
|
||||||
|
|
||||||
|
@ -9,10 +10,9 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
OmobiDisplayBackend b;
|
qmlRegisterType<OmobiDisplayBackend>("de.itsblue.omobidisplayapp", 1, 0, "OmobiDisplayBackend");
|
||||||
b.startScanning();
|
QBluetoothLeUart::init();
|
||||||
|
|
||||||
/*
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
const QUrl url(QStringLiteral("qrc:/main.qml"));
|
const QUrl url(QStringLiteral("qrc:/main.qml"));
|
||||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
||||||
|
@ -21,6 +21,6 @@ int main(int argc, char *argv[])
|
||||||
QCoreApplication::exit(-1);
|
QCoreApplication::exit(-1);
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
engine.load(url);
|
engine.load(url);
|
||||||
*/
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,54 @@
|
||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
import QtQuick.Controls 2.0
|
import QtQuick.Controls 2.0
|
||||||
import QtQuick.Window 2.12
|
import QtQuick.Window 2.12
|
||||||
|
import de.itsblue.omobidisplayapp 1.0
|
||||||
|
import de.itsblue.bluetoothleuart 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
width: 640
|
width: 640
|
||||||
height: 480
|
height: 480
|
||||||
visible: true
|
visible: true
|
||||||
title: qsTr("Hello World")
|
title: qsTr("Hello World")
|
||||||
|
|
||||||
|
Page {
|
||||||
|
id: app
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
OmobiDisplayBackend {
|
||||||
|
id: backend
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: connectButton
|
||||||
|
text: "Scan for devices"
|
||||||
|
|
||||||
|
visible: backend.bleController.state === QBluetoothLeUART.Idle
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
backend.bleController.startScanningForDevices()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ListView {
|
||||||
|
id: list
|
||||||
|
anchors.top: connectButton.bottom
|
||||||
|
anchors.margins: 10
|
||||||
|
|
||||||
|
height: parent.height
|
||||||
|
|
||||||
|
model: backend.bleController.avaliableDevices.length
|
||||||
|
|
||||||
|
delegate: Button {
|
||||||
|
property var thisDevice: backend.bleController.avaliableDevices[index]
|
||||||
|
|
||||||
|
text: thisDevice["name"]
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
backend.bleController.connectToDevice(thisDevice["id"])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ OmobiDisplayBackend::OmobiDisplayBackend(QObject *parent) : QObject(parent)
|
||||||
connect(this->ble, &QBluetoothLeUart::stateChanged, this, &OmobiDisplayBackend::handleBluetoothStateChange);
|
connect(this->ble, &QBluetoothLeUart::stateChanged, this, &OmobiDisplayBackend::handleBluetoothStateChange);
|
||||||
connect(this->ble, &QBluetoothLeUart::foundNewDevice, this, &OmobiDisplayBackend::handleFoundNewDevice);
|
connect(this->ble, &QBluetoothLeUart::foundNewDevice, this, &OmobiDisplayBackend::handleFoundNewDevice);
|
||||||
connect(this->ble, &QBluetoothLeUart::dataReceived, this, &OmobiDisplayBackend::DataHandler);
|
connect(this->ble, &QBluetoothLeUart::dataReceived, this, &OmobiDisplayBackend::DataHandler);
|
||||||
|
connect(this->ble, &QBluetoothLeUart::connectedToDevice, this, &OmobiDisplayBackend::handleBluetoothDeviceConected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,36 +21,6 @@ void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUart::Bluetooth
|
||||||
qDebug() << state;
|
qDebug() << state;
|
||||||
|
|
||||||
switch(state){
|
switch(state){
|
||||||
|
|
||||||
case QBluetoothLeUart::Scanning:
|
|
||||||
{
|
|
||||||
qDebug() << "Now scanning";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
case QBluetoothLeUart::ScanFinished:
|
|
||||||
{
|
|
||||||
qDebug() << "Scan finished";
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case QBluetoothLeUart::Connecting:
|
|
||||||
{
|
|
||||||
qDebug() << "Now connecting";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QBluetoothLeUart::Connected:
|
|
||||||
{
|
|
||||||
qDebug() << "Connected.";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QBluetoothLeUart::ServiceFound:
|
|
||||||
{
|
|
||||||
qDebug() << "Service found!";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QBluetoothLeUart::AcquireData:
|
case QBluetoothLeUart::AcquireData:
|
||||||
{
|
{
|
||||||
qDebug() << "Now acquiring data!";
|
qDebug() << "Now acquiring data!";
|
||||||
|
@ -68,13 +38,12 @@ void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUart::Bluetooth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OmobiDisplayBackend::handleBluetoothDeviceConected() {
|
||||||
|
this->ble->sendData("Hallihallo ich bin Julia Mueller");
|
||||||
|
}
|
||||||
|
|
||||||
void OmobiDisplayBackend::handleFoundNewDevice(QBluetoothLeUartDevice* device) {
|
void OmobiDisplayBackend::handleFoundNewDevice(QBluetoothLeUartDevice* device) {
|
||||||
qDebug() << "Found a device: name: " << device->getName() << " address: " << device->getAddress();
|
qDebug() << "Found a device: name: " << device->getName() << " address: " << device->getAddress();
|
||||||
|
|
||||||
if(device->getName() == "ESP32 Chat Test") {
|
|
||||||
this->ble->stopScanningForDevices();
|
|
||||||
this->ble->connectToDevice(device);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OmobiDisplayBackend::DataHandler(const QString &s){
|
void OmobiDisplayBackend::DataHandler(const QString &s){
|
||||||
|
@ -83,3 +52,6 @@ void OmobiDisplayBackend::DataHandler(const QString &s){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QBluetoothLeUart* OmobiDisplayBackend::getBleController() {
|
||||||
|
return this->ble;
|
||||||
|
}
|
||||||
|
|
|
@ -7,20 +7,26 @@
|
||||||
class OmobiDisplayBackend : public QObject
|
class OmobiDisplayBackend : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QBluetoothLeUart* bleController READ getBleController NOTIFY bleControllerChanged)
|
||||||
public:
|
public:
|
||||||
explicit OmobiDisplayBackend(QObject *parent = nullptr);
|
explicit OmobiDisplayBackend(QObject *parent = nullptr);
|
||||||
|
|
||||||
void startScanning();
|
Q_INVOKABLE void startScanning();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QBluetoothLeUart *ble;
|
QBluetoothLeUart *ble;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
QBluetoothLeUart* getBleController();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleBluetoothStateChange(QBluetoothLeUart::BluetoothLeUartState state);
|
void handleBluetoothStateChange(QBluetoothLeUart::BluetoothLeUartState state);
|
||||||
void handleFoundNewDevice(QBluetoothLeUartDevice* device);
|
void handleFoundNewDevice(QBluetoothLeUartDevice* device);
|
||||||
void DataHandler(const QString &s);
|
void DataHandler(const QString &s);
|
||||||
|
void handleBluetoothDeviceConected();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void bleControllerChanged();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue