diff options
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | app/Als-meter-demo.qml | 290 | ||||
-rw-r--r-- | app/CameraControl.qml | 136 | ||||
-rw-r--r-- | app/Mid.qml | 4 | ||||
-rw-r--r-- | app/MidOther.qml | 36 | ||||
-rw-r--r-- | app/Shift.qml | 9 | ||||
-rw-r--r-- | app/Speed.qml | 9 | ||||
-rw-r--r-- | app/Tacho.qml | 6 | ||||
-rw-r--r-- | app/app.pri | 15 | ||||
-rw-r--r-- | app/app.pro | 12 | ||||
-rw-r--r-- | app/camera.cpp | 10 | ||||
-rw-r--r-- | app/camera.h | 6 | ||||
-rw-r--r-- | app/config.tests/libhomescreen/libhomescreen.pro | 2 | ||||
-rw-r--r-- | app/config.tests/qlibwindowmanager/qlibwindowmanager.cpp | 8 | ||||
-rw-r--r-- | app/config.tests/qlibwindowmanager/qlibwindowmanager.pro | 5 | ||||
-rw-r--r-- | app/main.cpp | 132 | ||||
-rw-r--r-- | app/main.qml | 278 | ||||
-rw-r--r-- | app/main.qrc (renamed from app/als-meter-demo.qrc) | 4 | ||||
-rw-r--r-- | package/config.xml | 11 | ||||
-rw-r--r-- | package/package.pro | 2 | ||||
-rw-r--r-- | sample/tachometer_git.bb (renamed from sample/als-meter-demo_git.bb) | 0 | ||||
-rw-r--r-- | tachometer.pro (renamed from als-meter-demo.pro) | 0 |
22 files changed, 391 insertions, 592 deletions
@@ -8,13 +8,13 @@ Information * Hardware: Renesas m3ulcb * Software: Daring Dab 4.0.0 -* Application name: als-meter-demo -* Test Camera Device: Logitech c920r +* Application name: tachometer +* Test Device: Logitech c920r How to compile and install ==== -<br> These is a sample recipe for als-meter-demo, you can just add that recipes into your project and bitbake. -<br> Sample Recipes: als-meter-demo_git.bb +<br> These is a sample recipe for tachometer, you can just add that recipes into your project and bitbake. +<br> Sample Recipes: tachometer_git.bb How to use ==== diff --git a/app/Als-meter-demo.qml b/app/Als-meter-demo.qml deleted file mode 100644 index 4549704..0000000 --- a/app/Als-meter-demo.qml +++ /dev/null @@ -1,290 +0,0 @@ -/*
- * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import QtQuick 2.6
-import QtQuick.Layouts 1.3
-import QtQuick.Controls 2.0
-import QtQuick.Window 2.2
-import Camera 1.0
-import QtWebSockets 1.0
-
-ApplicationWindow {
- id: root
- width: 1080
- height: 1487
-
- property string als_meter_demo_request_str: ""
- property string api_str: "steering-wheel"
- property var msgid_enu: { "call":2, "retok":3, "reterr":4, "event":5 }
- property int recirc:0
- property int vehiclespeed: 0
- property real enginespeed: 0
- property int wshift: 0
-
- WebSocket {
- id: websocket
- url: bindingAddressWS
-
- onStatusChanged: {
- if (websocket.status === WebSocket.Error){
- console.log ("Error: " + websocket.errorString)
- websocket.active = false
- countdown.start()
- }else if (websocket.status === WebSocket.Open){
- console.log ("Socket Open")
- do_subscribe()
- }else if (websocket.status === WebSocket.Closed){
- console.log ("Socket closed")
- }
- }
-
- onTextMessageReceived: {
- var message_json = JSON.parse(message);
- console.log("Raw response: " + message)
-
- if (message_json[0] === msgid_enu.event){
- var propertyName = message_json[2].event.split("/")[1]
- if (propertyName === "TransmissionMode"){
- wshift = message_json[2].data.value
- }else if (propertyName === "VehicleSpeed"){
- vehiclespeed = message_json[2].data.value
- }else if (propertyName === "EngineSpeed"){
- enginespeed = message_json[2].data.value
- }
- }else if (message_json[0] === msgid_enu.retok){
- for (var item in message_json[2].response){
- if (item === "TransmissionMode"){
- wshift = message_json[2].response["TransmissionMode"]["value"]
- }else if (item === "VehicleSpeed"){
- vehiclespeed = message_json[2].response["VehicleSpeed"]["value"]
- }else if (item === "EngineSpeed"){
- enginespeed = message_json[2].response["EngineSpeed"]["value"]
- }
- }
- }else{
- console.log ("Event type error:", message_json[0])
- }
- }
-
- active: false
- }
-
- Timer {
- id: countdown
- repeat: false
- interval: 3000
- triggeredOnStart: false
- onTriggered: {
- websocket.active = true
- }
- }
-
- Item {
- id: topscreen_up
- width: root.width
- height: (root.height - bottomscreen.height)/2
-
- CameraControl {
- id:cameracontrol_up
- listWH: true
- device: camera_up
- width: root.width
- height:80
- }
- Camera {
- id: camera_up
- width: root.width
- height: topscreen_up.height - cameracontrol_up.height
- anchors.top: cameracontrol_up.bottom
- onIsrunningChanged: {
- camerabg_up.visible = !isrunning
-
- if (isrunning){
- if (cameracontrol_dn.device.cameraCnt() === 1)
- cameracontrol_dn.switchstatus = false;
- }else{
- cameracontrol_dn.switchstatus = true;
- }
- }
- onCamraCntChanged: {
- if (!camera_dn.isrunning)
- cameracontrol_dn.number = camera_dn.camranum();
-
- if (!camera_up.isrunning)
- cameracontrol_up.number = camera_up.camranum();
- }
-
- Image {
- id: camerabg_up
- anchors.centerIn: parent
- width: 200
- height: 200
- source: "images/camera/camera_bg.svg"
- }
- }
- }
-
- Item {
- id: topscreen_dn
- width: root.width
- height: (root.height - bottomscreen.height)/2
- anchors.top: topscreen_up.bottom
- CameraControl {
- id:cameracontrol_dn
- listWH: false
- device: camera_dn
- width: root.width
- height:80
- back:0
- }
- Camera {
- id: camera_dn
- width: root.width
- height: topscreen_dn.height - cameracontrol_dn.height
- anchors.top: cameracontrol_dn.bottom
- onIsrunningChanged: {
- camerabg_dn.visible = !isrunning
-
- if (isrunning){
- if (cameracontrol_up.device.cameraCnt() === 1)
- cameracontrol_up.switchstatus = false;
- }else{
- cameracontrol_up.switchstatus = true;
- }
- }
-
- onCamraCntChanged: {
- if (!camera_up.isrunning)
- cameracontrol_up.number = camera_up.camranum();
-
- if (!camera_dn.isrunning)
- cameracontrol_dn.number = camera_dn.camranum();
- }
-
- Image {
- id: camerabg_dn
- anchors.centerIn: parent
- width: 200
- height: 200
- source: "images/camera/camera_bg.svg"
- }
- }
- }
-
- Item {
- id: bottomscreen
- width: root.width
- height: 600
- anchors.bottom: parent.bottom
- Image {
- width: parent.width
- height: parent.height
- asynchronous: true
- fillMode: Image.TileHorizontally
- smooth: true
- source: "images/homescreen/homebg_bottom.svg"
- }
- RowLayout {
- id: smtparts
- anchors.left: parent.left
- anchors.right: parent.right
- Speed {
- id: speedparts
- anchors.left: parent.left
- anchors.leftMargin: 30
- anchors.bottom: parent.bottom
- anchors.bottomMargin: 120
- width: imgwidth
- height: imgheight
- }
- ColumnLayout {
- id: tachoparts
- anchors.horizontalCenter: parent.horizontalCenter
- Tacho {
- anchors.top: parent.top
- anchors.topMargin: -60
- anchors.horizontalCenter: parent.horizontalCenter
- width: imgwidth
- height: imgheight
- }
- MidOther {
- anchors.bottom: parent.bottom
- anchors.bottomMargin: 110
- anchors.horizontalCenter: parent.horizontalCenter
- width: imgwidth
- height: imgheight
- }
- }
- Mid {
- id: midparts
- anchors.right: parent.right
- anchors.rightMargin: 25
- anchors.bottom: parent.bottom
- anchors.bottomMargin: 90
- width: imgwidth
- height: imgheight
- }
- }
- }
-
- onVisibleChanged: {
- if (visible){
- if (!websocket.active){
- websocket.active = true
- }else{
- do_subscribe()
- }
- }
- else {
- countdown.stop()
- if (websocket.active)
- do_unsubscribe()
- }
- }
-
- Connections {
- target: appVisible
- onVisibleChanged: {
- if (!visible){
- if (websocket.active)
- do_unsubscribe()
- }else{
- if (websocket.active){
- do_subscribe()
- }else{
- websocket.active = true
- }
- }
- }
- }
-
- function do_call(binding, verb, event_name) {
- als_meter_demo_request_str = '[' + msgid_enu.call + ',"99999","' + binding+'/'+verb + '", {"event":"' + event_name + '"} ]'
- websocket.sendTextMessage (als_meter_demo_request_str)
- }
-
- function do_subscribe() {
- do_call(api_str, "subscribe", "VehicleSpeed")
- do_call(api_str, "subscribe", "TransmissionMode")
- do_call(api_str, "subscribe", "EngineSpeed")
- }
-
- function do_unsubscribe() {
- do_call(api_str, "unsubscribe", "VehicleSpeed")
- do_call(api_str, "unsubscribe", "TransmissionMode")
- do_call(api_str, "unsubscribe", "EngineSpeed")
- }
-}
diff --git a/app/CameraControl.qml b/app/CameraControl.qml deleted file mode 100644 index f3407d5..0000000 --- a/app/CameraControl.qml +++ /dev/null @@ -1,136 +0,0 @@ -/*
- * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import QtQuick 2.6
-import QtQuick.Layouts 1.3
-import QtQuick.Controls 2.0
-
-RowLayout {
- property var device
- property var listWH
- property var number: []
- property var fps: ["10", "20", "30", "40", "50", "60"]
- property var resolution: listWH ? ["320*240", "640*480", "1280*720", "1920*1080"] : ["320*240"]
- property var models: [number, fps, resolution]
- property real back: 1
- property bool switchstatus: true
-
- Repeater {
- id: info
- model: ["No.:", "FPS:", "W*H:"]
- delegate: RowLayout{
- Label {
- id: label
- text: model.modelData
- color: "#59FF7F"
- }
- ComboBox {
- id: camerainfo
- implicitWidth: index != 2 ? 100 : 245
- font: label.font
- model: models[index]
- contentItem: Text {
- text: camerainfo.displayText
- font: camerainfo.font
- color: camerainfo.pressed ? "#17a81a" : "white"
- horizontalAlignment: Text.AlignLeft
- verticalAlignment: Text.AlignVCenter
- elide: Text.ElideRight
- }
- indicator: Canvas {
- id: canvas
- x: camerainfo.width - width - camerainfo.rightPadding
- y: camerainfo.topPadding + (camerainfo.availableHeight - height) / 2
- width: 20
- height: 12
- contextType: "2d"
-
- Connections {
- target: camerainfo
- onPressedChanged: canvas.requestPaint()
- }
-
- onPaint: {
- context.reset();
- context.moveTo(0, 0);
- context.lineTo(width, 0);
- context.lineTo(width / 2, height);
- context.closePath();
- context.fillStyle = camerainfo.pressed ? "#17a81a" : "white";
- context.fill();
- }
- }
- popup: Popup {
- id: popup
- y: camerainfo.height - 1
- implicitWidth: camerainfo.width
- implicitHeight: listview.count > 6 ? (listview.contentHeight/3.3) : listview.contentHeight
- padding: 0
-
- contentItem: ListView {
- id: listview
- clip: true
- model: camerainfo.visible ? camerainfo.delegateModel : null
- currentIndex: camerainfo.highlightedIndex
- ScrollIndicator.vertical: ScrollIndicator { }
- }
- background: Image { source: "images/camera/camerainfo_bg.svg" }
- }
- delegate: ItemDelegate {
- id: popupdelegate
- width: camerainfo.width
- contentItem: Item {
- implicitHeight: 30
- Text {
- text: modelData
- color: popupdelegate.pressed || highlighted ? "#21be2b" : "white"
- font: camerainfo.font
- elide: Text.ElideRight
- verticalAlignment: Text.AlignVCenter
- }
- }
- highlighted: camerainfo.highlightedIndex == index
- }
-
- background: Image { source: "images/camera/camerainfo_bg.svg" }
- }
- }
- }
- Switch {
- id: cameraswitch
- enabled: switchstatus
- onCheckedChanged: {
- if (checked && device){
- device.start(info.itemAt(0).children[1].currentText, info.itemAt(1).children[1].currentText, info.itemAt(2).children[1].currentText)
- }else if (!checked && device){
- device.stop()
- }
- }
- }
-
- onVisibleChanged: {
- if (!visible)
- cameraswitch.checked = false
- }
-
- Component.onCompleted: {
- device.enumerateCameras();
- number = device.camranum();
-
- if (device.cameraCnt() === 0)
- switchstatus = false;
- }
-}
diff --git a/app/Mid.qml b/app/Mid.qml index e658138..51daf98 100644 --- a/app/Mid.qml +++ b/app/Mid.qml @@ -19,8 +19,8 @@ import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 Item { - property real imgwidth: 320 - property real imgheight: 320 + property real imgwidth: 384 + property real imgheight: 384 Image { id: midimg diff --git a/app/MidOther.qml b/app/MidOther.qml deleted file mode 100644 index 579d5f1..0000000 --- a/app/MidOther.qml +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017 TOYOTA MOTOR CORPORATION - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import QtQuick 2.6 -import QtQuick.Controls 2.0 -import QtQuick.Layouts 1.0 -import QtWebSockets 1.0 - -Item { - property real imgwidth: 430*120/150 - property real imgheight: 120 - - property var recirc_mid: ["images/mid/recirc_outer.svg", "images/mid/recirc_inter.svg"] - - Image { - width: imgwidth - height: imgheight - fillMode: Image.PreserveAspectFit - asynchronous: true - smooth: true - source: recirc_mid[recirc] - } -} diff --git a/app/Shift.qml b/app/Shift.qml index 60a0f0f..7d2d017 100644 --- a/app/Shift.qml +++ b/app/Shift.qml @@ -21,7 +21,8 @@ import QtWebSockets 1.0 Row { property real percent: 1 property var carshift: [ - "images/meters/tacho_shift_N.svg", "images/meters/tacho_shift_D.svg" + "images/meters/tacho_shift_N.svg", "images/meters/tacho_shift_D.svg", + "images/meters/tacho_shift_P.svg", "images/meters/tacho_shift_R.svg" ] property var wheelshift: [ @@ -36,16 +37,16 @@ Row { fillMode: Image.PreserveAspectFit smooth: true asynchronous: true - source: wshift === 0 ? carshift[0] : carshift[1] + source: wshift == "N" ? carshift[0] : ( wshift == "P" ? carshift[2] : ( wshift == "R" ? carshift[3] : carshift[1])) } Image { - visible: wshift > 0 + visible: (wshift == "D1" || wshift == "D2"||wshift == "D3"||wshift == "D4"||wshift == "D5"||wshift == "D6") width: percent*sourceSize.width height: percent*sourceSize.height fillMode: Image.PreserveAspectFit smooth: true asynchronous: true - source: (wshift > 0 && wshift <= wheelshift.length) ? wheelshift[wshift-1] : wheelshift[0] + source: (wshift == "D1") ? wheelshift[0] : ((wshift == "D2") ? wheelshift[1] : ((wshift == "D3") ? wheelshift[2] : ((wshift == "D4") ? wheelshift[3] : ((wshift == "D5") ? wheelshift[4] : wheelshift[5] )))) } } diff --git a/app/Speed.qml b/app/Speed.qml index 46ec01f..bb99f40 100644 --- a/app/Speed.qml +++ b/app/Speed.qml @@ -19,8 +19,8 @@ import QtQuick.Layouts 1.3 import QtWebSockets 1.0 Item { - property real imgwidth: 300 - property real imgheight: 300 + property real imgwidth: 360 + property real imgheight: 360 property var spdlist: [ "images/meters/speed_0.svg", "images/meters/speed_1.svg", "images/meters/speed_2.svg", "images/meters/speed_3.svg", @@ -31,8 +31,8 @@ Item { property var spdlimit: [ "images/meters/speed_limit_none.svg" ] Image { - width: 280 - height: 280 + width: 336 + height: 336 anchors.top: parent.top anchors.topMargin: 17 anchors.horizontalCenter: parent.horizontalCenter @@ -45,7 +45,6 @@ Item { Image { width: imgwidth height: imgheight - fillMode: Image.PreserveAspectFit smooth: true asynchronous: true source: spdlimit[0] diff --git a/app/Tacho.qml b/app/Tacho.qml index 9c4fbee..4dd71d2 100644 --- a/app/Tacho.qml +++ b/app/Tacho.qml @@ -18,8 +18,8 @@ import QtQuick 2.6 import QtWebSockets 1.0 Item { - property real imgwidth: 600 - property real imgheight: 600 + property real imgwidth: 500 + property real imgheight: 500 property real tacho: enginespeed === undefined ? 0 : (enginespeed > 9000 ? 9 : enginespeed*9/9000) @@ -50,7 +50,7 @@ Item { Shift { percent: imgwidth/480 anchors.right: parent.right - anchors.rightMargin: wshift > 0 ? (imgwidth-width)/2+25 : (imgwidth-width)/2-5 + anchors.rightMargin: (wshift == "N" || wshift == "P" ||wshift == "R" )? (imgwidth-width)/2+25 : (imgwidth-width)/2-5 anchors.bottom: parent.bottom anchors.bottomMargin: 100 spacing: -10 diff --git a/app/app.pri b/app/app.pri index e535cbc..590c154 100644 --- a/app/app.pri +++ b/app/app.pri @@ -2,4 +2,19 @@ TEMPLATE = app load(configure) +qtCompileTest(libhomescreen) +qtCompileTest(qlibwindowmanager) + +config_libhomescreen { + CONFIG += link_pkgconfig + PKGCONFIG += libhomescreen + DEFINES += HAVE_LIBHOMESCREEN +} + +config_qlibwindowmanager { + CONFIG += link_pkgconfig + PKGCONFIG += qlibwindowmanager + DEFINES += HAVE_QLIBWINDOWMANAGER +} + DESTDIR = $${OUT_PWD}/../package/root/bin diff --git a/app/app.pro b/app/app.pro index 035807c..d0b2961 100644 --- a/app/app.pro +++ b/app/app.pro @@ -1,13 +1,10 @@ -TARGET = als-meter-demo -QT = quickcontrols2 dbus - -LIBS += -lopencv_core -lopencv_videoio +TARGET = tachometer +QT = quickcontrols2 equals(QT_ARCH, "arm") { QMAKE_CXXFLAGS += -mfp16-format=ieee } - HEADERS += \ camera.h @@ -15,11 +12,10 @@ SOURCES += \ main.cpp \ camera.cpp -CONFIG += link_pkgconfig -PKGCONFIG += libhomescreen qlibwindowmanager +LIBS += -lopencv_core -lopencv_highgui -lopencv_videoio RESOURCES += \ - als-meter-demo.qrc \ + main.qrc \ images/images.qrc include(app.pri) diff --git a/app/camera.cpp b/app/camera.cpp index 107880c..bd3dd99 100644 --- a/app/camera.cpp +++ b/app/camera.cpp @@ -16,7 +16,7 @@ #include "camera.h" #include <QPainter> -#include <opencv2/imgproc.hpp> +#include <opencv2/imgproc/imgproc.hpp> #include <linux/videodev2.h> #include <fcntl.h> @@ -47,8 +47,8 @@ void Camera::paint(QPainter *painter) { } void Camera::enumerateCameras() { - int maxID = 10; - for (int idx = 0; idx <maxID; idx++){ + int maxID = 20; + for (int idx = 2; idx <maxID; idx++){ std::stringstream no; no << "/dev/video" << idx; qDebug() << idx; @@ -80,8 +80,8 @@ void Camera::start(int no, int fps, QString res) { } if (capture && capture->open(no)){ - capture->set(CAP_PROP_FRAME_WIDTH, res.section("*", 0, 0).toInt()); - capture->set(CAP_PROP_FRAME_HEIGHT, res.section("*", 1, 1).toInt()); + capture->set(CV_CAP_PROP_FRAME_WIDTH, res.section("*", 0, 0).toInt()); + capture->set(CV_CAP_PROP_FRAME_HEIGHT, res.section("*", 1, 1).toInt()); if (fps > 0){ timer->start(1000/fps); diff --git a/app/camera.h b/app/camera.h index 1b85d27..6d5d17c 100644 --- a/app/camera.h +++ b/app/camera.h @@ -21,11 +21,9 @@ #include <QTimer> #include <QImage> #include <QQuickPaintedItem> -#include <opencv2/videoio.hpp> #include <iostream> -#include <opencv2/core.hpp> -#include <opencv2/imgcodecs.hpp> -#include <opencv2/highgui.hpp> +#include <opencv2/core/core.hpp> +#include <opencv2/highgui/highgui.hpp> using namespace std; diff --git a/app/config.tests/libhomescreen/libhomescreen.pro b/app/config.tests/libhomescreen/libhomescreen.pro index eb4e8f3..7d43112 100644 --- a/app/config.tests/libhomescreen/libhomescreen.pro +++ b/app/config.tests/libhomescreen/libhomescreen.pro @@ -2,4 +2,4 @@ SOURCES = libhomescreen.cpp CONFIG -= qt CONFIG += link_pkgconfig -PKGCONFIG += homescreen +PKGCONFIG += libhomescreen diff --git a/app/config.tests/qlibwindowmanager/qlibwindowmanager.cpp b/app/config.tests/qlibwindowmanager/qlibwindowmanager.cpp new file mode 100644 index 0000000..bb95c93 --- /dev/null +++ b/app/config.tests/qlibwindowmanager/qlibwindowmanager.cpp @@ -0,0 +1,8 @@ +#include <qlibwindowmanager.h> + +int main(int argc,char **argv) +{ + QLibWindowmanager qwm; + return 0; +} + diff --git a/app/config.tests/qlibwindowmanager/qlibwindowmanager.pro b/app/config.tests/qlibwindowmanager/qlibwindowmanager.pro new file mode 100644 index 0000000..cb51d98 --- /dev/null +++ b/app/config.tests/qlibwindowmanager/qlibwindowmanager.pro @@ -0,0 +1,5 @@ +SOURCES = qlibwindowmanager.cpp + +CONFIG += qt +CONFIG += link_pkgconfig +PKGCONFIG += qlibwindowmanager diff --git a/app/main.cpp b/app/main.cpp index 88a4978..87ea458 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -19,76 +19,25 @@ #include <QtCore/QCommandLineParser> #include <QtCore/QUrlQuery> #include <QtCore/QFile> -#include <QtDBus/QDBusInterface> -#include <QtDBus/QDBusReply> #include <QtGui/QGuiApplication> -#include <QtQml/QQmlApplicationEngine> #include <QtQml/QQmlContext> +#include <QtQml/QQmlApplicationEngine> #include <QtQuickControls2/QQuickStyle> -#include <QtDBus/QDBusConnection> #include <unistd.h> #include "camera.h" #include <QQuickWindow> + +#ifdef HAVE_LIBHOMESCREEN #include <libhomescreen.hpp> +#endif +#ifdef HAVE_QLIBWINDOWMANAGER #include <qlibwindowmanager.h> - -class AppVisible : public QObject -{ - Q_OBJECT -public: - AppVisible(QObject *parent = nullptr) : QObject(parent){ - m_ppid = getppid(); - m_visible = true; - QDBusConnection::sessionBus().connect("org.agl.windowmanager", - "/windowmanager", - "org.agl.windowmanager", - "appLayerVisibleChanged", - this, - SLOT(appLayerVisibleChanged(int,bool))); - } - -public slots: - void appLayerVisibleChanged(int pid, bool visible){ - bool tempvis = visible; - - if(tempvis && (m_ppid != pid)) - tempvis = false; - - if(m_visible != tempvis){ - m_visible = tempvis; - emit visibleChanged(m_visible); - } - } - -signals: - void visibleChanged(const bool& visible); - -private: - int m_ppid; - bool m_visible; -}; - -class DBus : public QObject -{ - Q_OBJECT -public: - DBus(QObject *parent = nullptr) - : QObject(parent) - , interface("org.agl.homescreen", "/StatusBar", "org.agl.statusbar", QDBusConnection::sessionBus()) - {} - - Q_INVOKABLE void setStatusIcon(int index, const QString &url) { - interface.call("setStatusIcon", index, url); - } - -private: - QDBusInterface interface; -}; +#endif int main(int argc, char *argv[]) { - QString myname = QString("Als-meter-demo"); + QString myname = QString("tachometer"); QGuiApplication app(argc, argv); app.setApplicationName(myname); @@ -109,29 +58,28 @@ int main(int argc, char *argv[]) qmlRegisterType<Camera>("Camera", 1, 0, "Camera"); QQmlApplicationEngine engine; + QQmlContext *context = engine.rootContext(); + QUrl bindingAddress; int port = 0; + QString secret; if (positionalArguments.length() == 2) { port = positionalArguments.takeFirst().toInt(); + secret = positionalArguments.takeFirst(); + bindingAddress.setScheme(QStringLiteral("ws")); + bindingAddress.setHost(QStringLiteral("localhost")); + bindingAddress.setPort(port); + bindingAddress.setPath(QStringLiteral("/api")); + QUrlQuery query; + query.addQueryItem(QStringLiteral("token"), secret); + bindingAddress.setQuery(query); + context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress); + } else { + context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress); } - QString secret = positionalArguments.takeFirst(); - QUrl bindingAddressWS; - bindingAddressWS.setScheme(QStringLiteral("ws")); - bindingAddressWS.setHost(QStringLiteral("localhost")); - bindingAddressWS.setPort(port); - bindingAddressWS.setPath(QStringLiteral("/api")); - QUrlQuery query; - query.addQueryItem(QStringLiteral("token"), secret); - bindingAddressWS.setQuery(query); - QQmlContext *context = engine.rootContext(); - AppVisible appVisible; - context->setContextProperty(QStringLiteral("appVisible"), &appVisible); - context->setContextProperty(QStringLiteral("bindingAddressWS"), bindingAddressWS); - - std::string token = secret.toStdString(); - LibHomeScreen* hs = new LibHomeScreen(); - QLibWindowmanager* qwm = new QLibWindowmanager(); +#ifdef HAVE_QLIBWINDOWMANAGER // WindowManager + QLibWindowmanager* qwm = new QLibWindowmanager(); if(qwm->init(port,secret) != 0){ exit(EXIT_FAILURE); } @@ -144,8 +92,12 @@ int main(int argc, char *argv[]) fprintf(stderr, "Surface got syncDraw!\n"); qwm->endDraw(myname); }); +#endif +#ifdef HAVE_LIBHOMESCREEN // HomeScreen + LibHomeScreen* hs = new LibHomeScreen(); + std::string token = secret.toStdString(); hs->init(port, token.c_str()); // Set the event handler for Event_TapShortcut which will activate the surface for windowmanager hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [qwm, myname](json_object *object){ @@ -153,24 +105,34 @@ int main(int argc, char *argv[]) if(json_object_object_get_ex(object, "application_name", &appnameJ)) { const char *appname = json_object_get_string(appnameJ); - if(myname == appname) + if(QString::compare(myname, appname, Qt::CaseInsensitive) == 0) { qDebug("Surface %s got tapShortcut\n", appname); - qwm->activateSurface(myname); + qwm->activateSurface(myname, "split.main"); } } }); - - DBus dbus; - engine.rootContext()->setContextProperty("dbus", &dbus); - engine.load(QUrl(QStringLiteral("qrc:/Als-meter-demo.qml"))); +#endif + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QObject *root = engine.rootObjects().first(); QQuickWindow *window = qobject_cast<QQuickWindow *>(root); - QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface() - )); +#ifdef HAVE_QLIBWINDOWMANAGER +// QObject::connect(window, SIGNAL(frameSwapped()), qwm, SLOT(slotActivateSurface())); + + qwm->set_event_handler(QLibWindowmanager::Event_Visible, [qwm, root](json_object *object) { + fprintf(stderr, "Surface got Visible!\n"); + QMetaObject::invokeMethod(root, "changeVisible", Q_ARG(QVariant, true)); + }); + + qwm->set_event_handler(QLibWindowmanager::Event_Invisible, [qwm, root](json_object *object) { + fprintf(stderr, "Surface got Invisible!\n"); + QMetaObject::invokeMethod(root, "changeVisible", Q_ARG(QVariant, false)); + }); +#else + window->resize(1280, 720); + window->setVisible(true); +#endif return app.exec(); } - -#include "main.moc" diff --git a/app/main.qml b/app/main.qml new file mode 100644 index 0000000..5172440 --- /dev/null +++ b/app/main.qml @@ -0,0 +1,278 @@ +/*
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import QtQuick 2.6
+import QtQuick.Layouts 1.3
+import QtQuick.Controls 2.0
+import QtQuick.Window 2.2
+import Camera 1.0
+import QtWebSockets 1.0
+
+ApplicationWindow {
+ id: root
+ width: 1280
+ height: 720
+
+ property string request_str: ""
+ property string api_str: "low-can"
+ property var msgid_enu: { "call":2, "retok":3, "reterr":4, "event":5 }
+ property int recirc:0
+ property int vehiclespeed: 0
+ property real enginespeed: 0
+ property int fuellevel: 0
+ property string transmissionMode: 'MT'
+ property bool isAutoMode: false
+ property bool isSport: false
+ property string wshift: "N"
+
+ WebSocket {
+ id: websocket
+ url: bindingAddress
+
+ onStatusChanged: {
+ if (websocket.status === WebSocket.Error){
+ console.log ("Error: " + websocket.errorString)
+ websocket.active = false
+ countdown.start()
+ }else if (websocket.status === WebSocket.Open){
+ console.log ("Socket Open")
+ do_subscribe()
+ }else if (websocket.status === WebSocket.Closed){
+ console.log ("Socket closed")
+ }
+ }
+
+ onTextMessageReceived: {
+ var message_json = JSON.parse(message);
+ console.log("Raw response: " + message)
+
+ if (message_json[0] === msgid_enu.event){
+ var propertyName = message_json[2].event.split("/")[1]
+ if (propertyName === "messages.vehicle.average.speed"){
+ vehiclespeed = message_json[2].data.value
+ console.log("vehiclespeed: " + vehiclespeed)
+ }else if (propertyName === "messages.engine.speed"){
+ enginespeed = message_json[2].data.value
+ console.log("enginespeed: " + enginespeed)
+ }else if ( message.indexOf("messages.fuel.level") > 0 ){
+ fuellevel = message_json[2].data.value
+ }else if (propertyName === "messages.transmission.gearinfo"){
+ if (transmissionMode === "MT" && isAutoMode === false){
+ if( message_json[2].data.value === 0){
+ wshift = 'N'
+ }else{
+ wshift = 'D'+message_json[2].data.value
+ }
+ }
+ }else if (propertyName === "messages.transmission.mode"){
+ transmissionMode = message_json[2].data.value
+ }else if (propertyName === "messages.DriveMode"){
+ if( message_json[2].data.value === "sport"){
+ wshift = 'S1'
+ isSport = true
+ isAutoMode = true
+ }else if( message_json[2].data.value === "eco"){
+ isSport = false
+ wshift = 'E'
+ isAutoMode = true
+ }else if( message_json[2].data.value === "winter"){
+ isSport = false
+ wshift = 'W'
+ isAutoMode = true
+ }
+ }else if ( (propertyName === "messages.transmission.shift.gear") ){
+ if (isSport === true){
+ if(message_json[2].data.value != '0'){
+ wshift = 'S' + message_json[2].data.value
+ }else if(message_json[2].data.value == '0'){
+ wshift = 'D'
+ }
+
+ }
+ }else if (propertyName === "messages.Transmission.SiftPosition.neutral"){
+ if( message_json[2].data.value === true){
+ wshift = 'N'
+ isAutoMode = true
+ }
+ }else if (propertyName === "messages.Transmission.SiftPosition.driving"){
+ if( message_json[2].data.value === true){
+ wshift = 'D'
+ isAutoMode = true
+ }
+ }else if (propertyName === "messages.Transmission.SiftPosition.parking"){
+ if( message_json[2].data.value === true){
+ wshift = 'P'
+ isAutoMode = true
+ }
+ }else if (propertyName === "messages.Transmission.SiftPosition.reverse"){
+ if( message_json[2].data.value === true){
+ wshift = 'R'
+ isAutoMode = true
+ }
+ }else if (propertyName === "messages.Transmission.SiftPosition.B"){
+ if( message_json[2].data.value === true){
+ wshift = 'B'
+ isAutoMode = true
+ }
+ }
+ }else if (message_json[0] === msgid_enu.retok){
+ console.log ("Response is OK!")
+ }else{
+ console.log ("Event type error:", message_json[0])
+ }
+ }
+
+ active: false
+ }
+
+ Timer {
+ id: countdown
+ repeat: false
+ interval: 3000
+ triggeredOnStart: false
+ onTriggered: {
+ websocket.active = true
+ }
+ }
+
+ Item {
+ id: bottomscreen
+ width: root.width
+ height: root.height
+ anchors.bottom: parent.bottom
+ Image {
+ width: parent.width
+ height: parent.height
+ asynchronous: true
+ fillMode: Image.TileHorizontally
+ smooth: true
+ source: "images/homescreen/homebg_bottom.svg"
+ }
+ RowLayout {
+ id: smtparts
+ anchors.left: parent.left
+ anchors.right: parent.right
+ Speed {
+ id: speedparts
+ anchors.left: parent.left
+ anchors.leftMargin: 10
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 30
+ width: imgwidth
+ height: imgheight
+ }
+ ColumnLayout {
+ id: tachoparts
+ anchors.horizontalCenter: parent.horizontalCenter
+ Tacho {
+ anchors.top: parent.top
+ anchors.topMargin: -40
+ anchors.horizontalCenter: parent.horizontalCenter
+ width: imgwidth
+ height: imgheight
+ }
+
+ Item {
+ id: camarea
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 80
+ anchors.horizontalCenter: parent.horizontalCenter
+
+ width: 320
+ height: 180
+
+ Camera {
+ id: camdev
+ width: camarea.width
+ height: camarea.height
+ onIsrunningChanged: {
+ camerabg_up.visible = !isrunning
+ }
+ Image {
+ id: camerabg_up
+ anchors.centerIn: parent
+ width: 200
+ height: 200
+ source: "images/camera/camera_bg.svg"
+ }
+ }
+ Component.onCompleted: {
+ camdev.enumerateCameras();
+ }
+ }
+ }
+ Mid {
+ id: midparts
+ anchors.right: parent.right
+ anchors.rightMargin: 5
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 15
+ width: imgwidth
+ height: imgheight
+ }
+ }
+ }
+
+ function changeVisible(visible) {
+ if (visible){
+ if (!websocket.active){
+ websocket.active = true
+ }else{
+ do_subscribe()
+ }
+ var number = camdev.camranum();
+ camdev.start(number[0], "30", "640*480")
+ }else{
+ do_subscribe()
+ camdev.stop()
+ }
+ }
+
+ function do_call(binding, verb, event_name) {
+ request_str = '[' + msgid_enu.call + ',"99999","' + binding+'/'+verb + '", {"event":"' + event_name + '"} ]'
+ websocket.sendTextMessage (request_str)
+ }
+
+ function do_subscribe() {
+ do_call(api_str, "subscribe", "vehicle.average.speed")
+ do_call(api_str, "subscribe", "engine.speed")
+ do_call(api_str, "subscribe", "fuel.level")
+ do_call(api_str, "subscribe", "transmission.gearinfo")
+ do_call(api_str, "subscribe", "transmission.mode")
+ do_call(api_str, "subscribe", "DriveMode")
+ do_call(api_str, "subscribe", "transmission.shift.gear")
+ do_call(api_str, "subscribe", "Transmission.SiftPosition.neutral")
+ do_call(api_str, "subscribe", "Transmission.SiftPosition.driving")
+ do_call(api_str, "subscribe", "Transmission.SiftPosition.parking")
+ do_call(api_str, "subscribe", "Transmission.SiftPosition.reverse")
+ do_call(api_str, "subscribe", "Transmission.SiftPosition.B")
+ }
+
+ function do_unsubscribe() {
+ do_call(api_str, "unsubscribe", "vehicle.average.speed")
+ do_call(api_str, "unsubscribe", "engine.speed")
+ do_call(api_str, "unsubscribe", "fuel.level")
+ do_call(api_str, "unsubscribe", "transmission.gearinfo")
+ do_call(api_str, "unsubscribe", "transmission.mode")
+ do_call(api_str, "unsubscribe", "DriveMode")
+ do_call(api_str, "unsubscribe", "transmission.shift.gear")
+ do_call(api_str, "unsubscribe", "Transmission.SiftPosition.neutral")
+ do_call(api_str, "unsubscribe", "Transmission.SiftPosition.driving")
+ do_call(api_str, "unsubscribe", "Transmission.SiftPosition.parking")
+ do_call(api_str, "unsubscribe", "Transmission.SiftPosition.reverse")
+ do_call(api_str, "unsubscribe", "Transmission.SiftPosition.B")
+ }
+}
diff --git a/app/als-meter-demo.qrc b/app/main.qrc index 4843da7..ad91978 100644 --- a/app/als-meter-demo.qrc +++ b/app/main.qrc @@ -1,11 +1,9 @@ <RCC>
<qresource prefix="/">
- <file>Als-meter-demo.qml</file>
+ <file>main.qml</file>
<file>Speed.qml</file>
<file>Mid.qml</file>
<file>Tacho.qml</file>
- <file>CameraControl.qml</file>
<file>Shift.qml</file>
- <file>MidOther.qml</file>
</qresource>
</RCC>
diff --git a/package/config.xml b/package/config.xml index a8047f7..08fd98c 100644 --- a/package/config.xml +++ b/package/config.xml @@ -1,17 +1,18 @@ <?xml version="1.0" encoding="UTF-8"?> -<widget xmlns="http://www.w3.org/ns/widgets" id="als-meter-demo" version="0.1"> - <name>Als-meter-demo</name> +<widget xmlns="http://www.w3.org/ns/widgets" id="tachometer" version="0.1"> + <name>tachometer</name> <icon src="icon.svg"/> - <content src="bin/als-meter-demo" type="application/vnd.agl.native"/> - <description>This is a steering-wheel binding's demo application</description> + <content src="bin/tachometer" type="application/vnd.agl.native"/> + <description>This is a demo application</description> <author>TOYOTA</author> <license>APL 2.0</license> <feature name="urn:AGL:widget:required-api"> - <param name="steering-wheel" value="ws" /> + <param name="low-can" value="ws" /> <param name="windowmanager" value="ws"/> <param name="homescreen" value="ws"/> </feature> <feature name="urn:AGL:widget:required-permission"> + <param name="urn:AGL:permission::system:run-by-default" value="required"/> <param name="urn:AGL:permission::public:no-htdocs" value="required" /> </feature> </widget> diff --git a/package/package.pro b/package/package.pro index a69111f..491a1b0 100644 --- a/package/package.pro +++ b/package/package.pro @@ -14,6 +14,6 @@ QMAKE_EXTRA_TARGETS += copy_config PRE_TARGETDEPS += $$copy_config.target wgt.target = package -wgt.commands = wgtpkg-pack -f -o als-meter-demo.wgt root +wgt.commands = wgtpkg-pack -f -o tachometer.wgt root QMAKE_EXTRA_TARGETS += wgt diff --git a/sample/als-meter-demo_git.bb b/sample/tachometer_git.bb index 6dffeab..6dffeab 100644 --- a/sample/als-meter-demo_git.bb +++ b/sample/tachometer_git.bb diff --git a/als-meter-demo.pro b/tachometer.pro index 579a952..579a952 100644 --- a/als-meter-demo.pro +++ b/tachometer.pro |