mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
OP-1586 Re-factored to get rid of duplicated code.
This commit is contained in:
parent
02f50b952f
commit
516310248c
@ -26,7 +26,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "outputcalibrationutil.h"
|
#include "outputcalibrationutil.h"
|
||||||
#include "actuatorcommand.h"
|
#include "uavobject.h"
|
||||||
|
#include "uavobjectmanager.h"
|
||||||
#include "extensionsystem/pluginmanager.h"
|
#include "extensionsystem/pluginmanager.h"
|
||||||
#include "vehicleconfigurationhelper.h"
|
#include "vehicleconfigurationhelper.h"
|
||||||
#include "manualcontrolsettings.h"
|
#include "manualcontrolsettings.h"
|
||||||
@ -44,15 +45,24 @@ OutputCalibrationUtil::~OutputCalibrationUtil()
|
|||||||
stopChannelOutput();
|
stopChannelOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActuatorCommand * OutputCalibrationUtil::getActuatorCommandObject()
|
||||||
|
{
|
||||||
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||||
|
Q_ASSERT(pm);
|
||||||
|
|
||||||
|
UAVObjectManager *uavObjectManager = pm->getObject<UAVObjectManager>();
|
||||||
|
Q_ASSERT(uavObjectManager);
|
||||||
|
|
||||||
|
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(uavObjectManager);
|
||||||
|
Q_ASSERT(actuatorCommand);
|
||||||
|
|
||||||
|
return actuatorCommand;
|
||||||
|
}
|
||||||
|
|
||||||
void OutputCalibrationUtil::startOutputCalibration()
|
void OutputCalibrationUtil::startOutputCalibration()
|
||||||
{
|
{
|
||||||
if (!c_prepared) {
|
if (!c_prepared) {
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
ActuatorCommand *actuatorCommand = getActuatorCommandObject();
|
||||||
UAVObjectManager *uavObjectManager = pm->getObject<UAVObjectManager>();
|
|
||||||
Q_ASSERT(uavObjectManager);
|
|
||||||
|
|
||||||
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(uavObjectManager);
|
|
||||||
Q_ASSERT(actuatorCommand);
|
|
||||||
UAVObject::Metadata metaData = actuatorCommand->getMetadata();
|
UAVObject::Metadata metaData = actuatorCommand->getMetadata();
|
||||||
c_savedActuatorCommandMetaData = metaData;
|
c_savedActuatorCommandMetaData = metaData;
|
||||||
|
|
||||||
@ -75,13 +85,7 @@ void OutputCalibrationUtil::startOutputCalibration()
|
|||||||
void OutputCalibrationUtil::stopOutputCalibration()
|
void OutputCalibrationUtil::stopOutputCalibration()
|
||||||
{
|
{
|
||||||
if (c_prepared) {
|
if (c_prepared) {
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
ActuatorCommand *actuatorCommand = getActuatorCommandObject();
|
||||||
UAVObjectManager *uavObjectManager = pm->getObject<UAVObjectManager>();
|
|
||||||
Q_ASSERT(uavObjectManager);
|
|
||||||
|
|
||||||
// Restore metadata to what it was before
|
|
||||||
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(uavObjectManager);
|
|
||||||
Q_ASSERT(actuatorCommand);
|
|
||||||
actuatorCommand->setMetadata(c_savedActuatorCommandMetaData);
|
actuatorCommand->setMetadata(c_savedActuatorCommandMetaData);
|
||||||
actuatorCommand->updated();
|
actuatorCommand->updated();
|
||||||
c_prepared = false;
|
c_prepared = false;
|
||||||
@ -126,13 +130,7 @@ void OutputCalibrationUtil::setChannelOutputValue(quint16 value)
|
|||||||
if (m_outputChannel >= 0) {
|
if (m_outputChannel >= 0) {
|
||||||
// Set output value
|
// Set output value
|
||||||
qDebug() << "Setting output value for channel " << m_outputChannel << " to " << value << ".";
|
qDebug() << "Setting output value for channel " << m_outputChannel << " to " << value << ".";
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
ActuatorCommand *actuatorCommand = getActuatorCommandObject();
|
||||||
UAVObjectManager *uavObjectManager = pm->getObject<UAVObjectManager>();
|
|
||||||
Q_ASSERT(uavObjectManager);
|
|
||||||
|
|
||||||
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(uavObjectManager);
|
|
||||||
Q_ASSERT(actuatorCommand);
|
|
||||||
|
|
||||||
ActuatorCommand::DataFields data = actuatorCommand->getData();
|
ActuatorCommand::DataFields data = actuatorCommand->getData();
|
||||||
data.Channel[m_outputChannel] = value;
|
data.Channel[m_outputChannel] = value;
|
||||||
actuatorCommand->setData(data);
|
actuatorCommand->setData(data);
|
||||||
|
@ -29,10 +29,6 @@
|
|||||||
#define OUTPUTCALIBRATIONUTIL_H
|
#define OUTPUTCALIBRATIONUTIL_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QList>
|
|
||||||
#include "uavobject.h"
|
|
||||||
#include "uavobjectmanager.h"
|
|
||||||
#include "vehicleconfigurationsource.h"
|
|
||||||
#include "actuatorcommand.h"
|
#include "actuatorcommand.h"
|
||||||
|
|
||||||
|
|
||||||
@ -44,6 +40,8 @@ public:
|
|||||||
|
|
||||||
static void startOutputCalibration();
|
static void startOutputCalibration();
|
||||||
static void stopOutputCalibration();
|
static void stopOutputCalibration();
|
||||||
|
static ActuatorCommand * getActuatorCommandObject();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void startChannelOutput(quint16 channel, quint16 safeValue);
|
void startChannelOutput(quint16 channel, quint16 safeValue);
|
||||||
void stopChannelOutput();
|
void stopChannelOutput();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user