2011-03-28 17:39:22 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
2011-11-17 14:33:49 +01:00
|
|
|
* @file configoutputwidget.cpp
|
2011-03-28 17:39:22 +02:00
|
|
|
* @author E. Lafargue & The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup ConfigPlugin Config Plugin
|
|
|
|
* @{
|
2011-11-17 14:33:49 +01:00
|
|
|
* @brief Servo output configuration panel for the config gadget
|
2011-03-28 17:39:22 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* 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 "configoutputwidget.h"
|
2011-11-09 19:35:53 +01:00
|
|
|
#include "outputchannelform.h"
|
2012-05-21 20:28:29 +02:00
|
|
|
#include "configvehicletypewidget.h"
|
2011-03-28 17:39:22 +02:00
|
|
|
|
2013-12-11 22:22:28 +01:00
|
|
|
#include "mixersettings.h"
|
|
|
|
#include "actuatorcommand.h"
|
|
|
|
#include "actuatorsettings.h"
|
|
|
|
#include "systemsettings.h"
|
|
|
|
#include "uavsettingsimportexport/uavsettingsimportexportfactory.h"
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
#include <coreplugin/generalsettings.h>
|
2011-03-28 17:39:22 +02:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QStringList>
|
2013-09-15 23:06:25 +02:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QTextEdit>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QPushButton>
|
2011-03-29 02:15:56 +02:00
|
|
|
#include <QMessageBox>
|
2011-05-31 09:16:01 +02:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QUrl>
|
2012-07-21 19:07:47 +02:00
|
|
|
|
2014-10-02 21:25:38 +02:00
|
|
|
ConfigOutputWidget::ConfigOutputWidget(QWidget *parent) : ConfigTaskWidget(parent)
|
2011-03-28 17:39:22 +02:00
|
|
|
{
|
2013-05-04 00:13:15 +02:00
|
|
|
ui = new Ui_OutputWidget();
|
|
|
|
ui->setupUi(this);
|
2013-05-19 16:37:30 +02:00
|
|
|
|
2015-02-09 00:52:46 +01:00
|
|
|
ui->gvWarning->setScene(new QGraphicsScene(this));
|
|
|
|
|
2013-03-12 07:35:20 +01:00
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
Core::Internal::GeneralSettings *settings = pm->getObject<Core::Internal::GeneralSettings>();
|
2013-05-19 16:37:30 +02:00
|
|
|
if (!settings->useExpertMode()) {
|
2013-05-04 00:13:15 +02:00
|
|
|
ui->saveRCOutputToRAM->setVisible(false);
|
2013-03-12 07:35:20 +01:00
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
UAVSettingsImportExportFactory *importexportplugin = pm->getObject<UAVSettingsImportExportFactory>();
|
2013-03-12 07:35:20 +01:00
|
|
|
connect(importexportplugin, SIGNAL(importAboutToBegin()), this, SLOT(stopTests()));
|
2011-10-15 22:16:34 +02:00
|
|
|
|
2013-05-04 00:13:15 +02:00
|
|
|
connect(ui->channelOutTest, SIGNAL(toggled(bool)), this, SLOT(runChannelTests(bool)));
|
2011-03-28 17:39:22 +02:00
|
|
|
|
2012-05-28 21:06:34 +02:00
|
|
|
// Configure the task widget
|
2011-05-31 09:16:01 +02:00
|
|
|
// Connect the help button
|
2013-05-04 00:13:15 +02:00
|
|
|
connect(ui->outputHelp, SIGNAL(clicked()), this, SLOT(openHelp()));
|
2012-05-28 21:06:34 +02:00
|
|
|
|
2013-05-04 00:13:15 +02:00
|
|
|
addApplySaveButtons(ui->saveRCOutputToRAM, ui->saveRCOutputToSD);
|
2012-05-28 21:06:34 +02:00
|
|
|
|
|
|
|
// Track the ActuatorSettings object
|
|
|
|
addUAVObject("ActuatorSettings");
|
|
|
|
|
2013-05-04 00:13:15 +02:00
|
|
|
// NOTE: we have channel indices from 0 to 9, but the convention for OP is Channel 1 to Channel 10.
|
|
|
|
// Register for ActuatorSettings changes:
|
|
|
|
for (unsigned int i = 0; i < ActuatorCommand::CHANNEL_NUMELEM; i++) {
|
2014-05-10 20:40:14 +02:00
|
|
|
OutputChannelForm *form = new OutputChannelForm(i, this);
|
2014-05-12 22:30:50 +02:00
|
|
|
form->moveTo(*(ui->channelLayout));
|
2014-05-10 20:40:14 +02:00
|
|
|
|
2013-05-04 00:13:15 +02:00
|
|
|
connect(ui->channelOutTest, SIGNAL(toggled(bool)), form, SLOT(enableChannelTest(bool)));
|
2013-05-19 16:37:30 +02:00
|
|
|
connect(form, SIGNAL(channelChanged(int, int)), this, SLOT(sendChannelTest(int, int)));
|
2014-05-10 20:40:14 +02:00
|
|
|
|
2013-05-04 00:13:15 +02:00
|
|
|
addWidget(form->ui.actuatorMin);
|
|
|
|
addWidget(form->ui.actuatorNeutral);
|
|
|
|
addWidget(form->ui.actuatorMax);
|
|
|
|
addWidget(form->ui.actuatorRev);
|
|
|
|
addWidget(form->ui.actuatorLink);
|
|
|
|
}
|
|
|
|
|
2012-05-28 21:06:34 +02:00
|
|
|
// Associate the buttons with their UAVO fields
|
2013-05-04 00:13:15 +02:00
|
|
|
addWidget(ui->cb_outputRate6);
|
|
|
|
addWidget(ui->cb_outputRate5);
|
|
|
|
addWidget(ui->cb_outputRate4);
|
|
|
|
addWidget(ui->cb_outputRate3);
|
|
|
|
addWidget(ui->cb_outputRate2);
|
|
|
|
addWidget(ui->cb_outputRate1);
|
|
|
|
addWidget(ui->spinningArmed);
|
2011-10-16 01:57:59 +02:00
|
|
|
|
2015-01-30 21:43:59 +01:00
|
|
|
addWidgetBinding("ActuatorSettings", "BankMode", ui->cb_outputMode1, 0, 0, true);
|
|
|
|
addWidgetBinding("ActuatorSettings", "BankMode", ui->cb_outputMode2, 1, 0, true);
|
|
|
|
addWidgetBinding("ActuatorSettings", "BankMode", ui->cb_outputMode3, 2, 0, true);
|
|
|
|
addWidgetBinding("ActuatorSettings", "BankMode", ui->cb_outputMode4, 3, 0, true);
|
|
|
|
addWidgetBinding("ActuatorSettings", "BankMode", ui->cb_outputMode5, 4, 0, true);
|
|
|
|
addWidgetBinding("ActuatorSettings", "BankMode", ui->cb_outputMode6, 5, 0, true);
|
2015-01-24 15:40:21 +01:00
|
|
|
|
2015-02-09 00:52:46 +01:00
|
|
|
systemAlarmsObj = SystemAlarms::GetInstance(getObjectManager());
|
|
|
|
connect(systemAlarmsObj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(updateWarnings(UAVObject *)));
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
disconnect(this, SLOT(refreshWidgetsValues(UAVObject *)));
|
2012-05-28 21:06:34 +02:00
|
|
|
|
2015-01-24 15:40:21 +01:00
|
|
|
populateWidgets();
|
2012-05-28 21:06:34 +02:00
|
|
|
refreshWidgetsValues();
|
2015-01-24 15:40:21 +01:00
|
|
|
|
2013-05-04 00:13:15 +02:00
|
|
|
updateEnableControls();
|
2015-02-09 00:52:46 +01:00
|
|
|
setWarning("PIppo");
|
2011-03-28 17:39:22 +02:00
|
|
|
}
|
2013-03-12 07:35:20 +01:00
|
|
|
|
2013-06-21 09:39:06 +02:00
|
|
|
ConfigOutputWidget::~ConfigOutputWidget()
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2011-11-26 00:47:39 +01:00
|
|
|
void ConfigOutputWidget::enableControls(bool enable)
|
|
|
|
{
|
|
|
|
ConfigTaskWidget::enableControls(enable);
|
2013-05-19 16:37:30 +02:00
|
|
|
|
|
|
|
if (!enable) {
|
2013-05-04 00:13:15 +02:00
|
|
|
ui->channelOutTest->setChecked(false);
|
2013-03-12 07:35:20 +01:00
|
|
|
}
|
2013-05-04 00:13:15 +02:00
|
|
|
ui->channelOutTest->setEnabled(enable);
|
2011-11-26 00:47:39 +01:00
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
|
2014-08-23 15:45:16 +02:00
|
|
|
/**
|
|
|
|
Force update all channels with the values in the OutputChannelForms.
|
|
|
|
*/
|
|
|
|
void ConfigOutputWidget::sendAllChannelTests()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < ActuatorCommand::CHANNEL_NUMELEM; i++) {
|
|
|
|
OutputChannelForm *form = getOutputChannelForm(i);
|
|
|
|
sendChannelTest(i, form->neutral());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-28 17:39:22 +02:00
|
|
|
/**
|
2013-05-19 16:37:30 +02:00
|
|
|
Toggles the channel testing mode by making the GCS take over
|
|
|
|
the ActuatorCommand objects
|
|
|
|
*/
|
2011-03-28 17:39:22 +02:00
|
|
|
void ConfigOutputWidget::runChannelTests(bool state)
|
|
|
|
{
|
2011-10-20 14:20:23 +02:00
|
|
|
SystemAlarms::DataFields systemAlarms = systemAlarmsObj->getData();
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
if (state && systemAlarms.Alarm[SystemAlarms::ALARM_ACTUATOR] != SystemAlarms::ALARM_OK) {
|
2011-10-20 14:20:23 +02:00
|
|
|
QMessageBox mbox;
|
2014-09-30 00:39:51 +02:00
|
|
|
mbox.setText(QString(tr("The actuator module is in an error state. This can also occur because there are no inputs. "
|
|
|
|
"Please fix these before testing outputs.")));
|
2011-10-20 14:20:23 +02:00
|
|
|
mbox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
mbox.exec();
|
|
|
|
|
|
|
|
// Unfortunately must cache this since callback will reoccur
|
|
|
|
accInitialData = ActuatorCommand::GetInstance(getObjectManager())->getMetadata();
|
|
|
|
|
2013-05-04 00:13:15 +02:00
|
|
|
ui->channelOutTest->setChecked(false);
|
2011-10-20 14:20:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-29 02:15:56 +02:00
|
|
|
// Confirm this is definitely what they want
|
2013-05-19 16:37:30 +02:00
|
|
|
if (state) {
|
2011-03-29 02:15:56 +02:00
|
|
|
QMessageBox mbox;
|
2014-09-30 00:39:51 +02:00
|
|
|
mbox.setText(QString(tr("This option will start your motors by the amount selected on the sliders regardless of transmitter."
|
|
|
|
"It is recommended to remove any blades from motors. Are you sure you want to do this?")));
|
2011-03-29 02:15:56 +02:00
|
|
|
mbox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
|
|
int retval = mbox.exec();
|
2013-05-19 16:37:30 +02:00
|
|
|
if (retval != QMessageBox::Yes) {
|
2011-03-29 02:15:56 +02:00
|
|
|
state = false;
|
|
|
|
qDebug() << "Cancelled";
|
2013-05-04 00:13:15 +02:00
|
|
|
ui->channelOutTest->setChecked(false);
|
2011-03-29 02:15:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
ActuatorCommand *obj = ActuatorCommand::GetInstance(getObjectManager());
|
2011-03-28 17:39:22 +02:00
|
|
|
UAVObject::Metadata mdata = obj->getMetadata();
|
2013-03-12 07:35:20 +01:00
|
|
|
if (state) {
|
2011-03-28 17:39:22 +02:00
|
|
|
accInitialData = mdata;
|
2012-03-31 16:59:44 +02:00
|
|
|
UAVObject::SetFlightAccess(mdata, UAVObject::ACCESS_READONLY);
|
|
|
|
UAVObject::SetFlightTelemetryUpdateMode(mdata, UAVObject::UPDATEMODE_ONCHANGE);
|
|
|
|
UAVObject::SetGcsTelemetryAcked(mdata, false);
|
|
|
|
UAVObject::SetGcsTelemetryUpdateMode(mdata, UAVObject::UPDATEMODE_ONCHANGE);
|
2011-03-28 17:39:22 +02:00
|
|
|
mdata.gcsTelemetryUpdatePeriod = 100;
|
2013-05-19 16:37:30 +02:00
|
|
|
} else {
|
2014-10-03 23:14:38 +02:00
|
|
|
mdata = accInitialData; // Restore metadata
|
2011-03-28 17:39:22 +02:00
|
|
|
}
|
|
|
|
obj->setMetadata(mdata);
|
2011-10-16 01:57:59 +02:00
|
|
|
obj->updated();
|
2014-08-23 15:45:16 +02:00
|
|
|
|
|
|
|
// Setup the correct initial channel values when the channel testing mode is turned on.
|
|
|
|
if (state) {
|
|
|
|
sendAllChannelTests();
|
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
}
|
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
OutputChannelForm *ConfigOutputWidget::getOutputChannelForm(const int index) const
|
2011-11-09 19:35:53 +01:00
|
|
|
{
|
2013-05-19 16:37:30 +02:00
|
|
|
QList<OutputChannelForm *> outputChannelForms = findChildren<OutputChannelForm *>();
|
|
|
|
foreach(OutputChannelForm * outputChannelForm, outputChannelForms) {
|
|
|
|
if (outputChannelForm->index() == index) {
|
2011-11-09 19:35:53 +01:00
|
|
|
return outputChannelForm;
|
2013-03-12 07:35:20 +01:00
|
|
|
}
|
2011-11-09 19:35:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// no OutputChannelForm found with given index
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-28 17:39:22 +02:00
|
|
|
/**
|
2013-05-19 16:37:30 +02:00
|
|
|
* Set the label for a channel output assignement
|
|
|
|
*/
|
2014-05-12 22:30:50 +02:00
|
|
|
void ConfigOutputWidget::assignOutputChannel(UAVDataObject *obj, QString &str)
|
2011-03-28 17:39:22 +02:00
|
|
|
{
|
2013-05-19 16:37:30 +02:00
|
|
|
// FIXME: use signal/ slot approach
|
|
|
|
UAVObjectField *field = obj->getField(str);
|
|
|
|
QStringList options = field->getOptions();
|
2011-11-09 19:35:53 +01:00
|
|
|
int index = options.indexOf(field->getValue().toString());
|
|
|
|
|
|
|
|
OutputChannelForm *outputChannelForm = getOutputChannelForm(index);
|
2013-05-19 16:37:30 +02:00
|
|
|
|
|
|
|
if (outputChannelForm) {
|
2014-05-12 22:30:50 +02:00
|
|
|
outputChannelForm->setName(str);
|
2013-03-12 07:35:20 +01:00
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-19 16:37:30 +02:00
|
|
|
Sends the channel value to the UAV to move the servo.
|
|
|
|
Returns immediately if we are not in testing mode
|
|
|
|
*/
|
2011-11-09 19:35:53 +01:00
|
|
|
void ConfigOutputWidget::sendChannelTest(int index, int value)
|
2011-03-28 17:39:22 +02:00
|
|
|
{
|
2013-05-04 00:13:15 +02:00
|
|
|
if (!ui->channelOutTest->isChecked()) {
|
2011-11-09 19:35:53 +01:00
|
|
|
return;
|
2013-03-12 07:35:20 +01:00
|
|
|
}
|
2011-11-09 19:35:53 +01:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
if (index < 0 || (unsigned)index >= ActuatorCommand::CHANNEL_NUMELEM) {
|
2011-11-09 19:35:53 +01:00
|
|
|
return;
|
2013-03-12 07:35:20 +01:00
|
|
|
}
|
2011-11-09 19:35:53 +01:00
|
|
|
|
2011-11-17 14:33:49 +01:00
|
|
|
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(getObjectManager());
|
|
|
|
Q_ASSERT(actuatorCommand);
|
|
|
|
ActuatorCommand::DataFields actuatorCommandFields = actuatorCommand->getData();
|
|
|
|
actuatorCommandFields.Channel[index] = value;
|
|
|
|
actuatorCommand->setData(actuatorCommandFields);
|
2011-03-28 17:39:22 +02:00
|
|
|
}
|
|
|
|
|
2015-01-27 19:39:45 +01:00
|
|
|
void ConfigOutputWidget::setColor(QWidget *widget, const QColor color)
|
|
|
|
{
|
|
|
|
QPalette p(palette());
|
|
|
|
|
2015-02-01 21:27:25 +01:00
|
|
|
p.setColor(QPalette::Background, color);
|
|
|
|
p.setColor(QPalette::Base, color);
|
|
|
|
p.setColor(QPalette::Active, QPalette::Button, color);
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::Button, color);
|
2015-01-27 19:39:45 +01:00
|
|
|
widget->setAutoFillBackground(true);
|
|
|
|
widget->setPalette(p);
|
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
|
|
|
|
/********************************
|
2013-05-19 16:37:30 +02:00
|
|
|
* Output settings
|
|
|
|
*******************************/
|
2011-03-28 17:39:22 +02:00
|
|
|
|
|
|
|
/**
|
2013-05-19 16:37:30 +02:00
|
|
|
Request the current config from the board (RC Output)
|
|
|
|
*/
|
|
|
|
void ConfigOutputWidget::refreshWidgetsValues(UAVObject *obj)
|
2011-03-28 17:39:22 +02:00
|
|
|
{
|
2013-06-21 09:39:06 +02:00
|
|
|
bool dirty = isDirty();
|
|
|
|
|
2015-01-24 21:12:31 +01:00
|
|
|
ConfigTaskWidget::refreshWidgetsValues(obj);
|
|
|
|
|
2012-05-10 00:24:15 +02:00
|
|
|
// Get Actuator Settings
|
|
|
|
ActuatorSettings *actuatorSettings = ActuatorSettings::GetInstance(getObjectManager());
|
2015-01-24 21:12:31 +01:00
|
|
|
|
2012-05-10 00:24:15 +02:00
|
|
|
Q_ASSERT(actuatorSettings);
|
|
|
|
ActuatorSettings::DataFields actuatorSettingsData = actuatorSettings->getData();
|
|
|
|
|
2013-03-11 23:22:10 +01:00
|
|
|
// Get channel descriptions
|
2015-02-02 20:35:39 +01:00
|
|
|
QStringList channelDesc = ConfigVehicleTypeWidget::getChannelDescriptions();
|
2012-05-10 00:24:15 +02:00
|
|
|
|
2015-02-02 20:35:39 +01:00
|
|
|
QList<int> channelBanks;
|
2015-01-27 19:39:45 +01:00
|
|
|
QList<QColor> bankColors;
|
2015-02-01 21:27:25 +01:00
|
|
|
bankColors
|
|
|
|
<< QColor("#C6ECAE")
|
|
|
|
<< QColor("#91E5D3")
|
|
|
|
<< QColor("#FCEC52")
|
|
|
|
<< QColor("#C3A8FF")
|
|
|
|
<< QColor("#F7F7F2")
|
|
|
|
<< QColor("#FF9F51");
|
2015-02-02 20:35:39 +01:00
|
|
|
|
2012-05-10 00:24:15 +02:00
|
|
|
// Initialize output forms
|
2013-05-19 16:37:30 +02:00
|
|
|
QList<OutputChannelForm *> outputChannelForms = findChildren<OutputChannelForm *>();
|
|
|
|
foreach(OutputChannelForm * outputChannelForm, outputChannelForms) {
|
2015-02-02 20:35:39 +01:00
|
|
|
outputChannelForm->setName(channelDesc[outputChannelForm->index()]);
|
2012-05-10 00:24:15 +02:00
|
|
|
|
|
|
|
// init min,max,neutral
|
|
|
|
int minValue = actuatorSettingsData.ChannelMin[outputChannelForm->index()];
|
|
|
|
int maxValue = actuatorSettingsData.ChannelMax[outputChannelForm->index()];
|
2014-05-12 22:30:50 +02:00
|
|
|
outputChannelForm->setRange(minValue, maxValue);
|
2012-05-10 00:24:15 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
int neutral = actuatorSettingsData.ChannelNeutral[outputChannelForm->index()];
|
2014-05-12 22:30:50 +02:00
|
|
|
outputChannelForm->setNeutral(neutral);
|
2011-11-09 19:35:53 +01:00
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
|
2011-05-03 07:41:06 +02:00
|
|
|
// Get the SpinWhileArmed setting
|
2013-05-04 00:13:15 +02:00
|
|
|
ui->spinningArmed->setChecked(actuatorSettingsData.MotorsSpinWhileArmed == ActuatorSettings::MOTORSSPINWHILEARMED_TRUE);
|
2011-05-03 07:41:06 +02:00
|
|
|
|
2015-01-27 19:39:45 +01:00
|
|
|
QList<QLabel *> bank;
|
|
|
|
bank << ui->chBank1 << ui->chBank2 << ui->chBank3 << ui->chBank4 << ui->chBank5 << ui->chBank6;
|
2015-02-02 20:35:39 +01:00
|
|
|
|
2015-01-27 19:39:45 +01:00
|
|
|
QList<QComboBox *> outputRateCombos;
|
|
|
|
outputRateCombos << ui->cb_outputRate1 << ui->cb_outputRate2 << ui->cb_outputRate3 <<
|
|
|
|
ui->cb_outputRate4 << ui->cb_outputRate5 << ui->cb_outputRate6;
|
|
|
|
|
|
|
|
QList<QComboBox *> outputModeCombos;
|
|
|
|
outputModeCombos << ui->cb_outputMode1 << ui->cb_outputMode2 << ui->cb_outputMode3 <<
|
|
|
|
ui->cb_outputMode4 << ui->cb_outputMode5 << ui->cb_outputMode6;
|
|
|
|
|
2015-02-02 20:35:39 +01:00
|
|
|
Q_ASSERT(outputModeCombos.count() == outputRateCombos.count());
|
|
|
|
Q_ASSERT(outputRateCombos.count() == bank.count());
|
|
|
|
|
2015-02-10 23:51:19 +01:00
|
|
|
for (int i = 0; i < outputModeCombos.count(); i++) {
|
2015-02-02 20:35:39 +01:00
|
|
|
// Setup output rates for all banks
|
|
|
|
if (outputRateCombos.at(i)->findText(QString::number(actuatorSettingsData.BankUpdateFreq[i])) == -1) {
|
|
|
|
outputRateCombos.at(i)->addItem(QString::number(actuatorSettingsData.BankUpdateFreq[i]));
|
|
|
|
}
|
|
|
|
outputRateCombos.at(i)->setCurrentIndex(outputRateCombos.at(i)->findText(QString::number(actuatorSettingsData.BankUpdateFreq[i])));
|
|
|
|
|
|
|
|
// Reset to all disabled
|
|
|
|
bank.at(i)->setText("-");
|
|
|
|
|
|
|
|
outputRateCombos.at(i)->setEnabled(false);
|
|
|
|
setColor(outputRateCombos.at(i), palette().color(QPalette::Background));
|
|
|
|
|
|
|
|
outputModeCombos.at(i)->setEnabled(false);
|
|
|
|
setColor(outputModeCombos.at(i), palette().color(QPalette::Background));
|
2015-01-27 19:39:45 +01:00
|
|
|
}
|
2015-01-26 12:24:10 +01:00
|
|
|
|
2013-03-11 23:22:10 +01:00
|
|
|
// Get connected board model
|
2012-05-10 00:24:15 +02:00
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
Q_ASSERT(pm);
|
2013-05-19 16:37:30 +02:00
|
|
|
UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
|
2013-03-11 23:22:10 +01:00
|
|
|
Q_ASSERT(utilMngr);
|
2015-01-27 19:39:45 +01:00
|
|
|
QStringList bankLabels;
|
2013-03-11 23:22:10 +01:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
if (utilMngr) {
|
2011-05-03 16:50:31 +02:00
|
|
|
int board = utilMngr->getBoardModel();
|
2013-03-11 23:22:10 +01:00
|
|
|
// Setup labels and combos for banks according to board type
|
|
|
|
if ((board & 0xff00) == 0x0400) {
|
|
|
|
// Coptercontrol family of boards 4 timer banks
|
2015-01-27 19:39:45 +01:00
|
|
|
bankLabels << "1 (1-3)" << "2 (4)" << "3 (5,7-8)" << "4 (6,9-10)";
|
2015-02-02 20:35:39 +01:00
|
|
|
channelBanks << 1 << 1 << 1 << 2 << 3 << 4 << 3 << 3 << 4 << 4;
|
2013-05-19 16:37:30 +02:00
|
|
|
} else if ((board & 0xff00) == 0x0900) {
|
2013-03-11 23:22:10 +01:00
|
|
|
// Revolution family of boards 6 timer banks
|
2015-01-27 19:39:45 +01:00
|
|
|
bankLabels << "1 (1-2)" << "2 (3)" << "3 (4)" << "4 (5-6)" << "5 (7-8)" << "6 (9-10)";
|
2015-02-02 20:35:39 +01:00
|
|
|
channelBanks << 1 << 1 << 2 << 3 << 4 << 4 << 5 << 5 << 6 << 6;
|
2011-05-03 16:50:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-02 20:35:39 +01:00
|
|
|
int i = 0;
|
2015-01-27 19:39:45 +01:00
|
|
|
foreach(QString banklabel, bankLabels) {
|
|
|
|
bank[i]->setText(banklabel);
|
|
|
|
outputRateCombos[i]->setEnabled(true);
|
|
|
|
setColor(outputRateCombos[i], bankColors[i]);
|
|
|
|
outputModeCombos[i]->setEnabled(true);
|
|
|
|
setColor(outputModeCombos[i], bankColors[i]);
|
|
|
|
i++;
|
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
// Get Channel ranges:
|
2015-01-27 19:39:45 +01:00
|
|
|
i = 0;
|
2013-05-19 16:37:30 +02:00
|
|
|
foreach(OutputChannelForm * outputChannelForm, outputChannelForms) {
|
|
|
|
int minValue = actuatorSettingsData.ChannelMin[outputChannelForm->index()];
|
2011-11-17 14:33:49 +01:00
|
|
|
int maxValue = actuatorSettingsData.ChannelMax[outputChannelForm->index()];
|
2013-05-19 16:37:30 +02:00
|
|
|
|
2014-05-12 22:30:50 +02:00
|
|
|
outputChannelForm->setRange(minValue, maxValue);
|
2015-02-02 20:35:39 +01:00
|
|
|
if (channelBanks.count() > i) {
|
|
|
|
outputChannelForm->setBank(QString("%1").arg(channelBanks.at(i)));
|
|
|
|
outputChannelForm->setColor(bankColors[channelBanks.at(i++) - 1]);
|
2015-01-27 19:39:45 +01:00
|
|
|
}
|
2011-11-17 14:33:49 +01:00
|
|
|
int neutral = actuatorSettingsData.ChannelNeutral[outputChannelForm->index()];
|
2014-05-12 22:30:50 +02:00
|
|
|
outputChannelForm->setNeutral(neutral);
|
2011-03-28 17:39:22 +02:00
|
|
|
}
|
2013-06-21 09:39:06 +02:00
|
|
|
|
|
|
|
setDirty(dirty);
|
2011-03-28 17:39:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-19 16:37:30 +02:00
|
|
|
* Sends the config to the board, without saving to the SD card (RC Output)
|
|
|
|
*/
|
2011-08-02 18:06:17 +02:00
|
|
|
void ConfigOutputWidget::updateObjectsFromWidgets()
|
2011-03-28 17:39:22 +02:00
|
|
|
{
|
2015-01-24 21:12:31 +01:00
|
|
|
ConfigTaskWidget::updateObjectsFromWidgets();
|
2012-05-28 17:40:35 +02:00
|
|
|
|
2011-11-17 14:33:49 +01:00
|
|
|
ActuatorSettings *actuatorSettings = ActuatorSettings::GetInstance(getObjectManager());
|
2013-05-19 16:37:30 +02:00
|
|
|
|
2011-11-17 14:33:49 +01:00
|
|
|
Q_ASSERT(actuatorSettings);
|
2013-05-19 16:37:30 +02:00
|
|
|
if (actuatorSettings) {
|
2012-05-28 17:40:35 +02:00
|
|
|
ActuatorSettings::DataFields actuatorSettingsData = actuatorSettings->getData();
|
|
|
|
|
|
|
|
// Set channel ranges
|
2013-05-19 16:37:30 +02:00
|
|
|
QList<OutputChannelForm *> outputChannelForms = findChildren<OutputChannelForm *>();
|
|
|
|
foreach(OutputChannelForm * outputChannelForm, outputChannelForms) {
|
|
|
|
actuatorSettingsData.ChannelMax[outputChannelForm->index()] = outputChannelForm->max();
|
|
|
|
actuatorSettingsData.ChannelMin[outputChannelForm->index()] = outputChannelForm->min();
|
2012-05-28 17:40:35 +02:00
|
|
|
actuatorSettingsData.ChannelNeutral[outputChannelForm->index()] = outputChannelForm->neutral();
|
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
|
2012-05-28 17:40:35 +02:00
|
|
|
// Set update rates
|
2015-01-24 15:40:21 +01:00
|
|
|
actuatorSettingsData.BankUpdateFreq[0] = ui->cb_outputRate1->currentText().toUInt();
|
|
|
|
actuatorSettingsData.BankUpdateFreq[1] = ui->cb_outputRate2->currentText().toUInt();
|
|
|
|
actuatorSettingsData.BankUpdateFreq[2] = ui->cb_outputRate3->currentText().toUInt();
|
|
|
|
actuatorSettingsData.BankUpdateFreq[3] = ui->cb_outputRate4->currentText().toUInt();
|
|
|
|
actuatorSettingsData.BankUpdateFreq[4] = ui->cb_outputRate5->currentText().toUInt();
|
|
|
|
actuatorSettingsData.BankUpdateFreq[5] = ui->cb_outputRate6->currentText().toUInt();
|
2013-05-04 00:13:15 +02:00
|
|
|
|
|
|
|
actuatorSettingsData.MotorsSpinWhileArmed = ui->spinningArmed->isChecked() ?
|
2013-05-19 16:37:30 +02:00
|
|
|
ActuatorSettings::MOTORSSPINWHILEARMED_TRUE :
|
|
|
|
ActuatorSettings::MOTORSSPINWHILEARMED_FALSE;
|
2012-05-28 17:40:35 +02:00
|
|
|
|
|
|
|
// Apply settings
|
|
|
|
actuatorSettings->setData(actuatorSettingsData);
|
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
}
|
|
|
|
|
2011-05-31 09:16:01 +02:00
|
|
|
void ConfigOutputWidget::openHelp()
|
|
|
|
{
|
2014-05-10 11:56:24 +02:00
|
|
|
QDesktopServices::openUrl(QUrl(tr("http://wiki.openpilot.org/x/WIGf"), QUrl::StrictMode));
|
2011-05-31 09:16:01 +02:00
|
|
|
}
|
2011-03-28 17:39:22 +02:00
|
|
|
|
2011-10-15 22:16:34 +02:00
|
|
|
void ConfigOutputWidget::stopTests()
|
|
|
|
{
|
2013-05-04 00:13:15 +02:00
|
|
|
ui->channelOutTest->setChecked(false);
|
2011-10-15 22:16:34 +02:00
|
|
|
}
|
2015-02-09 00:52:46 +01:00
|
|
|
|
|
|
|
void ConfigOutputWidget::updateWarnings(UAVObject *)
|
|
|
|
{
|
|
|
|
SystemAlarms::DataFields systemAlarms = systemAlarmsObj->getData();
|
|
|
|
|
|
|
|
if (systemAlarms.Alarm[SystemAlarms::ALARM_SYSTEMCONFIGURATION] > SystemAlarms::ALARM_WARNING) {
|
|
|
|
switch (systemAlarms.ExtendedAlarmStatus[SystemAlarms::EXTENDEDALARMSTATUS_SYSTEMCONFIGURATION]) {
|
|
|
|
case SystemAlarms::EXTENDEDALARMSTATUS_UNSUPPORTEDCONFIG_ONESHOT:
|
2015-02-12 00:00:07 +01:00
|
|
|
setWarning(tr("OneShot only works with MainPort settings marked with \"+OneShot\"\nUsing \"PPM_PIN6+OneShot\" bank 4 (output 6) must be set to PWM"));
|
2015-02-09 00:52:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setWarning(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigOutputWidget::setWarning(QString message)
|
|
|
|
{
|
|
|
|
ui->gvWarning->scene()->clear();
|
|
|
|
if (!message.isNull()) {
|
|
|
|
warningPic.load(":/configgadget/images/error.svg");
|
|
|
|
} else {
|
|
|
|
warningPic.load("");
|
|
|
|
}
|
|
|
|
ui->gvWarning->scene()->addPixmap(warningPic);
|
|
|
|
ui->gvWarning->setSceneRect(warningPic.rect());
|
|
|
|
ui->gvWarning->fitInView(warningPic.rect(), Qt::KeepAspectRatio);
|
|
|
|
ui->txtWarning->setText(message);
|
|
|
|
}
|