From 1c7190e77afeb00acd07d3bb7cfefbd87e5e4114 Mon Sep 17 00:00:00 2001 From: David Graeff Date: Sat, 20 Jan 2018 13:51:36 +0100 Subject: [PATCH] Introduce PostProcessingSettings. Remove utils/dsoStrings and add translation methods directly to the location where the relevant enums are declared. Remove union for math-channel/coupling value: Some compilers have issues here. --- openhantek/readme.md | 24 ++++++++++++++++++++++-- openhantek/src/configdialog/DsoConfigAnalysisPage.cpp | 12 ++++++------ openhantek/src/docks/HorizontalDock.cpp | 1 - openhantek/src/docks/SpectrumDock.cpp | 1 - openhantek/src/docks/TriggerDock.cpp | 1 - openhantek/src/docks/VoltageDock.cpp | 14 ++++++-------- openhantek/src/docks/VoltageDock.h | 7 ++++--- openhantek/src/docks/dockwindows.cpp | 2 +- openhantek/src/dsowidget.cpp | 20 +++++--------------- openhantek/src/dsowidget.h | 3 --- openhantek/src/hantekdso/enums.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ openhantek/src/hantekdso/enums.h | 8 ++++++++ openhantek/src/hantekdso/hantekdsocontrol.cpp | 65 +++++++++++++++++++++++++++++++---------------------------------- openhantek/src/hantekdso/hantekdsocontrol.h | 36 +++++++++++++++++++++--------------- openhantek/src/post/enums.cpp | 8 -------- openhantek/src/post/enums.h | 43 ------------------------------------------- openhantek/src/post/mathchannelgenerator.cpp | 4 +++- openhantek/src/post/postprocessingsettings.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ openhantek/src/post/postprocessingsettings.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ openhantek/src/post/spectrumgenerator.cpp | 13 +++++++------ openhantek/src/post/spectrumgenerator.h | 5 +++-- openhantek/src/scopesettings.h | 28 ++++++++++------------------ openhantek/src/settings.cpp | 24 +++++++++++++----------- openhantek/src/settings.h | 16 ++++++++-------- openhantek/src/utils/dsoStrings.cpp | 170 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- openhantek/src/utils/dsoStrings.h | 22 ---------------------- 26 files changed, 349 insertions(+), 379 deletions(-) delete mode 100644 openhantek/src/post/enums.cpp delete mode 100644 openhantek/src/post/enums.h create mode 100644 openhantek/src/post/postprocessingsettings.cpp create mode 100644 openhantek/src/post/postprocessingsettings.h delete mode 100644 openhantek/src/utils/dsoStrings.cpp delete mode 100644 openhantek/src/utils/dsoStrings.h diff --git a/openhantek/readme.md b/openhantek/readme.md index 09c10fa..5ac9b65 100644 --- a/openhantek/readme.md +++ b/openhantek/readme.md @@ -52,8 +52,28 @@ and the graphical part. All OpenGL rendering takes place in the `GlScope` class. A helper class `GlScopeGraph` contains exactly one data sample snapshot including all channels for voltage and spectrum and a pointer to the respective GPU buffer. -`GlScope` works for OpenGL 3.2 and OpenGL ES 2.0, but this needs to be decided at compile time. Usually Qt -selects the right interface. +`GlScope` works for OpenGL 3.2 and OpenGL ES 2.0. If both is present, OpenGL will be prefered, but can be +overwritten by the user via a command flag. + +### Export + +All export related funtionality is within *src/exporting*. + +The following exporters are implemented: + +* Export to comma separated value file (CSV): Write to a user selected file, +* Export to an image/pdf: Writes an image/pdf to a user selected file, +* Print exporter: Creates a printable document and opens the print dialog. + +All export classes (exportcsv, exportimage, exportprint) implement the +ExporterInterface and are registered to the ExporterRegistry in the main.cpp. + +Some export classes are still using the legacyExportDrawer class to +draw the grid and paint all the labels, values and graphs. + +The plan is to retire this legacy class and replace the paint code with +a `GlScope` class shared OpenGL drawing code for at least the grid and the +scope graphs. ## Data flow diff --git a/openhantek/src/configdialog/DsoConfigAnalysisPage.cpp b/openhantek/src/configdialog/DsoConfigAnalysisPage.cpp index 25b64f0..5c02fc2 100644 --- a/openhantek/src/configdialog/DsoConfigAnalysisPage.cpp +++ b/openhantek/src/configdialog/DsoConfigAnalysisPage.cpp @@ -15,14 +15,14 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage(DsoSettings *settings, QWidget *par windowFunctionLabel = new QLabel(tr("Window function")); windowFunctionComboBox = new QComboBox(); windowFunctionComboBox->addItems(windowFunctionStrings); - windowFunctionComboBox->setCurrentIndex((int)settings->scope.spectrumWindow); + windowFunctionComboBox->setCurrentIndex((int)settings->post.spectrumWindow); referenceLevelLabel = new QLabel(tr("Reference level")); referenceLevelSpinBox = new QDoubleSpinBox(); referenceLevelSpinBox->setDecimals(1); referenceLevelSpinBox->setMinimum(-40.0); referenceLevelSpinBox->setMaximum(100.0); - referenceLevelSpinBox->setValue(settings->scope.spectrumReference); + referenceLevelSpinBox->setValue(settings->post.spectrumReference); referenceLevelUnitLabel = new QLabel(tr("dBm")); referenceLevelLayout = new QHBoxLayout(); referenceLevelLayout->addWidget(referenceLevelSpinBox); @@ -33,7 +33,7 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage(DsoSettings *settings, QWidget *par minimumMagnitudeSpinBox->setDecimals(1); minimumMagnitudeSpinBox->setMinimum(-40.0); minimumMagnitudeSpinBox->setMaximum(100.0); - minimumMagnitudeSpinBox->setValue(settings->scope.spectrumLimit); + minimumMagnitudeSpinBox->setValue(settings->post.spectrumLimit); minimumMagnitudeUnitLabel = new QLabel(tr("dBm")); minimumMagnitudeLayout = new QHBoxLayout(); minimumMagnitudeLayout->addWidget(minimumMagnitudeSpinBox); @@ -59,7 +59,7 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage(DsoSettings *settings, QWidget *par /// \brief Saves the new settings. void DsoConfigAnalysisPage::saveSettings() { - settings->scope.spectrumWindow = (Dso::WindowFunction)windowFunctionComboBox->currentIndex(); - settings->scope.spectrumReference = referenceLevelSpinBox->value(); - settings->scope.spectrumLimit = minimumMagnitudeSpinBox->value(); + settings->post.spectrumWindow = (Dso::WindowFunction)windowFunctionComboBox->currentIndex(); + settings->post.spectrumReference = referenceLevelSpinBox->value(); + settings->post.spectrumLimit = minimumMagnitudeSpinBox->value(); } diff --git a/openhantek/src/docks/HorizontalDock.cpp b/openhantek/src/docks/HorizontalDock.cpp index 6022c04..81af81e 100644 --- a/openhantek/src/docks/HorizontalDock.cpp +++ b/openhantek/src/docks/HorizontalDock.cpp @@ -15,7 +15,6 @@ #include "scopesettings.h" #include "sispinbox.h" -#include "utils/dsoStrings.h" #include "utils/printutils.h" template struct SELECT { diff --git a/openhantek/src/docks/SpectrumDock.cpp b/openhantek/src/docks/SpectrumDock.cpp index d6f5d5b..2d53607 100644 --- a/openhantek/src/docks/SpectrumDock.cpp +++ b/openhantek/src/docks/SpectrumDock.cpp @@ -14,7 +14,6 @@ #include "settings.h" #include "sispinbox.h" -#include "utils/dsoStrings.h" #include "utils/printutils.h" template struct SELECT { diff --git a/openhantek/src/docks/TriggerDock.cpp b/openhantek/src/docks/TriggerDock.cpp index 41f6dbd..03e9297 100644 --- a/openhantek/src/docks/TriggerDock.cpp +++ b/openhantek/src/docks/TriggerDock.cpp @@ -15,7 +15,6 @@ #include "hantekdso/controlspecification.h" #include "settings.h" #include "sispinbox.h" -#include "utils/dsoStrings.h" #include "utils/printutils.h" TriggerDock::TriggerDock(DsoSettingsScope *scope, const Dso::ControlSpecification *spec, QWidget *parent, diff --git a/openhantek/src/docks/VoltageDock.cpp b/openhantek/src/docks/VoltageDock.cpp index f72d97d..5cfb7ad 100644 --- a/openhantek/src/docks/VoltageDock.cpp +++ b/openhantek/src/docks/VoltageDock.cpp @@ -14,7 +14,6 @@ #include "settings.h" #include "sispinbox.h" -#include "utils/dsoStrings.h" #include "utils/printutils.h" template struct SELECT { @@ -66,9 +65,9 @@ VoltageDock::VoltageDock(DsoSettingsScope *scope, const Dso::ControlSpecificatio dockLayout->addWidget(b.invertCheckBox, (int)channel * 3 + 2, 1); if (channel < spec->channels) - setCoupling(channel, scope->voltage[channel].couplingIndex); + setCoupling(channel, scope->voltage[channel].couplingOrMathIndex); else - setMode(scope->voltage[channel].math); + setMode(scope->voltage[channel].couplingOrMathIndex); setGain(channel, scope->voltage[channel].gainStepIndex); setUsed(channel, scope->voltage[channel].used); @@ -80,12 +79,11 @@ VoltageDock::VoltageDock(DsoSettingsScope *scope, const Dso::ControlSpecificatio this->scope->voltage[channel].inverted = checked; }); connect(b.miscComboBox, SELECT::OVERLOAD_OF(&QComboBox::currentIndexChanged), [this,channel,spec,scope](int index){ + this->scope->voltage[channel].couplingOrMathIndex = (unsigned)index; if (channel < spec->channels) { - this->scope->voltage[channel].couplingIndex = (unsigned)index; emit couplingChanged(channel, scope->coupling(channel, spec)); } else { - this->scope->voltage[channel].math = (Dso::MathMode) index; - emit modeChanged(this->scope->voltage[channel].math); + emit modeChanged(Dso::getMathMode(this->scope->voltage[channel])); } }); connect(b.usedCheckBox, &QAbstractButton::toggled, [this,channel](bool checked) { @@ -119,9 +117,9 @@ void VoltageDock::setGain(ChannelID channel, unsigned gainStepIndex) { channelBlocks[channel].gainComboBox->setCurrentIndex((unsigned)gainStepIndex); } -void VoltageDock::setMode(Dso::MathMode mode) { +void VoltageDock::setMode(unsigned mathModeIndex) { QSignalBlocker blocker(channelBlocks[spec->channels].miscComboBox); - channelBlocks[spec->channels].miscComboBox->setCurrentIndex((int)mode); + channelBlocks[spec->channels].miscComboBox->setCurrentIndex((int)mathModeIndex); } void VoltageDock::setUsed(ChannelID channel, bool used) { diff --git a/openhantek/src/docks/VoltageDock.h b/openhantek/src/docks/VoltageDock.h index 1e21bc0..260a84b 100644 --- a/openhantek/src/docks/VoltageDock.h +++ b/openhantek/src/docks/VoltageDock.h @@ -10,6 +10,7 @@ #include "scopesettings.h" #include "hantekdso/controlspecification.h" +#include "post/postprocessingsettings.h" class SiSpinBox; @@ -28,7 +29,7 @@ class VoltageDock : public QDockWidget { /// \brief Sets the coupling for a channel. /// \param channel The channel, whose coupling should be set. - /// \param coupling The coupling-mode. + /// \param couplingIndex The coupling-mode index. void setCoupling(ChannelID channel, unsigned couplingIndex); /// \brief Sets the gain for a channel. @@ -37,8 +38,8 @@ class VoltageDock : public QDockWidget { void setGain(ChannelID channel, unsigned gainStepIndex); /// \brief Sets the mode for the math channel. - /// \param mode The math-mode. - void setMode(Dso::MathMode mode); + /// \param mathModeIndex The math-mode index. + void setMode(unsigned mathModeIndex); /// \brief Enables/disables a channel. /// \param channel The channel, that should be enabled/disabled. diff --git a/openhantek/src/docks/dockwindows.cpp b/openhantek/src/docks/dockwindows.cpp index 9a89144..37fff33 100644 --- a/openhantek/src/docks/dockwindows.cpp +++ b/openhantek/src/docks/dockwindows.cpp @@ -8,7 +8,7 @@ #include -#include "post/enums.h" +#include "post/postprocessingsettings.h" #include "hantekdso/enums.h" #include "hantekprotocol/types.h" #include "dockwindows.h" diff --git a/openhantek/src/dsowidget.cpp b/openhantek/src/dsowidget.cpp index 62becfd..54f58ad 100644 --- a/openhantek/src/dsowidget.cpp +++ b/openhantek/src/dsowidget.cpp @@ -10,10 +10,10 @@ #include "dsowidget.h" +#include "post/postprocessingsettings.h" #include "post/graphgenerator.h" #include "post/ppresult.h" -#include "utils/dsoStrings.h" #include "utils/printutils.h" #include "glscope.h" @@ -252,10 +252,6 @@ void DsoWidget::setupSliders(DsoWidget::Sliders &sliders) { } } -void DsoWidget::setExporterForNextFrame(std::unique_ptr exporter) { - this->exportNextFrame = std::move(exporter); -} - /// \brief Set the trigger level sliders minimum and maximum to the new values. void DsoWidget::adaptTriggerLevelSlider(DsoWidget::Sliders &sliders, ChannelID channel) { sliders.triggerLevelSlider->setLimits((int)channel, @@ -422,7 +418,8 @@ void DsoWidget::updateVoltageCoupling(ChannelID channel) { /// \brief Handles modeChanged signal from the voltage dock. void DsoWidget::updateMathMode() { - measurementMiscLabel[spec->channels]->setText(Dso::mathModeString(scope->voltage[spec->channels].math)); + measurementMiscLabel[spec->channels]->setText( + Dso::mathModeString(Dso::getMathMode(scope->voltage[spec->channels]))); } /// \brief Handles gainChanged signal from the voltage dock. @@ -486,15 +483,8 @@ void DsoWidget::updateZoom(bool enabled) { /// \brief Prints analyzed data. void DsoWidget::showNew(std::shared_ptr data) { - if (exportNextFrame) { - exportNextFrame->exportSamples(data.get()); - exportNextFrame.reset(nullptr); - } - - mainScope->showData(data.get()); - mainScope->update(); - zoomScope->showData(data.get()); - zoomScope->update(); + mainScope->showData(data); + zoomScope->showData(data); if (spec->isSoftwareTriggerDevice) { QPalette triggerLabelPalette = palette(); diff --git a/openhantek/src/dsowidget.h b/openhantek/src/dsowidget.h index 02d4e45..6b63b93 100644 --- a/openhantek/src/dsowidget.h +++ b/openhantek/src/dsowidget.h @@ -8,7 +8,6 @@ #include #include -#include "exporting/exporter.h" #include "glscope.h" #include "levelslider.h" #include "hantekdso/controlspecification.h" @@ -36,7 +35,6 @@ class DsoWidget : public QWidget { /// \param parent The parent widget. /// \param flags Flags for the window manager. DsoWidget(DsoSettingsScope* scope, DsoSettingsView* view, const Dso::ControlSpecification* spec, QWidget *parent = 0, Qt::WindowFlags flags = 0); - void setExporterForNextFrame(std::unique_ptr exporter); // Data arrived void showNew(std::shared_ptr data); @@ -87,7 +85,6 @@ class DsoWidget : public QWidget { GlScope *mainScope; ///< The main scope screen GlScope *zoomScope; ///< The optional magnified scope screen - std::unique_ptr exportNextFrame; public slots: // Horizontal axis diff --git a/openhantek/src/hantekdso/enums.cpp b/openhantek/src/hantekdso/enums.cpp index 83f7e43..8c573ff 100644 --- a/openhantek/src/hantekdso/enums.cpp +++ b/openhantek/src/hantekdso/enums.cpp @@ -1,7 +1,96 @@ #include "enums.h" +#include namespace Dso { Enum TriggerModeEnum; Enum SlopeEnum; Enum GraphFormatEnum; + + /// \brief Return string representation of the given channel mode. + /// \param mode The ::ChannelMode that should be returned as string. + /// \return The string that should be used in labels etc., empty when invalid. + QString channelModeString(ChannelMode mode) { + switch (mode) { + case ChannelMode::Voltage: + return QCoreApplication::tr("Voltage"); + case ChannelMode::Spectrum: + return QCoreApplication::tr("Spectrum"); + } + return QString(); + } + + /// \brief Return string representation of the given graph format. + /// \param format The ::GraphFormat that should be returned as string. + /// \return The string that should be used in labels etc. + QString graphFormatString(GraphFormat format) { + switch (format) { + case GraphFormat::TY: + return QCoreApplication::tr("T - Y"); + case GraphFormat::XY: + return QCoreApplication::tr("X - Y"); + } + return QString(); + } + + /// \brief Return string representation of the given channel coupling. + /// \param coupling The ::Coupling that should be returned as string. + /// \return The string that should be used in labels etc. + QString couplingString(Coupling coupling) { + switch (coupling) { + case Coupling::AC: + return QCoreApplication::tr("AC"); + case Coupling::DC: + return QCoreApplication::tr("DC"); + case Coupling::GND: + return QCoreApplication::tr("GND"); + } + return QString(); + } + + + /// \brief Return string representation of the given trigger mode. + /// \param mode The ::TriggerMode that should be returned as string. + /// \return The string that should be used in labels etc. + QString triggerModeString(TriggerMode mode) { + switch (mode) { + case TriggerMode::WAIT_FORCE: + return QCoreApplication::tr("Wait/Force"); + case TriggerMode::HARDWARE_SOFTWARE: + return QCoreApplication::tr("Hard-/Software"); + case TriggerMode::SINGLE: + return QCoreApplication::tr("Single"); + } + return QString(); + } + + /// \brief Return string representation of the given trigger slope. + /// \param slope The ::Slope that should be returned as string. + /// \return The string that should be used in labels etc. + QString slopeString(Slope slope) { + switch (slope) { + case Slope::Positive: + return QString::fromUtf8("\u2197"); + case Slope::Negative: + return QString::fromUtf8("\u2198"); + default: + return QString(); + } + } + + /// \brief Return string representation of the given graph interpolation mode. + /// \param interpolation The ::InterpolationMode that should be returned as + /// string. + /// \return The string that should be used in labels etc. + QString interpolationModeString(InterpolationMode interpolation) { + switch (interpolation) { + case INTERPOLATION_OFF: + return QCoreApplication::tr("Off"); + case INTERPOLATION_LINEAR: + return QCoreApplication::tr("Linear"); + case INTERPOLATION_SINC: + return QCoreApplication::tr("Sinc"); + default: + return QString(); + } + } } diff --git a/openhantek/src/hantekdso/enums.h b/openhantek/src/hantekdso/enums.h index c3a8ada..f89711c 100644 --- a/openhantek/src/hantekdso/enums.h +++ b/openhantek/src/hantekdso/enums.h @@ -2,6 +2,7 @@ #include "utils/enumclass.h" #include +#include namespace Dso { /// \enum ChannelMode /// \brief The channel display modes. @@ -52,6 +53,13 @@ enum InterpolationMode { INTERPOLATION_SINC, ///< Smooth graph through the dots INTERPOLATION_COUNT ///< Total number of interpolation modes }; + +QString channelModeString(ChannelMode mode); +QString graphFormatString(GraphFormat format); +QString couplingString(Coupling coupling); +QString triggerModeString(TriggerMode mode); +QString slopeString(Slope slope); +QString interpolationModeString(InterpolationMode interpolation); } Q_DECLARE_METATYPE(Dso::TriggerMode) diff --git a/openhantek/src/hantekdso/hantekdsocontrol.cpp b/openhantek/src/hantekdso/hantekdsocontrol.cpp index aca5474..5bd3b6d 100644 --- a/openhantek/src/hantekdso/hantekdsocontrol.cpp +++ b/openhantek/src/hantekdso/hantekdsocontrol.cpp @@ -22,30 +22,17 @@ using namespace Hantek; using namespace Dso; /// \brief Start sampling process. -void HantekDsoControl::startSampling() { - sampling = true; +void HantekDsoControl::enableSampling(bool enabled) { + sampling = enabled; // Emit signals for initial settings - emit availableRecordLengthsChanged(controlsettings.samplerate.limits->recordLengths); - updateSamplerateLimits(); - emit recordLengthChanged(getRecordLength()); - if (!isRollMode()) emit recordTimeChanged((double)getRecordLength() / controlsettings.samplerate.current); - emit samplerateChanged(controlsettings.samplerate.current); + // emit availableRecordLengthsChanged(controlsettings.samplerate.limits->recordLengths); + // updateSamplerateLimits(); + // emit recordLengthChanged(getRecordLength()); + // if (!isRollMode()) emit recordTimeChanged((double)getRecordLength() / controlsettings.samplerate.current); + // emit samplerateChanged(controlsettings.samplerate.current); - if (specification->isFixedSamplerateDevice) { - // Convert to GUI presentable values (1e5 -> 1.0, 48e6 -> 480.0 etc) - QList sampleSteps; - for (auto &v : specification->fixedSampleRates) { sampleSteps << v.samplerate / 1e5; } - emit samplerateSet(1, sampleSteps); - } - - emit samplingStarted(); -} - -/// \brief Stop sampling process. -void HantekDsoControl::stopSampling() { - sampling = false; - emit samplingStopped(); + emit samplingStatusChanged(enabled); } const USBDevice *HantekDsoControl::getDevice() const { return device; } @@ -91,25 +78,27 @@ int HantekDsoControl::bulkCommand(const std::vector *command, int return device->bulkWrite(command->data(), command->size(), attempts); } -unsigned HantekDsoControl::getChannelCount() { return specification->channels; } +unsigned HantekDsoControl::getChannelCount() const { return specification->channels; } const ControlSettings *HantekDsoControl::getDeviceSettings() const { return &controlsettings; } -const std::vector &HantekDsoControl::getAvailableRecordLengths() { // +const std::vector &HantekDsoControl::getAvailableRecordLengths() const { // return controlsettings.samplerate.limits->recordLengths; } -double HantekDsoControl::getMinSamplerate() { +double HantekDsoControl::getMinSamplerate() const { return (double)specification->samplerate.single.base / specification->samplerate.single.maxDownsampler; } -double HantekDsoControl::getMaxSamplerate() { +double HantekDsoControl::getMaxSamplerate() const { if (controlsettings.usedChannels <= 1) return specification->samplerate.multi.max; else return specification->samplerate.single.max; } +bool HantekDsoControl::isSampling() const { return sampling; } + /// \brief Updates the interval of the periodic thread timer. void HantekDsoControl::updateInterval() { // Check the current oscilloscope state everytime 25% of the time the buffer @@ -593,13 +582,21 @@ void HantekDsoControl::restoreTargets() { } void HantekDsoControl::updateSamplerateLimits() { - // Works only if the minimum samplerate for normal mode is lower than for fast - // rate mode, which is the case for all models - const double min = (double)specification->samplerate.single.base / specification->samplerate.single.maxDownsampler; - const double max = getMaxSamplerate(); - - emit samplerateLimitsChanged(min / specification->bufferDividers[controlsettings.recordLengthId], - max / specification->bufferDividers[controlsettings.recordLengthId]); + if (specification->isFixedSamplerateDevice) { + // Convert to GUI presentable values (1e5 -> 1.0, 48e6 -> 480.0 etc) + QList sampleSteps; + for (auto &v : specification->fixedSampleRates) { sampleSteps << v.samplerate / 1e5; } + emit samplerateSet(1, sampleSteps); + } else { + // Works only if the minimum samplerate for normal mode is lower than for fast + // rate mode, which is the case for all models + const double min = + (double)specification->samplerate.single.base / specification->samplerate.single.maxDownsampler; + const double max = getMaxSamplerate(); + + emit samplerateLimitsChanged(min / specification->bufferDividers[controlsettings.recordLengthId], + max / specification->bufferDividers[controlsettings.recordLengthId]); + } } Dso::ErrorCode HantekDsoControl::setRecordLength(unsigned index) { @@ -1175,7 +1172,7 @@ void HantekDsoControl::run() { // Check if we're in single trigger mode if (controlsettings.trigger.mode == Dso::TriggerMode::SINGLE && this->_samplingStarted) - this->stopSampling(); + this->enableSampling(false); // Sampling completed, restart it when necessary this->_samplingStarted = false; @@ -1216,7 +1213,7 @@ void HantekDsoControl::run() { // Check if we're in single trigger mode if (controlsettings.trigger.mode == Dso::TriggerMode::SINGLE && this->_samplingStarted) - this->stopSampling(); + this->enableSampling(false); // Sampling completed, restart it when necessary this->_samplingStarted = false; diff --git a/openhantek/src/hantekdso/hantekdsocontrol.h b/openhantek/src/hantekdso/hantekdsocontrol.h index f969127..1765da4 100644 --- a/openhantek/src/hantekdso/hantekdsocontrol.h +++ b/openhantek/src/hantekdso/hantekdsocontrol.h @@ -52,7 +52,7 @@ class HantekDsoControl : public QObject { /// \brief Gets the physical channel count for this oscilloscope. /// \return The number of physical channels. - unsigned getChannelCount(); + unsigned getChannelCount() const; /// Return the read-only device control settings. Use the set- Methods to change /// device settings. @@ -60,15 +60,17 @@ class HantekDsoControl : public QObject { /// \brief Get available record lengths for this oscilloscope. /// \return The number of physical channels, empty list for continuous. - const std::vector &getAvailableRecordLengths(); + const std::vector &getAvailableRecordLengths() const; /// \brief Get minimum samplerate for this oscilloscope. /// \return The minimum samplerate for the current configuration in S/s. - double getMinSamplerate(); + double getMinSamplerate() const; /// \brief Get maximum samplerate for this oscilloscope. /// \return The maximum samplerate for the current configuration in S/s. - double getMaxSamplerate(); + double getMaxSamplerate() const; + + bool isSampling() const; /// Return the associated usb device. const USBDevice *getDevice() const; @@ -182,8 +184,8 @@ class HantekDsoControl : public QObject { bool sampling = false; ///< true, if the oscilloscope is taking samples // Device setup - const Dso::ControlSpecification* specification; ///< The specifications of the device - Dso::ControlSettings controlsettings; ///< The current settings of the device + const Dso::ControlSpecification *specification; ///< The specifications of the device + Dso::ControlSettings controlsettings; ///< The current settings of the device // Results DSOsamples result; @@ -206,8 +208,10 @@ class HantekDsoControl : public QObject { int bulkCommand(const std::vector *command, int attempts = HANTEK_ATTEMPTS) const; public slots: - void startSampling(); - void stopSampling(); + /// \brief If sampling is disabled, no samplesAvailable() signals are send anymore, no samples + /// are fetched from the device and no processing takes place. + /// \param enabled Enables/Disables sampling + void enableSampling(bool enabled); /// \brief Sets the size of the oscilloscopes sample buffer. /// \param index The record length index that should be set. @@ -270,19 +274,21 @@ class HantekDsoControl : public QObject { void forceTrigger(); signals: - void samplingStarted(); ///< The oscilloscope started sampling/waiting for trigger - void samplingStopped(); ///< The oscilloscope stopped sampling/waiting for trigger + void samplingStatusChanged(bool enabled); ///< The oscilloscope started/stopped sampling/waiting for trigger void statusMessage(const QString &message, int timeout); ///< Status message about the oscilloscope void samplesAvailable(const DSOsamples *samples); ///< New sample data is available void availableRecordLengthsChanged(const std::vector &recordLengths); ///< The available record /// lengths, empty list for - void samplerateLimitsChanged(double minimum, double maximum); ///< The minimum or maximum samplerate has changed - void recordLengthChanged(unsigned long duration); ///< The record length has changed - void recordTimeChanged(double duration); ///< The record time duration has changed - void samplerateChanged(double samplerate); ///< The samplerate has changed - void samplerateSet(int mode, QList sampleSteps); ///< The samplerate has changed + /// The available samplerate range has changed + void samplerateLimitsChanged(double minimum, double maximum); + /// The available samplerate for fixed samplerate devices has changed + void samplerateSet(int mode, QList sampleSteps); + + void recordLengthChanged(unsigned long duration); ///< The record length has changed + void recordTimeChanged(double duration); ///< The record time duration has changed + void samplerateChanged(double samplerate); ///< The samplerate has changed void communicationError() const; }; diff --git a/openhantek/src/post/enums.cpp b/openhantek/src/post/enums.cpp deleted file mode 100644 index fc49508..0000000 --- a/openhantek/src/post/enums.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "enums.h" - -namespace Dso { - -Enum MathModeEnum; -Enum WindowFunctionEnum; - -} diff --git a/openhantek/src/post/enums.h b/openhantek/src/post/enums.h deleted file mode 100644 index a9872f9..0000000 --- a/openhantek/src/post/enums.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include -#include "utils/enumclass.h" -namespace Dso { - -/// \enum MathMode -/// \brief The different math modes for the math-channel. -enum class MathMode { - ADD_CH1_CH2, - SUB_CH2_FROM_CH1, - SUB_CH1_FROM_CH2 -}; -extern Enum MathModeEnum; - -/// \enum WindowFunction -/// \brief The supported window functions. -/// These are needed for spectrum analysis and are applied to the sample values -/// before calculating the DFT. -enum class WindowFunction: int { - RECTANGULAR, ///< Rectangular window (aka Dirichlet) - HAMMING, ///< Hamming window - HANN, ///< Hann window - COSINE, ///< Cosine window (aka Sine) - LANCZOS, ///< Lanczos window (aka Sinc) - BARTLETT, ///< Bartlett window (Endpoints == 0) - TRIANGULAR, ///< Triangular window (Endpoints != 0) - GAUSS, ///< Gauss window (simga = 0.4) - BARTLETTHANN, ///< Bartlett-Hann window - BLACKMAN, ///< Blackman window (alpha = 0.16) - // KAISER, ///< Kaiser window (alpha = 3.0) - NUTTALL, ///< Nuttall window, cont. first deriv. - BLACKMANHARRIS, ///< Blackman-Harris window - BLACKMANNUTTALL, ///< Blackman-Nuttall window - FLATTOP ///< Flat top window -}; -extern Enum WindowFunctionEnum; - -} - -Q_DECLARE_METATYPE(Dso::MathMode) -Q_DECLARE_METATYPE(Dso::WindowFunction) - diff --git a/openhantek/src/post/mathchannelgenerator.cpp b/openhantek/src/post/mathchannelgenerator.cpp index 309d698..233fa49 100644 --- a/openhantek/src/post/mathchannelgenerator.cpp +++ b/openhantek/src/post/mathchannelgenerator.cpp @@ -1,5 +1,7 @@ #include "mathchannelgenerator.h" #include "scopesettings.h" +#include "post/postprocessingsettings.h" +#include "enums.h" MathChannelGenerator::MathChannelGenerator(const DsoSettingsScope *scope, unsigned physicalChannels) : physicalChannels(physicalChannels), scope(scope) {} @@ -27,7 +29,7 @@ void MathChannelGenerator::process(PPresult *result) { std::vector::const_iterator ch1Iterator = result->data(0)->voltage.sample.begin(); std::vector::const_iterator ch2Iterator = result->data(1)->voltage.sample.begin(); for (std::vector::iterator it = resultData.begin(); it != resultData.end(); ++it) { - switch (scope->voltage[physicalChannels].math) { + switch (Dso::getMathMode(scope->voltage[physicalChannels])) { case Dso::MathMode::ADD_CH1_CH2: *it = *ch1Iterator + *ch2Iterator; break; diff --git a/openhantek/src/post/postprocessingsettings.cpp b/openhantek/src/post/postprocessingsettings.cpp new file mode 100644 index 0000000..7fef5f9 --- /dev/null +++ b/openhantek/src/post/postprocessingsettings.cpp @@ -0,0 +1,63 @@ +#include "postprocessingsettings.h" + +#include +#include + +namespace Dso { + +Enum MathModeEnum; +Enum WindowFunctionEnum; + +/// \brief Return string representation of the given math mode. +/// \param mode The ::MathMode that should be returned as string. +/// \return The string that should be used in labels etc. +QString mathModeString(MathMode mode) { + switch (mode) { + case MathMode::ADD_CH1_CH2: + return QCoreApplication::tr("CH1 + CH2"); + case MathMode::SUB_CH2_FROM_CH1: + return QCoreApplication::tr("CH1 - CH2"); + case MathMode::SUB_CH1_FROM_CH2: + return QCoreApplication::tr("CH2 - CH1"); + } + return QString(); +} +/// \brief Return string representation of the given dft window function. +/// \param window The ::WindowFunction that should be returned as string. +/// \return The string that should be used in labels etc. +QString windowFunctionString(WindowFunction window) { + switch (window) { + case WindowFunction::RECTANGULAR: + return QCoreApplication::tr("Rectangular"); + case WindowFunction::HAMMING: + return QCoreApplication::tr("Hamming"); + case WindowFunction::HANN: + return QCoreApplication::tr("Hann"); + case WindowFunction::COSINE: + return QCoreApplication::tr("Cosine"); + case WindowFunction::LANCZOS: + return QCoreApplication::tr("Lanczos"); + case WindowFunction::BARTLETT: + return QCoreApplication::tr("Bartlett"); + case WindowFunction::TRIANGULAR: + return QCoreApplication::tr("Triangular"); + case WindowFunction::GAUSS: + return QCoreApplication::tr("Gauss"); + case WindowFunction::BARTLETTHANN: + return QCoreApplication::tr("Bartlett-Hann"); + case WindowFunction::BLACKMAN: + return QCoreApplication::tr("Blackman"); + // case WindowFunction::WINDOW_KAISER: + // return QCoreApplication::tr("Kaiser"); + case WindowFunction::NUTTALL: + return QCoreApplication::tr("Nuttall"); + case WindowFunction::BLACKMANHARRIS: + return QCoreApplication::tr("Blackman-Harris"); + case WindowFunction::BLACKMANNUTTALL: + return QCoreApplication::tr("Blackman-Nuttall"); + case WindowFunction::FLATTOP: + return QCoreApplication::tr("Flat top"); + } + return QString(); +} +} diff --git a/openhantek/src/post/postprocessingsettings.h b/openhantek/src/post/postprocessingsettings.h new file mode 100644 index 0000000..0ed3d4f --- /dev/null +++ b/openhantek/src/post/postprocessingsettings.h @@ -0,0 +1,49 @@ +#pragma once + +#include "utils/enumclass.h" +#include +namespace Dso { + +/// \enum MathMode +/// \brief The different math modes for the math-channel. +enum class MathMode : unsigned { ADD_CH1_CH2, SUB_CH2_FROM_CH1, SUB_CH1_FROM_CH2 }; +extern Enum MathModeEnum; + +template +inline MathMode getMathMode(T& t) { return (MathMode)t.couplingOrMathIndex; } + +/// \enum WindowFunction +/// \brief The supported window functions. +/// These are needed for spectrum analysis and are applied to the sample values +/// before calculating the DFT. +enum class WindowFunction : int { + RECTANGULAR, ///< Rectangular window (aka Dirichlet) + HAMMING, ///< Hamming window + HANN, ///< Hann window + COSINE, ///< Cosine window (aka Sine) + LANCZOS, ///< Lanczos window (aka Sinc) + BARTLETT, ///< Bartlett window (Endpoints == 0) + TRIANGULAR, ///< Triangular window (Endpoints != 0) + GAUSS, ///< Gauss window (simga = 0.4) + BARTLETTHANN, ///< Bartlett-Hann window + BLACKMAN, ///< Blackman window (alpha = 0.16) + // KAISER, ///< Kaiser window (alpha = 3.0) + NUTTALL, ///< Nuttall window, cont. first deriv. + BLACKMANHARRIS, ///< Blackman-Harris window + BLACKMANNUTTALL, ///< Blackman-Nuttall window + FLATTOP ///< Flat top window +}; +extern Enum WindowFunctionEnum; + +QString mathModeString(MathMode mode); +QString windowFunctionString(WindowFunction window); +} + +Q_DECLARE_METATYPE(Dso::MathMode) +Q_DECLARE_METATYPE(Dso::WindowFunction) + +struct DsoSettingsPostProcessing { + Dso::WindowFunction spectrumWindow = Dso::WindowFunction::HANN; ///< Window function for DFT + double spectrumReference = 0.0; ///< Reference level for spectrum in dBm + double spectrumLimit = -20.0; ///< Minimum magnitude of the spectrum (Avoids peaks) +}; diff --git a/openhantek/src/post/spectrumgenerator.cpp b/openhantek/src/post/spectrumgenerator.cpp index 4fb395c..48dde97 100644 --- a/openhantek/src/post/spectrumgenerator.cpp +++ b/openhantek/src/post/spectrumgenerator.cpp @@ -16,7 +16,8 @@ #include "utils/printutils.h" /// \brief Analyzes the data from the dso. -SpectrumGenerator::SpectrumGenerator(const DsoSettingsScope *scope) : scope(scope) {} +SpectrumGenerator::SpectrumGenerator(const DsoSettingsScope *scope, const DsoSettingsPostProcessing *postprocessing) + : scope(scope), postprocessing(postprocessing) {} SpectrumGenerator::~SpectrumGenerator() { if (lastWindowBuffer) fftw_free(lastWindowBuffer); @@ -36,15 +37,15 @@ void SpectrumGenerator::process(PPresult *result) { // Calculate new window size_t sampleCount = channelData->voltage.sample.size(); - if (!lastWindowBuffer || lastWindow != scope->spectrumWindow || lastRecordLength != sampleCount) { + if (!lastWindowBuffer || lastWindow != postprocessing->spectrumWindow || lastRecordLength != sampleCount) { if (lastWindowBuffer) fftw_free(lastWindowBuffer); lastWindowBuffer = fftw_alloc_real(sampleCount); lastRecordLength = (unsigned)sampleCount; unsigned int windowEnd = lastRecordLength - 1; - lastWindow = scope->spectrumWindow; + lastWindow = postprocessing->spectrumWindow; - switch (scope->spectrumWindow) { + switch (postprocessing->spectrumWindow) { case Dso::WindowFunction::HAMMING: for (unsigned int windowPosition = 0; windowPosition < lastRecordLength; ++windowPosition) *(lastWindowBuffer + windowPosition) = 0.54 - 0.46 * cos(2.0 * M_PI * windowPosition / windowEnd); @@ -210,8 +211,8 @@ void SpectrumGenerator::process(PPresult *result) { // Finally calculate the real spectrum if we want it if (scope->spectrum[channel].used) { // Convert values into dB (Relative to the reference level) - double offset = 60 - scope->spectrumReference - 20 * log10(dftLength); - double offsetLimit = scope->spectrumLimit - scope->spectrumReference; + double offset = 60 - postprocessing->spectrumReference - 20 * log10(dftLength); + double offsetLimit = postprocessing->spectrumLimit - postprocessing->spectrumReference; for (std::vector::iterator spectrumIterator = channelData->spectrum.sample.begin(); spectrumIterator != channelData->spectrum.sample.end(); ++spectrumIterator) { double value = 20 * log10(fabs(*spectrumIterator)) + offset; diff --git a/openhantek/src/post/spectrumgenerator.h b/openhantek/src/post/spectrumgenerator.h index 7b7386b..d0f4710 100644 --- a/openhantek/src/post/spectrumgenerator.h +++ b/openhantek/src/post/spectrumgenerator.h @@ -11,7 +11,7 @@ #include "ppresult.h" #include "dsosamples.h" #include "utils/printutils.h" -#include "enums.h" +#include "postprocessingsettings.h" #include "processor.h" @@ -23,12 +23,13 @@ struct DsoSettingsScope; /// time-/frequencysteps between two values. class SpectrumGenerator : public Processor { public: - SpectrumGenerator(const DsoSettingsScope* scope); + SpectrumGenerator(const DsoSettingsScope* scope, const DsoSettingsPostProcessing* postprocessing); virtual ~SpectrumGenerator(); virtual void process(PPresult *data) override; private: const DsoSettingsScope* scope; + const DsoSettingsPostProcessing* postprocessing; unsigned int lastRecordLength = 0; ///< The record length of the previously analyzed data Dso::WindowFunction lastWindow = (Dso::WindowFunction)-1; ///< The previously used dft window function double *lastWindowBuffer = nullptr; diff --git a/openhantek/src/scopesettings.h b/openhantek/src/scopesettings.h index b50c5d2..daa50ce 100644 --- a/openhantek/src/scopesettings.h +++ b/openhantek/src/scopesettings.h @@ -7,7 +7,6 @@ #include "hantekdso/controlspecification.h" #include "hantekdso/enums.h" #include "hantekprotocol/definitions.h" -#include "post/enums.h" #include #define MARKER_COUNT 2 ///< Number of markers @@ -52,37 +51,30 @@ struct DsoSettingsScopeSpectrum { /// \brief Holds the settings for the normal voltage graphs. /// TODO Use ControlSettingsVoltage struct DsoSettingsScopeVoltage { - double offset = 0.0; ///< Vertical offset in divs - double trigger = 0.0; ///< Trigger level in V - unsigned gainStepIndex = 6; ///< The vertical resolution in V/div (default = 1.0) - union { ///< Different enums, coupling for real- and mode for math-channels - Dso::MathMode math; - unsigned couplingIndex = 0; - int rawValue; - }; - QString name; ///< Name of this channel - bool inverted = false; ///< true if the channel is inverted (mirrored on cross-axis) - bool used = false; ///< true if this channel is enabled + double offset = 0.0; ///< Vertical offset in divs + double trigger = 0.0; ///< Trigger level in V + unsigned gainStepIndex = 6; ///< The vertical resolution in V/div (default = 1.0) + unsigned couplingOrMathIndex = 0; ///< Different index: coupling for real- and mode for math-channels + QString name; ///< Name of this channel + bool inverted = false; ///< true if the channel is inverted (mirrored on cross-axis) + bool used = false; ///< true if this channel is enabled }; /// \brief Holds the settings for the oscilloscope. struct DsoSettingsScope { std::vector gainSteps = {1e-2, 2e-2, 5e-2, 1e-1, 2e-1, 5e-1, 1e0, 2e0, 5e0}; ///< The selectable voltage gain steps in V/div - Dso::WindowFunction spectrumWindow = Dso::WindowFunction::HANN; ///< Window function for DFT std::vector spectrum; ///< Spectrum analysis settings std::vector voltage; ///< Settings for the normal graphs DsoSettingsScopeHorizontal horizontal; ///< Settings for the horizontal axis DsoSettingsScopeTrigger trigger; ///< Settings for the trigger - double spectrumReference = 0.0; ///< Reference level for spectrum in dBm - double spectrumLimit = -20.0; ///< Minimum magnitude of the spectrum (Avoids peaks) double gain(unsigned channel) const { return gainSteps[voltage[channel].gainStepIndex]; } bool anyUsed(ChannelID channel) { return voltage[channel].used | spectrum[channel].used; } - Dso::Coupling coupling(ChannelID channel, const Dso::ControlSpecification *deviceSpecification) { - return deviceSpecification->couplings[voltage[channel].couplingIndex]; + Dso::Coupling coupling(ChannelID channel, const Dso::ControlSpecification *deviceSpecification) const { + return deviceSpecification->couplings[voltage[channel].couplingOrMathIndex]; } // Channels, including math channels - unsigned countChannels() { return (unsigned)voltage.size(); } + unsigned countChannels() const { return (unsigned)voltage.size(); } }; diff --git a/openhantek/src/settings.cpp b/openhantek/src/settings.cpp index bb8fc99..0d8b449 100644 --- a/openhantek/src/settings.cpp +++ b/openhantek/src/settings.cpp @@ -35,7 +35,7 @@ DsoSettings::DsoSettings(const Dso::ControlSpecification* deviceSpecification) { scope.spectrum.push_back(newSpectrum); DsoSettingsScopeVoltage newVoltage; - newVoltage.math = Dso::MathMode::ADD_CH1_CH2; + newVoltage.couplingOrMathIndex = (unsigned)Dso::MathMode::ADD_CH1_CH2; newVoltage.name = QApplication::tr("MATH"); scope.voltage.push_back(newVoltage); @@ -106,19 +106,20 @@ void DsoSettings::load() { for (ChannelID channel = 0; channel < scope.voltage.size(); ++channel) { store->beginGroup(QString("vertical%1").arg(channel)); if (store->contains("gainStepIndex")) scope.voltage[channel].gainStepIndex = store->value("gainStepIndex").toUInt(); - if (store->contains("couplingIndex")) scope.voltage[channel].couplingIndex = store->value("couplingIndex").toUInt(); + if (store->contains("couplingOrMathIndex")) scope.voltage[channel].couplingOrMathIndex = store->value("couplingIndex").toUInt(); if (store->contains("inverted")) scope.voltage[channel].inverted = store->value("inverted").toBool(); - if (store->contains("misc")) scope.voltage[channel].rawValue = store->value("misc").toInt(); if (store->contains("offset")) scope.voltage[channel].offset = store->value("offset").toDouble(); if (store->contains("trigger")) scope.voltage[channel].trigger = store->value("trigger").toDouble(); if (store->contains("used")) scope.voltage[channel].used = store->value("used").toBool(); store->endGroup(); } - if (store->contains("spectrumLimit")) scope.spectrumLimit = store->value("spectrumLimit").toDouble(); + + // Post processing + if (store->contains("spectrumLimit")) post.spectrumLimit = store->value("spectrumLimit").toDouble(); if (store->contains("spectrumReference")) - scope.spectrumReference = store->value("spectrumReference").toDouble(); + post.spectrumReference = store->value("spectrumReference").toDouble(); if (store->contains("spectrumWindow")) - scope.spectrumWindow = (Dso::WindowFunction)store->value("spectrumWindow").toInt(); + post.spectrumWindow = (Dso::WindowFunction)store->value("spectrumWindow").toInt(); store->endGroup(); // View @@ -209,17 +210,18 @@ void DsoSettings::save() { for (ChannelID channel = 0; channel < scope.voltage.size(); ++channel) { store->beginGroup(QString("vertical%1").arg(channel)); store->setValue("gainStepIndex", scope.voltage[channel].gainStepIndex); - store->setValue("couplingIndex", scope.voltage[channel].couplingIndex); + store->setValue("couplingOrMathIndex", scope.voltage[channel].couplingOrMathIndex); store->setValue("inverted", scope.voltage[channel].inverted); - store->setValue("misc", scope.voltage[channel].rawValue); store->setValue("offset", scope.voltage[channel].offset); store->setValue("trigger", scope.voltage[channel].trigger); store->setValue("used", scope.voltage[channel].used); store->endGroup(); } - store->setValue("spectrumLimit", scope.spectrumLimit); - store->setValue("spectrumReference", scope.spectrumReference); - store->setValue("spectrumWindow", (int)scope.spectrumWindow); + + // Post processing + store->setValue("spectrumLimit", post.spectrumLimit); + store->setValue("spectrumReference", post.spectrumReference); + store->setValue("spectrumWindow", (int)post.spectrumWindow); store->endGroup(); // View diff --git a/openhantek/src/settings.h b/openhantek/src/settings.h index ff1cbeb..17b2eff 100644 --- a/openhantek/src/settings.h +++ b/openhantek/src/settings.h @@ -7,22 +7,22 @@ #include #include +#include "exporting/exportsettings.h" +#include "post/postprocessingsettings.h" #include "scopesettings.h" #include "viewsettings.h" -#include "exporting/exportsettings.h" -#include "hantekdso/controlspecification.h" -#include "hantekdso/controlsettings.h" /// \brief Holds the settings of the program. class DsoSettings { public: - explicit DsoSettings(const Dso::ControlSpecification* deviceSpecification); + explicit DsoSettings(const Dso::ControlSpecification *deviceSpecification); bool setFilename(const QString &filename); - DsoSettingsExport exporting; ///< General options of the program - DsoSettingsScope scope; ///< All oscilloscope related settings - DsoSettingsView view; ///< All view related settings - bool alwaysSave = true; ///< Always save the settings on exit + DsoSettingsExport exporting; ///< General options of the program + DsoSettingsScope scope; ///< All oscilloscope related settings + DsoSettingsView view; ///< All view related settings + DsoSettingsPostProcessing post; ///< All post processing related settings + bool alwaysSave = true; ///< Always save the settings on exit QByteArray mainWindowGeometry; ///< Geometry of the main window QByteArray mainWindowState; ///< State of docking windows and toolbars diff --git a/openhantek/src/utils/dsoStrings.cpp b/openhantek/src/utils/dsoStrings.cpp deleted file mode 100644 index 1895c11..0000000 --- a/openhantek/src/utils/dsoStrings.cpp +++ /dev/null @@ -1,170 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// OpenHantek -// dso.cpp -// -// Copyright (C) 2010 Oliver Haag -// oliver.haag@gmail.com -// -// This program is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) -// any later version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -// more details. -// -// You should have received a copy of the GNU General Public License along with -// this program. If not, see . -// -//////////////////////////////////////////////////////////////////////////////// - -#include - -#include "dsoStrings.h" - -namespace Dso { -/// \brief Return string representation of the given channel mode. -/// \param mode The ::ChannelMode that should be returned as string. -/// \return The string that should be used in labels etc., empty when invalid. -QString channelModeString(ChannelMode mode) { - switch (mode) { - case ChannelMode::Voltage: - return QApplication::tr("Voltage"); - case ChannelMode::Spectrum: - return QApplication::tr("Spectrum"); - } - return QString(); -} - -/// \brief Return string representation of the given graph format. -/// \param format The ::GraphFormat that should be returned as string. -/// \return The string that should be used in labels etc. -QString graphFormatString(GraphFormat format) { - switch (format) { - case GraphFormat::TY: - return QApplication::tr("T - Y"); - case GraphFormat::XY: - return QApplication::tr("X - Y"); - } - return QString(); -} - -/// \brief Return string representation of the given channel coupling. -/// \param coupling The ::Coupling that should be returned as string. -/// \return The string that should be used in labels etc. -QString couplingString(Coupling coupling) { - switch (coupling) { - case Coupling::AC: - return QApplication::tr("AC"); - case Coupling::DC: - return QApplication::tr("DC"); - case Coupling::GND: - return QApplication::tr("GND"); - } - return QString(); -} - -/// \brief Return string representation of the given math mode. -/// \param mode The ::MathMode that should be returned as string. -/// \return The string that should be used in labels etc. -QString mathModeString(MathMode mode) { - switch (mode) { - case MathMode::ADD_CH1_CH2: - return QApplication::tr("CH1 + CH2"); - case MathMode::SUB_CH2_FROM_CH1: - return QApplication::tr("CH1 - CH2"); - case MathMode::SUB_CH1_FROM_CH2: - return QApplication::tr("CH2 - CH1"); - } - return QString(); -} - -/// \brief Return string representation of the given trigger mode. -/// \param mode The ::TriggerMode that should be returned as string. -/// \return The string that should be used in labels etc. -QString triggerModeString(TriggerMode mode) { - switch (mode) { - case TriggerMode::WAIT_FORCE: - return QApplication::tr("Wait/Force"); - case TriggerMode::HARDWARE_SOFTWARE: - return QApplication::tr("Hard-/Software"); - case TriggerMode::SINGLE: - return QApplication::tr("Single"); - } - return QString(); -} - -/// \brief Return string representation of the given trigger slope. -/// \param slope The ::Slope that should be returned as string. -/// \return The string that should be used in labels etc. -QString slopeString(Slope slope) { - switch (slope) { - case Slope::Positive: - return QString::fromUtf8("\u2197"); - case Slope::Negative: - return QString::fromUtf8("\u2198"); - default: - return QString(); - } -} - -/// \brief Return string representation of the given dft window function. -/// \param window The ::WindowFunction that should be returned as string. -/// \return The string that should be used in labels etc. -QString windowFunctionString(WindowFunction window) { - switch (window) { - case WindowFunction::RECTANGULAR: - return QApplication::tr("Rectangular"); - case WindowFunction::HAMMING: - return QApplication::tr("Hamming"); - case WindowFunction::HANN: - return QApplication::tr("Hann"); - case WindowFunction::COSINE: - return QApplication::tr("Cosine"); - case WindowFunction::LANCZOS: - return QApplication::tr("Lanczos"); - case WindowFunction::BARTLETT: - return QApplication::tr("Bartlett"); - case WindowFunction::TRIANGULAR: - return QApplication::tr("Triangular"); - case WindowFunction::GAUSS: - return QApplication::tr("Gauss"); - case WindowFunction::BARTLETTHANN: - return QApplication::tr("Bartlett-Hann"); - case WindowFunction::BLACKMAN: - return QApplication::tr("Blackman"); - // case WindowFunction::WINDOW_KAISER: - // return QApplication::tr("Kaiser"); - case WindowFunction::NUTTALL: - return QApplication::tr("Nuttall"); - case WindowFunction::BLACKMANHARRIS: - return QApplication::tr("Blackman-Harris"); - case WindowFunction::BLACKMANNUTTALL: - return QApplication::tr("Blackman-Nuttall"); - case WindowFunction::FLATTOP: - return QApplication::tr("Flat top"); - default: - return QString(); - } -} - -/// \brief Return string representation of the given graph interpolation mode. -/// \param interpolation The ::InterpolationMode that should be returned as -/// string. -/// \return The string that should be used in labels etc. -QString interpolationModeString(InterpolationMode interpolation) { - switch (interpolation) { - case INTERPOLATION_OFF: - return QApplication::tr("Off"); - case INTERPOLATION_LINEAR: - return QApplication::tr("Linear"); - case INTERPOLATION_SINC: - return QApplication::tr("Sinc"); - default: - return QString(); - } -} -} diff --git a/openhantek/src/utils/dsoStrings.h b/openhantek/src/utils/dsoStrings.h deleted file mode 100644 index 153bb27..0000000 --- a/openhantek/src/utils/dsoStrings.h +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ - -#pragma once -#include -#include "post/enums.h" -#include "hantekdso/enums.h" - -#define MARKER_COUNT 2 ///< Number of markers - -/// \namespace Dso -/// \brief All DSO specific things for different modes and so on. -namespace Dso { - -QString channelModeString(ChannelMode mode); -QString graphFormatString(GraphFormat format); -QString couplingString(Coupling coupling); -QString mathModeString(MathMode mode); -QString triggerModeString(TriggerMode mode); -QString slopeString(Slope slope); -QString windowFunctionString(WindowFunction window); -QString interpolationModeString(InterpolationMode interpolation); -} -- libgit2 0.21.4