diff --git a/.gitignore b/.gitignore index 92bf471..8cc1f75 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .o .so .*~ -build/ \ No newline at end of file +CMakeLists.txt.user +build/ diff --git a/openhantek/src/dockwindows.cpp b/openhantek/src/dockwindows.cpp index 93e4376..ee64356 100644 --- a/openhantek/src/dockwindows.cpp +++ b/openhantek/src/dockwindows.cpp @@ -27,6 +27,8 @@ #include #include +#include + #include "dockwindows.h" #include "helper.h" @@ -51,7 +53,6 @@ HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent, this->samplerateSiSpinBox->setMaximum(1e8); this->samplerateSiSpinBox->setUnitPostfix("/s"); - QList timebaseSteps; timebaseSteps << 1.0 << 2.0 << 4.0 << 10.0; this->timebaseLabel = new QLabel(tr("Timebase")); @@ -144,10 +145,19 @@ void HorizontalDock::setSamplerate(double samplerate) { /// \brief Changes the timebase. /// \param timebase The timebase in seconds. -void HorizontalDock::setTimebase(double timebase) { - this->suppressSignals = true; - this->timebaseSiSpinBox->setValue(timebase); - this->suppressSignals = false; +double HorizontalDock::setTimebase(double timebase) { + // timebaseSteps are repeated in each decade + double decade = pow(10, floor(log10(timebase))); + double vNorm = timebase / decade; + for (int i = 0; i < timebaseSteps.size() - 1; ++i) { + if (timebaseSteps.at(i) <= vNorm && vNorm < timebaseSteps.at(i + 1)) { + suppressSignals = true; + timebaseSiSpinBox->setValue(decade * timebaseSteps.at(i)); + suppressSignals = false; + break; + } + } + return timebaseSiSpinBox->value(); } /// \brief Changes the record length if the new value is supported. diff --git a/openhantek/src/dockwindows.h b/openhantek/src/dockwindows.h index 34812ee..199afb8 100644 --- a/openhantek/src/dockwindows.h +++ b/openhantek/src/dockwindows.h @@ -51,7 +51,7 @@ public: void setFrequencybase(double timebase); void setSamplerate(double samplerate); - void setTimebase(double timebase); + double setTimebase(double timebase); void setRecordLength(unsigned int recordLength); int setFormat(Dso::GraphFormat format); @@ -75,6 +75,7 @@ protected: ///interpreted and shown DsoSettings *settings; ///< The settings provided by the parent class + QList timebaseSteps; ///< Steps for the timebase spinbox QStringList formatStrings; ///< Strings for the formats diff --git a/openhantek/src/hantek/control.cpp b/openhantek/src/hantek/control.cpp index 91094d6..ec53107 100644 --- a/openhantek/src/hantek/control.cpp +++ b/openhantek/src/hantek/control.cpp @@ -266,7 +266,8 @@ int Control::getCaptureState() { int Control::getSamples(bool process) { int errorCode; - const unsigned int DROP_DSO6022_SAMPLES = 0x410; + const unsigned int DROP_DSO6022_HEAD = 0x410; + const unsigned int DROP_DSO6022_TAIL = 0x3F0; if (this->device->getModel() != MODEL_DSO6022BE) { // Request data @@ -395,13 +396,15 @@ int Control::getSamples(bool process) { } else { // Normal mode, channels are using their separate buffers sampleCount = totalSampleCount / HANTEK_CHANNELS; - // if device is 6022BE, drop first DROP_DSO6022_SAMPLES samples + // if device is 6022BE, drop heading & trailing samples if (this->device->getModel() == MODEL_DSO6022BE) - sampleCount -= DROP_DSO6022_SAMPLES; + sampleCount -= (DROP_DSO6022_HEAD + DROP_DSO6022_TAIL); for (int channel = 0; channel < HANTEK_CHANNELS; ++channel) { if (this->settings.voltage[channel].used) { // Resize sample vector - this->samples[channel].resize(sampleCount); + if (samples[channel].size() < sampleCount) { + this->samples[channel].resize(sampleCount); + } // Convert data from the oscilloscope and write it into the sample // buffer @@ -440,8 +443,8 @@ int Control::getSamples(bool process) { } else { if (this->device->getModel() == MODEL_DSO6022BE) { bufferPosition += channel; - // if device is 6022BE, offset DROP_DSO6022_SAMPLES incrementally - bufferPosition += DROP_DSO6022_SAMPLES * 2; + // if device is 6022BE, offset DROP_DSO6022_HEAD incrementally + bufferPosition += DROP_DSO6022_HEAD * 2; } else bufferPosition += HANTEK_CHANNELS - 1 - channel; @@ -1098,13 +1101,11 @@ void Control::connectDevice() { this->specification.samplerate.single.base = 1e6; this->specification.samplerate.single.max = 48e6; this->specification.samplerate.single.maxDownsampler = 10; - this->specification.samplerate.single.recordLengths << UINT_MAX << 10240 - << 32768; + this->specification.samplerate.single.recordLengths << UINT_MAX << 10240; this->specification.samplerate.multi.base = 1e6; this->specification.samplerate.multi.max = 48e6; this->specification.samplerate.multi.maxDownsampler = 10; - this->specification.samplerate.multi.recordLengths << UINT_MAX << 20480 - << 65536; + this->specification.samplerate.multi.recordLengths << UINT_MAX << 20480; this->specification.bufferDividers << 1000 << 1 << 1; this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0; @@ -1248,12 +1249,14 @@ double Control::setSamplerate(double samplerate) { this->controlPending[CONTROLINDEX_SETTIMEDIV] = true; this->settings.samplerate.current = samplerate; + // Provide margin for SW trigger + unsigned int sampleMargin = 2000; // Check for Roll mode if (this->settings.samplerate.limits ->recordLengths[this->settings.recordLengthId] != UINT_MAX) emit recordTimeChanged( - (double)this->settings.samplerate.limits - ->recordLengths[this->settings.recordLengthId] / + (double)(this->settings.samplerate.limits + ->recordLengths[this->settings.recordLengthId] - sampleMargin) / this->settings.samplerate.current); emit samplerateChanged(this->settings.samplerate.current); diff --git a/openhantek/src/openhantek.cpp b/openhantek/src/openhantek.cpp index f89fbdd..d3ef896 100644 --- a/openhantek/src/openhantek.cpp +++ b/openhantek/src/openhantek.cpp @@ -691,9 +691,8 @@ void OpenHantekMainWindow::recordTimeChanged(double duration) { if (this->settings->scope.horizontal.samplerateSet && this->settings->scope.horizontal.recordLength != UINT_MAX) { // The samplerate was set, let's adapt the timebase accordingly - this->settings->scope.horizontal.timebase = duration / DIVS_TIME; - this->horizontalDock->setTimebase( - this->settings->scope.horizontal.timebase); + this->settings->scope.horizontal.timebase = + this->horizontalDock->setTimebase(duration / DIVS_TIME); } // The trigger position should be kept at the same place but the timebase has @@ -733,6 +732,7 @@ void OpenHantekMainWindow::samplerateSelected() { void OpenHantekMainWindow::timebaseSelected() { this->dsoControl->setRecordTime(this->settings->scope.horizontal.timebase * DIVS_TIME); + this->dsoWidget->updateTimebase(settings->scope.horizontal.timebase); } /// \brief Sets the offset of the oscilloscope for the given channel.