From b53c55799ff50fb51bec1bf75bac477fa4165336 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Tue, 7 Jun 2022 15:39:51 -0400 Subject: Updates to restore to a functional state Changes: - Add setenv of QT_QUICK_CONTROLS_STYLE and setting of the frameless window hint to match the previous behavior before the removal of the previous application framework. - Use the new VehicleSignals API from libqtappfw to replace the previous signal-composer usage. - Update the use of the Navigation API from libqtappfw for its rework to use VIS signals instead of the previous signal-composer usage. - The default unit for the vehicle speed has been switched to kilometers with switching driven by the appropriate VSS schema value. Bug-AGL: SPEC-4409, SPEC-4426 Signed-off-by: Scott Murray Change-Id: I69b60a1e3207a54c34aaf114a1e89fce2cf0059f --- app/app.pro | 2 +- app/main.cpp | 15 ++++++++++++- app/navigation_client.cpp | 13 ++++++----- app/navigation_client.h | 5 ++--- app/qml/InfoWindow.qml | 2 +- app/qml/Main.qml | 57 ++++++++++++++++++++++++++++++++++++++--------- 6 files changed, 71 insertions(+), 23 deletions(-) diff --git a/app/app.pro b/app/app.pro index 8889208..398e063 100644 --- a/app/app.pro +++ b/app/app.pro @@ -2,7 +2,7 @@ TEMPLATE = app TARGET = tbtnavi QT = qml network quick positioning location widgets gui-private -PKGCONFIG += qtappfw-navigation wayland-client +PKGCONFIG += qtappfw-navigation qtappfw-vehicle-signals wayland-client CONFIG += c++1z link_pkgconfig wayland-scanner diff --git a/app/main.cpp b/app/main.cpp index 1be4efa..827a561 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "navigation_client.h" @@ -91,6 +92,8 @@ int main(int argc, char *argv[]) QString graphic_role = QString("tbtnavi"); struct agl_shell_desktop *agl_shell_desktop = nullptr; + setenv("QT_QUICK_CONTROLS_STYLE", "AGL", 1); + QGuiApplication app(argc, argv); QCoreApplication::setOrganizationDomain("automotivelinux.org"); QCoreApplication::setOrganizationName("AutomotiveGradeLinux"); @@ -132,7 +135,17 @@ int main(int argc, char *argv[]) File_Operation file; context->setContextProperty("fileOperation", &file); - Navigation *navigation = new Navigation(context); + VehicleSignalsConfig vsConfig("tbtnavi"); + VehicleSignals *vs = new VehicleSignals(vsConfig); + if (!vs) { + qFatal("Could not create VehicleSignals!"); + } + context->setContextProperty("VehicleSignals", vs); + + // Give the navigation client it's own vehicle signals connection + // to simplify state management wrt QML initialization, and keep the + // notification streams separate. + Navigation *navigation = new Navigation(new VehicleSignals(vsConfig), context); engine.load(QUrl(QStringLiteral("qrc:qml/Main.qml"))); diff --git a/app/navigation_client.cpp b/app/navigation_client.cpp index 426bbeb..a8682da 100644 --- a/app/navigation_client.cpp +++ b/app/navigation_client.cpp @@ -1,10 +1,11 @@ +#include #include "navigation_client.h" navigation_client::navigation_client(Navigation *navigation, QObject *parent) : m_navigation(navigation) { - QObject::connect(m_navigation, &Navigation::statusEvent, this, &navigation_client::statusEvent); - QObject::connect(m_navigation, &Navigation::positionEvent, this, &navigation_client::positionEvent); + QObject::connect(m_navigation, &Navigation::statusEvent, this, &navigation_client::onStatusEvent); + QObject::connect(m_navigation, &Navigation::positionEvent, this, &navigation_client::onPositionEvent); // connect the signal to qml inside function(addRoutePointsQml -> do_addRoutePoint) QObject::connect(this, SIGNAL(addRoutePointsQml(QVariant, QVariant, QVariant, QVariant)), @@ -23,21 +24,21 @@ navigation_client::navigation_client(Navigation *navigation, QObject *parent) : navigation_client::~navigation_client(){} -void navigation_client::statusEvent(QVariantMap data) +void navigation_client::onStatusEvent(QVariantMap data) { if (!data.contains("state")) return; QString state = data["state"].toString(); - if (state == "arrived") + if (state == "Arrived") emit arrivedestQml(); - if (state == "stopped" || state == "stop") + if (state == "Stopped") emit stopdemoQml(); } -void navigation_client::positionEvent(QVariantMap data) +void navigation_client::onPositionEvent(QVariantMap data) { if (!data.contains("position")) return;; diff --git a/app/navigation_client.h b/app/navigation_client.h index cdd9396..e884f69 100644 --- a/app/navigation_client.h +++ b/app/navigation_client.h @@ -24,8 +24,7 @@ signals: void arrivedestQml(); private slots: - - void statusEvent(QVariantMap data); - void positionEvent(QVariantMap data); + void onStatusEvent(QVariantMap data); + void onPositionEvent(QVariantMap data); }; #endif // NAVIGATION_CLIENT_H diff --git a/app/qml/InfoWindow.qml b/app/qml/InfoWindow.qml index 4acba5d..7183040 100644 --- a/app/qml/InfoWindow.qml +++ b/app/qml/InfoWindow.qml @@ -53,7 +53,7 @@ Rectangle { Layout.fillWidth: true Layout.alignment: Qt.AlignHCenter - text: "MPH" + text: tbtnavi.mphDisplay ? "MPH" : "KPH" color: "white" font.pixelSize: 32 font.bold: true diff --git a/app/qml/Main.qml b/app/qml/Main.qml index 188fa86..471d160 100644 --- a/app/qml/Main.qml +++ b/app/qml/Main.qml @@ -11,17 +11,54 @@ ApplicationWindow { title: "Turn By Turn Navigation Demo" height: Window.height width: Window.width + flags: Qt.FramelessWindowHint visible: true property double vehicleSpeed: 0 property double engineSpeed: 0 + property bool mphDisplay: false + + Component.onCompleted : { + VehicleSignals.connect() + } Connections { - target: SignalComposer + target: VehicleSignals + + onConnected: { + VehicleSignals.authorize() + } + + onAuthorized: { + VehicleSignals.subscribe("Vehicle.Speed") + VehicleSignals.subscribe("Vehicle.Powertrain.CombustionEngine.Engine.Speed") + VehicleSignals.subscribe("Vehicle.Cabin.Infotainment.Cluster.Mode") + VehicleSignals.get("Vehicle.Cabin.Infotainment.HMI.DistanceUnit") + VehicleSignals.subscribe("Vehicle.Cabin.Infotainment.HMI.DistanceUnit") + } - onSignalEvent: { - //console.log ("Received uid = " + uid + ", value = " + value) - if (uid === "event.info" && value === "true") { + onGetSuccessResponse: { + //console.log("response path = " + path + ", value = " + value) + if (path === "Vehicle.Cabin.Infotainment.HMI.DistanceUnit") { + if (value === "km") { + mphDisplay = false + } else if (value === "mi") { + mphDisplay = true + } + } + } + + onSignalNotification: { + //console.log("signal path = " + path + ", value = " + value) + if (path === "Vehicle.Speed") { + // value units are always km/h + if (mphDisplay) + vehicleSpeed = parseFloat(value) * 0.621504 + else + vehicleSpeed = parseFloat(value) + } else if (path === "Vehicle.Powertrain.CombustionEngine.Engine.Speed") { + engineSpeed = parseFloat(value) + } else if (path === "Vehicle.Cabin.Infotainment.Cluster.Mode" && value === "true") { console.log ("Switching views!") console.log ("currentIndex = " + container.currentIndex) if (container.currentIndex === 0) { @@ -31,14 +68,12 @@ ApplicationWindow { console.log ("Switching to map") container.currentIndex = 0 } - } else if (uid === "event.vehicle.speed") { - var speed_tmp = parseFloat(value) - if(units == "km/h") { - speed_tmp /= 1.609 + } else if (path === "Vehicle.Cabin.Infotainment.HMI.DistanceUnit") { + if (value === "km") { + mphDisplay = false + } else if (value === "mi") { + mphDisplay = true } - vehicleSpeed = speed_tmp - } else if (uid === "event.engine.speed") { - engineSpeed = parseFloat(value) } } } -- cgit 1.2.3-korg