TestPage.qml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. import QtQuick
  2. import Felgo
  3. import QtMultimedia
  4. import QtQuick.Controls
  5. // import QtQuick.Controls.Material 2.0 // 移除:与Felgo主题冲突,导致AppSwitch颜色异常
  6. import "../controls"
  7. import "../common"
  8. import Frames 0.1
  9. AppPage {
  10. objectName: "autoFocus_Page"
  11. navigationBarHidden: true
  12. backgroundColor: app.theme_backgroundColor
  13. property var videoFormats
  14. // 定义电机状态
  15. property int currentAxis: 0 // 当前选择的轴 (0: X, 1: Y, 2: Z)
  16. property var axisPositions: [0, 0, 0] // 各轴当前位置
  17. property int speed: 50 // 当前速度 (0-100)
  18. property int stepDistance: 20 // 步进脉冲数量
  19. property string fExposureTime: "0"
  20. function autotake(sw){
  21. if(sw)
  22. {
  23. console.log("autotakestart")
  24. frames.camera_sw = true
  25. //frames.auto_clicked = true //开始对焦
  26. auto_timer.start() //启动对焦定时器
  27. console.log("相机已打开")
  28. photoTimer.interval=60*1000
  29. photoTimer.start()
  30. }else{
  31. frames.camera_sw = true
  32. console.log("打开相机单次拍照!")
  33. }
  34. }
  35. Frames {
  36. objectName: "Frames"
  37. id: frames
  38. videoSink: output.videoSink
  39. onCameraOpenFailed:function(err){
  40. console.log("onCameraOpenFailed",err)
  41. nativeUtils.displayMessageBox("相机打开失败!",err,1)
  42. focus_switch.checked = false
  43. focus_switch.enabled = true
  44. takephoto_switch.checked = false
  45. takephoto_switch.enabled = true
  46. }
  47. onVideoSinkChanged: {
  48. console.log("onVideoSinkChanged")
  49. photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
  50. }
  51. onQulityStringChanged: {
  52. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  53. photoTimer.interval = 180*1000 //3分钟超时
  54. photoTimer.restart()
  55. }
  56. onCameraStaChanged: function(sta_cam) {
  57. if(sta_cam){
  58. //camera.active = sta_cam
  59. //camera.start()
  60. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  61. output.visible = sta_cam
  62. photoTimer.interval = 180*1000 //3分钟超时
  63. photoTimer.start()
  64. //uvc_camera.visible = false
  65. }else{
  66. //camera.active = sta_cam
  67. //camera.stop()
  68. output.visible= sta_cam
  69. photoTimer.stop() //停止计时器
  70. //uvc_camera.visible = true
  71. }
  72. console.log("相机状态改变",sta_cam)
  73. }
  74. onStepCountChanged: function(step){
  75. console.log("坐标改变",step)
  76. step_apptextfield.text = step
  77. }
  78. onExposureTimeChanged: {
  79. fExposureTime = frames.cam_ExposureTime
  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. function onTakephotodone() {
  108. console.log("立即拍照完成!")
  109. apptext_res.text = "立即拍照完成!"
  110. focus_switch.enabled = true
  111. focus_switch.checked = false
  112. }
  113. function onAutotestdone() {
  114. console.log("自动对焦完成!")
  115. apptext_res.text = "自动对焦完成!"
  116. autotest_switch.enabled = true
  117. autotest_switch.checked = false
  118. }
  119. function onTranslatedone() {
  120. console.log("胶带传送完成!")
  121. apptext_res.text = "胶带传送完成!"
  122. jiaodai_switch.enabled = true
  123. jiaodai_switch.checked = false
  124. }
  125. }
  126. SplitView{
  127. anchors.fill: parent
  128. orientation: Qt.Horizontal
  129. Rectangle {
  130. SplitView.preferredWidth: 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. VideoOutput{
  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. ScrollView
  190. {
  191. SplitView.preferredWidth: parent.width*0.29
  192. SplitView.minimumWidth: 200
  193. clip: true
  194. Column {
  195. width: parent.width
  196. spacing: dp(15)
  197. Row {
  198. spacing: 80
  199. AppText {
  200. id: text_title
  201. text: "测试调试"
  202. font.bold: true
  203. color: "#28a779"
  204. fontSize: 20
  205. }
  206. AppText {
  207. id: apptext_res
  208. text: "[测试结果]"
  209. fontSize:15
  210. color: "grey"
  211. anchors.verticalCenter: text_title.verticalCenter
  212. }
  213. }
  214. Row {
  215. spacing: 100
  216. AppText{
  217. text: "一键测试"
  218. fontSize: 15
  219. color: app.fontColor
  220. //font.bold: true
  221. anchors.verticalCenter: autotest_switch.verticalCenter
  222. }
  223. AppSwitch {
  224. id: autotest_switch
  225. onToggled: {
  226. if(autotest_switch.checked==true){
  227. autotest_switch.enabled = false
  228. serial.sendCmd("autotest",true,"","");
  229. t_autotest.start()
  230. }else{
  231. console.log("t_autotest 计数:",t_autotest.interval)
  232. }
  233. }
  234. }
  235. Timer {
  236. id: t_autotest
  237. interval: 1000*60
  238. running: false
  239. repeat: false
  240. onTriggered: {
  241. autotest_switch.enabled = true
  242. autotest_switch.checked = false
  243. }
  244. }
  245. }
  246. Row {
  247. spacing: 100
  248. AppText{
  249. text: "风机测试"
  250. color: app.fontColor
  251. fontSize: 15
  252. //font.bold: true
  253. anchors.verticalCenter: fantest_switch.verticalCenter
  254. }
  255. AppSwitch {
  256. id: fantest_switch
  257. onToggled: {
  258. if(fantest_switch.checked==true){
  259. serial.sendCmd("fan",true,"","");
  260. apptext_res.text = "打开风机"
  261. }else{
  262. serial.sendCmd("fan",false,"","");
  263. apptext_res.text = "关闭风机"
  264. }
  265. }
  266. }
  267. }
  268. Row {
  269. spacing: 100
  270. AppText{
  271. text: "胶带测试"
  272. fontSize: 15
  273. color: app.fontColor
  274. //font.bold: true
  275. anchors.verticalCenter: jiaodai_switch.verticalCenter
  276. }
  277. AppSwitch {
  278. id: jiaodai_switch
  279. onToggled: {
  280. if(jiaodai_switch.checked==true){
  281. //jiaodai_switch.enabled = false
  282. apptext_res.text = "胶带测试开始"
  283. serial.sendCmd("jiaodai",true,"","");
  284. }
  285. }
  286. }
  287. }
  288. Row {
  289. spacing: 100
  290. AppText{
  291. text: "补光测试"
  292. color: app.fontColor
  293. fontSize: 15
  294. //font.bold: true
  295. anchors.verticalCenter: led_switch.verticalCenter
  296. }
  297. AppSwitch {
  298. id: led_switch
  299. onToggled: {
  300. if(led_switch.checked==true){
  301. serial.sendCmd("led",true,"","");
  302. apptext_res.text = "补光灯已打开"
  303. }else{
  304. serial.sendCmd("led",false,"","");
  305. apptext_res.text = "补光灯已关闭"
  306. }
  307. }
  308. }
  309. }
  310. Row {
  311. spacing: 100
  312. AppText{
  313. text: "立即拍照"
  314. color: app.fontColor
  315. fontSize: 15
  316. //font.bold: true
  317. anchors.verticalCenter: takephoto_switch.verticalCenter
  318. }
  319. AppSwitch {
  320. id: takephoto_switch
  321. onToggled: {
  322. if(takephoto_switch.checked==true){
  323. apptext_res.text = "立即拍照"
  324. frames.captureImage()
  325. }
  326. }
  327. }
  328. }
  329. Row {
  330. spacing: 100
  331. AppText{
  332. text: "对焦拍照"
  333. color: app.fontColor
  334. fontSize: 15
  335. //font.bold: true
  336. anchors.verticalCenter: focus_switch.verticalCenter
  337. }
  338. AppSwitch {
  339. id: focus_switch
  340. onToggled: {
  341. if(focus_switch.checked==true){
  342. apptext_res.text = "开始对焦"
  343. focus_switch.enabled = false
  344. serial.auto_takephoto(true)
  345. }
  346. }
  347. }
  348. }
  349. AppText {
  350. id: text_title2
  351. text: "步进电机控制"
  352. font.bold: true
  353. color: "#28a779"
  354. fontSize: 20
  355. }
  356. // 轴选择
  357. Row {
  358. spacing: dp(1)
  359. width: parent.width
  360. AppText {
  361. text: "选择轴:"
  362. width: dp(60) // 固定文本宽度
  363. anchors.verticalCenter: parent.verticalCenter
  364. }
  365. ComboBox {
  366. width: parent.width - dp(60) // 剩余宽度
  367. height: dp(40)
  368. model: ["Y轴"]
  369. onCurrentIndexChanged: currentAxis = currentIndex
  370. }
  371. AppButton{
  372. text: "校准"
  373. textColor: "black"
  374. flat: false
  375. borderColor: "black"
  376. borderWidth: dp(1)
  377. backgroundColor: "white"
  378. minimumHeight: dp(30)
  379. minimumWidth: dp(50)
  380. onClicked:
  381. {
  382. autotake(false)
  383. if(currentAxis==0)
  384. {
  385. console.log("校准Y")
  386. serial.sendCmd("calibrate",false,"y",speed.toString())
  387. }
  388. }
  389. }
  390. }
  391. // 速度调节
  392. Row {
  393. spacing: dp(2)
  394. width: parent.width
  395. AppText {
  396. text: "速度:"
  397. width: dp(40) // 固定文本宽度
  398. anchors.verticalCenter: parent.verticalCenter
  399. }
  400. AppSlider {
  401. width: parent.width - dp(60) // 剩余宽度
  402. from: 0
  403. to: 100
  404. value: speed
  405. stepSize: 1
  406. onValueChanged: speed = value
  407. anchors.verticalCenter: parent.verticalCenter
  408. }
  409. AppText {
  410. text: speed
  411. width: dp(40) // 固定文本宽度
  412. anchors.verticalCenter: parent.verticalCenter
  413. }
  414. }
  415. // 步进距离设置
  416. Row {
  417. spacing: dp(10)
  418. width: parent.width
  419. AppText {
  420. text: "步进脉冲次数:"
  421. width: dp(120) // 固定文本宽度
  422. anchors.verticalCenter: parent.verticalCenter
  423. }
  424. AppTextField {
  425. id: step_apptextfield
  426. width: parent.width - dp(120) // 剩余宽度
  427. text: stepDistance
  428. validator: IntValidator { bottom: 0; top: 2000 }
  429. onTextChanged: stepDistance = parseInt(text)
  430. }
  431. }
  432. // 运动控制按钮
  433. Row {
  434. spacing: dp(10)
  435. width: parent.width
  436. AppButton {
  437. text: " 正转 "
  438. textColor: "black"
  439. flat: false
  440. borderColor: "black"
  441. borderWidth: dp(1)
  442. backgroundColor: "grey"
  443. minimumHeight: dp(30)
  444. minimumWidth: dp(50)
  445. width: (parent.width - dp(30))/3 // 平均分配宽度
  446. onClicked:
  447. {
  448. if(currentAxis==0)
  449. {
  450. console.log("Y轴正转:",stepDistance)
  451. serial.sendCmd("movy",false,"f"+stepDistance,speed.toString())
  452. }
  453. }
  454. }
  455. AppButton {
  456. text: " 停止 "
  457. textColor: "black"
  458. flat: false
  459. borderColor: "black"
  460. borderWidth: dp(1)
  461. backgroundColor: "red"
  462. minimumHeight: dp(30)
  463. minimumWidth: dp(50)
  464. width: (parent.width - dp(30))/3 // 平均分配宽度
  465. onClicked:
  466. {
  467. console.log("停止")
  468. serial.sendCmd("movy",false,"f0","")
  469. }
  470. }
  471. AppButton {
  472. text: " 反转 "
  473. textColor: "black"
  474. flat: false
  475. borderColor: "black"
  476. borderWidth: dp(1)
  477. backgroundColor: "grey"
  478. minimumHeight: dp(30)
  479. minimumWidth: dp(50)
  480. width: (parent.width - dp(30))/3 // 平均分配宽度
  481. onClicked:
  482. {
  483. if(currentAxis==0)
  484. {
  485. console.log("Y轴反转:",stepDistance)
  486. serial.sendCmd("movy",false,"b"+stepDistance,speed.toString())
  487. }
  488. }
  489. }
  490. AppButton {
  491. text: " 复位 "
  492. textColor: "black"
  493. flat: false
  494. borderColor: "black"
  495. borderWidth: dp(1)
  496. backgroundColor: "grey"
  497. minimumHeight: dp(30)
  498. minimumWidth: dp(50)
  499. width: (parent.width - dp(30))/3 // 平均分配宽度
  500. onClicked: {
  501. if(currentAxis==0)
  502. {
  503. console.log("Y轴复位!")
  504. serial.sendCmd("movy",true,"",speed.toString())
  505. }
  506. }
  507. }
  508. }
  509. AppText {
  510. id: text_camera
  511. text: "相机参数"
  512. font.bold: true
  513. color: "#28a779"
  514. fontSize: 20
  515. }
  516. Row {
  517. spacing: dp(10)
  518. width: parent.width
  519. AppText {
  520. id: txt_fExposureTime
  521. text: "曝光值:"
  522. }
  523. AppTextField {
  524. anchors.verticalCenter: txt_fExposureTime.verticalCenter
  525. placeholderText: fExposureTime
  526. text: fExposureTime
  527. width: parent.width - dp(10) // 剩余宽度
  528. EnterKey.type: Qt.EnterKeyDone
  529. wrapMode: Text.NoWrap
  530. inputMethodHints: Qt.ImhFormattedNumbersOnly |
  531. Qt.ImhPreferDone |
  532. Qt.ImhNoPredictiveText
  533. validator: DoubleValidator {
  534. bottom: 100.00 // 最小值
  535. top: 500000.00 // 最大值
  536. decimals: 0
  537. }
  538. // 🔥 关键 3:兜底(IME 再作妖也不怕)
  539. Keys.onReturnPressed: {
  540. frames.cam_ExposureTime = text
  541. console.log("设置曝光时间:",text)
  542. Qt.inputMethod.hide()
  543. }
  544. onAccepted: {
  545. frames.cam_ExposureTime = text
  546. console.log("设置曝光时间",text)
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. }