37 , m_background(nullptr)
43 connect(ui->cbMag, &QComboBox::currentTextChanged,
this, &SeppukuConfiguration::magChanged);
44 connect(ui->cbOutputs, &QComboBox::currentTextChanged,
this,
45 &SeppukuConfiguration::outputsChanged);
46 connect(ui->cbRcvrPort, &QComboBox::currentTextChanged,
this, &SeppukuConfiguration::checkRcvr);
47 connect(ui->cbUart1, &QComboBox::currentTextChanged,
this, &SeppukuConfiguration::checkDsm);
48 connect(ui->cbUart3, &QComboBox::currentTextChanged,
this, &SeppukuConfiguration::checkUart3);
49 connect(ui->cbUart4, &QComboBox::currentTextChanged,
this, &SeppukuConfiguration::checkDsm);
50 connect(ui->cbUart6, &QComboBox::currentTextChanged,
this, &SeppukuConfiguration::checkDsm);
51 connect(ui->cbDsmMode, &QComboBox::currentTextChanged,
this, &SeppukuConfiguration::checkDsm);
63 void SeppukuConfiguration::setupGraphicsScene()
65 const QString diagram =
":/dronin/images/seppuku-config.svg";
66 m_renderer =
new QSvgRenderer();
69 if (QFile::exists(diagram) && m_renderer->load(diagram) && m_renderer->isValid()) {
70 m_scene =
new QGraphicsScene(
this);
73 ui->boardDiagram->setScene(m_scene);
75 m_background =
new QGraphicsSvgItem();
78 m_background->setSharedRenderer(m_renderer);
79 m_background->setElementId(
"seppuku");
80 m_background->setOpacity(1.0);
81 m_background->setZValue(0);
82 m_scene->addItem(m_background);
84 m_uart3 = addGraphicsElement(
"uart3");
88 m_uart4 = addGraphicsElement(
"esc78");
92 const QRectF bound = m_background->boundingRect();
93 ui->boardDiagram->setSceneRect(bound);
94 ui->boardDiagram->setRenderHints(QPainter::SmoothPixmapTransform);
95 ui->boardDiagram->fitInView(m_background, Qt::KeepAspectRatio);
97 qWarning() <<
"failed to setup seppuku board diagram!";
101 QGraphicsSvgItem *SeppukuConfiguration::addGraphicsElement(
const QString &elementId)
103 QGraphicsSvgItem *item =
new QGraphicsSvgItem();
106 item->setSharedRenderer(m_renderer);
107 item->setElementId(elementId);
108 item->setOpacity(1.0);
110 item->setZValue(zval++);
111 QMatrix matrix = m_renderer->matrixForElement(elementId);
112 QRectF orig = matrix.mapRect(m_renderer->boundsOnElement(elementId));
113 item->setPos(orig.x(), orig.y());
114 m_scene->addItem(item);
118 void SeppukuConfiguration::showEvent(QShowEvent *event)
122 ui->boardDiagram->fitInView(m_background, Qt::KeepAspectRatio);
129 ui->boardDiagram->fitInView(m_background, Qt::KeepAspectRatio);
134 bool ext = newVal.contains(
"External");
140 void SeppukuConfiguration::outputsChanged(
const QString &newVal)
142 bool uart = newVal.contains(
"UART");
144 m_uart4->setElementId(uart ?
"uart4" :
"esc78");
149 void SeppukuConfiguration::checkExtMag()
151 bool extMag = ui->cbMag->currentText().contains(
"External");
152 bool uartExt = ui->cbUart3->currentText() ==
"I2C";
154 if (extMag && !uartExt)
155 setMessage(
"ExtMag", tr(
"External magnetometer selected but UART3 not configured as I2C!"),
157 else if (uartExt && !extMag)
158 setMessage(
"ExtMag", tr(
"UART3 configured as I2C but external magnetometer not selected."));
160 setMessage(
"ExtMag");
163 void SeppukuConfiguration::checkDsm()
166 dsm |= ui->cbRcvrPort->currentText().contains(
"DSM");
167 dsm |= ui->cbUart1->currentText().contains(
"DSM");
168 dsm |= ui->cbUart3->currentText().contains(
"DSM");
169 dsm |= ui->cbUart4->currentText().contains(
"DSM");
170 dsm |= ui->cbUart6->currentText().contains(
"DSM");
176 void SeppukuConfiguration::checkUart3(
const QString &newVal)
181 bool i2c = newVal.contains(
"I2C");
183 m_uart3->setElementId(i2c ?
"i2c" :
"uart3");
186 void SeppukuConfiguration::checkRcvr(
const QString &newVal)
190 bool dsm = newVal.contains(
"DSM");
191 bool enabled = newVal !=
"Disabled";
195 tr(
"Please remember to solder ONLY the 3V3 receiver voltage jumper under the board."),
200 tr(
"Please remember to solder ONE of the receiver voltage jumpers under the board."),
203 setMessage(
"RxPower");
206 void SeppukuConfiguration::setMessage(
const QString &name,
const QString &msg,
207 const QString &severity)
209 QLabel *lbl = ui->gbMessages->findChild<QLabel *>(name);
213 lbl->setObjectName(name);
214 ui->gbMessages->layout()->addWidget(lbl);
215 ui->gbMessages->layout()->setAlignment(lbl, Qt::AlignTop);
SeppukuConfiguration(QWidget *parent=nullptr)