From bbdb176409f39c0d20aab3519af94754c26650ce Mon Sep 17 00:00:00 2001 From: James Cotton Date: Wed, 7 Sep 2011 01:47:10 -0500 Subject: [PATCH] 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. --- .../src/plugins/config/configinputwidget.cpp | 21 +---- .../src/plugins/config/configinputwidget.h | 1 - .../src/plugins/config/configtaskwidget.cpp | 15 ++++ .../src/plugins/config/inputchannelform.cpp | 80 +++++++++++++++++++ .../src/plugins/config/inputchannelform.h | 7 ++ .../src/plugins/config/inputchannelform.ui | 64 ++++++++++++--- 6 files changed, 156 insertions(+), 32 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index f12ae4dd3..a1051f3d4 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -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;isetData(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]; diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.h b/ground/openpilotgcs/src/plugins/config/configinputwidget.h index 912867cf6..0b95371c5 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.h @@ -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); diff --git a/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp index eeb6c08aa..98b10683c 100644 --- a/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp @@ -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(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(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(ow->widget)) + { + ow->field->setValue(cb->value()* ow->scale,ow->index); + } } } diff --git a/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp index 904918a8e..72c2cfd5e 100644 --- a/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp @@ -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); +} diff --git a/ground/openpilotgcs/src/plugins/config/inputchannelform.h b/ground/openpilotgcs/src/plugins/config/inputchannelform.h index 50615cb2c..2567ba275 100644 --- a/ground/openpilotgcs/src/plugins/config/inputchannelform.h +++ b/ground/openpilotgcs/src/plugins/config/inputchannelform.h @@ -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; }; diff --git a/ground/openpilotgcs/src/plugins/config/inputchannelform.ui b/ground/openpilotgcs/src/plugins/config/inputchannelform.ui index dcd469485..1e8b53c7c 100644 --- a/ground/openpilotgcs/src/plugins/config/inputchannelform.ui +++ b/ground/openpilotgcs/src/plugins/config/inputchannelform.ui @@ -6,7 +6,7 @@ 0 0 - 449 + 482 48 @@ -26,7 +26,7 @@ 0 - + @@ -45,24 +45,30 @@ - - - - - - - 255 + + + + + 5 + 0 + + + + + 100 + 16777215 + - + 9999 - + 9999 @@ -95,7 +101,7 @@ true - Receiver type + Type @@ -129,13 +135,45 @@ - + Qt::Horizontal + + + + + 4 + 0 + + + + + 80 + 16777215 + + + + 7 + + + + + + + true + + + + 0 + 0 + + + +