TestPage.qml 48 KB

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