| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946 |
- import QtQuick
- import Felgo
- import QtMultimedia
- import QtQuick.Controls
- // import QtQuick.Controls.Material 2.0 // 移除:与Felgo主题冲突,导致AppSwitch颜色异常
- 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"
- property bool motorUnlocked: false
- 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
- //关闭相机重置按钮状态
- focus_switch.enabled = true
- focus_switch.checked = false
- takephoto_switch.checked = false
- takephoto_switch.enabled = 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: mqtt
- function onMessagePub(message) {
- if(app.showPubData){
- var time = new Date().toLocaleTimeString()
- app.txDataLog = "[" + time + "] " + message + "\n" + app.txDataLog
- if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
- }
- }
- function onMessageSub(message) {
- if(app.showSubData){
- var time = new Date().toLocaleTimeString()
- app.rxDataLog = "[" + time + "] " + message + "\n" + app.rxDataLog
- if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
- }
- }
- function onSignal_set_camera_exposure(exposureTime) {
- console.log("收到远程相机曝光设置指令,曝光时间:" + exposureTime)
- frames.cam_ExposureTime = exposureTime.toString()
- }
- }
- Connections {
- target: serial
- function onTakephotodone() {
- console.log("立即拍照完成!")
- apptext_res.text = "立即拍照完成!"
- focus_switch.enabled = true
- focus_switch.checked = false
- takephoto_switch.checked = false
- takephoto_switch.enabled = true
- }
- function onAutotestdone() {
- console.log("自动对焦完成!")
- apptext_res.text = "自动对焦完成!"
- autotest_switch.enabled = true
- autotest_switch.checked = false
- }
- onTranslatedone:function() {
- console.log("胶带传送完成!")
- apptext_res.text = "胶带传送完成!"
- jiaodai_switch.enabled = true
- jiaodai_switch.checked = false
- }
- onDataReceived:function(data) {
- if(app.showRxData){
- var time = new Date().toLocaleTimeString()
- app.rxDataLog = "[" + time + "] " + data + "\n" + app.rxDataLog
- if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
- }
- // 同步坐标值到输入框
- try {
- var jsonData = JSON.parse(data)
- if(jsonData.ext && !textInput_y.focus && jsonData.ext.y_init_dis !== undefined) {
- textInput_y.text = jsonData.ext.y_init_dis.toString()
- }
- } catch(e) {
- console.log("解析坐标数据失败:", e)
- }
- }
- onNetMessage:function(data) {
- if(app.showTxData){
- var time = new Date().toLocaleTimeString()
- app.txDataLog = "[" + time + "] " + data + "\n" + app.txDataLog
- if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
- }
- }
- }
- 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
- }
- }
- 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 {
- width: parent.width
- 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){
- // 检查是否处于温度保护状态
- if(app.tempProtectionState === true){
- // 弹出提示对话框
- nativeUtils.displayMessageBox(
- "提示",
- "当前处于温控状态,请解除温控后再进行测试胶带传送",
- 1
- );
- // 恢复开关状态为未选中
- jiaodai_switch.checked = false;
- return;
- }
- // 正常执行胶带测试
- //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)
- }
- }
- }
- }
- // 分割线
- Rectangle {
- visible: !motorUnlocked
- width: parent.width
- height: dp(1)
- color: "#e0e0e0"
- }
- // 分割线
- Rectangle {
- width: parent.width
- height: dp(2)
- color: "#28a779"
- }
- // 密码输入区域(未解锁时显示)
- Rectangle {
- visible: !motorUnlocked
- width: parent.width
- height: passwordColumn.height + dp(16)
- color: app.cardColor
- radius: dp(8)
- border.color: "#28a779"
- border.width: dp(1)
- Column {
- id: passwordColumn
- anchors.centerIn: parent
- spacing: dp(10)
- AppText {
- anchors.horizontalCenter: parent.horizontalCenter
- text: "请输入密码解锁高级设置"
- color: app.fontColor
- font.bold: true
- fontSize: 14
- }
- Row {
- anchors.horizontalCenter: parent.horizontalCenter
- spacing: dp(8)
- AppTextField {
- id: motorPasswordInput
- width: dp(130)
- height: dp(38)
- echoMode: TextInput.Password
- placeholderText: "密码"
- inputMethodHints: Qt.ImhDigitsOnly
- anchors.verticalCenter: parent.verticalCenter
- onAccepted: {
- if(text === "666888"){
- motorUnlocked = true
- text = ""
- }else{
- apptext_res.text = "密码错误"
- text = ""
- }
- }
- }
- AppButton {
- text: "确认"
- textColor: "white"
- flat: false
- backgroundColor: "#28a779"
- minimumHeight: dp(38)
- minimumWidth: dp(55)
- anchors.verticalCenter: parent.verticalCenter
- onClicked: {
- if(motorPasswordInput.text === "666888"){
- motorUnlocked = true
- motorPasswordInput.text = ""
- }else{
- apptext_res.text = "密码错误"
- motorPasswordInput.text = ""
- }
- }
- }
- }
- }
- }
- // 电机控制及以下所有控件(解锁后显示)
- Item {
- id: motorSection
- visible: motorUnlocked
- width: parent.width
- height: motorContent.height + dp(20)
- property alias content: motorContent
- Column {
- id: motorContent
- spacing: dp(12)
- width: parent.width
- // 锁定按钮
- Row {
- spacing: dp(5)
- width: parent.width
- AppText {
- text: "高级控制"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- anchors.verticalCenter: parent.verticalCenter
- }
- AppButton {
- text: "锁定"
- textColor: "white"
- flat: false
- backgroundColor: "#d9534f"
- minimumHeight: dp(25)
- minimumWidth: dp(50)
- anchors.verticalCenter: parent.verticalCenter
- onClicked: motorUnlocked = false
- }
- }
- AppText {
- id: text_title2
- text: "三轴步进电机控制"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- // 轴选择
- Row {
- spacing: dp(8)
- width: parent.width
- AppText {
- text: "选择轴:"
- width: dp(60)
- color: app.fontColor
- anchors.verticalCenter: parent.verticalCenter
- }
- ComboBox {
- width: parent.width - dp(100)
- height: dp(40)
- model: ["Y轴"]
- 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("校准y")
- serial.sendCmd("calibrate",false,"y",speed.toString())
- }
- }
- }
- }
- // 速度调节
- Row {
- spacing: dp(10)
- width: parent.width
- AppText {
- text: "速度:"
- width: dp(40)
- color: app.fontColor
- 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)
- color: app.fontColor
- 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(20)
- 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))/4
- onClicked:
- {
- if(currentAxis==0)
- {
- console.log("Y轴正转:",stepDistance)
- serial.sendCmd("movy",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))/4
- onClicked:
- {
- console.log("停止")
- serial.sendCmd("movy",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))/4
- onClicked:
- {
- if(currentAxis==0)
- {
- console.log("Y轴反转:",stepDistance)
- serial.sendCmd("movy",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))/4
- onClicked: {
- if(currentAxis==0)
- {
- console.log("Y轴复位!")
- serial.sendCmd("movy",true,"",speed.toString())
- }
- }
- }
- }
- // ===== 坐标参数 =====
- AppText {
- text: "坐标参数"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- // Y 坐标输入行
- Row {
- spacing: dp(5)
- width: parent.width
- AppText {
- text: "Y坐标:"
- width: dp(50)
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: textInput_y.verticalCenter
- }
- AppTextField {
- id: textInput_y
- width: parent.width - dp(80)
- height: dp(40)
- placeholderText: "0"
- text: "0"
- font.family: "Arial"
- font.pixelSize: 15
- validator: DoubleValidator { decimals: 2 }
- EnterKey.type: Qt.EnterKeyDone
- inputMethodHints: Qt.ImhFormattedNumbersOnly
- property real numericValue_y: Number(text) || 0
- Keys.onReturnPressed: {
- serial.setHt_xy_dis("0", numericValue_y)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- serial.setHt_xy_dis("0", numericValue_y)
- }
- }
- }
- // 分割线
- Rectangle {
- width: parent.width
- height: dp(2)
- color: "#e0e0e0"
- }
- // ===== 相机参数 =====
- AppText {
- id: text_camera
- text: "相机参数"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- Row {
- spacing: dp(10)
- width: parent.width
- AppText {
- id: txt_fExposureTime
- text: "曝光值:"
- color: app.fontColor
- }
- 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
- }
- // 关键:兜底(IME 再作妖也不怕)
- Keys.onReturnPressed: {
- frames.cam_ExposureTime = text
- console.log("设置曝光时间:",text)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- frames.cam_ExposureTime = text
- console.log("设置曝光时间",text)
- }
- }
- }
- AppText {
- id: text_debug
- text: "通信调试"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- Row {
- spacing: dp(12)
- AppText {
- text: "显示Serial发送数据"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: txSwitch.verticalCenter
- }
- AppSwitch {
- id: txSwitch
- onToggled: {
- app.floatPanel = checked
- app.showTxData = checked
- app.floatPanel_title = "Serial发送数据"
- }
- }
- }
- Row {
- spacing: dp(12)
- AppText {
- text: "显示Serial接收数据"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: rxSwitch.verticalCenter
- }
- AppSwitch {
- id: rxSwitch
- onToggled: {
- app.floatPanel = checked
- app.showRxData = checked
- app.floatPanel_title = "Serial接收数据"
- }
- }
- }
- Row {
- spacing: dp(12)
- AppText {
- text: "显示MQTT发送数据"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: pubSwitch.verticalCenter
- }
- AppSwitch {
- id: pubSwitch
- onToggled: {
- app.floatPanel = checked
- app.showPubData = checked
- app.showSubData = false
- app.floatPanel_title = "MQTT发送数据"
- }
- }
- }
- Row {
- spacing: dp(12)
- AppText {
- text: "显示MQTT接收数据"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: subSwitch.verticalCenter
- }
- AppSwitch {
- id: subSwitch
- onToggled: {
- app.floatPanel = checked
- app.showSubData = checked
- app.showPubData = false
- app.floatPanel_title = "MQTT接收数据"
- }
- }
- }
- } // motorContent
- } // motorSection
- }
- }
- }
- }
|