TestPage.qml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. import QtQuick
  2. import Felgo
  3. import QtMultimedia
  4. import QtQuick.Controls
  5. import Qt.labs.settings 1.0 as QtLabs
  6. import QtQuick.Controls.Material 2.0
  7. import QtLocation 5.5
  8. import QtPositioning 5.5
  9. import Qt5Compat.GraphicalEffects
  10. import "../controls"
  11. import "../common"
  12. import Frames 0.1
  13. AppPage {
  14. objectName: "autoFocus_Page"
  15. navigationBarHidden: true
  16. backgroundColor: app.theme_backgroundColor
  17. property var videoFormats
  18. // 定义电机状态
  19. property int currentAxis: 0 // 当前选择的轴 (0: X, 1: Y, 2: Z)
  20. property var axisPositions: [0, 0, 0] // 各轴当前位置
  21. property int speed: 50 // 当前速度 (0-100)
  22. property int stepDistance: 20 // 步进脉冲数量
  23. property string fExposureTime: "0"
  24. function autotake(sw){
  25. if(sw)
  26. {
  27. console.log("autotakestart")
  28. frames.camera_sw = true
  29. //frames.auto_clicked = true //开始对焦
  30. auto_timer.start() //启动对焦定时器
  31. console.log("相机已打开")
  32. photoTimer.interval=60*1000
  33. photoTimer.start()
  34. }else{
  35. frames.camera_sw = true
  36. console.log("打开相机单次拍照!")
  37. }
  38. }
  39. Frames {
  40. objectName: "Frames"
  41. id: frames
  42. videoSink: output.videoSink
  43. onCameraOpenFailed:function(err){
  44. console.log("onCameraOpenFailed",err)
  45. nativeUtils.displayMessageBox("相机打开失败!",err,1)
  46. focus_switch.checked = false
  47. focus_switch.enabled = true
  48. takephoto_switch.checked = false
  49. takephoto_switch.enabled = true
  50. }
  51. onVideoSinkChanged: {
  52. console.log("onVideoSinkChanged")
  53. photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
  54. }
  55. onQulityStringChanged: {
  56. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  57. photoTimer.interval = 180*1000 //3分钟超时
  58. photoTimer.restart()
  59. }
  60. onCameraStaChanged: function(sta_cam) {
  61. if(sta_cam){
  62. //camera.active = sta_cam
  63. //camera.start()
  64. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  65. output.visible = sta_cam
  66. photoTimer.interval = 180*1000 //3分钟超时
  67. photoTimer.start()
  68. //uvc_camera.visible = false
  69. }else{
  70. //camera.active = sta_cam
  71. //camera.stop()
  72. output.visible= sta_cam
  73. photoTimer.stop() //停止计时器
  74. //uvc_camera.visible = true
  75. }
  76. console.log("相机状态改变",sta_cam)
  77. }
  78. onStepCountChanged: function(step){
  79. console.log("坐标改变",step)
  80. step_apptextfield.text = step
  81. }
  82. onExposureTimeChanged: {
  83. fExposureTime = frames.cam_ExposureTime
  84. }
  85. }
  86. Timer {
  87. id: photoTimer
  88. interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  89. running: false // 初始状态下定时器停止
  90. repeat: false // 设置为false,以便只执行一次
  91. onTriggered: {
  92. // 定时器触发后,设置按钮可用
  93. // camera.active = false
  94. // camera.stop()
  95. output.visible = false
  96. frames.camera_sw = false
  97. }
  98. }
  99. Timer {
  100. id: auto_timer
  101. interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  102. running: false // 初始状态下定时器停止
  103. repeat: false // 设置为false,以便只执行一次
  104. onTriggered: {
  105. // 定时器触发后,开始对焦
  106. frames.auto_clicked = true
  107. }
  108. }
  109. Connections{
  110. target: serial
  111. onTakephotodone:{
  112. console.log("立即拍照完成!")
  113. apptext_res.text = "立即拍照完成!"
  114. focus_switch.enabled = true
  115. focus_switch.checked = false
  116. }
  117. onAutotestdone: {
  118. console.log("自动对焦完成!")
  119. apptext_res.text = "自动对焦完成!"
  120. autotest_switch.enabled = true
  121. autotest_switch.checked = false
  122. }
  123. onTranslatedone: {
  124. console.log("胶带传送完成!")
  125. apptext_res.text = "胶带传送完成!"
  126. jiaodai_switch.enabled = true
  127. jiaodai_switch.checked = false
  128. }
  129. }
  130. SplitView{
  131. anchors.fill: parent
  132. orientation: Qt.Horizontal
  133. Rectangle {
  134. SplitView.preferredWidth: parent.width * 0.7
  135. height: parent.height
  136. color: app.cardColor
  137. radius: 5
  138. AppButton {
  139. id: normButton
  140. //anchors.horizontalCenter: parent.horizontalCenter
  141. anchors.centerIn: parent
  142. anchors.fill: parent
  143. //text: "打开相机"
  144. flat: true //边框是否可视
  145. onClicked: {
  146. console.log("相机状态:",frames.camera_sw)
  147. //if(camera.active){
  148. if(frames.camera_sw){
  149. text = "相机已关闭"
  150. output.visible = false
  151. frames.camera_sw = false
  152. //uvc_camera.visible = false
  153. }else{
  154. text = "打开相机"
  155. output.visible = true
  156. frames.camera_sw = true
  157. //uvc_camera.visible = true
  158. }
  159. }
  160. Timer {
  161. id: longPressTimer
  162. interval: 1000 // 长按时间1000ms
  163. running: false // 初始状态下定时器停止
  164. repeat: false // 设置为false,以便只执行一次
  165. onTriggered: {
  166. console.log("长按触发")
  167. }
  168. }
  169. onPressed: {
  170. console.log("按钮按下,开始计时")
  171. longPressTimer.start()
  172. }
  173. onReleased: {
  174. console.log("按钮释放,停止计时")
  175. longPressTimer.stop()
  176. }
  177. AppImage{
  178. id: image_picdis
  179. anchors.centerIn: parent
  180. source: "../../assets/photoico.svg"
  181. }
  182. }
  183. VideoOutput
  184. {
  185. id: output
  186. anchors.fill: parent
  187. visible: false
  188. fillMode: VideoOutput.PreserveAspectFit //根据视频的纵横比例等比例缩放
  189. //fillMode: VideoOutput.Stretch
  190. Component.onCompleted: {
  191. console.log("output onCompleted")
  192. }
  193. }
  194. Row {
  195. AppText {
  196. id: photoclarity_text
  197. width: parent.width
  198. text: frames.fpsString
  199. color: "red"
  200. }
  201. AppText {
  202. visible: true//app.photoclarity
  203. id: photoclarity2_text
  204. anchors.top: photoclarity_text.bottom
  205. width: parent.width
  206. text: frames.qulityString
  207. color: "green"
  208. }
  209. }
  210. }
  211. ScrollView
  212. {
  213. SplitView.preferredWidth: parent.width*0.29
  214. SplitView.minimumWidth: 200
  215. clip: true
  216. Column {
  217. spacing: dp(15)
  218. Row {
  219. spacing: 80
  220. AppText {
  221. id: text_title
  222. text: "测试调试"
  223. font.bold: true
  224. color: "#28a779"
  225. fontSize: 20
  226. }
  227. AppText {
  228. id: apptext_res
  229. text: "[测试结果]"
  230. fontSize:15
  231. color: "grey"
  232. anchors.verticalCenter: text_title.verticalCenter
  233. }
  234. }
  235. Row {
  236. spacing: 100
  237. AppText{
  238. text: "一键测试"
  239. fontSize: 15
  240. color: app.fontColor
  241. //font.bold: true
  242. anchors.verticalCenter: autotest_switch.verticalCenter
  243. }
  244. AppSwitch {
  245. id: autotest_switch
  246. onToggled: {
  247. if(autotest_switch.checked==true){
  248. autotest_switch.enabled = false
  249. serial.sendCmd("autotest",true,"","");
  250. t_autotest.start()
  251. }else{
  252. console.log("t_autotest 计数:",t_autotest.interval)
  253. }
  254. }
  255. }
  256. Timer {
  257. id: t_autotest
  258. interval: 1000*60
  259. running: false
  260. repeat: false
  261. onTriggered: {
  262. autotest_switch.enabled = true
  263. autotest_switch.checked = false
  264. }
  265. }
  266. }
  267. Row {
  268. spacing: 100
  269. AppText{
  270. text: "风机测试"
  271. color: app.fontColor
  272. fontSize: 15
  273. //font.bold: true
  274. anchors.verticalCenter: fantest_switch.verticalCenter
  275. }
  276. AppSwitch {
  277. id: fantest_switch
  278. onToggled: {
  279. if(fantest_switch.checked==true){
  280. serial.sendCmd("fan",true,"","");
  281. apptext_res.text = "打开风机"
  282. }else{
  283. serial.sendCmd("fan",false,"","");
  284. apptext_res.text = "关闭风机"
  285. }
  286. }
  287. }
  288. }
  289. Row {
  290. spacing: 100
  291. AppText{
  292. text: "胶带测试"
  293. fontSize: 15
  294. color: app.fontColor
  295. //font.bold: true
  296. anchors.verticalCenter: jiaodai_switch.verticalCenter
  297. }
  298. AppSwitch {
  299. id: jiaodai_switch
  300. onToggled: {
  301. if(jiaodai_switch.checked==true){
  302. //jiaodai_switch.enabled = false
  303. apptext_res.text = "胶带测试开始"
  304. serial.sendCmd("jiaodai",true,"","");
  305. }
  306. }
  307. }
  308. }
  309. Row {
  310. spacing: 100
  311. AppText{
  312. text: "补光测试"
  313. color: app.fontColor
  314. fontSize: 15
  315. //font.bold: true
  316. anchors.verticalCenter: led_switch.verticalCenter
  317. }
  318. AppSwitch {
  319. id: led_switch
  320. onToggled: {
  321. if(led_switch.checked==true){
  322. serial.sendCmd("led",true,"","");
  323. apptext_res.text = "补光灯已打开"
  324. }else{
  325. serial.sendCmd("led",false,"","");
  326. apptext_res.text = "补光灯已关闭"
  327. }
  328. }
  329. }
  330. }
  331. Row {
  332. spacing: 100
  333. AppText{
  334. text: "立即拍照"
  335. color: app.fontColor
  336. fontSize: 15
  337. //font.bold: true
  338. anchors.verticalCenter: takephoto_switch.verticalCenter
  339. }
  340. AppSwitch {
  341. id: takephoto_switch
  342. onToggled: {
  343. if(takephoto_switch.checked==true){
  344. apptext_res.text = "立即拍照"
  345. frames.captureImage()
  346. }
  347. }
  348. }
  349. }
  350. Row {
  351. spacing: 100
  352. AppText{
  353. text: "对焦拍照"
  354. color: app.fontColor
  355. fontSize: 15
  356. //font.bold: true
  357. anchors.verticalCenter: focus_switch.verticalCenter
  358. }
  359. AppSwitch {
  360. id: focus_switch
  361. onToggled: {
  362. if(focus_switch.checked==true){
  363. apptext_res.text = "开始对焦"
  364. focus_switch.enabled = false
  365. serial.auto_takephoto(true)
  366. }
  367. }
  368. }
  369. }
  370. AppText {
  371. id: text_title2
  372. text: "三轴步进电机控制"
  373. font.bold: true
  374. color: "#28a779"
  375. fontSize: 20
  376. }
  377. // 轴选择
  378. Row {
  379. spacing: dp(1)
  380. width: parent.width
  381. AppText {
  382. text: "选择轴:"
  383. width: dp(60) // 固定文本宽度
  384. anchors.verticalCenter: parent.verticalCenter
  385. }
  386. ComboBox {
  387. width: parent.width - dp(60) // 剩余宽度
  388. height: dp(40)
  389. model: ["X轴", "Y轴", "Z轴"]
  390. onCurrentIndexChanged: currentAxis = currentIndex
  391. }
  392. AppButton{
  393. text: "校准"
  394. textColor: "black"
  395. flat: false
  396. borderColor: "black"
  397. borderWidth: dp(1)
  398. backgroundColor: "white"
  399. minimumHeight: dp(30)
  400. minimumWidth: dp(50)
  401. onClicked:
  402. {
  403. autotake(false)
  404. if(currentAxis==0)
  405. {
  406. console.log("校准X")
  407. serial.sendCmd("calibrate",false,"x",speed.toString())
  408. }else if(currentAxis==1)
  409. {
  410. console.log("校准Y")
  411. serial.sendCmd("calibrate",false,"y",speed.toString())
  412. }else if(currentAxis==2)
  413. {
  414. console.log("校准Z")
  415. serial.sendCmd("calibrate",false,"z",speed.toString())
  416. }
  417. }
  418. }
  419. }
  420. // 速度调节
  421. Row {
  422. spacing: dp(2)
  423. width: parent.width
  424. AppText {
  425. text: "速度:"
  426. width: dp(40) // 固定文本宽度
  427. anchors.verticalCenter: parent.verticalCenter
  428. }
  429. AppSlider {
  430. width: parent.width - dp(60) // 剩余宽度
  431. from: 0
  432. to: 100
  433. value: speed
  434. stepSize: 1
  435. onValueChanged: speed = value
  436. anchors.verticalCenter: parent.verticalCenter
  437. }
  438. AppText {
  439. text: speed
  440. width: dp(40) // 固定文本宽度
  441. anchors.verticalCenter: parent.verticalCenter
  442. }
  443. }
  444. // 步进距离设置
  445. Row {
  446. spacing: dp(10)
  447. width: parent.width
  448. AppText {
  449. text: "步进脉冲次数:"
  450. width: dp(120) // 固定文本宽度
  451. anchors.verticalCenter: parent.verticalCenter
  452. }
  453. AppTextField {
  454. id: step_apptextfield
  455. width: parent.width - dp(120) // 剩余宽度
  456. text: stepDistance
  457. validator: IntValidator { bottom: 0; top: 2000 }
  458. onTextChanged: stepDistance = parseInt(text)
  459. }
  460. }
  461. // 运动控制按钮
  462. Row {
  463. spacing: dp(10)
  464. width: parent.width
  465. AppButton {
  466. text: " 正转 "
  467. textColor: "black"
  468. flat: false
  469. borderColor: "black"
  470. borderWidth: dp(1)
  471. backgroundColor: "grey"
  472. minimumHeight: dp(30)
  473. minimumWidth: dp(50)
  474. width: (parent.width - dp(30))/3 // 平均分配宽度
  475. onClicked:
  476. {
  477. if(currentAxis==0)
  478. {
  479. console.log("X轴正转:",stepDistance)
  480. serial.sendCmd("movx",false,"f"+stepDistance,speed.toString())
  481. }else if(currentAxis==1)
  482. {
  483. console.log("Y轴正转:",stepDistance)
  484. serial.sendCmd("movy",false,"f"+stepDistance,speed.toString())
  485. }else if(currentAxis==2)
  486. {
  487. console.log("Z轴正转:",stepDistance)
  488. serial.sendCmd("movz",false,"f"+stepDistance,speed.toString())
  489. }
  490. }
  491. }
  492. AppButton {
  493. text: " 停止 "
  494. textColor: "black"
  495. flat: false
  496. borderColor: "black"
  497. borderWidth: dp(1)
  498. backgroundColor: "red"
  499. minimumHeight: dp(30)
  500. minimumWidth: dp(50)
  501. width: (parent.width - dp(30))/3 // 平均分配宽度
  502. onClicked:
  503. {
  504. console.log("停止")
  505. serial.sendCmd("movx",false,"f0","")
  506. }
  507. }
  508. AppButton {
  509. text: " 反转 "
  510. textColor: "black"
  511. flat: false
  512. borderColor: "black"
  513. borderWidth: dp(1)
  514. backgroundColor: "grey"
  515. minimumHeight: dp(30)
  516. minimumWidth: dp(50)
  517. width: (parent.width - dp(30))/3 // 平均分配宽度
  518. onClicked:
  519. {
  520. if(currentAxis==0)
  521. {
  522. console.log("X轴反转:",stepDistance)
  523. serial.sendCmd("movx",false,"b"+stepDistance,speed.toString())
  524. }else if(currentAxis==1)
  525. {
  526. console.log("Y轴反转:",stepDistance)
  527. serial.sendCmd("movy",false,"b"+stepDistance,speed.toString())
  528. }else if(currentAxis==2)
  529. {
  530. console.log("Z轴反转:",stepDistance)
  531. serial.sendCmd("movz",false,"b"+stepDistance,speed.toString())
  532. }
  533. }
  534. }
  535. AppButton {
  536. text: " 复位 "
  537. textColor: "black"
  538. flat: false
  539. borderColor: "black"
  540. borderWidth: dp(1)
  541. backgroundColor: "grey"
  542. minimumHeight: dp(30)
  543. minimumWidth: dp(50)
  544. width: (parent.width - dp(30))/3 // 平均分配宽度
  545. onClicked: {
  546. if(currentAxis==0)
  547. {
  548. console.log("X轴复位!")
  549. serial.sendCmd("movx",true,"",speed.toString())
  550. }else if(currentAxis==1)
  551. {
  552. console.log("Y轴复位!")
  553. serial.sendCmd("movy",true,"",speed.toString())
  554. }else if(currentAxis==2)
  555. {
  556. console.log("Z轴复位!")
  557. serial.sendCmd("movz",true,"",speed.toString())
  558. }
  559. }
  560. }
  561. }
  562. AppText {
  563. id: text_camera
  564. text: "相机参数"
  565. font.bold: true
  566. color: "#28a779"
  567. fontSize: 20
  568. }
  569. Row {
  570. spacing: dp(10)
  571. width: parent.width
  572. AppText {
  573. id: txt_fExposureTime
  574. text: "曝光值:"
  575. }
  576. AppTextField {
  577. anchors.verticalCenter: txt_fExposureTime.verticalCenter
  578. placeholderText: fExposureTime
  579. text: fExposureTime
  580. width: parent.width - dp(10) // 剩余宽度
  581. EnterKey.type: Qt.EnterKeyDone
  582. wrapMode: Text.NoWrap
  583. inputMethodHints: Qt.ImhFormattedNumbersOnly |
  584. Qt.ImhPreferDone |
  585. Qt.ImhNoPredictiveText
  586. validator: DoubleValidator {
  587. bottom: 100.00 // 最小值
  588. top: 500000.00 // 最大值
  589. decimals: 0
  590. }
  591. // 🔥 关键 3:兜底(IME 再作妖也不怕)
  592. Keys.onReturnPressed: {
  593. frames.cam_ExposureTime = text
  594. console.log("设置曝光时间:",text)
  595. Qt.inputMethod.hide()
  596. }
  597. onAccepted: {
  598. frames.cam_ExposureTime = text
  599. console.log("设置曝光时间",text)
  600. }
  601. }
  602. }
  603. }
  604. }
  605. }
  606. }