From dbe7c1a64e3acbf58d32ec208d4faf6743e8dadf Mon Sep 17 00:00:00 2001 From: luocai Date: Thu, 12 Dec 2024 18:49:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=AE=89=E5=85=A8=E5=B8=BD?= =?UTF-8?q?=E9=98=88=E5=80=BC=E4=B8=8B=E5=8F=91=E6=8E=A7=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DeviceConnection.cpp | 16 +++++++++++++++- DeviceConnection.h | 2 +- qml/DeviceView.qml | 16 +++++++++++++++- qml/Main.qml | 4 +++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/DeviceConnection.cpp b/DeviceConnection.cpp index 95a04f2..a05729a 100644 --- a/DeviceConnection.cpp +++ b/DeviceConnection.cpp @@ -240,7 +240,7 @@ void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList DeviceConnection::updateHelmetThreshold(int threshold) { constexpr auto command = "thresholdwithhat_setdata"; Task task; task.command = command; @@ -254,10 +254,13 @@ void DeviceConnection::updateHelmetThreshold(int threshold) { auto text = boost::json::serialize(request); m_commandSocket->write(text.data(), text.size()); }; + task.future = std::make_shared>(); if (m_requests.empty()) { task.task(); } + auto ret = task.future->future(); m_requests.push(task); + return ret; } void DeviceConnection::requestHelmetThreshold() { @@ -741,6 +744,16 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const auto &value = data.at("value").as_int64(); m_infomation.helmetThreshold = value; emit helmetThresholdChanged(m_infomation.helmetThreshold); + } else if (function == "thresholdwithhat_setdata") { + if ((task != nullptr) && (task->command.toStdString() == function)) { + if (task->timeoutTimer) { + task->timeoutTimer->stop(); + } + bool status = true; + if (task->future) { + task->future->reportFinished(&status); + } + } } else { LOG(warning) << "unknown reply: " << replyText; } @@ -756,6 +769,7 @@ void DeviceConnection::onConnected() { requestAntiClipArea(); requestNetworkInfomation(); requestVideoInformation(); + requestHelmetThreshold(); emit connected(); m_heartbeatTimerId = startTimer(2500); if (m_otaProgress == 99) { diff --git a/DeviceConnection.h b/DeviceConnection.h index 71e28e9..af15c3c 100644 --- a/DeviceConnection.h +++ b/DeviceConnection.h @@ -72,7 +72,7 @@ public: void updateAntiClipAreaPoints(bool enabled, const QList &points, int sensitivity); void requestResolution(Resolution resolution); void requestNetworkInfomation(); - void updateHelmetThreshold(int threshold); + QFuture updateHelmetThreshold(int threshold); void requestHelmetThreshold(); QFuture updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway, const QString &dns); diff --git a/qml/DeviceView.qml b/qml/DeviceView.qml index cf4204d..d3f8977 100644 --- a/qml/DeviceView.qml +++ b/qml/DeviceView.qml @@ -17,6 +17,7 @@ Item { property var antiClipAreaPoints: [] property bool antiClipAreaEnabled: false property int antiClipSensitivity: 1 + property alias helmetThreshold: helmetInput.text property alias flip: flipSwitch.checked property alias videoRotation: rotateComboBox.currentIndex @@ -335,6 +336,7 @@ Item { ComboBox { id: antiClipSensitivityComboBox enabled: root.enabled + implicitWidth: 60 Layout.alignment: Qt.AlignLeft model: [1,2,3,4,5] currentIndex: root.antiClipSensitivity-1 @@ -343,12 +345,24 @@ Item { } } - Label { text: qsTr("安全帽灵敏度: ") + Label { text: qsTr("安全帽阈值: ") Layout.alignment: Qt.AlignRight } TextField { + id: helmetInput enabled: root.enabled + implicitWidth: 60 Layout.alignment: Qt.AlignLeft + validator: IntValidator { + bottom: 0 + top: 300 + } + onAccepted: { + if(App.currentHelmetThreshold !== parseInt(helmetInput.text)){ + App.currentHelmetThreshold= parseInt(helmetInput.text) + window.showSuccess("设置成功",2500) + } + } } Label {text: qsTr("屏蔽区域: ")} diff --git a/qml/Main.qml b/qml/Main.qml index 3f7feb4..1074da3 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -48,7 +48,8 @@ ApplicationWindow { id: emptyHint visible: false anchors.centerIn: parent - text: qsTr("未搜索到设备") + horizontalAlignment: Text.AlignHCenter + text: qsTr("未搜索到设备\n请尝试关闭Windows防火墙后再重试") } delegate: Rectangle { width: deviceList.width @@ -120,6 +121,7 @@ ApplicationWindow { antiClipAreaEnabled: App.currentAntiClipAreaEnabled antiClipSensitivity: App.currentAntiClipSensitivity antiClipAreaPoints: App.currentAntiClipAreaPoints + helmetThreshold: App.currentHelmetThreshold flip: App.currentDeviceFlip videoRotation: App.currentDeviceRotation }