TestPage.qml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. function autotake(sw){
  20. if(sw)
  21. {
  22. console.log("autotakestart")
  23. frames.camera_sw = true
  24. //frames.auto_clicked = true //开始对焦
  25. auto_timer.start() //启动对焦定时器
  26. console.log("相机已打开")
  27. photoTimer.interval=60*1000
  28. photoTimer.start()
  29. }else{
  30. frames.camera_sw = true
  31. console.log("打开相机单次拍照!")
  32. }
  33. }
  34. Frames {
  35. objectName: "Frames"
  36. id: frames
  37. videoSink: output.videoSink
  38. onCameraOpenFailed:function(err){
  39. console.log("onCameraOpenFailed",err)
  40. nativeUtils.displayMessageBox("相机打开失败!",err,1)
  41. focus_switch.checked = false
  42. focus_switch.enabled = true
  43. takephoto_switch.checked = false
  44. takephoto_switch.enabled = true
  45. }
  46. onVideoSinkChanged: {
  47. console.log("onVideoSinkChanged")
  48. photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
  49. }
  50. onQulityStringChanged: {
  51. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  52. photoTimer.interval = 180*1000 //3分钟超时
  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 = 180*1000 //3分钟超时
  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. onStepCountChanged: function(step){
  74. console.log("坐标改变",step)
  75. step_apptextfield.text = step
  76. }
  77. }
  78. Timer {
  79. id: photoTimer
  80. interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  81. running: false // 初始状态下定时器停止
  82. repeat: false // 设置为false,以便只执行一次
  83. onTriggered: {
  84. // 定时器触发后,设置按钮可用
  85. // camera.active = false
  86. // camera.stop()
  87. output.visible = false
  88. frames.camera_sw = false
  89. }
  90. }
  91. Timer {
  92. id: auto_timer
  93. interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  94. running: false // 初始状态下定时器停止
  95. repeat: false // 设置为false,以便只执行一次
  96. onTriggered: {
  97. // 定时器触发后,开始对焦
  98. frames.auto_clicked = true
  99. }
  100. }
  101. Connections {
  102. target: serial
  103. function onTakephotodone() {
  104. console.log("立即拍照完成!")
  105. apptext_res.text = "立即拍照完成!"
  106. focus_switch.enabled = true
  107. focus_switch.checked = false
  108. }
  109. function onAutotestdone() {
  110. console.log("自动对焦完成!")
  111. apptext_res.text = "自动对焦完成!"
  112. autotest_switch.enabled = true
  113. autotest_switch.checked = false
  114. }
  115. function onTranslatedone() {
  116. console.log("胶带传送完成!")
  117. apptext_res.text = "胶带传送完成!"
  118. jiaodai_switch.enabled = true
  119. jiaodai_switch.checked = false
  120. }
  121. }
  122. Row{
  123. anchors.fill: parent
  124. spacing: 5
  125. Rectangle {
  126. width: parent.width*0.7
  127. height: parent.height
  128. color: app.cardColor
  129. radius: 5
  130. AppButton {
  131. id: normButton
  132. //anchors.horizontalCenter: parent.horizontalCenter
  133. anchors.centerIn: parent
  134. anchors.fill: parent
  135. //text: "打开相机"
  136. flat: true //边框是否可视
  137. onClicked: {
  138. console.log("相机状态:",frames.camera_sw)
  139. //if(camera.active){
  140. if(frames.camera_sw){
  141. text = "相机已关闭"
  142. output.visible = false
  143. frames.camera_sw = false
  144. //uvc_camera.visible = false
  145. }else{
  146. text = "打开相机"
  147. output.visible = true
  148. frames.camera_sw = true
  149. //uvc_camera.visible = true
  150. }
  151. }
  152. AppImage{
  153. id: image_picdis
  154. anchors.centerIn: parent
  155. source: "../../assets/photoico.svg"
  156. }
  157. }
  158. // AppImage {
  159. // id: uvc_camera
  160. // visible: false
  161. // anchors.fill: parent
  162. // cache: false
  163. // source: "image://UCamera"
  164. // }
  165. VideoOutput
  166. {
  167. id: output
  168. anchors.fill: parent
  169. visible: false
  170. fillMode: VideoOutput.PreserveAspectFit //根据视频的纵横比例等比例缩放
  171. //fillMode: VideoOutput.Stretch
  172. Component.onCompleted: {
  173. console.log("output onCompleted")
  174. }
  175. }
  176. Row {
  177. AppText {
  178. id: photoclarity_text
  179. width: parent.width
  180. text: frames.fpsString
  181. color: "red"
  182. }
  183. AppText {
  184. visible: true//app.photoclarity
  185. id: photoclarity2_text
  186. anchors.top: photoclarity_text.bottom
  187. width: parent.width
  188. text: frames.qulityString
  189. color: "green"
  190. }
  191. }
  192. }
  193. Rectangle {
  194. width: parent.width*0.29
  195. height: parent.height
  196. color: app.cardColor
  197. radius: 5
  198. Column {
  199. id: testContent
  200. anchors.top: parent.top
  201. anchors.topMargin: dp(10)
  202. anchors.left: parent.left
  203. anchors.leftMargin: dp(10)
  204. anchors.right: parent.right
  205. spacing: dp(10)
  206. AppText {
  207. id: text_title
  208. text: "测试调试"
  209. font.bold: true
  210. color: "#28a779"
  211. fontSize: 20
  212. }
  213. AppText {
  214. id: apptext_res
  215. text: "[测试结果]"
  216. fontSize: 15
  217. color: "grey"
  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. }
  245. AppSwitch {
  246. id: fantest_switch
  247. onToggled: {
  248. if(fantest_switch.checked==true){
  249. serial.sendCmd("fan",true,"","");
  250. apptext_res.text = "打开风机"
  251. }else{
  252. serial.sendCmd("fan",false,"","");
  253. apptext_res.text = "关闭风机"
  254. }
  255. }
  256. }
  257. }
  258. Row {
  259. spacing: 100
  260. AppText{
  261. text: "胶带测试"
  262. fontSize: 15
  263. color: app.fontColor
  264. }
  265. AppSwitch {
  266. id: jiaodai_switch
  267. onToggled: {
  268. if(jiaodai_switch.checked==true){
  269. //jiaodai_switch.enabled = false
  270. apptext_res.text = "胶带测试开始"
  271. serial.sendCmd("jiaodai",true,"","");
  272. }
  273. }
  274. }
  275. }
  276. Row {
  277. spacing: 100
  278. AppText{
  279. text: "补光测试"
  280. color: app.fontColor
  281. fontSize: 15
  282. }
  283. AppSwitch {
  284. id: led_switch
  285. onToggled: {
  286. if(led_switch.checked==true){
  287. serial.sendCmd("led",true,"","");
  288. apptext_res.text = "补光灯已打开"
  289. }else{
  290. serial.sendCmd("led",false,"","");
  291. apptext_res.text = "补光灯已关闭"
  292. }
  293. }
  294. }
  295. }
  296. Row {
  297. spacing: 100
  298. AppText{
  299. text: "立即拍照"
  300. color: app.fontColor
  301. fontSize: 15
  302. }
  303. AppSwitch {
  304. id: takephoto_switch
  305. onToggled: {
  306. if(takephoto_switch.checked==true){
  307. apptext_res.text = "立即拍照"
  308. frames.captureImage()
  309. }
  310. }
  311. }
  312. }
  313. Row {
  314. spacing: 100
  315. AppText{
  316. text: "对焦拍照"
  317. color: app.fontColor
  318. fontSize: 15
  319. }
  320. AppSwitch {
  321. id: focus_switch
  322. onToggled: {
  323. if(focus_switch.checked==true){
  324. apptext_res.text = "开始对焦"
  325. focus_switch.enabled = false
  326. serial.auto_takephoto(true)
  327. }
  328. }
  329. }
  330. }
  331. AppText {
  332. id: text_title2
  333. text: "步进电机控制"
  334. font.bold: true
  335. color: "#28a779"
  336. fontSize: 20
  337. }
  338. // 轴选择
  339. Row {
  340. spacing: dp(1)
  341. width: parent.width
  342. AppText {
  343. text: "选择轴:"
  344. width: dp(60) // 固定文本宽度
  345. anchors.verticalCenter: parent.verticalCenter
  346. }
  347. ComboBox {
  348. width: parent.width - dp(60) // 剩余宽度
  349. model: ["Y轴"]
  350. onCurrentIndexChanged: currentAxis = currentIndex
  351. }
  352. AppButton{
  353. text: "校准"
  354. textColor: "black"
  355. flat: false
  356. borderColor: "black"
  357. borderWidth: dp(1)
  358. backgroundColor: "white"
  359. minimumHeight: dp(30)
  360. minimumWidth: dp(50)
  361. onClicked:
  362. {
  363. autotake(false)
  364. if(currentAxis==0)
  365. {
  366. console.log("校准Y")
  367. serial.sendCmd("calibrate",false,"y",speed.toString())
  368. }else if(currentAxis==1)
  369. {
  370. console.log("校准Y")
  371. serial.sendCmd("calibrate",false,"y",speed.toString())
  372. }else if(currentAxis==2)
  373. {
  374. console.log("校准Z")
  375. serial.sendCmd("calibrate",false,"z",speed.toString())
  376. }
  377. }
  378. }
  379. }
  380. // 速度调节
  381. Row {
  382. spacing: dp(2)
  383. width: parent.width
  384. AppText {
  385. text: "速度:"
  386. width: dp(40) // 固定文本宽度
  387. anchors.verticalCenter: parent.verticalCenter
  388. }
  389. AppSlider {
  390. width: parent.width - dp(60) // 剩余宽度
  391. from: 0
  392. to: 100
  393. value: speed
  394. stepSize: 1
  395. onValueChanged: speed = value
  396. anchors.verticalCenter: parent.verticalCenter
  397. }
  398. AppText {
  399. text: speed
  400. width: dp(40) // 固定文本宽度
  401. anchors.verticalCenter: parent.verticalCenter
  402. }
  403. }
  404. // 步进距离设置
  405. Row {
  406. spacing: dp(10)
  407. width: parent.width
  408. AppText {
  409. text: "步进脉冲次数:"
  410. width: dp(120) // 固定文本宽度
  411. anchors.verticalCenter: parent.verticalCenter
  412. }
  413. AppTextField {
  414. id: step_apptextfield
  415. width: parent.width - dp(120) // 剩余宽度
  416. text: stepDistance
  417. validator: IntValidator { bottom: 0; top: 2000 }
  418. onTextChanged: stepDistance = parseInt(text)
  419. }
  420. }
  421. // 运动控制按钮
  422. Row {
  423. spacing: dp(10)
  424. width: parent.width
  425. AppButton {
  426. text: " 正转 "
  427. textColor: "black"
  428. flat: false
  429. borderColor: "black"
  430. borderWidth: dp(1)
  431. backgroundColor: "grey"
  432. minimumHeight: dp(30)
  433. minimumWidth: dp(50)
  434. width: (parent.width - dp(30))/3 // 平均分配宽度
  435. onClicked:
  436. {
  437. if(currentAxis==0)
  438. {
  439. console.log("Y轴正转:",stepDistance)
  440. serial.sendCmd("movy",false,"f"+stepDistance,speed.toString())
  441. }
  442. }
  443. }
  444. AppButton {
  445. text: " 停止 "
  446. textColor: "black"
  447. flat: false
  448. borderColor: "black"
  449. borderWidth: dp(1)
  450. backgroundColor: "red"
  451. minimumHeight: dp(30)
  452. minimumWidth: dp(50)
  453. width: (parent.width - dp(30))/3 // 平均分配宽度
  454. onClicked:
  455. {
  456. console.log("停止")
  457. serial.sendCmd("movy",false,"f0","")
  458. }
  459. }
  460. AppButton {
  461. text: " 反转 "
  462. textColor: "black"
  463. flat: false
  464. borderColor: "black"
  465. borderWidth: dp(1)
  466. backgroundColor: "grey"
  467. minimumHeight: dp(30)
  468. minimumWidth: dp(50)
  469. width: (parent.width - dp(30))/3 // 平均分配宽度
  470. onClicked:
  471. {
  472. if(currentAxis==0)
  473. {
  474. console.log("Y轴反转:",stepDistance)
  475. serial.sendCmd("movy",false,"b"+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: "grey"
  486. minimumHeight: dp(30)
  487. minimumWidth: dp(50)
  488. width: (parent.width - dp(30))/3 // 平均分配宽度
  489. onClicked: {
  490. if(currentAxis==0)
  491. {
  492. console.log("Y轴复位!")
  493. serial.sendCmd("movy",true,"",speed.toString())
  494. }
  495. }
  496. }
  497. }
  498. }
  499. }
  500. }
  501. }