dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
brainre1configuration.cpp
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 
30 #include "brainre1configuration.h"
31 #include "ui_brainre1configuration.h"
32 
33 #include "hwbrainre1.h"
34 
35 #include <random>
36 
38  : ConfigTaskWidget(parent)
39  , ui(new Ui::BrainRE1Configuration)
40 {
41  ui->setupUi(this);
42 
43  re1_settings_obj = HwBrainRE1::GetInstance(getObjectManager());
44 
45  addUAVObjectToWidgetRelation("HwBrainRE1", "RxPort", ui->cmbRxPort);
46  addUAVObjectToWidgetRelation("HwBrainRE1", "DSMxMode", ui->cmbDSMxMode);
47 
48  addUAVObjectToWidgetRelation("HwBrainRE1", "SerialPort", ui->cmbSerialPort);
49 
50  addUAVObjectToWidgetRelation("HwBrainRE1", "MultiPortMode", ui->cmbMultiPortMode);
51  addUAVObjectToWidgetRelation("HwBrainRE1", "MultiPortSerial", ui->cmbMultiPortSerial);
52  addUAVObjectToWidgetRelation("HwBrainRE1", "MultiPortSerial2", ui->cmbMultiPortSerial2);
53 
54  addUAVObjectToWidgetRelation("HwBrainRE1", "I2CExtBaro", ui->cmbI2CExtBaro);
55  addUAVObjectToWidgetRelation("HwBrainRE1", "I2CExtMag", ui->cmbI2CExtMag);
56  addUAVObjectToWidgetRelation("HwBrainRE1", "ExtMagOrientation", ui->cmbExtMagOrientation);
57 
58  addUAVObjectToWidgetRelation("HwBrainRE1", "USB_HIDPort", ui->cmbUsbHidPort);
59  addUAVObjectToWidgetRelation("HwBrainRE1", "USB_VCPPort", ui->cmbUsbVcpPort);
60 
61  addUAVObjectToWidgetRelation("HwBrainRE1", "IRProtocol", ui->cmbIRProtocol);
62  addUAVObjectToWidgetRelation("HwBrainRE1", "IRIDILap", ui->sbILapID);
63  addUAVObjectToWidgetRelation("HwBrainRE1", "IRIDTrackmate", ui->sbTrackmateID);
64  connect(ui->pbGenerateILap, &QAbstractButton::clicked, this,
65  &BrainRE1Configuration::generateILapID);
66  connect(ui->pbGenerateTrackmate, &QAbstractButton::clicked, this,
67  &BrainRE1Configuration::generateTrackmateID);
68 
69  addUAVObjectToWidgetRelation("HwBrainRE1", "BuzzerType", ui->cmbBuzzerType);
70  addUAVObjectToWidgetRelation("HwBrainRE1", "VideoSyncDetectorThreshold",
71  ui->sbVideoSyncDetectorThreshold);
72 
73  // Load UAVObjects to widget relations from UI file
74  // using objrelation dynamic property
76 
77  enableControls(true);
81 
82  QPixmap img;
83  img = QPixmap(":/brainfpv/images/brainre1.png");
84  ui->imgLabel->setPixmap(img);
85 
86  connect(ui->cmbMultiPortMode, SIGNAL(currentIndexChanged(int)), this, SLOT(mpChanged(int)));
87  connect(ui->cmbI2CExtMag, SIGNAL(currentIndexChanged(int)), this, SLOT(extMagChanged(int)));
88 
89  mpChanged(re1_settings_obj->getMultiPortMode());
90  extMagChanged(re1_settings_obj->getI2CExtMag());
91 }
92 
94 {
95  delete ui;
96 }
97 
98 void BrainRE1Configuration::widgetsContentsChanged()
99 {
101 
102  if ((ui->cmbUsbHidPort->currentIndex() == HwBrainRE1::USB_HIDPORT_USBTELEMETRY)
103  && (ui->cmbUsbVcpPort->currentIndex() == HwBrainRE1::USB_VCPPORT_USBTELEMETRY)) {
104  enableControls(false);
105  ui->lblMsg->setText(tr("Warning: you have configured both USB HID Port and USB VCP Port "
106  "for telemetry, this currently is not supported"));
107  } else if ((ui->cmbUsbHidPort->currentIndex() != HwBrainRE1::USB_HIDPORT_USBTELEMETRY)
108  && (ui->cmbUsbVcpPort->currentIndex() != HwBrainRE1::USB_VCPPORT_USBTELEMETRY)) {
109  enableControls(false);
110  ui->lblMsg->setText(tr("Warning: you have disabled USB Telemetry on both USB HID Port and "
111  "USB VCP Port, this currently is not supported"));
112  } else {
113  ui->lblMsg->setText("");
114  enableControls(true);
115  }
116 }
117 
118 void BrainRE1Configuration::generateILapID()
119 {
120  ui->sbILapID->setValue(generateRandomNumber(9999999));
121 }
122 
123 void BrainRE1Configuration::generateTrackmateID()
124 {
125  uint16_t trackmate_id;
126  bool valid = false;
127  while (!valid) {
128  trackmate_id = generateRandomNumber(0xFFF);
129  // It seems like the ID has some weird requirements:
130  // 1st nibble is 0, 2nd nibble is not 0, 1, 8, or F
131  // 3rd and 4th nibbles are not 0 or F
132  valid = ((trackmate_id & 0x0F00) >> 8) != 0x0;
133  valid = valid && (((trackmate_id & 0x0F00) >> 8) != 0x1);
134  valid = valid && (((trackmate_id & 0x0F00) >> 8) != 0x8);
135  valid = valid && (((trackmate_id & 0x0F00) >> 8) != 0xF);
136  valid = valid && (((trackmate_id & 0x00F0) >> 4) != 0x0);
137  valid = valid && (((trackmate_id & 0x00F0) >> 4) != 0xF);
138  valid = valid && ((trackmate_id & 0x000F) != 0x0);
139  valid = valid && ((trackmate_id & 0x000F) != 0xF);
140  }
141  ui->sbTrackmateID->setValue(trackmate_id);
142 }
143 
144 int BrainRE1Configuration::generateRandomNumber(int max)
145 {
146  // std::default_random_engine generator;
147  std::random_device generator;
148  std::uniform_int_distribution<int> distribution(0, max);
149  // generator.seed(QTime::currentTime().msec());
150  return distribution(generator);
151 }
152 
153 void BrainRE1Configuration::mpChanged(int idx)
154 {
155  QPixmap img;
156  if (idx == HwBrainRE1::MULTIPORTMODE_NORMAL) {
157  img = QPixmap(":/brainfpv/images/re1_mp_normal.png");
158  ui->cmbMultiPortSerial2->setHidden(true);
159  ui->labelMultiPortSerial2->setHidden(true);
160  } else {
161  img = QPixmap(":/brainfpv/images/re1_mp_4pwm.png");
162  ui->cmbMultiPortSerial2->setHidden(false);
163  ui->labelMultiPortSerial2->setHidden(false);
164  }
165  ui->imgLabelMp->setPixmap(img);
166 }
167 
168 void BrainRE1Configuration::extMagChanged(int idx)
169 {
170  if (idx == 0) {
171  ui->cmbExtMagOrientation->setHidden(true);
172  ui->labelExtMagOrientation->setHidden(true);
173  } else {
174  ui->cmbExtMagOrientation->setHidden(false);
175  ui->labelExtMagOrientation->setHidden(false);
176  }
177 }
virtual void widgetsContentsChanged()
void addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, int index=0, double scale=1, bool isLimited=false, bool useUnits=false, QList< int > *defaultReloadGroups=nullptr, quint32 instID=0, bool oneWayBind=false)
Add an UAVObject field to widget relation to the management system Note: This is the instance called ...
BrainRE1Configuration(QWidget *parent=nullptr)
virtual void populateWidgets()
virtual void enableControls(bool enable)
virtual void refreshWidgetsValues(UAVObject *obj=NULL)
UAVObjectManager * getObjectManager()
ConfigTaskWidget::getObjectManager Utility function to get a pointer to the object manager...