1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

OP-1020 Removes AltitudeHoldSettings object from list of objects to save if connected board does not support it.

This commit is contained in:
Fredrik Arvidsson 2013-06-25 12:21:16 +02:00
parent 023ee2b97e
commit bf573e6adc
6 changed files with 56 additions and 22 deletions

View File

@ -38,8 +38,10 @@
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/generalsettings.h>
#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<UAVObjectUtilManager>();
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<AltitudeHoldSettings*>(object) == 0;
}
else {
return true;
}
}

View File

@ -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

View File

@ -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
*/

View File

@ -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();
};

View File

@ -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="<<result;
loop.quit();
}
}
@ -203,7 +208,7 @@ void smartSaveButton::enableControls(bool value)
void smartSaveButton::resetIcons()
{
foreach(QPushButton * button, buttonList.keys())
button->setIcon(QIcon());
button->setIcon(QIcon());
}
void smartSaveButton::apply()

View File

@ -38,13 +38,15 @@
#include <QObject>
#include <QDebug>
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<UAVDataObject *>);
void addObject(UAVDataObject *);
@ -79,6 +81,7 @@ private:
QEventLoop loop;
QList<UAVDataObject *> objects;
QMap<QPushButton *, buttonTypeEnum> buttonList;
ConfigTaskWidget *configWidget;
public slots:
void enableControls(bool value);