diff --git a/OmobiDisplayApp/QBluetoothLeUart b/OmobiDisplayApp/QBluetoothLeUart index 76e4575..6ad924f 160000 --- a/OmobiDisplayApp/QBluetoothLeUart +++ b/OmobiDisplayApp/QBluetoothLeUart @@ -1 +1 @@ -Subproject commit 76e457593e889885fd410fdbcdd659706a1eceb8 +Subproject commit 6ad924f42634aa71df54b53f7de98394ad2ce298 diff --git a/OmobiDisplayApp/main.cpp b/OmobiDisplayApp/main.cpp index 79e3c05..043d5b7 100644 --- a/OmobiDisplayApp/main.cpp +++ b/OmobiDisplayApp/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "omobidisplaybackend.h" #include "omobidisplaytextmodel.h" @@ -11,11 +12,14 @@ int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setOrganizationName("Itsblue"); + QCoreApplication::setOrganizationDomain("itsblue.de"); + QCoreApplication::setApplicationName("Itsblue smart display"); + QGuiApplication app(argc, argv); QTranslator translator; translator.load(":/" + QLocale::system().name() + ".qm"); - translator.load(":/de.qm"); app.installTranslator(&translator); qmlRegisterType("de.itsblue.omobidisplayapp", 1, 0, "OmobiDisplayBackend"); diff --git a/OmobiDisplayApp/omobidisplaybackend.cpp b/OmobiDisplayApp/omobidisplaybackend.cpp index 393dc51..7a689ba 100644 --- a/OmobiDisplayApp/omobidisplaybackend.cpp +++ b/OmobiDisplayApp/omobidisplaybackend.cpp @@ -9,6 +9,8 @@ OmobiDisplayBackend::OmobiDisplayBackend(QObject *parent) : QObject(parent) this->displayBrightness = -1; this->waitingCommands = 0; + this->settings = new QSettings(); + this->keepAliveTimer = new QTimer(this); this->keepAliveTimer->setInterval(5000); this->keepAliveTimer->setSingleShot(false); @@ -34,10 +36,15 @@ void OmobiDisplayBackend::startScanning() { void OmobiDisplayBackend::authenticate(QString code) { // tell display to send over existing model data this->setState(Authenticating); - QString combinedCode = this->bleClient->getCurrentDevice()->getAddress().toUpper() + code; - QString secret = QCryptographicHash::hash(combinedCode.toUtf8(), QCryptographicHash::Sha256).toHex(); - this->sendBluetoothCommand(AuthorizeSessionCommand, QVariantMap{{"secret", secret}}); + if(code.length() == 64) + this->lastDisplaySecret = code; + else if(code.length() == 4) { + QString combinedCode = this->bleClient->getCurrentDevice()->getAddress().toUpper() + code; + this->lastDisplaySecret = QCryptographicHash::hash(combinedCode.toUtf8(), QCryptographicHash::Sha256).toHex(); + } + + this->sendBluetoothCommand(AuthenticateCommand, QVariantMap{{"secret", this->lastDisplaySecret}}); } void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUartClient::BluetoothLeUartClientState state){ @@ -79,9 +86,10 @@ void OmobiDisplayBackend::handleBluetoothStateChange(QBluetoothLeUartClient::Blu } void OmobiDisplayBackend::handleBluetoothDeviceConected() { - this->setState(AuthenticationRequired); - this->authenticate("1234"); - // TODO: stuff + if(this->settings->contains(this->bleClient->getCurrentDevice()->getAddress())) + this->authenticate(this->settings->value(this->bleClient->getCurrentDevice()->getAddress()).toString()); + else + this->setState(AuthenticationRequired); } void OmobiDisplayBackend::handleFoundNewDevice(QBluetoothLeUartDevice* device) { @@ -118,7 +126,7 @@ void OmobiDisplayBackend::sendBluetoothCommand(OmobiDisplayCommand command, QVar QJsonDocument doc = QJsonDocument::fromVariant(commandMap); - qDebug() << "Sending command: \n" << qPrintable(doc.toJson(QJsonDocument::Indented)); + //qDebug() << "Sending command: \n" << qPrintable(doc.toJson(QJsonDocument::Indented)); this->waitingCommands ++; @@ -131,13 +139,13 @@ void OmobiDisplayBackend::sendBluetoothCommand(OmobiDisplayCommand command, QVar void OmobiDisplayBackend::sendBluetoothKeepAlive() { QJsonDocument doc = QJsonDocument::fromVariant(QVariantMap{{"header", KeepAliveCommand}}); - qDebug() << "Sending keep alive: \n" << qPrintable(doc.toJson(QJsonDocument::Indented)); + //qDebug() << "Sending keep alive: \n" << qPrintable(doc.toJson(QJsonDocument::Indented)); this->bleClient->sendData(doc.toJson(QJsonDocument::Compact)); } void OmobiDisplayBackend::handleBluetoothDataReceived(QString s){ - qDebug() << "New data: \n" << qPrintable(s); + //qDebug() << "New data: \n" << qPrintable(s); QJsonParseError parseError; QJsonDocument doc = QJsonDocument::fromJson(s.toUtf8(), &parseError); @@ -150,12 +158,15 @@ void OmobiDisplayBackend::handleBluetoothDataReceived(QString s){ OmobiDisplayStatusCode status = OmobiDisplayStatusCode(doc.toVariant().toMap()["status"].toInt()); switch (header) { - case AuthorizeSessionCommand: { + case AuthenticateCommand: { if(status != Success) { this->setState(AuthenticationRequired); + this->lastDisplaySecret = ""; return; } + this->settings->setValue(this->bleClient->getCurrentDevice()->getAddress(), this->lastDisplaySecret); + this->waitingCommands = 0; this->setState(Initing); this->sendBluetoothCommand(GetAllTextSetsCommand); diff --git a/OmobiDisplayApp/omobidisplaybackend.h b/OmobiDisplayApp/omobidisplaybackend.h index 8da8338..350aba4 100644 --- a/OmobiDisplayApp/omobidisplaybackend.h +++ b/OmobiDisplayApp/omobidisplaybackend.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -35,7 +36,7 @@ public: private: enum OmobiDisplayCommand { - AuthorizeSessionCommand = 0, + AuthenticateCommand = 0, KeepAliveCommand = 1, GetAllTextSetsCommand = 10, GetTextSetParameterCommand = 11, @@ -59,6 +60,9 @@ private: QList> textSetsBuffer; int displayBrightness; + QSettings* settings; + QString lastDisplaySecret; + public slots: Q_INVOKABLE void startScanning(); Q_INVOKABLE void authenticate(QString secret); diff --git a/OmobiDisplayApp/omobidisplaytextmodel.cpp b/OmobiDisplayApp/omobidisplaytextmodel.cpp index d8ed150..169d15d 100644 --- a/OmobiDisplayApp/omobidisplaytextmodel.cpp +++ b/OmobiDisplayApp/omobidisplaytextmodel.cpp @@ -9,7 +9,6 @@ OmobiDisplayTextModel::OmobiDisplayTextModel(QObject* parent) : QAbstractListMod connect(this, &OmobiDisplayTextModel::rowsRemoved, this, &OmobiDisplayTextModel::rowCountChanged); } - int OmobiDisplayTextModel::rowCount(const QModelIndex &) const { return this->texts.length(); diff --git a/OmobiDisplayApp/ressources/qml/ConnectPage.qml b/OmobiDisplayApp/ressources/qml/ConnectPage.qml index a8d229c..991d307 100644 --- a/OmobiDisplayApp/ressources/qml/ConnectPage.qml +++ b/OmobiDisplayApp/ressources/qml/ConnectPage.qml @@ -16,6 +16,11 @@ Page { title: qsTr("Available displays") + signal opened() + + onOpened: { + } + ColumnLayout { id: mainLayout anchors { @@ -114,6 +119,7 @@ Page { } Item { + id: noDisplaysItem anchors.centerIn: parent width: Math.min(parent.height, parent.width) diff --git a/OmobiDisplayApp/ressources/qml/ConnectedPage.qml b/OmobiDisplayApp/ressources/qml/ConnectedPage.qml index 9788b0b..f3399da 100644 --- a/OmobiDisplayApp/ressources/qml/ConnectedPage.qml +++ b/OmobiDisplayApp/ressources/qml/ConnectedPage.qml @@ -15,6 +15,8 @@ Page { title: backend.bleClient.currentDevice === null ? "":backend.bleClient.currentDevice.name + signal opened() + function backButtonClicked() { backend.bleClient.disconnectFromDevice() } @@ -50,15 +52,17 @@ Page { Layout.fillHeight: true verticalAlignment: Text.AlignVCenter font.pixelSize: parent.height * 0.5 + font.family: fontAwesome.name text: "\uf186" } Slider { + id: brightnessSlider Layout.fillWidth: true Layout.fillHeight: true from: 0 - to: 10 + to: 255 stepSize: 1 value: backend.displayBrightness @@ -67,12 +71,19 @@ Page { if(!pressed) backend.displayBrightness = value } + + ToolTip { + parent: brightnessSlider.handle + visible: brightnessSlider.pressed + text: brightnessSlider.value.toFixed(1) + } } Text { Layout.fillHeight: true verticalAlignment: Text.AlignVCenter font.pixelSize: parent.height * 0.5 + font.family: fontAwesome.name text: "\uf185" } } diff --git a/OmobiDisplayApp/ressources/qml/SpinBoxDelegate.qml b/OmobiDisplayApp/ressources/qml/SpinBoxDelegate.qml index f8d8d98..4df3e3c 100644 --- a/OmobiDisplayApp/ressources/qml/SpinBoxDelegate.qml +++ b/OmobiDisplayApp/ressources/qml/SpinBoxDelegate.qml @@ -8,6 +8,7 @@ ItemDelegate { property string value: "" property alias from: spinBox.from property alias to: spinBox.to + property bool editable: false onClicked: { spinBox.value = control.value @@ -67,6 +68,7 @@ ItemDelegate { contentItem: SpinBox { id: spinBox value: control.value + editable: control.editable } onAccepted: { diff --git a/OmobiDisplayApp/ressources/qml/TextEditDialog.qml b/OmobiDisplayApp/ressources/qml/TextEditDialog.qml index f248110..66b6a9f 100644 --- a/OmobiDisplayApp/ressources/qml/TextEditDialog.qml +++ b/OmobiDisplayApp/ressources/qml/TextEditDialog.qml @@ -82,6 +82,8 @@ Dialog { SpinBoxDelegate { id: runtimeSpinBox Layout.fillWidth: true + editable: true + to: 3600 text: qsTr("Runtime (in s)") } @@ -107,7 +109,7 @@ Dialog { SpinBoxDelegate { id: scrollSpeedSpinBox Layout.fillWidth: true - from: 0 + from: 1 to: 10 text: qsTr("Scroll speed") } @@ -116,6 +118,7 @@ Dialog { id: scrollCountSpinBox Layout.fillWidth: true from: 0 + editable: true text: qsTr("Scroll count") } } diff --git a/OmobiDisplayApp/ressources/qml/main.qml b/OmobiDisplayApp/ressources/qml/main.qml index 31f4139..24366e1 100644 --- a/OmobiDisplayApp/ressources/qml/main.qml +++ b/OmobiDisplayApp/ressources/qml/main.qml @@ -46,7 +46,7 @@ ApplicationWindow { opacity: mainStack.currentItem.backButtonVisible ? 1:0 - font.styleName: fontAwesome.name + font.family: fontAwesome.name font.pixelSize: height * 0.6 Material.foreground: "black" @@ -63,7 +63,7 @@ ApplicationWindow { onClicked: mainStack.currentItem.backButtonClicked() } - Text { + Label { Layout.fillHeight: true Layout.fillWidth: true Layout.alignment: Layout.Center @@ -71,6 +71,7 @@ ApplicationWindow { verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter + color: "black" text: mainStack.currentItem.title } @@ -82,7 +83,7 @@ ApplicationWindow { opacity: mainStack.currentItem.actionButtonVisible ? 1:0 - font.styleName: fontAwesome.name + font.family: fontAwesome.name font.pixelSize: height * 0.4 Material.foreground: "black" @@ -102,7 +103,11 @@ ApplicationWindow { FontLoader { id: fontAwesome - source: "qrc:/fa5regular.woff" + source: "qrc:/fa5solid.woff" + + Component.onCompleted: { + console.log("Font name: " + fontAwesome.name) + } } StackView { @@ -117,6 +122,10 @@ ApplicationWindow { mainStack.replace(currentComponent) } + onCurrentItemChanged: { + currentItem.opened() + } + initialItem: connectedPageComp replaceEnter: Transition { diff --git a/OmobiDisplayApp/ressources/shared/fa5solid.woff b/OmobiDisplayApp/ressources/shared/fa5solid.woff new file mode 100644 index 0000000..beec791 Binary files /dev/null and b/OmobiDisplayApp/ressources/shared/fa5solid.woff differ diff --git a/OmobiDisplayApp/ressources/shared/shared.qrc b/OmobiDisplayApp/ressources/shared/shared.qrc index 74f0f89..ca7d0d2 100644 --- a/OmobiDisplayApp/ressources/shared/shared.qrc +++ b/OmobiDisplayApp/ressources/shared/shared.qrc @@ -2,6 +2,6 @@ omobi.png itsblue.png - fa5regular.woff + fa5solid.woff diff --git a/OmobiDisplayApp/ressources/translations/de.qm b/OmobiDisplayApp/ressources/translations/de.qm index 55c0917..981f93a 100644 Binary files a/OmobiDisplayApp/ressources/translations/de.qm and b/OmobiDisplayApp/ressources/translations/de.qm differ diff --git a/OmobiDisplayApp/ressources/translations/de.ts b/OmobiDisplayApp/ressources/translations/de.ts index 8ffc4b5..bce6f7c 100644 --- a/OmobiDisplayApp/ressources/translations/de.ts +++ b/OmobiDisplayApp/ressources/translations/de.ts @@ -76,7 +76,8 @@ Display name (needs restart) - Displayname\n(neutstart nötig) + Displayname +(neutstart nötig) Display code (4 digits)