TestPage.qml 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. import QtQuick
  2. import QtQuick.Layouts
  3. import Felgo
  4. import QtMultimedia
  5. import QtQuick.Controls
  6. import Qt.labs.settings 1.0 as QtLabs
  7. import QtQuick.Controls.Material 2.0
  8. import QtLocation 5.5
  9. import QtPositioning 5.5
  10. import Qt5Compat.GraphicalEffects
  11. import "../controls"
  12. import "../common"
  13. import Frames 0.1
  14. AppPage {
  15. objectName: "autoFocus_Page"
  16. navigationBarHidden: true
  17. backgroundColor: app.theme_backgroundColor
  18. property var videoFormats
  19. // 定义电机状态
  20. property int currentAxis: 0 // 当前选择的轴 (0: X, 1: Y, 2: Z)
  21. property var axisPositions: [0, 0, 0] // 各轴当前位置
  22. property int speed: 50 // 当前速度 (0-100)
  23. property int stepDistance: 20 // 步进脉冲数量
  24. property string fExposureTime: "0"
  25. property bool motorUnlocked: false
  26. // ===== 上传进度网格(32格), 蛇形编号, 1 在右上角 =====
  27. // 数组下标 = GridLayout 摆放顺序(左上→右下), 元素 = 该格显示/对应的图片序号
  28. property var uploadGridSerials: [
  29. 32,25,24,17,16, 9, 8, 1,
  30. 31,26,23,18,15,10, 7, 2,
  31. 30,27,22,19,14,11, 6, 3,
  32. 29,28,21,20,13,12, 5, 4
  33. ]
  34. ListModel { id: uploadGridModel }
  35. Component.onCompleted: {
  36. for(var i = 0; i < 32; i++){
  37. uploadGridModel.append({serial: uploadGridSerials[i], percent: 0, done: false})
  38. }
  39. }
  40. // 从上传文件路径解析图片序号(文件名形如 ..._sharp_7.jpg)
  41. function uploadSerialFromPath(filePath) {
  42. if(!filePath) return -1
  43. var m = filePath.match(/sharp_(\d+)/)
  44. if(m && m.length > 1) return parseInt(m[1])
  45. return -1
  46. }
  47. // 由图片序号(1..32)换算成网格摆放索引(0..31, 蛇形, 1 在右上角)
  48. function uploadSerialToIndex(serial){
  49. var n = serial - 1
  50. var q = Math.floor(n / 4) // 0..7 列组(自右向左)
  51. var pos = n % 4 // 组内 0..3
  52. var col = 7 - q
  53. var row = (q % 2 === 0) ? pos : (3 - pos)
  54. return row * 8 + col
  55. }
  56. // 更新某个网格格子的状态
  57. function setUploadCell(serial, percent, done) {
  58. var idx = uploadSerialToIndex(serial)
  59. if(idx < 0 || idx > 31) return
  60. var p = Math.max(0, Math.min(100, percent))
  61. uploadGridModel.setProperty(idx, "percent", p)
  62. uploadGridModel.setProperty(idx, "done", done)
  63. }
  64. // 清空网格全部状态(percent=0, done=false)
  65. function resetUploadGrid() {
  66. for(var i = 0; i < uploadGridModel.count; i++){
  67. uploadGridModel.setProperty(i, "percent", 0)
  68. uploadGridModel.setProperty(i, "done", false)
  69. }
  70. }
  71. function autotake(sw){
  72. if(sw)
  73. {
  74. console.log("autotakestart")
  75. frames.camera_sw = true
  76. //frames.auto_clicked = true //开始对焦
  77. auto_timer.start() //启动对焦定时器
  78. console.log("相机已打开")
  79. photoTimer.interval=60*1000
  80. photoTimer.start()
  81. }else{
  82. frames.camera_sw = true
  83. console.log("打开相机单次拍照!")
  84. }
  85. }
  86. Frames {
  87. objectName: "Frames"
  88. id: frames
  89. videoSink: output.videoSink
  90. onCameraOpenFailed:function(err){
  91. console.log("onCameraOpenFailed",err)
  92. nativeUtils.displayMessageBox("相机打开失败!",err,1)
  93. focus_switch.checked = false
  94. focus_switch.enabled = true
  95. takephoto_switch.checked = false
  96. takephoto_switch.enabled = true
  97. }
  98. onVideoSinkChanged: {
  99. console.log("onVideoSinkChanged")
  100. photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
  101. }
  102. onQulityStringChanged: {
  103. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  104. photoTimer.interval = 180*1000 //3分钟超时
  105. photoTimer.restart()
  106. }
  107. onCameraStaChanged: function(sta_cam) {
  108. if(sta_cam){
  109. //camera.active = sta_cam
  110. //camera.start()
  111. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  112. output.visible = sta_cam
  113. photoTimer.interval = 180*1000 //3分钟超时
  114. photoTimer.start()
  115. //uvc_camera.visible = false
  116. }else{
  117. //camera.active = sta_cam
  118. //camera.stop()
  119. output.visible= sta_cam
  120. photoTimer.stop() //停止计时器
  121. focus_switch.checked = false
  122. focus_switch.enabled = true
  123. takephoto_switch.checked = false
  124. takephoto_switch.enabled = true
  125. //uvc_camera.visible = true
  126. }
  127. console.log("相机状态改变",sta_cam)
  128. }
  129. onStepCountChanged: function(step){
  130. console.log("坐标改变",step)
  131. step_apptextfield.text = step
  132. }
  133. onExposureTimeChanged: {
  134. fExposureTime = frames.cam_ExposureTime
  135. }
  136. }
  137. Timer {
  138. id: photoTimer
  139. interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  140. running: false // 初始状态下定时器停止
  141. repeat: false // 设置为false,以便只执行一次
  142. onTriggered: {
  143. // 定时器触发后,设置按钮可用
  144. // camera.active = false
  145. // camera.stop()
  146. output.visible = false
  147. frames.camera_sw = false
  148. }
  149. }
  150. Timer {
  151. id: auto_timer
  152. interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  153. running: false // 初始状态下定时器停止
  154. repeat: false // 设置为false,以便只执行一次
  155. onTriggered: {
  156. // 定时器触发后,开始对焦
  157. frames.auto_clicked = true
  158. }
  159. }
  160. Connections{
  161. target: mqtt
  162. function onMessagePub(message) {
  163. if(app.showPubData){
  164. var time = new Date().toLocaleTimeString()
  165. app.txDataLog = "[" + time + "] " + message + "\n" + app.txDataLog
  166. if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
  167. }
  168. }
  169. function onMessageSub(message) {
  170. if(app.showSubData){
  171. var time = new Date().toLocaleTimeString()
  172. app.rxDataLog = "[" + time + "] " + message + "\n" + app.rxDataLog
  173. if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
  174. }
  175. }
  176. function onSignal_set_camera_exposure(exposureTime) {
  177. console.log("收到远程相机曝光设置指令,曝光时间:" + exposureTime)
  178. frames.cam_ExposureTime = exposureTime.toString()
  179. }
  180. // 远程校准指令: {"cmd":"slide","ext":{"calibrate":"y","speed":"50"}} → 打开相机
  181. function onSignal_open_camera() {
  182. console.log("收到远程相机开启指令,打开相机!")
  183. frames.camera_sw = true
  184. }
  185. }
  186. // 图片上传进度 → 右上角 32 格进度网格
  187. Connections {
  188. target: curl_picture
  189. function onProgressChanged(uploadedPercent, filePath){
  190. var serial = uploadSerialFromPath(filePath)
  191. if(serial < 1 || serial > 32){
  192. console.log("上传进度: 无法识别图片序号", filePath)
  193. return
  194. }
  195. setUploadCell(serial, uploadedPercent, uploadedPercent >= 100)
  196. }
  197. }
  198. Connections{
  199. target: serial
  200. onTakephotodone:{
  201. console.log("立即拍照完成!")
  202. apptext_res.text = "立即拍照完成!"
  203. focus_switch.enabled = true
  204. focus_switch.checked = false
  205. }
  206. onAutotestdone: {
  207. console.log("自动对焦完成!")
  208. apptext_res.text = "自动对焦完成!"
  209. autotest_switch.enabled = true
  210. autotest_switch.checked = false
  211. }
  212. onTranslatedone: {
  213. console.log("胶带传送完成!")
  214. apptext_res.text = "胶带传送完成!"
  215. jiaodai_switch.enabled = true
  216. jiaodai_switch.checked = false
  217. }
  218. onDataReceived:function(data) {
  219. if(app.showRxData){
  220. var time = new Date().toLocaleTimeString()
  221. app.rxDataLog = "[" + time + "] " + data + "\n" + app.rxDataLog
  222. if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
  223. }
  224. // 同步坐标值到输入框
  225. try {
  226. var jsonData = JSON.parse(data)
  227. if(jsonData.ext && !textInput_x.focus && jsonData.ext.x_init_dis !== undefined) {
  228. textInput_x.text = jsonData.ext.x_init_dis.toString()
  229. }
  230. if(jsonData.ext && !textInput_y.focus && jsonData.ext.y_init_dis !== undefined) {
  231. textInput_y.text = jsonData.ext.y_init_dis.toString()
  232. }
  233. } catch(e) {
  234. console.log("解析坐标数据失败:", e)
  235. }
  236. }
  237. onNetMessage:function(data) {
  238. if(app.showTxData){
  239. var time = new Date().toLocaleTimeString()
  240. app.txDataLog = "[" + time + "] " + data + "\n" + app.txDataLog
  241. if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
  242. }
  243. }
  244. }
  245. SplitView{
  246. anchors.fill: parent
  247. orientation: Qt.Horizontal
  248. Rectangle {
  249. SplitView.preferredWidth: parent.width * 0.7
  250. height: parent.height
  251. color: app.cardColor
  252. radius: 5
  253. AppButton {
  254. id: normButton
  255. //anchors.horizontalCenter: parent.horizontalCenter
  256. anchors.centerIn: parent
  257. anchors.fill: parent
  258. //text: "打开相机"
  259. flat: true //边框是否可视
  260. onClicked: {
  261. console.log("相机状态:",frames.camera_sw)
  262. //if(camera.active){
  263. if(frames.camera_sw){
  264. text = "相机已关闭"
  265. output.visible = false
  266. frames.camera_sw = false
  267. //uvc_camera.visible = false
  268. }else{
  269. text = "打开相机"
  270. output.visible = true
  271. frames.camera_sw = true
  272. //uvc_camera.visible = true
  273. }
  274. }
  275. Timer {
  276. id: longPressTimer
  277. interval: 1000 // 长按时间1000ms
  278. running: false // 初始状态下定时器停止
  279. repeat: false // 设置为false,以便只执行一次
  280. onTriggered: {
  281. console.log("长按触发")
  282. }
  283. }
  284. onPressed: {
  285. console.log("按钮按下,开始计时")
  286. longPressTimer.start()
  287. }
  288. onReleased: {
  289. console.log("按钮释放,停止计时")
  290. longPressTimer.stop()
  291. }
  292. AppImage{
  293. id: image_picdis
  294. anchors.centerIn: parent
  295. source: "../../assets/photoico.svg"
  296. }
  297. }
  298. VideoOutput
  299. {
  300. id: output
  301. anchors.fill: parent
  302. visible: false
  303. fillMode: VideoOutput.PreserveAspectFit //根据视频的纵横比例等比例缩放
  304. //fillMode: VideoOutput.Stretch
  305. Component.onCompleted: {
  306. console.log("output onCompleted")
  307. }
  308. }
  309. Row {
  310. AppText {
  311. id: photoclarity_text
  312. width: parent.width
  313. text: frames.fpsString
  314. color: "red"
  315. }
  316. AppText {
  317. visible: true//app.photoclarity
  318. id: photoclarity2_text
  319. anchors.top: photoclarity_text.bottom
  320. width: parent.width
  321. text: frames.qulityString
  322. color: "green"
  323. }
  324. }
  325. // 图片上传进度网格(8列 x 4行 = 32格), 蛇形编号 1 在右上角, 常显示; 可按住拖动位置
  326. Rectangle {
  327. id: uploadGridWrap
  328. visible: true
  329. width: uploadGrid.implicitWidth
  330. height: uploadGrid.implicitHeight
  331. color: "transparent"
  332. // 初始位置: 画面右上角
  333. Component.onCompleted: {
  334. uploadGridWrap.x = uploadGridWrap.parent.width - uploadGridWrap.width - dp(10)
  335. uploadGridWrap.y = dp(10)
  336. }
  337. GridLayout {
  338. id: uploadGrid
  339. columns: 8
  340. columnSpacing: dp(2)
  341. rowSpacing: dp(2)
  342. Repeater {
  343. id: uploadGridRepeater
  344. model: uploadGridModel
  345. Rectangle {
  346. width: dp(42)
  347. height: dp(34)
  348. radius: dp(3)
  349. color: model.done ? "#8C1f9e4d" : "transparent"
  350. border.color: model.done ? "#37a24b" : "#66ffffff"
  351. border.width: 1
  352. Column {
  353. anchors.fill: parent
  354. spacing: 0
  355. AppText {
  356. text: model.serial
  357. color: "white"
  358. font.bold: true
  359. font.pixelSize: 11
  360. anchors.horizontalCenter: parent.horizontalCenter
  361. }
  362. AppText {
  363. text: model.percent > 0 ? Math.round(model.percent) + "%" : ""
  364. color: model.done ? "white" : "#ffb020"
  365. font.pixelSize: 10
  366. anchors.horizontalCenter: parent.horizontalCenter
  367. }
  368. }
  369. }
  370. }
  371. }
  372. // 按住拖动整个网格(DragHandler原生手势,平滑不卡顿;支持鼠标与触摸)
  373. DragHandler {
  374. id: gridDragHandler
  375. target: null
  376. acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchScreen
  377. property real startX: 0
  378. property real startY: 0
  379. onActiveChanged: {
  380. if(active){
  381. // 记录按下瞬间网格位置
  382. startX = uploadGridWrap.x
  383. startY = uploadGridWrap.y
  384. }
  385. }
  386. onTranslationChanged: {
  387. if(!active) return
  388. var nx = startX + translation.x
  389. var ny = startY + translation.y
  390. // 限制在父容器范围内
  391. nx = Math.max(0, Math.min(uploadGridWrap.parent.width - uploadGridWrap.width, nx))
  392. ny = Math.max(0, Math.min(uploadGridWrap.parent.height - uploadGridWrap.height, ny))
  393. uploadGridWrap.x = nx
  394. uploadGridWrap.y = ny
  395. }
  396. }
  397. }
  398. // 抓图按钮:仅相机打开时显示,画面右下角透明背景,点击=模拟MCU拍照指令(按序号保存/锐化/上传)
  399. Rectangle {
  400. id: captureBtn
  401. visible: frames.camera_sw
  402. width: dp(56)
  403. height: dp(56)
  404. radius: width / 2
  405. color: "transparent"
  406. border.color: "#80ffffff"
  407. border.width: dp(2)
  408. anchors.right: parent.right
  409. anchors.bottom: parent.bottom
  410. anchors.rightMargin: dp(12)
  411. anchors.bottomMargin: dp(12)
  412. AppImage {
  413. anchors.centerIn: parent
  414. width: dp(34)
  415. height: dp(34)
  416. source: "../../assets/photoico.svg"
  417. }
  418. MouseArea {
  419. anchors.fill: parent
  420. onClicked: {
  421. console.log("抓图按钮点击!")
  422. frames.manualCapture()
  423. }
  424. }
  425. }
  426. }
  427. ScrollView
  428. {
  429. SplitView.preferredWidth: parent.width*0.29
  430. SplitView.minimumWidth: 200
  431. clip: true
  432. Column {
  433. spacing: dp(15)
  434. Row {
  435. spacing: 80
  436. AppText {
  437. id: text_title
  438. text: "测试调试"
  439. font.bold: true
  440. color: "#28a779"
  441. fontSize: 20
  442. }
  443. AppText {
  444. id: apptext_res
  445. text: "[测试结果]"
  446. fontSize:15
  447. color: "grey"
  448. anchors.verticalCenter: text_title.verticalCenter
  449. }
  450. }
  451. Row {
  452. spacing: dp(120)
  453. AppText{
  454. text: "一键测试"
  455. fontSize: 15
  456. color: app.fontColor
  457. anchors.verticalCenter: autotest_switch.verticalCenter
  458. }
  459. AppSwitch {
  460. id: autotest_switch
  461. onToggled: {
  462. if(autotest_switch.checked==true){
  463. autotest_switch.enabled = false
  464. serial.sendCmd("autotest",true,"","");
  465. t_autotest.start()
  466. }else{
  467. console.log("t_autotest 计数:",t_autotest.interval)
  468. }
  469. }
  470. }
  471. Timer {
  472. id: t_autotest
  473. interval: 1000*60
  474. running: false
  475. repeat: false
  476. onTriggered: {
  477. autotest_switch.enabled = true
  478. autotest_switch.checked = false
  479. }
  480. }
  481. }
  482. Row {
  483. spacing: dp(120)
  484. AppText{
  485. text: "风机测试"
  486. color: app.fontColor
  487. fontSize: 15
  488. anchors.verticalCenter: fantest_switch.verticalCenter
  489. }
  490. AppSwitch {
  491. id: fantest_switch
  492. onToggled: {
  493. if(fantest_switch.checked==true){
  494. serial.sendCmd("fan",true,"","");
  495. apptext_res.text = "打开风机"
  496. }else{
  497. serial.sendCmd("fan",false,"","");
  498. apptext_res.text = "关闭风机"
  499. }
  500. }
  501. }
  502. }
  503. Row {
  504. spacing: dp(120)
  505. AppText{
  506. text: "胶带测试"
  507. fontSize: 15
  508. color: app.fontColor
  509. //font.bold: true
  510. anchors.verticalCenter: jiaodai_switch.verticalCenter
  511. }
  512. AppSwitch {
  513. id: jiaodai_switch
  514. onToggled: {
  515. if(jiaodai_switch.checked==true){
  516. // 检查是否处于温度保护状态
  517. if(app.tempProtectionState === true){
  518. // 弹出提示对话框
  519. nativeUtils.displayMessageBox(
  520. "提示",
  521. "当前处于温控状态,请解除温控后再进行测试胶带传送",
  522. 1
  523. );
  524. // 恢复开关状态为未选中
  525. jiaodai_switch.checked = false;
  526. return;
  527. }
  528. // 正常执行胶带测试
  529. //jiaodai_switch.enabled = false
  530. apptext_res.text = "胶带测试开始"
  531. serial.sendCmd("jiaodai",true,"","");
  532. }
  533. }
  534. }
  535. }
  536. Row {
  537. spacing: dp(120)
  538. AppText {
  539. text: "补光测试"
  540. color: app.fontColor
  541. fontSize: 15
  542. anchors.verticalCenter: led_switch.verticalCenter
  543. }
  544. AppSwitch {
  545. id: led_switch
  546. onToggled: {
  547. if(led_switch.checked==true){
  548. serial.sendCmd("led",true,"","");
  549. apptext_res.text = "补光灯已打开"
  550. }else{
  551. serial.sendCmd("led",false,"","");
  552. apptext_res.text = "补光灯已关闭"
  553. }
  554. }
  555. }
  556. }
  557. Row {
  558. spacing: dp(120)
  559. AppText {
  560. text: "立即拍照"
  561. color: app.fontColor
  562. fontSize: 15
  563. anchors.verticalCenter: takephoto_switch.verticalCenter
  564. }
  565. AppSwitch {
  566. id: takephoto_switch
  567. onToggled: {
  568. if(takephoto_switch.checked==true){
  569. apptext_res.text = "立即拍照"
  570. frames.captureImage()
  571. }
  572. }
  573. }
  574. }
  575. Row {
  576. spacing: dp(120)
  577. AppText {
  578. text: "对焦拍照"
  579. color: app.fontColor
  580. fontSize: 15
  581. anchors.verticalCenter: focus_switch.verticalCenter
  582. }
  583. AppSwitch {
  584. id: focus_switch
  585. onToggled: {
  586. if(focus_switch.checked==true){
  587. apptext_res.text = "开始对焦"
  588. focus_switch.enabled = false
  589. serial.auto_takephoto(true)
  590. }
  591. }
  592. }
  593. }
  594. // 滤网更换测试按钮(始终可见)
  595. Row {
  596. spacing: dp(120)
  597. AppText {
  598. text: "滤网更换"
  599. color: app.fontColor
  600. fontSize: 15
  601. anchors.verticalCenter: selfclean_switch.verticalCenter
  602. }
  603. AppSwitch {
  604. id: selfclean_switch
  605. onToggled: {
  606. if(selfclean_switch.checked==true){
  607. apptext_res.text = "自清洁测试中..."
  608. serial.sendCmd("selfclean",true,"","");
  609. }
  610. }
  611. }
  612. }
  613. // 分割线
  614. Rectangle {
  615. visible: !motorUnlocked
  616. width: parent.width
  617. height: dp(1)
  618. color: "#e0e0e0"
  619. }
  620. // 分割线
  621. Rectangle {
  622. width: parent.width
  623. height: dp(2)
  624. color: "#28a779"
  625. }
  626. // 密码输入区域(未解锁时显示)
  627. Rectangle {
  628. visible: !motorUnlocked
  629. width: parent.width
  630. height: passwordColumn.height + dp(16)
  631. color: app.cardColor
  632. radius: dp(8)
  633. border.color: "#28a779"
  634. border.width: dp(1)
  635. Column {
  636. id: passwordColumn
  637. anchors.centerIn: parent
  638. spacing: dp(10)
  639. AppText {
  640. anchors.horizontalCenter: parent.horizontalCenter
  641. text: "请输入密码解锁电机控制"
  642. color: app.fontColor
  643. font.bold: true
  644. fontSize: 14
  645. }
  646. Row {
  647. anchors.horizontalCenter: parent.horizontalCenter
  648. spacing: dp(8)
  649. AppTextField {
  650. id: motorPasswordInput
  651. width: dp(130)
  652. height: dp(38)
  653. echoMode: TextInput.Password
  654. placeholderText: "密码"
  655. inputMethodHints: Qt.ImhDigitsOnly
  656. anchors.verticalCenter: parent.verticalCenter
  657. onAccepted: {
  658. if(text === "666888"){
  659. motorUnlocked = true
  660. text = ""
  661. }else{
  662. apptext_res.text = "密码错误"
  663. text = ""
  664. }
  665. }
  666. }
  667. AppButton {
  668. text: "确认"
  669. textColor: "white"
  670. flat: false
  671. backgroundColor: "#28a779"
  672. minimumHeight: dp(38)
  673. minimumWidth: dp(55)
  674. anchors.verticalCenter: parent.verticalCenter
  675. onClicked: {
  676. if(motorPasswordInput.text === "666888"){
  677. motorUnlocked = true
  678. motorPasswordInput.text = ""
  679. }else{
  680. apptext_res.text = "密码错误"
  681. motorPasswordInput.text = ""
  682. }
  683. }
  684. }
  685. }
  686. }
  687. }
  688. // 电机控制及以下所有控件(解锁后显示)
  689. Item {
  690. id: motorSection
  691. visible: motorUnlocked
  692. width: parent.width
  693. height: motorContent.height + dp(20)
  694. property alias content: motorContent
  695. Column {
  696. id: motorContent
  697. spacing: dp(12)
  698. width: parent.width
  699. // 锁定按钮
  700. Row {
  701. spacing: dp(5)
  702. width: parent.width
  703. AppText {
  704. text: "高级控制"
  705. font.bold: true
  706. color: "#28a779"
  707. fontSize: 20
  708. anchors.verticalCenter: parent.verticalCenter
  709. }
  710. AppButton {
  711. text: "锁定"
  712. textColor: "white"
  713. flat: false
  714. backgroundColor: "#d9534f"
  715. minimumHeight: dp(25)
  716. minimumWidth: dp(50)
  717. anchors.verticalCenter: parent.verticalCenter
  718. onClicked: motorUnlocked = false
  719. }
  720. }
  721. AppText {
  722. id: text_title2
  723. text: "三轴步进电机控制"
  724. font.bold: true
  725. color: "#28a779"
  726. fontSize: 20
  727. }
  728. // 轴选择
  729. Row {
  730. spacing: dp(8)
  731. width: parent.width
  732. AppText {
  733. text: "选择轴:"
  734. width: dp(60)
  735. color: app.fontColor
  736. anchors.verticalCenter: parent.verticalCenter
  737. }
  738. ComboBox {
  739. width: parent.width - dp(100)
  740. height: dp(40)
  741. model: ["X轴", "Y轴", "Z轴"]
  742. onCurrentIndexChanged: currentAxis = currentIndex
  743. }
  744. AppButton {
  745. text: "校准"
  746. textColor: "black"
  747. flat: false
  748. borderColor: "black"
  749. borderWidth: dp(1)
  750. backgroundColor: "white"
  751. minimumHeight: dp(30)
  752. minimumWidth: dp(50)
  753. onClicked:
  754. {
  755. autotake(false)
  756. if(currentAxis==0)
  757. {
  758. console.log("校准X")
  759. serial.sendCmd("calibrate",false,"x",speed.toString())
  760. }else if(currentAxis==1)
  761. {
  762. console.log("校准Y")
  763. serial.sendCmd("calibrate",false,"y",speed.toString())
  764. }else if(currentAxis==2)
  765. {
  766. console.log("校准Z")
  767. serial.sendCmd("calibrate",false,"z",speed.toString())
  768. }
  769. }
  770. }
  771. }
  772. // 速度调节
  773. Row {
  774. spacing: dp(10)
  775. width: parent.width
  776. AppText {
  777. text: "速度:"
  778. width: dp(40)
  779. color: app.fontColor
  780. anchors.verticalCenter: parent.verticalCenter
  781. }
  782. AppSlider {
  783. width: parent.width - dp(60)
  784. from: 0
  785. to: 100
  786. value: speed
  787. stepSize: 1
  788. onValueChanged: speed = value
  789. anchors.verticalCenter: parent.verticalCenter
  790. }
  791. AppText {
  792. text: speed
  793. width: dp(40)
  794. anchors.verticalCenter: parent.verticalCenter
  795. }
  796. }
  797. // 步进距离设置
  798. Row {
  799. spacing: dp(10)
  800. width: parent.width
  801. AppText {
  802. text: "步进脉冲次数:"
  803. width: dp(120)
  804. color: app.fontColor
  805. anchors.verticalCenter: parent.verticalCenter
  806. }
  807. AppTextField {
  808. id: step_apptextfield
  809. width: parent.width - dp(120)
  810. text: stepDistance
  811. validator: IntValidator { bottom: 0; top: 2000 }
  812. onTextChanged: stepDistance = parseInt(text)
  813. }
  814. }
  815. // 运动控制按钮
  816. Row {
  817. spacing: dp(10)
  818. width: parent.width
  819. AppButton {
  820. text: " 正转 "
  821. textColor: "black"
  822. flat: false
  823. borderColor: "black"
  824. borderWidth: dp(1)
  825. backgroundColor: "grey"
  826. minimumHeight: dp(30)
  827. minimumWidth: dp(50)
  828. width: (parent.width - dp(30))/4
  829. onClicked:
  830. {
  831. if(currentAxis==0)
  832. {
  833. console.log("X轴正转:",stepDistance)
  834. serial.sendCmd("movx",false,"f"+stepDistance,speed.toString())
  835. }else if(currentAxis==1)
  836. {
  837. console.log("Y轴正转:",stepDistance)
  838. serial.sendCmd("movy",false,"f"+stepDistance,speed.toString())
  839. }else if(currentAxis==2)
  840. {
  841. console.log("Z轴正转:",stepDistance)
  842. serial.sendCmd("movz",false,"f"+stepDistance,speed.toString())
  843. }
  844. }
  845. }
  846. AppButton {
  847. text: " 停止 "
  848. textColor: "black"
  849. flat: false
  850. borderColor: "black"
  851. borderWidth: dp(1)
  852. backgroundColor: "red"
  853. minimumHeight: dp(30)
  854. minimumWidth: dp(50)
  855. width: (parent.width - dp(30))/4
  856. onClicked:
  857. {
  858. console.log("停止")
  859. serial.sendCmd("movx",false,"f0","")
  860. }
  861. }
  862. AppButton {
  863. text: " 反转 "
  864. textColor: "black"
  865. flat: false
  866. borderColor: "black"
  867. borderWidth: dp(1)
  868. backgroundColor: "grey"
  869. minimumHeight: dp(30)
  870. minimumWidth: dp(50)
  871. width: (parent.width - dp(30))/4
  872. onClicked:
  873. {
  874. if(currentAxis==0)
  875. {
  876. console.log("X轴反转:",stepDistance)
  877. serial.sendCmd("movx",false,"b"+stepDistance,speed.toString())
  878. }else if(currentAxis==1)
  879. {
  880. console.log("Y轴反转:",stepDistance)
  881. serial.sendCmd("movy",false,"b"+stepDistance,speed.toString())
  882. }else if(currentAxis==2)
  883. {
  884. console.log("Z轴反转:",stepDistance)
  885. serial.sendCmd("movz",false,"b"+stepDistance,speed.toString())
  886. }
  887. }
  888. }
  889. AppButton {
  890. text: " 复位 "
  891. textColor: "black"
  892. flat: false
  893. borderColor: "black"
  894. borderWidth: dp(1)
  895. backgroundColor: "grey"
  896. minimumHeight: dp(30)
  897. minimumWidth: dp(50)
  898. width: (parent.width - dp(30))/4
  899. onClicked: {
  900. if(currentAxis==0)
  901. {
  902. console.log("X轴复位!")
  903. serial.sendCmd("movx",true,"",speed.toString())
  904. }else if(currentAxis==1)
  905. {
  906. console.log("Y轴复位!")
  907. serial.sendCmd("movy",true,"",speed.toString())
  908. }else if(currentAxis==2)
  909. {
  910. console.log("Z轴复位!")
  911. serial.sendCmd("movz",true,"",speed.toString())
  912. }
  913. }
  914. }
  915. }
  916. // ===== 坐标参数 =====
  917. AppText {
  918. text: "坐标参数"
  919. font.bold: true
  920. color: "#28a779"
  921. fontSize: 20
  922. }
  923. // X 坐标输入行
  924. Row {
  925. spacing: dp(5)
  926. width: parent.width
  927. AppText {
  928. text: "X坐标:"
  929. width: dp(50)
  930. color: app.fontColor
  931. fontSize: 15
  932. anchors.verticalCenter: textInput_x.verticalCenter
  933. }
  934. AppTextField {
  935. id: textInput_x
  936. width: parent.width - dp(80)
  937. height: dp(40)
  938. placeholderText: "0"
  939. text: "0"
  940. font.family: "Arial"
  941. font.pixelSize: 15
  942. validator: DoubleValidator { decimals: 2 }
  943. EnterKey.type: Qt.EnterKeyDone
  944. inputMethodHints: Qt.ImhFormattedNumbersOnly
  945. property real numericValue_x: Number(text) || 0
  946. Keys.onReturnPressed: {
  947. serial.setHt_xy_dis(numericValue_x, textInput_y.numericValue_y)
  948. Qt.inputMethod.hide()
  949. }
  950. onAccepted: {
  951. serial.setHt_xy_dis(numericValue_x, textInput_y.numericValue_y)
  952. }
  953. }
  954. }
  955. // Y 坐标输入行
  956. Row {
  957. spacing: dp(5)
  958. width: parent.width
  959. AppText {
  960. text: "Y坐标:"
  961. width: dp(50)
  962. color: app.fontColor
  963. fontSize: 15
  964. anchors.verticalCenter: textInput_y.verticalCenter
  965. }
  966. AppTextField {
  967. id: textInput_y
  968. width: parent.width - dp(80)
  969. height: dp(40)
  970. placeholderText: "0"
  971. text: "0"
  972. font.family: "Arial"
  973. font.pixelSize: 15
  974. validator: DoubleValidator { decimals: 2 }
  975. EnterKey.type: Qt.EnterKeyDone
  976. inputMethodHints: Qt.ImhFormattedNumbersOnly
  977. property real numericValue_y: Number(text) || 0
  978. Keys.onReturnPressed: {
  979. serial.setHt_xy_dis(textInput_x.numericValue_x, numericValue_y)
  980. Qt.inputMethod.hide()
  981. }
  982. onAccepted: {
  983. serial.setHt_xy_dis(textInput_x.numericValue_x, numericValue_y)
  984. }
  985. }
  986. }
  987. // 分割线
  988. Rectangle {
  989. width: parent.width
  990. height: dp(2)
  991. color: "#e0e0e0"
  992. }
  993. // ===== 相机参数 =====
  994. AppText {
  995. id: text_camera
  996. text: "相机参数"
  997. font.bold: true
  998. color: "#28a779"
  999. fontSize: 20
  1000. }
  1001. Row {
  1002. spacing: dp(10)
  1003. width: parent.width
  1004. AppText {
  1005. id: txt_fExposureTime
  1006. text: "曝光值:"
  1007. color: app.fontColor
  1008. }
  1009. AppTextField {
  1010. anchors.verticalCenter: txt_fExposureTime.verticalCenter
  1011. placeholderText: fExposureTime
  1012. text: fExposureTime
  1013. width: parent.width - dp(10)
  1014. EnterKey.type: Qt.EnterKeyDone
  1015. wrapMode: Text.NoWrap
  1016. inputMethodHints: Qt.ImhFormattedNumbersOnly |
  1017. Qt.ImhPreferDone |
  1018. Qt.ImhNoPredictiveText
  1019. validator: DoubleValidator {
  1020. bottom: 100.00
  1021. top: 500000.00
  1022. decimals: 0
  1023. }
  1024. // 关键:兜底(IME 再作妖也不怕)
  1025. Keys.onReturnPressed: {
  1026. frames.cam_ExposureTime = text
  1027. console.log("设置曝光时间:",text)
  1028. Qt.inputMethod.hide()
  1029. }
  1030. onAccepted: {
  1031. frames.cam_ExposureTime = text
  1032. console.log("设置曝光时间",text)
  1033. }
  1034. }
  1035. }
  1036. AppText {
  1037. id: text_debug
  1038. text: "通信调试"
  1039. font.bold: true
  1040. color: "#28a779"
  1041. fontSize: 20
  1042. }
  1043. Row {
  1044. spacing: dp(12)
  1045. AppText {
  1046. text: "显示Serial发送数据"
  1047. color: app.fontColor
  1048. fontSize: 15
  1049. anchors.verticalCenter: txSwitch.verticalCenter
  1050. }
  1051. AppSwitch {
  1052. id: txSwitch
  1053. onToggled: {
  1054. app.floatPanel = checked
  1055. app.showTxData = checked
  1056. app.floatPanel_title = "Serial发送数据"
  1057. }
  1058. }
  1059. }
  1060. Row {
  1061. spacing: dp(12)
  1062. AppText {
  1063. text: "显示Serial接收数据"
  1064. color: app.fontColor
  1065. fontSize: 15
  1066. anchors.verticalCenter: rxSwitch.verticalCenter
  1067. }
  1068. AppSwitch {
  1069. id: rxSwitch
  1070. onToggled: {
  1071. app.floatPanel = checked
  1072. app.showRxData = checked
  1073. app.floatPanel_title = "Serial接收数据"
  1074. }
  1075. }
  1076. }
  1077. Row {
  1078. spacing: dp(12)
  1079. AppText {
  1080. text: "显示MQTT发送数据"
  1081. color: app.fontColor
  1082. fontSize: 15
  1083. anchors.verticalCenter: pubSwitch.verticalCenter
  1084. }
  1085. AppSwitch {
  1086. id: pubSwitch
  1087. onToggled: {
  1088. app.floatPanel = checked
  1089. app.showPubData = checked
  1090. app.showSubData = false
  1091. app.floatPanel_title = "MQTT发送数据"
  1092. }
  1093. }
  1094. }
  1095. Row {
  1096. spacing: dp(12)
  1097. AppText {
  1098. text: "显示MQTT接收数据"
  1099. color: app.fontColor
  1100. fontSize: 15
  1101. anchors.verticalCenter: subSwitch.verticalCenter
  1102. }
  1103. AppSwitch {
  1104. id: subSwitch
  1105. onToggled: {
  1106. app.floatPanel = checked
  1107. app.showSubData = checked
  1108. app.showPubData = false
  1109. app.floatPanel_title = "MQTT接收数据"
  1110. }
  1111. }
  1112. }
  1113. } // motorContent
  1114. } // motorSection
  1115. }
  1116. }
  1117. }
  1118. }