diff options
Diffstat (limited to 'app/Hudtbt.qml')
-rw-r--r-- | app/Hudtbt.qml | 196 |
1 files changed, 182 insertions, 14 deletions
diff --git a/app/Hudtbt.qml b/app/Hudtbt.qml index 8d26719..6f3458b 100644 --- a/app/Hudtbt.qml +++ b/app/Hudtbt.qml @@ -15,30 +15,46 @@ * limitations under the License. */ +//import QtQuick 2.6 +//import QtQuick.Window 2.2 +//import QtQuick.Layouts 1.1 +//import QtQuick.Controls 1.4 +//import QtWebSockets 1.0 import QtQuick 2.6 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.0 import QtWebSockets 1.0 +import QtQuick.Controls.Styles 1.4 ApplicationWindow { id: window title: "HUD Tbt Demo" - width: 1920 - height: 1080 + width: 1024 + height: 768 visible: true property string api_str: "naviapi" property string verb_subscribe: "subscribe" property string verb_getcurretdirstate: "navicore_getcurrentdestdir" + property string verb_getcurretdistance: "navicore_getcurrentdistance" + property string verb_getcurrentguidancestate: "navicore_getcurrentguidancestate" property string event_getdestdir: "naviapi/navicore_getdestdir" + property string event_getdistance: "naviapi/navicore_getdistance" property string event_cancelguidance: "naviapi/navicore_cancelguidance" - property string nodirection_str:"0" + property string event_startguidance: "naviapi/navicore_startguidance" + + property string park_str:"13" property string arrivedirection_str:"12" + property string cancelguidance_str:"false" + property string startguidance_str:"true" property var msgid_enu: { "call":2, "retok":3, "reterr":4, "event":5 } property string request_str: "" property string status_str: "" + property real val: 0 + property int total_distance: 0 + property int cumulative_distance: 0 property double state: 0 WebSocket { @@ -51,9 +67,12 @@ ApplicationWindow { websocket.active = false }else if (websocket.status === WebSocket.Open){ console.log ("Socket Open") - do_getcurrentdirstate() + do_getcurrentguidancestate() do_subscribe("getdestdir") do_subscribe("cancelguidance") + do_subscribe("getdistance") + do_subscribe("startguidance") + subscribe_timer.start() }else if (websocket.status === WebSocket.Closed){ console.log ("Socket closed") } @@ -61,8 +80,8 @@ ApplicationWindow { onTextMessageReceived: { var message_json = JSON.parse(message) - console.log ("Raw response: " + message) - console.log ("JSON response: " + message_json) + // console.log ("Raw response: " + message) + // console.log ("JSON response: " + message_json) if (message_json[0] === msgid_enu.event){ @@ -70,26 +89,66 @@ ApplicationWindow { { var state = message_json[2].data.state tbt_board.state = state - console.log ("state is ok !") + // console.log ("state is ok !dirstate="+state) if (tbt_board.state === arrivedirection_str) { clear_timer.start() - console.log ("clear arrive direction state 12 is ok !") + // console.log ("clear arrive direction state 12 is ok !") } } + else if(message_json[2].event === event_getdistance) + { + var totaldistance = message_json[2].data.totaldistance + var cumulativedistance = message_json[2].data.cumulativedistance + setProgress(totaldistance,cumulativedistance) + // console.log ("getdistance is ok !totaldistance="+totaldistance+"cumulativedistance="+cumulativedistance) + } else if(message_json[2].event === event_cancelguidance) { - tbt_board.state = nodirection_str + console.log ("cancelguidance !") + distanceBar.visible = false + totalDistance.visible = false + val = 0 + total_distance = 0 + cumulative_distance = 0 + setProgress(total_distance,cumulative_distance) + tbt_board.state = park_str + } + else if(message_json[2].event === event_startguidance) + { + console.log ("startguidance !") + distanceBar.visible = true + totalDistance.visible = true } } else if(message_json[0] === msgid_enu.retok){ if (message_json[2].request.info === verb_getcurretdirstate){ var currentdirstate = message_json[2].response[0].CurrentDirState tbt_board.state = currentdirstate - console.log ("get current state is ok !") + // console.log ("get current state is ok !currentdirstate="+currentdirstate) + } + else if (message_json[2].request.info === verb_getcurretdistance){ + var currenttotaldistance = message_json[2].response[0].CurrentTotalDistance + var currentcumulativedistance = message_json[2].response[0].CurrentCumulativeDistance + setProgress(currenttotaldistance,currenttotaldistance) + // console.log ("get current distance is ok !currenttotaldistance:"+currenttotaldistance+"currentcumulativedistance:"+currentcumulativedistance) + } + else if (message_json[2].request.info === verb_getcurrentguidancestate){ + var currentguidancestate = message_json[2].response[0].CurrentGuidanceState + if (currentguidancestate === startguidance_str) + { + distanceBar.visible = true + totalDistance.visible = true + do_getcurrentdirstate() + do_getcurrentdistance() + } + else + { + tbt_board.state = park_str + } + // console.log ("get current guidance state is ok !currentguidancestate="+currentguidancestate) } } - else{ if (message_json[0] !== msgid_enu.retok) { console.log ("Return value is not ok !") @@ -107,27 +166,136 @@ ApplicationWindow { websocket.sendTextMessage (request_str) } + //get current total distance and cumulative distance + function do_getcurrentdistance() { + request_str = '[' + msgid_enu.call + ',"99999","' + api_str+'/'+verb_getcurretdistance + '", {} ]' + console.log (request_str) + websocket.sendTextMessage (request_str) + + } + //get current guidance state + function do_getcurrentguidancestate() { + request_str = '[' + msgid_enu.call + ',"99999","' + api_str+'/'+verb_getcurrentguidancestate + '", {} ]' + console.log (request_str) + websocket.sendTextMessage (request_str) + + } //subscribe function do_subscribe( event ) { request_str = '[' + msgid_enu.call + ',"99999","' + api_str+'/'+verb_subscribe + '", {"value":"' + event + '"} ]' console.log (request_str) websocket.sendTextMessage (request_str) } + //set distance + function setProgress(totaldistance,cumulativedistance) { + if (totaldistance === 0 && cumulativedistance === 0){ + val = 0 + total_distance = totaldistance + totalDistance.setTotalDistance(total_distance/1000) + }else{ + total_distance = totaldistance + cumulative_distance = cumulativedistance + totalDistance.setTotalDistance(total_distance/1000) + val = ((total_distance + 60)-cumulative_distance)/(total_distance + 60) + } + if ( (bar.from <= val) && (val < bar.to ) ) { + bar.value = val + } + else if ( bar.to < val ){ + bar.value = bar.to + } + // console.log ("setdistanceok! totalDistance:"+total_distance+"bar.value:"+val) + + } TbtBoard { id: tbt_board - z: 1 visible: true anchors.fill: parent } + + + Image { + id: distanceBar + width: 280 + height: 110 + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + anchors.verticalCenterOffset: 65 + source: "qrc:distance_meter.png" + visible: false + Item { + width: 168 + height: 20 + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + + ProgressBar { + id: bar + anchors.fill: parent + + LayoutMirroring.enabled: true + LayoutMirroring.childrenInherit: true + value: 0.0 + from: 0.0 + to: 1.0 + + background: Rectangle { + radius: 2 + color: "#111111" + implicitWidth: 200 + implicitHeight: 24 + } + + contentItem: Rectangle { + anchors.left: bar.left + anchors.verticalCenter:bar.verticalCenter + width: (1.0 - bar.visualPosition) * bar.width + height: bar.height / 2 + color: "#00ff00" + } + } + } + + TotalDistance { + id: totalDistance + width: 30 + visible: false + anchors.verticalCenter: parent.verticalCenter + anchors.verticalCenterOffset: -10 + anchors.right: parent.right + anchors.rightMargin: 60 + } + } + Timer { id: clear_timer repeat: false interval: 5000 triggeredOnStart: false onTriggered: { - tbt_board.state = nodirection_str + tbt_board.state = park_str + val = 0 + total_distance = 0 + cumulative_distance = 0 + setProgress(total_distance,cumulative_distance) + distanceBar.visible = false + totalDistance.visible = false + } + } + Timer { + id: subscribe_timer + repeat: false + interval: 2000 + triggeredOnStart: false + onTriggered: { + console.log ("subscribe again") + do_getcurrentguidancestate() + do_subscribe("getdestdir") + do_subscribe("cancelguidance") + do_subscribe("getdistance") + do_subscribe("startguidance") } } - } |