1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-09 20:46:07 +01:00
LibrePilot/ground/openpilotgcs/src/plugins/config/configpipxtremewidget.cpp

134 lines
4.3 KiB
C++
Raw Normal View History

/**
******************************************************************************
*
* @file configtxpidswidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup ConfigPlugin Config Plugin
* @{
* @brief The Configuration Gadget used to configure the PipXtreme
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "configpipxtremewidget.h"
#include <pipxsettings.h>
#include <pipxstatus.h>
ConfigPipXtremeWidget::ConfigPipXtremeWidget(QWidget *parent) : ConfigTaskWidget(parent)
{
m_pipx = new Ui_PipXtremeWidget();
m_pipx->setupUi(this);
// Connect to the PipXStatus object updates
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
pipxStatusObj = dynamic_cast<UAVDataObject*>(objManager->getObject("PipXStatus"));
if (pipxStatusObj != NULL ) {
connect(pipxStatusObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateStatus(UAVObject*)));
} else {
qDebug() << "Error: Object is unknown (PipXStatus).";
}
addApplySaveButtons(m_pipx->Apply, m_pipx->Save);
}
ConfigPipXtremeWidget::~ConfigPipXtremeWidget()
{
// Do nothing
}
void ConfigPipXtremeWidget::refreshValues()
{
}
void ConfigPipXtremeWidget::applySettings()
{
PipXSettings *pipxSettings = PipXSettings::GetInstance(getObjectManager());
PipXSettings::DataFields pipxSettingsData = pipxSettings->getData();
pipxSettings->setData(pipxSettingsData);
}
void ConfigPipXtremeWidget::saveSettings()
{
applySettings();
UAVObject *obj = PipXSettings::GetInstance(getObjectManager());
saveObjectToSD(obj);
}
/*!
\brief Called by updates to @PipXStatus
*/
void ConfigPipXtremeWidget::updateStatus(UAVObject *object) {
// Update the DeviceID field
UAVObjectField* idField = object->getField("DeviceID");
if (idField) {
m_pipx->DeviceID->setText(QString::number(idField->getValue().toUInt(), 16).toUpper());
} else {
qDebug() << "PipXtremeGadgetWidget: Count not read DeviceID field.";
}
// Update the detected devices.
UAVObjectField* pairIdField = object->getField("PairIDs");
if (pairIdField) {
m_pipx->PairID1->setText(QString::number(pairIdField->getValue(0).toUInt(), 16).toUpper());
m_pipx->PairID2->setText(QString::number(pairIdField->getValue(1).toUInt(), 16).toUpper());
m_pipx->PairID3->setText(QString::number(pairIdField->getValue(2).toUInt(), 16).toUpper());
m_pipx->PairID4->setText(QString::number(pairIdField->getValue(3).toUInt(), 16).toUpper());
} else {
qDebug() << "PipXtremeGadgetWidget: Count not read PairID field.";
}
UAVObjectField* pairRssiField = object->getField("PairSignalStrengths");
if (pairRssiField) {
m_pipx->PairSignalStrength1->setValue(pairRssiField->getValue(0).toInt());
m_pipx->PairSignalStrength2->setValue(pairRssiField->getValue(1).toInt());
m_pipx->PairSignalStrength3->setValue(pairRssiField->getValue(2).toInt());
m_pipx->PairSignalStrength4->setValue(pairRssiField->getValue(3).toInt());
} else {
qDebug() << "PipXtremeGadgetWidget: Count not read PairID field.";
}
// Update the link state
UAVObjectField* linkField = object->getField("LinkState");
if (linkField) {
const char *msg = "Unknown";
switch (linkField->getValue().toInt())
{
case PipXStatus::LINKSTATE_DISCONNECTED:
msg = "Disconnected";
break;
case PipXStatus::LINKSTATE_CONNECTING:
msg = "Connecting";
break;
case PipXStatus::LINKSTATE_CONNECTED:
msg = "Connected";
break;
}
m_pipx->LinkState->setText(msg);
} else {
qDebug() << "PipXtremeGadgetWidget: Count not read link state field.";
}
}
/**
@}
@}
*/