画了一个简单的qml界面用于测试指令

This commit is contained in:
2020-04-08 18:05:00 +08:00
parent b051a1e969
commit 2594deaa06
8 changed files with 231 additions and 67 deletions
+111 -39
View File
@@ -1,98 +1,170 @@
import QtQuick 2.6 import QtQuick 2.6
//import QtQuick.Controls 2.2 import QtQuick.Controls 2.5
//导入指令模块,这样就能发指令了
//import Protocol.MavLinkNode 1.0
Rectangle { Rectangle {
id:root
visible: true visible: true
x:0 x:0
y:0 y:0
border.width: 1
border.color: "blue"
color: "white" color: "white"
signal btnclicked_int(real param1, real param2, real param3, real param4, int x, int y, real z)
signal btnclicked_long(real param1, real param2, real param3, real param4, real param5, real param6, real param7)
Rectangle { Rectangle {
id:loadqml id:armbtn
x:20 x:10
y:20 y:20
width: 100 radius: 5
width: 80
height: 40 height: 40
border.width:1
color: "lightgreen"
color: "blue" Text{
anchors.centerIn: parent
text: qsTr("ARM")
}
MouseArea { MouseArea {
hoverEnabled: true //默认是false hoverEnabled: true //默认是false
x:0
y:0
anchors.fill: parent anchors.fill: parent
onEntered: { onEntered: {
loadqml.color = "yellow" parent.color = "yellow"
console.log("Entered")
} }
onExited:{ onExited:{
loadqml.color = "blue" parent.color = "lightgreen"
console.log("Exited") }
onPressed: {
parent.width = parent.width - 4
parent.height = parent.height - 2
parent.x = parent.x + 2
parent.y = parent.y + 1
parent.border.width = 2
}
onReleased:{
parent.width = parent.width + 4
parent.height = parent.height + 2
parent.x = parent.x - 2
parent.y = parent.y - 1
parent.border.width = 1
}
onClicked: {
console.log("clicked")
btnclicked_int(0,0,0,0,0,0,0)
} }
onClicked: console.log("Clicked")
onReleased: console.log("Released")
} }
} }
Rectangle { Rectangle {
id: loadbtn id: takeoffbtn
x:20 x:100
y:80 y:20
width: 100 radius: 5
height: 20 width: 80
height: 40
color: "blue" border.width:1
color: "lightgreen"
Text{ Text{
text: qsTr("Load") anchors.centerIn: parent
text: qsTr("TakeOff")
} }
MouseArea{ MouseArea{
hoverEnabled: true //默认是false
anchors.fill: parent anchors.fill: parent
onClicked: console.log("loadbtn")
onEntered: { onEntered: {
loadbtn.color = "yellow" parent.color = "yellow"
console.log("Entered")
} }
onExited:{ onExited:{
loadbtn.color = "blue" parent.color = "lightgreen"
console.log("Exited") }
onPressed: {
parent.width = parent.width - 4
parent.height = parent.height - 2
parent.x = parent.x + 2
parent.y = parent.y + 1
parent.border.width = 2
}
onReleased:{
parent.width = parent.width + 4
parent.height = parent.height + 2
parent.x = parent.x - 2
parent.y = parent.y - 1
parent.border.width = 1
}
onClicked: {
console.log("clicked")
} }
} }
} }
Rectangle { Rectangle {
id: resetbtn id: killbtn
x:20 x:190
y:150 y:20
width: 100 radius: 5
height: 20 width: 80
height: 40
border.width:1
color: "darkorange"
color: "blue"
Text{ Text{
text: qsTr("Reset") anchors.centerIn: parent
text: qsTr("Kill")
} }
MouseArea{ MouseArea{
hoverEnabled: true //默认是false
anchors.fill: parent anchors.fill: parent
onClicked: console.log("resetbtn")
onEntered: { onEntered: {
resetbtn.color = "yellow" parent.color = "yellow"
console.log("Entered")
} }
onExited:{ onExited:{
resetbtn.color = "blue" parent.color = "darkorange"
console.log("Exited") }
onPressed: {
parent.color = "red"
parent.width = parent.width - 4
parent.height = parent.height - 2
parent.x = parent.x + 2
parent.y = parent.y + 1
parent.border.width = 2
}
onReleased:{
parent.width = parent.width + 4
parent.height = parent.height + 2
parent.x = parent.x - 2
parent.y = parent.y - 1
parent.border.width = 1
}
onClicked: {
console.log("clicked")
} }
} }
+9
View File
@@ -13,6 +13,8 @@
#include <QDebug> #include <QDebug>
#include <QTextCodec> #include <QTextCodec>
#include <QQmlEngine>
//#include <windows.h> //#include <windows.h>
//#include <winver.h> //#include <winver.h>
//#pragma comment(lib, "Version") //#pragma comment(lib, "Version")
@@ -108,6 +110,13 @@ int main(int argc, char *argv[])
a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); a.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
w.show(); w.show();
return a.exec(); return a.exec();
+17 -24
View File
@@ -1,21 +1,15 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "QPushButton" #include "QPushButton"
#include "QAction" #include "QAction"
#include "QHBoxLayout" #include "QHBoxLayout"
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
//qmlRegisterType<DLink>("Protocol.DLink", 1, 0, "DLink");
//this->setAttribute(Qt::AA_NativeWindows);
//ui initial //ui initial
linkui = new LinkUI(this); linkui = new LinkUI(this);
@@ -45,7 +39,6 @@ MainWindow::MainWindow(QWidget *parent)
map = new mapcontrol::OPMapWidget(this); map = new mapcontrol::OPMapWidget(this);
map->SetShowHome(false); map->SetShowHome(false);
map->SetShowCompass(false); map->SetShowCompass(false);
map->SetUseOpenGL(true); map->SetUseOpenGL(true);
@@ -61,6 +54,9 @@ MainWindow::MainWindow(QWidget *parent)
QIcon icon; QIcon icon;
nav = new QNavigationWidget(this); nav = new QNavigationWidget(this);
nav->setAttribute(Qt::WA_AlwaysStackOnTop);
nav->setGeometry(0,0,50,this->height()); nav->setGeometry(0,0,50,this->height());
nav->setRowHeight(50); nav->setRowHeight(50);
nav->addItem(tr("Flight"),icon); nav->addItem(tr("Flight"),icon);
@@ -71,6 +67,8 @@ MainWindow::MainWindow(QWidget *parent)
nav->addItem(tr("Data"),icon);//all data nav->addItem(tr("Data"),icon);//all data
nav->addItem(tr("Tools"),icon);//soft setting help about nav->addItem(tr("Tools"),icon);//soft setting help about
connect(nav,SIGNAL(ItemChanged(int)), connect(nav,SIGNAL(ItemChanged(int)),
this,SLOT(onTabIndexChanged(int))); this,SLOT(onTabIndexChanged(int)));
@@ -143,14 +141,19 @@ void MainWindow::resizeEvent(QResizeEvent *event)
this->width()- copk->width() - nav->width(), this->width()- copk->width() - nav->width(),
this->height()); this->height());
/*
map->setGeometry(0,
0,
this->width(),
this->height());
*/
nav->setGeometry(0,0,nav->width(),this->height()); nav->setGeometry(0,0,nav->width(),this->height());
copk->setGeometry(this->width() - copk->width(),0,copk->width(),copk->height()); copk->setGeometry(this->width() - copk->width(),0,copk->width(),copk->height());
quick->setGeometry(this->width() - quick->width(),copk->height(),quick->width(),this->height() - copk->height()); quick->setGeometry(this->width() - quick->width(),copk->height(),quick->width(),this->height() - copk->height());
} }
@@ -162,11 +165,9 @@ void MainWindow::keyPressEvent(QKeyEvent *event) //键盘按下事件
case Qt::Key_A: case Qt::Key_A:
break; break;
case Qt::Key_D: case Qt::Key_D:
if(event->modifiers() == Qt::AltModifier) if(event->modifiers() == Qt::AltModifier)
{ {
qInfo() << "alt + D"; qInfo() << "alt + D";
dlink->mavlinknode->Mission->ReadCmd(1,1);
} }
break; break;
case Qt::Key_U : case Qt::Key_U :
@@ -174,8 +175,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event) //键盘按下事件
if(event->modifiers() == Qt::AltModifier) if(event->modifiers() == Qt::AltModifier)
{ {
qInfo() << "atl + U"; qInfo() << "atl + U";
//dlink->Mavlink_msg_mission_count(map->WPTotal());
//qDebug() << map->WPTotal();
} }
}break; }break;
case Qt::Key_P : case Qt::Key_P :
@@ -183,8 +182,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event) //键盘按下事件
if(event->modifiers() == Qt::AltModifier) if(event->modifiers() == Qt::AltModifier)
{//下载参数 {//下载参数
qInfo() << "atl + P"; qInfo() << "atl + P";
dlink->mavlinknode->Parameter->ReadCmd(1,1,1);
} }
}break; }break;
case Qt::Key_O : case Qt::Key_O :
@@ -192,8 +189,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event) //键盘按下事件
if(event->modifiers() == Qt::AltModifier) if(event->modifiers() == Qt::AltModifier)
{//上传参数 {//上传参数
qInfo() << "atl + O"; qInfo() << "atl + O";
//dlink->Mavlink_msg_mission_count(map->WPTotal());
} }
}break; }break;
case Qt::Key_S: case Qt::Key_S:
@@ -211,8 +206,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event) //键盘按下事件
case Qt::Key_Space : case Qt::Key_Space :
{ {
internals::PointLatLng LatLng; internals::PointLatLng LatLng;
//LatLng.SetLat(dlink->v*1e-7);
//LatLng.SetLng(dlink->vehicle.gps_raw_int.lon*1e-7);
map->SetCurrentPosition(LatLng); map->SetCurrentPosition(LatLng);
} }
break; break;
@@ -354,7 +347,7 @@ void MainWindow::dlink_triggered()
disconnectdialog dlg(this); disconnectdialog dlg(this);
dlg.setWindowTitle(tr("SerialPort")); dlg.setWindowTitle(tr("SerialPort"));
dlg.setWindowIcon(QIcon(":/images/LinkUI/SerialPort.ico")); dlg.setWindowIcon(QIcon("qrc:/images/LinkUI/SerialPort.ico"));
int ret = dlg.exec(); int ret = dlg.exec();
if (QDialog::Accepted == ret) if (QDialog::Accepted == ret)
@@ -367,7 +360,7 @@ void MainWindow::dlink_triggered()
ConnectDialog dlg(this); ConnectDialog dlg(this);
dlg.setWindowTitle(tr("SerialPort")); dlg.setWindowTitle(tr("SerialPort"));
dlg.setWindowIcon(QIcon(":/images/LinkUI/SerialPort.ico")); dlg.setWindowIcon(QIcon("qrc:/images/LinkUI/SerialPort.ico"));
dlg.baudrate = 115200; dlg.baudrate = 115200;
dlg.parity = QSerialPort::NoParity; dlg.parity = QSerialPort::NoParity;
-1
View File
@@ -9,7 +9,6 @@ QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MavLinkNode TARGET = MavLinkNode
TEMPLATE = lib TEMPLATE = lib
+77 -1
View File
@@ -85,6 +85,49 @@ void commandprocess::SendMessage(mavlink_message_t msg)
emit SendMessageTo(0,buff, len);//使用信号和槽 emit SendMessageTo(0,buff, len);//使用信号和槽
} }
//发送函数
void commandprocess::WriteCmd(uint8_t m_sysid, uint8_t m_compid ,
float param1,
float param2,
float param3,
float param4,
int32_t x,
int32_t y,
float z, uint16_t command, uint8_t frame, uint8_t current, uint8_t autocontinue)
{
sysid = m_sysid;
compid = m_compid;
//给指令赋值
cmd_int.param1 = param1;
cmd_int.param2 = param2;
cmd_int.param3 = param3;
cmd_int.param4 = param4;
cmd_int.x = x;
cmd_int.y = y;
cmd_int.z = z;
cmd_int.command = command;
cmd_int.frame = frame;
cmd_int.current = current;
cmd_int.autocontinue = autocontinue;
//开启线程开始传输
status.m_Mode = TransmitMode;//发送模式
start();//开启线程
}
//这个函数类似中断,专门处理接收到的状态 //这个函数类似中断,专门处理接收到的状态
void commandprocess::Parse(mavlink_message_t msg) void commandprocess::Parse(mavlink_message_t msg)
{ {
@@ -106,6 +149,10 @@ void commandprocess::Parse(mavlink_message_t msg)
{ {
status.transmit.isWaitingforACK = false; status.transmit.isWaitingforACK = false;
} }
else
{
//拒绝该指令
}
break; break;
} }
} }
@@ -142,7 +189,9 @@ void commandprocess::WriteStateMachine(void)
{ {
status.transmit.isWaitingforACK = true; status.transmit.isWaitingforACK = true;
//set("id",0,1);//发送一个指令 _int(cmd_int.param1,cmd_int.param2,cmd_int.param3,cmd_int.param4,
cmd_int.x,cmd_int.y,cmd_int.z,
cmd_int.command,cmd_int.frame,cmd_int.current,cmd_int.autocontinue);//发送一个指令
time = QTime::currentTime().msecsSinceStartOfDay(); time = QTime::currentTime().msecsSinceStartOfDay();
step++;//下一个阶段 step++;//下一个阶段
} }
@@ -159,6 +208,20 @@ void commandprocess::WriteStateMachine(void)
status.m_Mode = Nop_Mode; status.m_Mode = Nop_Mode;
status.transmit.isWaitingforACK = false; status.transmit.isWaitingforACK = false;
timeout_count = 0; timeout_count = 0;
//清除指令
cmd_int.param1 = 0;
cmd_int.param2 = 0;
cmd_int.param3 = 0;
cmd_int.param4 = 0;
cmd_int.x = 0;
cmd_int.y = 0;
cmd_int.z = 0;
cmd_int.command = 0;
cmd_int.frame = 0;
cmd_int.current = 0;
cmd_int.autocontinue = 0;
} }
} }
else else
@@ -170,6 +233,19 @@ void commandprocess::WriteStateMachine(void)
status.m_Mode = Nop_Mode; status.m_Mode = Nop_Mode;
status.transmit.isWaitingforACK = false; status.transmit.isWaitingforACK = false;
timeout_count = 0; timeout_count = 0;
//清除指令
cmd_int.param1 = 0;
cmd_int.param2 = 0;
cmd_int.param3 = 0;
cmd_int.param4 = 0;
cmd_int.x = 0;
cmd_int.y = 0;
cmd_int.z = 0;
cmd_int.command = 0;
cmd_int.frame = 0;
cmd_int.current = 0;
cmd_int.autocontinue = 0;
} }
} }
} }
+10 -2
View File
@@ -58,7 +58,14 @@ public:
public slots: public slots:
//读取和写入指令 //读取和写入指令
//void ReadCmd(uint8_t m_sysid, uint8_t m_compid, uint8_t type); //void ReadCmd(uint8_t m_sysid, uint8_t m_compid, uint8_t type);
//void WriteCmd(uint8_t m_sysid, uint8_t m_compid ,uint32_t count); void WriteCmd(uint8_t m_sysid, uint8_t m_compid ,
float param1,
float param2,
float param3,
float param4,
int32_t x,
int32_t y,
float z, uint16_t command, uint8_t frame, uint8_t current, uint8_t autocontinue);
@@ -116,7 +123,8 @@ private:
uint8_t sysid; uint8_t sysid;
uint8_t compid; uint8_t compid;
mavlink_command_int_t cmd_int;
mavlink_command_long_t cmd_long;
+4
View File
@@ -9,6 +9,10 @@
MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent) MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
{ {
// qmlRegisterType<commandprocess>(static_cast<void>("Protocol.Command"), static_cast<void>(1), static_cast<void>(0), "Command");
//main thread //main thread
running_flag = false; running_flag = false;
Nodethread = new QThread(); Nodethread = new QThread();
+3
View File
@@ -270,6 +270,9 @@ void ParameterProcess::ReadStateMachine(void)//一整列
status.m_Mode = Nop_Mode;//切换到什么都不做 status.m_Mode = Nop_Mode;//切换到什么都不做
timeout_count = 0; timeout_count = 0;
status.recieve.isWaitingforValue = false; status.recieve.isWaitingforValue = false;
//停止线程,不能停止
//stop();
} }
} }