2020-10-08 20:06:57 +02:00
|
|
|
#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);
|
2020-10-09 00:03:50 +02:00
|
|
|
connect(this->ble, &QBluetoothLeUart::connectedToDevice, this, &OmobiDisplayBackend::handleBluetoothDeviceConected);
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
this->setState(Idle);
|
|
|
|
this->ble->startScanningForDevices();
|
2020-10-08 20:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OmobiDisplayBackend::startScanning() {
|
|
|
|
this->ble->startScanningForDevices();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUart::BluetoothLeUartState state){
|
|
|
|
switch(state){
|
2020-10-11 15:50:13 +02:00
|
|
|
case QBluetoothLeUart::Idle: {
|
|
|
|
this->setState(Idle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QBluetoothLeUart::Scanning: {
|
|
|
|
this->setState(Scanning);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QBluetoothLeUart::ScanFinished: {
|
|
|
|
this->setState(ReadyToConnect);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QBluetoothLeUart::Connecting: {
|
|
|
|
this->setState(Connecting);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QBluetoothLeUart::ScanningForService: {
|
|
|
|
this->setState(Connecting);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QBluetoothLeUart::ServiceFound: {
|
|
|
|
this->setState(Connecting);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QBluetoothLeUart::Connected:
|
|
|
|
{
|
|
|
|
this->setState(Connected);
|
2020-10-08 20:06:57 +02:00
|
|
|
break;
|
2020-10-11 15:50:13 +02:00
|
|
|
}
|
2020-10-08 20:06:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 00:03:50 +02:00
|
|
|
void OmobiDisplayBackend::handleBluetoothDeviceConected() {
|
|
|
|
this->ble->sendData("Hallihallo ich bin Julia Mueller");
|
|
|
|
}
|
|
|
|
|
2020-10-08 22:03:30 +02:00
|
|
|
void OmobiDisplayBackend::handleFoundNewDevice(QBluetoothLeUartDevice* device) {
|
2020-10-08 20:06:57 +02:00
|
|
|
qDebug() << "Found a device: name: " << device->getName() << " address: " << device->getAddress();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OmobiDisplayBackend::DataHandler(const QString &s){
|
|
|
|
|
|
|
|
qDebug() << "NEw data: " << s;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-09 00:03:50 +02:00
|
|
|
QBluetoothLeUart* OmobiDisplayBackend::getBleController() {
|
|
|
|
return this->ble;
|
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
OmobiDisplayBackend::OmobiDisplayAppState OmobiDisplayBackend::getState() {
|
|
|
|
return this->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OmobiDisplayBackend::setState(OmobiDisplayAppState state) {
|
|
|
|
if(state == this->state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->state = state;
|
|
|
|
emit this->stateChanged();
|
|
|
|
|
|
|
|
if(this->state == Idle)
|
|
|
|
this->ble->startScanningForDevices();
|
|
|
|
}
|