Commit 67afd83c7996eec867cf38d4ad79aa6ba34e7c10

Authored by Denis Dovzhenko
Committed by David Gräff
1 parent 93d81624

Moved timebaseSteps to HorizontalDock, record length changed to 8K samples (6022BE only)

.gitignore
... ... @@ -2,4 +2,5 @@
2 2 .o
3 3 .so
4 4 .*~
5   -build/
6 5 \ No newline at end of file
  6 +CMakeLists.txt.user
  7 +build/
... ...
openhantek/src/dockwindows.cpp
... ... @@ -27,6 +27,8 @@
27 27 #include <QDockWidget>
28 28 #include <QLabel>
29 29  
  30 +#include <cmath>
  31 +
30 32 #include "dockwindows.h"
31 33  
32 34 #include "helper.h"
... ... @@ -51,7 +53,6 @@ HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent,
51 53 this->samplerateSiSpinBox->setMaximum(1e8);
52 54 this->samplerateSiSpinBox->setUnitPostfix("/s");
53 55  
54   - QList<double> timebaseSteps;
55 56 timebaseSteps << 1.0 << 2.0 << 4.0 << 10.0;
56 57  
57 58 this->timebaseLabel = new QLabel(tr("Timebase"));
... ... @@ -144,10 +145,19 @@ void HorizontalDock::setSamplerate(double samplerate) {
144 145  
145 146 /// \brief Changes the timebase.
146 147 /// \param timebase The timebase in seconds.
147   -void HorizontalDock::setTimebase(double timebase) {
148   - this->suppressSignals = true;
149   - this->timebaseSiSpinBox->setValue(timebase);
150   - this->suppressSignals = false;
  148 +double HorizontalDock::setTimebase(double timebase) {
  149 + // timebaseSteps are repeated in each decade
  150 + double decade = pow(10, floor(log10(timebase)));
  151 + double vNorm = timebase / decade;
  152 + for (int i = 0; i < timebaseSteps.size() - 1; ++i) {
  153 + if (timebaseSteps.at(i) <= vNorm && vNorm < timebaseSteps.at(i + 1)) {
  154 + suppressSignals = true;
  155 + timebaseSiSpinBox->setValue(decade * timebaseSteps.at(i));
  156 + suppressSignals = false;
  157 + break;
  158 + }
  159 + }
  160 + return timebaseSiSpinBox->value();
151 161 }
152 162  
153 163 /// \brief Changes the record length if the new value is supported.
... ...
openhantek/src/dockwindows.h
... ... @@ -51,7 +51,7 @@ public:
51 51  
52 52 void setFrequencybase(double timebase);
53 53 void setSamplerate(double samplerate);
54   - void setTimebase(double timebase);
  54 + double setTimebase(double timebase);
55 55 void setRecordLength(unsigned int recordLength);
56 56 int setFormat(Dso::GraphFormat format);
57 57  
... ... @@ -75,6 +75,7 @@ protected:
75 75 ///interpreted and shown
76 76  
77 77 DsoSettings *settings; ///< The settings provided by the parent class
  78 + QList<double> timebaseSteps; ///< Steps for the timebase spinbox
78 79  
79 80 QStringList formatStrings; ///< Strings for the formats
80 81  
... ...
openhantek/src/hantek/control.cpp
... ... @@ -266,7 +266,8 @@ int Control::getCaptureState() {
266 266 int Control::getSamples(bool process) {
267 267 int errorCode;
268 268  
269   - const unsigned int DROP_DSO6022_SAMPLES = 0x410;
  269 + const unsigned int DROP_DSO6022_HEAD = 0x410;
  270 + const unsigned int DROP_DSO6022_TAIL = 0x3F0;
270 271  
271 272 if (this->device->getModel() != MODEL_DSO6022BE) {
272 273 // Request data
... ... @@ -395,13 +396,15 @@ int Control::getSamples(bool process) {
395 396 } else {
396 397 // Normal mode, channels are using their separate buffers
397 398 sampleCount = totalSampleCount / HANTEK_CHANNELS;
398   - // if device is 6022BE, drop first DROP_DSO6022_SAMPLES samples
  399 + // if device is 6022BE, drop heading & trailing samples
399 400 if (this->device->getModel() == MODEL_DSO6022BE)
400   - sampleCount -= DROP_DSO6022_SAMPLES;
  401 + sampleCount -= (DROP_DSO6022_HEAD + DROP_DSO6022_TAIL);
401 402 for (int channel = 0; channel < HANTEK_CHANNELS; ++channel) {
402 403 if (this->settings.voltage[channel].used) {
403 404 // Resize sample vector
404   - this->samples[channel].resize(sampleCount);
  405 + if (samples[channel].size() < sampleCount) {
  406 + this->samples[channel].resize(sampleCount);
  407 + }
405 408  
406 409 // Convert data from the oscilloscope and write it into the sample
407 410 // buffer
... ... @@ -440,8 +443,8 @@ int Control::getSamples(bool process) {
440 443 } else {
441 444 if (this->device->getModel() == MODEL_DSO6022BE) {
442 445 bufferPosition += channel;
443   - // if device is 6022BE, offset DROP_DSO6022_SAMPLES incrementally
444   - bufferPosition += DROP_DSO6022_SAMPLES * 2;
  446 + // if device is 6022BE, offset DROP_DSO6022_HEAD incrementally
  447 + bufferPosition += DROP_DSO6022_HEAD * 2;
445 448 } else
446 449 bufferPosition += HANTEK_CHANNELS - 1 - channel;
447 450  
... ... @@ -1098,13 +1101,11 @@ void Control::connectDevice() {
1098 1101 this->specification.samplerate.single.base = 1e6;
1099 1102 this->specification.samplerate.single.max = 48e6;
1100 1103 this->specification.samplerate.single.maxDownsampler = 10;
1101   - this->specification.samplerate.single.recordLengths << UINT_MAX << 10240
1102   - << 32768;
  1104 + this->specification.samplerate.single.recordLengths << UINT_MAX << 10240;
1103 1105 this->specification.samplerate.multi.base = 1e6;
1104 1106 this->specification.samplerate.multi.max = 48e6;
1105 1107 this->specification.samplerate.multi.maxDownsampler = 10;
1106   - this->specification.samplerate.multi.recordLengths << UINT_MAX << 20480
1107   - << 65536;
  1108 + this->specification.samplerate.multi.recordLengths << UINT_MAX << 20480;
1108 1109 this->specification.bufferDividers << 1000 << 1 << 1;
1109 1110 this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60
1110 1111 << 4.00 << 8.0 << 16.0 << 40.0;
... ... @@ -1248,12 +1249,14 @@ double Control::setSamplerate(double samplerate) {
1248 1249 this->controlPending[CONTROLINDEX_SETTIMEDIV] = true;
1249 1250 this->settings.samplerate.current = samplerate;
1250 1251  
  1252 + // Provide margin for SW trigger
  1253 + unsigned int sampleMargin = 2000;
1251 1254 // Check for Roll mode
1252 1255 if (this->settings.samplerate.limits
1253 1256 ->recordLengths[this->settings.recordLengthId] != UINT_MAX)
1254 1257 emit recordTimeChanged(
1255   - (double)this->settings.samplerate.limits
1256   - ->recordLengths[this->settings.recordLengthId] /
  1258 + (double)(this->settings.samplerate.limits
  1259 + ->recordLengths[this->settings.recordLengthId] - sampleMargin) /
1257 1260 this->settings.samplerate.current);
1258 1261 emit samplerateChanged(this->settings.samplerate.current);
1259 1262  
... ...
openhantek/src/openhantek.cpp
... ... @@ -691,9 +691,8 @@ void OpenHantekMainWindow::recordTimeChanged(double duration) {
691 691 if (this->settings->scope.horizontal.samplerateSet &&
692 692 this->settings->scope.horizontal.recordLength != UINT_MAX) {
693 693 // The samplerate was set, let's adapt the timebase accordingly
694   - this->settings->scope.horizontal.timebase = duration / DIVS_TIME;
695   - this->horizontalDock->setTimebase(
696   - this->settings->scope.horizontal.timebase);
  694 + this->settings->scope.horizontal.timebase =
  695 + this->horizontalDock->setTimebase(duration / DIVS_TIME);
697 696 }
698 697  
699 698 // The trigger position should be kept at the same place but the timebase has
... ... @@ -733,6 +732,7 @@ void OpenHantekMainWindow::samplerateSelected() {
733 732 void OpenHantekMainWindow::timebaseSelected() {
734 733 this->dsoControl->setRecordTime(this->settings->scope.horizontal.timebase *
735 734 DIVS_TIME);
  735 + this->dsoWidget->updateTimebase(settings->scope.horizontal.timebase);
736 736 }
737 737  
738 738 /// \brief Sets the offset of the oscilloscope for the given channel.
... ...