mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
TelemetryMonitorWidget: add op-131 support for connect/disconnect signals
from telemetrymonitor, slots and timers in connectionmanager;
This commit is contained in:
parent
c414f80fd7
commit
8c3488e220
@ -50,18 +50,13 @@ ConnectionManager::ConnectionManager(Internal::MainWindow *mainWindow, QTabWidge
|
||||
m_ioDev(NULL),
|
||||
m_mainWindow(mainWindow)
|
||||
{
|
||||
// Q_UNUSED(mainWindow);
|
||||
|
||||
/* QVBoxLayout *top = new QVBoxLayout;
|
||||
top->setSpacing(0);
|
||||
top->setMargin(0);*/
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout;
|
||||
layout->setSpacing(5);
|
||||
layout->setContentsMargins(5,2,5,2);
|
||||
|
||||
m_monitor = new TelemetryMonitorWidget(this);
|
||||
layout->addWidget(m_monitor, Qt::AlignHCenter);
|
||||
m_monitorWidget = new TelemetryMonitorWidget(this);
|
||||
layout->addWidget(m_monitorWidget, Qt::AlignHCenter);
|
||||
|
||||
layout->addWidget(new QLabel(tr("Connections:")));
|
||||
|
||||
@ -76,22 +71,26 @@ ConnectionManager::ConnectionManager(Internal::MainWindow *mainWindow, QTabWidge
|
||||
m_connectBtn->setEnabled(false);
|
||||
layout->addWidget(m_connectBtn);
|
||||
|
||||
/* Utils::StyledBar *bar = new Utils::StyledBar;
|
||||
bar->setLayout(layout);
|
||||
|
||||
top->addWidget(bar);*/
|
||||
setLayout(layout);
|
||||
|
||||
// modeStack->insertCornerWidget(modeStack->cornerWidgetCount()-1, this);
|
||||
modeStack->setCornerWidget(this, Qt::TopRightCorner);
|
||||
|
||||
QObject::connect(m_connectBtn, SIGNAL(clicked()), this, SLOT(onConnectClicked()));
|
||||
|
||||
// setup our reconnect timers
|
||||
reconnect = new QTimer(this);
|
||||
reconnectCheck = new QTimer(this);
|
||||
connect(reconnect,SIGNAL(timeout()),this,SLOT(reconnectSlot()));
|
||||
connect(reconnectCheck,SIGNAL(timeout()),this,SLOT(reconnectCheckSlot()));
|
||||
}
|
||||
|
||||
ConnectionManager::~ConnectionManager()
|
||||
{
|
||||
disconnectDevice(); // Pip
|
||||
suspendPolling(); // Pip
|
||||
|
||||
if (m_monitorWidget)
|
||||
delete m_monitorWidget;
|
||||
}
|
||||
|
||||
void ConnectionManager::init()
|
||||
@ -145,8 +144,8 @@ bool ConnectionManager::connectDevice()
|
||||
m_connectBtn->setText("Disconnect");
|
||||
m_availableDevList->setEnabled(false);
|
||||
|
||||
// tell the monitor we're connected
|
||||
m_monitor->connect();
|
||||
// tell the monitorwidget we're conneced
|
||||
m_monitorWidget->connect();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -157,6 +156,9 @@ bool ConnectionManager::connectDevice()
|
||||
*/
|
||||
bool ConnectionManager::disconnectDevice()
|
||||
{
|
||||
// tell the monitor widget we're disconnected
|
||||
m_monitorWidget->disconnect();
|
||||
|
||||
if (!m_ioDev) {
|
||||
// apparently we are already disconnected: this can
|
||||
// happen if a plugin tries to force a disconnect whereas
|
||||
@ -166,6 +168,12 @@ bool ConnectionManager::disconnectDevice()
|
||||
|
||||
// We are connected - disconnect from the device
|
||||
|
||||
// stop our timers
|
||||
if(reconnect->isActive())
|
||||
reconnect->stop();
|
||||
if(reconnectCheck->isActive())
|
||||
reconnectCheck->stop();
|
||||
|
||||
// signal interested plugins that user is disconnecting his device
|
||||
emit deviceAboutToDisconnect();
|
||||
|
||||
@ -176,9 +184,6 @@ bool ConnectionManager::disconnectDevice()
|
||||
qDebug() << "Exception: m_connectionDevice.connection->closeDevice(" << m_connectionDevice.devName << ")";
|
||||
}
|
||||
|
||||
//tell the monitor we're disconnected
|
||||
m_monitor->disconnect();
|
||||
|
||||
m_connectionDevice.connection = NULL;
|
||||
m_ioDev = NULL;
|
||||
|
||||
@ -250,12 +255,55 @@ void ConnectionManager::onConnectClicked()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slot called when the telemetry is connected
|
||||
*/
|
||||
void ConnectionManager::telemetryConnected()
|
||||
{
|
||||
qDebug() << "TelemetryMonitor: connected";
|
||||
|
||||
//tell the monitor we're connected
|
||||
m_monitorWidget->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slot called when the telemetry is disconnected
|
||||
*/
|
||||
void ConnectionManager::telemetryDisconnected()
|
||||
{
|
||||
qDebug() << "TelemetryMonitor: disconnected";
|
||||
|
||||
//tell the monitor we're disconnected
|
||||
m_monitorWidget->disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slot called when the telemetry rates are updated
|
||||
*/
|
||||
void ConnectionManager::telemetryUpdated(double txRate, double rxRate)
|
||||
{
|
||||
m_monitor->updateTelemetry(txRate, rxRate);
|
||||
m_monitorWidget->updateTelemetry(txRate, rxRate);
|
||||
}
|
||||
|
||||
void ConnectionManager::reconnectSlot()
|
||||
{
|
||||
qDebug()<<"reconnect";
|
||||
if(m_ioDev->isOpen())
|
||||
m_ioDev->close();
|
||||
|
||||
if(m_ioDev->open(QIODevice::ReadWrite)) {
|
||||
qDebug()<<"reconnect successfull";
|
||||
reconnect->stop();
|
||||
reconnectCheck->start(20000);
|
||||
}
|
||||
else
|
||||
qDebug()<<"reconnect NOT successfull";
|
||||
}
|
||||
|
||||
void ConnectionManager::reconnectCheckSlot()
|
||||
{
|
||||
reconnectCheck->stop();
|
||||
reconnect->start(1000);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,6 +91,8 @@ signals:
|
||||
void deviceAboutToDisconnect();
|
||||
|
||||
public slots:
|
||||
void telemetryConnected();
|
||||
void telemetryDisconnected();
|
||||
void telemetryUpdated(double txRate, double rxRate);
|
||||
|
||||
private slots:
|
||||
@ -102,7 +104,10 @@ private slots:
|
||||
|
||||
// void onConnectionClosed(QObject *obj);
|
||||
void onConnectionDestroyed(QObject *obj);
|
||||
void connectionsCallBack(); //used to call devChange after all the plugins are loaded
|
||||
void connectionsCallBack(); //used to call devChange after all the plugins are loaded
|
||||
void reconnectSlot();
|
||||
void reconnectCheckSlot();
|
||||
|
||||
protected:
|
||||
QComboBox *m_availableDevList;
|
||||
QPushButton *m_connectBtn;
|
||||
@ -110,7 +115,7 @@ protected:
|
||||
QList<IConnection*> m_connectionsList;
|
||||
|
||||
//tx/rx telemetry monitor
|
||||
TelemetryMonitorWidget* m_monitor;
|
||||
TelemetryMonitorWidget* m_monitorWidget;
|
||||
|
||||
//currently connected connection plugin
|
||||
devListItem m_connectionDevice;
|
||||
@ -120,8 +125,10 @@ protected:
|
||||
|
||||
private:
|
||||
bool connectDevice();
|
||||
Internal::MainWindow *m_mainWindow;
|
||||
QList <IConnection *> connectionBackup;
|
||||
Internal::MainWindow *m_mainWindow;
|
||||
QList <IConnection *> connectionBackup;
|
||||
QTimer *reconnect;
|
||||
QTimer *reconnectCheck;
|
||||
|
||||
};
|
||||
|
||||
|
@ -56,6 +56,8 @@ TelemetryMonitor::TelemetryMonitor(UAVObjectManager* objMngr, Telemetry* tel)
|
||||
statsTimer->start(STATS_CONNECT_PERIOD_MS);
|
||||
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
connect(this,SIGNAL(connected()),cm,SLOT(telemetryConnected()));
|
||||
connect(this,SIGNAL(disconnected()),cm,SLOT(telemetryDisconnected()));
|
||||
connect(this,SIGNAL(telemetryUpdated(double,double)),cm,SLOT(telemetryUpdated(double,double)));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user