57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
#include "omobidisplaybackend.h"
|
|
|
|
OmobiDisplayBackend::OmobiDisplayBackend(QObject *parent) : QObject(parent)
|
|
{
|
|
|
|
this->ble = new QBluetoothLeUart();
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
void OmobiDisplayBackend::startScanning() {
|
|
this->ble->startScanningForDevices();
|
|
}
|
|
|
|
void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUart::BluetoothLeUartState state){
|
|
|
|
qDebug() << state;
|
|
|
|
switch(state){
|
|
case QBluetoothLeUart::AcquireData:
|
|
{
|
|
qDebug() << "Now acquiring data!";
|
|
|
|
/* Initialise Slot DataHandler(QString) - gets new data */
|
|
|
|
this->ble->sendData("Hat geklappt");
|
|
break;
|
|
}
|
|
default:
|
|
//nothing for now
|
|
break;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
void OmobiDisplayBackend::DataHandler(const QString &s){
|
|
|
|
qDebug() << "NEw data: " << s;
|
|
|
|
}
|
|
|
|
QBluetoothLeUart* OmobiDisplayBackend::getBleController() {
|
|
return this->ble;
|
|
}
|