added some basic controls

This commit is contained in:
Dorian Zedler 2020-10-09 00:03:50 +02:00
parent 9d5790533d
commit 1cd6884e7f
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
5 changed files with 64 additions and 42 deletions

View file

@ -1,5 +1,5 @@
QT += quick bluetooth
CONFIG += c++11 console
CONFIG += c++11
TARGET = OmobiDisplayApp

View file

@ -1,5 +1,6 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <qbluetoothleuart.h>
#include "omobidisplaybackend.h"
@ -9,10 +10,9 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
OmobiDisplayBackend b;
b.startScanning();
qmlRegisterType<OmobiDisplayBackend>("de.itsblue.omobidisplayapp", 1, 0, "OmobiDisplayBackend");
QBluetoothLeUart::init();
/*
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
@ -21,6 +21,6 @@ int main(int argc, char *argv[])
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
*/
return app.exec();
}

View file

@ -1,10 +1,54 @@
import QtQuick 2.12
import QtQuick.Controls 2.0
import QtQuick.Window 2.12
import de.itsblue.omobidisplayapp 1.0
import de.itsblue.bluetoothleuart 1.0
ApplicationWindow {
width: 640
height: 480
visible: true
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"])
}
}
}
}
}

View file

@ -8,7 +8,7 @@ OmobiDisplayBackend::OmobiDisplayBackend(QObject *parent) : QObject(parent)
connect(this->ble, &QBluetoothLeUart::stateChanged, this, &OmobiDisplayBackend::handleBluetoothStateChange);
connect(this->ble, &QBluetoothLeUart::foundNewDevice, this, &OmobiDisplayBackend::handleFoundNewDevice);
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;
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:
{
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) {
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){
@ -83,3 +52,6 @@ void OmobiDisplayBackend::DataHandler(const QString &s){
}
QBluetoothLeUart* OmobiDisplayBackend::getBleController() {
return this->ble;
}

View file

@ -7,20 +7,26 @@
class OmobiDisplayBackend : public QObject
{
Q_OBJECT
Q_PROPERTY(QBluetoothLeUart* bleController READ getBleController NOTIFY bleControllerChanged)
public:
explicit OmobiDisplayBackend(QObject *parent = nullptr);
void startScanning();
Q_INVOKABLE void startScanning();
private:
QBluetoothLeUart *ble;
public slots:
QBluetoothLeUart* getBleController();
private slots:
void handleBluetoothStateChange(QBluetoothLeUart::BluetoothLeUartState state);
void handleFoundNewDevice(QBluetoothLeUartDevice* device);
void DataHandler(const QString &s);
void handleBluetoothDeviceConected();
signals:
void bleControllerChanged();
};