import QtQuick import Felgo import QtMultimedia import QtQuick.Controls import Qt.labs.settings 1.0 as QtLabs import QtQuick.Controls.Material 2.0 import QtLocation 5.5 import QtPositioning 5.5 import Qt5Compat.GraphicalEffects import "../controls" import "../common" import Frames 0.1 AppPage { objectName: "autoFocus_Page" navigationBarHidden: true backgroundColor: app.theme_backgroundColor property var videoFormats // 定义电机状态 property int currentAxis: 0 // 当前选择的轴 (0: X, 1: Y, 2: Z) property var axisPositions: [0, 0, 0] // 各轴当前位置 property int speed: 50 // 当前速度 (0-100) property int stepDistance: 20 // 步进脉冲数量 function autotake(sw){ if(sw) { console.log("autotakestart") frames.camera_sw = true //frames.auto_clicked = true //开始对焦 auto_timer.start() //启动对焦定时器 console.log("相机已打开") photoTimer.interval=600*1000 photoTimer.start() }else{ frames.camera_sw = true console.log("打开相机单次拍照!") } } Frames { objectName: "Frames" id: frames videoSink: output.videoSink onVideoSinkChanged: { console.log("onVideoSinkChanged") photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住 } onQulityStringChanged: { loginpage.logintimeout = 600; //拍照刷新熄屏计时 photoTimer.interval = 600*1000 photoTimer.restart() } onCameraStaChanged: function(sta_cam) { if(sta_cam){ //camera.active = sta_cam //camera.start() loginpage.logintimeout = 600; //拍照刷新熄屏计时 output.visible = sta_cam photoTimer.interval = 600*1000 photoTimer.start() //uvc_camera.visible = false }else{ //camera.active = sta_cam //camera.stop() output.visible= sta_cam photoTimer.stop() //停止计时器 //uvc_camera.visible = true } console.log("相机状态改变",sta_cam) } } Timer { id: photoTimer interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位) running: false // 初始状态下定时器停止 repeat: false // 设置为false,以便只执行一次 onTriggered: { // 定时器触发后,设置按钮可用 // camera.active = false // camera.stop() output.visible = false frames.camera_sw = false } } Timer { id: auto_timer interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位) running: false // 初始状态下定时器停止 repeat: false // 设置为false,以便只执行一次 onTriggered: { // 定时器触发后,开始对焦 frames.auto_clicked = true } } Connections{ target: serial onTakephotodone:{ console.log("立即拍照完成!") apptext_res.text = "立即拍照完成!" focus_switch.enabled = true focus_switch.checked = false } onAutotestdone: { console.log("自动对焦完成!") apptext_res.text = "自动对焦完成!" autotest_switch.enabled = true autotest_switch.checked = false } onTranslatedone: { console.log("胶带传送完成!") apptext_res.text = "胶带传送完成!" jiaodai_switch.enabled = true jiaodai_switch.checked = false } } Row{ anchors.fill: parent spacing: 5 Rectangle { width: parent.width*0.7 height: parent.height color: app.cardColor radius: 5 AppButton { id: normButton //anchors.horizontalCenter: parent.horizontalCenter anchors.centerIn: parent anchors.fill: parent //text: "打开相机" flat: true //边框是否可视 onClicked: { console.log("相机状态:",frames.camera_sw) //if(camera.active){ if(frames.camera_sw){ text = "相机已关闭" output.visible = false frames.camera_sw = false //uvc_camera.visible = false }else{ text = "打开相机" output.visible = true frames.camera_sw = true //uvc_camera.visible = true } } AppImage{ id: image_picdis anchors.centerIn: parent source: "../../assets/photoico.svg" } } // AppImage { // id: uvc_camera // visible: false // anchors.fill: parent // cache: false // source: "image://UCamera" // } VideoOutput { id: output anchors.fill: parent visible: false fillMode: VideoOutput.PreserveAspectFit //根据视频的纵横比例等比例缩放 //fillMode: VideoOutput.Stretch Component.onCompleted: { console.log("output onCompleted") } } Row { AppText { id: photoclarity_text width: parent.width text: frames.fpsString color: "red" } AppText { visible: true//app.photoclarity id: photoclarity2_text anchors.top: photoclarity_text.bottom width: parent.width text: frames.qulityString color: "green" } } } Rectangle { width: parent.width*0.29 height: parent.height color: app.cardColor radius: 5 Rectangle{ id: rec_test anchors.top: text_title.bottom anchors.topMargin: 5 anchors.left: parent.left width: parent.width*0.97 height: parent.height *0.6 border.width: 1 border.color: "white" radius: 5 color: app.cardColor Column { anchors.top: text_title.bottom anchors.left: parent.left anchors.leftMargin: 10 spacing: dp(15) Row { spacing: 80 AppText { id: text_title text: "测试调试" font.bold: true color: "#28a779" fontSize: 20 } AppText { id: apptext_res text: "[测试结果]" fontSize:15 color: "grey" anchors.verticalCenter: text_title.verticalCenter } } Row { spacing: 100 AppText{ text: "一键测试" fontSize: 15 color: app.fontColor //font.bold: true anchors.verticalCenter: autotest_switch.verticalCenter } AppSwitch { id: autotest_switch onToggled: { if(autotest_switch.checked==true){ autotest_switch.enabled = false serial.sendCmd("autotest",true,"",""); } } } } Row { spacing: 100 AppText{ text: "风机测试" color: app.fontColor fontSize: 15 //font.bold: true anchors.verticalCenter: fantest_switch.verticalCenter } AppSwitch { id: fantest_switch onToggled: { if(fantest_switch.checked==true){ serial.sendCmd("fan",true,"",""); apptext_res.text = "打开风机" }else{ serial.sendCmd("fan",false,"",""); apptext_res.text = "关闭风机" } } } } Row { spacing: 100 AppText{ text: "胶带测试" fontSize: 15 color: app.fontColor //font.bold: true anchors.verticalCenter: jiaodai_switch.verticalCenter } AppSwitch { id: jiaodai_switch onToggled: { if(jiaodai_switch.checked==true){ jiaodai_switch.enabled = false apptext_res.text = "胶带测试开始" serial.sendCmd("jiaodai",true,"",""); } } } } Row { spacing: 100 AppText{ text: "补光测试" color: app.fontColor fontSize: 15 //font.bold: true anchors.verticalCenter: led_switch.verticalCenter } AppSwitch { id: led_switch onToggled: { if(led_switch.checked==true){ serial.sendCmd("led",true,"",""); apptext_res.text = "补光灯已打开" }else{ serial.sendCmd("led",false,"",""); apptext_res.text = "补光灯已关闭" } } } } Row { spacing: 100 AppText{ text: "立即拍照" color: app.fontColor fontSize: 15 //font.bold: true anchors.verticalCenter: takephoto_switch.verticalCenter } AppSwitch { id: takephoto_switch onToggled: { if(takephoto_switch.checked==true){ apptext_res.text = "立即拍照" frames.captureImage() } } } } Row { spacing: 100 AppText{ text: "对焦拍照" color: app.fontColor fontSize: 15 //font.bold: true anchors.verticalCenter: focus_switch.verticalCenter } AppSwitch { id: focus_switch onToggled: { if(focus_switch.checked==true){ apptext_res.text = "开始对焦" focus_switch.enabled = false serial.auto_takephoto(true) } } } } AppText { id: text_title2 text: "三轴步进电机控制" font.bold: true color: "#28a779" fontSize: 20 } // 轴选择 Row { spacing: dp(1) width: parent.width AppText { text: "选择轴:" width: dp(60) // 固定文本宽度 anchors.verticalCenter: parent.verticalCenter } ComboBox { width: parent.width - dp(60) // 剩余宽度 model: ["X轴", "Y轴", "Z轴"] onCurrentIndexChanged: currentAxis = currentIndex } } // 速度调节 Row { spacing: dp(2) width: parent.width AppText { text: "速度:" width: dp(40) // 固定文本宽度 anchors.verticalCenter: parent.verticalCenter } AppSlider { width: parent.width - dp(60) // 剩余宽度 from: 0 to: 100 value: speed stepSize: 1 onValueChanged: speed = value anchors.verticalCenter: parent.verticalCenter } AppText { text: speed width: dp(40) // 固定文本宽度 anchors.verticalCenter: parent.verticalCenter } } // 步进距离设置 Row { spacing: dp(10) width: parent.width AppText { text: "步进脉冲次数:" width: dp(120) // 固定文本宽度 anchors.verticalCenter: parent.verticalCenter } AppTextField { width: parent.width - dp(120) // 剩余宽度 text: stepDistance validator: IntValidator { bottom: 0; top: 2000 } onTextChanged: stepDistance = parseInt(text) } } // 运动控制按钮 Row { spacing: dp(10) width: parent.width AppButton { text: " 正转 " textColor: "black" flat: false borderColor: "black" borderWidth: dp(1) backgroundColor: "grey" minimumHeight: dp(30) minimumWidth: dp(50) width: (parent.width - dp(30))/3 // 平均分配宽度 onClicked: { if(currentAxis==0) { console.log("X轴正转:",stepDistance) serial.sendCmd("movx",false,"f"+stepDistance,speed.toString()) }else if(currentAxis==1) { console.log("Y轴正转:",stepDistance) serial.sendCmd("movy",false,"f"+stepDistance,speed.toString()) }else if(currentAxis==2) { console.log("Z轴正转:",stepDistance) serial.sendCmd("movz",false,"f"+stepDistance,speed.toString()) } } } AppButton { text: " 停止 " textColor: "black" flat: false borderColor: "black" borderWidth: dp(1) backgroundColor: "red" minimumHeight: dp(30) minimumWidth: dp(50) width: (parent.width - dp(30))/3 // 平均分配宽度 onClicked: { console.log("停止") serial.sendCmd("movx",false,"f0","") } } AppButton { text: " 反转 " textColor: "black" flat: false borderColor: "black" borderWidth: dp(1) backgroundColor: "grey" minimumHeight: dp(30) minimumWidth: dp(50) width: (parent.width - dp(30))/3 // 平均分配宽度 // property var pressTime: 0 // property bool isLongPress: false // Timer{ // id: longPressTimer // interval: 200 // onTriggered: { // if (myButton.pressed) { // myButton.isLongPress = true // console.log("长按") // 持续按下超过 200ms,打印 // if(currentAxis==0) // { // console.log("X轴反转:",stepDistance) // serial.sendCmd("movx",false,"b1000","0") // }else if(currentAxis==1) // { // console.log("Y轴反转:",stepDistance) // serial.sendCmd("movy",false,"b1000","0") // }else if(currentAxis==2) // { // console.log("Z轴反转:",stepDistance) // serial.sendCmd("movz",false,"b1000","0") // } // } // } // } // onPressed: // { // console.log("反转按钮按下!") //持续200ms后,长时运动 // longPressTimer.start() // 启动定时器 // } // onReleased: // { // console.log("反转按钮释放!") //立即关闭电机驱动 // longPressTimer.stop() // 停止定时器 // if (myButton.isLongPress) { // console.log("0") // 释放时打印 0 // } else { // console.log("1") // 按下时间小于 200ms,打印 1 // } // // 重置状态 // myButton.isLongPress = false // } onClicked: { if(currentAxis==0) { console.log("X轴反转:",stepDistance) serial.sendCmd("movx",false,"b"+stepDistance,speed.toString()) }else if(currentAxis==1) { console.log("Y轴反转:",stepDistance) serial.sendCmd("movy",false,"b"+stepDistance,speed.toString()) }else if(currentAxis==2) { console.log("Z轴反转:",stepDistance) serial.sendCmd("movz",false,"b"+stepDistance,speed.toString()) } } } AppButton { text: " 复位 " textColor: "black" flat: false borderColor: "black" borderWidth: dp(1) backgroundColor: "grey" minimumHeight: dp(30) minimumWidth: dp(50) width: (parent.width - dp(30))/3 // 平均分配宽度 onClicked: { if(currentAxis==0) { console.log("X轴复位!") serial.sendCmd("movx",true,"",speed.toString()) }else if(currentAxis==1) { console.log("Y轴复位!") serial.sendCmd("movy",true,"",speed.toString()) }else if(currentAxis==2) { console.log("Z轴复位!") serial.sendCmd("movz",true,"",speed.toString()) } } } } } } } } }