Commit 2ae4b4393b53de46d4c240c376a22bbfef8a83b8
1 parent
0dd75a14
New SiSpinBox
Showing
7 changed files
with
169 additions
and
71 deletions
openhantek/ChangeLog
| ... | ... | @@ -176,3 +176,7 @@ |
| 176 | 176 | |
| 177 | 177 | 2012-11-05 Oliver Haag <oliver.haag@gmail.com> |
| 178 | 178 | * Bugfix: short instead of long int for DSO-2250 trigger offset |
| 179 | + | |
| 180 | +2012-11-05 Oliver Haag <oliver.haag@gmail.com> | |
| 181 | +* Added new SiSpinBox | |
| 182 | +* Replaced ComboBox with SiSpinBox for time- and frequencybase | ... | ... |
openhantek/OpenHantek.pro
| ... | ... | @@ -26,6 +26,7 @@ SOURCES += \ |
| 26 | 26 | src/configpages.cpp \ |
| 27 | 27 | src/dataanalyzer.cpp \ |
| 28 | 28 | src/dockwindows.cpp \ |
| 29 | + src/dso.cpp \ | |
| 29 | 30 | src/dsocontrol.cpp \ |
| 30 | 31 | src/dsowidget.cpp \ |
| 31 | 32 | src/exporter.cpp \ |
| ... | ... | @@ -36,16 +37,17 @@ SOURCES += \ |
| 36 | 37 | src/main.cpp \ |
| 37 | 38 | src/openhantek.cpp \ |
| 38 | 39 | src/settings.cpp \ |
| 40 | + src/sispinbox.cpp \ | |
| 39 | 41 | src/hantek/control.cpp \ |
| 40 | 42 | src/hantek/device.cpp \ |
| 41 | - src/hantek/types.cpp \ | |
| 42 | - src/dso.cpp | |
| 43 | + src/hantek/types.cpp | |
| 43 | 44 | HEADERS += \ |
| 44 | 45 | src/colorbox.h \ |
| 45 | 46 | src/configdialog.h \ |
| 46 | 47 | src/configpages.h \ |
| 47 | 48 | src/dataanalyzer.h \ |
| 48 | 49 | src/dockwindows.h \ |
| 50 | + src/dso.h \ | |
| 49 | 51 | src/dsocontrol.h \ |
| 50 | 52 | src/dsowidget.h \ |
| 51 | 53 | src/exporter.h \ |
| ... | ... | @@ -55,10 +57,10 @@ HEADERS += \ |
| 55 | 57 | src/levelslider.h \ |
| 56 | 58 | src/openhantek.h \ |
| 57 | 59 | src/settings.h \ |
| 60 | + src/sispinbox.h \ | |
| 58 | 61 | src/hantek/control.h \ |
| 59 | 62 | src/hantek/device.h \ |
| 60 | - src/hantek/types.h \ | |
| 61 | - src/dso.h | |
| 63 | + src/hantek/types.h | |
| 62 | 64 | |
| 63 | 65 | # Ressource files |
| 64 | 66 | RESOURCES += \ | ... | ... |
openhantek/src/dockwindows.cpp
| ... | ... | @@ -32,6 +32,7 @@ |
| 32 | 32 | #include "dockwindows.h" |
| 33 | 33 | |
| 34 | 34 | #include "settings.h" |
| 35 | +#include "sispinbox.h" | |
| 35 | 36 | #include "helper.h" |
| 36 | 37 | |
| 37 | 38 | |
| ... | ... | @@ -44,29 +45,20 @@ |
| 44 | 45 | HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent, Qt::WindowFlags flags) : QDockWidget(tr("Horizontal"), parent, flags) { |
| 45 | 46 | this->settings = settings; |
| 46 | 47 | |
| 47 | - // Initialize lists for comboboxes | |
| 48 | - this->timebaseSteps << 1e-8 << 2e-8 << 4e-8 << 1e-7 << 2e-7 << 4e-7 | |
| 49 | - << 1e-6 << 2e-6 << 4e-6 << 1e-5 << 2e-5 << 4e-5 << 1e-4 << 2e-4 << 4e-4 | |
| 50 | - << 1e-3 << 2e-3 << 4e-3 << 1e-2 << 2e-2 << 4e-2 << 1e-1 << 2e-1 << 4e-1 | |
| 51 | - << 1e0 << 2e0 << 4e0 << 1e1 << 2e1 << 4e1 << 6e1 << 12e1 << 24e1 | |
| 52 | - << 6e2 << 12e2 << 24e2 << 36e2; ///< Timebase steps in seconds/div | |
| 53 | - for(QList<double>::iterator timebase = this->timebaseSteps.begin(); timebase != this->timebaseSteps.end(); ++timebase) | |
| 54 | - this->timebaseStrings << Helper::valueToString(*timebase, Helper::UNIT_SECONDS, 0); | |
| 55 | - this->frequencybaseSteps | |
| 56 | - << 1.0 << 2.0 << 5.0 << 1e1 << 2e1 << 5e1 << 1e2 << 2e2 << 5e2 | |
| 57 | - << 1e3 << 2e3 << 5e3 << 1e4 << 2e4 << 4e4 << 1e5 << 2e5 << 5e5 | |
| 58 | - << 1e6 << 2e6 << 5e6 << 1e7; ///< Frequencybase steps in Hz/div | |
| 59 | - for(QList<double>::iterator frequencybase = this->frequencybaseSteps.begin(); frequencybase != this->frequencybaseSteps.end(); ++frequencybase) | |
| 60 | - this->frequencybaseStrings << Helper::valueToString(*frequencybase, Helper::UNIT_HERTZ, 0); | |
| 61 | - | |
| 62 | 48 | // Initialize elements |
| 63 | 49 | this->timebaseLabel = new QLabel(tr("Timebase")); |
| 64 | - this->timebaseComboBox = new QComboBox(); | |
| 65 | - this->timebaseComboBox->addItems(this->timebaseStrings); | |
| 50 | + this->timebaseSiSpinBox = new SiSpinBox(Helper::UNIT_SECONDS); | |
| 51 | + this->timebaseSiSpinBox->setMinimum(1e-9); | |
| 52 | + this->timebaseSiSpinBox->setMaximum(3.6e3); | |
| 53 | + | |
| 54 | + QList<double> frequencybaseSteps; | |
| 55 | + frequencybaseSteps << 1.0 << 2.0 << 5.0 << 10.0; | |
| 66 | 56 | |
| 67 | 57 | this->frequencybaseLabel = new QLabel(tr("Frequencybase")); |
| 68 | - this->frequencybaseComboBox = new QComboBox(); | |
| 69 | - this->frequencybaseComboBox->addItems(this->frequencybaseStrings); | |
| 58 | + this->frequencybaseSiSpinBox = new SiSpinBox(Helper::UNIT_HERTZ); | |
| 59 | + this->frequencybaseSiSpinBox->setSteps(frequencybaseSteps); | |
| 60 | + this->frequencybaseSiSpinBox->setMinimum(1.0); | |
| 61 | + this->frequencybaseSiSpinBox->setMaximum(100e6); | |
| 70 | 62 | |
| 71 | 63 | this->formatLabel = new QLabel(tr("Format")); |
| 72 | 64 | this->formatComboBox = new QComboBox(); |
| ... | ... | @@ -77,9 +69,9 @@ HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent, Qt::Windo |
| 77 | 69 | this->dockLayout->setColumnMinimumWidth(0, 64); |
| 78 | 70 | this->dockLayout->setColumnStretch(1, 1); |
| 79 | 71 | this->dockLayout->addWidget(this->timebaseLabel, 0, 0); |
| 80 | - this->dockLayout->addWidget(this->timebaseComboBox, 0, 1); | |
| 72 | + this->dockLayout->addWidget(this->timebaseSiSpinBox, 0, 1); | |
| 81 | 73 | this->dockLayout->addWidget(this->frequencybaseLabel, 1, 0); |
| 82 | - this->dockLayout->addWidget(this->frequencybaseComboBox, 1, 1); | |
| 74 | + this->dockLayout->addWidget(this->frequencybaseSiSpinBox, 1, 1); | |
| 83 | 75 | this->dockLayout->addWidget(this->formatLabel, 2, 0); |
| 84 | 76 | this->dockLayout->addWidget(this->formatComboBox, 2, 1); |
| 85 | 77 | |
| ... | ... | @@ -90,8 +82,8 @@ HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent, Qt::Windo |
| 90 | 82 | this->setWidget(this->dockWidget); |
| 91 | 83 | |
| 92 | 84 | // Connect signals and slots |
| 93 | - connect(this->frequencybaseComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(frequencybaseSelected(int))); | |
| 94 | - connect(this->timebaseComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(timebaseSelected(int))); | |
| 85 | + connect(this->frequencybaseSiSpinBox, SIGNAL(valueChanged(double)), this, SLOT(frequencybaseSelected(double))); | |
| 86 | + connect(this->timebaseSiSpinBox, SIGNAL(valueChanged(double)), this, SLOT(timebaseSelected(double))); | |
| 95 | 87 | connect(this->formatComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(formatSelected(int))); |
| 96 | 88 | |
| 97 | 89 | // Set values |
| ... | ... | @@ -114,26 +106,14 @@ void HorizontalDock::closeEvent(QCloseEvent *event) { |
| 114 | 106 | |
| 115 | 107 | /// \brief Changes the frequencybase if the new value is supported. |
| 116 | 108 | /// \param frequencybase The frequencybase in hertz. |
| 117 | -/// \return Index of frequencybase-value, -1 on error. | |
| 118 | -int HorizontalDock::setFrequencybase(double frequencybase) { | |
| 119 | - int index = this->frequencybaseSteps.indexOf(frequencybase); | |
| 120 | - | |
| 121 | - if(index != -1) | |
| 122 | - this->frequencybaseComboBox->setCurrentIndex(index); | |
| 123 | - | |
| 124 | - return index; | |
| 109 | +void HorizontalDock::setFrequencybase(double frequencybase) { | |
| 110 | + this->frequencybaseSiSpinBox->setValue(frequencybase); | |
| 125 | 111 | } |
| 126 | 112 | |
| 127 | 113 | /// \brief Changes the timebase if the new value is supported. |
| 128 | 114 | /// \param timebase The timebase in seconds. |
| 129 | -/// \return Index of timebase-value, -1 on error. | |
| 130 | -int HorizontalDock::setTimebase(double timebase) { | |
| 131 | - int index = this->timebaseSteps.indexOf(timebase); | |
| 132 | - | |
| 133 | - if(index != -1) | |
| 134 | - this->timebaseComboBox->setCurrentIndex(index); | |
| 135 | - | |
| 136 | - return index; | |
| 115 | +void HorizontalDock::setTimebase(double timebase) { | |
| 116 | + this->timebaseSiSpinBox->setValue(timebase); | |
| 137 | 117 | } |
| 138 | 118 | |
| 139 | 119 | /// \brief Changes the format if the new value is supported. |
| ... | ... | @@ -149,17 +129,17 @@ int HorizontalDock::setFormat(Dso::GraphFormat format) { |
| 149 | 129 | } |
| 150 | 130 | |
| 151 | 131 | /// \brief Called when the frequencybase combo box changes it's value. |
| 152 | -/// \param index The index of the combo box item. | |
| 153 | -void HorizontalDock::frequencybaseSelected(int index) { | |
| 154 | - this->settings->scope.horizontal.frequencybase = this->frequencybaseSteps.at(index); | |
| 155 | - emit frequencybaseChanged(this->settings->scope.horizontal.frequencybase); | |
| 132 | +/// \param frequencybase The frequencybase in hertz. | |
| 133 | +void HorizontalDock::frequencybaseSelected(double frequencybase) { | |
| 134 | + this->settings->scope.horizontal.frequencybase = frequencybase; | |
| 135 | + emit frequencybaseChanged(frequencybase); | |
| 156 | 136 | } |
| 157 | 137 | |
| 158 | 138 | /// \brief Called when the timebase combo box changes it's value. |
| 159 | -/// \param index The index of the combo box item. | |
| 160 | -void HorizontalDock::timebaseSelected(int index) { | |
| 161 | - this->settings->scope.horizontal.timebase = this->timebaseSteps.at(index); | |
| 162 | - emit timebaseChanged(this->settings->scope.horizontal.timebase); | |
| 139 | +/// \param timebase The timebase in seconds. | |
| 140 | +void HorizontalDock::timebaseSelected(double timebase) { | |
| 141 | + this->settings->scope.horizontal.timebase = timebase; | |
| 142 | + emit timebaseChanged(timebase); | |
| 163 | 143 | } |
| 164 | 144 | |
| 165 | 145 | /// \brief Called when the format combo box changes it's value. | ... | ... |
openhantek/src/dockwindows.h
| ... | ... | @@ -39,6 +39,8 @@ class QLabel; |
| 39 | 39 | class QCheckBox; |
| 40 | 40 | class QComboBox; |
| 41 | 41 | |
| 42 | +class SiSpinBox; | |
| 43 | + | |
| 42 | 44 | |
| 43 | 45 | //////////////////////////////////////////////////////////////////////////////// |
| 44 | 46 | /// \class HorizontalDock dockwindows.h |
| ... | ... | @@ -51,8 +53,8 @@ class HorizontalDock : public QDockWidget { |
| 51 | 53 | HorizontalDock(DsoSettings *settings, QWidget *parent = 0, Qt::WindowFlags flags = 0); |
| 52 | 54 | ~HorizontalDock(); |
| 53 | 55 | |
| 54 | - int setFrequencybase(double timebase); | |
| 55 | - int setTimebase(double timebase); | |
| 56 | + void setFrequencybase(double timebase); | |
| 57 | + void setTimebase(double timebase); | |
| 56 | 58 | int setFormat(Dso::GraphFormat format); |
| 57 | 59 | |
| 58 | 60 | protected: |
| ... | ... | @@ -63,21 +65,17 @@ class HorizontalDock : public QDockWidget { |
| 63 | 65 | QLabel *timebaseLabel; ///< The label for the timebase combobox |
| 64 | 66 | QLabel *frequencybaseLabel; ///< The label for the frequencybase combobox |
| 65 | 67 | QLabel *formatLabel; ///< The label for the format combobox |
| 66 | - QComboBox *timebaseComboBox; ///< Selects the timebase for voltage graphs | |
| 67 | - QComboBox *frequencybaseComboBox; ///< Selects the frequencybase for spectrum graphs | |
| 68 | + SiSpinBox *timebaseSiSpinBox; ///< Selects the timebase for voltage graphs | |
| 69 | + SiSpinBox *frequencybaseSiSpinBox; ///< Selects the frequencybase for spectrum graphs | |
| 68 | 70 | QComboBox *formatComboBox; ///< Selects the way the sampled data is interpreted and shown |
| 69 | 71 | |
| 70 | 72 | DsoSettings *settings; ///< The settings provided by the parent class |
| 71 | 73 | |
| 72 | - QList<double> frequencybaseSteps; ///< The selectable steps for the frequencybase | |
| 73 | - QList<double> timebaseSteps; ///< The selectable steps for the timebase | |
| 74 | - QStringList frequencybaseStrings; ///< String representations for the frequencybase steps | |
| 75 | - QStringList timebaseStrings; ///< String representations for the timebase steps | |
| 76 | 74 | QStringList formatStrings; ///< Strings for the formats |
| 77 | 75 | |
| 78 | 76 | protected slots: |
| 79 | - void frequencybaseSelected(int index); | |
| 80 | - void timebaseSelected(int index); | |
| 77 | + void frequencybaseSelected(double frequencybase); | |
| 78 | + void timebaseSelected(double timebase); | |
| 81 | 79 | void formatSelected(int index); |
| 82 | 80 | |
| 83 | 81 | signals: | ... | ... |
openhantek/src/hantek/types.cpp
| ... | ... | @@ -673,13 +673,13 @@ namespace Hantek { |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /// \brief Get the downsampling state in ESamplerateBits. |
| 676 | - /// \return The samplerateFast state. | |
| 676 | + /// \return The downsampling state. | |
| 677 | 677 | bool BulkSetSamplerate2250::getDownsampling() { |
| 678 | 678 | return ((ESamplerateBits *) &(this->array[2]))->downsampling == 1; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - /// \brief Set the samplerateFast in ESamplerateBits to the given value. | |
| 682 | - /// \param value The new samplerateFast value. | |
| 681 | + /// \brief Set the downsampling in ESamplerateBits to the given state. | |
| 682 | + /// \param downsampling The new downsampling state. | |
| 683 | 683 | void BulkSetSamplerate2250::setDownsampling(bool downsampling) { |
| 684 | 684 | ((ESamplerateBits *) &(this->array[2]))->downsampling = downsampling ? 1 : 0; |
| 685 | 685 | } | ... | ... |
openhantek/src/helper.cpp
| ... | ... | @@ -25,6 +25,8 @@ |
| 25 | 25 | #include <cmath> |
| 26 | 26 | |
| 27 | 27 | #include <QApplication> |
| 28 | +#include <QLocale> | |
| 29 | +#include <QStringList> | |
| 28 | 30 | |
| 29 | 31 | #if LIBUSB_VERSION == 0 |
| 30 | 32 | #include <usb.h> |
| ... | ... | @@ -74,7 +76,7 @@ namespace Helper { |
| 74 | 76 | } |
| 75 | 77 | } |
| 76 | 78 | |
| 77 | - /// \brief Converts double to string containing value and (prefix+)unit. | |
| 79 | + /// \brief Converts double to string containing value and (prefix+)unit (Counterpart to Helper::stringToValue). | |
| 78 | 80 | /// \param value The value in prefixless units. |
| 79 | 81 | /// \param unit The unit for the value. |
| 80 | 82 | /// \param precision Significant digits, 0 for integer, -1 for auto. |
| ... | ... | @@ -87,9 +89,9 @@ namespace Helper { |
| 87 | 89 | // Voltage string representation |
| 88 | 90 | int logarithm = floor(log10(fabs(value))); |
| 89 | 91 | if(value < 1e-3) |
| 90 | - return QApplication::tr("%L1 \265V").arg(value * 1e6, 0, format, (precision <= 0) ? precision : qBound(0, precision - 7 - logarithm, precision)); | |
| 92 | + return QApplication::tr("%L1 \265V").arg(value / 1e-6, 0, format, (precision <= 0) ? precision : qBound(0, precision - 7 - logarithm, precision)); | |
| 91 | 93 | else if(value < 1.0) |
| 92 | - return QApplication::tr("%L1 mV").arg(value * 1e3, 0, format, (precision <= 0) ? precision : (precision - 4 - logarithm)); | |
| 94 | + return QApplication::tr("%L1 mV").arg(value / 1e-3, 0, format, (precision <= 0) ? precision : (precision - 4 - logarithm)); | |
| 93 | 95 | else |
| 94 | 96 | return QApplication::tr("%L1 V").arg(value, 0, format, (precision <= 0) ? precision : qMax(0, precision - 1 - logarithm)); |
| 95 | 97 | } |
| ... | ... | @@ -100,13 +102,13 @@ namespace Helper { |
| 100 | 102 | case UNIT_SECONDS: |
| 101 | 103 | // Time string representation |
| 102 | 104 | if(value < 1e-9) |
| 103 | - return QApplication::tr("%L1 ps").arg(value * 1e12, 0, format, (precision <= 0) ? precision : qBound(0, precision - 13 - (int) floor(log10(fabs(value))), precision)); | |
| 105 | + return QApplication::tr("%L1 ps").arg(value / 1e-12, 0, format, (precision <= 0) ? precision : qBound(0, precision - 13 - (int) floor(log10(fabs(value))), precision)); | |
| 104 | 106 | else if(value < 1e-6) |
| 105 | - return QApplication::tr("%L1 ns").arg(value * 1e9, 0, format, (precision <= 0) ? precision : (precision - 10 - (int) floor(log10(fabs(value))))); | |
| 107 | + return QApplication::tr("%L1 ns").arg(value / 1e-9, 0, format, (precision <= 0) ? precision : (precision - 10 - (int) floor(log10(fabs(value))))); | |
| 106 | 108 | else if(value < 1e-3) |
| 107 | - return QApplication::tr("%L1 \265s").arg(value * 1e6, 0, format, (precision <= 0) ? precision : (precision - 7 - (int) floor(log10(fabs(value))))); | |
| 109 | + return QApplication::tr("%L1 \265s").arg(value / 1e-6, 0, format, (precision <= 0) ? precision : (precision - 7 - (int) floor(log10(fabs(value))))); | |
| 108 | 110 | else if(value < 1.0) |
| 109 | - return QApplication::tr("%L1 ms").arg(value * 1e3, 0, format, (precision <= 0) ? precision : (precision - 4 - (int) floor(log10(fabs(value))))); | |
| 111 | + return QApplication::tr("%L1 ms").arg(value / 1e-3, 0, format, (precision <= 0) ? precision : (precision - 4 - (int) floor(log10(fabs(value))))); | |
| 110 | 112 | else if(value < 60) |
| 111 | 113 | return QApplication::tr("%L1 s").arg(value, 0, format, (precision <= 0) ? precision : (precision - 1 - (int) floor(log10(fabs(value))))); |
| 112 | 114 | else if(value < 3600) |
| ... | ... | @@ -143,6 +145,116 @@ namespace Helper { |
| 143 | 145 | } |
| 144 | 146 | } |
| 145 | 147 | |
| 148 | + /// \brief Converts string containing value and (prefix+)unit to double (Counterpart to Helper::valueToString). | |
| 149 | + /// \param text The text containing the value and its unit. | |
| 150 | + /// \param unit The base unit of the value. | |
| 151 | + /// \param ok Pointer to a success-flag, true on success, false on error. | |
| 152 | + /// \return Decoded value. | |
| 153 | + double stringToValue(const QString &text, Unit unit, bool *ok) { | |
| 154 | + // Check if the text is empty | |
| 155 | + int totalSize = text.size(); | |
| 156 | + if(!totalSize){ | |
| 157 | + if(ok) | |
| 158 | + *ok = false; | |
| 159 | + return 0.0; | |
| 160 | + } | |
| 161 | + | |
| 162 | + // Split value and unit apart | |
| 163 | + int valueSize = 0; | |
| 164 | + QLocale locale; | |
| 165 | + bool decimalFound = false; | |
| 166 | + bool exponentFound = false; | |
| 167 | + if(text[valueSize] == locale.negativeSign()) | |
| 168 | + ++valueSize; | |
| 169 | + for(; valueSize < text.size(); ++valueSize) { | |
| 170 | + QChar character = text[valueSize]; | |
| 171 | + | |
| 172 | + if(character.isDigit()) { | |
| 173 | + } | |
| 174 | + else if(character == locale.decimalPoint() && decimalFound == false && exponentFound == false) { | |
| 175 | + decimalFound = true; | |
| 176 | + } | |
| 177 | + else if(character == locale.exponential() && exponentFound == false) { | |
| 178 | + exponentFound = true; | |
| 179 | + if(text[valueSize + 1] == locale.negativeSign()) | |
| 180 | + ++valueSize; | |
| 181 | + } | |
| 182 | + else { | |
| 183 | + break; | |
| 184 | + } | |
| 185 | + } | |
| 186 | + QString valueString = text.left(valueSize); | |
| 187 | + bool valueOk = false; | |
| 188 | + double value = valueString.toDouble(&valueOk); | |
| 189 | + if(!valueOk) { | |
| 190 | + if(ok) | |
| 191 | + *ok = false; | |
| 192 | + return value; | |
| 193 | + } | |
| 194 | + QString unitString = text.right(text.size() - valueSize).trimmed(); | |
| 195 | + | |
| 196 | + if(ok) | |
| 197 | + *ok = true; | |
| 198 | + switch(unit) { | |
| 199 | + case UNIT_VOLTS: { | |
| 200 | + // Voltage string decoding | |
| 201 | + if(unitString.startsWith('\265')) | |
| 202 | + return value * 1e-6; | |
| 203 | + else if(unitString.startsWith('m')) | |
| 204 | + return value * 1e-3; | |
| 205 | + else | |
| 206 | + return value; | |
| 207 | + } | |
| 208 | + case UNIT_DECIBEL: | |
| 209 | + // Power level string decoding | |
| 210 | + return value; | |
| 211 | + | |
| 212 | + case UNIT_SECONDS: | |
| 213 | + // Time string decoding | |
| 214 | + if(unitString.startsWith('p')) | |
| 215 | + return value * 1e-12; | |
| 216 | + else if(unitString.startsWith('n')) | |
| 217 | + return value * 1e-9; | |
| 218 | + else if(unitString.startsWith('\265')) | |
| 219 | + return value * 1e-6; | |
| 220 | + else if(unitString.startsWith("min")) | |
| 221 | + return value * 60; | |
| 222 | + else if(unitString.startsWith('m')) | |
| 223 | + return value * 1e-3; | |
| 224 | + else if(unitString.startsWith('h')) | |
| 225 | + return value * 3600; | |
| 226 | + else | |
| 227 | + return value; | |
| 228 | + | |
| 229 | + case UNIT_HERTZ: | |
| 230 | + // Frequency string decoding | |
| 231 | + if(unitString.startsWith('k')) | |
| 232 | + return value * 1e3; | |
| 233 | + else if(unitString.startsWith('M')) | |
| 234 | + return value * 1e6; | |
| 235 | + else if(unitString.startsWith('G')) | |
| 236 | + return value * 1e9; | |
| 237 | + else | |
| 238 | + return value; | |
| 239 | + | |
| 240 | + case UNIT_SAMPLES: | |
| 241 | + // Sample count string decoding | |
| 242 | + if(unitString.startsWith('k')) | |
| 243 | + return value * 1e3; | |
| 244 | + else if(unitString.startsWith('M')) | |
| 245 | + return value * 1e6; | |
| 246 | + else if(unitString.startsWith('G')) | |
| 247 | + return value * 1e9; | |
| 248 | + else | |
| 249 | + return value; | |
| 250 | + | |
| 251 | + default: | |
| 252 | + if(ok) | |
| 253 | + *ok = false; | |
| 254 | + return value; | |
| 255 | + } | |
| 256 | + } | |
| 257 | + | |
| 146 | 258 | #ifdef DEBUG |
| 147 | 259 | /// \brief Returns the hex dump for the given data. |
| 148 | 260 | /// \param data Pointer to the data bytes that should be dumped. | ... | ... |
openhantek/src/helper.h
| ... | ... | @@ -64,7 +64,9 @@ namespace Helper { |
| 64 | 64 | }; |
| 65 | 65 | |
| 66 | 66 | QString libUsbErrorString(int error); |
| 67 | + | |
| 67 | 68 | QString valueToString(double value, Unit unit, int precision = -1); |
| 69 | + double stringToValue(const QString &text, Unit unit, bool *ok = 0); | |
| 68 | 70 | |
| 69 | 71 | #ifdef DEBUG |
| 70 | 72 | QString hexDump(unsigned char *data, unsigned int length); | ... | ... |