ConfigOutputWidget::ConfigOutputWidget(QWidget *parent) : ConfigTaskWidget(parent),wasItMe(false) { m_config = new Ui_OutputWidget(); m_config->setupUi(this); ExtensionSystem::PluginManager *pm=ExtensionSystem::PluginManager::instance(); Core::Internal::GeneralSettings * settings=pm->getObject<Core::Internal::GeneralSettings>(); if(!settings->useExpertMode()) m_config->saveRCOutputToRAM->setVisible(false); UAVSettingsImportExportFactory * importexportplugin = pm->getObject<UAVSettingsImportExportFactory>(); connect(importexportplugin,SIGNAL(importAboutToBegin()),this,SLOT(stopTests())); // 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++) { OutputChannelForm *outputForm = new OutputChannelForm(i, this, i==0); m_config->channelLayout->addWidget(outputForm); connect(m_config->channelOutTest, SIGNAL(toggled(bool)), outputForm, SLOT(enableChannelTest(bool))); connect(outputForm, SIGNAL(channelChanged(int,int)), this, SLOT(sendChannelTest(int,int))); connect(outputForm, SIGNAL(formChanged()), this, SLOT(do_SetDirty())); } connect(m_config->channelOutTest, SIGNAL(toggled(bool)), this, SLOT(runChannelTests(bool))); // Configure the task widget // Connect the help button connect(m_config->outputHelp, SIGNAL(clicked()), this, SLOT(openHelp())); addApplySaveButtons(m_config->saveRCOutputToRAM,m_config->saveRCOutputToSD); // Track the ActuatorSettings object addUAVObject("ActuatorSettings"); // Associate the buttons with their UAVO fields addWidget(m_config->cb_outputRate4); addWidget(m_config->cb_outputRate3); addWidget(m_config->cb_outputRate2); addWidget(m_config->cb_outputRate1); addWidget(m_config->spinningArmed); disconnect(this, SLOT(refreshWidgetsValues(UAVObject*))); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObject* obj = objManager->getObject(QString("ActuatorCommand")); if(UAVObject::GetGcsTelemetryUpdateMode(obj->getMetadata()) == UAVObject::UPDATEMODE_ONCHANGE) this->setEnabled(false); connect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(disableIfNotMe(UAVObject*))); connect(SystemSettings::GetInstance(objManager), SIGNAL(objectUpdated(UAVObject*)),this,SLOT(assignOutputChannels(UAVObject*))); refreshWidgetsValues(); }
/** * Constructor */ ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent),isConnected(false),smartsave(NULL),dirty(false),outOfLimitsStyle("background-color: rgb(255, 0, 0);") { pm = ExtensionSystem::PluginManager::instance(); objManager = pm->getObject<UAVObjectManager>(); TelemetryManager* telMngr = pm->getObject<TelemetryManager>(); connect(telMngr, SIGNAL(connected()), this, SLOT(onAutopilotConnect())); connect(telMngr, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect())); connect(telMngr, SIGNAL(connected()), this, SIGNAL(autoPilotConnected())); connect(telMngr, SIGNAL(disconnected()), this, SIGNAL(autoPilotDisconnected())); UAVSettingsImportExportFactory * importexportplugin = pm->getObject<UAVSettingsImportExportFactory>(); connect(importexportplugin,SIGNAL(importAboutToBegin()),this,SLOT(invalidateObjects())); }
ConfigOutputWidget::ConfigOutputWidget(QWidget *parent) : ConfigTaskWidget(parent) { m_ui = new Ui_OutputWidget(); m_ui->setupUi(this); m_ui->gvFrame->setVisible(false); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); Core::Internal::GeneralSettings *settings = pm->getObject<Core::Internal::GeneralSettings>(); if (!settings->useExpertMode()) { m_ui->saveRCOutputToRAM->setVisible(false); } UAVSettingsImportExportFactory *importexportplugin = pm->getObject<UAVSettingsImportExportFactory>(); connect(importexportplugin, SIGNAL(importAboutToBegin()), this, SLOT(stopTests())); connect(m_ui->channelOutTest, SIGNAL(clicked(bool)), this, SLOT(runChannelTests(bool))); // Configure the task widget // Connect the help button connect(m_ui->outputHelp, SIGNAL(clicked()), this, SLOT(openHelp())); addApplySaveButtons(m_ui->saveRCOutputToRAM, m_ui->saveRCOutputToSD); // Track the ActuatorSettings object addUAVObject("ActuatorSettings"); // 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++) { OutputChannelForm *form = new OutputChannelForm(i, this); form->moveTo(*(m_ui->channelLayout)); connect(m_ui->channelOutTest, SIGNAL(toggled(bool)), form, SLOT(enableChannelTest(bool))); connect(form, SIGNAL(channelChanged(int, int)), this, SLOT(sendChannelTest(int, int))); addWidget(form->ui.actuatorMin); addWidget(form->ui.actuatorNeutral); addWidget(form->ui.actuatorMax); addWidget(form->ui.actuatorRev); addWidget(form->ui.actuatorLink); } // Associate the buttons with their UAVO fields addWidget(m_ui->spinningArmed); MixerSettings *mixer = MixerSettings::GetInstance(getObjectManager()); Q_ASSERT(mixer); m_banks << OutputBankControls(mixer, m_ui->chBank1, QColor("#C6ECAE"), m_ui->cb_outputRate1, m_ui->cb_outputMode1); m_banks << OutputBankControls(mixer, m_ui->chBank2, QColor("#91E5D3"), m_ui->cb_outputRate2, m_ui->cb_outputMode2); m_banks << OutputBankControls(mixer, m_ui->chBank3, QColor("#FCEC52"), m_ui->cb_outputRate3, m_ui->cb_outputMode3); m_banks << OutputBankControls(mixer, m_ui->chBank4, QColor("#C3A8FF"), m_ui->cb_outputRate4, m_ui->cb_outputMode4); m_banks << OutputBankControls(mixer, m_ui->chBank5, QColor("#F7F7F2"), m_ui->cb_outputRate5, m_ui->cb_outputMode5); m_banks << OutputBankControls(mixer, m_ui->chBank6, QColor("#FF9F51"), m_ui->cb_outputRate6, m_ui->cb_outputMode6); QList<int> rates; rates << 50 << 60 << 125 << 165 << 270 << 330 << 400 << 490; int i = 0; foreach(OutputBankControls controls, m_banks) { addWidget(controls.rateCombo()); controls.rateCombo()->addItem(tr("-"), QVariant(0)); controls.rateCombo()->model()->setData(controls.rateCombo()->model()->index(0, 0), QVariant(0), Qt::UserRole - 1); foreach(int rate, rates) { controls.rateCombo()->addItem(tr("%1 Hz").arg(rate), rate); }
ConfigOutputWidget::ConfigOutputWidget(QWidget *parent) : ConfigTaskWidget(parent) { m_config = new Ui_OutputWidget(); m_config->setupUi(this); ExtensionSystem::PluginManager *pm=ExtensionSystem::PluginManager::instance(); Core::Internal::GeneralSettings * settings=pm->getObject<Core::Internal::GeneralSettings>(); if(!settings->useExpertMode()) m_config->saveRCOutputToRAM->setVisible(false); /* There's lots of situations where it's unsafe to run tests. * Import/export: */ UAVSettingsImportExportFactory * importexportplugin = pm->getObject<UAVSettingsImportExportFactory>(); connect(importexportplugin,SIGNAL(importAboutToBegin()),this,SLOT(stopTests())); /* Board connection/disconnection: */ TelemetryManager* telMngr = pm->getObject<TelemetryManager>(); connect(telMngr, SIGNAL(connected()), this, SLOT(stopTests())); connect(telMngr, SIGNAL(disconnected()), this, SLOT(stopTests())); /* When we go into wizards, etc.. time to stop this too. */ Core::ModeManager *modeMngr = Core::ModeManager::instance(); connect(modeMngr, SIGNAL(currentModeAboutToChange(Core::IMode *)), this, SLOT(stopTests())); connect(modeMngr, SIGNAL(currentModeChanged(Core::IMode *)), this, SLOT(stopTests())); // 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++) { OutputChannelForm *outputForm = new OutputChannelForm(i, this, i==0); m_config->channelLayout->addWidget(outputForm); connect(m_config->channelOutTest, SIGNAL(toggled(bool)), outputForm, SLOT(enableChannelTest(bool))); connect(outputForm, SIGNAL(channelChanged(int,int)), this, SLOT(sendChannelTest(int,int))); connect(outputForm, SIGNAL(formChanged()), this, SLOT(do_SetDirty())); } connect(m_config->channelOutTest, SIGNAL(toggled(bool)), this, SLOT(runChannelTests(bool))); connect(m_config->calibrateESC, SIGNAL(clicked()), this, SLOT(startESCCalibration())); // Configure the task widget // Connect the help button connect(m_config->outputHelp, SIGNAL(clicked()), this, SLOT(openHelp())); addApplySaveButtons(m_config->saveRCOutputToRAM,m_config->saveRCOutputToSD); // Track the ActuatorSettings object addUAVObject("ActuatorSettings"); // Associate the buttons with their UAVO fields addWidget(m_config->cb_outputRate6); addWidget(m_config->cb_outputRate5); addWidget(m_config->cb_outputRate4); addWidget(m_config->cb_outputRate3); addWidget(m_config->cb_outputRate2); addWidget(m_config->cb_outputRate1); addWidget(m_config->spinningArmed); // Cache all the combo boxes and labels lblList.clear(); lblList << m_config->chBank1 << m_config->chBank2 << m_config->chBank3 << m_config->chBank4 << m_config->chBank5 << m_config->chBank6; rateList.clear(); rateList << m_config->cb_outputRate1 << m_config->cb_outputRate2 << m_config->cb_outputRate3 << m_config->cb_outputRate4 << m_config->cb_outputRate5 << m_config->cb_outputRate6; resList.clear(); resList << m_config->cb_outputResolution1 << m_config->cb_outputResolution2 << m_config->cb_outputResolution3 << m_config->cb_outputResolution4 << m_config->cb_outputResolution5 << m_config->cb_outputResolution6; // Get the list of output resolutions and assign to the resolution dropdowns ActuatorSettings *actuatorSettings = ActuatorSettings::GetInstance(getObjectManager()); Q_ASSERT(actuatorSettings); UAVObjectField *resolutions = actuatorSettings->getField("TimerPwmResolution"); Q_ASSERT(resolutions); QList<QComboBox*>::iterator resIter; for (resIter = resList.begin(); resIter != resList.end(); resIter++) { QComboBox *res = *resIter; res->clear(); res->addItems(resolutions->getOptions()); addWidget(res); connect(res, SIGNAL(currentIndexChanged(int)), this, SLOT(refreshWidgetRanges())); } QList<QComboBox*>::iterator rateIter; for (rateIter = rateList.begin(); rateIter != rateList.end(); rateIter++) { QComboBox *rate = *rateIter; connect(rate, SIGNAL(currentIndexChanged(int)), this, SLOT(refreshWidgetRanges())); } disconnect(this, SLOT(refreshWidgetsValues(UAVObject*))); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObject* obj = objManager->getObject(QString("ActuatorCommand")); if(UAVObject::GetGcsTelemetryUpdateMode(obj->getMetadata()) == UAVObject::UPDATEMODE_ONCHANGE) this->setEnabled(false); connect(SystemSettings::GetInstance(objManager), SIGNAL(objectUpdated(UAVObject*)),this,SLOT(assignOutputChannels(UAVObject*))); refreshWidgetsValues(); }
// Slot called by the menu manager on user action void UAVSettingsImportExportFactory::importUAVSettings() { // ask for file name QString fileName; QString filters = tr("UAVObjects XML files (*.uav);; XML files (*.xml)"); fileName = QFileDialog::getOpenFileName(0, tr("Import UAV Settings"), "", filters); if (fileName.isEmpty()) { return; } // Now open the file QFile file(fileName); QDomDocument doc("UAVObjects"); file.open(QFile::ReadOnly | QFile::Text); if (!doc.setContent(file.readAll())) { QMessageBox msgBox; msgBox.setText(tr("File Parsing Failed.")); msgBox.setInformativeText(tr("This file is not a correct XML file")); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); return; } file.close(); // find the root of settings subtree emit importAboutToBegin(); qDebug() << "Import about to begin"; QDomElement root = doc.documentElement(); if (root.tagName() == "uavobjects") { root = root.firstChildElement("settings"); } if (root.isNull() || (root.tagName() != "settings")) { QMessageBox msgBox; msgBox.setText(tr("Wrong file contents")); msgBox.setInformativeText(tr("This file does not contain correct UAVSettings")); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); return; } // We are now ok: setup the import summary dialog & update it as we // go along. ImportSummaryDialog swui((QWidget *)Core::ICore::instance()->mainWindow()); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); swui.show(); QDomNode node = root.firstChild(); while (!node.isNull()) { QDomElement e = node.toElement(); if (e.tagName() == "object") { // - Read each object QString uavObjectName = e.attribute("name"); uint uavObjectID = e.attribute("id").toUInt(NULL, 16); // Sanity Check: UAVObject *obj = objManager->getObject(uavObjectName); if (obj == NULL) { // This object is unknown! qDebug() << "Object unknown:" << uavObjectName << uavObjectID; swui.addLine(uavObjectName, "Error (Object unknown)", false); } else { // - Update each field // - Issue and "updated" command bool error = false; bool setError = false; QDomNode field = node.firstChild(); while (!field.isNull()) { QDomElement f = field.toElement(); if (f.tagName() == "field") { UAVObjectField *uavfield = obj->getField(f.attribute("name")); if (uavfield) { QStringList list = f.attribute("values").split(","); if (list.length() == 1) { if (false == uavfield->checkValue(f.attribute("values"))) { qDebug() << "checkValue returned false on: " << uavObjectName << f.attribute("values"); setError = true; } else { uavfield->setValue(f.attribute("values")); } } else { // This is an enum: int i = 0; QStringList list = f.attribute("values").split(","); foreach(QString element, list) { if (false == uavfield->checkValue(element, i)) { qDebug() << "checkValue(list) returned false on: " << uavObjectName << list; setError = true; } else { uavfield->setValue(element, i); } i++; } } } else { error = true; } } field = field.nextSibling(); } obj->updated(); if (error) { swui.addLine(uavObjectName, "Warning (Object field unknown)", true); } else if (uavObjectID != obj->getObjID()) { qDebug() << "Mismatch for Object " << uavObjectName << uavObjectID << " - " << obj->getObjID(); swui.addLine(uavObjectName, "Warning (ObjectID mismatch)", true); } else if (setError) { swui.addLine(uavObjectName, "Warning (Objects field value(s) invalid)", false); } else { swui.addLine(uavObjectName, "OK", true); } }