TestPage.qml 25 KB

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