1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-16 08:29:15 +01:00

Merge branch 'thread/OP-1222_FW_Wizard' of ssh://git.openpilot.org/OpenPilot into laurent/OP-1222_FW_Wizard

This commit is contained in:
Laurent Lalanne 2014-09-26 18:22:55 +02:00
commit 6f74ffdc8d
8 changed files with 66 additions and 21 deletions

View File

@ -82,6 +82,9 @@ bool AirframeInitialTuningPage::validatePage()
if (ui->templateList->currentRow() >= 0) {
templ = ui->templateList->item(ui->templateList->currentRow())->data(Qt::UserRole + 1).value<QJsonObject *>();
}
if (getWizard()->getVehicleTemplate() != NULL) {
delete getWizard()->getVehicleTemplate();
}
getWizard()->setVehicleTemplate(new QJsonObject(*templ));
return true;
}
@ -114,8 +117,11 @@ void AirframeInitialTuningPage::updateDescription(QJsonObject *templ)
if (templ != NULL) {
QString description;
description.append("<b>").append(tr("Name of Vehicle: ")).append("</b>").append(templ->value("name").toString()).append("<br>");
description.append("<b>").append(tr("Name of Owner: ")).append("</b>").append(templ->value("owner").toString())
.append(" (").append(templ->value("nick").toString()).append(")").append("<br>");
description.append("<b>").append(tr("Name of Owner: ")).append("</b>").append(templ->value("owner").toString());
if (templ->value("nick") != "") {
description.append(" (").append(templ->value("nick").toString()).append(")");
}
description.append("<br>");
description.append("<b>").append(tr("Size: ")).append("</b>").append(templ->value("size").toString()).append("<br>");
description.append("<b>").append(tr("Weight: ")).append("</b>").append(templ->value("weight").toString()).append("<br>");
description.append("<b>").append(tr("Motor(s): ")).append("</b>").append(templ->value("motor").toString()).append("<br>");
@ -163,21 +169,15 @@ void AirframeInitialTuningPage::loadValidFiles()
QJsonObject json = templateDoc.object();
if (json["type"].toInt() == getWizard()->getVehicleType() &&
json["subtype"].toInt() == getWizard()->getVehicleSubType()) {
QString nameKey = getTemplateKey(&json);
int index = 0;
while (true) {
if (!m_templates.contains(nameKey)) {
m_templates[nameKey] = new QJsonObject(json);
break;
} else {
nameKey = QString("%1 - %2").arg(nameKey).arg(++index);
QString uuid = json["uuid"].toString();
if (!m_templates.contains(uuid)) {
m_templates[json["uuid"].toString()] = new QJsonObject(json);
}
}
}
file.close();
}
}
}
void AirframeInitialTuningPage::setupTemplateList()
{
@ -185,15 +185,17 @@ void AirframeInitialTuningPage::setupTemplateList()
item->setData(Qt::UserRole + 1, QVariant::fromValue((QJsonObject *)NULL));
foreach(QString templ, m_templates.keys()) {
item = new QListWidgetItem(templ, ui->templateList);
item->setData(Qt::UserRole + 1, QVariant::fromValue(m_templates[templ]));
QJsonObject *json = m_templates[templ];
item = new QListWidgetItem(json->value("name").toString(), ui->templateList);
item->setData(Qt::UserRole + 1, QVariant::fromValue(json));
}
ui->templateList->setCurrentRow(0);
}
QString AirframeInitialTuningPage::getTemplateKey(QJsonObject *templ)
{
return QString("%1 - %2").arg(templ->value("nick").toString()).arg(templ->value("name").toString());
return QString(templ->value("name").toString());
}
void AirframeInitialTuningPage::resizeEvent(QResizeEvent *)

View File

@ -42,6 +42,7 @@
#include "gpssettings.h"
#include "airspeedsettings.h"
#include <QtCore/qmath.h>
#include <QJsonObject>
const qint16 VehicleConfigurationHelper::LEGACY_ESC_FREQUENCE = 50;
const qint16 VehicleConfigurationHelper::RAPID_ESC_FREQUENCE = 400;
@ -82,6 +83,8 @@ bool VehicleConfigurationHelper::setupVehicle(bool save)
applyStabilizationConfiguration();
applyManualControlDefaults();
applyTemplateSettings();
bool result = saveChangesToController(save);
emit saveProgress(m_modifiedObjects.count() + 1, ++m_progress, result ? tr("Done!") : tr("Failed!"));
return result;
@ -747,6 +750,22 @@ void VehicleConfigurationHelper::applyManualControlDefaults()
addModifiedObject(mcSettings, tr("Writing manual control defaults"));
}
void VehicleConfigurationHelper::applyTemplateSettings()
{
if (m_configSource->getVehicleTemplate() != NULL) {
QJsonObject *json = m_configSource->getVehicleTemplate();
QList<UAVObject *> updatedObjects;
m_uavoManager->fromJson(*json, &updatedObjects);
foreach(UAVObject * object, updatedObjects) {
UAVDataObject *dataObj = dynamic_cast<UAVDataObject *>(object);
if (dataObj != NULL) {
addModifiedObject(dataObj, QString(tr("Writing template settings for %1")).arg(object->getName()));
}
}
}
}
bool VehicleConfigurationHelper::saveChangesToController(bool save)
{
qDebug() << "Saving modified objects to controller. " << m_modifiedObjects.count() << " objects in found.";

View File

@ -87,6 +87,7 @@ private:
void applySensorBiasConfiguration();
void applyStabilizationConfiguration();
void applyManualControlDefaults();
void applyTemplateSettings();
void applyMixerConfiguration(mixerChannelSettings channels[]);

View File

@ -199,6 +199,8 @@ void VehicleTemplateExportDialog::accept()
exportObject["propeller"] = ui->Propeller->text();
exportObject["controller"] = ui->Controllers->currentText();
exportObject["comment"] = ui->Comment->document()->toPlainText();
QUuid uuid = QUuid::createUuid();
exportObject["uuid"] = uuid.toString();
QByteArray bytes;
QBuffer buffer(&bytes);
@ -209,13 +211,12 @@ void VehicleTemplateExportDialog::accept()
QJsonDocument saveDoc(exportObject);
QString fileName = QString("%1/%2/%3-%4-%5-%6.optmpl")
QString fileName = QString("%1/%2/%3-%4-%5.optmpl")
.arg(EXPORT_BASE_NAME)
.arg(getTypeDirectory())
.arg(fixFilenameString(ui->ForumNick->text(), 15))
.arg(fixFilenameString(ui->Name->text(), 20))
.arg(fixFilenameString(ui->Type->text(), 30))
.arg(fixFilenameString(QUuid::createUuid().toString().right(12)));
.arg(fixFilenameString(uuid.toString().right(12)));
QFile saveFile(fileName);
QDir dir;
dir.mkpath(QFileInfo(saveFile).absoluteDir().absolutePath());

View File

@ -540,6 +540,25 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>Type</tabstop>
<tabstop>Name</tabstop>
<tabstop>Owner</tabstop>
<tabstop>ForumNick</tabstop>
<tabstop>Size</tabstop>
<tabstop>Weight</tabstop>
<tabstop>Motor</tabstop>
<tabstop>Esc</tabstop>
<tabstop>Servo</tabstop>
<tabstop>Battery</tabstop>
<tabstop>Propeller</tabstop>
<tabstop>Controllers</tabstop>
<tabstop>Comment</tabstop>
<tabstop>ImportButton</tabstop>
<tabstop>acceptBtn</tabstop>
<tabstop>cancelBtn</tabstop>
<tabstop>Photo</tabstop>
</tabstops>
<resources/>
<connections>
<connection>

View File

@ -340,7 +340,7 @@ void UAVObjectManager::toJson(QJsonObject &jsonObject, const QList<UAVObject *>
jsonObject["objects"] = jObjects;
}
void UAVObjectManager::fromJson(const QJsonObject &jsonObject)
void UAVObjectManager::fromJson(const QJsonObject &jsonObject, QList<UAVObject *> *updatedObjects)
{
QJsonArray jObjects = jsonObject["objects"].toArray();
@ -349,6 +349,9 @@ void UAVObjectManager::fromJson(const QJsonObject &jsonObject)
UAVObject *object = getObject(jObject["name"].toString(), jObject["instance"].toInt());
if (object != NULL) {
object->fromJson(jObject);
if (updatedObjects != NULL) {
updatedObjects->append(object);
}
}
}
}

View File

@ -59,7 +59,7 @@ public:
void toJson(QJsonObject &jsonObject, JSON_EXPORT_OPTION what = JSON_EXPORT_ALL);
void toJson(QJsonObject &jsonObject, const QList<QString> &objectsToExport);
void toJson(QJsonObject &jsonObject, const QList<UAVObject *> &objectsToExport);
void fromJson(const QJsonObject &jsonObject);
void fromJson(const QJsonObject &jsonObject, QList<UAVObject *> *updatedObjects = NULL);
signals:
void newObject(UAVObject *obj);

View File

@ -1,7 +1,7 @@
<xml>
<object name="Mpu6000Settings" singleinstance="true" settings="true" category="Sensors">
<description>Settings for the @ref MPU6000 sensor used on CC3D and Revolution. Reboot the board for this to takes effect</description>
<field name="GyroScale" units="deg/s" type="enum" elements="1" defaultvalue="Scale_1000">
<field name="GyroScale" units="deg/s" type="enum" elements="1" defaultvalue="Scale_2000">
<options>
<option>Scale_250</option>
<option>Scale_500</option>