| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589 |
- import QtQuick
- import Felgo
- import QtMultimedia
- import QtQuick.Controls
- import Qt.labs.settings 1.0 as QtLabs
- import QtQuick.Controls.Material 2.0
- import QtLocation 5.5
- import QtPositioning 5.5
- import Qt5Compat.GraphicalEffects
- import "../controls"
- import "../common"
- import Frames 0.1
- AppPage {
- objectName: "autoFocus_Page"
- navigationBarHidden: true
- backgroundColor: app.theme_backgroundColor
- property var videoFormats
- function autotake(sw){
- if(sw)
- {
- console.log("autotakestart")
- frames.camera_sw = true
- //frames.auto_clicked = true //开始对焦
- auto_timer.start() //启动对焦定时器
- console.log("相机已打开")
- photoTimer.interval=300*1000
- photoTimer.start()
- }else{
- frames.camera_sw = true
- console.log("打开相机单次拍照!")
- }
- }
- Frames {
- objectName: "Frames"
- id: frames
- videoSink: output.videoSink
- onVideoSinkChanged: {
- console.log("onVideoSinkChanged")
- photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
- }
- onCameraStaChanged: function(sta_cam) {
- if(sta_cam)
- {
- //camera.active = sta_cam
- //camera.start()
- output.visible= sta_cam
- photoTimer.interval=300*1000
- photoTimer.start()
- }else{
- //camera.active = sta_cam
- //camera.stop()
- output.visible= sta_cam
- photoTimer.stop() //停止计时器
- }
- console.log("相机状态改变",sta_cam)
- }
- }
- // MediaDevices {
- // id: mediaDevices
- // }
- /*//https://github.com/igormironchik/qt6_qcamera/blob/main/main.qml
- Camera {
- id: camera
- //cameraFormat:
- active: false
- whiteBalanceMode: Camera.WhiteBalanceAuto
- //colorTemperature: 5600
- //zoomFactor: maximumZoomFactor
- }
- CaptureSession {
- camera: camera
- videoOutput: output
- imageCapture : ImageCapture {
- id: imageCapture
- onImageSaved: {
- console.log("Image saved. Request ID:", requestId, "Path:", path);
- }
- onImageCaptured: {
- console.log("Image saved. Request ID:");
- imageCapture.captureToFile(appdir+"1.jpg")
- }
- }
- }
- */
- Timer {
- id: photoTimer
- interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
- running: false // 初始状态下定时器停止
- repeat: false // 设置为false,以便只执行一次
- onTriggered: {
- // 定时器触发后,设置按钮可用
- // camera.active = false
- // camera.stop()
- output.visible = false
- frames.camera_sw = false
- }
- }
- Timer {
- id: auto_timer
- interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
- running: false // 初始状态下定时器停止
- repeat: false // 设置为false,以便只执行一次
- onTriggered: {
- // 定时器触发后,开始对焦
- frames.auto_clicked = true
- }
- }
- Connections{
- target: serial
- onTakephotodone:{
- console.log("立即拍照完成!")
- focus_switch.enabled = true
- focus_switch.checked = false
- }
- onAutotestdone: {
- console.log("自动对焦完成!")
- autotest_switch.enabled = true
- autotest_switch.checked = false
- }
- onTranslatedone: {
- console.log("胶带传送完成!")
- jiaodai_switch.enabled = true
- jiaodai_switch.checked = false
- }
- }
- // 接收并显示日志消息
- Connections {
- target: logger
- onLogMessage: {
- logTextArea.text += message + "\n"
- console.log("logTextArea:",logTextArea.contentHeight)
- if(logTextArea.contentHeight>5000){
- logTextArea.clear()
- }
- }
- }
- Row{
- anchors.fill: parent
- spacing: 5
- Rectangle {
- width: parent.width*0.7
- height: parent.height
- color: app.cardColor
- radius: 5
- AppButton {
- id: normButton
- //anchors.horizontalCenter: parent.horizontalCenter
- anchors.centerIn: parent
- anchors.fill: parent
- //text: "打开相机"
- flat: true //边框是否可视
- onClicked: {
- console.log("相机状态:",frames.camera_sw)
- //if(camera.active){
- if(frames.camera_sw){
- text = "相机已关闭"
- output.visible = false
- frames.camera_sw = false
- }else{
- text = "打开相机"
- output.visible = true
- frames.camera_sw = true
- }
- }
- AppImage{
- id: image_picdis
- anchors.centerIn: parent
- source: "../../assets/photoico.svg"
- }
- }
- VideoOutput
- {
- id: output
- anchors.centerIn: parent
- // width: parent.width
- anchors.fill: parent
- focus: visible
- fillMode: VideoOutput.PreserveAspectFit //根据视频的纵横比例等比例缩放
- // //fillMode: VideoOutput.Stretch
- Component.onCompleted: {
- console.log("output onCompleted")
- }
- }
- Row {
- AppText {
- id: photoclarity_text
- width: parent.width
- text: frames.fpsString
- color: "red"
- }
- AppText {
- id: photoclarity2_text
- anchors.top: photoclarity_text.bottom
- width: parent.width
- text: frames.qulityString
- color: "red"
- }
- }
- Row {
- anchors.bottom: parent.bottom
- anchors.bottomMargin: 10
- anchors.left: parent.left
- anchors.leftMargin: 10
- spacing: -5
- CustomRadioButton {
- id: x_rdb
- checked: true
- text: "X轴"
- }
- CustomRadioButton {
- id: y_rdb
- text: "Y轴"
- }
- CustomRadioButton {
- id: z_rdb
- text: "Z轴"
- }
- AppButton {
- text: "复位"
- flat: false
- minimumHeight: 20
- minimumWidth: 50
- textColor: "green"
- backgroundColor: "white"
- borderColor: "#f5f5f5"
- anchors.verticalCenter: x_rdb.verticalCenter
- onClicked: {
- if(x_rdb.checked){
- serial.sendCmd("movx",true,"");
- }else if(y_rdb.checked){
- serial.sendCmd("movy",true,"");
- }else if(z_rdb.checked){
- serial.sendCmd("movz",true,"");
- }
- }
- }
- AppButton {
- text: "前进"
- flat: false
- textColor: "green"
- backgroundColor: "white"
- borderColor: "#f5f5f5"
- minimumHeight: 20
- minimumWidth: 50
- anchors.verticalCenter: x_rdb.verticalCenter
- onClicked: {
- var dialog = InputDialog.inputTextSingleLine(app,
- "请输入距离:",
- "0um",
- function(ok,text){
- if(ok){
- if(text){
- if(x_rdb.checked===true){
- serial.sendCmd("movx",false,"f"+text);
- }else if(y_rdb.checked===true){
- serial.sendCmd("movy",false,"f"+text);
- }else if(z_rdb.checked===true){
- serial.sendCmd("movz",false,"f"+text);
- }
- }
- console.log("行进",text)
- }
- })
- }
- }
- AppButton {
- text: "后退"
- flat: false
- textColor: "green"
- backgroundColor: "white"
- borderColor: "#f5f5f5"
- minimumHeight: 30
- minimumWidth: 50
- anchors.verticalCenter: x_rdb.verticalCenter
- onClicked: {
- var dialog = InputDialog.inputTextSingleLine(app,
- "请输入距离:",
- "0um",
- function(ok,text){
- if(ok){
- if(text){
- if(x_rdb.checked===true){
- serial.sendCmd("movx",false,"b"+text);
- }else if(y_rdb.checked===true){
- serial.sendCmd("movy",false,"b"+text);
- }else if(z_rdb.checked===true){
- serial.sendCmd("movz",false,"b"+text);
- }
- }
- console.log("行进",text)
- }
- })
- }
- }
- AppButton{
- text: "+"
- flat: false
- textColor: "green"
- backgroundColor: "white"
- borderColor: "#f5f5f5"
- minimumHeight: 20
- minimumWidth: 20
- anchors.verticalCenter: x_rdb.verticalCenter
- onClicked:{
- if(x_rdb.checked===true){
- serial.sendCmd("movx",false,"f100");
- }else if(y_rdb.checked===true){
- serial.sendCmd("movy",false,"f100");
- }else if(z_rdb.checked===true){
- serial.sendCmd("movz",false,"f100");
- }
- }
- }
- AppButton{
- text: "-"
- flat: false
- textColor: "green"
- backgroundColor: "white"
- borderColor: "#f5f5f5"
- minimumHeight: 20
- minimumWidth: 20
- anchors.verticalCenter: x_rdb.verticalCenter
- onClicked: {
- if(x_rdb.checked===true){
- serial.sendCmd("movx",false,"b100");
- }else if(y_rdb.checked===true){
- serial.sendCmd("movy",false,"b100");
- }else if(z_rdb.checked===true){
- serial.sendCmd("movz",false,"b100");
- }
- }
- }
- }
- }
- Rectangle {
- width: parent.width*0.29
- height: parent.height
- color: app.cardColor
- radius: 5
- AppText {
- id: text_title
- anchors.left: parent.left
- anchors.leftMargin: 10
- anchors.top: parent.top
- anchors.topMargin: 10
- text: "测试设置"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- Rectangle{
- id: rec_test
- anchors.top: text_title.bottom
- anchors.topMargin: 5
- anchors.left: parent.left
- width: parent.width*0.97
- height: parent.height *0.5
- border.width: 1
- border.color: "white"
- radius: 5
- color: app.cardColor
- Column {
- anchors.top: text_title.bottom
- anchors.left: parent.left
- anchors.leftMargin: 10
- spacing: -15
- Row {
- spacing: 80
- AppText{
- text: "一键测试"
- fontSize: 15
- color: app.fontColor
- //font.bold: true
- anchors.verticalCenter: autotest_switch.verticalCenter
- }
- Switch {
- id: autotest_switch
- onToggled: {
- if(autotest_switch.checked==true){
- autotest_switch.enabled = false
- serial.sendCmd("autotest",true,"");
- }
- }
- }
- }
- Row {
- spacing: 80
- AppText{
- text: "风机测试"
- color: app.fontColor
- fontSize: 15
- //font.bold: true
- anchors.verticalCenter: fantest_switch.verticalCenter
- }
- Switch {
- id: fantest_switch
- onToggled: {
- if(fantest_switch.checked==true){
- serial.sendCmd("fan",true,"");
- }else{
- serial.sendCmd("fan",false,"");
- }
- }
- }
- }
- Row {
- spacing: 80
- AppText{
- text: "胶带测试"
- fontSize: 15
- color: app.fontColor
- //font.bold: true
- anchors.verticalCenter: jiaodai_switch.verticalCenter
- }
- Switch {
- id: jiaodai_switch
- onToggled: {
- if(jiaodai_switch.checked==true){
- jiaodai_switch.enabled = false
- serial.sendCmd("jiaodai",true,"");
- }
- }
- }
- }
- Row {
- spacing: 80
- AppText{
- text: "补光测试"
- color: app.fontColor
- fontSize: 15
- //font.bold: true
- anchors.verticalCenter: led_switch.verticalCenter
- }
- Switch {
- id: led_switch
- onToggled: {
- if(led_switch.checked==true){
- serial.sendCmd("led",true,"");
- }else{
- serial.sendCmd("led",false,"");
- }
- }
- }
- }
- Row {
- spacing: 80
- AppText{
- text: "立即拍照"
- color: app.fontColor
- fontSize: 15
- //font.bold: true
- anchors.verticalCenter: takephoto_switch.verticalCenter
- }
- Switch {
- id: takephoto_switch
- onToggled: {
- if(takephoto_switch.checked==true){
- frames.captureImage()
- }
- }
- }
- }
- Row {
- spacing: 80
- AppText{
- text: "对焦拍照"
- color: app.fontColor
- fontSize: 15
- //font.bold: true
- anchors.verticalCenter: focus_switch.verticalCenter
- }
- Switch {
- id: focus_switch
- onToggled: {
- if(focus_switch.checked==true){
- focus_switch.enabled = false
- serial.auto_takephoto(true)
- }
- }
- }
- }
- }
- Rectangle {
- anchors.top: rec_test.bottom
- anchors.left: parent.left
- width: parent.width
- height: parent.height * 0.85
- border.width: 1
- color: app.cardColor
- border.color: "white"
- radius: 5
- AppFlickable {
- id: scroll
- anchors.fill: parent
- contentHeight: content.height
- bottomMargin: nativeUtils.safeAreaInsets.bottom
- Column {
- id: content
- width: parent.width
- TextArea {
- id: logTextArea
- readOnly: true
- wrapMode: TextArea.WrapAtWordBoundaryOrAnywhere
- width: parent.width
- text: "日志"
- color: app.fontColor
- font.pixelSize: 8
- function scrollToLatestLine() {
- // 获取TextArea的内容高度
- var contentHeight = logTextArea.contentHeight;
- // 计算滚动位置,使视图滚动到最底部
- var scrollPosition = contentHeight - scroll.height;
- // 使用动画效果来平滑滚动
- scroll.contentY = scrollPosition;
- }
- onTextChanged: {
- // 当文本发生变化时,调用滚动函数以将视图滚动到最新行
- scrollToLatestLine();
- }
- }
- }
- }
- }
- }
- }
- }
- }
|