2011-08-10 05:52:02 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
2011-08-10 10:27:41 +02:00
|
|
|
* @file configcamerastabilizationwidget.cpp
|
2012-01-02 02:32:03 +01:00
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011.
|
2011-08-10 05:52:02 +02:00
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup ConfigPlugin Config Plugin
|
|
|
|
* @{
|
|
|
|
* @brief The Configuration Gadget used to update settings in the firmware
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* 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 "configcamerastabilizationwidget.h"
|
2011-08-10 10:27:41 +02:00
|
|
|
#include "camerastabsettings.h"
|
|
|
|
#include "hwsettings.h"
|
|
|
|
#include "mixersettings.h"
|
2011-10-11 09:05:24 +02:00
|
|
|
#include "actuatorcommand.h"
|
2011-08-10 10:27:41 +02:00
|
|
|
|
2011-08-10 05:52:02 +02:00
|
|
|
ConfigCameraStabilizationWidget::ConfigCameraStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent)
|
|
|
|
{
|
|
|
|
m_camerastabilization = new Ui_CameraStabilizationWidget();
|
|
|
|
m_camerastabilization->setupUi(this);
|
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
// These widgets don't have direct relation to UAVObjects
|
|
|
|
// and need special processing
|
|
|
|
QComboBox *outputs[] = {
|
2011-10-11 09:05:24 +02:00
|
|
|
m_camerastabilization->rollChannel,
|
|
|
|
m_camerastabilization->pitchChannel,
|
2012-01-02 02:32:03 +01:00
|
|
|
m_camerastabilization->yawChannel,
|
2011-10-11 09:05:24 +02:00
|
|
|
};
|
2012-08-14 16:15:53 +02:00
|
|
|
const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]);
|
2011-10-11 09:05:24 +02:00
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
// Populate widgets with channel numbers
|
|
|
|
for (int i = 0; i < NUM_OUTPUTS; i++) {
|
2011-12-30 21:25:24 +01:00
|
|
|
outputs[i]->clear();
|
|
|
|
outputs[i]->addItem("None");
|
|
|
|
for (quint32 j = 0; j < ActuatorCommand::CHANNEL_NUMELEM; j++)
|
|
|
|
outputs[i]->addItem(QString("Channel %1").arg(j+1));
|
2011-10-11 09:05:24 +02:00
|
|
|
}
|
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
// Load UAVObjects to widget relations from UI file
|
|
|
|
// using objrelation dynamic property
|
2012-08-13 09:13:35 +02:00
|
|
|
autoLoadWidgets();
|
2012-08-14 16:15:53 +02:00
|
|
|
|
|
|
|
// Add some widgets and UAVObjects to track widget dirty state
|
|
|
|
// and monitor UAVObject changes in addition to autoloaded ones
|
|
|
|
addWidget(m_camerastabilization->enableCameraStabilization);
|
|
|
|
addWidget(m_camerastabilization->rollChannel);
|
|
|
|
addWidget(m_camerastabilization->pitchChannel);
|
|
|
|
addWidget(m_camerastabilization->yawChannel);
|
|
|
|
addUAVObject("HwSettings");
|
|
|
|
addUAVObject("MixerSettings");
|
|
|
|
|
2012-05-22 00:20:23 +02:00
|
|
|
disableMouseWheelEvents();
|
2011-08-10 05:52:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigCameraStabilizationWidget::~ConfigCameraStabilizationWidget()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
/*
|
|
|
|
* This overridden function refreshes widgets which have no direct relation
|
|
|
|
* to any of UAVObjects. It saves their dirty state first because update comes
|
|
|
|
* from UAVObjects, and then restores it. Aftewards it calls base class
|
|
|
|
* function to take care of other widgets which were dynamically added.
|
|
|
|
*/
|
|
|
|
void ConfigCameraStabilizationWidget::refreshWidgetsValues(UAVObject *obj)
|
2011-08-11 04:57:17 +02:00
|
|
|
{
|
2012-08-14 16:15:53 +02:00
|
|
|
bool dirty = isDirty();
|
2011-08-11 04:57:17 +02:00
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
// Set module enable checkbox from OptionalModules UAVObject item.
|
|
|
|
// It needs special processing because ConfigTaskWidget uses TRUE/FALSE
|
|
|
|
// for QCheckBox, but OptionalModules uses Enabled/Disabled enum values.
|
2011-12-30 21:25:24 +01:00
|
|
|
HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager());
|
2011-08-10 10:27:41 +02:00
|
|
|
HwSettings::DataFields hwSettingsData = hwSettings->getData();
|
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
m_camerastabilization->enableCameraStabilization->setChecked(
|
|
|
|
hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] == HwSettings::OPTIONALMODULES_ENABLED);
|
|
|
|
|
|
|
|
// Load mixer outputs which are mapped to camera controls
|
2011-12-30 21:25:24 +01:00
|
|
|
MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager());
|
2011-08-10 10:27:41 +02:00
|
|
|
MixerSettings::DataFields mixerSettingsData = mixerSettings->getData();
|
|
|
|
|
|
|
|
// TODO: Need to reformat object so types are an
|
|
|
|
// array themselves. This gets really awkward
|
2012-08-14 16:15:53 +02:00
|
|
|
quint8 *mixerTypes[] = {
|
2011-08-10 10:27:41 +02:00
|
|
|
&mixerSettingsData.Mixer1Type,
|
|
|
|
&mixerSettingsData.Mixer2Type,
|
|
|
|
&mixerSettingsData.Mixer3Type,
|
|
|
|
&mixerSettingsData.Mixer4Type,
|
|
|
|
&mixerSettingsData.Mixer5Type,
|
|
|
|
&mixerSettingsData.Mixer6Type,
|
|
|
|
&mixerSettingsData.Mixer7Type,
|
|
|
|
&mixerSettingsData.Mixer8Type,
|
2011-11-07 22:53:57 +01:00
|
|
|
&mixerSettingsData.Mixer9Type,
|
|
|
|
&mixerSettingsData.Mixer10Type,
|
2011-08-10 10:27:41 +02:00
|
|
|
};
|
2012-08-14 16:15:53 +02:00
|
|
|
const int NUM_MIXERS = sizeof(mixerTypes) / sizeof(mixerTypes[0]);
|
2011-08-10 10:27:41 +02:00
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
QComboBox *outputs[] = {
|
|
|
|
m_camerastabilization->rollChannel,
|
|
|
|
m_camerastabilization->pitchChannel,
|
|
|
|
m_camerastabilization->yawChannel
|
|
|
|
};
|
|
|
|
const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]);
|
2011-08-10 10:27:41 +02:00
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
for (int i = 0; i < NUM_OUTPUTS; i++) {
|
|
|
|
// Default to none if not found.
|
|
|
|
// Then search for any mixer channels set to this
|
|
|
|
outputs[i]->setCurrentIndex(0);
|
|
|
|
for (int j = 0; j < NUM_MIXERS; j++)
|
|
|
|
if (*mixerTypes[j] == (MixerSettings::MIXER1TYPE_CAMERAROLL + i) &&
|
|
|
|
outputs[i]->currentIndex() != (j + 1))
|
|
|
|
outputs[i]->setCurrentIndex(j + 1);
|
2011-08-10 10:27:41 +02:00
|
|
|
}
|
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
setDirty(dirty);
|
2011-08-10 10:27:41 +02:00
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
ConfigTaskWidget::refreshWidgetsValues(obj);
|
2011-08-10 10:27:41 +02:00
|
|
|
}
|
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
/*
|
|
|
|
* This overridden function updates UAVObjects which have no direct relation
|
|
|
|
* to any of widgets. Aftewards it calls base class function to take care of
|
|
|
|
* other object to widget relations which were dynamically added.
|
|
|
|
*/
|
|
|
|
void ConfigCameraStabilizationWidget::updateObjectsFromWidgets()
|
2012-01-02 02:32:03 +01:00
|
|
|
{
|
2012-08-14 16:15:53 +02:00
|
|
|
// Save state of the module enable checkbox first
|
2012-01-02 02:32:03 +01:00
|
|
|
HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager());
|
|
|
|
HwSettings::DataFields hwSettingsData = hwSettings->getData();
|
2012-08-14 16:15:53 +02:00
|
|
|
hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] =
|
|
|
|
m_camerastabilization->enableCameraStabilization->isChecked() ?
|
|
|
|
HwSettings::OPTIONALMODULES_ENABLED : HwSettings::OPTIONALMODULES_DISABLED;
|
|
|
|
hwSettings->setData(hwSettingsData);
|
2011-12-30 21:25:24 +01:00
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
// Update mixer channels which were mapped to camera outputs in case they are
|
|
|
|
// not used for other function yet
|
2011-12-30 21:25:24 +01:00
|
|
|
MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager());
|
2011-08-10 10:27:41 +02:00
|
|
|
MixerSettings::DataFields mixerSettingsData = mixerSettings->getData();
|
|
|
|
|
|
|
|
// TODO: Need to reformat object so types are an
|
|
|
|
// array themselves. This gets really awkward
|
2012-08-14 16:15:53 +02:00
|
|
|
quint8 *mixerTypes[] = {
|
2011-08-10 10:27:41 +02:00
|
|
|
&mixerSettingsData.Mixer1Type,
|
|
|
|
&mixerSettingsData.Mixer2Type,
|
|
|
|
&mixerSettingsData.Mixer3Type,
|
|
|
|
&mixerSettingsData.Mixer4Type,
|
|
|
|
&mixerSettingsData.Mixer5Type,
|
|
|
|
&mixerSettingsData.Mixer6Type,
|
|
|
|
&mixerSettingsData.Mixer7Type,
|
|
|
|
&mixerSettingsData.Mixer8Type,
|
2011-11-07 22:58:08 +01:00
|
|
|
&mixerSettingsData.Mixer9Type,
|
|
|
|
&mixerSettingsData.Mixer10Type,
|
2011-08-10 10:27:41 +02:00
|
|
|
};
|
2012-08-14 16:15:53 +02:00
|
|
|
const int NUM_MIXERS = sizeof(mixerTypes) / sizeof(mixerTypes[0]);
|
2011-08-10 10:27:41 +02:00
|
|
|
|
2012-08-14 16:15:53 +02:00
|
|
|
QComboBox *outputs[] = {
|
|
|
|
m_camerastabilization->rollChannel,
|
|
|
|
m_camerastabilization->pitchChannel,
|
|
|
|
m_camerastabilization->yawChannel
|
|
|
|
};
|
|
|
|
const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]);
|
|
|
|
|
|
|
|
m_camerastabilization->message->setText("");
|
|
|
|
for (int i = 0; i < NUM_OUTPUTS; i++) {
|
|
|
|
// Channel 1 is second entry, so becomes zero
|
|
|
|
int mixerNum = outputs[i]->currentIndex() - 1;
|
|
|
|
|
|
|
|
if ((mixerNum >= 0) && // Short circuit in case of none
|
|
|
|
(*mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_DISABLED) &&
|
|
|
|
(*mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_CAMERAROLL + i) ) {
|
|
|
|
// If the mixer channel already mapped to something, it should not be
|
|
|
|
// used for camera output, we reset it to none
|
|
|
|
outputs[i]->setCurrentIndex(0);
|
|
|
|
m_camerastabilization->message->setText("One of the channels is already assigned, reverted to none");
|
|
|
|
} else {
|
|
|
|
// Make sure no other channels have this output set
|
|
|
|
for (int j = 0; j < NUM_MIXERS; j++)
|
|
|
|
if (*mixerTypes[j] == (MixerSettings::MIXER1TYPE_CAMERAROLL + i))
|
|
|
|
*mixerTypes[j] = MixerSettings::MIXER1TYPE_DISABLED;
|
|
|
|
|
|
|
|
// If this channel is assigned to one of the outputs that is not disabled
|
|
|
|
// set it
|
|
|
|
if ((mixerNum >= 0) && (mixerNum < NUM_MIXERS))
|
|
|
|
*mixerTypes[mixerNum] = MixerSettings::MIXER1TYPE_CAMERAROLL + i;
|
|
|
|
}
|
2011-08-10 10:27:41 +02:00
|
|
|
}
|
2012-08-14 16:15:53 +02:00
|
|
|
mixerSettings->setData(mixerSettingsData);
|
|
|
|
|
|
|
|
ConfigTaskWidget::updateObjectsFromWidgets();
|
2011-08-10 05:52:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
*/
|