TestPage.qml 24 KB

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