1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Input configuration: Make input channel into a dropdown box and make the

neutral position into a slider.  During calibration the slider moves and the
min and max values are updated appropriately.  Also make the collective channel
skippable in the configuration wizard.
This commit is contained in:
James Cotton 2011-09-07 01:47:10 -05:00
parent 1a5fd9f30e
commit bbdb176409
6 changed files with 156 additions and 32 deletions

View File

@ -78,7 +78,6 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent)
connect(m_config->configurationWizard,SIGNAL(clicked()),this,SLOT(goToNormalWizard()));
connect(m_config->runCalibration,SIGNAL(toggled(bool)),this, SLOT(simpleCalibration(bool)));
connect(manualSettingsObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(settingsUpdated()));
connect(m_config->wzNext,SIGNAL(clicked()),this,SLOT(wzNext()));
connect(m_config->wzCancel,SIGNAL(clicked()),this,SLOT(wzCancel()));
@ -565,7 +564,8 @@ void ConfigInputWidget::identifyControls()
}
m_config->wzText->setText(QString(tr("Please move each control once at a time according to the instructions and picture below.\n\n"
"Move the %1 stick")).arg(manualSettingsObj->getFields().at(0)->getElementNames().at(currentCommand)));
if(manualSettingsObj->getField("ChannelGroups")->getElementNames().at(currentCommand).contains("Accessory"))
if(manualSettingsObj->getField("ChannelGroups")->getElementNames().at(currentCommand).contains("Accessory") ||
manualSettingsObj->getField("ChannelGroups")->getElementNames().at(currentCommand).contains("Collective"))
{
m_config->wzNext->setEnabled(true);
}
@ -981,8 +981,6 @@ void ConfigInputWidget::moveFMSlider()
void ConfigInputWidget::updateCalibration()
{
bool changed = false;
manualCommandData=manualCommandObj->getData();
for(uint i=0;i<ManualControlSettings::CHANNELMAX_NUMELEM;++i)
{
@ -995,19 +993,6 @@ void ConfigInputWidget::updateCalibration()
manualSettingsObj->setData(manualSettingsData);
manualSettingsObj->updated();
settingsUpdated();
}
void ConfigInputWidget::settingsUpdated()
{
manualSettingsData=manualSettingsObj->getData();
Q_ASSERT(inputList.length() <= ManualControlSettings::CHANNELGROUPS_NUMELEM);
for(int i = 0; i < inputList.length(); i++) {
inputList[i]->ui->channelNeutral->setMaximum(manualSettingsData.ChannelMax[i]);
inputList[i]->ui->channelNeutral->setMinimum(manualSettingsData.ChannelMin[i]);
inputList[i]->ui->channelNeutral->setValue(manualSettingsData.ChannelNeutral[i]);
}
}
void ConfigInputWidget::simpleCalibration(bool enable)
@ -1026,7 +1011,7 @@ void ConfigInputWidget::simpleCalibration(bool enable)
manualSettingsData.Arming=ManualControlSettings::ARMING_ALWAYSDISARMED;
manualSettingsObj->setData(manualSettingsData);
for (int i = 0; i < ManualControlCommand::CHANNEL_NUMELEM; i++) {
for (unsigned int i = 0; i < ManualControlCommand::CHANNEL_NUMELEM; i++) {
manualSettingsData.ChannelMin[i] = manualCommandData.Channel[i];
manualSettingsData.ChannelNeutral[i] = manualCommandData.Channel[i];
manualSettingsData.ChannelMax[i] = manualCommandData.Channel[i];

View File

@ -134,7 +134,6 @@ private slots:
void invertControls();
void simpleCalibration(bool state);
void updateCalibration();
void settingsUpdated();
protected:
void resizeEvent(QResizeEvent *event);
virtual void enableControls(bool enable);

View File

@ -48,7 +48,9 @@ void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString fiel
UAVObject *obj=NULL;
UAVObjectField *_field=NULL;
obj = objManager->getObject(QString(object));
Q_ASSERT(obj);
_field = obj->getField(QString(field));
Q_ASSERT(_field);
addUAVObjectToWidgetRelation(object,field,widget,_field->getElementNames().indexOf(index));
}
@ -59,6 +61,7 @@ void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString fiel
if(!object.isEmpty())
{
obj = objManager->getObject(QString(object));
Q_ASSERT(obj);
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(refreshWidgetsValues()));
}
//smartsave->addObject(obj);
@ -182,6 +185,10 @@ void ConfigTaskWidget::populateWidgets()
{
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
}
else if(QSlider * cb=qobject_cast<QSlider *>(ow->widget))
{
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
}
}
setDirty(dirtyBack);
}
@ -207,6 +214,10 @@ void ConfigTaskWidget::refreshWidgetsValues()
{
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
}
else if(QSlider * cb=qobject_cast<QSlider *>(ow->widget))
{
cb->setValue(ow->field->getValue(ow->index).toInt()/ow->scale);
}
}
setDirty(dirtyBack);
}
@ -231,6 +242,10 @@ void ConfigTaskWidget::updateObjectsFromWidgets()
{
ow->field->setValue(cb->value()* ow->scale,ow->index);
}
else if(QSlider * cb=qobject_cast<QSlider *>(ow->widget))
{
ow->field->setValue(cb->value()* ow->scale,ow->index);
}
}
}

View File

@ -1,6 +1,8 @@
#include "inputchannelform.h"
#include "ui_inputchannelform.h"
#include "manualcontrolsettings.h"
inputChannelForm::inputChannelForm(QWidget *parent,bool showlegend) :
QWidget(parent),
ui(new Ui::inputChannelForm)
@ -21,9 +23,87 @@ inputChannelForm::inputChannelForm(QWidget *parent,bool showlegend) :
delete ui->legend4;
delete ui->legend5;
}
connect(ui->channelMin,SIGNAL(valueChanged(int)),this,SLOT(minUpdated(int)));
connect(ui->channelMax,SIGNAL(valueChanged(int)),this,SLOT(maxUpdated(int)));
connect(ui->channelGroup,SIGNAL(currentIndexChanged(int)),this,SLOT(groupUpdated()));
// This is awkward but since we want the UI to be a dropdown but the field is not an enum
// it breaks the UAUVObject widget relation of the task gadget. Running the data through
// a spin box fixes this
connect(ui->channelNumberDropdown,SIGNAL(currentIndexChanged(int)),this,SLOT(channelDropdownUpdated(int)));
connect(ui->channelNumber,SIGNAL(valueChanged(int)),this,SLOT(channelNumberUpdated(int)));
}
inputChannelForm::~inputChannelForm()
{
delete ui;
}
void inputChannelForm::minUpdated(int newval)
{
ui->channelNeutral->setMinimum(newval);
}
void inputChannelForm::maxUpdated(int newval)
{
ui->channelNeutral->setMaximum(newval);
}
/**
* Update the channel options based on the selected receiver type
*
* I fully admit this is terrible practice to embed data within UI
* like this. Open to suggestions. JC 2011-09-07
*/
void inputChannelForm::groupUpdated()
{
ui->channelNumberDropdown->clear();
ui->channelNumberDropdown->addItem("Disabled");
quint8 count = 0;
switch(ui->channelGroup->currentIndex()) {
case -1: // Nothing selected
count = 0;
break;
case ManualControlSettings::CHANNELGROUPS_PWM:
count = 8; // Need to make this 6 for CC
break;
case ManualControlSettings::CHANNELGROUPS_PPM:
case ManualControlSettings::CHANNELGROUPS_SBUS:
case ManualControlSettings::CHANNELGROUPS_SPEKTRUM1:
case ManualControlSettings::CHANNELGROUPS_SPEKTRUM2:
count = 12;
break;
case ManualControlSettings::CHANNELGROUPS_GCS:
count = 5;
case ManualControlSettings::CHANNELGROUPS_NONE:
count = 0;
break;
default:
Q_ASSERT(0);
}
for (int i = 0; i < count; i++)
ui->channelNumberDropdown->addItem(QString(tr("Chan %1").arg(i+1)));
ui->channelNumber->setMaximum(count);
ui->channelNumber->setMinimum(0);
}
/**
* Update the dropdown from the hidden control
*/
void inputChannelForm::channelDropdownUpdated(int newval)
{
ui->channelNumber->setValue(newval);
}
/**
* Update the hidden control from the dropdown
*/
void inputChannelForm::channelNumberUpdated(int newval)
{
ui->channelNumberDropdown->setCurrentIndex(newval);
}

View File

@ -16,6 +16,13 @@ public:
~inputChannelForm();
friend class ConfigInputWidget;
private slots:
void minUpdated(int);
void maxUpdated(int);
void groupUpdated();
void channelDropdownUpdated(int);
void channelNumberUpdated(int);
private:
Ui::inputChannelForm *ui;
};

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>449</width>
<width>482</width>
<height>48</height>
</rect>
</property>
@ -26,7 +26,7 @@
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLabel" name="channelName">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
@ -45,24 +45,30 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="channelGroup"/>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="channelNumber">
<property name="maximum">
<number>255</number>
<item row="2" column="2">
<widget class="QComboBox" name="channelGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="1" column="4">
<item row="2" column="4">
<widget class="QSpinBox" name="channelMin">
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="1" column="6">
<item row="2" column="6">
<widget class="QSpinBox" name="channelMax">
<property name="maximum">
<number>9999</number>
@ -95,7 +101,7 @@
<bool>true</bool>
</property>
<property name="text">
<string>Receiver type</string>
<string>Type</string>
</property>
</widget>
</item>
@ -129,13 +135,45 @@
</property>
</widget>
</item>
<item row="1" column="5">
<item row="2" column="5">
<widget class="QSlider" name="channelNeutral">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QComboBox" name="channelNumberDropdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="maxVisibleItems">
<number>7</number>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="channelNumber">
<property name="enabled">
<bool>true</bool>
</property>
<property name="maximumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>