mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14: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:
parent
023ee2b97e
commit
bf573e6adc
@ -38,8 +38,10 @@
|
|||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <coreplugin/generalsettings.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 = new Ui_StabilizationWidget();
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -198,7 +200,18 @@ void ConfigStabilizationWidget::onBoardConnected()
|
|||||||
UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
|
UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
|
||||||
|
|
||||||
Q_ASSERT(utilMngr);
|
Q_ASSERT(utilMngr);
|
||||||
|
boardModel = utilMngr->getBoardModel();
|
||||||
// If Revolution board enable misc tab, otherwise disable it
|
// 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ class ConfigStabilizationWidget : public ConfigTaskWidget {
|
|||||||
public:
|
public:
|
||||||
ConfigStabilizationWidget(QWidget *parent = 0);
|
ConfigStabilizationWidget(QWidget *parent = 0);
|
||||||
~ConfigStabilizationWidget();
|
~ConfigStabilizationWidget();
|
||||||
|
bool shouldObjectBeSaved(UAVObject * object);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_StabilizationWidget *ui;
|
Ui_StabilizationWidget *ui;
|
||||||
@ -51,6 +52,8 @@ private:
|
|||||||
// Milliseconds between automatic 'Instant Updates'
|
// Milliseconds between automatic 'Instant Updates'
|
||||||
static const int AUTOMATIC_UPDATE_RATE = 500;
|
static const int AUTOMATIC_UPDATE_RATE = 500;
|
||||||
|
|
||||||
|
int boardModel;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void refreshWidgetsValues(UAVObject *o = NULL);
|
void refreshWidgetsValues(UAVObject *o = NULL);
|
||||||
|
|
||||||
@ -59,6 +62,7 @@ private slots:
|
|||||||
void linkCheckBoxes(bool value);
|
void linkCheckBoxes(bool value);
|
||||||
void processLinkedWidgets(QWidget *);
|
void processLinkedWidgets(QWidget *);
|
||||||
void onBoardConnected();
|
void onBoardConnected();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ConfigStabilizationWidget_H
|
#endif // ConfigStabilizationWidget_H
|
||||||
|
@ -413,7 +413,7 @@ void ConfigTaskWidget::helpButtonPressed()
|
|||||||
void ConfigTaskWidget::addApplySaveButtons(QPushButton *update, QPushButton *save)
|
void ConfigTaskWidget::addApplySaveButtons(QPushButton *update, QPushButton *save)
|
||||||
{
|
{
|
||||||
if (!smartsave) {
|
if (!smartsave) {
|
||||||
smartsave = new smartSaveButton();
|
smartsave = new smartSaveButton(this);
|
||||||
connect(smartsave, SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets()));
|
connect(smartsave, SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets()));
|
||||||
connect(smartsave, SIGNAL(saveSuccessfull()), this, SLOT(clearDirty()));
|
connect(smartsave, SIGNAL(saveSuccessfull()), this, SLOT(clearDirty()));
|
||||||
connect(smartsave, SIGNAL(beginOp()), this, SLOT(disableObjUpdates()));
|
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
|
* SLOT function called when on of the widgets contents added to the framework changes
|
||||||
*/
|
*/
|
||||||
|
@ -144,6 +144,7 @@ public:
|
|||||||
void addHelpButton(QPushButton *button, QString url);
|
void addHelpButton(QPushButton *button, QString url);
|
||||||
void forceShadowUpdates();
|
void forceShadowUpdates();
|
||||||
void forceConnectedState();
|
void forceConnectedState();
|
||||||
|
virtual bool shouldObjectBeSaved(UAVObject * object);
|
||||||
public slots:
|
public slots:
|
||||||
void onAutopilotDisconnect();
|
void onAutopilotDisconnect();
|
||||||
void onAutopilotConnect();
|
void onAutopilotConnect();
|
||||||
@ -204,8 +205,10 @@ protected slots:
|
|||||||
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
|
virtual void refreshWidgetsValues(UAVObject *obj = NULL);
|
||||||
virtual void updateObjectsFromWidgets();
|
virtual void updateObjectsFromWidgets();
|
||||||
virtual void helpButtonPressed();
|
virtual void helpButtonPressed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void enableControls(bool enable);
|
virtual void enableControls(bool enable);
|
||||||
|
|
||||||
void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, QVariant value, double scale);
|
void checkWidgetsLimits(QWidget *widget, UAVObjectField *field, int index, bool hasLimits, QVariant value, double scale);
|
||||||
void updateEnableControls();
|
void updateEnableControls();
|
||||||
};
|
};
|
||||||
|
@ -25,8 +25,9 @@
|
|||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
#include "smartsavebutton.h"
|
#include "smartsavebutton.h"
|
||||||
|
#include "configtaskwidget.h"
|
||||||
|
|
||||||
smartSaveButton::smartSaveButton()
|
smartSaveButton::smartSaveButton(ConfigTaskWidget *configTaskWidget) : configWidget(configTaskWidget)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void smartSaveButton::addButtons(QPushButton *save, QPushButton *apply)
|
void smartSaveButton::addButtons(QPushButton *save, QPushButton *apply)
|
||||||
@ -77,60 +78,65 @@ void smartSaveButton::processOperation(QPushButton *button, bool save)
|
|||||||
foreach(UAVDataObject * obj, objects) {
|
foreach(UAVDataObject * obj, objects) {
|
||||||
UAVObject::Metadata mdata = obj->getMetadata();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
up_result = false;
|
up_result = false;
|
||||||
current_object = obj;
|
current_object = obj;
|
||||||
for (int i = 0; i < 3; ++i) {
|
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(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(transaction_finished(UAVObject *, bool)));
|
||||||
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
||||||
obj->updated();
|
obj->updated();
|
||||||
|
|
||||||
timer.start(3000);
|
timer.start(3000);
|
||||||
// qDebug()<<"begin loop";
|
|
||||||
loop.exec();
|
loop.exec();
|
||||||
if (timer.isActive()) {
|
if (!timer.isActive()) {
|
||||||
qDebug() << "SMARTSAVEBUTTON" << "Upload did not timeout" << i << "Object" << obj->getName();
|
qDebug() << "Upload of" << obj->getName() << "timed out." ;
|
||||||
} else {
|
|
||||||
qDebug() << "SMARTSAVEBUTTON" << "Upload TIMEOUT" << i << "Object" << obj->getName();
|
|
||||||
}
|
}
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
disconnect(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(transaction_finished(UAVObject *, bool)));
|
disconnect(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(transaction_finished(UAVObject *, bool)));
|
||||||
disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
||||||
if (up_result) {
|
if (up_result) {
|
||||||
|
qDebug() << "Upload of" << obj->getName() << "successful.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (up_result == false) {
|
if (up_result == false) {
|
||||||
qDebug() << "SMARTSAVEBUTTON" << "Object upload error:" << obj->getName();
|
qDebug() << "Upload of" << obj->getName() << "failed after 3 tries.";
|
||||||
error = true;
|
error = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sv_result = false;
|
sv_result = false;
|
||||||
current_objectID = obj->getObjID();
|
current_objectID = obj->getObjID();
|
||||||
if (save && (obj->isSettings())) {
|
if (save && (obj->isSettings())) {
|
||||||
for (int i = 0; i < 3; ++i) {
|
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(utilMngr, SIGNAL(saveCompleted(int, bool)), this, SLOT(saving_finished(int, bool)));
|
||||||
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
||||||
utilMngr->saveObjectToSD(obj);
|
utilMngr->saveObjectToSD(obj);
|
||||||
|
|
||||||
timer.start(3000);
|
timer.start(3000);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
if (timer.isActive()) {
|
if (!timer.isActive()) {
|
||||||
qDebug() << "SMARTSAVEBUTTON" << "Saving did not timeout" << i << "Object" << obj->getName();
|
qDebug() << "Saving of" << obj->getName() << "timed out.";
|
||||||
} else {
|
|
||||||
qDebug() << "SMARTSAVEBUTTON" << "Saving TIMEOUT" << i << "Object" << obj->getName();
|
|
||||||
}
|
}
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
disconnect(utilMngr, SIGNAL(saveCompleted(int, bool)), this, SLOT(saving_finished(int, bool)));
|
disconnect(utilMngr, SIGNAL(saveCompleted(int, bool)), this, SLOT(saving_finished(int, bool)));
|
||||||
disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
||||||
if (sv_result) {
|
if (sv_result) {
|
||||||
|
qDebug() << "Saving of" << obj->getName() << "successful.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sv_result == false) {
|
if (sv_result == false) {
|
||||||
qDebug() << "SMARTSAVEBUTTON" << "failed to save:" << obj->getName();
|
qDebug() << "Saving of" << obj->getName() << "failed after 3 tries.";
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,7 +195,6 @@ void smartSaveButton::saving_finished(int id, bool result)
|
|||||||
{
|
{
|
||||||
if (id == current_objectID) {
|
if (id == current_objectID) {
|
||||||
sv_result = result;
|
sv_result = result;
|
||||||
// qDebug()<<"saving_finished result="<<result;
|
|
||||||
loop.quit();
|
loop.quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +208,7 @@ void smartSaveButton::enableControls(bool value)
|
|||||||
void smartSaveButton::resetIcons()
|
void smartSaveButton::resetIcons()
|
||||||
{
|
{
|
||||||
foreach(QPushButton * button, buttonList.keys())
|
foreach(QPushButton * button, buttonList.keys())
|
||||||
button->setIcon(QIcon());
|
button->setIcon(QIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
void smartSaveButton::apply()
|
void smartSaveButton::apply()
|
||||||
|
@ -38,13 +38,15 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
class ConfigTaskWidget;
|
||||||
|
|
||||||
class smartSaveButton : public QObject {
|
class smartSaveButton : public QObject {
|
||||||
enum buttonTypeEnum { save_button, apply_button };
|
enum buttonTypeEnum { save_button, apply_button };
|
||||||
public:
|
public:
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
smartSaveButton();
|
smartSaveButton(ConfigTaskWidget *configTaskWidget);
|
||||||
void addButtons(QPushButton *save, QPushButton *apply);
|
void addButtons(QPushButton *save, QPushButton *apply);
|
||||||
void setObjects(QList<UAVDataObject *>);
|
void setObjects(QList<UAVDataObject *>);
|
||||||
void addObject(UAVDataObject *);
|
void addObject(UAVDataObject *);
|
||||||
@ -79,6 +81,7 @@ private:
|
|||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QList<UAVDataObject *> objects;
|
QList<UAVDataObject *> objects;
|
||||||
QMap<QPushButton *, buttonTypeEnum> buttonList;
|
QMap<QPushButton *, buttonTypeEnum> buttonList;
|
||||||
|
ConfigTaskWidget *configWidget;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void enableControls(bool value);
|
void enableControls(bool value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user