- some fixes

- new icons
- German translation
- tooltip with number on brightness slider
This commit is contained in:
Dorian Zedler 2020-10-18 01:39:59 +02:00
parent a5521d5bb2
commit 66e5229da0
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
14 changed files with 72 additions and 22 deletions

@ -1 +1 @@
Subproject commit 76e457593e889885fd410fdbcdd659706a1eceb8
Subproject commit 6ad924f42634aa71df54b53f7de98394ad2ce298

View file

@ -3,6 +3,7 @@
#include <QQuickStyle>
#include <qbluetoothleuartclient.h>
#include <QTranslator>
#include <QFontDatabase>
#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<OmobiDisplayBackend>("de.itsblue.omobidisplayapp", 1, 0, "OmobiDisplayBackend");

View file

@ -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);

View file

@ -5,6 +5,7 @@
#include <QTimer>
#include <QJsonDocument>
#include <QCryptographicHash>
#include <QSettings>
#include <qbluetoothleuartclient.h>
#include <omobidisplaytextmodel.h>
@ -35,7 +36,7 @@ public:
private:
enum OmobiDisplayCommand {
AuthorizeSessionCommand = 0,
AuthenticateCommand = 0,
KeepAliveCommand = 1,
GetAllTextSetsCommand = 10,
GetTextSetParameterCommand = 11,
@ -59,6 +60,9 @@ private:
QList<QMap<int, QVariant>> textSetsBuffer;
int displayBrightness;
QSettings* settings;
QString lastDisplaySecret;
public slots:
Q_INVOKABLE void startScanning();
Q_INVOKABLE void authenticate(QString secret);

View file

@ -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();

View file

@ -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)

View file

@ -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"
}
}

View file

@ -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: {

View file

@ -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")
}
}

View file

@ -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 {

Binary file not shown.

View file

@ -2,6 +2,6 @@
<qresource prefix="/">
<file>omobi.png</file>
<file>itsblue.png</file>
<file>fa5regular.woff</file>
<file>fa5solid.woff</file>
</qresource>
</RCC>

View file

@ -76,7 +76,8 @@
<message>
<source>Display name
(needs restart)</source>
<translation>Displayname\n(neutstart nötig)</translation>
<translation>Displayname
(neutstart nötig)</translation>
</message>
<message>
<source>Display code (4 digits)</source>