添加安全帽检测阈值设置。

This commit is contained in:
luocai 2024-12-11 19:05:37 +08:00
parent 7284f18c43
commit 559867bd31
9 changed files with 207 additions and 3 deletions

View File

@ -12,5 +12,7 @@
<file>resources/prompt_delete.svg</file> <file>resources/prompt_delete.svg</file>
<file>resources/successfull.svg</file> <file>resources/successfull.svg</file>
<file>resources/warning.svg</file> <file>resources/warning.svg</file>
<file>qml/MessageBar.qml</file>
<file>qml/Object.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -210,6 +210,21 @@ void Application::setCurrentDeviceRotation(int rotation) {
} }
} }
int Application::currentHelmetThreshold() const {
return m_currentHelmetThreshold;
}
void Application::setCurrentHelmetThreshold(int threshold) {
if (m_currentHelmetThreshold != threshold) {
m_currentHelmetThreshold = threshold;
emit currentHelmetThresholdChanged();
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateHelmetThreshold(threshold);
}
}
}
void Application::updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway, void Application::updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway,
const QString &dns) { const QString &dns) {
if (!m_device.expired()) { if (!m_device.expired()) {
@ -231,6 +246,8 @@ void Application::connectToDevice(int index) {
disconnect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea); disconnect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea);
disconnect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea); disconnect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
disconnect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea); disconnect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
disconnect(device.get(), &DeviceConnection::helmetThresholdChanged, this,
&Application::onDeviceHelmetThreshold);
disconnect(device.get(), &DeviceConnection::networkInfomationChanged, this, disconnect(device.get(), &DeviceConnection::networkInfomationChanged, this,
&Application::onDeviceNetworkInfomation); &Application::onDeviceNetworkInfomation);
disconnect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware); disconnect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware);
@ -255,6 +272,7 @@ void Application::connectToDevice(int index) {
connect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea); connect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea);
connect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea); connect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
connect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea); connect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
connect(device.get(), &DeviceConnection::helmetThresholdChanged, this, &Application::onDeviceHelmetThreshold);
connect(device.get(), &DeviceConnection::networkInfomationChanged, this, connect(device.get(), &DeviceConnection::networkInfomationChanged, this,
&Application::onDeviceNetworkInfomation); &Application::onDeviceNetworkInfomation);
connect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware); connect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware);
@ -283,6 +301,7 @@ void Application::connectToDevice(int index) {
m_currentDeviceConnected = device->isConnected(); m_currentDeviceConnected = device->isConnected();
m_currentDeviceFlip = info.flip; m_currentDeviceFlip = info.flip;
m_currentDeviceRotation = info.rotation; m_currentDeviceRotation = info.rotation;
m_currentHelmetThreshold = info.helmetThreshold;
emit currentDeviceRotationChanged(); emit currentDeviceRotationChanged();
emit currentDeviceFlipChanged(); emit currentDeviceFlipChanged();
emit currentOpenDoorAreaPointsChanged(); emit currentOpenDoorAreaPointsChanged();
@ -292,6 +311,7 @@ void Application::connectToDevice(int index) {
emit currentShieldedAreaEnabledChanged(); emit currentShieldedAreaEnabledChanged();
emit currentAntiClipAreaEnabledChanged(); emit currentAntiClipAreaEnabledChanged();
emit currentAntiClipSensitivityChanged(); emit currentAntiClipSensitivityChanged();
emit currentHelmetThresholdChanged();
emit currentNetworkInfomationChanged(); emit currentNetworkInfomationChanged();
} }
emit currentFirmwareChanged(); emit currentFirmwareChanged();
@ -358,6 +378,10 @@ void Application::onDeviceAntiClipArea(bool enabled, const QList<QPointF> &point
setCurrentAntiClipSensitivity(sensitivity); setCurrentAntiClipSensitivity(sensitivity);
} }
void Application::onDeviceHelmetThreshold(int threshold) {
setCurrentHelmetThreshold(threshold);
}
void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) { void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) {
m_currentNetworkInfomation = info; m_currentNetworkInfomation = info;
emit currentNetworkInfomationChanged(); emit currentNetworkInfomationChanged();

View File

@ -35,6 +35,8 @@ class Application : public QObject {
Q_PROPERTY(bool currentAntiClipAreaEnabled READ currentAntiClipAreaEnabled WRITE setCurrentAntiClipAreaEnabled Q_PROPERTY(bool currentAntiClipAreaEnabled READ currentAntiClipAreaEnabled WRITE setCurrentAntiClipAreaEnabled
NOTIFY currentAntiClipAreaEnabledChanged) NOTIFY currentAntiClipAreaEnabledChanged)
Q_PROPERTY(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged) Q_PROPERTY(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged)
Q_PROPERTY(int currentHelmetThreshold READ currentHelmetThreshold WRITE setCurrentHelmetThreshold NOTIFY
currentHelmetThresholdChanged)
Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE
setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged) setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged)
Q_PROPERTY( Q_PROPERTY(
@ -77,6 +79,9 @@ public:
int currentDeviceRotation() const; int currentDeviceRotation() const;
void setCurrentDeviceRotation(int rotation); void setCurrentDeviceRotation(int rotation);
int currentHelmetThreshold() const;
void setCurrentHelmetThreshold(int threshold);
Q_INVOKABLE void updateOpenDoorAreaPoints(const QList<QPointF> &points); Q_INVOKABLE void updateOpenDoorAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateAntiClipAreaPoints(const QList<QPointF> &points); Q_INVOKABLE void updateAntiClipAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateShieldedAreaPoints(const QList<QPointF> &points); Q_INVOKABLE void updateShieldedAreaPoints(const QList<QPointF> &points);
@ -99,6 +104,7 @@ signals:
void currentShieldedAreaEnabledChanged(); void currentShieldedAreaEnabledChanged();
void currentAntiClipAreaEnabledChanged(); void currentAntiClipAreaEnabledChanged();
void currentAntiClipSensitivityChanged(); void currentAntiClipSensitivityChanged();
void currentHelmetThresholdChanged();
void currentNetworkInfomationChanged(); void currentNetworkInfomationChanged();
void currentFirmwareChanged(); void currentFirmwareChanged();
void currentDeviceConnectedChanged(); void currentDeviceConnectedChanged();
@ -114,6 +120,7 @@ protected:
void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points); void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points);
void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points); void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points);
void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity); void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity);
void onDeviceHelmetThreshold(int threshold);
void onDeviceNetworkInfomation(const NetworkInfomation &info); void onDeviceNetworkInfomation(const NetworkInfomation &info);
void onDeviceFirmware(const QString &firmware); void onDeviceFirmware(const QString &firmware);
void onDeviceConnected(); void onDeviceConnected();
@ -140,6 +147,7 @@ private:
bool m_currentDeviceConnected = false; bool m_currentDeviceConnected = false;
bool m_currentDeviceFlip = false; bool m_currentDeviceFlip = false;
int m_currentDeviceRotation = 0; int m_currentDeviceRotation = 0;
int m_currentHelmetThreshold = 1;
}; };
#endif // APPLICATION_H #endif // APPLICATION_H

View File

@ -240,6 +240,45 @@ void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList<QPoint
m_requests.push(task); m_requests.push(task);
} }
void DeviceConnection::updateHelmetThreshold(int threshold) {
constexpr auto command = "thresholdwithhat_setdata";
Task task;
task.command = command;
task.task = [this, threshold, command]() {
boost::json::object request;
request["func"] = command;
request["deviceid"] = "0";
boost::json::object data;
data["value"] = threshold;
request["data"] = std::move(data);
auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size());
};
if (m_requests.empty()) {
task.task();
}
m_requests.push(task);
}
void DeviceConnection::requestHelmetThreshold() {
constexpr auto command = "thresholdwithhat_getdata";
Task task;
task.command = command;
task.task = [this, command]() {
boost::json::object request;
request["func"] = command;
request["deviceid"] = "0";
boost::json::object data;
request["data"] = std::move(data);
auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size());
};
if (m_requests.empty()) {
task.task();
}
m_requests.push(task);
}
void DeviceConnection::requestResolution(Resolution resolution) { void DeviceConnection::requestResolution(Resolution resolution) {
Task task; Task task;
task.command = "quality_setdata"; task.command = "quality_setdata";
@ -697,6 +736,11 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
requestVideoInformation(); requestVideoInformation();
} else if (function == "a12factory_setdata") { } else if (function == "a12factory_setdata") {
LOG(info) << "device factory reset"; LOG(info) << "device factory reset";
} else if (function == "thresholdwithhat_getdata") {
auto &data = reply.at("data").as_object();
auto &value = data.at("value").as_int64();
m_infomation.helmetThreshold = value;
emit helmetThresholdChanged(m_infomation.helmetThreshold);
} else { } else {
LOG(warning) << "unknown reply: " << replyText; LOG(warning) << "unknown reply: " << replyText;
} }

View File

@ -48,6 +48,7 @@ public:
QList<QPointF> antiClipArea; QList<QPointF> antiClipArea;
bool antiClipAreaEnabled; bool antiClipAreaEnabled;
int antiClipSensitivity = 1; int antiClipSensitivity = 1;
int helmetThreshold = 1;
}; };
Q_ENUM(AreaWay) Q_ENUM(AreaWay)
@ -71,6 +72,8 @@ public:
void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points, int sensitivity); void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points, int sensitivity);
void requestResolution(Resolution resolution); void requestResolution(Resolution resolution);
void requestNetworkInfomation(); void requestNetworkInfomation();
void updateHelmetThreshold(int threshold);
void requestHelmetThreshold();
QFuture<bool> updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway, QFuture<bool> updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway,
const QString &dns); const QString &dns);
void requestVersion(); void requestVersion();
@ -98,6 +101,7 @@ signals:
void antiClipAreaChanged(bool enabled, const QList<QPointF> &points, int sensitivity); void antiClipAreaChanged(bool enabled, const QList<QPointF> &points, int sensitivity);
void rotationChanged(int rotation); void rotationChanged(int rotation);
void flipChanged(bool flip); void flipChanged(bool flip);
void helmetThresholdChanged(int threshold);
void networkInfomationChanged(const NetworkInfomation &info); void networkInfomationChanged(const NetworkInfomation &info);
void firmwareChanged(const QString &firmware); void firmwareChanged(const QString &firmware);
void otaProgressChanged(bool status, int progress, const QString &message); void otaProgressChanged(bool status, int progress, const QString &message);

View File

@ -247,13 +247,13 @@ Item {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
columns: 4 columns: 6
Label { text: qsTr("图像: ") } Label { text: qsTr("图像: ") }
Row { Row {
enabled: root.enabled enabled: root.enabled
Layout.columnSpan: 3 Layout.columnSpan: 5
Label { Label {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: qsTr("旋转") text: qsTr("旋转")
@ -283,7 +283,7 @@ Item {
} }
Row { Row {
enabled: root.enabled enabled: root.enabled
Layout.columnSpan: 3 Layout.columnSpan: 5
RadioButton { RadioButton {
text: "关闭" text: "关闭"
checked: App.currentOpenDoorAreaWay ==DeviceConnection.Diabled checked: App.currentOpenDoorAreaWay ==DeviceConnection.Diabled
@ -343,6 +343,14 @@ Item {
} }
} }
Label { text: qsTr("安全帽灵敏度: ")
Layout.alignment: Qt.AlignRight
}
TextField {
enabled: root.enabled
Layout.alignment: Qt.AlignLeft
}
Label {text: qsTr("屏蔽区域: ")} Label {text: qsTr("屏蔽区域: ")}
Row { Row {
id: shieldedRow id: shieldedRow

View File

@ -195,6 +195,14 @@ ApplicationWindow {
spacing: (parent.width - (2 * 100)) / 3 spacing: (parent.width - (2 * 100)) / 3
} }
MessageBar {
id: messageBar
root: window.contentItem
}
function showSuccess(text,duration){
return messageBar.showSuccess(text,duration)
}
function showMessageDialog(type, title, message, callback) { function showMessageDialog(type, title, message, callback) {
let component = Qt.createComponent("MessageDialog.qml") let component = Qt.createComponent("MessageDialog.qml")
if (component.status === Component.Ready) { if (component.status === Component.Ready) {

101
qml/MessageBar.qml Normal file
View File

@ -0,0 +1,101 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
Object {
id: control
property var root
property var screenLayout: null
property int layoutY: 75
function showSuccess(text,duration=1000){
return create("success",text,duration)
}
function create(type,text,duration){
if(screenLayout){
let last = screenLayout.getLastloader()
if(last.type === type && last.text === text){
last.duration = duration
if (duration > 0) last.restart()
return last
}
} else {
initScreenLayout()
}
return contentComponent.createObject(screenLayout,{type:type,text:text,duration:duration,})
}
function initScreenLayout() {
if(control.screenLayout == null) {
control.screenLayout = screenLayoutComponent.createObject(root)
screenLayout.y = control.layoutY
screenLayout.z = 100000
}
}
Component {
id:contentComponent
Rectangle {
id: content
property int duration: 1500
property string type
property alias text: message.text
color: "#EBF8ED"
radius: 3.2
border.width: 1
border.color: Qt.darker(content.color)
layer.enabled: true
x:(parent.width - width) / 2
width: 200
height: 32
Row {
anchors.fill: parent
Image {
width: 32
height: 32
fillMode: Image.Pad
source: "qrc:/qt/qml/AntiClipSettings/resources/successfull.svg"
anchors.verticalCenter: parent.verticalCenter
}
Label {
id: message
anchors.verticalCenter: parent.verticalCenter
}
}
Timer {
id:delayTimer
interval: duration
running: duration > 0
repeat: duration > 0
onTriggered: content.close()
}
function close(){
content.destroy()
}
}
}
Component {
id:screenLayoutComponent
Column{
parent: Overlay.overlay
z:999
spacing: 5
width: root.width
move: Transition {
NumberAnimation {
properties: "y"
easing.type: Easing.InOutQuad
duration: 167
}
}
onChildrenChanged: if(children.length === 0) destroy()
function getLastloader(){
if(children.length > 0){
return children[children.length - 1]
}
return null
}
}
}
}

5
qml/Object.qml Normal file
View File

@ -0,0 +1,5 @@
import QtQml 2.15
QtObject {
default property list<QtObject> children
}