TestPage.qml 24 KB

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