修正姿态显示和指令发送

This commit is contained in:
2020-06-03 18:09:41 +08:00
parent d20e39a987
commit 72aa91dfb8
12 changed files with 354 additions and 140 deletions
+25 -4
View File
@@ -1,13 +1,18 @@
{
"comment": "Any Firmware, Any Vehicle",
"comment": "Custom",
"version": 1,
"spacing" : 10,
"Width": 80,
"Height": 60,
"CommandButton": [
{
"Name" : "关机",
"Text" : "关机",
"row": 0,
"column": 0,
"command": 400,
"confirm": 0,
"param1": 1,
"param2": 2,
"param3": 3,
@@ -17,9 +22,25 @@
"param7": 7
},
{
"Name" : "起飞",
"Text" : "降落",
"row": 0,
"column": 1,
"command": 900,
"confirm": 0,
"param1": 7,
"param2": 6,
"param3": 5,
"param4": 4,
"param5": 3,
"param6": 2,
"param7": 1
},
{
"Text" : "起飞",
"row": 1,
"column": 1,
"command": 900,
"confirm": 0,
"param1": 7,
"param2": 6,
"param3": 5,
+22 -16
View File
@@ -6,10 +6,14 @@ const char* CommandUI::_versionJsonKey = "version";
const char* CommandUI::_commentJsonKey = "comment";
const char* CommandUI::_CommandButtonJsonKey = "CommandButton";
const char* CommandUI::_NameJsonKey = "Name";
const char* CommandUI::_WidthJsonKey = "Width";
const char* CommandUI::_HeightJsonKey = "Height";
const char* CommandUI::_TextJsonKey = "Text";
const char* CommandUI::_rowJsonKey = "row";
const char* CommandUI::_columnJsonKey = "column";
const char* CommandUI::_param1JsonKey = "param1";
const char* CommandUI::_param2JsonKey = "param2";
const char* CommandUI::_param3JsonKey = "param3";
@@ -17,8 +21,8 @@ const char* CommandUI::_param4JsonKey = "param4";
const char* CommandUI::_param5JsonKey = "param5";
const char* CommandUI::_param6JsonKey = "param6";
const char* CommandUI::_param7JsonKey = "param7";
const char* CommandUI::_commandJsonKey = "command";
const char* CommandUI::_confirmJsonKey = "confirm";
@@ -41,6 +45,8 @@ CommandUI::CommandUI(QWidget *parent) :
//载入json
loadCommandJson(":/json/Command.json");
ui->groupBox_Command->setTitle(tr("Command Version:") + QString::number(CMD_version));
for(QJsonValue info: CMD_infoArray) {
if (!info.isObject()) {
return;
@@ -48,15 +54,9 @@ CommandUI::CommandUI(QWidget *parent) :
QPushButton *btn = new QPushButton(ui->groupBox_Command);
btn->setText(info.toObject().find(_NameJsonKey).value().toString());
btn->setText(info.toObject().find(_TextJsonKey).value().toString());
btn->setFixedSize(60,60);
/*
btn->setGeometry(10 + info.toObject().find(_rowJsonKey).value().toInt() * 70,
10 + info.toObject().find(_columnJsonKey).value().toInt() * 70,
60,60);
*/
btn->setFixedSize(CMDwidth,CMDheight);
ui->gridLayout_Command->addWidget(btn,
info.toObject().find(_rowJsonKey).value().toInt(),
@@ -104,8 +104,8 @@ void CommandUI::loadCommandJson(const QString& jsonFilename)
}
QJsonObject json = doc.object();
int version = json.value(_versionJsonKey).toInt();
qDebug() << "command version :" << version;
CMD_version = json.value(_versionJsonKey).toInt();
qDebug() << "command version :" << CMD_version;
/*
if (version != 1) {
@@ -114,6 +114,8 @@ void CommandUI::loadCommandJson(const QString& jsonFilename)
}
*/
CMDwidth = json.value(_WidthJsonKey).toInt();
CMDheight = json.value(_HeightJsonKey).toInt();
QJsonValue jsonValue = json.value(_CommandButtonJsonKey);
@@ -148,7 +150,7 @@ void CommandUI::loadCommandJson(const QString& jsonFilename)
//找到id或者名字一样的按键,找到参数,发出去
QString _name = info.toObject().find(_NameJsonKey).value().toString();
QString _name = info.toObject().find(_TextJsonKey).value().toString();
QString _text = btn->text();
if(_name == _text)
@@ -160,9 +162,11 @@ void CommandUI::loadCommandJson(const QString& jsonFilename)
float param5 = info.toObject().find(_param5JsonKey).value().toDouble();
float param6 = info.toObject().find(_param6JsonKey).value().toDouble();
float param7 = info.toObject().find(_param7JsonKey).value().toDouble();
uint16_t command = info.toObject().find(_commandJsonKey).value().toInt();
uint8_t confirm = info.toObject().find(_confirmJsonKey).value().toInt();
emit cmd_long(param1,param2, param3,param4,param5,param6,param7);
emit cmd_long(param1,param2, param3,param4,param5,param6,param7,command,confirm);
qDebug() << tr("clicked") << btn->text()
<< param1
@@ -171,7 +175,9 @@ void CommandUI::loadCommandJson(const QString& jsonFilename)
<< param4
<< param5
<< param6
<< param7;
<< param7
<< command
<< confirm;
}
}
+11 -5
View File
@@ -29,7 +29,7 @@ public:
signals:
void cmd_int(float param1, float param2, float param3, float param4, int x, int y, float z);
void cmd_long(float param1, float param2, float param3, float param4, float param5, float param6, float param7);
void cmd_long( float param1,float param2,float param3,float param4,float param5,float param6,float param7,uint16_t command,uint8_t confirmation);
private slots:
@@ -47,10 +47,14 @@ private:
static const char* _commentJsonKey;
static const char* _CommandButtonJsonKey;
static const char* _NameJsonKey;
static const char* _WidthJsonKey;
static const char* _HeightJsonKey;
static const char* _TextJsonKey;
static const char* _rowJsonKey;
static const char* _columnJsonKey;
static const char* _param1JsonKey;
static const char* _param2JsonKey;
static const char* _param3JsonKey;
@@ -58,13 +62,15 @@ private:
static const char* _param5JsonKey;
static const char* _param6JsonKey;
static const char* _param7JsonKey;
static const char* _commandJsonKey;
static const char* _confirmJsonKey;
QJsonArray CMD_infoArray;
int CMDwidth = 60;
int CMDheight = 60;
int CMD_version;
+2 -4
View File
@@ -12,12 +12,10 @@ FORMS += \
$$PWD/CommandUI.ui \
HEADERS += \
$$PWD/CommandUI.h \
$$PWD/commandmsg.h
$$PWD/CommandUI.h
SOURCES += \
$$PWD/CommandUI.cpp \
$$PWD/commandmsg.cpp
$$PWD/CommandUI.cpp
RESOURCES += \
$$PWD/CommandUIres.qrc