From 689eb2c588df5d7f17cae1af55eaaa6eb7ce4858 Mon Sep 17 00:00:00 2001 From: zedamota Date: Sun, 12 Jun 2011 00:49:05 +0100 Subject: [PATCH] Minor Cleaning --- .../plugins/config/configairframewidget.cpp | 72 +++++++------------ .../src/plugins/config/configccpmwidget.cpp | 7 +- .../src/plugins/config/mixercurvewidget.cpp | 12 +++- .../src/plugins/config/mixercurvewidget.h | 1 + 4 files changed, 37 insertions(+), 55 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configairframewidget.cpp b/ground/openpilotgcs/src/plugins/config/configairframewidget.cpp index d97cb2d77..53296f3f5 100644 --- a/ground/openpilotgcs/src/plugins/config/configairframewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configairframewidget.cpp @@ -397,12 +397,8 @@ void ConfigAirframeWidget::resetCt2Mixer() */ void ConfigAirframeWidget::resetMixer(MixerCurveWidget *mixer, int numElements, double maxvalue) { - QList curveValues; - for (double i=0; iinitCurve(curveValues); + mixer->initLinearCurve((quint32)numElements,maxvalue); } /** @@ -469,38 +465,30 @@ void ConfigAirframeWidget::requestAircraftUpdate() QList curveValues; // If the 1st element of the curve is <= -10, then the curve // is a straight line (that's how the mixer works on the mainboard): - double temp=0; //used to check if default value(all 0s) is being returned if (field->getValue(0).toInt() <= -10) { - double temp=1; - for (double i=0; igetNumElements(); i++) { - curveValues.append(i/(field->getNumElements()-1)); - } - } else { + m_aircraft->multiThrottleCurve->initLinearCurve(field->getNumElements(),(double)1); + m_aircraft->fixedWingThrottle->initLinearCurve(field->getNumElements(),(double)1); + } + else { + double temp=0; double value; for (unsigned int i=0; i < field->getNumElements(); i++) { value=field->getValue(i).toDouble(); temp+=value; curveValues.append(value); } + if(temp==0) + { + m_aircraft->multiThrottleCurve->initLinearCurve(field->getNumElements(),0.95);; + m_aircraft->fixedWingThrottle->initLinearCurve(field->getNumElements(),(double)1); + } + else + { + m_aircraft->multiThrottleCurve->initCurve(curveValues); + m_aircraft->fixedWingThrottle->initCurve(curveValues); + } } // Setup all Throttle1 curves for all types of airframes - if(temp==0) - { curveValues.clear(); - for (double i=0; igetNumElements(); i++) { - curveValues.append(0.95*(i/(field->getNumElements()-1))); - } - m_aircraft->multiThrottleCurve->initCurve(curveValues); - curveValues.clear(); - for (double i=0; igetNumElements(); i++) { - curveValues.append(i/(field->getNumElements()-1)); - } - m_aircraft->fixedWingThrottle->initCurve(curveValues); - } - else - { - m_aircraft->multiThrottleCurve->initCurve(curveValues); - m_aircraft->fixedWingThrottle->initCurve(curveValues); - } // Load the Settings for fixed wing frames: if (frameType.startsWith("FixedWing")) { // Then retrieve how channels are setup @@ -1758,45 +1746,33 @@ void ConfigAirframeWidget::updateCustomAirframeUI() QList curveValues; // If the 1st element of the curve is <= -10, then the curve // is a straight line (that's how the mixer works on the mainboard): - double temp=0; //used to check if default value(all 0s) is being returned if (field->getValue(0).toInt() <= -10) { - double temp=1; - for (double i=0; igetNumElements(); i++) { - curveValues.append(i/(field->getNumElements()-1)); - } + m_aircraft->customThrottle1Curve->initLinearCurve(field->getNumElements(),(double)1); } else { + double temp=0; double value; for (unsigned int i=0; i < field->getNumElements(); i++) { value=field->getValue(i).toDouble(); temp+=value; curveValues.append(value); } + if(temp==0) + m_aircraft->customThrottle1Curve->initLinearCurve(field->getNumElements(),(double)1); + else + m_aircraft->customThrottle1Curve->initCurve(curveValues); } - - // Setup all Throttle1 curves for all types of airframes - if(temp==0) - { curveValues.clear(); - for (double i=0; igetNumElements(); i++) { - curveValues.append(1*(i/(field->getNumElements()-1))); - } - } - m_aircraft->customThrottle1Curve->initCurve(curveValues); - field = obj->getField(QString("ThrottleCurve2")); curveValues.clear();; // If the 1st element of the curve is <= -10, then the curve // is a straight line (that's how the mixer works on the mainboard): if (field->getValue(0).toInt() <= -10) { - for (double i=0; igetNumElements(); i++) { - curveValues.append(i/(field->getNumElements()-1)); - } + m_aircraft->customThrottle2Curve->initLinearCurve(field->getNumElements(),(double)1); } else { for (unsigned int i=0; i < field->getNumElements(); i++) { curveValues.append(field->getValue(i).toDouble()); } + m_aircraft->customThrottle2Curve->initCurve(curveValues); } - m_aircraft->customThrottle2Curve->initCurve(curveValues); - // Retrieve Feed Forward: field = obj->getField(QString("FeedForward")); m_aircraft->customFFSlider->setValue(field->getDouble()*100); diff --git a/ground/openpilotgcs/src/plugins/config/configccpmwidget.cpp b/ground/openpilotgcs/src/plugins/config/configccpmwidget.cpp index bd4239159..84564c14b 100644 --- a/ground/openpilotgcs/src/plugins/config/configccpmwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configccpmwidget.cpp @@ -372,12 +372,7 @@ void ConfigccpmWidget::UpdateType() */ void ConfigccpmWidget::resetMixer(MixerCurveWidget *mixer, int numElements) { - QList curveValues; - for (double i=0; iinitCurve(curveValues); + mixer->initLinearCurve(numElements,(double)1); } void ConfigccpmWidget::UpdateCurveWidgets() diff --git a/ground/openpilotgcs/src/plugins/config/mixercurvewidget.cpp b/ground/openpilotgcs/src/plugins/config/mixercurvewidget.cpp index 2acf5babd..6e031d8d7 100644 --- a/ground/openpilotgcs/src/plugins/config/mixercurvewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/mixercurvewidget.cpp @@ -147,7 +147,17 @@ QList MixerCurveWidget::getCurve() { return list; } - +/** + Sets a linear graph + */ +void MixerCurveWidget::initLinearCurve(quint32 numPoints, double maxValue) +{ + QList points; + for (double i=0; i points); QList getCurve(); + void initLinearCurve(quint32 numPoints, double maxValue); void setCurve(QList); void setMin(double value); void setMax(double value);