| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216 |
- import QtQuick
- import Felgo
- import QtMultimedia
- import QtQuick.Controls
- import QtQuick.Layouts
- 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"
- property bool motorUnlocked: false
- property real coordX: 0
- property real coordY: 0
- // ===== 上传进度网格(32格), 蛇形编号, 1 在右上角 =====
- // 数组下标 = GridLayout 摆放顺序(左上→右下), 元素 = 该格显示/对应的图片序号
- property var uploadGridSerials: [
- 32,25,24,17,16, 9, 8, 1,
- 31,26,23,18,15,10, 7, 2,
- 30,27,22,19,14,11, 6, 3,
- 29,28,21,20,13,12, 5, 4
- ]
- ListModel { id: uploadGridModel }
- Component.onCompleted: {
- for(var i = 0; i < 32; i++){
- uploadGridModel.append({serial: uploadGridSerials[i], percent: 0, done: false})
- }
- }
- // 从上传文件路径解析图片序号(文件名形如 ..._sharp_7.jpg)
- function uploadSerialFromPath(filePath) {
- if(!filePath) return -1
- var m = filePath.match(/sharp_(\d+)/)
- if(m && m.length > 1) return parseInt(m[1])
- return -1
- }
- // 由图片序号(1..32)换算成网格摆放索引(0..31, 蛇形, 1 在右上角)
- function uploadSerialToIndex(serial){
- var n = serial - 1
- var q = Math.floor(n / 4) // 0..7 列组(自右向左)
- var pos = n % 4 // 组内 0..3
- var col = 7 - q
- var row = (q % 2 === 0) ? pos : (3 - pos)
- return row * 8 + col
- }
- // 更新某个网格格子的状态
- function setUploadCell(serial, percent, done) {
- var idx = uploadSerialToIndex(serial)
- if(idx < 0 || idx > 31) return
- var p = Math.max(0, Math.min(100, percent))
- uploadGridModel.setProperty(idx, "percent", p)
- uploadGridModel.setProperty(idx, "done", done)
- }
- // 清空网格全部状态(percent=0, done=false)
- function resetUploadGrid() {
- for(var i = 0; i < uploadGridModel.count; i++){
- uploadGridModel.setProperty(i, "percent", 0)
- uploadGridModel.setProperty(i, "done", 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
- // 打开相机:清空上传进度网格状态,开始新一轮上传统计
- resetUploadGrid()
- }else{
- //camera.active = sta_cam
- //camera.stop()
- output.visible= sta_cam
- photoTimer.stop() //停止计时器
- focus_switch.checked = false
- focus_switch.enabled = true
- takephoto_switch.checked = false
- takephoto_switch.enabled = true
- //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: 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()
- }
- // 远程校准指令: {"cmd":"slide","ext":{"calibrate":"y","speed":"50"}} → 打开相机
- function onSignal_open_camera() {
- console.log("收到远程相机开启指令,打开相机!")
- frames.camera_sw = true
- }
- }
- // 图片上传进度 → 右上角 32 格进度网格
- Connections {
- target: curl_picture
- function onProgressChanged(uploadedPercent, filePath){
- var serial = uploadSerialFromPath(filePath)
- if(serial < 1 || serial > 32){
- console.log("上传进度: 无法识别图片序号", filePath)
- return
- }
- setUploadCell(serial, uploadedPercent, uploadedPercent >= 100)
- }
- }
- 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
- }
- 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_x.focus && jsonData.ext.x_init_dis !== undefined) {
- coordX = parseInt(jsonData.ext.x_init_dis) || 0
- }
- if(jsonData.ext && !textInput_y.focus && jsonData.ext.y_init_dis !== undefined) {
- coordY = parseInt(jsonData.ext.y_init_dis) || 0
- }
- } 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
- }
- }
- 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"
- }
- }
- // 图片上传进度网格(8列 x 4行 = 32格), 蛇形编号 1 在右上角, 常显示; 可按住拖动位置
- Rectangle {
- id: uploadGridWrap
- visible: true
- width: uploadGrid.implicitWidth
- height: uploadGrid.implicitHeight
- color: "transparent"
- // 初始位置: 画面右上角
- Component.onCompleted: {
- uploadGridWrap.x = uploadGridWrap.parent.width - uploadGridWrap.width - dp(10)
- uploadGridWrap.y = dp(10)
- }
- GridLayout {
- id: uploadGrid
- columns: 8
- columnSpacing: dp(2)
- rowSpacing: dp(2)
- Repeater {
- id: uploadGridRepeater
- model: uploadGridModel
- Rectangle {
- width: dp(42)
- height: dp(34)
- radius: dp(3)
- color: model.done ? "#8C1f9e4d" : "transparent"
- border.color: model.done ? "#37a24b" : "#66ffffff"
- border.width: 1
- Column {
- anchors.fill: parent
- spacing: 0
- AppText {
- text: model.serial
- color: "white"
- font.bold: true
- font.pixelSize: 11
- anchors.horizontalCenter: parent.horizontalCenter
- }
- AppText {
- text: model.percent > 0 ? Math.round(model.percent) + "%" : ""
- color: model.done ? "white" : "#ffb020"
- font.pixelSize: 10
- anchors.horizontalCenter: parent.horizontalCenter
- }
- }
- }
- }
- }
- // 按住拖动整个网格(DragHandler原生手势,平滑不卡顿;支持鼠标与触摸)
- DragHandler {
- id: gridDragHandler
- target: null
- acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchScreen
- property real startX: 0
- property real startY: 0
- onActiveChanged: {
- if(active){
- // 记录按下瞬间网格位置
- startX = uploadGridWrap.x
- startY = uploadGridWrap.y
- }
- }
- onTranslationChanged: {
- if(!active) return
- var nx = startX + translation.x
- var ny = startY + translation.y
- // 限制在父容器范围内
- nx = Math.max(0, Math.min(uploadGridWrap.parent.width - uploadGridWrap.width, nx))
- ny = Math.max(0, Math.min(uploadGridWrap.parent.height - uploadGridWrap.height, ny))
- uploadGridWrap.x = nx
- uploadGridWrap.y = ny
- }
- }
- }
- // 抓图按钮:仅相机打开时显示,画面右下角透明背景,点击=模拟MCU拍照指令(按序号保存/锐化/上传)
- Rectangle {
- id: captureBtn
- visible: frames.camera_sw
- width: dp(56)
- height: dp(56)
- radius: width / 2
- color: "transparent"
- border.color: "#80ffffff"
- border.width: dp(2)
- anchors.right: parent.right
- anchors.bottom: parent.bottom
- anchors.rightMargin: dp(12)
- anchors.bottomMargin: dp(12)
- AppImage {
- anchors.centerIn: parent
- width: dp(34)
- height: dp(34)
- source: "../../assets/photoico.svg"
- }
- MouseArea {
- anchors.fill: parent
- onClicked: {
- console.log("抓图按钮点击!")
- frames.manualCapture()
- }
- }
- }
- }
- 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: dp(120)
- AppText{
- text: "一键测试"
- fontSize: 15
- color: app.fontColor
- 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: dp(120)
- AppText{
- text: "风机测试"
- color: app.fontColor
- fontSize: 15
- 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: dp(120)
- 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: dp(120)
- AppText {
- text: "补光测试"
- color: app.fontColor
- fontSize: 15
- 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: dp(120)
- AppText {
- text: "立即拍照"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: takephoto_switch.verticalCenter
- }
- AppSwitch {
- id: takephoto_switch
- onToggled: {
- if(takephoto_switch.checked==true){
- apptext_res.text = "立即拍照"
- frames.captureImage()
- }
- }
- }
- }
- Row {
- spacing: dp(120)
- AppText {
- text: "对焦拍照"
- color: app.fontColor
- fontSize: 15
- 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: ["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(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(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))/4
- 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))/4
- 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))/4
- 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))/4
- 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 {
- text: "坐标参数"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- // X 坐标输入行
- Row {
- spacing: dp(5)
- width: parent.width
- AppText {
- text: "X坐标:"
- width: dp(50)
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: textInput_x.verticalCenter
- }
- AppTextField {
- id: textInput_x
- width: parent.width - dp(80)
- height: dp(40)
- placeholderText: "0"
- text: coordX.toString()
- font.family: "Arial"
- font.pixelSize: 15
- validator: IntValidator { }
- EnterKey.type: Qt.EnterKeyDone
- inputMethodHints: Qt.ImhDigitsOnly
- Keys.onReturnPressed: {
- coordX = parseInt(text) || 0
- serial.setHt_xy_dis(coordX, coordY)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- coordX = parseInt(text) || 0
- serial.setHt_xy_dis(coordX, coordY)
- }
- }
- }
- // 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: coordY.toString()
- font.family: "Arial"
- font.pixelSize: 15
- validator: IntValidator { }
- EnterKey.type: Qt.EnterKeyDone
- inputMethodHints: Qt.ImhDigitsOnly
- Keys.onReturnPressed: {
- coordY = parseInt(text) || 0
- serial.setHt_xy_dis(coordX, coordY)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- coordY = parseInt(text) || 0
- serial.setHt_xy_dis(coordX, coordY)
- }
- }
- }
- // 分割线
- 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
- }
- }
- }
- }
|