diff --git a/openhantek/ChangeLog b/openhantek/ChangeLog index 8aa3808..a907bc5 100644 --- a/openhantek/ChangeLog +++ b/openhantek/ChangeLog @@ -164,3 +164,8 @@ 2012-10-07 Oliver Haag * Ignore errors after first packet was received by Hantek::Device::bulkReadMulti + +2012-10-17 Oliver Haag +* Change back workaround for Mac OS that is most probably not required anymore +* Various performance improvements and small fixes +* New cppcheck build target diff --git a/openhantek/OpenHantek.pro b/openhantek/OpenHantek.pro index f8d94e3..54782b6 100644 --- a/openhantek/OpenHantek.pro +++ b/openhantek/OpenHantek.pro @@ -1,69 +1,87 @@ +# Helper functions +defineReplace(surround) { + elements = $$1 + prefix = $$2 + postfix = $$3 + result = + for(element, elements) { + result += "$${prefix}$${element}$${postfix}" + } + return($${result}) +} + TEMPLATE = app # Configuration -CONFIG += warn_on \ - qt +CONFIG += \ + warn_on \ + qt QT += opengl LIBS += -lfftw3 # Source files -SOURCES += src/colorbox.cpp \ - src/configdialog.cpp \ - src/configpages.cpp \ - src/dataanalyzer.cpp \ - src/dockwindows.cpp \ - src/dsocontrol.cpp \ - src/dsowidget.cpp \ - src/exporter.cpp \ - src/glgenerator.cpp \ - src/glscope.cpp \ - src/helper.cpp \ - src/levelslider.cpp \ - src/main.cpp \ - src/openhantek.cpp \ - src/settings.cpp \ - src/hantek/control.cpp \ - src/hantek/device.cpp \ - src/hantek/types.cpp \ - src/dso.cpp -HEADERS += src/colorbox.h \ - src/configdialog.h \ - src/configpages.h \ - src/dataanalyzer.h \ - src/dockwindows.h \ - src/dsocontrol.h \ - src/dsowidget.h \ - src/exporter.h \ - src/glscope.h \ - src/glgenerator.h \ - src/helper.h \ - src/levelslider.h \ - src/openhantek.h \ - src/settings.h \ - src/hantek/control.h \ - src/hantek/device.h \ - src/hantek/types.h \ - src/dso.h +SOURCES += \ + src/colorbox.cpp \ + src/configdialog.cpp \ + src/configpages.cpp \ + src/dataanalyzer.cpp \ + src/dockwindows.cpp \ + src/dsocontrol.cpp \ + src/dsowidget.cpp \ + src/exporter.cpp \ + src/glgenerator.cpp \ + src/glscope.cpp \ + src/helper.cpp \ + src/levelslider.cpp \ + src/main.cpp \ + src/openhantek.cpp \ + src/settings.cpp \ + src/hantek/control.cpp \ + src/hantek/device.cpp \ + src/hantek/types.cpp \ + src/dso.cpp +HEADERS += \ + src/colorbox.h \ + src/configdialog.h \ + src/configpages.h \ + src/dataanalyzer.h \ + src/dockwindows.h \ + src/dsocontrol.h \ + src/dsowidget.h \ + src/exporter.h \ + src/glscope.h \ + src/glgenerator.h \ + src/helper.h \ + src/levelslider.h \ + src/openhantek.h \ + src/settings.h \ + src/hantek/control.h \ + src/hantek/device.h \ + src/hantek/types.h \ + src/dso.h # Ressource files -RESOURCES += res/application.qrc \ - res/configdialog.qrc +RESOURCES += \ + res/application.qrc \ + res/configdialog.qrc # Doxygen files -DOXYFILES += Doxyfile \ - mainpage.dox \ - roadmap.dox +DOXYFILES += \ + Doxyfile \ + mainpage.dox \ + roadmap.dox # Files copied into the distribution package -DISTFILES += ChangeLog \ - COPYING \ - INSTALL \ - res/images/*.png \ - res/images/*.icns \ - res/images/*.svg \ - translations/*.qm \ - translations/*.ts \ - $${DOXYFILES} +DISTFILES += \ + ChangeLog \ + COPYING \ + INSTALL \ + res/images/*.png \ + res/images/*.icns \ + res/images/*.svg \ + translations/*.qm \ + translations/*.ts \ + $${DOXYFILES} # Translations TRANSLATIONS += translations/openhantek_de.ts @@ -82,15 +100,14 @@ OBJECTS_DIR = build/obj UI_DIR = build/ui MOC_DIR = build/moc -# Include directory -QMAKE_CXXFLAGS += "-iquote $${IN_PWD}/src" - # libusb version LIBUSB_VERSION = $$(LIBUSB_VERSION) -contains(LIBUSB_VERSION, 0): LIBS += -lusb +contains(LIBUSB_VERSION, 0) { + LIBS += -lusb +} else { - LIBUSB_VERSION = 1 - LIBS += -lusb-1.0 + LIBUSB_VERSION = 1 + LIBS += -lusb-1.0 } DEFINES += LIBUSB_VERSION=$${LIBUSB_VERSION} @@ -98,49 +115,74 @@ DEFINES += LIBUSB_VERSION=$${LIBUSB_VERSION} CONFIG(debug, debug|release): DEFINES += DEBUG else: DEFINES += QT_NO_DEBUG_OUTPUT +# Quoted include directories +INCLUDEPATH_QUOTE = "$${IN_PWD}/src" + +# Include directory +QMAKE_CXXFLAGS += "-iquote $${INCLUDEPATH_QUOTE}" + # Settings for different operating systems unix:!macx { - isEmpty(PREFIX):PREFIX = /usr/local - TARGET = openhantek - - # Installation directories - target.path = $${PREFIX}/bin - translations.path = $${PREFIX}/share/apps/openhantek/translations - INCLUDEPATH += /usr/include/libusb - DEFINES += QMAKE_TRANSLATIONS_PATH=\\\"$${translations.path}\\\" \ - OS_UNIX VERSION=\\\"$${VERSION}\\\" + isEmpty(PREFIX): PREFIX = /usr/local + TARGET = openhantek + + # Installation directories + target.path = $${PREFIX}/bin + translations.path = $${PREFIX}/share/apps/openhantek/translations + contains(LIBUSB_VERSION, 0) { + INCLUDEPATH += /usr/include/libusb + } + else { + INCLUDEPATH += /usr/include/libusb-1.0 + } + DEFINES += \ + QMAKE_TRANSLATIONS_PATH=\\\"$${translations.path}\\\" \ + OS_UNIX VERSION=\\\"$${VERSION}\\\" } macx { - isEmpty(PREFIX):PREFIX = OpenHantek.app - TARGET = OpenHantek - - # Installation directories - target.path = $${PREFIX}/Contents/MacOS - translations.path = $${PREFIX}/Contents/Resources/translations - INCLUDEPATH += src - LIBS += -framework IOKit -framework CoreFoundation - ICON = res/images/openhantek.icns - DEFINES += QMAKE_TRANSLATIONS_PATH=\"Contents/Resources/translations\" \ - OS_DARWIN VERSION=\"$${VERSION}\" + isEmpty(PREFIX): PREFIX = OpenHantek.app + TARGET = OpenHantek + + # Installation directories + target.path = $${PREFIX}/Contents/MacOS + translations.path = $${PREFIX}/Contents/Resources/translations + INCLUDEPATH += $${INCLUDEPATH_QUOTE} + LIBS += -framework IOKit -framework CoreFoundation + ICON = res/images/openhantek.icns + DEFINES += \ + QMAKE_TRANSLATIONS_PATH=\\\"Contents/Resources/translations\\\" \ + OS_DARWIN VERSION=\\\"$${VERSION}\\\" } win32 { - isEmpty(PREFIX):PREFIX = OpenHantek - TARGET = OpenHantek - - # Installation directories - target.path = $${PREFIX} - translations.path = $${PREFIX}/translations - DEFINES += QMAKE_TRANSLATIONS_PATH=\\\"translations\\\" \ - OS_WINDOWS VERSION=\\\"$${VERSION}\\\" + isEmpty(PREFIX): PREFIX = OpenHantek + TARGET = OpenHantek + + # Installation directories + target.path = $${PREFIX} + translations.path = $${PREFIX}/translations + INCLUDEPATH += $${INCLUDEPATH_QUOTE} + DEFINES += \ + QMAKE_TRANSLATIONS_PATH=\\\"translations\\\" \ + OS_WINDOWS VERSION=\\\"$${VERSION}\\\" } translations.files += translations/*.qm -INSTALLS += target \ - translations +INSTALLS += \ + target \ + translations + +# Custom target "cppcheck" for Cppcheck +INCLUDEPARAMETERS = $$surround($${INCLUDEPATH} $${INCLUDEPATH_QUOTE}, "-I \"", "\"") +cppcheck.commands = "cppcheck --enable=all $${INCLUDEPARAMETERS} -q $${SOURCES} --template=\"{file}:{line}: {severity}: {message}\"" +cppcheck.depends = $${SOURCES} # Custom target "doc" for Doxygen -doxygen.target = doc +doxygen.target = "doc" doxygen.commands = "rm -r doc/; env DEFINES=\"$${DEFINES}\" doxygen Doxyfile" -doxygen.depends = $${SOURCES} \ - $${HEADERS} \ - $${DOXYFILES} -QMAKE_EXTRA_TARGETS += doxygen +doxygen.depends = \ + $${SOURCES} \ + $${HEADERS} \ + $${DOXYFILES} + +QMAKE_EXTRA_TARGETS += \ + cppcheck \ + doxygen diff --git a/openhantek/src/configpages.cpp b/openhantek/src/configpages.cpp index d61f675..bdbe6c8 100644 --- a/openhantek/src/configpages.cpp +++ b/openhantek/src/configpages.cpp @@ -170,7 +170,7 @@ DsoConfigColorsPage::DsoConfigColorsPage(DsoSettings *settings, QWidget *parent) this->channelLabel->setAlignment(Qt::AlignHCenter); this->spectrumLabel = new QLabel(tr("Spectrum")); this->spectrumLabel->setAlignment(Qt::AlignHCenter); - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->colorLabel.append(new QLabel(this->settings->scope.voltage[channel].name)); this->channelColorBox.append(new ColorBox(this->settings->view.color.screen.voltage[channel])); this->spectrumColorBox.append(new ColorBox(this->settings->view.color.screen.spectrum[channel])); @@ -182,7 +182,7 @@ DsoConfigColorsPage::DsoConfigColorsPage(DsoSettings *settings, QWidget *parent) this->graphLayout->setColumnMinimumWidth(2, 80); this->graphLayout->addWidget(this->channelLabel, 0, 1); this->graphLayout->addWidget(this->spectrumLabel, 0, 2); - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->graphLayout->addWidget(this->colorLabel[channel], channel + 1, 0); this->graphLayout->addWidget(this->channelColorBox[channel], channel + 1, 1); this->graphLayout->addWidget(this->spectrumColorBox[channel], channel + 1, 2); @@ -215,7 +215,7 @@ void DsoConfigColorsPage::saveSettings() { this->settings->view.color.screen.text = this->textColorBox->getColor(); // Graph category - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->settings->view.color.screen.voltage[channel] = this->channelColorBox[channel]->getColor(); this->settings->view.color.screen.spectrum[channel] = this->spectrumColorBox[channel]->getColor(); } diff --git a/openhantek/src/dataanalyzer.cpp b/openhantek/src/dataanalyzer.cpp index bfd6c48..c510f75 100644 --- a/openhantek/src/dataanalyzer.cpp +++ b/openhantek/src/dataanalyzer.cpp @@ -50,15 +50,22 @@ DataAnalyzer::DataAnalyzer(DsoSettings *settings, QObject *parent) : QThread(par this->window = 0; this->analyzedDataMutex = new QMutex(); + + this->maxSamples = 0; + + this->waitingDataSamplerate = 0.0; + this->waitingDataMutex = 0; } /// \brief Deallocates the buffers. DataAnalyzer::~DataAnalyzer() { - for(int channel = 0; channel < this->analyzedData.count(); channel++) { - if(this->analyzedData[channel]->samples.voltage.sample) - delete[] this->analyzedData[channel]->samples.voltage.sample; - if(this->analyzedData[channel]->samples.spectrum.sample) - delete[] this->analyzedData[channel]->samples.spectrum.sample; + for(int channel = 0; channel < this->analyzedData.count(); ++channel) { + AnalyzedData *channelData = this->analyzedData[channel]; + + if(channelData->samples.voltage.sample) + delete[] channelData->samples.voltage.sample; + if(channelData->samples.spectrum.sample) + delete[] channelData->samples.spectrum.sample; } } @@ -89,32 +96,48 @@ void DataAnalyzer::run() { this->analyzedDataMutex->lock(); unsigned long int maxSamples = 0; + unsigned int channelCount = (unsigned int) this->settings->scope.voltage.count(); // Adapt the number of channels for analyzed data - for(int channel = this->analyzedData.count(); channel < this->settings->scope.voltage.count(); channel++) { - this->analyzedData.append(new AnalyzedData); - this->analyzedData[channel]->samples.voltage.count = 0; - this->analyzedData[channel]->samples.voltage.interval = 0; - this->analyzedData[channel]->samples.voltage.sample = 0; - this->analyzedData[channel]->samples.spectrum.count = 0; - this->analyzedData[channel]->samples.spectrum.interval = 0; - this->analyzedData[channel]->samples.spectrum.sample = 0; - this->analyzedData[channel]->amplitude = 0; - this->analyzedData[channel]->frequency = 0; + for(unsigned int channel = this->analyzedData.count(); channel < channelCount; ++channel) { + AnalyzedData *channelData = new AnalyzedData; + channelData->samples.voltage.count = 0; + channelData->samples.voltage.interval = 0; + channelData->samples.voltage.sample = 0; + channelData->samples.spectrum.count = 0; + channelData->samples.spectrum.interval = 0; + channelData->samples.spectrum.sample = 0; + channelData->amplitude = 0; + channelData->frequency = 0; + this->analyzedData.append(channelData); } - for(int channel = this->settings->scope.voltage.count(); channel < this->analyzedData.count(); channel++) { - if(this->analyzedData.last()->samples.voltage.sample) - delete[] this->analyzedData.last()->samples.voltage.sample; - if(this->analyzedData.last()->samples.spectrum.sample) - delete[] this->analyzedData.last()->samples.spectrum.sample; + for(unsigned int channel = this->analyzedData.count(); channel > channelCount; --channel) { + AnalyzedData *channelData = this->analyzedData.last(); + if(channelData->samples.voltage.sample) + delete[] channelData->samples.voltage.sample; + if(channelData->samples.spectrum.sample) + delete[] channelData->samples.spectrum.sample; this->analyzedData.removeLast(); } - for(unsigned int channel = 0; channel < (unsigned int) this->analyzedData.count(); channel++) { - // Check if we got data for this channel or if it's a math channel that can be calculated - if(((channel < this->settings->scope.physicalChannels) && channel < (unsigned int) this->waitingData.count() && this->waitingData[channel]) || ((channel >= this->settings->scope.physicalChannels) && (this->settings->scope.voltage[channel].used || this->settings->scope.spectrum[channel].used) && this->analyzedData.count() >= 2 && this->analyzedData[0]->samples.voltage.sample && this->analyzedData[1]->samples.voltage.sample)) { + for(unsigned int channel = 0; channel < channelCount; ++channel) { + AnalyzedData *channelData = this->analyzedData[channel]; + + if( // Check... + ( // ...if we got data for this channel... + channel < this->settings->scope.physicalChannels && + channel < (unsigned int) this->waitingData.count() && + this->waitingData[channel]) || + ( // ...or if it's a math channel that can be calculated + channel >= this->settings->scope.physicalChannels && + (this->settings->scope.voltage[channel].used || this->settings->scope.spectrum[channel].used) && + this->analyzedData.count() >= 2 && + this->analyzedData[0]->samples.voltage.sample && + this->analyzedData[1]->samples.voltage.sample + ) + ) { // Set sampling interval - this->analyzedData[channel]->samples.voltage.interval = 1.0 / this->waitingDataSamplerate; + channelData->samples.voltage.interval = 1.0 / this->waitingDataSamplerate; unsigned int size; if(channel < this->settings->scope.physicalChannels) { @@ -125,19 +148,19 @@ void DataAnalyzer::run() { else size = maxSamples; // Reallocate memory for samples if the sample count has changed - if(this->analyzedData[channel]->samples.voltage.count != size) { - this->analyzedData[channel]->samples.voltage.count = size; - if(this->analyzedData[channel]->samples.voltage.sample) - delete[] this->analyzedData[channel]->samples.voltage.sample; - this->analyzedData[channel]->samples.voltage.sample = new double[size]; + if(channelData->samples.voltage.count != size) { + channelData->samples.voltage.count = size; + if(channelData->samples.voltage.sample) + delete[] channelData->samples.voltage.sample; + channelData->samples.voltage.sample = new double[size]; } // Physical channels if(channel < this->settings->scope.physicalChannels) { // Copy the buffer of the oscilloscope into the sample buffer if(channel < (unsigned int) this->waitingData.count()) - for(unsigned int position = 0; position < this->waitingDataSize[channel]; position++) - this->analyzedData[channel]->samples.voltage.sample[position] = this->waitingData[channel][position]; + for(unsigned int position = 0; position < this->waitingDataSize[channel]; ++position) + channelData->samples.voltage.sample[position] = this->waitingData[channel][position]; } // Math channel else { @@ -153,7 +176,7 @@ void DataAnalyzer::run() { } // Calculate values and write them into the sample buffer - for(unsigned int realPosition = 0; realPosition < this->analyzedData[this->settings->scope.physicalChannels]->samples.voltage.count; realPosition++) { + for(unsigned int realPosition = 0; realPosition < this->analyzedData[this->settings->scope.physicalChannels]->samples.voltage.count; ++realPosition) { switch(this->settings->scope.voltage[this->settings->scope.physicalChannels].misc) { case Dso::MATHMODE_1ADD2: this->analyzedData[this->settings->scope.physicalChannels]->samples.voltage.sample[realPosition] = this->analyzedData[0]->samples.voltage.sample[realPosition] + this->analyzedData[1]->samples.voltage.sample[realPosition]; @@ -170,11 +193,11 @@ void DataAnalyzer::run() { } else { // Clear unused channels - this->analyzedData[channel]->samples.voltage.count = 0; + channelData->samples.voltage.count = 0; this->analyzedData[this->settings->scope.physicalChannels]->samples.voltage.interval = 0; - if(this->analyzedData[channel]->samples.voltage.sample) { - delete[] this->analyzedData[channel]->samples.voltage.sample; - this->analyzedData[channel]->samples.voltage.sample = 0; + if(channelData->samples.voltage.sample) { + delete[] channelData->samples.voltage.sample; + channelData->samples.voltage.sample = 0; } } } @@ -186,12 +209,14 @@ void DataAnalyzer::run() { // Calculate frequencies, peak-to-peak voltages and spectrums - for(int channel = 0; channel < this->analyzedData.count(); channel++) { - if(this->analyzedData[channel]->samples.voltage.sample) { + for(int channel = 0; channel < this->analyzedData.count(); ++channel) { + AnalyzedData *channelData = this->analyzedData[channel]; + + if(channelData->samples.voltage.sample) { // Calculate new window - if(this->lastWindow != this->settings->scope.spectrumWindow || this->lastRecordLength != this->analyzedData[channel]->samples.voltage.count) { - if(this->lastRecordLength != this->analyzedData[channel]->samples.voltage.count) { - this->lastRecordLength = this->analyzedData[channel]->samples.voltage.count; + if(this->lastWindow != this->settings->scope.spectrumWindow || this->lastRecordLength != channelData->samples.voltage.count) { + if(this->lastRecordLength != channelData->samples.voltage.count) { + this->lastRecordLength = channelData->samples.voltage.count; if(this->window) fftw_free(this->window); @@ -203,19 +228,19 @@ void DataAnalyzer::run() { switch(this->settings->scope.spectrumWindow) { case Dso::WINDOW_HAMMING: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 0.54 - 0.46 * cos(2.0 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_HANN: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 0.5 * (1.0 - cos(2.0 * M_PI * windowPosition / windowEnd)); break; case Dso::WINDOW_COSINE: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = sin(M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_LANCZOS: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) { + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) { double sincParameter = (2.0 * windowPosition / windowEnd - 1.0) * M_PI; if(sincParameter == 0) *(this->window + windowPosition) = 1; @@ -224,82 +249,82 @@ void DataAnalyzer::run() { } break; case Dso::WINDOW_BARTLETT: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 2.0 / windowEnd * (windowEnd / 2 - abs(windowPosition - windowEnd / 2)); break; case Dso::WINDOW_TRIANGULAR: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 2.0 / this->lastRecordLength * (this->lastRecordLength / 2 - abs(windowPosition - windowEnd / 2)); break; case Dso::WINDOW_GAUSS: { double sigma = 0.4; - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = exp(-0.5 * pow(((windowPosition - windowEnd / 2) / (sigma * windowEnd / 2)), 2)); } break; case Dso::WINDOW_BARTLETTHANN: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 0.62 - 0.48 * abs(windowPosition / windowEnd - 0.5) - 0.38 * cos(2.0 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_BLACKMAN: { double alpha = 0.16; - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = (1 - alpha) / 2 - 0.5 * cos(2.0 * M_PI * windowPosition / windowEnd) + alpha / 2 * cos(4.0 * M_PI * windowPosition / windowEnd); } break; //case WINDOW_KAISER: // TODO //double alpha = 3.0; - //for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + //for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) //*(this->window + windowPosition) = ; //break; case Dso::WINDOW_NUTTALL: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 0.355768 - 0.487396 * cos(2 * M_PI * windowPosition / windowEnd) + 0.144232 * cos(4 * M_PI * windowPosition / windowEnd) - 0.012604 * cos(6 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_BLACKMANHARRIS: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 0.35875 - 0.48829 * cos(2 * M_PI * windowPosition / windowEnd) + 0.14128 * cos(4 * M_PI * windowPosition / windowEnd) - 0.01168 * cos(6 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_BLACKMANNUTTALL: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 0.3635819 - 0.4891775 * cos(2 * M_PI * windowPosition / windowEnd) + 0.1365995 * cos(4 * M_PI * windowPosition / windowEnd) - 0.0106411 * cos(6 * M_PI * windowPosition / windowEnd); break; case Dso::WINDOW_FLATTOP: - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 1.0 - 1.93 * cos(2 * M_PI * windowPosition / windowEnd) + 1.29 * cos(4 * M_PI * windowPosition / windowEnd) - 0.388 * cos(6 * M_PI * windowPosition / windowEnd) + 0.032 * cos(8 * M_PI * windowPosition / windowEnd); break; default: // Dso::WINDOW_RECTANGULAR - for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; windowPosition++) + for(unsigned int windowPosition = 0; windowPosition < this->lastRecordLength; ++windowPosition) *(this->window + windowPosition) = 1.0; } } // Set sampling interval - this->analyzedData[channel]->samples.spectrum.interval = 1.0 / this->analyzedData[channel]->samples.voltage.interval / this->analyzedData[channel]->samples.voltage.count; + channelData->samples.spectrum.interval = 1.0 / channelData->samples.voltage.interval / channelData->samples.voltage.count; // Number of real/complex samples - unsigned int dftLength = this->analyzedData[channel]->samples.voltage.count / 2; + unsigned int dftLength = channelData->samples.voltage.count / 2; // Reallocate memory for samples if the sample count has changed - if(this->analyzedData[channel]->samples.spectrum.count != dftLength) { - this->analyzedData[channel]->samples.spectrum.count = dftLength; - if(this->analyzedData[channel]->samples.spectrum.sample) - delete[] this->analyzedData[channel]->samples.spectrum.sample; - this->analyzedData[channel]->samples.spectrum.sample = new double[this->analyzedData[channel]->samples.voltage.count]; + if(channelData->samples.spectrum.count != dftLength) { + channelData->samples.spectrum.count = dftLength; + if(channelData->samples.spectrum.sample) + delete[] channelData->samples.spectrum.sample; + channelData->samples.spectrum.sample = new double[channelData->samples.voltage.count]; } // Create sample buffer and apply window - double *windowedValues = new double[this->analyzedData[channel]->samples.voltage.count]; - for(unsigned int position = 0; position < this->analyzedData[channel]->samples.voltage.count; position++) - windowedValues[position] = this->window[position] * this->analyzedData[channel]->samples.voltage.sample[position]; + double *windowedValues = new double[channelData->samples.voltage.count]; + for(unsigned int position = 0; position < channelData->samples.voltage.count; ++position) + windowedValues[position] = this->window[position] * channelData->samples.voltage.sample[position]; // Do discrete real to half-complex transformation /// \todo Check if record length is multiple of 2 /// \todo Reuse plan and use FFTW_MEASURE to get fastest algorithm - fftw_plan fftPlan = fftw_plan_r2r_1d(this->analyzedData[channel]->samples.voltage.count, windowedValues, this->analyzedData[channel]->samples.spectrum.sample, FFTW_R2HC, FFTW_ESTIMATE); + fftw_plan fftPlan = fftw_plan_r2r_1d(channelData->samples.voltage.count, windowedValues, channelData->samples.spectrum.sample, FFTW_R2HC, FFTW_ESTIMATE); fftw_execute(fftPlan); fftw_destroy_plan(fftPlan); @@ -309,40 +334,40 @@ void DataAnalyzer::run() { // Real values unsigned int position; double correctionFactor = 1.0 / dftLength / dftLength; - conjugateComplex[0] = (this->analyzedData[channel]->samples.spectrum.sample[0] * this->analyzedData[channel]->samples.spectrum.sample[0]) * correctionFactor; - for(position = 1; position < dftLength; position++) - conjugateComplex[position] = (this->analyzedData[channel]->samples.spectrum.sample[position] * this->analyzedData[channel]->samples.spectrum.sample[position] + this->analyzedData[channel]->samples.spectrum.sample[this->analyzedData[channel]->samples.voltage.count - position] * this->analyzedData[channel]->samples.spectrum.sample[this->analyzedData[channel]->samples.voltage.count - position]) * correctionFactor; + conjugateComplex[0] = (channelData->samples.spectrum.sample[0] * channelData->samples.spectrum.sample[0]) * correctionFactor; + for(position = 1; position < dftLength; ++position) + conjugateComplex[position] = (channelData->samples.spectrum.sample[position] * channelData->samples.spectrum.sample[position] + channelData->samples.spectrum.sample[channelData->samples.voltage.count - position] * channelData->samples.spectrum.sample[channelData->samples.voltage.count - position]) * correctionFactor; // Complex values, all zero for autocorrelation - conjugateComplex[dftLength] = (this->analyzedData[channel]->samples.spectrum.sample[dftLength] * this->analyzedData[channel]->samples.spectrum.sample[dftLength]) * correctionFactor; - for(position++; position < this->analyzedData[channel]->samples.voltage.count; position++) + conjugateComplex[dftLength] = (channelData->samples.spectrum.sample[dftLength] * channelData->samples.spectrum.sample[dftLength]) * correctionFactor; + for(++position; position < channelData->samples.voltage.count; ++position) conjugateComplex[position] = 0; // Do half-complex to real inverse transformation - double *correlation = new double[this->analyzedData[channel]->samples.voltage.count]; - fftPlan = fftw_plan_r2r_1d(this->analyzedData[channel]->samples.voltage.count, conjugateComplex, correlation, FFTW_HC2R, FFTW_ESTIMATE); + double *correlation = new double[channelData->samples.voltage.count]; + fftPlan = fftw_plan_r2r_1d(channelData->samples.voltage.count, conjugateComplex, correlation, FFTW_HC2R, FFTW_ESTIMATE); fftw_execute(fftPlan); fftw_destroy_plan(fftPlan); delete[] conjugateComplex; // Calculate peak-to-peak voltage double minimalVoltage, maximalVoltage; - minimalVoltage = maximalVoltage = this->analyzedData[channel]->samples.voltage.sample[0]; + minimalVoltage = maximalVoltage = channelData->samples.voltage.sample[0]; - for(unsigned int position = 1; position < this->analyzedData[channel]->samples.voltage.count; position++) { - if(this->analyzedData[channel]->samples.voltage.sample[position] < minimalVoltage) - minimalVoltage = this->analyzedData[channel]->samples.voltage.sample[position]; - else if(this->analyzedData[channel]->samples.voltage.sample[position] > maximalVoltage) - maximalVoltage = this->analyzedData[channel]->samples.voltage.sample[position]; + for(unsigned int position = 1; position < channelData->samples.voltage.count; ++position) { + if(channelData->samples.voltage.sample[position] < minimalVoltage) + minimalVoltage = channelData->samples.voltage.sample[position]; + else if(channelData->samples.voltage.sample[position] > maximalVoltage) + maximalVoltage = channelData->samples.voltage.sample[position]; } - this->analyzedData[channel]->amplitude = maximalVoltage - minimalVoltage; + channelData->amplitude = maximalVoltage - minimalVoltage; // Get the frequency from the correlation results double minimumCorrelation = correlation[0]; double peakCorrelation = 0; unsigned int peakPosition = 0; - for(unsigned int position = 1; position < this->analyzedData[channel]->samples.voltage.count / 2; position++) { + for(unsigned int position = 1; position < channelData->samples.voltage.count / 2; ++position) { if(correlation[position] > peakCorrelation && correlation[position] > minimumCorrelation * 2) { peakCorrelation = correlation[position]; peakPosition = position; @@ -354,30 +379,30 @@ void DataAnalyzer::run() { // Calculate the frequency in Hz if(peakPosition) - this->analyzedData[channel]->frequency = 1.0 / (this->analyzedData[channel]->samples.voltage.interval * peakPosition); + channelData->frequency = 1.0 / (channelData->samples.voltage.interval * peakPosition); else - this->analyzedData[channel]->frequency = 0; + channelData->frequency = 0; // Finally calculate the real spectrum if we want it if(this->settings->scope.spectrum[channel].used) { // Convert values into dB (Relative to the reference level) double offset = 60 - this->settings->scope.spectrumReference - 20 * log10(dftLength); double offsetLimit = this->settings->scope.spectrumLimit - this->settings->scope.spectrumReference; - for(unsigned int position = 0; position < this->analyzedData[channel]->samples.spectrum.count; position++) { - this->analyzedData[channel]->samples.spectrum.sample[position] = 20 * log10(fabs(this->analyzedData[channel]->samples.spectrum.sample[position])) + offset; + for(unsigned int position = 0; position < channelData->samples.spectrum.count; ++position) { + channelData->samples.spectrum.sample[position] = 20 * log10(fabs(channelData->samples.spectrum.sample[position])) + offset; // Check if this value has to be limited - if(offsetLimit > this->analyzedData[channel]->samples.spectrum.sample[position]) - this->analyzedData[channel]->samples.spectrum.sample[position] = offsetLimit; + if(offsetLimit > channelData->samples.spectrum.sample[position]) + channelData->samples.spectrum.sample[position] = offsetLimit; } } } - else if(this->analyzedData[channel]->samples.spectrum.sample) { + else if(channelData->samples.spectrum.sample) { // Clear unused channels - this->analyzedData[channel]->samples.spectrum.count = 0; - this->analyzedData[channel]->samples.spectrum.interval = 0; - delete[] this->analyzedData[channel]->samples.spectrum.sample; - this->analyzedData[channel]->samples.spectrum.sample = 0; + channelData->samples.spectrum.count = 0; + channelData->samples.spectrum.interval = 0; + delete[] channelData->samples.spectrum.sample; + channelData->samples.spectrum.sample = 0; } } diff --git a/openhantek/src/dockwindows.cpp b/openhantek/src/dockwindows.cpp index dc8057e..62b48b6 100644 --- a/openhantek/src/dockwindows.cpp +++ b/openhantek/src/dockwindows.cpp @@ -50,13 +50,13 @@ HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent, Qt::Windo << 1e-3 << 2e-3 << 4e-3 << 1e-2 << 2e-2 << 4e-2 << 1e-1 << 2e-1 << 4e-1 << 1e0 << 2e0 << 4e0 << 1e1 << 2e1 << 4e1 << 6e1 << 12e1 << 24e1 << 6e2 << 12e2 << 24e2 << 36e2; ///< Timebase steps in seconds/div - for(QList::iterator timebase = this->timebaseSteps.begin(); timebase != this->timebaseSteps.end(); timebase++) + for(QList::iterator timebase = this->timebaseSteps.begin(); timebase != this->timebaseSteps.end(); ++timebase) this->timebaseStrings << Helper::valueToString(*timebase, Helper::UNIT_SECONDS, 0); this->frequencybaseSteps << 1.0 << 2.0 << 5.0 << 1e1 << 2e1 << 5e1 << 1e2 << 2e2 << 5e2 << 1e3 << 2e3 << 5e3 << 1e4 << 2e4 << 4e4 << 1e5 << 2e5 << 5e5 << 1e6 << 2e6 << 5e6 << 1e7; ///< Frequencybase steps in Hz/div - for(QList::iterator frequencybase = this->frequencybaseSteps.begin(); frequencybase != this->frequencybaseSteps.end(); frequencybase++) + for(QList::iterator frequencybase = this->frequencybaseSteps.begin(); frequencybase != this->frequencybaseSteps.end(); ++frequencybase) this->frequencybaseStrings << Helper::valueToString(*frequencybase, Helper::UNIT_HERTZ, 0); // Initialize elements @@ -70,7 +70,7 @@ HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent, Qt::Windo this->formatLabel = new QLabel(tr("Format")); this->formatComboBox = new QComboBox(); - for(int format = Dso::GRAPHFORMAT_TY; format < Dso::GRAPHFORMAT_COUNT; format++) + for(int format = Dso::GRAPHFORMAT_TY; format < Dso::GRAPHFORMAT_COUNT; ++format) this->formatComboBox->addItem(Dso::graphFormatString((Dso::GraphFormat) format)); this->dockLayout = new QGridLayout(); @@ -181,19 +181,19 @@ TriggerDock::TriggerDock(DsoSettings *settings, const QStringList *specialTrigge this->settings = settings; // Initialize lists for comboboxes - for(unsigned int channel = 0; channel < this->settings->scope.physicalChannels; channel++) + for(unsigned int channel = 0; channel < this->settings->scope.physicalChannels; ++channel) this->sourceStandardStrings << tr("CH%1").arg(channel + 1); this->sourceSpecialStrings << *specialTriggers; // Initialize elements this->modeLabel = new QLabel(tr("Mode")); this->modeComboBox = new QComboBox(); - for(int mode = Dso::TRIGGERMODE_AUTO; mode < Dso::TRIGGERMODE_COUNT; mode++) + for(int mode = Dso::TRIGGERMODE_AUTO; mode < Dso::TRIGGERMODE_COUNT; ++mode) this->modeComboBox->addItem(Dso::triggerModeString((Dso::TriggerMode) mode)); this->slopeLabel = new QLabel(tr("Slope")); this->slopeComboBox = new QComboBox(); - for(int slope = Dso::SLOPE_POSITIVE; slope < Dso::SLOPE_COUNT; slope++) + for(int slope = Dso::SLOPE_POSITIVE; slope < Dso::SLOPE_COUNT; ++slope) this->slopeComboBox->addItem(Dso::slopeString((Dso::Slope) slope)); this->sourceLabel = new QLabel(tr("Source")); @@ -323,11 +323,11 @@ SpectrumDock::SpectrumDock(DsoSettings *settings, QWidget *parent, Qt::WindowFla // Initialize lists for comboboxes this->magnitudeSteps << 1e0 << 2e0 << 3e0 << 6e0 << 1e1 << 2e1 << 3e1 << 6e1 << 1e2 << 2e2 << 3e2 << 6e2; ///< Magnitude steps in dB/div - for(QList::iterator magnitude = this->magnitudeSteps.begin(); magnitude != this->magnitudeSteps.end(); magnitude++) + for(QList::iterator magnitude = this->magnitudeSteps.begin(); magnitude != this->magnitudeSteps.end(); ++magnitude) this->magnitudeStrings << Helper::valueToString(*magnitude, Helper::UNIT_DECIBEL, 0); // Initialize elements - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->magnitudeComboBox.append(new QComboBox()); this->magnitudeComboBox[channel]->addItems(this->magnitudeStrings); @@ -337,7 +337,7 @@ SpectrumDock::SpectrumDock(DsoSettings *settings, QWidget *parent, Qt::WindowFla this->dockLayout = new QGridLayout(); this->dockLayout->setColumnMinimumWidth(0, 64); this->dockLayout->setColumnStretch(1, 1); - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->dockLayout->addWidget(this->usedCheckBox[channel], channel, 0); this->dockLayout->addWidget(this->magnitudeComboBox[channel], channel, 1); } @@ -349,13 +349,13 @@ SpectrumDock::SpectrumDock(DsoSettings *settings, QWidget *parent, Qt::WindowFla this->setWidget(this->dockWidget); // Connect signals and slots - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { connect(this->magnitudeComboBox[channel], SIGNAL(currentIndexChanged(int)), this, SLOT(magnitudeSelected(int))); connect(this->usedCheckBox[channel], SIGNAL(toggled(bool)), this, SLOT(usedSwitched(bool))); } // Set values - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->setMagnitude(channel, this->settings->scope.spectrum[channel].magnitude); this->setUsed(channel, this->settings->scope.spectrum[channel].used); } @@ -407,7 +407,7 @@ void SpectrumDock::magnitudeSelected(int index) { int channel; // Which combobox was it? - for(channel = 0; channel < this->settings->scope.voltage.count(); channel++) + for(channel = 0; channel < this->settings->scope.voltage.count(); ++channel) if(this->sender() == this->magnitudeComboBox[channel]) break; @@ -424,7 +424,7 @@ void SpectrumDock::usedSwitched(bool checked) { int channel; // Which checkbox was it? - for(channel = 0; channel < this->settings->scope.voltage.count(); channel++) + for(channel = 0; channel < this->settings->scope.voltage.count(); ++channel) if(this->sender() == this->usedCheckBox[channel]) break; @@ -446,19 +446,19 @@ VoltageDock::VoltageDock(DsoSettings *settings, QWidget *parent, Qt::WindowFlags this->settings = settings; // Initialize lists for comboboxes - for(int coupling = Dso::COUPLING_AC; coupling < Dso::COUPLING_COUNT; coupling++) + for(int coupling = Dso::COUPLING_AC; coupling < Dso::COUPLING_COUNT; ++coupling) this->couplingStrings.append(Dso::couplingString((Dso::Coupling) coupling)); - for(int mode = Dso::MATHMODE_1ADD2; mode < Dso::MATHMODE_COUNT; mode++) + for(int mode = Dso::MATHMODE_1ADD2; mode < Dso::MATHMODE_COUNT; ++mode) this->modeStrings.append(Dso::mathModeString((Dso::MathMode) mode)); this->gainSteps << 1e-2 << 2e-2 << 5e-2 << 1e-1 << 2e-1 << 5e-1 << 1e0 << 2e0 << 5e0; ///< Voltage steps in V/div - for(QList::iterator gain = this->gainSteps.begin(); gain != this->gainSteps.end(); gain++) + for(QList::iterator gain = this->gainSteps.begin(); gain != this->gainSteps.end(); ++gain) this->gainStrings << Helper::valueToString(*gain, Helper::UNIT_VOLTS, 0); // Initialize elements - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->miscComboBox.append(new QComboBox()); if(channel < (int) this->settings->scope.physicalChannels) this->miscComboBox[channel]->addItems(this->couplingStrings); @@ -474,7 +474,7 @@ VoltageDock::VoltageDock(DsoSettings *settings, QWidget *parent, Qt::WindowFlags this->dockLayout = new QGridLayout(); this->dockLayout->setColumnMinimumWidth(0, 64); this->dockLayout->setColumnStretch(1, 1); - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->dockLayout->addWidget(this->usedCheckBox[channel], channel * 2, 0); this->dockLayout->addWidget(this->gainComboBox[channel], channel * 2, 1); this->dockLayout->addWidget(this->miscComboBox[channel], channel * 2 + 1, 1); @@ -487,14 +487,14 @@ VoltageDock::VoltageDock(DsoSettings *settings, QWidget *parent, Qt::WindowFlags this->setWidget(this->dockWidget); // Connect signals and slots - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { connect(this->gainComboBox[channel], SIGNAL(currentIndexChanged(int)), this, SLOT(gainSelected(int))); connect(this->miscComboBox[channel], SIGNAL(currentIndexChanged(int)), this, SLOT(miscSelected(int))); connect(this->usedCheckBox[channel], SIGNAL(toggled(bool)), this, SLOT(usedSwitched(bool))); } // Set values - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { if(channel < (int) this->settings->scope.physicalChannels) this->setCoupling(channel, (Dso::Coupling) this->settings->scope.voltage[channel].misc); else @@ -576,7 +576,7 @@ void VoltageDock::gainSelected(int index) { int channel; // Which combobox was it? - for(channel = 0; channel < this->settings->scope.voltage.count(); channel++) + for(channel = 0; channel < this->settings->scope.voltage.count(); ++channel) if(this->sender() == this->gainComboBox[channel]) break; @@ -594,7 +594,7 @@ void VoltageDock::miscSelected(int index) { int channel; // Which combobox was it? - for(channel = 0; channel < this->settings->scope.voltage.count(); channel++) + for(channel = 0; channel < this->settings->scope.voltage.count(); ++channel) if(this->sender() == this->miscComboBox[channel]) break; @@ -614,7 +614,7 @@ void VoltageDock::usedSwitched(bool checked) { int channel; // Which checkbox was it? - for(channel = 0; channel < this->settings->scope.voltage.count(); channel++) + for(channel = 0; channel < this->settings->scope.voltage.count(); ++channel) if(this->sender() == this->usedCheckBox[channel]) break; diff --git a/openhantek/src/dsowidget.cpp b/openhantek/src/dsowidget.cpp index 5c7127a..46d7dcf 100644 --- a/openhantek/src/dsowidget.cpp +++ b/openhantek/src/dsowidget.cpp @@ -66,7 +66,7 @@ DsoWidget::DsoWidget(DsoSettings *settings, DataAnalyzer *dataAnalyzer, QWidget // The offset sliders for all possible channels this->offsetSlider = new LevelSlider(Qt::RightArrow); - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->offsetSlider->addSlider(this->settings->scope.voltage[channel].name, channel); this->offsetSlider->setColor(channel, this->settings->view.color.screen.voltage[channel]); this->offsetSlider->setLimits(channel, -DIVS_VOLTAGE / 2, DIVS_VOLTAGE / 2); @@ -74,7 +74,7 @@ DsoWidget::DsoWidget(DsoSettings *settings, DataAnalyzer *dataAnalyzer, QWidget this->offsetSlider->setValue(channel, this->settings->scope.voltage[channel].offset); this->offsetSlider->setVisible(channel, this->settings->scope.voltage[channel].used); } - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { this->offsetSlider->addSlider(this->settings->scope.spectrum[channel].name, this->settings->scope.voltage.count() + channel); this->offsetSlider->setColor(this->settings->scope.voltage.count() + channel, this->settings->view.color.screen.spectrum[channel]); this->offsetSlider->setLimits(this->settings->scope.voltage.count() + channel, -DIVS_VOLTAGE / 2, DIVS_VOLTAGE / 2); @@ -93,7 +93,7 @@ DsoWidget::DsoWidget(DsoSettings *settings, DataAnalyzer *dataAnalyzer, QWidget // The sliders for the trigger levels this->triggerLevelSlider = new LevelSlider(Qt::LeftArrow); - for(int channel = 0; channel < (int) this->settings->scope.physicalChannels; channel++) { + for(int channel = 0; channel < (int) this->settings->scope.physicalChannels; ++channel) { this->triggerLevelSlider->addSlider(channel); this->triggerLevelSlider->setColor(channel, (!this->settings->scope.trigger.special && channel == (int) this->settings->scope.trigger.source) ? this->settings->view.color.screen.voltage[channel] : this->settings->view.color.screen.voltage[channel].darker()); this->adaptTriggerLevelSlider(channel); @@ -103,7 +103,7 @@ DsoWidget::DsoWidget(DsoSettings *settings, DataAnalyzer *dataAnalyzer, QWidget // The marker slider this->markerSlider = new LevelSlider(Qt::UpArrow); - for(int marker = 0; marker < MARKER_COUNT; marker++) { + for(int marker = 0; marker < MARKER_COUNT; ++marker) { this->markerSlider->addSlider(QString::number(marker + 1), marker); this->markerSlider->setLimits(marker, -DIVS_TIME / 2, DIVS_TIME / 2); this->markerSlider->setStep(marker, 0.2); @@ -165,7 +165,7 @@ DsoWidget::DsoWidget(DsoSettings *settings, DataAnalyzer *dataAnalyzer, QWidget this->measurementLayout->setColumnStretch(3, 2); this->measurementLayout->setColumnStretch(4, 3); this->measurementLayout->setColumnStretch(5, 3); - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { tablePalette.setColor(QPalette::WindowText, this->settings->view.color.screen.voltage[channel]); this->measurementNameLabel.append(new QLabel(this->settings->scope.voltage[channel].name)); this->measurementNameLabel[channel]->setPalette(tablePalette); @@ -378,7 +378,7 @@ void DsoWidget::updateTriggerSource() { else this->triggerPositionSlider->setColor(0, this->settings->view.color.screen.voltage[this->settings->scope.trigger.source]); - for(int channel = 0; channel < (int) this->settings->scope.physicalChannels; channel++) + for(int channel = 0; channel < (int) this->settings->scope.physicalChannels; ++channel) this->triggerLevelSlider->setColor(channel, (!this->settings->scope.trigger.special && channel == (int) this->settings->scope.trigger.source) ? this->settings->view.color.screen.voltage[channel] : this->settings->view.color.screen.voltage[channel].darker()); this->updateTriggerDetails(); @@ -439,13 +439,13 @@ bool DsoWidget::exportAs() { << tr("Image (*.png *.xpm *.jpg)") << tr("Comma-Separated Values (*.csv)"); - QFileDialog fileDialog((QWidget *) this->parent(), tr("Export file..."), QString(), filters.join(";;")); + QFileDialog fileDialog(static_cast(this->parent()), tr("Export file..."), QString(), filters.join(";;")); fileDialog.setFileMode(QFileDialog::AnyFile); fileDialog.setAcceptMode(QFileDialog::AcceptSave); if(fileDialog.exec() != QDialog::Accepted) return false; - Exporter exporter(this->settings, this->dataAnalyzer, (QWidget *) this->parent()); + Exporter exporter(this->settings, this->dataAnalyzer, static_cast(this->parent())); exporter.setFilename(fileDialog.selectedFiles().first()); exporter.setFormat((ExportFormat) (EXPORT_FORMAT_PDF + filters.indexOf(fileDialog.selectedFilter()))); @@ -455,7 +455,7 @@ bool DsoWidget::exportAs() { /// \brief Print the oscilloscope screen. /// \return true if the document was sent to the printer successfully. bool DsoWidget::print() { - Exporter exporter(this->settings, this->dataAnalyzer, (QWidget *) this->parent()); + Exporter exporter(this->settings, this->dataAnalyzer, static_cast(this->parent())); exporter.setFormat(EXPORT_FORMAT_PRINTER); return exporter.doExport(); @@ -481,7 +481,7 @@ void DsoWidget::updateZoom(bool enabled) { /// \brief Prints analyzed data. void DsoWidget::dataAnalyzed() { - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { if(this->settings->scope.voltage[channel].used && this->dataAnalyzer->data(channel)) { // Amplitude string representation (4 significant digits) this->measurementAmplitudeLabel[channel]->setText(Helper::valueToString(this->dataAnalyzer->data(channel)->amplitude, Helper::UNIT_VOLTS, 4)); diff --git a/openhantek/src/exporter.cpp b/openhantek/src/exporter.cpp index 8aa9663..bc2ffca 100644 --- a/openhantek/src/exporter.cpp +++ b/openhantek/src/exporter.cpp @@ -84,26 +84,28 @@ bool Exporter::doExport() { if(this->format < EXPORT_FORMAT_IMAGE) { // We need a QPrinter for printing, pdf- and ps-export paintDevice = new QPrinter(QPrinter::HighResolution); - ((QPrinter *) paintDevice)->setOrientation(this->settings->view.zoom ? QPrinter::Portrait : QPrinter::Landscape); - ((QPrinter *) paintDevice)->setPageMargins(20, 20, 20, 20, QPrinter::Millimeter); + static_cast(paintDevice)->setOrientation(this->settings->view.zoom ? QPrinter::Portrait : QPrinter::Landscape); + static_cast(paintDevice)->setPageMargins(20, 20, 20, 20, QPrinter::Millimeter); if(this->format == EXPORT_FORMAT_PRINTER) { // Show the printing dialog - QPrintDialog *dialog = new QPrintDialog((QPrinter *) paintDevice, (QWidget *) this->parent()); - dialog->setWindowTitle(tr("Print oscillograph")); - if(dialog->exec() != QDialog::Accepted) + QPrintDialog dialog(static_cast(paintDevice), static_cast(this->parent())); + dialog.setWindowTitle(tr("Print oscillograph")); + if(dialog.exec() != QDialog::Accepted) { + delete paintDevice; return false; + } } else { // Configure the QPrinter - ((QPrinter *) paintDevice)->setOutputFileName(this->filename); - ((QPrinter *) paintDevice)->setOutputFormat((this->format == EXPORT_FORMAT_PDF) ? QPrinter::PdfFormat : QPrinter::PostScriptFormat); + static_cast(paintDevice)->setOutputFileName(this->filename); + static_cast(paintDevice)->setOutputFormat((this->format == EXPORT_FORMAT_PDF) ? QPrinter::PdfFormat : QPrinter::PostScriptFormat); } } else { // We need a QPixmap for image-export paintDevice = new QPixmap(this->settings->options.imageSize); - ((QPixmap *) paintDevice)->fill(colorValues->background); + static_cast(paintDevice)->fill(colorValues->background); } // Create a painter for our device @@ -142,7 +144,7 @@ bool Exporter::doExport() { int channelCount = 0; for(int channel = this->settings->scope.voltage.count() - 1; channel >= 0; channel--) { if((this->settings->scope.voltage[channel].used || this->settings->scope.spectrum[channel].used) && this->dataAnalyzer->data(channel)) { - channelCount++; + ++channelCount; double top = (double) paintDevice->height() - channelCount * lineHeight; // Print label @@ -208,11 +210,11 @@ bool Exporter::doExport() { painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(Qt::NoBrush); - for(int zoomed = 0; zoomed < (this->settings->view.zoom ? 2 : 1); zoomed++) { + for(int zoomed = 0; zoomed < (this->settings->view.zoom ? 2 : 1); ++zoomed) { switch(this->settings->scope.horizontal.format) { case Dso::GRAPHFORMAT_TY: // Add graphs for channels - for(int channel = 0 ; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0 ; channel < this->settings->scope.voltage.count(); ++channel) { if(this->settings->scope.voltage[channel].used && this->dataAnalyzer->data(channel)) { painter.setPen(colorValues->voltage[channel]); @@ -233,14 +235,17 @@ bool Exporter::doExport() { // Draw graph QPointF *graph = new QPointF[lastPosition - firstPosition + 1]; - for(unsigned int position = firstPosition; position <= lastPosition; position++) + + for(unsigned int position = firstPosition; position <= lastPosition; ++position) graph[position - firstPosition] = QPointF(position * horizontalFactor - DIVS_TIME / 2, this->dataAnalyzer->data(channel)->samples.voltage.sample[position] / this->settings->scope.voltage[channel].gain + this->settings->scope.voltage[channel].offset); + painter.drawPolyline(graph, lastPosition - firstPosition + 1); + delete[] graph; } } // Add spectrum graphs - for (int channel = 0; channel < this->settings->scope.spectrum.count(); channel++) { + for (int channel = 0; channel < this->settings->scope.spectrum.count(); ++channel) { if(this->settings->scope.spectrum[channel].used && this->dataAnalyzer->data(channel)) { painter.setPen(colorValues->spectrum[channel]); @@ -261,9 +266,12 @@ bool Exporter::doExport() { // Draw graph QPointF *graph = new QPointF[lastPosition - firstPosition + 1]; - for(unsigned int position = firstPosition; position <= lastPosition; position++) + + for(unsigned int position = firstPosition; position <= lastPosition; ++position) graph[position - firstPosition] = QPointF(position * horizontalFactor - DIVS_TIME / 2, this->dataAnalyzer->data(channel)->samples.spectrum.sample[position] / this->settings->scope.spectrum[channel].magnitude + this->settings->scope.spectrum[channel].offset); + painter.drawPolyline(graph, lastPosition - firstPosition + 1); + delete[] graph; } } break; @@ -283,7 +291,7 @@ bool Exporter::doExport() { // Draw grids painter.setRenderHint(QPainter::Antialiasing, false); - for(int zoomed = 0; zoomed < (this->settings->view.zoom ? 2 : 1); zoomed++) { + for(int zoomed = 0; zoomed < (this->settings->view.zoom ? 2 : 1); ++zoomed) { // Set DIVS_TIME x DIVS_VOLTAGE matrix for oscillograph painter.setMatrix(QMatrix((paintDevice->width() - 1) / DIVS_TIME, 0, 0, -(scopeHeight - 1) / DIVS_VOLTAGE, (double) (paintDevice->width() - 1) / 2, (scopeHeight - 1) * (zoomed + 0.5) + lineHeight * 1.5 + lineHeight * 2.5 * zoomed), false); @@ -292,8 +300,8 @@ bool Exporter::doExport() { if(this->format < EXPORT_FORMAT_IMAGE) { // Draw vertical lines - for(int div = 1; div < DIVS_TIME / 2; div++) { - for(int dot = 1; dot < DIVS_VOLTAGE / 2 * 5; dot++) { + for(int div = 1; div < DIVS_TIME / 2; ++div) { + for(int dot = 1; dot < DIVS_VOLTAGE / 2 * 5; ++dot) { painter.drawLine(QPointF((double) -div - 0.02, (double) -dot / 5), QPointF((double) -div + 0.02, (double) -dot / 5)); painter.drawLine(QPointF((double) -div - 0.02, (double) dot / 5), QPointF((double) -div + 0.02, (double) dot / 5)); painter.drawLine(QPointF((double) div - 0.02, (double) -dot / 5), QPointF((double) div + 0.02, (double) -dot / 5)); @@ -301,8 +309,8 @@ bool Exporter::doExport() { } } // Draw horizontal lines - for(int div = 1; div < DIVS_VOLTAGE / 2; div++) { - for(int dot = 1; dot < DIVS_TIME / 2 * 5; dot++) { + for(int div = 1; div < DIVS_VOLTAGE / 2; ++div) { + for(int dot = 1; dot < DIVS_TIME / 2 * 5; ++dot) { painter.drawLine(QPointF((double) -dot / 5, (double) -div - 0.02), QPointF((double) -dot / 5, (double) -div + 0.02)); painter.drawLine(QPointF((double) dot / 5, (double) -div - 0.02), QPointF((double) dot / 5, (double) -div + 0.02)); painter.drawLine(QPointF((double) -dot / 5, (double) div - 0.02), QPointF((double) -dot / 5, (double) div + 0.02)); @@ -312,8 +320,8 @@ bool Exporter::doExport() { } else { // Draw vertical lines - for(int div = 1; div < DIVS_TIME / 2; div++) { - for(int dot = 1; dot < DIVS_VOLTAGE / 2 * 5; dot++) { + for(int div = 1; div < DIVS_TIME / 2; ++div) { + for(int dot = 1; dot < DIVS_VOLTAGE / 2 * 5; ++dot) { painter.drawPoint(QPointF(-div, (double) -dot / 5)); painter.drawPoint(QPointF(-div, (double) dot / 5)); painter.drawPoint(QPointF(div, (double) -dot / 5)); @@ -321,8 +329,8 @@ bool Exporter::doExport() { } } // Draw horizontal lines - for(int div = 1; div < DIVS_VOLTAGE / 2; div++) { - for(int dot = 1; dot < DIVS_TIME / 2 * 5; dot++) { + for(int div = 1; div < DIVS_VOLTAGE / 2; ++div) { + for(int dot = 1; dot < DIVS_TIME / 2 * 5; ++dot) { if(dot % 5 == 0) continue; // Already done by vertical lines painter.drawPoint(QPointF((double) -dot / 5, -div)); @@ -354,7 +362,9 @@ bool Exporter::doExport() { painter.end(); if(this->format == EXPORT_FORMAT_IMAGE) - ((QPixmap *) paintDevice)->save(this->filename); + static_cast(paintDevice)->save(this->filename); + + delete paintDevice; return true; } @@ -365,14 +375,14 @@ bool Exporter::doExport() { QTextStream csvStream(&csvFile); - for(int channel = 0 ; channel < this->settings->scope.voltage.count(); channel++) { + for(int channel = 0 ; channel < this->settings->scope.voltage.count(); ++channel) { if(this->dataAnalyzer->data(channel)) { if(this->settings->scope.voltage[channel].used) { // Start with channel name and the sample interval csvStream << "\"" << this->settings->scope.voltage[channel].name << "\"," << this->dataAnalyzer->data(channel)->samples.voltage.interval; // And now all sample values in volts - for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; position++) + for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; ++position) csvStream << "," << this->dataAnalyzer->data(channel)->samples.voltage.sample[position]; // Finally a newline @@ -384,7 +394,7 @@ bool Exporter::doExport() { csvStream << "\"" << this->settings->scope.spectrum[channel].name << "\"," << this->dataAnalyzer->data(channel)->samples.spectrum.interval; // And now all magnitudes in dB - for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.spectrum.count; position++) + for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.spectrum.count; ++position) csvStream << "," << this->dataAnalyzer->data(channel)->samples.spectrum.sample[position]; // Finally a newline diff --git a/openhantek/src/glgenerator.cpp b/openhantek/src/glgenerator.cpp index 1a76015..f02af00 100644 --- a/openhantek/src/glgenerator.cpp +++ b/openhantek/src/glgenerator.cpp @@ -104,10 +104,10 @@ void GlGenerator::generateGraphs() { return; // Adapt the number of graphs - for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; mode++) { - for(int channel = this->vaChannel[mode].count(); channel < this->settings->scope.voltage.count(); channel++) + for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; ++mode) { + for(int channel = this->vaChannel[mode].count(); channel < this->settings->scope.voltage.count(); ++channel) this->vaChannel[mode].append(QList()); - for(int channel = this->settings->scope.voltage.count(); channel < this->vaChannel[mode].count(); channel++) + for(int channel = this->settings->scope.voltage.count(); channel < this->vaChannel[mode].count(); ++channel) this->vaChannel[mode].removeLast(); } @@ -118,13 +118,13 @@ void GlGenerator::generateGraphs() { this->digitalPhosphorDepth = 1; // Handle all digital phosphor related list manipulations - for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; mode++) { - for(int channel = 0; channel < this->vaChannel[mode].count(); channel++) { + for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; ++mode) { + for(int channel = 0; channel < this->vaChannel[mode].count(); ++channel) { // Resize lists for vector array if the digital phosphor depth has changed if(this->vaChannel[mode][channel].count() != this->digitalPhosphorDepth) - for(int index = this->vaChannel[mode][channel].count(); index < this->digitalPhosphorDepth; index++) + for(int index = this->vaChannel[mode][channel].count(); index < this->digitalPhosphorDepth; ++index) this->vaChannel[mode][channel].append(new GlArray()); - for(int index = this->digitalPhosphorDepth; index < this->vaChannel[mode][channel].count(); index++) { + for(int index = this->digitalPhosphorDepth; index < this->vaChannel[mode][channel].count(); ++index) { delete this->vaChannel[mode][channel].last(); this->vaChannel[mode][channel].removeLast(); } @@ -139,13 +139,13 @@ void GlGenerator::generateGraphs() { switch(this->settings->scope.horizontal.format) { case Dso::GRAPHFORMAT_TY: // Add graphs for channels - for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; mode++) { - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; ++mode) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { // Check if this channel is used and available at the data analyzer if(((mode == Dso::CHANNELMODE_VOLTAGE) ? this->settings->scope.voltage[channel].used : this->settings->scope.spectrum[channel].used) && this->dataAnalyzer->data(channel) && this->dataAnalyzer->data(channel)->samples.voltage.sample) { // Check if the sample count has changed unsigned int neededSize = ((mode == Dso::CHANNELMODE_VOLTAGE) ? this->dataAnalyzer->data(channel)->samples.voltage.count : this->dataAnalyzer->data(channel)->samples.spectrum.count) * 2; - for(int index = 0; index < this->digitalPhosphorDepth; index++) { + for(int index = 0; index < this->digitalPhosphorDepth; ++index) { if(this->vaChannel[mode][channel][index]->getSize() != neededSize) this->vaChannel[mode][channel][index]->setSize(0); } @@ -166,13 +166,13 @@ void GlGenerator::generateGraphs() { // Fill vector array unsigned int arrayPosition = 0; if(mode == Dso::CHANNELMODE_VOLTAGE) { - for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; position++) { + for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; ++position) { vaNewChannel[arrayPosition++] = position * horizontalFactor - DIVS_TIME / 2; vaNewChannel[arrayPosition++] = this->dataAnalyzer->data(channel)->samples.voltage.sample[position] / this->settings->scope.voltage[channel].gain + this->settings->scope.voltage[channel].offset; } } else { - for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.spectrum.count; position++) { + for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.spectrum.count; ++position) { vaNewChannel[arrayPosition++] = position * horizontalFactor - DIVS_TIME / 2; vaNewChannel[arrayPosition++] = this->dataAnalyzer->data(channel)->samples.spectrum.sample[position] / this->settings->scope.spectrum[channel].magnitude + this->settings->scope.spectrum[channel].offset; } @@ -180,7 +180,7 @@ void GlGenerator::generateGraphs() { } else { // Delete all vector arrays - for(int index = 0; index < this->digitalPhosphorDepth; index++) + for(int index = 0; index < this->digitalPhosphorDepth; ++index) this->vaChannel[mode][channel][index]->setSize(0); } } @@ -188,12 +188,12 @@ void GlGenerator::generateGraphs() { break; case Dso::GRAPHFORMAT_XY: - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel ++) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { // For even channel numbers check if this channel is used and this and the following channel are available at the data analyzer if(channel % 2 == 0 && channel + 1 < this->settings->scope.voltage.count() && this->settings->scope.voltage[channel].used && this->dataAnalyzer->data(channel) && this->dataAnalyzer->data(channel)->samples.voltage.sample && this->dataAnalyzer->data(channel + 1) && this->dataAnalyzer->data(channel + 1)->samples.voltage.sample) { // Check if the sample count has changed unsigned int neededSize = qMin(this->dataAnalyzer->data(channel)->samples.voltage.count, this->dataAnalyzer->data(channel + 1)->samples.voltage.count) * 2; - for(int index = 0; index < this->digitalPhosphorDepth; index++) { + for(int index = 0; index < this->digitalPhosphorDepth; ++index) { if(this->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel][index]->getSize() != neededSize) this->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel][index]->setSize(0); } @@ -208,19 +208,19 @@ void GlGenerator::generateGraphs() { unsigned int arrayPosition = 0; unsigned int xChannel = channel; unsigned int yChannel = channel + 1; - for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; position++) { + for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; ++position) { vaNewChannel[arrayPosition++] = this->dataAnalyzer->data(xChannel)->samples.voltage.sample[position] / this->settings->scope.voltage[xChannel].gain + this->settings->scope.voltage[xChannel].offset; vaNewChannel[arrayPosition++] = this->dataAnalyzer->data(yChannel)->samples.voltage.sample[position] / this->settings->scope.voltage[yChannel].gain + this->settings->scope.voltage[yChannel].offset; } } else { // Delete all vector arrays - for(int index = 0; index < this->digitalPhosphorDepth; index++) + for(int index = 0; index < this->digitalPhosphorDepth; ++index) this->vaChannel[Dso::CHANNELMODE_VOLTAGE][channel][index]->setSize(0); } // Delete all spectrum graphs - for(int index = 0; index < this->digitalPhosphorDepth; index++) + for(int index = 0; index < this->digitalPhosphorDepth; ++index) this->vaChannel[Dso::CHANNELMODE_SPECTRUM][channel][index]->setSize(0); } break; @@ -240,8 +240,8 @@ void GlGenerator::generateGrid() { this->vaGrid[0].setSize(((DIVS_TIME * DIVS_SUB - 2) * (DIVS_VOLTAGE - 2) + (DIVS_VOLTAGE * DIVS_SUB - 2) * (DIVS_TIME - 2) - ((DIVS_TIME - 2) * (DIVS_VOLTAGE - 2))) * 2); int pointIndex = 0; // Draw vertical lines - for(int div = 1; div < DIVS_TIME / 2; div++) { - for(int dot = 1; dot < DIVS_VOLTAGE / 2 * DIVS_SUB; dot++) { + for(int div = 1; div < DIVS_TIME / 2; ++div) { + for(int dot = 1; dot < DIVS_VOLTAGE / 2 * DIVS_SUB; ++dot) { float dotPosition = (float) dot / DIVS_SUB; this->vaGrid[0].data[pointIndex++] = -div; this->vaGrid[0].data[pointIndex++] = -dotPosition; @@ -254,8 +254,8 @@ void GlGenerator::generateGrid() { } } // Draw horizontal lines - for(int div = 1; div < DIVS_VOLTAGE / 2; div++) { - for(int dot = 1; dot < DIVS_TIME / 2 * DIVS_SUB; dot++) { + for(int div = 1; div < DIVS_VOLTAGE / 2; ++div) { + for(int dot = 1; dot < DIVS_TIME / 2 * DIVS_SUB; ++dot) { if(dot % DIVS_SUB == 0) continue; // Already done by vertical lines float dotPosition = (float) dot / DIVS_SUB; @@ -284,7 +284,7 @@ void GlGenerator::generateGrid() { this->vaGrid[1].data[pointIndex++] = 0; this->vaGrid[1].data[pointIndex++] = DIVS_VOLTAGE / 2; // Subdiv lines on horizontal axis - for(int line = 1; line < DIVS_TIME / 2 * DIVS_SUB; line++) { + for(int line = 1; line < DIVS_TIME / 2 * DIVS_SUB; ++line) { float linePosition = (float) line / DIVS_SUB; this->vaGrid[1].data[pointIndex++] = linePosition; this->vaGrid[1].data[pointIndex++] = -0.05; @@ -296,7 +296,7 @@ void GlGenerator::generateGrid() { this->vaGrid[1].data[pointIndex++] = 0.05; } // Subdiv lines on vertical axis - for(int line = 1; line < DIVS_VOLTAGE / 2 * DIVS_SUB; line++) { + for(int line = 1; line < DIVS_VOLTAGE / 2 * DIVS_SUB; ++line) { float linePosition = (float) line / DIVS_SUB; this->vaGrid[1].data[pointIndex++] = -0.05; this->vaGrid[1].data[pointIndex++] = linePosition; diff --git a/openhantek/src/glscope.cpp b/openhantek/src/glscope.cpp index b5f6a88..adcabf7 100644 --- a/openhantek/src/glscope.cpp +++ b/openhantek/src/glscope.cpp @@ -96,14 +96,14 @@ void GlScope::paintGL() { double *fadingFactor = new double[this->generator->digitalPhosphorDepth]; fadingFactor[0] = 100; double fadingRatio = pow(10.0, 2.0 / this->generator->digitalPhosphorDepth); - for(int index = 1; index < this->generator->digitalPhosphorDepth; index++) + for(int index = 1; index < this->generator->digitalPhosphorDepth; ++index) fadingFactor[index] = fadingFactor[index - 1] * fadingRatio; switch(this->settings->scope.horizontal.format) { case Dso::GRAPHFORMAT_TY: // Real and virtual channels - for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; mode++) { - for(int channel = 0; channel < this->settings->scope.voltage.count(); channel++) { + for(int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; ++mode) { + for(int channel = 0; channel < this->settings->scope.voltage.count(); ++channel) { if((mode == Dso::CHANNELMODE_VOLTAGE) ? this->settings->scope.voltage[channel].used : this->settings->scope.spectrum[channel].used) { // Draw graph for all available depths for(int index = this->generator->digitalPhosphorDepth - 1; index >= 0; index--) { @@ -155,7 +155,7 @@ void GlScope::paintGL() { glEnable(GL_LINE_STIPPLE); this->qglColor(this->settings->view.color.screen.markers); - for(int marker = 0; marker < MARKER_COUNT; marker++) { + for(int marker = 0; marker < MARKER_COUNT; ++marker) { if(!this->vaMarker[marker].data) { this->vaMarker[marker].setSize(2 * 2); this->vaMarker[marker].data[1] = - DIVS_VOLTAGE; diff --git a/openhantek/src/hantek/control.cpp b/openhantek/src/hantek/control.cpp index bc0926a..ab5f9a1 100644 --- a/openhantek/src/hantek/control.cpp +++ b/openhantek/src/hantek/control.cpp @@ -58,21 +58,32 @@ namespace Hantek { this->specification.samplerate.multi.base = 100e6; this->specification.samplerate.multi.max = 100e6; - for(unsigned int channel = 0; channel < HANTEK_CHANNELS; channel++) { - for(unsigned int gainId = 0; gainId < 9; gainId++) { + for(unsigned int channel = 0; channel < HANTEK_CHANNELS; ++channel) { + for(unsigned int gainId = 0; gainId < 9; ++gainId) { this->specification.offsetLimit[channel][gainId][OFFSET_START] = 0x0000; this->specification.offsetLimit[channel][gainId][OFFSET_END] = 0xffff; } } // Set settings to default values - this->settings.recordLengthId = 0; this->settings.samplerate.limits = &(this->specification.samplerate.single); this->settings.samplerate.downsampling = 1; + this->settings.samplerate.current = 0.0; this->settings.trigger.position = 0; + this->settings.trigger.point = 0; + this->settings.trigger.mode = Dso::TRIGGERMODE_NORMAL; this->settings.trigger.slope = Dso::SLOPE_POSITIVE; this->settings.trigger.special = false; this->settings.trigger.source = 0; + for(unsigned int channel = 0; channel < HANTEK_CHANNELS; ++channel) { + this->settings.trigger.level[channel] = 0.0; + this->settings.voltage[channel].gain = 0; + this->settings.voltage[channel].offset = 0.0; + this->settings.voltage[channel].offsetReal = 0.0; + this->settings.voltage[channel].used = false; + } + this->settings.recordLengthId = 0; + this->settings.usedChannels = 0; // Special trigger sources this->specialTriggerSources << tr("EXT") << tr("EXT/10"); @@ -89,14 +100,14 @@ namespace Hantek { this->control[CONTROLINDEX_SETRELAYS] = new ControlSetRelays(); this->controlCode[CONTROLINDEX_SETRELAYS] = CONTROL_SETRELAYS; - for(int control = 0; control < CONTROLINDEX_COUNT; control++) + for(int control = 0; control < CONTROLINDEX_COUNT; ++control) this->controlPending[control] = false; // USB device this->device = new Device(this); // Sample buffers - for(unsigned int channel = 0; channel < HANTEK_CHANNELS; channel++) { + for(unsigned int channel = 0; channel < HANTEK_CHANNELS; ++channel) { this->samples.append(0); this->samplesSize.append(0); } @@ -132,7 +143,7 @@ namespace Hantek { while(captureState != LIBUSB_ERROR_NO_DEVICE && !this->terminate) { // Send all pending bulk commands - for(int command = 0; command < BULK_COUNT; command++) { + for(int command = 0; command < BULK_COUNT; ++command) { if(!this->commandPending[command]) continue; @@ -142,7 +153,7 @@ namespace Hantek { errorCode = this->device->bulkCommand(this->command[command]); if(errorCode < 0) { - qWarning("Sending bulk command 0x%02x failed: %s", command, Helper::libUsbErrorString(errorCode).toLocal8Bit().data()); + qWarning("Sending bulk command %02x failed: %s", command, Helper::libUsbErrorString(errorCode).toLocal8Bit().data()); if(errorCode == LIBUSB_ERROR_NO_DEVICE) { captureState = LIBUSB_ERROR_NO_DEVICE; @@ -156,17 +167,17 @@ namespace Hantek { break; // Send all pending control commands - for(int control = 0; control < CONTROLINDEX_COUNT; control++) { + for(int control = 0; control < CONTROLINDEX_COUNT; ++control) { if(!this->controlPending[control]) continue; #ifdef DEBUG - qDebug("Sending control command 0x%02x:%s", control, Helper::hexDump(this->control[control]->data(), this->control[control]->getSize()).toLocal8Bit().data()); + qDebug("Sending control command %02x:%s", this->controlCode[control], Helper::hexDump(this->control[control]->data(), this->control[control]->getSize()).toLocal8Bit().data()); #endif errorCode = this->device->controlWrite(this->controlCode[control], this->control[control]->data(), this->control[control]->getSize()); if(errorCode < 0) { - qWarning("Sending control command 0x%2x failed: %s", control, Helper::libUsbErrorString(errorCode).toLocal8Bit().data()); + qWarning("Sending control command %2x failed: %s", this->controlCode[control], Helper::libUsbErrorString(errorCode).toLocal8Bit().data()); if(errorCode == LIBUSB_ERROR_NO_DEVICE) { captureState = LIBUSB_ERROR_NO_DEVICE; @@ -181,7 +192,7 @@ namespace Hantek { // Check the current oscilloscope state everytime 25% of the time the buffer should be refilled // Not more often than every 10 ms though - int cycleTime = qMax((unsigned long int) (this->specification.recordLengths[this->settings.recordLengthId] / this->settings.samplerate.current * 250), (long unsigned int) 10); + int cycleTime = qMax((unsigned long int) (this->specification.recordLengths[this->settings.recordLengthId] / this->settings.samplerate.current * 250), 10lu); this->msleep(cycleTime); if(!this->sampling) { @@ -225,7 +236,7 @@ namespace Hantek { case CAPTURE_WAITING: if(samplingStarted && lastTriggerMode == this->settings.trigger.mode) { - cycleCounter++; + ++cycleCounter; if(cycleCounter == startCycle) { // Buffer refilled completely since start of sampling, enable the trigger now @@ -249,7 +260,7 @@ namespace Hantek { #endif } - if(cycleCounter < 50 || cycleCounter < 4000 / cycleTime) + if(cycleCounter < 20 || cycleCounter < 4000 / cycleTime) break; } @@ -356,7 +367,7 @@ namespace Hantek { } // Clear unused channels - for(int channelCounter = 0; channelCounter < HANTEK_CHANNELS; channelCounter++) + for(int channelCounter = 0; channelCounter < HANTEK_CHANNELS; ++channelCounter) if(channelCounter != channel && this->samples[channelCounter]) { delete this->samples[channelCounter]; @@ -380,7 +391,7 @@ namespace Hantek { unsigned int extraBitsSize = this->specification.sampleSize - 8; // Number of extra bits unsigned short int extraBitsMask = (0x00ff << extraBitsSize) & 0xff00; // Mask for extra bits extraction - for(unsigned int realPosition = 0; realPosition < dataCount; realPosition++, bufferPosition++) { + for(unsigned int realPosition = 0; realPosition < dataCount; ++realPosition, ++bufferPosition) { if(bufferPosition >= dataCount) bufferPosition %= dataCount; @@ -390,7 +401,7 @@ namespace Hantek { } } else { - for(unsigned int realPosition = 0; realPosition < dataCount; realPosition++, bufferPosition++) { + for(unsigned int realPosition = 0; realPosition < dataCount; ++realPosition, ++bufferPosition) { if(bufferPosition >= dataCount) bufferPosition %= dataCount; @@ -403,7 +414,7 @@ namespace Hantek { // Normal mode, channels are using their separate buffers unsigned int channelDataCount = dataCount / HANTEK_CHANNELS; - for(int channel = 0; channel < HANTEK_CHANNELS; channel++) { + for(int channel = 0; channel < HANTEK_CHANNELS; ++channel) { if(this->settings.voltage[channel].used) { // Reallocate memory for samples if the sample count has changed if(!this->samples[channel] || this->samplesSize[channel] != channelDataCount) { @@ -421,7 +432,7 @@ namespace Hantek { unsigned short int extraBitsMask = (0x00ff << extraBitsSize) & 0xff00; // Mask for extra bits extraction unsigned int extraBitsIndex = 8 - channel * 2; // Bit position offset for extra bits extraction - for(unsigned int realPosition = 0; realPosition < channelDataCount; realPosition++, bufferPosition += 2) { + for(unsigned int realPosition = 0; realPosition < channelDataCount; ++realPosition, bufferPosition += 2) { if(bufferPosition >= dataCount) bufferPosition %= dataCount; @@ -429,7 +440,7 @@ namespace Hantek { } } else { - for(unsigned int realPosition = 0; realPosition < channelDataCount; realPosition++, bufferPosition += 2) { + for(unsigned int realPosition = 0; realPosition < channelDataCount; ++realPosition, bufferPosition += 2) { if(bufferPosition >= dataCount) bufferPosition %= dataCount; @@ -459,7 +470,7 @@ namespace Hantek { unsigned long int Control::updateRecordLength(unsigned long int size) { // Get the record length supporting the highest samplerate while meeting the requirement int bestSizeId = -1; - for(int sizeId = 0; sizeId < this->specification.recordLengths.count(); sizeId++) { + for(int sizeId = 0; sizeId < this->specification.recordLengths.count(); ++sizeId) { if(this->specification.recordLengths[sizeId] >= size) { // We meet the size-requirement, check if we provide the highest possible samplerate if(bestSizeId == -1 || this->specification.recordLengths[bestSizeId] < size || this->specification.bufferDividers[sizeId] < this->specification.bufferDividers[bestSizeId]) @@ -475,7 +486,7 @@ namespace Hantek { switch(this->specification.command.bulk.setRecordLength) { case BULK_SETTRIGGERANDSAMPLERATE: // SetTriggerAndSamplerate bulk command for record length - ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setRecordLength(bestSizeId); + static_cast(this->command[BULK_SETTRIGGERANDSAMPLERATE])->setRecordLength(bestSizeId); this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; break; @@ -483,8 +494,8 @@ namespace Hantek { case BULK_DSETBUFFER: if(this->specification.command.bulk.setPretrigger == BULK_FSETBUFFER) { // Pointers to needed commands - BulkSetRecordLength2250 *commandSetRecordLength2250 = (BulkSetRecordLength2250 *) this->command[BULK_DSETBUFFER]; - BulkSetBuffer2250 *commandSetBuffer2250 = (BulkSetBuffer2250 *) this->command[BULK_FSETBUFFER]; + BulkSetRecordLength2250 *commandSetRecordLength2250 = static_cast(this->command[BULK_DSETBUFFER]); + BulkSetBuffer2250 *commandSetBuffer2250 = static_cast(this->command[BULK_FSETBUFFER]); commandSetRecordLength2250->setRecordLength(bestSizeId); commandSetBuffer2250->setUsedPre(FTRIGGERPOSITION_ON); @@ -497,7 +508,7 @@ namespace Hantek { } else { // SetBuffer5200 bulk command for record length - BulkSetBuffer5200 *commandSetBuffer5200 = (BulkSetBuffer5200 *) this->command[BULK_DSETBUFFER]; + BulkSetBuffer5200 *commandSetBuffer5200 = static_cast(this->command[BULK_DSETBUFFER]); commandSetBuffer5200->setUsedPre(DTRIGGERPOSITION_ON); commandSetBuffer5200->setUsedPost(DTRIGGERPOSITION_ON); commandSetBuffer5200->setRecordLength(bestSizeId); @@ -617,14 +628,14 @@ namespace Hantek { if(unsupported) qWarning("Warning: This Hantek DSO model isn't supported officially, so it may not be working as expected. Reports about your experiences are very welcome though (Please open a feature request in the tracker at https://sf.net/projects/openhantek/ or email me directly to oliver.haag@gmail.com). If it's working perfectly I can remove this warning, if not it should be possible to get it working with your help soon."); - for(int control = 0; control < CONTROLINDEX_COUNT; control++) + for(int control = 0; control < CONTROLINDEX_COUNT; ++control) this->controlPending[control] = true; // Maximum possible samplerate for a single channel and dividers for record lengths this->specification.bufferDividers.clear(); this->specification.recordLengths.clear(); this->specification.gainSteps.clear(); - for(int channel = 0; channel < HANTEK_CHANNELS; channel++) + for(int channel = 0; channel < HANTEK_CHANNELS; ++channel) this->specification.voltageLimit[channel].clear(); switch(this->device->getModel()) { @@ -639,7 +650,7 @@ namespace Hantek { this->specification.gainSteps << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0 << 80.0; /// \todo Use calibration data to get the DSO-5200(A) sample ranges - for(int channel = 0; channel < HANTEK_CHANNELS; channel++) + for(int channel = 0; channel < HANTEK_CHANNELS; ++channel) this->specification.voltageLimit[channel] << 368 << 454 << 908 << 368 << 454 << 908 << 368 << 454 << 908; this->specification.gainIndex @@ -656,7 +667,7 @@ namespace Hantek { this->specification.recordLengths << ULONG_MAX << 10240 << 524288; this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0; - for(int channel = 0; channel < HANTEK_CHANNELS; channel++) + for(int channel = 0; channel < HANTEK_CHANNELS; ++channel) this->specification.voltageLimit[channel] << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255; this->specification.gainIndex @@ -673,7 +684,7 @@ namespace Hantek { this->specification.recordLengths << ULONG_MAX << 10240 << 32768; this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0; - for(int channel = 0; channel < HANTEK_CHANNELS; channel++) + for(int channel = 0; channel < HANTEK_CHANNELS; ++channel) this->specification.voltageLimit[channel] << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255; this->specification.gainIndex @@ -690,7 +701,7 @@ namespace Hantek { this->specification.recordLengths << ULONG_MAX << 10240 << 32768; this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0; - for(int channel = 0; channel < HANTEK_CHANNELS; channel++) + for(int channel = 0; channel < HANTEK_CHANNELS; ++channel) this->specification.voltageLimit[channel] << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255; this->specification.gainIndex @@ -779,7 +790,7 @@ namespace Hantek { switch(this->specification.command.bulk.setSamplerate) { case BULK_SETTRIGGERANDSAMPLERATE: { // Pointers to needed commands - BulkSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = (BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE]; + BulkSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = static_cast(this->command[BULK_SETTRIGGERANDSAMPLERATE]); // Store samplerate fast value commandSetTriggerAndSamplerate->setSamplerateFast(valueFast); @@ -794,8 +805,8 @@ namespace Hantek { } case BULK_CSETTRIGGERORSAMPLERATE: { // Pointers to needed commands - BulkSetSamplerate5200 *commandSetSamplerate5200 = (BulkSetSamplerate5200 *) this->command[BULK_CSETTRIGGERORSAMPLERATE]; - BulkSetTrigger5200 *commandSetTrigger5200 = (BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE]; + BulkSetSamplerate5200 *commandSetSamplerate5200 = static_cast(this->command[BULK_CSETTRIGGERORSAMPLERATE]); + BulkSetTrigger5200 *commandSetTrigger5200 = static_cast(this->command[BULK_ESETTRIGGERORSAMPLERATE]); // Store samplerate fast value commandSetSamplerate5200->setSamplerateFast(4 - valueFast); @@ -811,7 +822,7 @@ namespace Hantek { } case BULK_ESETTRIGGERORSAMPLERATE: { // Pointers to needed commands - BulkSetSamplerate2250 *commandSetSamplerate2250 = (BulkSetSamplerate2250 *) this->command[BULK_ESETTRIGGERORSAMPLERATE]; + BulkSetSamplerate2250 *commandSetSamplerate2250 = static_cast(this->command[BULK_ESETTRIGGERORSAMPLERATE]); // Store samplerate fast value commandSetSamplerate2250->setSamplerateFast(4 - valueFast); @@ -848,7 +859,7 @@ namespace Hantek { switch(this->specification.command.bulk.setFilter) { case BULK_SETFILTER: { // SetFilter bulk command for channel filter (used has to be inverted!) - BulkSetFilter *commandSetFilter = (BulkSetFilter *) this->command[BULK_SETFILTER]; + BulkSetFilter *commandSetFilter = static_cast(this->command[BULK_SETFILTER]); commandSetFilter->setChannel(channel, !used); this->commandPending[BULK_SETFILTER] = true; @@ -856,7 +867,7 @@ namespace Hantek { } case BULK_BSETFILTER: { // SetFilter2250 bulk command for channel filter (used has to be inverted!) - BulkSetFilter2250 *commandSetFilter2250 = (BulkSetFilter2250 *) this->command[BULK_BSETFILTER]; + BulkSetFilter2250 *commandSetFilter2250 = static_cast(this->command[BULK_BSETFILTER]); commandSetFilter2250->setChannel(channel, !used); this->commandPending[BULK_BSETFILTER] = true; @@ -889,13 +900,13 @@ namespace Hantek { switch(this->specification.command.bulk.setTrigger) { case BULK_SETTRIGGERANDSAMPLERATE: { // SetTriggerAndSamplerate bulk command for trigger source - ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setUsedChannels(usedChannels); + static_cast(this->command[BULK_SETTRIGGERANDSAMPLERATE])->setUsedChannels(usedChannels); this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; break; } case BULK_ESETTRIGGERORSAMPLERATE: { // SetTrigger5200s bulk command for trigger source - ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->setUsedChannels(usedChannels); + static_cast(this->command[BULK_ESETTRIGGERORSAMPLERATE])->setUsedChannels(usedChannels); this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; break; } @@ -919,7 +930,7 @@ namespace Hantek { return Dso::ERROR_PARAMETER; // SetRelays control command for coupling relays - ((ControlSetRelays *) this->control[CONTROLINDEX_SETRELAYS])->setCoupling(channel, coupling != Dso::COUPLING_AC); + static_cast(this->control[CONTROLINDEX_SETRELAYS])->setCoupling(channel, coupling != Dso::COUPLING_AC); this->controlPending[CONTROLINDEX_SETRELAYS] = true; return Dso::ERROR_NONE; @@ -938,16 +949,16 @@ namespace Hantek { // Find lowest gain voltage thats at least as high as the requested int gainId; - for(gainId = 0; gainId < this->specification.gainSteps.count() - 1; gainId++) + for(gainId = 0; gainId < this->specification.gainSteps.count() - 1; ++gainId) if(this->specification.gainSteps[gainId] >= gain) break; // SetGain bulk command for gain - ((BulkSetGain *) this->command[BULK_SETGAIN])->setGain(channel, this->specification.gainIndex[gainId]); + static_cast(this->command[BULK_SETGAIN])->setGain(channel, this->specification.gainIndex[gainId]); this->commandPending[BULK_SETGAIN] = true; // SetRelays control command for gain relays - ControlSetRelays *controlSetRelays = (ControlSetRelays *) this->control[CONTROLINDEX_SETRELAYS]; + ControlSetRelays *controlSetRelays = static_cast(this->control[CONTROLINDEX_SETRELAYS]); controlSetRelays->setBelow1V(channel, gainId < 3); controlSetRelays->setBelow100mV(channel, gainId < 6); this->controlPending[CONTROLINDEX_SETRELAYS] = true; @@ -978,7 +989,7 @@ namespace Hantek { double offsetReal = (double) (offsetValue - minimum) / (maximum - minimum); // SetOffset control command for channel offset - ((ControlSetOffset *) this->control[CONTROLINDEX_SETOFFSET])->setChannel(channel, offsetValue); + static_cast(this->control[CONTROLINDEX_SETOFFSET])->setChannel(channel, offsetValue); this->controlPending[CONTROLINDEX_SETOFFSET] = true; this->settings.voltage[channel].offset = offset; @@ -1023,19 +1034,19 @@ namespace Hantek { switch(this->specification.command.bulk.setTrigger) { case BULK_SETTRIGGERANDSAMPLERATE: // SetTriggerAndSamplerate bulk command for trigger source - ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerSource(sourceValue); + static_cast(this->command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerSource(sourceValue); this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; break; case BULK_CSETTRIGGERORSAMPLERATE: // SetTrigger2250 bulk command for trigger source - ((BulkSetTrigger2250 *) this->command[BULK_CSETTRIGGERORSAMPLERATE])->setTriggerSource(sourceValue); + static_cast(this->command[BULK_CSETTRIGGERORSAMPLERATE])->setTriggerSource(sourceValue); this->commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; break; case BULK_ESETTRIGGERORSAMPLERATE: // SetTrigger5200 bulk command for trigger source - ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->setTriggerSource(sourceValue); + static_cast(this->command[BULK_ESETTRIGGERORSAMPLERATE])->setTriggerSource(sourceValue); this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; break; @@ -1044,7 +1055,7 @@ namespace Hantek { } // SetRelays control command for external trigger relay - ((ControlSetRelays *) this->control[CONTROLINDEX_SETRELAYS])->setTrigger(special); + static_cast(this->control[CONTROLINDEX_SETRELAYS])->setTrigger(special); this->controlPending[CONTROLINDEX_SETRELAYS] = true; this->settings.trigger.special = special; @@ -1053,7 +1064,7 @@ namespace Hantek { // Apply trigger level of the new source if(special) { // SetOffset control command for changed trigger level - ((ControlSetOffset *) this->control[CONTROLINDEX_SETOFFSET])->setTrigger(0x7f); + static_cast(this->control[CONTROLINDEX_SETOFFSET])->setTrigger(0x7f); this->controlPending[CONTROLINDEX_SETOFFSET] = true; } else @@ -1096,7 +1107,7 @@ namespace Hantek { // Check if the set channel is the trigger source if(!this->settings.trigger.special && channel == this->settings.trigger.source) { // SetOffset control command for trigger level - ((ControlSetOffset *) this->control[CONTROLINDEX_SETOFFSET])->setTrigger(levelValue); + static_cast(this->control[CONTROLINDEX_SETOFFSET])->setTrigger(levelValue); this->controlPending[CONTROLINDEX_SETOFFSET] = true; } @@ -1119,19 +1130,19 @@ namespace Hantek { switch(this->specification.command.bulk.setTrigger) { case BULK_SETTRIGGERANDSAMPLERATE: { // SetTriggerAndSamplerate bulk command for trigger slope - ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerSlope(slope); + static_cast(this->command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerSlope(slope); this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; break; } case BULK_CSETTRIGGERORSAMPLERATE: { // SetTrigger2250 bulk command for trigger slope - ((BulkSetTrigger2250 *) this->command[BULK_CSETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); + static_cast(this->command[BULK_CSETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); this->commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; break; } case BULK_ESETTRIGGERORSAMPLERATE: { // SetTrigger5200 bulk command for trigger slope - ((BulkSetTrigger5200 *) this->command[BULK_ESETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); + static_cast(this->command[BULK_ESETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; break; } @@ -1162,7 +1173,7 @@ namespace Hantek { unsigned long int position = 0x7ffff - this->specification.recordLengths[this->settings.recordLengthId] + positionSamples; // SetTriggerAndSamplerate bulk command for trigger position - ((BulkSetTriggerAndSamplerate *) this->command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(position); + static_cast(this->command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(position); this->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; break; @@ -1173,7 +1184,7 @@ namespace Hantek { unsigned short int positionPost = 0xffff - positionSamples; // SetBuffer2250 bulk command for trigger position - BulkSetBuffer2250 *commandSetBuffer2250 = (BulkSetBuffer2250 *) this->command[BULK_FSETBUFFER]; + BulkSetBuffer2250 *commandSetBuffer2250 = static_cast(this->command[BULK_FSETBUFFER]); commandSetBuffer2250->setTriggerPositionPre(positionPre); commandSetBuffer2250->setTriggerPositionPost(positionPost); this->commandPending[BULK_FSETBUFFER] = true; @@ -1186,7 +1197,7 @@ namespace Hantek { unsigned short int positionPost = 0xffff - positionSamples; // SetBuffer5200 bulk command for trigger position - BulkSetBuffer5200 *commandSetBuffer5200 = (BulkSetBuffer5200 *) this->command[BULK_DSETBUFFER]; + BulkSetBuffer5200 *commandSetBuffer5200 = static_cast(this->command[BULK_DSETBUFFER]); commandSetBuffer5200->setTriggerPositionPre(positionPre); commandSetBuffer5200->setTriggerPositionPost(positionPost); this->commandPending[BULK_DSETBUFFER] = true; @@ -1240,7 +1251,7 @@ namespace Hantek { // Get control code from third part unsigned char controlCode = commandParts[2].toUShort(); int control; - for(control = 0; control < CONTROLINDEX_COUNT; control++) { + for(control = 0; control < CONTROLINDEX_COUNT; ++control) { if(this->controlCode[control] == controlCode) break; } diff --git a/openhantek/src/hantek/control.h b/openhantek/src/hantek/control.h index 022fd78..4cf12e0 100644 --- a/openhantek/src/hantek/control.h +++ b/openhantek/src/hantek/control.h @@ -133,7 +133,6 @@ namespace Hantek { /// \brief Stores the current samplerate settings of the device. struct ControlSettingsSamplerate { ControlSamplerateLimits *limits; ///< The samplerate limits - //unsigned long int divider; ///< The fixed samplerate divider unsigned long int downsampling; ///< The variable downsampling factor double current; ///< The current samplerate }; @@ -144,7 +143,7 @@ namespace Hantek { struct ControlSettingsTrigger { double level[HANTEK_CHANNELS]; ///< The trigger level for each channel in V double position; ///< The current pretrigger position - unsigned int point; ///< The trigger point value + unsigned int point; ///< The trigger position in Hantek coding Dso::TriggerMode mode; ///< The trigger mode Dso::Slope slope; ///< The trigger slope bool special; ///< true, if the trigger source is special diff --git a/openhantek/src/hantek/device.cpp b/openhantek/src/hantek/device.cpp index 61a07bc..c0333b0 100644 --- a/openhantek/src/hantek/device.cpp +++ b/openhantek/src/hantek/device.cpp @@ -51,6 +51,9 @@ namespace Hantek { this->handle = 0; this->interface = -1; + this->outPacketLength = 0; + this->inPacketLength = 0; + #if LIBUSB_VERSION == 0 usb_init(); this->error = LIBUSB_SUCCESS; @@ -107,7 +110,7 @@ namespace Hantek { struct usb_config_descriptor *configDescriptor = device->config; struct usb_interface *interface; struct usb_interface_descriptor *interfaceDescriptor; - for(int interfaceIndex = 0; interfaceIndex < configDescriptor->bNumInterfaces; interfaceIndex++) { + for(int interfaceIndex = 0; interfaceIndex < configDescriptor->bNumInterfaces; ++interfaceIndex) { interface = &configDescriptor->interface[interfaceIndex]; if(interface->num_altsetting < 1) continue; @@ -128,7 +131,7 @@ namespace Hantek { usb_endpoint_descriptor *endpointDescriptor; this->outPacketLength = 0; this->inPacketLength = 0; - for (int endpoint = 0; endpoint < interfaceDescriptor->bNumEndpoints; endpoint++) { + for (int endpoint = 0; endpoint < interfaceDescriptor->bNumEndpoints; ++endpoint) { endpointDescriptor = &interfaceDescriptor->endpoint[endpoint]; switch(endpointDescriptor->bEndpointAddress) { case HANTEK_EP_OUT: @@ -163,7 +166,7 @@ namespace Hantek { // Iterate through all usb devices this->model = MODEL_UNKNOWN; - for(ssize_t deviceIterator = 0; deviceIterator < deviceCount; deviceIterator++) { + for(ssize_t deviceIterator = 0; deviceIterator < deviceCount; ++deviceIterator) { device = deviceList[deviceIterator]; // Get device descriptor if(libusb_get_device_descriptor(device, &(this->descriptor)) < 0) @@ -188,7 +191,7 @@ namespace Hantek { // Search for the needed interface libusb_get_config_descriptor(device, 0, &configDescriptor); - for(int interfaceIndex = 0; interfaceIndex < (int) configDescriptor->bNumInterfaces; interfaceIndex++) { + for(int interfaceIndex = 0; interfaceIndex < (int) configDescriptor->bNumInterfaces; ++interfaceIndex) { interface = &configDescriptor->interface[interfaceIndex]; if(interface->num_altsetting < 1) continue; @@ -209,7 +212,7 @@ namespace Hantek { const libusb_endpoint_descriptor *endpointDescriptor; this->outPacketLength = 0; this->inPacketLength = 0; - for (int endpoint = 0; endpoint < interfaceDescriptor->bNumEndpoints; endpoint++) { + for (int endpoint = 0; endpoint < interfaceDescriptor->bNumEndpoints; ++endpoint) { endpointDescriptor = &(interfaceDescriptor->endpoint[endpoint]); switch(endpointDescriptor->bEndpointAddress) { case HANTEK_EP_OUT: @@ -285,7 +288,7 @@ namespace Hantek { int errorCode = LIBUSB_ERROR_TIMEOUT; int transferred; - for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++) + for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; ++attempt) errorCode = libusb_bulk_transfer(this->handle, endpoint, data, length, &transferred, HANTEK_TIMEOUT); if(errorCode == LIBUSB_ERROR_NO_DEVICE) @@ -312,7 +315,7 @@ namespace Hantek { #if LIBUSB_VERSION == 0 errorCode = LIBUSB_ERROR_TIMEOUT; - for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++) + for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; ++attempt) errorCode = usb_bulk_write(this->handle, HANTEK_EP_OUT, (char *) data, length, HANTEK_TIMEOUT); if(errorCode == LIBUSB_ERROR_NO_DEVICE) @@ -339,7 +342,7 @@ namespace Hantek { #if LIBUSB_VERSION == 0 errorCode = LIBUSB_ERROR_TIMEOUT; - for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++) + for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; ++attempt) errorCode = usb_bulk_read(this->handle, HANTEK_EP_IN, (char *) data, length, HANTEK_TIMEOUT); if(errorCode == LIBUSB_ERROR_NO_DEVICE) @@ -385,10 +388,10 @@ namespace Hantek { errorCode = this->inPacketLength; unsigned int packet, received = 0; - for(packet = 0; received < length && errorCode == this->inPacketLength; packet++) { + for(packet = 0; received < length && errorCode == this->inPacketLength; ++packet) { #if LIBUSB_VERSION == 0 errorCode = LIBUSB_ERROR_TIMEOUT; - for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++) + for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; ++attempt) errorCode = usb_bulk_read(this->handle, HANTEK_EP_IN, (char *) data + packet * this->inPacketLength, qMin(length - received, (unsigned int) this->inPacketLength), HANTEK_TIMEOUT); #else errorCode = this->bulkTransfer(HANTEK_EP_IN, data + packet * this->inPacketLength, qMin(length - received, (unsigned int) this->inPacketLength), attempts); @@ -417,7 +420,7 @@ namespace Hantek { return LIBUSB_ERROR_NO_DEVICE; int errorCode = LIBUSB_ERROR_TIMEOUT; - for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++) + for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; ++attempt) #if LIBUSB_VERSION == 0 errorCode = usb_control_msg(this->handle, type, request, value, index, (char *) data, length, HANTEK_TIMEOUT); #else @@ -441,7 +444,7 @@ namespace Hantek { if(!this->handle) return LIBUSB_ERROR_NO_DEVICE; - return this->controlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, request, data, length, value, index,attempts); + return this->controlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, request, data, length, value, index, attempts); } /// \brief Control read to the oscilloscope. diff --git a/openhantek/src/hantek/device.h b/openhantek/src/hantek/device.h index 22f1b71..598cfdc 100644 --- a/openhantek/src/hantek/device.h +++ b/openhantek/src/hantek/device.h @@ -37,7 +37,7 @@ #define libusb_device_handle usb_device_handle #define libusb_device_descriptor usb_device_descriptor #else -#include +#include #endif diff --git a/openhantek/src/helper.cpp b/openhantek/src/helper.cpp index fb242d3..4059470 100644 --- a/openhantek/src/helper.cpp +++ b/openhantek/src/helper.cpp @@ -151,7 +151,7 @@ namespace Helper { QString hexDump(unsigned char *data, unsigned int length) { QString dumpString, byteString; - for(unsigned int index = 0; index < length; index++) + for(unsigned int index = 0; index < length; ++index) dumpString.append(byteString.sprintf(" %02x", data[index])); return dumpString; @@ -168,7 +168,7 @@ namespace Helper { QString byteString; unsigned int index; - for(index = 0; index < length; index++) { + for(index = 0; index < length; ++index) { byteString = dumpString.mid(index * 2, 2); // Check if we reached the end of the string diff --git a/openhantek/src/helper.h b/openhantek/src/helper.h index cd897b0..935c226 100644 --- a/openhantek/src/helper.h +++ b/openhantek/src/helper.h @@ -93,7 +93,7 @@ namespace Helper { /// \param size Size of the data array. template DataArray::DataArray(unsigned int size) { this->array = new T[size]; - for(unsigned int index = 0; index < size; index++) + for(unsigned int index = 0; index < size; ++index) this->array[index] = 0; this->size = size; } diff --git a/openhantek/src/levelslider.cpp b/openhantek/src/levelslider.cpp index 4b66df1..ab697ee 100644 --- a/openhantek/src/levelslider.cpp +++ b/openhantek/src/levelslider.cpp @@ -353,7 +353,7 @@ void LevelSlider::mousePressEvent(QMouseEvent *event) { } this->pressedSlider = -1; - for(int sliderId = 0; sliderId < this->slider.count(); sliderId++) { + for(int sliderId = 0; sliderId < this->slider.count(); ++sliderId) { if(this->slider[sliderId]->visible && this->slider[sliderId]->rect.contains(event->pos())) { this->pressedSlider = sliderId; break; @@ -400,7 +400,7 @@ void LevelSlider::paintEvent(QPaintEvent *event) { QList::iterator slider = this->slider.end(); while(slider != this->slider.begin()) { - slider--; + --slider; if(!(*slider)->visible) continue; @@ -475,7 +475,7 @@ void LevelSlider::paintEvent(QPaintEvent *event) { void LevelSlider::resizeEvent(QResizeEvent *event) { Q_UNUSED(event); - for(int sliderId = 0; sliderId < this->slider.count(); sliderId++) + for(int sliderId = 0; sliderId < this->slider.count(); ++sliderId) this->calculateRect(sliderId); this->repaint(); diff --git a/openhantek/src/openhantek.cpp b/openhantek/src/openhantek.cpp index 6ee88fd..4635d7c 100644 --- a/openhantek/src/openhantek.cpp +++ b/openhantek/src/openhantek.cpp @@ -133,7 +133,7 @@ OpenHantekMainWindow::OpenHantekMainWindow(QWidget *parent, Qt::WindowFlags flag // Set up the oscilloscope this->dsoControl->connectDevice(); - for(unsigned int channel = 0; channel < this->settings->scope.physicalChannels; channel++) { + for(unsigned int channel = 0; channel < this->settings->scope.physicalChannels; ++channel) { this->dsoControl->setCoupling(channel, (Dso::Coupling) this->settings->scope.voltage[channel].misc); this->updateVoltageGain(channel); this->updateOffset(channel); @@ -489,7 +489,7 @@ void OpenHantekMainWindow::applySettings() { QList dockedWindows[2]; // Docks docked on the sides of the main window - for(int dockId = 0; dockId < docks.size(); dockId++) { + for(int dockId = 0; dockId < docks.size(); ++dockId) { docks[dockId]->setVisible(dockSettings[dockId]->visible); if(!dockSettings[dockId]->position.isNull()) { if(dockSettings[dockId]->floating) { @@ -502,7 +502,7 @@ void OpenHantekMainWindow::applySettings() { int side = (dockSettings[dockId]->position.x() < this->settings->options.window.size.width() / 2) ? 0 : 1; int index = 0; while(index < dockedWindows[side].size() && dockSettings[dockedWindows[side][index]]->position.y() <= dockSettings[dockId]->position.y()) - index++; + ++index; dockedWindows[side].insert(index, dockId); } } @@ -512,9 +512,9 @@ void OpenHantekMainWindow::applySettings() { } // Put the docked docking windows into the main window - for(int position = 0; position < dockedWindows[0].size(); position++) + for(int position = 0; position < dockedWindows[0].size(); ++position) this->addDockWidget(Qt::LeftDockWidgetArea, docks[dockedWindows[0][position]]); - for(int position = 0; position < dockedWindows[1].size(); position++) + for(int position = 0; position < dockedWindows[1].size(); ++position) this->addDockWidget(Qt::RightDockWidgetArea, docks[dockedWindows[1][position]]); // Toolbars @@ -530,7 +530,7 @@ void OpenHantekMainWindow::applySettings() { QList dockedToolbars; // Docks docked on the sides of the main window - for(int toolbarId = 0; toolbarId < toolbars.size(); toolbarId++) { + for(int toolbarId = 0; toolbarId < toolbars.size(); ++toolbarId) { toolbars[toolbarId]->setVisible(toolbarSettings[toolbarId]->visible); //toolbars[toolbarId]->setFloating(toolbarSettings[toolbarId]->floating); // setFloating missing, a bug in Qt? if(!toolbarSettings[toolbarId]->position.isNull() && !toolbarSettings[toolbarId]->floating) { @@ -541,7 +541,7 @@ void OpenHantekMainWindow::applySettings() { // Check in which order the toolbars where placed int index = 0; while(index < dockedToolbars.size() && toolbarSettings[dockedToolbars[index]]->position.x() <= toolbarSettings[toolbarId]->position.x()) - index++; + ++index; dockedToolbars.insert(index, toolbarId); } } @@ -551,7 +551,7 @@ void OpenHantekMainWindow::applySettings() { } // Put the docked toolbars into the main window - for(int position = 0; position < dockedToolbars.size(); position++) + for(int position = 0; position < dockedToolbars.size(); ++position) this->addToolBar(toolbars[dockedToolbars[position]]); } @@ -574,7 +574,7 @@ void OpenHantekMainWindow::updateSettings() { dockSettings.append(&(this->settings->options.window.dock.trigger)); dockSettings.append(&(this->settings->options.window.dock.voltage)); - for(int dockId = 0; dockId < docks.size(); dockId++) { + for(int dockId = 0; dockId < docks.size(); ++dockId) { dockSettings[dockId]->floating = docks[dockId]->isFloating(); dockSettings[dockId]->position = docks[dockId]->pos(); dockSettings[dockId]->visible = docks[dockId]->isVisible(); @@ -591,7 +591,7 @@ void OpenHantekMainWindow::updateSettings() { toolbarSettings.append(&(this->settings->options.window.toolbar.oscilloscope)); toolbarSettings.append(&(this->settings->options.window.toolbar.view)); - for(int toolbarId = 0; toolbarId < toolbars.size(); toolbarId++) { + for(int toolbarId = 0; toolbarId < toolbars.size(); ++toolbarId) { toolbarSettings[toolbarId]->floating = toolbars[toolbarId]->isFloating(); toolbarSettings[toolbarId]->position = toolbars[toolbarId]->pos(); toolbarSettings[toolbarId]->visible = toolbars[toolbarId]->isVisible(); @@ -636,7 +636,7 @@ void OpenHantekMainWindow::updateUsed(unsigned int channel) { this->dsoControl->setChannelUsed(channel, mathUsed | this->settings->scope.voltage[channel].used | this->settings->scope.spectrum[channel].used); // Math channel, update all channels else if(channel == this->settings->scope.physicalChannels) { - for(unsigned int channelCounter = 0; channelCounter < this->settings->scope.physicalChannels; channelCounter++) + for(unsigned int channelCounter = 0; channelCounter < this->settings->scope.physicalChannels; ++channelCounter) this->dsoControl->setChannelUsed(channelCounter, mathUsed | this->settings->scope.voltage[channelCounter].used | this->settings->scope.spectrum[channelCounter].used); } } diff --git a/openhantek/src/settings.cpp b/openhantek/src/settings.cpp index bd01b9e..f382c42 100644 --- a/openhantek/src/settings.cpp +++ b/openhantek/src/settings.cpp @@ -51,7 +51,7 @@ DsoSettings::DsoSettings(QWidget *parent) : QObject(parent) { panels.append(&(this->options.window.toolbar.file)); panels.append(&(this->options.window.toolbar.oscilloscope)); panels.append(&(this->options.window.toolbar.view)); - for(int panelId = 0; panelId < panels.size(); panelId++) { + for(int panelId = 0; panelId < panels.size(); ++panelId) { panels[panelId]->floating = false; panels[panelId]->position = QPoint(); panels[panelId]->visible = true; @@ -126,7 +126,7 @@ void DsoSettings::setChannelCount(unsigned int channels) { this->scope.spectrum.removeAt(channel); // Add new channels to the list - for(int channel = 0; channel < (int) channels; channel++) { + for(int channel = 0; channel < (int) channels; ++channel) { // Oscilloscope settings // Spectrum if(this->scope.spectrum.count() <= channel + 1) { @@ -218,7 +218,7 @@ int DsoSettings::load(const QString &fileName) { docks.append(&(this->options.window.dock.voltage)); QStringList dockNames; dockNames << "horizontal" << "spectrum" << "trigger" << "voltage"; - for(int dockId = 0; dockId < docks.size(); dockId++) { + for(int dockId = 0; dockId < docks.size(); ++dockId) { settingsLoader->beginGroup(dockNames[dockId]); if(settingsLoader->contains("floating")) docks[dockId]->floating = settingsLoader->value("floating").toBool(); @@ -236,7 +236,7 @@ int DsoSettings::load(const QString &fileName) { toolbars.append(&(this->options.window.toolbar.view)); QStringList toolbarNames; toolbarNames << "file" << "oscilloscope" << "view"; - for(int toolbarId = 0; toolbarId < toolbars.size(); toolbarId++) { + for(int toolbarId = 0; toolbarId < toolbars.size(); ++toolbarId) { settingsLoader->beginGroup(toolbarNames[toolbarId]); if(settingsLoader->contains("floating")) toolbars[toolbarId]->floating = settingsLoader->value("floating").toBool(); @@ -268,7 +268,7 @@ int DsoSettings::load(const QString &fileName) { this->scope.horizontal.format = (Dso::GraphFormat) settingsLoader->value("format").toInt(); if(settingsLoader->contains("frequencybase")) this->scope.horizontal.frequencybase = settingsLoader->value("frequencybase").toDouble(); - for(int marker = 0; marker < 2; marker++) { + for(int marker = 0; marker < 2; ++marker) { QString name; name = QString("marker%1").arg(marker); if(settingsLoader->contains(name)) @@ -293,7 +293,7 @@ int DsoSettings::load(const QString &fileName) { this->scope.trigger.special = settingsLoader->value("special").toInt(); settingsLoader->endGroup(); // Spectrum - for(int channel = 0; channel < this->scope.spectrum.count(); channel++) { + for(int channel = 0; channel < this->scope.spectrum.count(); ++channel) { settingsLoader->beginGroup(QString("spectrum%1").arg(channel)); if(settingsLoader->contains("magnitude")) this->scope.spectrum[channel].magnitude = settingsLoader->value("magnitude").toDouble(); @@ -304,7 +304,7 @@ int DsoSettings::load(const QString &fileName) { settingsLoader->endGroup(); } // Vertical axis - for(int channel = 0; channel < this->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->scope.voltage.count(); ++channel) { settingsLoader->beginGroup(QString("vertical%1").arg(channel)); if(settingsLoader->contains("gain")) this->scope.voltage[channel].gain = settingsLoader->value("gain").toDouble(); @@ -331,7 +331,7 @@ int DsoSettings::load(const QString &fileName) { // Colors settingsLoader->beginGroup("color"); DsoSettingsColorValues *colors; - for(int mode = 0; mode < 2; mode++) { + for(int mode = 0; mode < 2; ++mode) { if(mode == 0) { colors = &this->view.color.screen; settingsLoader->beginGroup("screen"); @@ -351,14 +351,14 @@ int DsoSettings::load(const QString &fileName) { colors->grid = settingsLoader->value("grid").value(); if(settingsLoader->contains("markers")) colors->markers = settingsLoader->value("markers").value(); - for(int channel = 0; channel < this->scope.spectrum.count(); channel++) { + for(int channel = 0; channel < this->scope.spectrum.count(); ++channel) { QString key = QString("spectrum%1").arg(channel); if(settingsLoader->contains(key)) colors->spectrum[channel] = settingsLoader->value(key).value(); } if(settingsLoader->contains("text")) colors->text = settingsLoader->value("text").value(); - for(int channel = 0; channel < this->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->scope.voltage.count(); ++channel) { QString key = QString("voltage%1").arg(channel); if(settingsLoader->contains(key)) colors->voltage[channel] = settingsLoader->value(key).value(); @@ -409,7 +409,7 @@ int DsoSettings::save(const QString &fileName) { docks.append(&(this->options.window.dock.voltage)); QStringList dockNames; dockNames << "horizontal" << "spectrum" << "trigger" << "voltage"; - for(int dockId = 0; dockId < docks.size(); dockId++) { + for(int dockId = 0; dockId < docks.size(); ++dockId) { settingsSaver->beginGroup(dockNames[dockId]); settingsSaver->setValue("floating", docks[dockId]->floating); settingsSaver->setValue("position", docks[dockId]->position); @@ -424,7 +424,7 @@ int DsoSettings::save(const QString &fileName) { toolbars.append(&(this->options.window.toolbar.view)); QStringList toolbarNames; toolbarNames << "file" << "oscilloscope" << "view"; - for(int toolbarId = 0; toolbarId < toolbars.size(); toolbarId++) { + for(int toolbarId = 0; toolbarId < toolbars.size(); ++toolbarId) { settingsSaver->beginGroup(toolbarNames[toolbarId]); settingsSaver->setValue("floating", toolbars[toolbarId]->floating); settingsSaver->setValue("position", toolbars[toolbarId]->position); @@ -446,7 +446,7 @@ int DsoSettings::save(const QString &fileName) { settingsSaver->beginGroup("horizontal"); settingsSaver->setValue("format", this->scope.horizontal.format); settingsSaver->setValue("frequencybase", this->scope.horizontal.frequencybase); - for(int marker = 0; marker < 2; marker++) + for(int marker = 0; marker < 2; ++marker) settingsSaver->setValue(QString("marker%1").arg(marker), this->scope.horizontal.marker[marker]); settingsSaver->setValue("timebase", this->scope.horizontal.timebase); settingsSaver->endGroup(); @@ -459,7 +459,7 @@ int DsoSettings::save(const QString &fileName) { settingsSaver->setValue("source", this->scope.trigger.source); settingsSaver->endGroup(); // Spectrum - for(int channel = 0; channel < this->scope.spectrum.count(); channel++) { + for(int channel = 0; channel < this->scope.spectrum.count(); ++channel) { settingsSaver->beginGroup(QString("spectrum%1").arg(channel)); settingsSaver->setValue("magnitude", this->scope.spectrum[channel].magnitude); settingsSaver->setValue("offset", this->scope.spectrum[channel].offset); @@ -467,7 +467,7 @@ int DsoSettings::save(const QString &fileName) { settingsSaver->endGroup(); } // Vertical axis - for(int channel = 0; channel < this->scope.voltage.count(); channel++) { + for(int channel = 0; channel < this->scope.voltage.count(); ++channel) { settingsSaver->beginGroup(QString("vertical%1").arg(channel)); settingsSaver->setValue("gain", this->scope.voltage[channel].gain); settingsSaver->setValue("misc", this->scope.voltage[channel].misc); @@ -487,7 +487,7 @@ int DsoSettings::save(const QString &fileName) { if(complete) { settingsSaver->beginGroup("color"); DsoSettingsColorValues *colors; - for(int mode = 0; mode < 2; mode++) { + for(int mode = 0; mode < 2; ++mode) { if(mode == 0) { colors = &this->view.color.screen; settingsSaver->beginGroup("screen"); @@ -502,10 +502,10 @@ int DsoSettings::save(const QString &fileName) { settingsSaver->setValue("border", colors->border); settingsSaver->setValue("grid", colors->grid); settingsSaver->setValue("markers", colors->markers); - for(int channel = 0; channel < this->scope.spectrum.count(); channel++) + for(int channel = 0; channel < this->scope.spectrum.count(); ++channel) settingsSaver->setValue(QString("spectrum%1").arg(channel), colors->spectrum[channel]); settingsSaver->setValue("text", colors->text); - for(int channel = 0; channel < this->scope.voltage.count(); channel++) + for(int channel = 0; channel < this->scope.voltage.count(); ++channel) settingsSaver->setValue(QString("voltage%1").arg(channel), colors->voltage[channel]); settingsSaver->endGroup(); }