32 #include "airspeedsettings.h"
33 #include "flightbatterysettings.h"
34 #include "hottsettings.h"
35 #include "flightbatterystate.h"
36 #include "geofencesettings.h"
37 #include "modulesettings.h"
38 #include "vibrationanalysissettings.h"
40 #include "loggingsettings.h"
41 #include "rgbledsettings.h"
43 #include <QColorDialog>
50 ui =
new Ui::Modules();
54 ui->moduleTab->setCurrentIndex(0);
59 AirspeedSettings *airspeedSettings;
63 ui->cbAutotune->setDisabled(
true);
64 ui->cbTxPid->setDisabled(
true);
65 ui->cbCameraStab->setDisabled(
true);
68 ui->lblOnBoardLeds->setVisible(
false);
69 ui->lblOnBoardLeds->setProperty(
"format", QVariant::fromValue(ui->lblOnBoardLeds->text()));
72 connect(ui->gbAutoCellDetection, &QGroupBox::toggled,
this,
73 &ConfigModuleWidget::autoCellDetectionToggled);
74 connect(ui->sbMaxCellVoltage, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this,
75 &ConfigModuleWidget::maxCellVoltageChanged);
78 connect(ui->gb_measureVoltage, &QGroupBox::toggled,
this,
79 &ConfigModuleWidget::toggleBatteryMonitoringPin);
80 connect(ui->gb_measureCurrent, &QGroupBox::toggled,
this,
81 &ConfigModuleWidget::toggleBatteryMonitoringPin);
82 connect(ui->cbVoltagePin, QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
83 &ConfigModuleWidget::toggleBatteryMonitoringGb);
84 connect(ui->cbCurrentPin, QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
85 &ConfigModuleWidget::toggleBatteryMonitoringGb);
88 connect(ui->sb_voltageRatio, &QAbstractSpinBox::editingFinished,
this,
89 &ConfigModuleWidget::updateVoltageRatio);
90 connect(ui->sb_voltageFactor, &QAbstractSpinBox::editingFinished,
this,
91 &ConfigModuleWidget::updateVoltageFactor);
93 &FlightBatterySettings::SensorCalibrationFactor_VoltageChanged,
this,
94 &ConfigModuleWidget::updateVoltageFactorFromUavo);
98 &ConfigModuleWidget::updateAirspeedGroupbox);
99 connect(ui->gb_airspeedGPS, &QGroupBox::clicked,
this,
100 &ConfigModuleWidget::enableAirspeedTypeGPS);
101 connect(ui->gb_airspeedPitot, &QGroupBox::clicked,
this,
102 &ConfigModuleWidget::enableAirspeedTypePitot);
107 this, &ConfigModuleWidget::updateAnnunciatorTab);
108 updateAnnunciatorTab();
110 enableBatteryTab(
false);
111 enableAirspeedTab(
false);
112 enableHoTTTelemetryTab(
false);
114 enableLoggingTab(
false);
140 QWidget::resizeEvent(event);
149 void ConfigModuleWidget::recheckTabs()
154 ui->cbComBridge->setChecked(
false);
155 ui->cbGPS->setChecked(
false);
156 ui->cbUavoMavlink->setChecked(
false);
157 ui->cbUAVOHottBridge->setChecked(
false);
158 ui->cbUAVOLighttelemetryBridge->setChecked(
false);
159 ui->cbUAVOFrskyBridge->setChecked(
false);
160 ui->cbUAVOMSPBridge->setChecked(
false);
161 ui->cbUAVOFrSkySPortBridge->setChecked(
false);
168 &ConfigModuleWidget::objectUpdated, Qt::UniqueConnection);
173 &ConfigModuleWidget::objectUpdated, Qt::UniqueConnection);
178 &ConfigModuleWidget::objectUpdated, Qt::UniqueConnection);
181 if (taskInfo && taskInfo->getIsPresentOnHardware()) {
184 taskInfo->requestUpdate();
191 &ConfigModuleWidget::objectUpdated, Qt::UniqueConnection);
196 ui->cbAutotune->setDisabled(
true);
197 ui->cbTxPid->setDisabled(
true);
198 ui->cbCameraStab->setDisabled(
true);
202 void ConfigModuleWidget::objectUpdated(
UAVObject *obj,
bool success)
207 ModuleSettings *moduleSettings =
209 Q_ASSERT(moduleSettings);
211 bool enableHott = (taskInfo && taskInfo->getIsPresentOnHardware())
212 ? (taskInfo->getRunning_UAVOHoTTBridge() == TaskInfo::RUNNING_TRUE)
214 bool enableGps = (taskInfo && taskInfo->getIsPresentOnHardware())
215 ? (taskInfo->getRunning_GPS() == TaskInfo::RUNNING_TRUE)
217 enableGps &= moduleSettings->getIsPresentOnHardware();
219 enableGpsTab(enableGps);
221 QString objName = obj->
getName();
223 enableAirspeedTab(success
224 && moduleSettings->getAdminState_Airspeed()
225 == ModuleSettings::ADMINSTATE_ENABLED);
227 enableBatteryTab(success
228 && moduleSettings->getAdminState_Battery()
229 == ModuleSettings::ADMINSTATE_ENABLED);
232 enableHoTTTelemetryTab(success && enableHott);
234 enableLoggingTab(success
235 && moduleSettings->getAdminState_Logging()
236 == ModuleSettings::ADMINSTATE_ENABLED);
243 void ConfigModuleWidget::toggleBatteryMonitoringPin()
245 if (!ui->gb_measureVoltage->isChecked())
246 ui->cbVoltagePin->setCurrentIndex(ui->cbVoltagePin->findText(
"NONE"));
248 if (!ui->gb_measureCurrent->isChecked())
249 ui->cbCurrentPin->setCurrentIndex(ui->cbCurrentPin->findText(
"NONE"));
255 void ConfigModuleWidget::toggleBatteryMonitoringGb()
257 if (ui->cbVoltagePin->currentText().compare(
"NONE") != 0)
258 ui->gb_measureVoltage->setChecked(
true);
260 ui->gb_measureVoltage->setChecked(
false);
262 if (ui->cbCurrentPin->currentText().compare(
"NONE") != 0)
263 ui->gb_measureCurrent->setChecked(
true);
265 ui->gb_measureCurrent->setChecked(
false);
272 void ConfigModuleWidget::updateAirspeedGroupbox(
UAVObject *obj)
276 AirspeedSettings *airspeedSettings;
278 AirspeedSettings::DataFields airspeedSettingsData;
279 airspeedSettingsData = airspeedSettings->getData();
281 ui->gb_airspeedGPS->setChecked(
false);
282 ui->gb_airspeedPitot->setChecked(
false);
284 if (airspeedSettingsData.AirspeedSensorType == AirspeedSettings::AIRSPEEDSENSORTYPE_GPSONLY) {
285 ui->gb_airspeedGPS->setChecked(
true);
287 ui->gb_airspeedPitot->setChecked(
true);
295 void ConfigModuleWidget::enableAirspeedTypeGPS(
bool checked)
298 AirspeedSettings *airspeedSettings;
300 AirspeedSettings::DataFields airspeedSettingsData;
301 airspeedSettingsData = airspeedSettings->getData();
302 airspeedSettingsData.AirspeedSensorType = AirspeedSettings::AIRSPEEDSENSORTYPE_GPSONLY;
303 airspeedSettings->setData(airspeedSettingsData);
311 void ConfigModuleWidget::enableAirspeedTypePitot(
bool checked)
314 AirspeedSettings *airspeedSettings;
316 AirspeedSettings::DataFields airspeedSettingsData;
317 airspeedSettingsData = airspeedSettings->getData();
318 airspeedSettingsData.AirspeedSensorType =
319 AirspeedSettings::AIRSPEEDSENSORTYPE_EAGLETREEAIRSPEEDV3;
320 airspeedSettings->setData(airspeedSettingsData);
325 void ConfigModuleWidget::enableBatteryTab(
bool enabled)
327 int idx = ui->moduleTab->indexOf(ui->tabBattery);
328 ui->moduleTab->setTabEnabled(idx, enabled);
332 void ConfigModuleWidget::enableAirspeedTab(
bool enabled)
334 int idx = ui->moduleTab->indexOf(ui->tabAirspeed);
335 ui->moduleTab->setTabEnabled(idx, enabled);
339 void ConfigModuleWidget::enableHoTTTelemetryTab(
bool enabled)
341 int idx = ui->moduleTab->indexOf(ui->tabHoTTTelemetry);
342 ui->moduleTab->setTabEnabled(idx, enabled);
346 void ConfigModuleWidget::enableGpsTab(
bool enabled)
348 int idx = ui->moduleTab->indexOf(ui->tabGPS);
349 ui->moduleTab->setTabEnabled(idx, enabled);
353 void ConfigModuleWidget::enableLoggingTab(
bool enabled)
355 int idx = ui->moduleTab->indexOf(ui->tabLogging);
356 ui->moduleTab->setTabEnabled(idx, enabled);
360 void ConfigModuleWidget::refreshAdcNames(
void)
369 for (
int i = 0;
i <= 8;
i++) {
371 if (
i < names.length())
372 name = names[
i] + QString(
" (ADC%1)").arg(
i);
374 name = QString(
"N/A (ADC%1)").arg(
i);
376 if (i < ui->cbVoltagePin->count())
377 ui->cbVoltagePin->setItemText(
i, name);
378 if (i < ui->cbCurrentPin->count())
379 ui->cbCurrentPin->setItemText(
i, name);
383 void ConfigModuleWidget::updateVoltageRatio()
385 ui->sb_voltageFactor->setValue(1000.0 / ui->sb_voltageRatio->value());
388 void ConfigModuleWidget::updateVoltageFactor()
390 ui->sb_voltageRatio->setValue(1000.0 / ui->sb_voltageFactor->value());
393 void ConfigModuleWidget::updateVoltageFactorFromUavo(
float value)
395 ui->sb_voltageRatio->setValue(1000.0 / (
double)value);
398 void ConfigModuleWidget::autoCellDetectionToggled(
bool checked)
400 ui->sbMaxCellVoltage->setEnabled(checked);
401 ui->lblMaxCellVoltage->setEnabled(checked);
402 ui->sb_numBatteryCells->setEnabled(!checked);
403 ui->lblNumBatteryCells->setEnabled(!checked);
405 if (ui->sbMaxCellVoltage->property(
"ValueBackup").isValid())
406 ui->sbMaxCellVoltage->setValue(
407 ui->sbMaxCellVoltage->property(
"ValueBackup").toDouble());
409 ui->sbMaxCellVoltage->setValue(
412 ui->sbMaxCellVoltage->setProperty(
"ValueBackup", ui->sbMaxCellVoltage->value());
413 ui->sbMaxCellVoltage->setValue(0.0);
417 void ConfigModuleWidget::maxCellVoltageChanged(
double value)
420 if (!ui->gbAutoCellDetection->isChecked())
421 ui->gbAutoCellDetection->setChecked(
true);
422 }
else if (ui->gbAutoCellDetection->isChecked()) {
423 ui->gbAutoCellDetection->setChecked(
false);
427 void ConfigModuleWidget::setupLedTab()
433 auto obj = qobject_cast<
UAVDataObject *>(objMgr->getObject(
"RGBLEDSettings"));
438 connect(ui->btnLEDDefaultColor, &QPushButton::clicked,
this,
439 &ConfigModuleWidget::ledTabSetColor);
440 connect(ui->btnLEDRange1Begin, &QPushButton::clicked,
this,
441 &ConfigModuleWidget::ledTabSetColor);
442 connect(ui->btnLEDRange1End, &QPushButton::clicked,
this, &ConfigModuleWidget::ledTabSetColor);
445 [=](
bool enable) { tabEnable(ui->tabLED, enable); });
446 tabEnable(ui->tabLED, obj->getIsPresentOnHardware());
449 void ConfigModuleWidget::ledTabUpdate(
UAVObject *obj)
451 auto rgb = qobject_cast<RGBLEDSettings *>(obj);
454 qWarning() <<
"Invalid object!";
458 auto data = rgb->getData();
460 ui->lblLEDDefaultColor->setStyleSheet(QString(
"background: rgb(%0, %1, %2);")
461 .arg(
data.DefaultColor[0])
462 .arg(
data.DefaultColor[1])
463 .arg(
data.DefaultColor[2]));
464 ui->lblLEDRange1Begin->setStyleSheet(QString(
"background: rgb(%0, %1, %2);")
465 .arg(
data.RangeBaseColor[0])
466 .arg(
data.RangeBaseColor[1])
467 .arg(
data.RangeBaseColor[2]));
468 ui->lblLEDRange1End->setStyleSheet(QString(
"background: rgb(%0, %1, %2);")
469 .arg(
data.RangeEndColor[0])
470 .arg(
data.RangeEndColor[1])
471 .arg(
data.RangeEndColor[2]));
474 void ConfigModuleWidget::ledTabSetColor()
476 QPointer<QPushButton> btn = qobject_cast<QPushButton *>(sender());
484 auto obj = objMgr->getObject(
"RGBLEDSettings");
487 auto field = obj->
getField(btn->property(
"fieldname").toString());
491 const QColor initial(field->getValue(0).toInt(), field->getValue(1).toInt(),
492 field->getValue(2).toInt());
493 QColorDialog picker(initial,
this);
495 if (picker.exec() != QDialog::Accepted)
498 const QColor &col = picker.selectedColor();
499 field->setValue(col.red(), 0);
500 field->setValue(col.green(), 1);
501 field->setValue(col.blue(), 2);
503 QPointer<QLabel> lbl(ui->tabLED->findChild<QLabel *>(btn->objectName().replace(
"btn",
"lbl")));
508 QString(
"background: rgb(%0, %1, %2);").arg(col.red()).arg(col.green()).arg(col.blue()));
511 void ConfigModuleWidget::tabEnable(QWidget *tab,
bool enable)
513 int idx = ui->moduleTab->indexOf(tab);
514 if (ui->moduleTab->currentIndex() ==
idx)
515 ui->moduleTab->setCurrentIndex(0);
517 ui->moduleTab->setTabEnabled(idx, enable);
523 void ConfigModuleWidget::updateAnnunciatorTab()
529 static const std::vector<AnuncType> annuncTypes = {
536 static const std::vector<QString> widgets = {
547 for (
const auto &annunc : annuncTypes) {
550 for (
const auto &name : widgets) {
551 const auto widget = ui->tabAnnunc->findChild<QWidget *>(name.arg(annunc.widgetName));
553 widget->setVisible(have);
555 qWarning() <<
"Failed to get widget:" << name.arg(annunc.widgetName);
561 ui->lblOnBoardLeds->setVisible(onBoard > 0);
563 ui->lblOnBoardLeds->setText(
564 ui->lblOnBoardLeds->property(
"format").toString().arg(onBoard));
virtual int onBoardRgbLeds() const
Number of RGB LEDs located on the board The first n LEDs in the chain will apply to on-board LEDs rat...
virtual QStringList getAdcNames()
ConfigModuleWidget(QWidget *parent=nullptr)
virtual bool hasAnnunciator(AnnunciatorType annunc)
Check if the board has the given type of annunciator.
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
void transactionCompleted(UAVObject *obj, bool success)
transactionCompleted. Triggered by a call to emitTransactionCompleted - done in telemetry.cpp whenever a transaction finishes.
UAVObjectField * getField(const QString &name)
void resizeEvent(QResizeEvent *event)
UAVObject * getObject(const QString &name, quint32 instId=0)
Core::IBoardType * getBoardType()
Get the IBoardType corresponding to the connected board.
void presentOnHardwareChanged(UAVDataObject *)
virtual void enableControls(bool enable)