From b1d837fbf583cedac569461c7e32a297d1da5f16 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 6 Aug 2020 00:59:36 +0200 Subject: [PATCH] Add support for barcode scanners --- libnymea-app/devicemanager.cpp | 4 +- nymea-app/images.qrc | 1 + nymea-app/resources.qrc | 1 + nymea-app/ui/Nymea.qml | 9 + .../devicepages/BarcodeScannerThingPage.qml | 111 ++++++++++++ nymea-app/ui/images/qrcode.svg | 166 ++++++++++++++++++ 6 files changed, 290 insertions(+), 2 deletions(-) create mode 100644 nymea-app/ui/devicepages/BarcodeScannerThingPage.qml create mode 100644 nymea-app/ui/images/qrcode.svg diff --git a/libnymea-app/devicemanager.cpp b/libnymea-app/devicemanager.cpp index eb03b2f3..bbb77a9e 100644 --- a/libnymea-app/devicemanager.cpp +++ b/libnymea-app/devicemanager.cpp @@ -76,7 +76,7 @@ void DeviceManager::init() qWarning() << "received an event from a device we don't know..." << deviceId << event; return; } -// qDebug() << "Event received" << deviceId.toString() << eventTypeId.toString(); + qDebug() << "Event received" << deviceId.toString() << eventTypeId.toString() << qUtf8Printable(QJsonDocument::fromVariant(event).toJson()); dev->eventTriggered(eventTypeId.toString(), event.value("params").toMap()); emit eventTriggered(deviceId.toString(), eventTypeId.toString(), event.value("params").toMap()); }); @@ -226,7 +226,7 @@ void DeviceManager::notificationReceived(const QVariantMap &data) qWarning() << "received an event from a device we don't know..." << deviceId << qUtf8Printable(QJsonDocument::fromVariant(data).toJson()); return; } -// qDebug() << "Event received" << deviceId.toString() << eventTypeId.toString(); + qDebug() << "Event received" << deviceId.toString() << eventTypeId.toString() << qUtf8Printable(QJsonDocument::fromVariant(event).toJson()); dev->eventTriggered(eventTypeId.toString(), event.value("params").toMap()); } else if (notification == "Integrations.IOConnectionAdded") { QVariantMap connectionMap = data.value("params").toMap().value("ioConnection").toMap(); diff --git a/nymea-app/images.qrc b/nymea-app/images.qrc index 44d134f3..15fd48a9 100644 --- a/nymea-app/images.qrc +++ b/nymea-app/images.qrc @@ -233,5 +233,6 @@ ui/images/garage/garage-090.svg ui/images/garage/garage-100.svg ui/images/navigationpad.svg + ui/images/qrcode.svg diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index e5bcd139..0a5a92aa 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -217,5 +217,6 @@ ui/devicepages/VentilationDevicePage.qml ui/thingconfiguration/ThingClassDetailsPage.qml ui/components/ClosablesControlLarge.qml + ui/devicepages/BarcodeScannerThingPage.qml diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml index 744998ba..9b5227e3 100644 --- a/nymea-app/ui/Nymea.qml +++ b/nymea-app/ui/Nymea.qml @@ -125,6 +125,7 @@ ApplicationWindow { "fingerprintreader", "smartlock", "button", + "barcodescanner", "notifications", "inputtrigger", "outputtrigger", @@ -283,6 +284,10 @@ ApplicationWindow { case "extendedblind": return Qt.resolvedUrl("images/shutter/shutter-060.svg") case "garagedoor": + case "impulsegaragedoor": + case "statefulgaragedoor": + case "extendedstatefulgaragedoor": + case "garagegate": return Qt.resolvedUrl("images/garage/garage-100.svg") case "awning": case "extendedawning": @@ -335,6 +340,8 @@ ApplicationWindow { return Qt.resolvedUrl("images/media-playlist-shuffle.svg") case "alert": return Qt.resolvedUrl("images/notification.svg") + case "barcodescanner": + return Qt.resolvedUrl("images/qrcode.svg") default: console.warn("InterfaceToIcon: Unhandled interface", name) } @@ -486,6 +493,8 @@ ApplicationWindow { page = "IrrigationDevicePage.qml"; } else if (interfaceList.indexOf("ventilation") >= 0) { page = "VentilationDevicePage.qml"; + } else if (interfaceList.indexOf("barcodescanner") >= 0) { + page = "BarcodeScannerThingPage.qml"; } else { page = "GenericDevicePage.qml"; } diff --git a/nymea-app/ui/devicepages/BarcodeScannerThingPage.qml b/nymea-app/ui/devicepages/BarcodeScannerThingPage.qml new file mode 100644 index 00000000..9a53c42f --- /dev/null +++ b/nymea-app/ui/devicepages/BarcodeScannerThingPage.qml @@ -0,0 +1,111 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU General Public License as published by the Free Software +* Foundation, GNU version 3. This project is distributed in the hope that it +* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +* Public License for more details. +* +* You should have received a copy of the GNU General Public License along with +* this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" +import "../customviews" + +DevicePageBase { + id: root + + Connections { + target: logsModelNg + onCountChanged: { + codeLabel.text = logsModelNg.get(0).value + timestampLabel.text = Qt.formatDateTime(logsModelNg.get(0).timestamp) + } + } + + ColumnLayout { + anchors.fill: parent + spacing: app.margins + + + Label { + Layout.fillWidth: true + Layout.topMargin: app.margins + horizontalAlignment: Text.AlignHCenter + text: qsTr("Last scan") + } + + Label { + id: codeLabel + Layout.fillWidth: true + font.pixelSize: app.largeFont * 2 + horizontalAlignment: Text.AlignHCenter + } + + Label { + id: timestampLabel + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + } + + ThinDivider {} + + GenericTypeLogView { + id: logView + Layout.fillWidth: true + Layout.fillHeight: true + + logsModel: logsModelNg + LogsModelNg { + id: logsModelNg + engine: _engine + deviceId: root.thing.id + live: true + typeIds: [root.thing.thingClass.eventTypes.findByName("codeScanned").id] + } + + onAddRuleClicked: { + var value = logView.logsModel.get(index).value + var typeId = logView.logsModel.get(index).typeId + var rule = engine.ruleManager.createNewRule(); + var eventDescriptor = rule.eventDescriptors.createNewEventDescriptor(); + eventDescriptor.deviceId = device.id; + var eventType = root.deviceClass.eventTypes.getEventType(typeId); + eventDescriptor.eventTypeId = eventType.id; + rule.name = root.device.name + " - " + eventType.displayName; + if (eventType.paramTypes.count === 1) { + var paramType = eventType.paramTypes.get(0); + eventDescriptor.paramDescriptors.setParamDescriptor(paramType.id, value, ParamDescriptor.ValueOperatorEquals); + rule.eventDescriptors.addEventDescriptor(eventDescriptor); + rule.name = rule.name + " - " + value + } + var rulePage = pageStack.push(Qt.resolvedUrl("../magic/DeviceRulesPage.qml"), {device: root.device}); + rulePage.addRule(rule); + } + } + } + +} diff --git a/nymea-app/ui/images/qrcode.svg b/nymea-app/ui/images/qrcode.svg new file mode 100644 index 00000000..949b1951 --- /dev/null +++ b/nymea-app/ui/images/qrcode.svg @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + +