diff --git a/AntiClipSettings.qrc b/AntiClipSettings.qrc
index 7d996ed..6e08a90 100644
--- a/AntiClipSettings.qrc
+++ b/AntiClipSettings.qrc
@@ -12,5 +12,7 @@
resources/prompt_delete.svg
resources/successfull.svg
resources/warning.svg
+ qml/MessageBar.qml
+ qml/Object.qml
diff --git a/Application.cpp b/Application.cpp
index 5747c09..1f90714 100644
--- a/Application.cpp
+++ b/Application.cpp
@@ -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,
const QString &dns) {
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::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
disconnect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
+ disconnect(device.get(), &DeviceConnection::helmetThresholdChanged, this,
+ &Application::onDeviceHelmetThreshold);
disconnect(device.get(), &DeviceConnection::networkInfomationChanged, this,
&Application::onDeviceNetworkInfomation);
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::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
connect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
+ connect(device.get(), &DeviceConnection::helmetThresholdChanged, this, &Application::onDeviceHelmetThreshold);
connect(device.get(), &DeviceConnection::networkInfomationChanged, this,
&Application::onDeviceNetworkInfomation);
connect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware);
@@ -283,6 +301,7 @@ void Application::connectToDevice(int index) {
m_currentDeviceConnected = device->isConnected();
m_currentDeviceFlip = info.flip;
m_currentDeviceRotation = info.rotation;
+ m_currentHelmetThreshold = info.helmetThreshold;
emit currentDeviceRotationChanged();
emit currentDeviceFlipChanged();
emit currentOpenDoorAreaPointsChanged();
@@ -292,6 +311,7 @@ void Application::connectToDevice(int index) {
emit currentShieldedAreaEnabledChanged();
emit currentAntiClipAreaEnabledChanged();
emit currentAntiClipSensitivityChanged();
+ emit currentHelmetThresholdChanged();
emit currentNetworkInfomationChanged();
}
emit currentFirmwareChanged();
@@ -358,6 +378,10 @@ void Application::onDeviceAntiClipArea(bool enabled, const QList &point
setCurrentAntiClipSensitivity(sensitivity);
}
+void Application::onDeviceHelmetThreshold(int threshold) {
+ setCurrentHelmetThreshold(threshold);
+}
+
void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) {
m_currentNetworkInfomation = info;
emit currentNetworkInfomationChanged();
diff --git a/Application.h b/Application.h
index 0b8cf0d..59e961e 100644
--- a/Application.h
+++ b/Application.h
@@ -35,6 +35,8 @@ class Application : public QObject {
Q_PROPERTY(bool currentAntiClipAreaEnabled READ currentAntiClipAreaEnabled WRITE setCurrentAntiClipAreaEnabled
NOTIFY currentAntiClipAreaEnabledChanged)
Q_PROPERTY(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged)
+ Q_PROPERTY(int currentHelmetThreshold READ currentHelmetThreshold WRITE setCurrentHelmetThreshold NOTIFY
+ currentHelmetThresholdChanged)
Q_PROPERTY(QList currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE
setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged)
Q_PROPERTY(
@@ -77,6 +79,9 @@ public:
int currentDeviceRotation() const;
void setCurrentDeviceRotation(int rotation);
+ int currentHelmetThreshold() const;
+ void setCurrentHelmetThreshold(int threshold);
+
Q_INVOKABLE void updateOpenDoorAreaPoints(const QList &points);
Q_INVOKABLE void updateAntiClipAreaPoints(const QList &points);
Q_INVOKABLE void updateShieldedAreaPoints(const QList &points);
@@ -99,6 +104,7 @@ signals:
void currentShieldedAreaEnabledChanged();
void currentAntiClipAreaEnabledChanged();
void currentAntiClipSensitivityChanged();
+ void currentHelmetThresholdChanged();
void currentNetworkInfomationChanged();
void currentFirmwareChanged();
void currentDeviceConnectedChanged();
@@ -114,6 +120,7 @@ protected:
void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList &points);
void onDeviceShieldedArea(bool enabled, const QList &points);
void onDeviceAntiClipArea(bool enabled, const QList &points, int sensitivity);
+ void onDeviceHelmetThreshold(int threshold);
void onDeviceNetworkInfomation(const NetworkInfomation &info);
void onDeviceFirmware(const QString &firmware);
void onDeviceConnected();
@@ -140,6 +147,7 @@ private:
bool m_currentDeviceConnected = false;
bool m_currentDeviceFlip = false;
int m_currentDeviceRotation = 0;
+ int m_currentHelmetThreshold = 1;
};
#endif // APPLICATION_H
diff --git a/DeviceConnection.cpp b/DeviceConnection.cpp
index 7ea3379..95a04f2 100644
--- a/DeviceConnection.cpp
+++ b/DeviceConnection.cpp
@@ -240,6 +240,45 @@ void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QListwrite(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) {
Task task;
task.command = "quality_setdata";
@@ -697,6 +736,11 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
requestVideoInformation();
} else if (function == "a12factory_setdata") {
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 {
LOG(warning) << "unknown reply: " << replyText;
}
diff --git a/DeviceConnection.h b/DeviceConnection.h
index 9cbc028..71e28e9 100644
--- a/DeviceConnection.h
+++ b/DeviceConnection.h
@@ -48,6 +48,7 @@ public:
QList antiClipArea;
bool antiClipAreaEnabled;
int antiClipSensitivity = 1;
+ int helmetThreshold = 1;
};
Q_ENUM(AreaWay)
@@ -71,6 +72,8 @@ public:
void updateAntiClipAreaPoints(bool enabled, const QList &points, int sensitivity);
void requestResolution(Resolution resolution);
void requestNetworkInfomation();
+ void updateHelmetThreshold(int threshold);
+ void requestHelmetThreshold();
QFuture updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway,
const QString &dns);
void requestVersion();
@@ -98,6 +101,7 @@ signals:
void antiClipAreaChanged(bool enabled, const QList &points, int sensitivity);
void rotationChanged(int rotation);
void flipChanged(bool flip);
+ void helmetThresholdChanged(int threshold);
void networkInfomationChanged(const NetworkInfomation &info);
void firmwareChanged(const QString &firmware);
void otaProgressChanged(bool status, int progress, const QString &message);
diff --git a/qml/DeviceView.qml b/qml/DeviceView.qml
index 9e785d5..cf4204d 100644
--- a/qml/DeviceView.qml
+++ b/qml/DeviceView.qml
@@ -247,13 +247,13 @@ Item {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
- columns: 4
+ columns: 6
Label { text: qsTr("图像: ") }
Row {
enabled: root.enabled
- Layout.columnSpan: 3
+ Layout.columnSpan: 5
Label {
anchors.verticalCenter: parent.verticalCenter
text: qsTr("旋转")
@@ -283,7 +283,7 @@ Item {
}
Row {
enabled: root.enabled
- Layout.columnSpan: 3
+ Layout.columnSpan: 5
RadioButton {
text: "关闭"
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("屏蔽区域: ")}
Row {
id: shieldedRow
diff --git a/qml/Main.qml b/qml/Main.qml
index aae2e76..3f7feb4 100644
--- a/qml/Main.qml
+++ b/qml/Main.qml
@@ -195,6 +195,14 @@ ApplicationWindow {
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) {
let component = Qt.createComponent("MessageDialog.qml")
if (component.status === Component.Ready) {
diff --git a/qml/MessageBar.qml b/qml/MessageBar.qml
new file mode 100644
index 0000000..575d5a7
--- /dev/null
+++ b/qml/MessageBar.qml
@@ -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
+ }
+ }
+ }
+}
diff --git a/qml/Object.qml b/qml/Object.qml
new file mode 100644
index 0000000..e45b8b3
--- /dev/null
+++ b/qml/Object.qml
@@ -0,0 +1,5 @@
+import QtQml 2.15
+
+QtObject {
+ default property list children
+}