From 4f4d88ba4caf3e3fe2d393be5ab4c6536c7cf8d0 Mon Sep 17 00:00:00 2001 From: Michael Carpenter Date: Thu, 6 Jun 2013 13:22:32 -0400 Subject: [PATCH] Fix for min/max values of radio configuration sliders not being scaled appropriatly --- src/ui/QGCVehicleConfig.cc | 28 ++++++++++-- src/ui/QGCVehicleConfig.h | 2 + src/ui/designer/QGCRadioChannelDisplay.cpp | 52 ++++++++++++++++++---- 3 files changed, 70 insertions(+), 12 deletions(-) diff --git a/src/ui/QGCVehicleConfig.cc b/src/ui/QGCVehicleConfig.cc index b4500a052..370dfa2bd 100644 --- a/src/ui/QGCVehicleConfig.cc +++ b/src/ui/QGCVehicleConfig.cc @@ -1182,6 +1182,7 @@ void QGCVehicleConfig::parameterChanged(int uas, int component, QString paramete if (ok && index < chanMax) { rcMin[index] = value.toInt(); + updateMinMax(); } } @@ -1191,6 +1192,7 @@ void QGCVehicleConfig::parameterChanged(int uas, int component, QString paramete if (ok && index < chanMax) { rcMax[index] = value.toInt(); + updateMinMax(); } } @@ -1323,6 +1325,26 @@ void QGCVehicleConfig::updateError(const QString& str) ui->statusLabel->setText(str); ui->statusLabel->setStyleSheet(QString("QLabel { margin: 0px 2px; font: 14px; color: %1; background-color: %2; }").arg(QGC::colorDarkWhite.name()).arg(QGC::colorMagenta.name())); } +void QGCVehicleConfig::updateMinMax() +{ + // Order is: roll, pitch, yaw, throttle, mode sw, aux 1-3 + /*ui->rollWidget->setMin(rcMin[0]); + ui->rollWidget->setMax(rcMax[0]); + ui->pitchWidget->setMin(rcMin[1]); + ui->pitchWidget->setMax(rcMax[1]); + ui->yawWidget->setMin(rcMin[2]); + ui->yawWidget->setMax(rcMax[2]); + ui->throttleWidget->setMin(rcMin[3]); + ui->throttleWidget->setMax(rcMax[3]); + ui->radio5Widget->setMin(rcMin[4]); + ui->radio5Widget->setMax(rcMax[4]); + ui->radio6Widget->setMin(rcMin[5]); + ui->radio6Widget->setMax(rcMax[5]); + ui->radio7Widget->setMin(rcMin[6]); + ui->radio7Widget->setMax(rcMax[6]); + ui->radio8Widget->setMin(rcMin[7]); + ui->radio8Widget->setMax(rcMax[7]);*/ +} void QGCVehicleConfig::setRCType(int type) { @@ -1466,7 +1488,7 @@ void QGCVehicleConfig::updateView() if (rcValue[rcMapping[5]] != UINT16_MAX) { //ui->aux1Slider->setValue(rcAux1 * 50 + 50); - ui->radio5Widget->setValue(rcValue[5]); + ui->radio6Widget->setValue(rcValue[5]); ui->chanLabel_6->setText(QString("%1/%2").arg(rcValue[rcMapping[5]]).arg(rcAux1, 5, 'f', 2, QChar(' '))); } else { ui->chanLabel_6->setText(tr("---")); @@ -1474,7 +1496,7 @@ void QGCVehicleConfig::updateView() if (rcValue[rcMapping[6]] != UINT16_MAX) { //ui->aux2Slider->setValue(rcAux2 * 50 + 50); - ui->radio6Widget->setValue(rcValue[6]); + ui->radio7Widget->setValue(rcValue[6]); ui->chanLabel_7->setText(QString("%1/%2").arg(rcValue[rcMapping[6]]).arg(rcAux2, 5, 'f', 2, QChar(' '))); } else { ui->chanLabel_7->setText(tr("---")); @@ -1482,7 +1504,7 @@ void QGCVehicleConfig::updateView() if (rcValue[rcMapping[7]] != UINT16_MAX) { //ui->aux3Slider->setValue(rcAux3 * 50 + 50); - ui->radio7Widget->setValue(rcValue[7]); + ui->radio8Widget->setValue(rcValue[7]); ui->chanLabel_8->setText(QString("%1/%2").arg(rcValue[rcMapping[7]]).arg(rcAux3, 5, 'f', 2, QChar(' '))); } else { ui->chanLabel_8->setText(tr("---")); diff --git a/src/ui/QGCVehicleConfig.h b/src/ui/QGCVehicleConfig.h index 644b3b7ff..a38e450ec 100644 --- a/src/ui/QGCVehicleConfig.h +++ b/src/ui/QGCVehicleConfig.h @@ -57,6 +57,8 @@ public slots: /** Render the data updated */ void updateView(); + void updateMinMax(); + /** Set the RC channel */ void setRollChan(int channel) { rcMapping[0] = channel - 1; diff --git a/src/ui/designer/QGCRadioChannelDisplay.cpp b/src/ui/designer/QGCRadioChannelDisplay.cpp index 21c724f9b..148965eb6 100644 --- a/src/ui/designer/QGCRadioChannelDisplay.cpp +++ b/src/ui/designer/QGCRadioChannelDisplay.cpp @@ -4,7 +4,7 @@ QGCRadioChannelDisplay::QGCRadioChannelDisplay(QWidget *parent) : QWidget(parent { m_showMinMax = false; m_min = 0; - m_max = 0; + m_max = 1; m_value = 1500; m_orientation = Qt::Vertical; m_name = "Yaw"; @@ -26,14 +26,36 @@ void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event) //1500 is the middle, static servo value. QPainter painter(this); + int currval = m_value; + if (currval > m_max) + { + currval = m_max; + } + if (currval < m_min) + { + currval = m_min; + } + if (m_orientation == Qt::Vertical) { painter.drawRect(0,0,width()-1,(height()-1) - (painter.fontMetrics().height() * 2)); painter.setBrush(Qt::SolidPattern); painter.setPen(QColor::fromRgb(50,255,50)); - int newval = (height()-2-(painter.fontMetrics().height() * 2)) * ((float)m_value / 3001.0); - int newvaly = (height()-2-(painter.fontMetrics().height() * 2)) - newval; - painter.drawRect(1,newvaly,width()-3,((height()-2) - newvaly - (painter.fontMetrics().height() * 2))); + //m_value - m_min / m_max - m_min + + if (!m_showMinMax) + { + int newval = (height()-2-(painter.fontMetrics().height() * 2)) * ((float)(currval - m_min) / ((m_max-m_min)+1)); + int newvaly = (height()-2-(painter.fontMetrics().height() * 2)) - newval; + painter.drawRect(1,newvaly,width()-3,((height()-2) - newvaly - (painter.fontMetrics().height() * 2))); + } + else + { + int newval = (height()-2-(painter.fontMetrics().height() * 2)) * ((float)(currval / 3001.0)); + int newvaly = (height()-2-(painter.fontMetrics().height() * 2)) - newval; + painter.drawRect(1,newvaly,width()-3,((height()-2) - newvaly - (painter.fontMetrics().height() * 2))); + } + QString valstr = QString::number(m_value); painter.setPen(QColor::fromRgb(255,255,255)); painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (painter.fontMetrics().height()*1)),m_name); @@ -44,10 +66,7 @@ void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event) painter.setPen(QColor::fromRgb(255,0,0)); int maxyval = (height()-3 - (painter.fontMetrics().height() * 2)) - (((height()-3-(painter.fontMetrics().height() * 2)) * ((float)m_max / 3000.0))); int minyval = (height()-3 - (painter.fontMetrics().height() * 2)) - (((height()-3-(painter.fontMetrics().height() * 2)) * ((float)m_min / 3000.0))); - painter.drawRect(2, - maxyval, - width()-3, - minyval - maxyval); + painter.drawRect(2,maxyval,width()-3,minyval - maxyval); QString minstr = QString::number(m_min); painter.drawText((width() / 2.0) - (painter.fontMetrics().width("min")/2.0),minyval,"min"); painter.drawText((width() / 2.0) - (painter.fontMetrics().width(minstr)/2.0),minyval + painter.fontMetrics().height(),minstr); @@ -64,7 +83,14 @@ void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event) painter.drawRect(0,0,width()-1,(height()-1) - (painter.fontMetrics().height() * 2)); painter.setBrush(Qt::SolidPattern); painter.setPen(QColor::fromRgb(50,255,50)); - painter.drawRect(1,1,(width()-3) * ((float)m_value / 3000.0),(height()-3) - (painter.fontMetrics().height() * 2)); + if (!m_showMinMax) + { + painter.drawRect(1,1,(width()-3) * ((float)(currval-m_min) / (m_max-m_min)),(height()-3) - (painter.fontMetrics().height() * 2)); + } + else + { + painter.drawRect(1,1,(width()-3) * ((float)currval / 3000.0),(height()-3) - (painter.fontMetrics().height() * 2)); + } painter.setPen(QColor::fromRgb(255,255,255)); QString valstr = QString::number(m_value); painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (painter.fontMetrics().height()*1)),m_name); @@ -118,11 +144,19 @@ void QGCRadioChannelDisplay::hideMinMax() void QGCRadioChannelDisplay::setMin(int value) { m_min = value; + if (m_min == m_max) + { + m_min--; + } update(); } void QGCRadioChannelDisplay::setMax(int value) { m_max = value; + if (m_min == m_max) + { + m_max++; + } update(); } -- 2.22.0