TestPage.qml 24 KB

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