2020-10-18 15:08:12 +02:00
|
|
|
#include "leddisplaybackend.h"
|
2020-10-08 20:06:57 +02:00
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
LedDisplayBackend::LedDisplayBackend(QObject *parent) : QObject(parent)
|
2020-10-08 20:06:57 +02:00
|
|
|
{
|
2020-10-17 21:51:33 +02:00
|
|
|
this->bleClient = new QBluetoothLeUartClient();
|
|
|
|
this->bleClient->setUUIDs("92fecb20-1406-426a-afa5-cd5c1f306462", "92fecb21-1406-426a-afa5-cd5c1f306462", "92fecb22-1406-426a-afa5-cd5c1f306462");
|
2020-10-18 15:08:12 +02:00
|
|
|
this->displayTextModel = new LedDisplayTextModel(this);
|
2020-10-14 23:54:12 +02:00
|
|
|
this->textSetsBuffer.clear();
|
2020-10-18 16:26:24 +02:00
|
|
|
this->displayBrightness = {{"displayBrightness", 0}, {"automaticBrightnessAdjustment", false}};
|
2022-08-03 11:07:40 +02:00
|
|
|
this->runningCommands = 0;
|
2020-10-14 23:54:12 +02:00
|
|
|
this->waitingCommands = 0;
|
2020-10-08 20:06:57 +02:00
|
|
|
|
2020-10-18 01:39:59 +02:00
|
|
|
this->settings = new QSettings();
|
|
|
|
|
2020-10-15 16:57:07 +02:00
|
|
|
this->keepAliveTimer = new QTimer(this);
|
|
|
|
this->keepAliveTimer->setInterval(5000);
|
|
|
|
this->keepAliveTimer->setSingleShot(false);
|
2020-10-18 15:08:12 +02:00
|
|
|
connect(this->keepAliveTimer, &QTimer::timeout, this, &LedDisplayBackend::sendBluetoothKeepAlive);
|
2020-10-15 16:57:07 +02:00
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
connect(this->bleClient, &QBluetoothLeUartClient::stateChanged, this, &LedDisplayBackend::handleBluetoothStateChange);
|
|
|
|
connect(this->bleClient, &QBluetoothLeUartClient::foundNewDevice, this, &LedDisplayBackend::handleFoundNewDevice);
|
|
|
|
connect(this->bleClient, &QBluetoothLeUartClient::dataReceived, this, &LedDisplayBackend::handleBluetoothDataReceived);
|
|
|
|
connect(this->bleClient, &QBluetoothLeUartClient::connectedToDevice, this, &LedDisplayBackend::handleBluetoothDeviceConected);
|
|
|
|
connect(this->displayTextModel, &LedDisplayTextModel::dataChanged, this, &LedDisplayBackend::handleDisplayTextModelDataChanged);
|
|
|
|
connect(this->displayTextModel, &LedDisplayTextModel::rowsInserted, this, &LedDisplayBackend::handleDisplayTextModelRowsInserted);
|
|
|
|
connect(this->displayTextModel, &LedDisplayTextModel::rowsRemoved, this, &LedDisplayBackend::handleDisplayTextModelRowsRemoved);
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
this->setState(Idle);
|
2020-10-17 21:51:33 +02:00
|
|
|
this->bleClient->startScanningForDevices();
|
2020-10-08 20:06:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::startScanning() {
|
2020-10-17 21:51:33 +02:00
|
|
|
this->bleClient->startScanningForDevices();
|
2020-10-08 20:06:57 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::authenticate(QString code) {
|
2020-10-17 01:08:23 +02:00
|
|
|
// tell display to send over existing model data
|
|
|
|
this->setState(Authenticating);
|
|
|
|
|
2020-10-18 01:39:59 +02:00
|
|
|
if(code.length() == 64)
|
|
|
|
this->lastDisplaySecret = code;
|
|
|
|
else if(code.length() == 4) {
|
2020-10-18 19:16:27 +02:00
|
|
|
QString combinedCode = code;
|
2020-10-18 01:39:59 +02:00
|
|
|
this->lastDisplaySecret = QCryptographicHash::hash(combinedCode.toUtf8(), QCryptographicHash::Sha256).toHex();
|
|
|
|
}
|
|
|
|
|
|
|
|
this->sendBluetoothCommand(AuthenticateCommand, QVariantMap{{"secret", this->lastDisplaySecret}});
|
2020-10-17 01:08:23 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::handleBluetoothScanningError(QBluetoothLeUartClient::BluetoothScanError error) {
|
|
|
|
Q_UNUSED(error)
|
2020-10-18 03:26:02 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::handleBluetoothStateChange(QBluetoothLeUartClient::BluetoothLeUartClientState state){
|
2020-10-08 20:06:57 +02:00
|
|
|
switch(state){
|
2020-10-17 21:51:33 +02:00
|
|
|
case QBluetoothLeUartClient::Idle: {
|
2020-10-11 15:50:13 +02:00
|
|
|
this->setState(Idle);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-18 03:26:02 +02:00
|
|
|
case QBluetoothLeUartClient::AdapterTurnedOff: {
|
|
|
|
this->setState(BluetoothOff);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QBluetoothLeUartClient::LocationPermissionDenied: {
|
|
|
|
this->setState(LocationPermissionDenied);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-17 21:51:33 +02:00
|
|
|
case QBluetoothLeUartClient::Scanning: {
|
2020-10-11 15:50:13 +02:00
|
|
|
this->setState(Scanning);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-17 21:51:33 +02:00
|
|
|
case QBluetoothLeUartClient::ScanFinished: {
|
2020-10-11 15:50:13 +02:00
|
|
|
this->setState(ReadyToConnect);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-17 21:51:33 +02:00
|
|
|
case QBluetoothLeUartClient::Connecting: {
|
2020-10-11 15:50:13 +02:00
|
|
|
this->setState(Connecting);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-17 21:51:33 +02:00
|
|
|
case QBluetoothLeUartClient::ScanningForService: {
|
2020-10-11 15:50:13 +02:00
|
|
|
this->setState(Connecting);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-17 21:51:33 +02:00
|
|
|
case QBluetoothLeUartClient::ServiceFound: {
|
2020-10-11 15:50:13 +02:00
|
|
|
this->setState(Connecting);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-17 21:51:33 +02:00
|
|
|
case QBluetoothLeUartClient::Connected:
|
2020-10-11 15:50:13 +02:00
|
|
|
{
|
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-15 16:57:07 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
if(state == QBluetoothLeUartClient::Connected)
|
2020-10-15 16:57:07 +02:00
|
|
|
this->keepAliveTimer->start();
|
|
|
|
else if(this->keepAliveTimer->isActive())
|
|
|
|
this->keepAliveTimer->stop();
|
2020-10-08 20:06:57 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::handleBluetoothDeviceConected() {
|
2020-10-18 01:39:59 +02:00
|
|
|
if(this->settings->contains(this->bleClient->getCurrentDevice()->getAddress()))
|
|
|
|
this->authenticate(this->settings->value(this->bleClient->getCurrentDevice()->getAddress()).toString());
|
|
|
|
else
|
|
|
|
this->setState(AuthenticationRequired);
|
2020-10-09 00:03:50 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::handleFoundNewDevice(QBluetoothLeUartDevice* device) {
|
2020-10-08 20:06:57 +02:00
|
|
|
qDebug() << "Found a device: name: " << device->getName() << " address: " << device->getAddress();
|
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::handleDisplayTextModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) {
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2022-08-02 22:08:30 +02:00
|
|
|
if(this->state == Initing) return;
|
|
|
|
|
2020-10-15 16:57:07 +02:00
|
|
|
qDebug() << "Data changed: topLeft: " << topLeft << " bottomRight: " << bottomRight << " roles: " << roles;
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-15 16:57:07 +02:00
|
|
|
for(int role : roles)
|
|
|
|
this->updateDisplayTextSetParameter(topLeft.row(), role);
|
2020-10-14 23:54:12 +02:00
|
|
|
}
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::handleDisplayTextModelRowsInserted(const QModelIndex &parent, int first, int last) {
|
2020-10-14 23:54:12 +02:00
|
|
|
qDebug() << "Rows inserted: parent: " << parent << " first: " << first << " last " << last;
|
2020-10-18 15:08:12 +02:00
|
|
|
for(int i = 0; i < LedDisplayTextModel::LedDisplayTextModelRoleCount; i++) {
|
2020-10-14 23:54:12 +02:00
|
|
|
this->updateDisplayTextSetParameter(first, i);
|
|
|
|
}
|
|
|
|
}
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::handleDisplayTextModelRowsRemoved(const QModelIndex &parent, int first, int last) {
|
2020-10-14 23:54:12 +02:00
|
|
|
qDebug() << "Rows removed: parent: " << parent << " first: " << first << " last " << last;
|
|
|
|
// Setting Text to "" will delete the item
|
2020-10-18 15:08:12 +02:00
|
|
|
this->updateDisplayTextSetParameter(first, LedDisplayTextModel::TextRole, "");
|
2020-10-14 23:54:12 +02:00
|
|
|
}
|
2020-10-13 01:58:14 +02:00
|
|
|
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::sendBluetoothCommand(OmobiDisplayCommand command, QVariant data) {
|
2020-10-14 23:54:12 +02:00
|
|
|
QVariantMap commandMap = {
|
|
|
|
{"header", command},
|
|
|
|
{"data", data}
|
|
|
|
};
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
QJsonDocument doc = QJsonDocument::fromVariant(commandMap);
|
|
|
|
|
2020-10-18 22:42:42 +02:00
|
|
|
qDebug() << "Sending command: \n" << qPrintable(doc.toJson(QJsonDocument::Compact));
|
2020-10-14 23:54:12 +02:00
|
|
|
|
2022-08-03 11:07:40 +02:00
|
|
|
if((this->state != Initing && this->runningCommands > 0) || (this->state == Initing && this->runningCommands > 1)) {
|
|
|
|
this->waitingCommands++;
|
2022-08-02 22:08:30 +02:00
|
|
|
QEventLoop loop;
|
|
|
|
loop.connect(this, &LedDisplayBackend::commandFinished, &loop, &QEventLoop::quit);
|
|
|
|
loop.exec();
|
2022-08-03 11:07:40 +02:00
|
|
|
this->waitingCommands--;
|
2022-08-02 22:08:30 +02:00
|
|
|
if(this->state == Idle) return;
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:07:40 +02:00
|
|
|
this->runningCommands ++;
|
2020-10-14 23:54:12 +02:00
|
|
|
|
|
|
|
if(this->state == Connected)
|
|
|
|
this->setState(Loading);
|
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
this->bleClient->sendData(doc.toJson(QJsonDocument::Compact));
|
2020-10-08 20:06:57 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::sendBluetoothKeepAlive() {
|
2020-10-15 16:57:07 +02:00
|
|
|
QJsonDocument doc = QJsonDocument::fromVariant(QVariantMap{{"header", KeepAliveCommand}});
|
|
|
|
|
2020-10-18 01:39:59 +02:00
|
|
|
//qDebug() << "Sending keep alive: \n" << qPrintable(doc.toJson(QJsonDocument::Indented));
|
2020-10-15 16:57:07 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
this->bleClient->sendData(doc.toJson(QJsonDocument::Compact));
|
2020-10-15 16:57:07 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::handleBluetoothDataReceived(QString s){
|
2020-10-18 15:44:18 +02:00
|
|
|
qDebug() << "New data: \n" << qPrintable(s);
|
2020-10-11 21:01:21 +02:00
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
QJsonParseError parseError;
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(s.toUtf8(), &parseError);
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
if(parseError.error != QJsonParseError::NoError)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OmobiDisplayCommand header = OmobiDisplayCommand(doc.toVariant().toMap()["header"].toInt());
|
|
|
|
QVariantMap data = doc.toVariant().toMap()["data"].toMap();
|
|
|
|
OmobiDisplayStatusCode status = OmobiDisplayStatusCode(doc.toVariant().toMap()["status"].toInt());
|
|
|
|
|
2022-08-02 22:08:30 +02:00
|
|
|
qDebug() << "Header is:" << header;
|
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
switch (header) {
|
2020-10-18 01:39:59 +02:00
|
|
|
case AuthenticateCommand: {
|
2020-10-17 01:08:23 +02:00
|
|
|
if(status != Success) {
|
|
|
|
this->setState(AuthenticationRequired);
|
2020-10-18 01:39:59 +02:00
|
|
|
this->lastDisplaySecret = "";
|
2020-10-17 01:08:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-18 01:39:59 +02:00
|
|
|
this->settings->setValue(this->bleClient->getCurrentDevice()->getAddress(), this->lastDisplaySecret);
|
|
|
|
|
2022-08-03 11:07:40 +02:00
|
|
|
this->runningCommands = 0;
|
2022-08-02 22:08:30 +02:00
|
|
|
emit this->commandFinished();
|
2022-08-03 11:07:40 +02:00
|
|
|
this->setLoadingProgress(0);
|
2020-10-17 01:08:23 +02:00
|
|
|
this->setState(Initing);
|
|
|
|
this->sendBluetoothCommand(GetAllTextSetsCommand);
|
|
|
|
|
2020-10-15 16:57:07 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KeepAliveCommand: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
case GetAllTextSetsCommand: {
|
2022-08-02 22:08:30 +02:00
|
|
|
// indicates that all existing text sets have been sent over after GetAllTextSetsCommand was called
|
2020-10-14 23:54:12 +02:00
|
|
|
if(status != Success)
|
|
|
|
// TODO: handle error
|
|
|
|
break;
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
this->displayTextModel->maximumTextLength = data["maximumTextLength"].toInt();
|
|
|
|
this->displayTextModel->maximumTextSets = data["maximumTextSets"].toInt();
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2022-08-02 22:08:30 +02:00
|
|
|
this->displayTextModel->setTexts({});
|
2020-10-14 23:54:12 +02:00
|
|
|
this->textSetsBuffer.clear();
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2022-08-02 22:08:30 +02:00
|
|
|
for(int i = 0; i < this->displayTextModel->maximumTextSets; i++) {
|
|
|
|
for(int param = 0; param < DisplayTextSetParameterCount; param++) {
|
2022-08-03 11:07:40 +02:00
|
|
|
this->setLoadingProgress(float((i*DisplayTextSetParameterCount) + param +1) / float(this->displayTextModel->maximumTextSets * DisplayTextSetParameterCount));
|
2022-08-02 22:08:30 +02:00
|
|
|
this->sendBluetoothCommand(GetTextSetParameterCommand, QVariantMap({{"index", i}, {"parameter", param}}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->sendBluetoothCommand(GetDisplayBrightnessCommand);
|
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
this->refreshLoadingState();
|
|
|
|
|
|
|
|
break;
|
2020-10-13 01:58:14 +02:00
|
|
|
}
|
2020-10-14 23:54:12 +02:00
|
|
|
case GetTextSetParameterCommand: {
|
|
|
|
|
|
|
|
int index = data["index"].toInt();
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
if(index < 0)
|
|
|
|
return;
|
|
|
|
|
2020-10-15 12:52:19 +02:00
|
|
|
while(this->textSetsBuffer.length() <= index)
|
2020-10-14 23:54:12 +02:00
|
|
|
this->textSetsBuffer.append(QMap<int, QVariant>());
|
|
|
|
|
|
|
|
int parameter = data["parameter"].toInt();
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
if(!this->textSetsBuffer[index].contains(parameter))
|
|
|
|
this->textSetsBuffer[index].insert(parameter, QVariant());
|
2020-10-13 17:00:25 +02:00
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
this->textSetsBuffer[index][parameter] = data["value"].toString();
|
2022-08-02 22:08:30 +02:00
|
|
|
qDebug() << "Got value: " << this->textSetsBuffer[index][parameter];
|
|
|
|
this->displayTextModel->setTexts(this->textSetsBuffer);
|
|
|
|
this->refreshLoadingState();
|
2020-10-14 23:54:12 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GetDisplayBrightnessCommand: {
|
2020-10-18 16:26:24 +02:00
|
|
|
this->setDisplayBrightness(data);
|
2020-10-14 23:54:12 +02:00
|
|
|
this->refreshLoadingState();
|
|
|
|
break;
|
|
|
|
}
|
2020-10-17 03:22:37 +02:00
|
|
|
case SetTextSetParameterCommand:
|
|
|
|
case SetDisplayBrightnessCommand:
|
|
|
|
case SetDisplayCodeCommand:
|
|
|
|
case SetDisplayNameCommand:
|
2020-10-14 23:54:12 +02:00
|
|
|
// TODO: Error handling
|
|
|
|
this->refreshLoadingState();
|
|
|
|
break;
|
2020-10-17 03:22:37 +02:00
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::updateDisplayTextSetParameter(int index, int parameter) {
|
2020-10-14 23:54:12 +02:00
|
|
|
this->updateDisplayTextSetParameter(index, parameter, this->displayTextModel->data(index, parameter).toString());
|
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::updateDisplayTextSetParameter(int index, int parameter, QString value) {
|
2020-10-14 23:54:12 +02:00
|
|
|
if(this->state == Initing)
|
|
|
|
return;
|
|
|
|
qDebug() << "Updating data at index: " << index << " parameter: " << parameter << " and value: " << value;
|
|
|
|
|
|
|
|
QVariantMap dataMap = {
|
|
|
|
{"index", index},
|
|
|
|
{"parameter", parameter},
|
|
|
|
{"value", value}
|
|
|
|
};
|
|
|
|
|
|
|
|
this->sendBluetoothCommand(SetTextSetParameterCommand, dataMap);
|
2020-10-11 21:01:21 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
QBluetoothLeUartClient* LedDisplayBackend::getBleClient() {
|
2020-10-17 21:51:33 +02:00
|
|
|
return this->bleClient;
|
2020-10-09 00:03:50 +02:00
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-11 21:01:21 +02:00
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
LedDisplayTextModel* LedDisplayBackend::getDisplayTextModel() {
|
2020-10-11 21:01:21 +02:00
|
|
|
return this->displayTextModel;
|
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
LedDisplayBackend::OmobiDisplayAppState LedDisplayBackend::getState() {
|
2020-10-11 15:50:13 +02:00
|
|
|
return this->state;
|
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::refreshLoadingState() {
|
2020-10-14 23:54:12 +02:00
|
|
|
if(this->state != Initing && this->state != Loading)
|
|
|
|
return;
|
|
|
|
|
2022-08-03 11:07:40 +02:00
|
|
|
qDebug() << "Refreshing loading state! Waiting: " << this->runningCommands;
|
2022-08-02 22:08:30 +02:00
|
|
|
emit this->commandFinished();
|
2020-10-14 23:54:12 +02:00
|
|
|
|
2022-08-03 11:07:40 +02:00
|
|
|
if(this->runningCommands <= 1 && this->waitingCommands == 0) {
|
|
|
|
this->runningCommands = 0;
|
2020-10-14 23:54:12 +02:00
|
|
|
this->setState(Connected);
|
2022-08-03 11:07:40 +02:00
|
|
|
this->setLoadingProgress(0);
|
2020-10-14 23:54:12 +02:00
|
|
|
}
|
|
|
|
else
|
2022-08-03 11:07:40 +02:00
|
|
|
this->runningCommands--;
|
2020-10-14 23:54:12 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::setState(OmobiDisplayAppState state) {
|
2020-10-11 15:50:13 +02:00
|
|
|
if(state == this->state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->state = state;
|
|
|
|
emit this->stateChanged();
|
|
|
|
|
2020-10-14 23:54:12 +02:00
|
|
|
qDebug() << "Now in " << state << " state";
|
|
|
|
|
2022-08-02 22:08:30 +02:00
|
|
|
if(this->state == Idle) {
|
2022-08-03 11:07:40 +02:00
|
|
|
this->runningCommands = 0;
|
2022-08-02 22:08:30 +02:00
|
|
|
emit this->commandFinished();
|
2020-10-17 21:51:33 +02:00
|
|
|
this->bleClient->startScanningForDevices();
|
2022-08-02 22:08:30 +02:00
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
}
|
2020-10-13 01:58:14 +02:00
|
|
|
|
2020-10-18 16:26:24 +02:00
|
|
|
QVariantMap LedDisplayBackend::getDisplayBrightness() {
|
2020-10-13 01:58:14 +02:00
|
|
|
return this->displayBrightness;
|
|
|
|
}
|
|
|
|
|
2020-10-18 16:26:24 +02:00
|
|
|
void LedDisplayBackend::setDisplayBrightness(QVariantMap brightness) {
|
2020-10-13 01:58:14 +02:00
|
|
|
if(brightness == this->displayBrightness)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->displayBrightness = brightness;
|
|
|
|
|
2020-10-18 16:26:24 +02:00
|
|
|
this->sendBluetoothCommand(SetDisplayBrightnessCommand, this->displayBrightness);
|
2020-10-13 01:58:14 +02:00
|
|
|
|
|
|
|
emit this->displayBrightnessChanged();
|
|
|
|
}
|
2020-10-17 03:22:37 +02:00
|
|
|
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::setDisplayCode(QString code) {
|
2020-10-17 03:22:37 +02:00
|
|
|
this->sendBluetoothCommand(SetDisplayCodeCommand, QVariantMap{{"displayCode",code}});
|
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
void LedDisplayBackend::setDisplayName(QString name) {
|
2020-10-17 03:22:37 +02:00
|
|
|
// This will restart the display!!
|
|
|
|
this->sendBluetoothCommand(SetDisplayNameCommand, QVariantMap{{"displayName", name}});
|
|
|
|
}
|
2022-08-03 11:07:40 +02:00
|
|
|
|
|
|
|
void LedDisplayBackend::setLoadingProgress(float progress) {
|
|
|
|
this->loadingProgress = progress;
|
|
|
|
emit this->loadingProgressChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
float LedDisplayBackend::getLoadingProgress() {
|
|
|
|
return this->loadingProgress;
|
|
|
|
}
|