diff --git a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp index 013f82666..f0312a35a 100644 --- a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp @@ -38,8 +38,10 @@ #include #include +#include "altitudeholdsettings.h" -ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent) +ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent), + boardModel(0) { ui = new Ui_StabilizationWidget(); ui->setupUi(this); @@ -198,7 +200,18 @@ void ConfigStabilizationWidget::onBoardConnected() UAVObjectUtilManager *utilMngr = pm->getObject(); Q_ASSERT(utilMngr); - + boardModel = utilMngr->getBoardModel(); // If Revolution board enable misc tab, otherwise disable it - ui->AltitudeHold->setEnabled((utilMngr->getBoardModel() & 0xff00) == 0x0900); + ui->AltitudeHold->setEnabled((boardModel & 0xff00) == 0x0900); +} + +bool ConfigStabilizationWidget::shouldObjectBeSaved(UAVObject *object) +{ + // AltitudeHoldSettings should only be saved for Revolution board to avoid error. + if((boardModel & 0xff00) != 0x0900) { + return dynamic_cast(object) == 0; + } + else { + return true; + } } diff --git a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h index 0a783f4c5..6d3b500ef 100644 --- a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h @@ -43,6 +43,7 @@ class ConfigStabilizationWidget : public ConfigTaskWidget { public: ConfigStabilizationWidget(QWidget *parent = 0); ~ConfigStabilizationWidget(); + bool shouldObjectBeSaved(UAVObject * object); private: Ui_StabilizationWidget *ui; @@ -51,6 +52,8 @@ private: // Milliseconds between automatic 'Instant Updates' static const int AUTOMATIC_UPDATE_RATE = 500; + int boardModel; + protected slots: void refreshWidgetsValues(UAVObject *o = NULL); @@ -59,6 +62,7 @@ private slots: void linkCheckBoxes(bool value); void processLinkedWidgets(QWidget *); void onBoardConnected(); + }; #endif // ConfigStabilizationWidget_H diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp index 2f007eec0..df6cf2236 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp @@ -413,7 +413,7 @@ void ConfigTaskWidget::helpButtonPressed() void ConfigTaskWidget::addApplySaveButtons(QPushButton *update, QPushButton *save) { if (!smartsave) { - smartsave = new smartSaveButton(); + smartsave = new smartSaveButton(this); connect(smartsave, SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets())); connect(smartsave, SIGNAL(saveSuccessfull()), this, SLOT(clearDirty())); connect(smartsave, SIGNAL(beginOp()), this, SLOT(disableObjUpdates())); @@ -459,6 +459,12 @@ void ConfigTaskWidget::enableControls(bool enable) } } +bool ConfigTaskWidget::shouldObjectBeSaved(UAVObject *object) +{ + Q_UNUSED(object); + return true; +} + /** * SLOT function called when on of the widgets contents added to the framework changes */ diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h index c4c26f0fb..25ea31a47 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h @@ -144,6 +144,7 @@ public: void addHelpButton(QPushButton *button, QString url); void forceShadowUpdates(); void forceConnectedState(); + virtual bool shouldObjectBeSaved(UAVObject * object); public slots: void onAutopilotDisconnect(); void onAutopilotConnect(); @@ -204,8 +205,10 @@ protected slots: virtual void refreshWidgetsValues(UAVObject *obj = NULL); virtual void updateObjectsFromWidgets(); virtual void helpButtonPressed(); + protected: virtual void enableControls(bool enable); + void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, QVariant value, double scale); void updateEnableControls(); }; diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp index 20f26e7ed..9d0ff284f 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp @@ -25,8 +25,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "smartsavebutton.h" +#include "configtaskwidget.h" -smartSaveButton::smartSaveButton() +smartSaveButton::smartSaveButton(ConfigTaskWidget *configTaskWidget) : configWidget(configTaskWidget) {} void smartSaveButton::addButtons(QPushButton *save, QPushButton *apply) @@ -77,60 +78,65 @@ void smartSaveButton::processOperation(QPushButton *button, bool save) foreach(UAVDataObject * obj, objects) { UAVObject::Metadata mdata = obj->getMetadata(); - if (UAVObject::GetGcsAccess(mdata) == UAVObject::ACCESS_READONLY) { + //Should we really save this object to the board? + if (!configWidget->shouldObjectBeSaved(obj) || UAVObject::GetGcsAccess(mdata) == UAVObject::ACCESS_READONLY) { + qDebug() << obj->getName() << "was skipped."; continue; } + up_result = false; current_object = obj; for (int i = 0; i < 3; ++i) { - qDebug() << "SMARTSAVEBUTTON" << "Upload try number" << i << "Object" << obj->getName(); + qDebug() << "Uploading" << obj->getName() << "to board."; connect(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(transaction_finished(UAVObject *, bool))); connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); obj->updated(); + timer.start(3000); - // qDebug()<<"begin loop"; loop.exec(); - if (timer.isActive()) { - qDebug() << "SMARTSAVEBUTTON" << "Upload did not timeout" << i << "Object" << obj->getName(); - } else { - qDebug() << "SMARTSAVEBUTTON" << "Upload TIMEOUT" << i << "Object" << obj->getName(); + if (!timer.isActive()) { + qDebug() << "Upload of" << obj->getName() << "timed out." ; } timer.stop(); + disconnect(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(transaction_finished(UAVObject *, bool))); disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); if (up_result) { + qDebug() << "Upload of" << obj->getName() << "successful."; break; } } if (up_result == false) { - qDebug() << "SMARTSAVEBUTTON" << "Object upload error:" << obj->getName(); + qDebug() << "Upload of" << obj->getName() << "failed after 3 tries."; error = true; continue; } + sv_result = false; current_objectID = obj->getObjID(); if (save && (obj->isSettings())) { for (int i = 0; i < 3; ++i) { - qDebug() << "SMARTSAVEBUTTON" << "Save try number" << i << "Object" << obj->getName(); + qDebug() << "Saving" << obj->getName() << "to board."; connect(utilMngr, SIGNAL(saveCompleted(int, bool)), this, SLOT(saving_finished(int, bool))); connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); utilMngr->saveObjectToSD(obj); + timer.start(3000); loop.exec(); - if (timer.isActive()) { - qDebug() << "SMARTSAVEBUTTON" << "Saving did not timeout" << i << "Object" << obj->getName(); - } else { - qDebug() << "SMARTSAVEBUTTON" << "Saving TIMEOUT" << i << "Object" << obj->getName(); + if (!timer.isActive()) { + qDebug() << "Saving of" << obj->getName() << "timed out."; } timer.stop(); + disconnect(utilMngr, SIGNAL(saveCompleted(int, bool)), this, SLOT(saving_finished(int, bool))); disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); if (sv_result) { + qDebug() << "Saving of" << obj->getName() << "successful."; break; } } if (sv_result == false) { - qDebug() << "SMARTSAVEBUTTON" << "failed to save:" << obj->getName(); + qDebug() << "Saving of" << obj->getName() << "failed after 3 tries."; error = true; } } @@ -189,7 +195,6 @@ void smartSaveButton::saving_finished(int id, bool result) { if (id == current_objectID) { sv_result = result; - // qDebug()<<"saving_finished result="<setIcon(QIcon()); + button->setIcon(QIcon()); } void smartSaveButton::apply() diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.h index 275ea3c44..42d9b06e8 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.h @@ -38,13 +38,15 @@ #include #include +class ConfigTaskWidget; + class smartSaveButton : public QObject { enum buttonTypeEnum { save_button, apply_button }; public: Q_OBJECT public: - smartSaveButton(); + smartSaveButton(ConfigTaskWidget *configTaskWidget); void addButtons(QPushButton *save, QPushButton *apply); void setObjects(QList); void addObject(UAVDataObject *); @@ -79,6 +81,7 @@ private: QEventLoop loop; QList objects; QMap buttonList; + ConfigTaskWidget *configWidget; public slots: void enableControls(bool value);