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

Only show PipX config gadget when the PipX is connected.

This commit is contained in:
Brian Webb 2012-06-05 19:34:42 -07:00
parent 0bc3c5061f
commit 6f9c6ae86d
4 changed files with 62 additions and 24 deletions

View File

@ -90,9 +90,6 @@ ConfigGadgetWidget::ConfigGadgetWidget(QWidget *parent) : QWidget(parent)
qwd = new ConfigTxPIDWidget(this);
ftw->insertTab(ConfigGadgetWidget::txpid, qwd, QIcon(":/configgadget/images/txpid.png"), QString("TxPID"));
qwd = new ConfigPipXtremeWidget(this);
ftw->insertTab(ConfigGadgetWidget::pipxtreme, qwd, QIcon(":/configgadget/images/PipXtreme.png"), QString("PipXtreme"));
// *********************
// Listen to autopilot connection events
@ -108,6 +105,19 @@ ConfigGadgetWidget::ConfigGadgetWidget(QWidget *parent) : QWidget(parent)
help = 0;
connect(ftw,SIGNAL(currentAboutToShow(int,bool*)),this,SLOT(tabAboutToChange(int,bool*)));//,Qt::BlockingQueuedConnection);
// Connect to the PipXStatus object updates
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
pipxStatusObj = dynamic_cast<UAVDataObject*>(objManager->getObject("PipXStatus"));
if (pipxStatusObj != NULL ) {
connect(pipxStatusObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updatePipXStatus(UAVObject*)));
} else {
qDebug() << "Error: Object is unknown (PipXStatus).";
}
// Create the timer that is used to timeout the connection to the PipX.
pipxTimeout = new QTimer(this);
connect(pipxTimeout, SIGNAL(timeout()),this,SLOT(onPipxtremeDisconnect()));
pipxConnected = false;
}
ConfigGadgetWidget::~ConfigGadgetWidget()
@ -203,5 +213,27 @@ void ConfigGadgetWidget::tabAboutToChange(int i,bool * proceed)
}
}
/*!
\brief Called by updates to @PipXStatus
*/
void ConfigGadgetWidget::updatePipXStatus(UAVObject *object)
{
// Restart the disconnection timer.
pipxTimeout->start(5000);
if (!pipxConnected)
{
qDebug()<<"ConfigGadgetWidget onPipxtremeConnect";
QWidget *qwd = new ConfigPipXtremeWidget(this);
ftw->insertTab(ConfigGadgetWidget::pipxtreme, qwd, QIcon(":/configgadget/images/PipXtreme.png"), QString("PipXtreme"));
ftw->setCurrentIndex(ConfigGadgetWidget::pipxtreme);
pipxConnected = true;
}
}
void ConfigGadgetWidget::onPipxtremeDisconnect() {
qDebug()<<"ConfigGadgetWidget onPipxtremeDisconnect";
pipxTimeout->stop();
ftw->removeTab(ConfigGadgetWidget::pipxtreme);
pipxConnected = false;
}

View File

@ -56,14 +56,25 @@ public slots:
void onAutopilotConnect();
void onAutopilotDisconnect();
void tabAboutToChange(int i,bool *);
void updatePipXStatus(UAVObject *object);
void onPipxtremeDisconnect();
signals:
void autopilotConnected();
void autopilotDisconnected();
void pipxtremeConnect();
void pipxtremeDisconnect();
protected:
void resizeEvent(QResizeEvent * event);
MyTabbedStackWidget *ftw;
private:
UAVDataObject* pipxStatusObj;
// A timer that timesout the connction to the PipX.
QTimer *pipxTimeout;
bool pipxConnected;
};
#endif // CONFIGGADGETWIDGET_H

View File

@ -86,21 +86,16 @@ ConfigPipXtremeWidget::ConfigPipXtremeWidget(QWidget *parent) : ConfigTaskWidget
connect(m_pipx->PairSelect3, SIGNAL(toggled(bool)), this, SLOT(pair3Toggled(bool)));
connect(m_pipx->PairSelect4, SIGNAL(toggled(bool)), this, SLOT(pair4Toggled(bool)));
// Create the timer that is used to timeout the connection to the PipX.
timeOut = new QTimer(this);
connect(timeOut, SIGNAL(timeout()),this,SLOT(disconnected()));
//Add scroll bar when necessary
QScrollArea *scroll = new QScrollArea;
scroll->setWidget(m_pipx->frame_3);
m_pipx->verticalLayout_3->addWidget(scroll);
//Add scroll bar when necessary
QScrollArea *scroll = new QScrollArea;
scroll->setWidget(m_pipx->frame_3);
m_pipx->verticalLayout_3->addWidget(scroll);
// Request and update of the setting object.
settingsUpdated = false;
pipxSettingsObj->requestUpdate();
disableMouseWheelEvents();
//pipxSettingsObj->requestUpdate();
disableMouseWheelEvents();
}
ConfigPipXtremeWidget::~ConfigPipXtremeWidget()
@ -145,9 +140,6 @@ void ConfigPipXtremeWidget::saveSettings()
void ConfigPipXtremeWidget::updateStatus(UAVObject *object)
{
// Restart the disconnection timer.
timeOut->start(10000);
// Request and update of the setting object if we haven't received it yet.
if (!settingsUpdated)
pipxSettingsObj->requestUpdate();
@ -267,14 +259,20 @@ void ConfigPipXtremeWidget::updateStatus(UAVObject *object)
*/
void ConfigPipXtremeWidget::updateSettings(UAVObject *object)
{
settingsUpdated = true;
enableControls(true);
if (!settingsUpdated)
{
settingsUpdated = true;
enableControls(true);
}
}
void ConfigPipXtremeWidget::disconnected()
{
settingsUpdated = false;
enableControls(false);
if (settingsUpdated)
{
settingsUpdated = false;
enableControls(false);
}
}
void ConfigPipXtremeWidget::pairIDToggled(bool checked, quint8 idx)

View File

@ -53,9 +53,6 @@ private:
bool settingsUpdated;
// A timer that timesout the connction to the PipX.
QTimer *timeOut;
private slots:
void refreshValues();
void applySettings();