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 // 步进脉冲数量 property string fExposureTime: "0" function autotake(sw){ if(sw) { console.log("autotakestart") frames.camera_sw = true //frames.auto_clicked = true //开始对焦 auto_timer.start() //启动对焦定时器 console.log("相机已打开") photoTimer.interval=60*1000 photoTimer.start() }else{ frames.camera_sw = true console.log("打开相机单次拍照!") } } Frames { objectName: "Frames" id: frames videoSink: output.videoSink onCameraOpenFailed:function(err){ console.log("onCameraOpenFailed",err) nativeUtils.displayMessageBox("相机打开失败!",err,1) focus_switch.checked = false focus_switch.enabled = true takephoto_switch.checked = false takephoto_switch.enabled = true } onVideoSinkChanged: { console.log("onVideoSinkChanged") photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住 } onQulityStringChanged: { loginpage.logintimeout = 600; //拍照刷新熄屏计时 photoTimer.interval = 180*1000 //3分钟超时 photoTimer.restart() } onCameraStaChanged: function(sta_cam) { if(sta_cam){ //camera.active = sta_cam //camera.start() loginpage.logintimeout = 600; //拍照刷新熄屏计时 output.visible = sta_cam photoTimer.interval = 180*1000 //3分钟超时 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) } onStepCountChanged: function(step){ console.log("坐标改变",step) step_apptextfield.text = step } onExposureTimeChanged: { fExposureTime = frames.cam_ExposureTime } } 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 } } SplitView{ anchors.fill: parent orientation: Qt.Horizontal Rectangle { SplitView.preferredWidth: 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 } } Timer { id: longPressTimer interval: 1000 // 长按时间1000ms running: false // 初始状态下定时器停止 repeat: false // 设置为false,以便只执行一次 onTriggered: { console.log("长按触发") } } onPressed: { console.log("按钮按下,开始计时") longPressTimer.start() } onReleased: { console.log("按钮释放,停止计时") longPressTimer.stop() } AppImage{ id: image_picdis anchors.centerIn: parent source: "../../assets/photoico.svg" } } 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" } } } ScrollView { SplitView.preferredWidth: parent.width*0.29 SplitView.minimumWidth: 200 clip: true Column { 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,"",""); t_autotest.start() }else{ console.log("t_autotest 计数:",t_autotest.interval) } } } Timer { id: t_autotest interval: 1000*60 running: false repeat: false onTriggered: { autotest_switch.enabled = true autotest_switch.checked = false } } } 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) // 剩余宽度 height: dp(40) model: ["X轴", "Y轴", "Z轴"] onCurrentIndexChanged: currentAxis = currentIndex } AppButton{ text: "校准" textColor: "black" flat: false borderColor: "black" borderWidth: dp(1) backgroundColor: "white" minimumHeight: dp(30) minimumWidth: dp(50) onClicked: { autotake(false) if(currentAxis==0) { console.log("校准X") serial.sendCmd("calibrate",false,"x",speed.toString()) }else if(currentAxis==1) { console.log("校准Y") serial.sendCmd("calibrate",false,"y",speed.toString()) }else if(currentAxis==2) { console.log("校准Z") serial.sendCmd("calibrate",false,"z",speed.toString()) } } } } // 速度调节 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 { id: step_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 // 平均分配宽度 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()) } } } } AppText { id: text_camera text: "相机参数" font.bold: true color: "#28a779" fontSize: 20 } Row { spacing: dp(10) width: parent.width AppText { id: txt_fExposureTime text: "曝光值:" } AppTextField { anchors.verticalCenter: txt_fExposureTime.verticalCenter placeholderText: fExposureTime text: fExposureTime width: parent.width - dp(10) // 剩余宽度 EnterKey.type: Qt.EnterKeyDone wrapMode: Text.NoWrap inputMethodHints: Qt.ImhFormattedNumbersOnly | Qt.ImhPreferDone | Qt.ImhNoPredictiveText validator: DoubleValidator { bottom: 100.00 // 最小值 top: 500000.00 // 最大值 decimals: 0 } // 🔥 关键 3:兜底(IME 再作妖也不怕) Keys.onReturnPressed: { frames.cam_ExposureTime = text console.log("设置曝光时间:",text) Qt.inputMethod.hide() } onAccepted: { frames.cam_ExposureTime = text console.log("设置曝光时间",text) } } } } } } }