From 87a2b63379ff1f63638fd215c434c36d55d5e01d Mon Sep 17 00:00:00 2001
From: oliverhaag
Date: Tue, 21 Sep 2010 19:58:54 +0000
Subject: [PATCH] Improved samplerate calculation routine and fixed some bugs
---
openhantek/ChangeLog | 7 +++++++
openhantek/src/exporter.cpp | 4 ++--
openhantek/src/hantek/control.cpp | 23 +++++++++++++++--------
openhantek/src/hantek/types.h | 2 +-
openhantek/src/openhantek.cpp | 2 +-
5 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/openhantek/ChangeLog b/openhantek/ChangeLog
index d820b25..c999603 100644
--- a/openhantek/ChangeLog
+++ b/openhantek/ChangeLog
@@ -85,3 +85,10 @@
2010-09-16 Oliver Haag
* Added csv export return value to doExport method
* Fixed DSO-2150 samplerates
+
+2010-09-21 Oliver Haag
+* Fixed print shortcut
+* Made samplerate calculation more flexible
+* DSO-5200 data conversion bugfix
+* Exporter::setFormat not filtering CSV format out anymore
+* Removed misplaced " before voltages in exported CSV file
diff --git a/openhantek/src/exporter.cpp b/openhantek/src/exporter.cpp
index 4f2c236..5307b61 100644
--- a/openhantek/src/exporter.cpp
+++ b/openhantek/src/exporter.cpp
@@ -66,7 +66,7 @@ void Exporter::setFilename(QString filename) {
/// \brief Set the output format.
void Exporter::setFormat(ExportFormat format) {
- if(format >= EXPORT_FORMAT_PRINTER && format <= EXPORT_FORMAT_IMAGE)
+ if(format >= EXPORT_FORMAT_PRINTER && format <= EXPORT_FORMAT_CSV)
this->format = format;
}
@@ -379,7 +379,7 @@ bool Exporter::doExport() {
// And now all sample values in volts
for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; position++)
- csvStream << "\"," << this->dataAnalyzer->data(channel)->samples.voltage.sample[position];
+ csvStream << "," << this->dataAnalyzer->data(channel)->samples.voltage.sample[position];
// Finally a newline
csvStream << '\n';
diff --git a/openhantek/src/hantek/control.cpp b/openhantek/src/hantek/control.cpp
index dd47c4f..4f5ff99 100644
--- a/openhantek/src/hantek/control.cpp
+++ b/openhantek/src/hantek/control.cpp
@@ -381,7 +381,7 @@ namespace Hantek {
if(bufferPosition >= dataCount)
bufferPosition %= dataCount;
- this->samples[channel][realPosition] = ((double) (data[bufferPosition] + (data[dataCount + bufferPosition] << 8)) / 0x1ff - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]];
+ this->samples[channel][realPosition] = ((double) ((unsigned short int) data[bufferPosition] + ((unsigned short int) data[dataCount + bufferPosition] << 8)) / 0x1ff - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]];
}
}
else {
@@ -600,25 +600,32 @@ namespace Hantek {
}
// The maximum sample rate depends on the buffer size
+ unsigned int bufferDivider = 1;
switch((this->commandVersion == 0) ? commandSetTriggerAndSamplerate->getBufferSize() : commandSetBuffer5200->getBufferSize()) {
case BUFFERID_ROLL:
- this->samplerateMax /= 1000;
+ bufferDivider = 1000;
break;
case BUFFERID_LARGE:
- this->samplerateMax /= 2;
+ bufferDivider = 2;
break;
default:
break;
}
// Get divider that would provide the requested rate, can't be zero
+ this->samplerateMax /= bufferDivider;
this->samplerateDivider = qMax(this->samplerateMax / samplerate, (long unsigned int) 1);
- // Use normal mode if it would meet the rate as exactly as fast rate mode
- if(fastRate && this->samplerateDivider % HANTEK_CHANNELS == 0) {
- fastRate = false;
- this->samplerateMax /= 2;
- this->samplerateDivider /= HANTEK_CHANNELS;
+ // Use normal mode if we need valueSlow or it would meet the rate at least as exactly as fast rate mode
+ if(fastRate) {
+ unsigned long int slowSamplerate = this->samplerateChannelMax / bufferDivider;
+ unsigned long int slowDivider = qMax(slowSamplerate / samplerate, (long unsigned int) 1);
+
+ if(this->samplerateDivider > 4 || (qAbs((double) slowSamplerate / slowDivider - samplerate) <= qAbs(((double) this->samplerateMax / this->samplerateDivider) - samplerate))) {
+ fastRate = false;
+ this->samplerateMax = slowSamplerate;
+ this->samplerateDivider = slowDivider;
+ }
}
// Split the resulting divider into the values understood by the device
diff --git a/openhantek/src/hantek/types.h b/openhantek/src/hantek/types.h
index 82d27d8..be21dba 100644
--- a/openhantek/src/hantek/types.h
+++ b/openhantek/src/hantek/types.h
@@ -96,7 +96,7 @@ namespace Hantek {
/// Without using fast rate mode, the samplerate is:
/// Samplerate = SamplerateMax / (1comp(SamplerateSlow) * 2 + Tsr1Bits.samplerateFast)
/// SamplerateMax is 50 MHz for the DSO-2090.
- /// When using fast rate mode the resulting samplerate is twice as fast, when using the large buffer it is half as fast. When Tsr1Bits.bufferSize is 0 (Roll mode) the sampling rate is divided by 1000. Setting Tsr1Bits.samplerateFast to 0 doesn't work, the result will be the same as Tsr1Bits.samplerateFast = 1.
+ /// When using fast rate mode the resulting samplerate is twice (For DSO-2150 three times) as fast, when using the large buffer it is half as fast. When Tsr1Bits.bufferSize is 0 (Roll mode) the sampling rate is divided by 1000. Setting Tsr1Bits.samplerateFast to 0 doesn't work, the result will be the same as Tsr1Bits.samplerateFast = 1. SamplerateSlow can't be used together with fast rate mode, the result is always the the same as SlowValue = 0.
///
///
/// The TriggerPosition sets the position of the pretrigger in samples. The left side (0 %) is 0x77660 when using the small buffer and 0x78000 when using the large buffer.
diff --git a/openhantek/src/openhantek.cpp b/openhantek/src/openhantek.cpp
index 21dd72c..70a1adc 100644
--- a/openhantek/src/openhantek.cpp
+++ b/openhantek/src/openhantek.cpp
@@ -177,7 +177,7 @@ void OpenHantekMainWindow::createActions() {
connect(this->saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs()));
this->printAction = new QAction(QIcon(":actions/print.png"), tr("&Print..."), this);
- this->saveAction->setShortcut(tr("Ctrl+P"));
+ this->printAction->setShortcut(tr("Ctrl+P"));
this->printAction->setStatusTip(tr("Print the oscilloscope screen"));
connect(this->printAction, SIGNAL(triggered()), this->dsoWidget, SLOT(print()));
--
libgit2 0.21.4