TestPage.qml 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. import QtQuick
  2. import Felgo
  3. import QtMultimedia
  4. import QtQuick.Controls
  5. import QtQuick.Layouts
  6. import Qt.labs.settings 1.0 as QtLabs
  7. import QtQuick.Controls.Material 2.0
  8. import QtLocation 5.5
  9. import QtPositioning 5.5
  10. import Qt5Compat.GraphicalEffects
  11. import "../controls"
  12. import "../common"
  13. import Frames 0.1
  14. AppPage {
  15. objectName: "autoFocus_Page"
  16. navigationBarHidden: true
  17. backgroundColor: app.theme_backgroundColor
  18. property var videoFormats
  19. // 定义电机状态
  20. property int currentAxis: 0 // 当前选择的轴 (0: X, 1: Y, 2: Z)
  21. property var axisPositions: [0, 0, 0] // 各轴当前位置
  22. property int speed: 50 // 当前速度 (0-100)
  23. property int stepDistance: 20 // 步进脉冲数量
  24. property string fExposureTime: "0"
  25. property bool motorUnlocked: false
  26. property real coordX: 0
  27. property real coordY: 0
  28. // ===== 上传进度网格(32格), 蛇形编号, 1 在右上角 =====
  29. // 数组下标 = GridLayout 摆放顺序(左上→右下), 元素 = 该格显示/对应的图片序号
  30. property var uploadGridSerials: [
  31. 32,25,24,17,16, 9, 8, 1,
  32. 31,26,23,18,15,10, 7, 2,
  33. 30,27,22,19,14,11, 6, 3,
  34. 29,28,21,20,13,12, 5, 4
  35. ]
  36. ListModel { id: uploadGridModel }
  37. Component.onCompleted: {
  38. for(var i = 0; i < 32; i++){
  39. uploadGridModel.append({serial: uploadGridSerials[i], percent: 0, done: false})
  40. }
  41. }
  42. // 从上传文件路径解析图片序号(文件名形如 ..._sharp_7.jpg)
  43. function uploadSerialFromPath(filePath) {
  44. if(!filePath) return -1
  45. var m = filePath.match(/sharp_(\d+)/)
  46. if(m && m.length > 1) return parseInt(m[1])
  47. return -1
  48. }
  49. // 由图片序号(1..32)换算成网格摆放索引(0..31, 蛇形, 1 在右上角)
  50. function uploadSerialToIndex(serial){
  51. var n = serial - 1
  52. var q = Math.floor(n / 4) // 0..7 列组(自右向左)
  53. var pos = n % 4 // 组内 0..3
  54. var col = 7 - q
  55. var row = (q % 2 === 0) ? pos : (3 - pos)
  56. return row * 8 + col
  57. }
  58. // 更新某个网格格子的状态
  59. function setUploadCell(serial, percent, done) {
  60. var idx = uploadSerialToIndex(serial)
  61. if(idx < 0 || idx > 31) return
  62. var p = Math.max(0, Math.min(100, percent))
  63. uploadGridModel.setProperty(idx, "percent", p)
  64. uploadGridModel.setProperty(idx, "done", done)
  65. }
  66. // 清空网格全部状态(percent=0, done=false)
  67. function resetUploadGrid() {
  68. for(var i = 0; i < uploadGridModel.count; i++){
  69. uploadGridModel.setProperty(i, "percent", 0)
  70. uploadGridModel.setProperty(i, "done", false)
  71. }
  72. }
  73. function autotake(sw){
  74. if(sw)
  75. {
  76. console.log("autotakestart")
  77. frames.camera_sw = true
  78. //frames.auto_clicked = true //开始对焦
  79. auto_timer.start() //启动对焦定时器
  80. console.log("相机已打开")
  81. photoTimer.interval=60*1000
  82. photoTimer.start()
  83. }else{
  84. frames.camera_sw = true
  85. console.log("打开相机单次拍照!")
  86. }
  87. }
  88. Frames {
  89. objectName: "Frames"
  90. id: frames
  91. videoSink: output.videoSink
  92. onCameraOpenFailed:function(err){
  93. console.log("onCameraOpenFailed",err)
  94. nativeUtils.displayMessageBox("相机打开失败!",err,1)
  95. focus_switch.checked = false
  96. focus_switch.enabled = true
  97. takephoto_switch.checked = false
  98. takephoto_switch.enabled = true
  99. }
  100. onVideoSinkChanged: {
  101. console.log("onVideoSinkChanged")
  102. photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
  103. }
  104. onQulityStringChanged: {
  105. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  106. photoTimer.interval = 180*1000 //3分钟超时
  107. photoTimer.restart()
  108. }
  109. onCameraStaChanged: function(sta_cam) {
  110. if(sta_cam){
  111. //camera.active = sta_cam
  112. //camera.start()
  113. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  114. output.visible = sta_cam
  115. photoTimer.interval = 180*1000 //3分钟超时
  116. photoTimer.start()
  117. //uvc_camera.visible = false
  118. // 打开相机:清空上传进度网格状态,开始新一轮上传统计
  119. resetUploadGrid()
  120. }else{
  121. //camera.active = sta_cam
  122. //camera.stop()
  123. output.visible= sta_cam
  124. photoTimer.stop() //停止计时器
  125. focus_switch.checked = false
  126. focus_switch.enabled = true
  127. takephoto_switch.checked = false
  128. takephoto_switch.enabled = true
  129. //uvc_camera.visible = true
  130. }
  131. console.log("相机状态改变",sta_cam)
  132. }
  133. onStepCountChanged: function(step){
  134. console.log("坐标改变",step)
  135. step_apptextfield.text = step
  136. }
  137. onExposureTimeChanged: {
  138. fExposureTime = frames.cam_ExposureTime
  139. }
  140. }
  141. Timer {
  142. id: photoTimer
  143. interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  144. running: false // 初始状态下定时器停止
  145. repeat: false // 设置为false,以便只执行一次
  146. onTriggered: {
  147. // 定时器触发后,设置按钮可用
  148. // camera.active = false
  149. // camera.stop()
  150. output.visible = false
  151. frames.camera_sw = false
  152. }
  153. }
  154. Timer {
  155. id: auto_timer
  156. interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  157. running: false // 初始状态下定时器停止
  158. repeat: false // 设置为false,以便只执行一次
  159. onTriggered: {
  160. // 定时器触发后,开始对焦
  161. frames.auto_clicked = true
  162. }
  163. }
  164. Connections{
  165. target: mqtt
  166. function onMessagePub(message) {
  167. if(app.showPubData){
  168. var time = new Date().toLocaleTimeString()
  169. app.txDataLog = "[" + time + "] " + message + "\n" + app.txDataLog
  170. if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
  171. }
  172. }
  173. function onMessageSub(message) {
  174. if(app.showSubData){
  175. var time = new Date().toLocaleTimeString()
  176. app.rxDataLog = "[" + time + "] " + message + "\n" + app.rxDataLog
  177. if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
  178. }
  179. }
  180. function onSignal_set_camera_exposure(exposureTime) {
  181. console.log("收到远程相机曝光设置指令,曝光时间:" + exposureTime)
  182. frames.cam_ExposureTime = exposureTime.toString()
  183. }
  184. // 远程校准指令: {"cmd":"slide","ext":{"calibrate":"y","speed":"50"}} → 打开相机
  185. function onSignal_open_camera() {
  186. console.log("收到远程相机开启指令,打开相机!")
  187. frames.camera_sw = true
  188. }
  189. }
  190. // 图片上传进度 → 右上角 32 格进度网格
  191. Connections {
  192. target: curl_picture
  193. function onProgressChanged(uploadedPercent, filePath){
  194. var serial = uploadSerialFromPath(filePath)
  195. if(serial < 1 || serial > 32){
  196. console.log("上传进度: 无法识别图片序号", filePath)
  197. return
  198. }
  199. setUploadCell(serial, uploadedPercent, uploadedPercent >= 100)
  200. }
  201. }
  202. // 录制结束:视频流已保存到文件系统
  203. Connections {
  204. target: frames
  205. function onRecordFileSaved(path) {
  206. console.log("录制视频流已保存:", path)
  207. apptext_res.text = "录制已保存:" + path.split("/").pop()
  208. }
  209. }
  210. Connections{
  211. target: serial
  212. onTakephotodone:{
  213. console.log("立即拍照完成!")
  214. apptext_res.text = "立即拍照完成!"
  215. focus_switch.enabled = true
  216. focus_switch.checked = false
  217. }
  218. onAutotestdone: {
  219. console.log("自动对焦完成!")
  220. apptext_res.text = "自动对焦完成!"
  221. autotest_switch.enabled = true
  222. autotest_switch.checked = false
  223. }
  224. onTranslatedone: {
  225. console.log("胶带传送完成!")
  226. apptext_res.text = "胶带传送完成!"
  227. jiaodai_switch.enabled = true
  228. jiaodai_switch.checked = false
  229. }
  230. onDataReceived:function(data) {
  231. if(app.showRxData){
  232. var time = new Date().toLocaleTimeString()
  233. app.rxDataLog = "[" + time + "] " + data + "\n" + app.rxDataLog
  234. if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
  235. }
  236. // 同步坐标值到输入框
  237. try {
  238. var jsonData = JSON.parse(data)
  239. if(jsonData.ext && !textInput_x.focus && jsonData.ext.x_init_dis !== undefined) {
  240. coordX = parseInt(jsonData.ext.x_init_dis) || 0
  241. }
  242. if(jsonData.ext && !textInput_y.focus && jsonData.ext.y_init_dis !== undefined) {
  243. coordY = parseInt(jsonData.ext.y_init_dis) || 0
  244. }
  245. } catch(e) {
  246. console.log("解析坐标数据失败:", e)
  247. }
  248. }
  249. onNetMessage:function(data) {
  250. if(app.showTxData){
  251. var time = new Date().toLocaleTimeString()
  252. app.txDataLog = "[" + time + "] " + data + "\n" + app.txDataLog
  253. if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
  254. }
  255. }
  256. }
  257. SplitView{
  258. anchors.fill: parent
  259. orientation: Qt.Horizontal
  260. Rectangle {
  261. SplitView.preferredWidth: parent.width * 0.7
  262. height: parent.height
  263. color: app.cardColor
  264. radius: 5
  265. AppButton {
  266. id: normButton
  267. //anchors.horizontalCenter: parent.horizontalCenter
  268. anchors.centerIn: parent
  269. anchors.fill: parent
  270. //text: "打开相机"
  271. flat: true //边框是否可视
  272. onClicked: {
  273. console.log("相机状态:",frames.camera_sw)
  274. //if(camera.active){
  275. if(frames.camera_sw){
  276. text = "相机已关闭"
  277. output.visible = false
  278. frames.camera_sw = false
  279. //uvc_camera.visible = false
  280. }else{
  281. text = "打开相机"
  282. output.visible = true
  283. frames.camera_sw = true
  284. //uvc_camera.visible = true
  285. }
  286. }
  287. Timer {
  288. id: longPressTimer
  289. interval: 1000 // 长按时间1000ms
  290. running: false // 初始状态下定时器停止
  291. repeat: false // 设置为false,以便只执行一次
  292. onTriggered: {
  293. console.log("长按触发")
  294. }
  295. }
  296. onPressed: {
  297. console.log("按钮按下,开始计时")
  298. longPressTimer.start()
  299. }
  300. onReleased: {
  301. console.log("按钮释放,停止计时")
  302. longPressTimer.stop()
  303. }
  304. AppImage{
  305. id: image_picdis
  306. anchors.centerIn: parent
  307. source: "../../assets/photoico.svg"
  308. }
  309. }
  310. VideoOutput
  311. {
  312. id: output
  313. anchors.fill: parent
  314. visible: false
  315. fillMode: VideoOutput.PreserveAspectFit //根据视频的纵横比例等比例缩放
  316. //fillMode: VideoOutput.Stretch
  317. Component.onCompleted: {
  318. console.log("output onCompleted")
  319. }
  320. }
  321. Row {
  322. AppText {
  323. id: photoclarity_text
  324. width: parent.width
  325. text: frames.fpsString
  326. color: "red"
  327. }
  328. AppText {
  329. visible: true//app.photoclarity
  330. id: photoclarity2_text
  331. anchors.top: photoclarity_text.bottom
  332. width: parent.width
  333. text: frames.qulityString
  334. color: "green"
  335. }
  336. }
  337. // 图片上传进度网格(8列 x 4行 = 32格), 蛇形编号 1 在右上角, 常显示; 可按住拖动位置
  338. Rectangle {
  339. id: uploadGridWrap
  340. visible: true
  341. width: uploadGrid.implicitWidth
  342. height: uploadGrid.implicitHeight
  343. color: "transparent"
  344. // 初始位置: 画面右上角
  345. Component.onCompleted: {
  346. uploadGridWrap.x = uploadGridWrap.parent.width - uploadGridWrap.width - dp(10)
  347. uploadGridWrap.y = dp(10)
  348. }
  349. GridLayout {
  350. id: uploadGrid
  351. columns: 8
  352. columnSpacing: dp(2)
  353. rowSpacing: dp(2)
  354. Repeater {
  355. id: uploadGridRepeater
  356. model: uploadGridModel
  357. Rectangle {
  358. width: dp(42)
  359. height: dp(34)
  360. radius: dp(3)
  361. color: model.done ? "#8C1f9e4d" : "transparent"
  362. border.color: model.done ? "#37a24b" : "#66ffffff"
  363. border.width: 1
  364. Column {
  365. anchors.fill: parent
  366. spacing: 0
  367. AppText {
  368. text: model.serial
  369. color: "white"
  370. font.bold: true
  371. font.pixelSize: 11
  372. anchors.horizontalCenter: parent.horizontalCenter
  373. }
  374. AppText {
  375. text: model.percent > 0 ? Math.round(model.percent) + "%" : ""
  376. color: model.done ? "white" : "#ffb020"
  377. font.pixelSize: 10
  378. anchors.horizontalCenter: parent.horizontalCenter
  379. }
  380. }
  381. }
  382. }
  383. }
  384. // 按住拖动整个网格(DragHandler原生手势,平滑不卡顿;支持鼠标与触摸)
  385. DragHandler {
  386. id: gridDragHandler
  387. target: null
  388. acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchScreen
  389. property real startX: 0
  390. property real startY: 0
  391. onActiveChanged: {
  392. if(active){
  393. // 记录按下瞬间网格位置
  394. startX = uploadGridWrap.x
  395. startY = uploadGridWrap.y
  396. }
  397. }
  398. onTranslationChanged: {
  399. if(!active) return
  400. var nx = startX + translation.x
  401. var ny = startY + translation.y
  402. // 限制在父容器范围内
  403. nx = Math.max(0, Math.min(uploadGridWrap.parent.width - uploadGridWrap.width, nx))
  404. ny = Math.max(0, Math.min(uploadGridWrap.parent.height - uploadGridWrap.height, ny))
  405. uploadGridWrap.x = nx
  406. uploadGridWrap.y = ny
  407. }
  408. }
  409. }
  410. // 抓图按钮:仅相机打开时显示,画面右下角透明背景,点击=模拟MCU拍照指令(按序号保存/锐化/上传)
  411. Rectangle {
  412. id: captureBtn
  413. visible: frames.camera_sw
  414. width: dp(56)
  415. height: dp(56)
  416. radius: width / 2
  417. color: "transparent"
  418. border.color: "#80ffffff"
  419. border.width: dp(2)
  420. anchors.right: parent.right
  421. anchors.bottom: parent.bottom
  422. anchors.rightMargin: dp(12)
  423. anchors.bottomMargin: dp(12)
  424. AppImage {
  425. anchors.centerIn: parent
  426. width: dp(34)
  427. height: dp(34)
  428. source: "../../assets/photoico.svg"
  429. }
  430. MouseArea {
  431. anchors.fill: parent
  432. onClicked: {
  433. console.log("抓图按钮点击!")
  434. frames.manualCapture()
  435. }
  436. }
  437. }
  438. // 录制按钮:仅相机打开时显示,画面右下角(抓图按钮左侧)
  439. // 点击开始录制原始(未压缩)视频流,再次点击停止并把视频流保存到相机打开时创建的文件夹
  440. Rectangle {
  441. id: recordBtn
  442. visible: frames.camera_sw
  443. width: dp(56)
  444. height: dp(56)
  445. radius: width / 2
  446. color: "transparent"
  447. border.color: frames.recording ? "#e74c3c" : "#80ffffff"
  448. border.width: dp(2)
  449. anchors.right: captureBtn.left
  450. anchors.bottom: parent.bottom
  451. anchors.rightMargin: dp(12)
  452. anchors.bottomMargin: dp(12)
  453. // 未录制:红色圆点(开始);录制中:红色方块(停止)
  454. Rectangle {
  455. anchors.centerIn: parent
  456. width: frames.recording ? dp(22) : dp(26)
  457. height: frames.recording ? dp(22) : dp(26)
  458. radius: frames.recording ? dp(3) : width / 2
  459. color: "#e74c3c"
  460. }
  461. MouseArea {
  462. anchors.fill: parent
  463. onClicked: {
  464. if(frames.recording){
  465. console.log("停止录制视频流")
  466. frames.stopRecord()
  467. }else{
  468. console.log("开始录制视频流")
  469. if(frames.startRecord()){
  470. apptext_res.text = "开始录制视频流"
  471. }else{
  472. nativeUtils.displayMessageBox("提示","录制失败,请先打开相机!",1)
  473. }
  474. }
  475. }
  476. }
  477. }
  478. }
  479. ScrollView
  480. {
  481. SplitView.preferredWidth: parent.width*0.29
  482. SplitView.minimumWidth: 200
  483. clip: true
  484. Column {
  485. spacing: dp(15)
  486. Row {
  487. spacing: 80
  488. AppText {
  489. id: text_title
  490. text: "测试调试"
  491. font.bold: true
  492. color: "#28a779"
  493. fontSize: 20
  494. }
  495. AppText {
  496. id: apptext_res
  497. text: "[测试结果]"
  498. fontSize:15
  499. color: "grey"
  500. anchors.verticalCenter: text_title.verticalCenter
  501. }
  502. }
  503. Row {
  504. spacing: dp(120)
  505. AppText{
  506. text: "一键测试"
  507. fontSize: 15
  508. color: app.fontColor
  509. anchors.verticalCenter: autotest_switch.verticalCenter
  510. }
  511. AppSwitch {
  512. id: autotest_switch
  513. onToggled: {
  514. if(autotest_switch.checked==true){
  515. autotest_switch.enabled = false
  516. serial.sendCmd("autotest",true,"","");
  517. t_autotest.start()
  518. }else{
  519. console.log("t_autotest 计数:",t_autotest.interval)
  520. }
  521. }
  522. }
  523. Timer {
  524. id: t_autotest
  525. interval: 1000*60
  526. running: false
  527. repeat: false
  528. onTriggered: {
  529. autotest_switch.enabled = true
  530. autotest_switch.checked = false
  531. }
  532. }
  533. }
  534. Row {
  535. spacing: dp(120)
  536. AppText{
  537. text: "风机测试"
  538. color: app.fontColor
  539. fontSize: 15
  540. anchors.verticalCenter: fantest_switch.verticalCenter
  541. }
  542. AppSwitch {
  543. id: fantest_switch
  544. onToggled: {
  545. if(fantest_switch.checked==true){
  546. serial.sendCmd("fan",true,"","");
  547. apptext_res.text = "打开风机"
  548. }else{
  549. serial.sendCmd("fan",false,"","");
  550. apptext_res.text = "关闭风机"
  551. }
  552. }
  553. }
  554. }
  555. Row {
  556. spacing: dp(120)
  557. AppText{
  558. text: "胶带测试"
  559. fontSize: 15
  560. color: app.fontColor
  561. //font.bold: true
  562. anchors.verticalCenter: jiaodai_switch.verticalCenter
  563. }
  564. AppSwitch {
  565. id: jiaodai_switch
  566. onToggled: {
  567. if(jiaodai_switch.checked==true){
  568. // 检查是否处于温度保护状态
  569. if(app.tempProtectionState === true){
  570. // 弹出提示对话框
  571. nativeUtils.displayMessageBox(
  572. "提示",
  573. "当前处于温控状态,请解除温控后再进行测试胶带传送",
  574. 1
  575. );
  576. // 恢复开关状态为未选中
  577. jiaodai_switch.checked = false;
  578. return;
  579. }
  580. // 正常执行胶带测试
  581. //jiaodai_switch.enabled = false
  582. apptext_res.text = "胶带测试开始"
  583. serial.sendCmd("jiaodai",true,"","");
  584. }
  585. }
  586. }
  587. }
  588. Row {
  589. spacing: dp(120)
  590. AppText {
  591. text: "补光测试"
  592. color: app.fontColor
  593. fontSize: 15
  594. anchors.verticalCenter: led_switch.verticalCenter
  595. }
  596. AppSwitch {
  597. id: led_switch
  598. onToggled: {
  599. if(led_switch.checked==true){
  600. serial.sendCmd("led",true,"","");
  601. apptext_res.text = "补光灯已打开"
  602. }else{
  603. serial.sendCmd("led",false,"","");
  604. apptext_res.text = "补光灯已关闭"
  605. }
  606. }
  607. }
  608. }
  609. Row {
  610. spacing: dp(120)
  611. AppText {
  612. text: "立即拍照"
  613. color: app.fontColor
  614. fontSize: 15
  615. anchors.verticalCenter: takephoto_switch.verticalCenter
  616. }
  617. AppSwitch {
  618. id: takephoto_switch
  619. onToggled: {
  620. if(takephoto_switch.checked==true){
  621. apptext_res.text = "立即拍照"
  622. frames.captureImage()
  623. }
  624. }
  625. }
  626. }
  627. Row {
  628. spacing: dp(120)
  629. AppText {
  630. text: "对焦拍照"
  631. color: app.fontColor
  632. fontSize: 15
  633. anchors.verticalCenter: focus_switch.verticalCenter
  634. }
  635. AppSwitch {
  636. id: focus_switch
  637. onToggled: {
  638. if(focus_switch.checked==true){
  639. apptext_res.text = "开始对焦"
  640. focus_switch.enabled = false
  641. serial.auto_takephoto(true)
  642. }
  643. }
  644. }
  645. }
  646. // 分割线
  647. Rectangle {
  648. visible: !motorUnlocked
  649. width: parent.width
  650. height: dp(1)
  651. color: "#e0e0e0"
  652. }
  653. // 分割线
  654. Rectangle {
  655. width: parent.width
  656. height: dp(2)
  657. color: "#28a779"
  658. }
  659. // 密码输入区域(未解锁时显示)
  660. Rectangle {
  661. visible: !motorUnlocked
  662. width: parent.width
  663. height: passwordColumn.height + dp(16)
  664. color: app.cardColor
  665. radius: dp(8)
  666. border.color: "#28a779"
  667. border.width: dp(1)
  668. Column {
  669. id: passwordColumn
  670. anchors.centerIn: parent
  671. spacing: dp(10)
  672. AppText {
  673. anchors.horizontalCenter: parent.horizontalCenter
  674. text: "请输入密码解锁电机控制"
  675. color: app.fontColor
  676. font.bold: true
  677. fontSize: 14
  678. }
  679. Row {
  680. anchors.horizontalCenter: parent.horizontalCenter
  681. spacing: dp(8)
  682. AppTextField {
  683. id: motorPasswordInput
  684. width: dp(130)
  685. height: dp(38)
  686. echoMode: TextInput.Password
  687. placeholderText: "密码"
  688. inputMethodHints: Qt.ImhDigitsOnly
  689. anchors.verticalCenter: parent.verticalCenter
  690. onAccepted: {
  691. if(text === "666888"){
  692. motorUnlocked = true
  693. text = ""
  694. }else{
  695. apptext_res.text = "密码错误"
  696. text = ""
  697. }
  698. }
  699. }
  700. AppButton {
  701. text: "确认"
  702. textColor: "white"
  703. flat: false
  704. backgroundColor: "#28a779"
  705. minimumHeight: dp(38)
  706. minimumWidth: dp(55)
  707. anchors.verticalCenter: parent.verticalCenter
  708. onClicked: {
  709. if(motorPasswordInput.text === "666888"){
  710. motorUnlocked = true
  711. motorPasswordInput.text = ""
  712. }else{
  713. apptext_res.text = "密码错误"
  714. motorPasswordInput.text = ""
  715. }
  716. }
  717. }
  718. }
  719. }
  720. }
  721. // 电机控制及以下所有控件(解锁后显示)
  722. Item {
  723. id: motorSection
  724. visible: motorUnlocked
  725. width: parent.width
  726. height: motorContent.height + dp(20)
  727. property alias content: motorContent
  728. Column {
  729. id: motorContent
  730. spacing: dp(12)
  731. width: parent.width
  732. // 锁定按钮
  733. Row {
  734. spacing: dp(5)
  735. width: parent.width
  736. AppText {
  737. text: "高级控制"
  738. font.bold: true
  739. color: "#28a779"
  740. fontSize: 20
  741. anchors.verticalCenter: parent.verticalCenter
  742. }
  743. AppButton {
  744. text: "锁定"
  745. textColor: "white"
  746. flat: false
  747. backgroundColor: "#d9534f"
  748. minimumHeight: dp(25)
  749. minimumWidth: dp(50)
  750. anchors.verticalCenter: parent.verticalCenter
  751. onClicked: motorUnlocked = false
  752. }
  753. }
  754. AppText {
  755. id: text_title2
  756. text: "三轴步进电机控制"
  757. font.bold: true
  758. color: "#28a779"
  759. fontSize: 20
  760. }
  761. // 轴选择
  762. Row {
  763. spacing: dp(8)
  764. width: parent.width
  765. AppText {
  766. text: "选择轴:"
  767. width: dp(60)
  768. color: app.fontColor
  769. anchors.verticalCenter: parent.verticalCenter
  770. }
  771. ComboBox {
  772. width: parent.width - dp(100)
  773. height: dp(40)
  774. model: ["X轴", "Y轴", "Z轴"]
  775. onCurrentIndexChanged: currentAxis = currentIndex
  776. }
  777. AppButton {
  778. text: "校准"
  779. textColor: "black"
  780. flat: false
  781. borderColor: "black"
  782. borderWidth: dp(1)
  783. backgroundColor: "white"
  784. minimumHeight: dp(30)
  785. minimumWidth: dp(50)
  786. onClicked:
  787. {
  788. autotake(false)
  789. if(currentAxis==0)
  790. {
  791. console.log("校准X")
  792. serial.sendCmd("calibrate",false,"x",speed.toString())
  793. }else if(currentAxis==1)
  794. {
  795. console.log("校准Y")
  796. serial.sendCmd("calibrate",false,"y",speed.toString())
  797. }else if(currentAxis==2)
  798. {
  799. console.log("校准Z")
  800. serial.sendCmd("calibrate",false,"z",speed.toString())
  801. }
  802. }
  803. }
  804. }
  805. // 速度调节
  806. Row {
  807. spacing: dp(10)
  808. width: parent.width
  809. AppText {
  810. text: "速度:"
  811. width: dp(40)
  812. color: app.fontColor
  813. anchors.verticalCenter: parent.verticalCenter
  814. }
  815. AppSlider {
  816. width: parent.width - dp(60)
  817. from: 0
  818. to: 100
  819. value: speed
  820. stepSize: 1
  821. onValueChanged: speed = value
  822. anchors.verticalCenter: parent.verticalCenter
  823. }
  824. AppText {
  825. text: speed
  826. width: dp(40)
  827. anchors.verticalCenter: parent.verticalCenter
  828. }
  829. }
  830. // 步进距离设置
  831. Row {
  832. spacing: dp(10)
  833. width: parent.width
  834. AppText {
  835. text: "步进脉冲次数:"
  836. width: dp(120)
  837. color: app.fontColor
  838. anchors.verticalCenter: parent.verticalCenter
  839. }
  840. AppTextField {
  841. id: step_apptextfield
  842. width: parent.width - dp(120)
  843. text: stepDistance
  844. validator: IntValidator { bottom: 0; top: 2000 }
  845. onTextChanged: stepDistance = parseInt(text)
  846. }
  847. }
  848. // 运动控制按钮
  849. Row {
  850. spacing: dp(10)
  851. width: parent.width
  852. AppButton {
  853. text: " 正转 "
  854. textColor: "black"
  855. flat: false
  856. borderColor: "black"
  857. borderWidth: dp(1)
  858. backgroundColor: "grey"
  859. minimumHeight: dp(30)
  860. minimumWidth: dp(50)
  861. width: (parent.width - dp(30))/4
  862. onClicked:
  863. {
  864. if(currentAxis==0)
  865. {
  866. console.log("X轴正转:",stepDistance)
  867. serial.sendCmd("movx",false,"f"+stepDistance,speed.toString())
  868. }else if(currentAxis==1)
  869. {
  870. console.log("Y轴正转:",stepDistance)
  871. serial.sendCmd("movy",false,"f"+stepDistance,speed.toString())
  872. }else if(currentAxis==2)
  873. {
  874. console.log("Z轴正转:",stepDistance)
  875. serial.sendCmd("movz",false,"f"+stepDistance,speed.toString())
  876. }
  877. }
  878. }
  879. AppButton {
  880. text: " 停止 "
  881. textColor: "black"
  882. flat: false
  883. borderColor: "black"
  884. borderWidth: dp(1)
  885. backgroundColor: "red"
  886. minimumHeight: dp(30)
  887. minimumWidth: dp(50)
  888. width: (parent.width - dp(30))/4
  889. onClicked:
  890. {
  891. console.log("停止")
  892. serial.sendCmd("movx",false,"f0","")
  893. }
  894. }
  895. AppButton {
  896. text: " 反转 "
  897. textColor: "black"
  898. flat: false
  899. borderColor: "black"
  900. borderWidth: dp(1)
  901. backgroundColor: "grey"
  902. minimumHeight: dp(30)
  903. minimumWidth: dp(50)
  904. width: (parent.width - dp(30))/4
  905. onClicked:
  906. {
  907. if(currentAxis==0)
  908. {
  909. console.log("X轴反转:",stepDistance)
  910. serial.sendCmd("movx",false,"b"+stepDistance,speed.toString())
  911. }else if(currentAxis==1)
  912. {
  913. console.log("Y轴反转:",stepDistance)
  914. serial.sendCmd("movy",false,"b"+stepDistance,speed.toString())
  915. }else if(currentAxis==2)
  916. {
  917. console.log("Z轴反转:",stepDistance)
  918. serial.sendCmd("movz",false,"b"+stepDistance,speed.toString())
  919. }
  920. }
  921. }
  922. AppButton {
  923. text: " 复位 "
  924. textColor: "black"
  925. flat: false
  926. borderColor: "black"
  927. borderWidth: dp(1)
  928. backgroundColor: "grey"
  929. minimumHeight: dp(30)
  930. minimumWidth: dp(50)
  931. width: (parent.width - dp(30))/4
  932. onClicked: {
  933. if(currentAxis==0)
  934. {
  935. console.log("X轴复位!")
  936. serial.sendCmd("movx",true,"",speed.toString())
  937. }else if(currentAxis==1)
  938. {
  939. console.log("Y轴复位!")
  940. serial.sendCmd("movy",true,"",speed.toString())
  941. }else if(currentAxis==2)
  942. {
  943. console.log("Z轴复位!")
  944. serial.sendCmd("movz",true,"",speed.toString())
  945. }
  946. }
  947. }
  948. }
  949. // ===== 坐标参数 =====
  950. AppText {
  951. text: "坐标参数"
  952. font.bold: true
  953. color: "#28a779"
  954. fontSize: 20
  955. }
  956. // X 坐标输入行
  957. Row {
  958. spacing: dp(5)
  959. width: parent.width
  960. AppText {
  961. text: "X坐标:"
  962. width: dp(50)
  963. color: app.fontColor
  964. fontSize: 15
  965. anchors.verticalCenter: textInput_x.verticalCenter
  966. }
  967. AppTextField {
  968. id: textInput_x
  969. width: parent.width - dp(80)
  970. height: dp(40)
  971. placeholderText: "0"
  972. text: coordX.toString()
  973. font.family: "Arial"
  974. font.pixelSize: 15
  975. validator: IntValidator { }
  976. EnterKey.type: Qt.EnterKeyDone
  977. inputMethodHints: Qt.ImhDigitsOnly
  978. Keys.onReturnPressed: {
  979. coordX = parseInt(text) || 0
  980. serial.setHt_xy_dis(coordX, coordY)
  981. Qt.inputMethod.hide()
  982. }
  983. onAccepted: {
  984. coordX = parseInt(text) || 0
  985. serial.setHt_xy_dis(coordX, coordY)
  986. }
  987. }
  988. }
  989. // Y 坐标输入行
  990. Row {
  991. spacing: dp(5)
  992. width: parent.width
  993. AppText {
  994. text: "Y坐标:"
  995. width: dp(50)
  996. color: app.fontColor
  997. fontSize: 15
  998. anchors.verticalCenter: textInput_y.verticalCenter
  999. }
  1000. AppTextField {
  1001. id: textInput_y
  1002. width: parent.width - dp(80)
  1003. height: dp(40)
  1004. placeholderText: "0"
  1005. text: coordY.toString()
  1006. font.family: "Arial"
  1007. font.pixelSize: 15
  1008. validator: IntValidator { }
  1009. EnterKey.type: Qt.EnterKeyDone
  1010. inputMethodHints: Qt.ImhDigitsOnly
  1011. Keys.onReturnPressed: {
  1012. coordY = parseInt(text) || 0
  1013. serial.setHt_xy_dis(coordX, coordY)
  1014. Qt.inputMethod.hide()
  1015. }
  1016. onAccepted: {
  1017. coordY = parseInt(text) || 0
  1018. serial.setHt_xy_dis(coordX, coordY)
  1019. }
  1020. }
  1021. }
  1022. // 分割线
  1023. Rectangle {
  1024. width: parent.width
  1025. height: dp(2)
  1026. color: "#e0e0e0"
  1027. }
  1028. // ===== 相机参数 =====
  1029. AppText {
  1030. id: text_camera
  1031. text: "相机参数"
  1032. font.bold: true
  1033. color: "#28a779"
  1034. fontSize: 20
  1035. }
  1036. Row {
  1037. spacing: dp(10)
  1038. width: parent.width
  1039. AppText {
  1040. id: txt_fExposureTime
  1041. text: "曝光值:"
  1042. color: app.fontColor
  1043. }
  1044. AppTextField {
  1045. anchors.verticalCenter: txt_fExposureTime.verticalCenter
  1046. placeholderText: fExposureTime
  1047. text: fExposureTime
  1048. width: parent.width - dp(10)
  1049. EnterKey.type: Qt.EnterKeyDone
  1050. wrapMode: Text.NoWrap
  1051. inputMethodHints: Qt.ImhFormattedNumbersOnly |
  1052. Qt.ImhPreferDone |
  1053. Qt.ImhNoPredictiveText
  1054. validator: DoubleValidator {
  1055. bottom: 100.00
  1056. top: 500000.00
  1057. decimals: 0
  1058. }
  1059. // 关键:兜底(IME 再作妖也不怕)
  1060. Keys.onReturnPressed: {
  1061. frames.cam_ExposureTime = text
  1062. console.log("设置曝光时间:",text)
  1063. Qt.inputMethod.hide()
  1064. }
  1065. onAccepted: {
  1066. frames.cam_ExposureTime = text
  1067. console.log("设置曝光时间",text)
  1068. }
  1069. }
  1070. }
  1071. AppText {
  1072. id: text_debug
  1073. text: "通信调试"
  1074. font.bold: true
  1075. color: "#28a779"
  1076. fontSize: 20
  1077. }
  1078. Row {
  1079. spacing: dp(12)
  1080. AppText {
  1081. text: "显示Serial发送数据"
  1082. color: app.fontColor
  1083. fontSize: 15
  1084. anchors.verticalCenter: txSwitch.verticalCenter
  1085. }
  1086. AppSwitch {
  1087. id: txSwitch
  1088. onToggled: {
  1089. app.floatPanel = checked
  1090. app.showTxData = checked
  1091. app.floatPanel_title = "Serial发送数据"
  1092. }
  1093. }
  1094. }
  1095. Row {
  1096. spacing: dp(12)
  1097. AppText {
  1098. text: "显示Serial接收数据"
  1099. color: app.fontColor
  1100. fontSize: 15
  1101. anchors.verticalCenter: rxSwitch.verticalCenter
  1102. }
  1103. AppSwitch {
  1104. id: rxSwitch
  1105. onToggled: {
  1106. app.floatPanel = checked
  1107. app.showRxData = checked
  1108. app.floatPanel_title = "Serial接收数据"
  1109. }
  1110. }
  1111. }
  1112. Row {
  1113. spacing: dp(12)
  1114. AppText {
  1115. text: "显示MQTT发送数据"
  1116. color: app.fontColor
  1117. fontSize: 15
  1118. anchors.verticalCenter: pubSwitch.verticalCenter
  1119. }
  1120. AppSwitch {
  1121. id: pubSwitch
  1122. onToggled: {
  1123. app.floatPanel = checked
  1124. app.showPubData = checked
  1125. app.showSubData = false
  1126. app.floatPanel_title = "MQTT发送数据"
  1127. }
  1128. }
  1129. }
  1130. Row {
  1131. spacing: dp(12)
  1132. AppText {
  1133. text: "显示MQTT接收数据"
  1134. color: app.fontColor
  1135. fontSize: 15
  1136. anchors.verticalCenter: subSwitch.verticalCenter
  1137. }
  1138. AppSwitch {
  1139. id: subSwitch
  1140. onToggled: {
  1141. app.floatPanel = checked
  1142. app.showSubData = checked
  1143. app.showPubData = false
  1144. app.floatPanel_title = "MQTT接收数据"
  1145. }
  1146. }
  1147. }
  1148. } // motorContent
  1149. } // motorSection
  1150. }
  1151. }
  1152. }
  1153. }