Skip to content

Commit 2c49e9e

Browse files
author
David Graeff
committed
Add format (clang-format) as build target to cmake. Remove unnessesary #ifdef DEBUG: We have a smart timestampDebug macro now. Convert more Qt connect to Qt5 style
1 parent 8182254 commit 2c49e9e

11 files changed

+176
-308
lines changed

.clang-format

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ AlignEscapedNewlinesLeft: false
99
AlignOperands: true
1010
AlignTrailingComments: true
1111
AllowAllParametersOfDeclarationOnNextLine: true
12-
AllowShortBlocksOnASingleLine: false
12+
AllowShortBlocksOnASingleLine: true
1313
AllowShortCaseLabelsOnASingleLine: false
1414
AllowShortFunctionsOnASingleLine: All
15-
AllowShortIfStatementsOnASingleLine: false
16-
AllowShortLoopsOnASingleLine: false
15+
AllowShortIfStatementsOnASingleLine: true
16+
AllowShortLoopsOnASingleLine: true
1717
AlwaysBreakAfterDefinitionReturnType: None
1818
AlwaysBreakAfterReturnType: None
1919
AlwaysBreakBeforeMultilineStrings: false
@@ -38,7 +38,7 @@ BreakBeforeTernaryOperators: true
3838
BreakConstructorInitializersBeforeComma: false
3939
BreakAfterJavaFieldAnnotations: false
4040
BreakStringLiterals: true
41-
ColumnLimit: 80
41+
ColumnLimit: 120
4242
CommentPragmas: '^ IWYU pragma:'
4343
ConstructorInitializerAllOnOneLineOrOnePerLine: false
4444
ConstructorInitializerIndentWidth: 4
@@ -57,7 +57,7 @@ IncludeCategories:
5757
Priority: 1
5858
IncludeIsMainRegex: '$'
5959
IndentCaseLabels: false
60-
IndentWidth: 2
60+
IndentWidth: 4
6161
IndentWrappedFunctionNames: false
6262
JavaScriptQuotes: Leave
6363
JavaScriptWrapImports: true

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ endif()
3232

3333
# Add auxiliary files to the project, so that these files appear in VisualStudio/QtCreator
3434
add_custom_target(readme SOURCES readme.md)
35+
add_custom_target(format SOURCES ".clang-format"
36+
COMMAND "clang-format" "-style=.clang-format" "-i" "-sort-includes" ${SRC} ${HEADERS})
3537

3638
# Add "cppcheck" command
3739
add_custom_target(cppcheck COMMAND "cppcheck --enable=all -I \"${CMAKE_CURRENT_LIST_DIR}/openhantek/src\" -q ${SRC} --template=\"{file}:{line}: {severity}: {message}\"")

openhantek/src/dsowidget.cpp

+13-20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "utils/dsoStrings.h"
1515
#include "exporter.h"
1616
#include "glscope.h"
17+
#include "glgenerator.h"
1718
#include "widgets/levelslider.h"
1819
#include "settings.h"
1920

@@ -248,18 +249,14 @@ DsoWidget::DsoWidget(DsoSettings *settings, QWidget *parent, Qt::WindowFlags fla
248249
this->setLayout(this->mainLayout);
249250

250251
// Connect change-signals of sliders
251-
this->connect(this->offsetSlider, SIGNAL(valueChanged(int, double)), this,
252-
SLOT(updateOffset(int, double)));
253-
this->connect(this->triggerPositionSlider, SIGNAL(valueChanged(int, double)),
254-
this, SLOT(updateTriggerPosition(int, double)));
255-
this->connect(this->triggerLevelSlider, SIGNAL(valueChanged(int, double)),
256-
this, SLOT(updateTriggerLevel(int, double)));
257-
this->connect(this->markerSlider, SIGNAL(valueChanged(int, double)), this,
258-
SLOT(updateMarker(int, double)));
259-
this->connect(this->markerSlider, SIGNAL(valueChanged(int, double)),
260-
this->mainScope, SLOT(update()));
261-
this->connect(this->markerSlider, SIGNAL(valueChanged(int, double)),
262-
this->zoomScope, SLOT(update()));
252+
this->connect(this->offsetSlider, &LevelSlider::valueChanged, this, &DsoWidget::updateOffset);
253+
this->connect(this->triggerPositionSlider, &LevelSlider::valueChanged, this, &DsoWidget::updateTriggerPosition);
254+
this->connect(this->triggerLevelSlider, &LevelSlider::valueChanged, this, &DsoWidget::updateTriggerLevel);
255+
this->connect(this->markerSlider, &LevelSlider::valueChanged, [this](int index, double value) {
256+
this->updateMarker(index, value);
257+
this->mainScope->update();
258+
this->zoomScope->update();
259+
});
263260
}
264261

265262
void DsoWidget::showNewData(std::unique_ptr<DataAnalyzerResult> data)
@@ -544,16 +541,12 @@ void DsoWidget::doShowNewData() {
544541

545542
updateRecordLength(data.get()->getMaxSamples());
546543

547-
for (int channel = 0; channel < this->settings->scope.voltage.count();
548-
++channel) {
549-
if (this->settings->scope.voltage[channel].used &&
550-
data.get()->data(channel)) {
544+
for (int channel = 0; channel < settings->scope.voltage.count(); ++channel) {
545+
if (settings->scope.voltage[channel].used && data.get()->data(channel)) {
551546
// Amplitude string representation (4 significant digits)
552-
this->measurementAmplitudeLabel[channel]->setText(valueToString(
553-
data.get()->data(channel)->amplitude, UNIT_VOLTS, 4));
547+
measurementAmplitudeLabel[channel]->setText(valueToString(data.get()->data(channel)->amplitude, UNIT_VOLTS, 4));
554548
// Frequency string representation (5 significant digits)
555-
this->measurementFrequencyLabel[channel]->setText(valueToString(
556-
data.get()->data(channel)->frequency, UNIT_HERTZ, 5));
549+
measurementFrequencyLabel[channel]->setText(valueToString(data.get()->data(channel)->frequency, UNIT_HERTZ, 5));
557550
}
558551
}
559552
}

openhantek/src/glscope.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "glscope.h"
88

9-
#include "dataanalyzer.h"
109
#include "glgenerator.h"
1110
#include "settings.h"
1211

openhantek/src/glscope.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ using GL_WIDGET_CLASS = QGLWidget;
1414
#endif
1515

1616
#include "definitions.h"
17-
#include "glgenerator.h"
1817

19-
class DataAnalyzer;
18+
class GlGenerator;
2019
class DsoSettings;
2120

2221
////////////////////////////////////////////////////////////////////////////////

openhantek/src/hantek/hantekdsocontrol.cpp

+12-45
Original file line numberDiff line numberDiff line change
@@ -1766,19 +1766,7 @@ double HantekDsoControl::setPretriggerPosition(double position) {
17661766
return (double)positionSamples / settings.samplerate.current;
17671767
}
17681768

1769-
#ifdef DEBUG
1770-
/// \brief Sends bulk/control commands directly.
1771-
/// <p>
1772-
/// <b>Syntax:</b><br />
1773-
/// <br />
1774-
/// Bulk command:
1775-
/// <pre>send bulk [<em>hex data</em>]</pre>
1776-
/// %Control command:
1777-
/// <pre>send control [<em>hex code</em>] [<em>hex data</em>]</pre>
1778-
/// </p>
1779-
/// \param command The command as string (Has to be parsed).
1780-
/// \return See ::Dso::ErrorCode.
1781-
int Control::stringCommand(QString command) {
1769+
int HantekDsoControl::stringCommand(QString command) {
17821770
if (!this->device->isConnected())
17831771
return Dso::ERROR_CONNECTION;
17841772

@@ -1832,7 +1820,6 @@ int Control::stringCommand(QString command) {
18321820

18331821
return Dso::ERROR_UNSUPPORTED;
18341822
}
1835-
#endif
18361823

18371824
void HantekDsoControl::run() {
18381825
int errorCode = 0;
@@ -1842,12 +1829,9 @@ void HantekDsoControl::run() {
18421829
if (!this->commandPending[command])
18431830
continue;
18441831

1845-
#ifdef DEBUG
1846-
timestampDebug(
1847-
QString("Sending bulk command:%1")
1832+
timestampDebug(QString("Sending bulk command:%1")
18481833
.arg(hexDump(this->command[command]->data(),
18491834
this->command[command]->getSize())));
1850-
#endif
18511835

18521836
errorCode = this->device->bulkCommand(this->command[command]);
18531837
if (errorCode < 0) {
@@ -1867,13 +1851,11 @@ void HantekDsoControl::run() {
18671851
if (!this->controlPending[control])
18681852
continue;
18691853

1870-
#ifdef DEBUG
18711854
timestampDebug(
18721855
QString("Sending control command %1:%2")
18731856
.arg(QString::number(this->controlCode[control], 16),
18741857
hexDump(this->control[control]->data(),
18751858
this->control[control]->getSize())));
1876-
#endif
18771859

18781860
errorCode = this->device->controlWrite(this->controlCode[control],
18791861
this->control[control]->data(),
@@ -1917,9 +1899,8 @@ void HantekDsoControl::run() {
19171899
}
19181900
break;
19191901
}
1920-
#ifdef DEBUG
1902+
19211903
timestampDebug("Starting to capture");
1922-
#endif
19231904

19241905
this->_samplingStarted = true;
19251906

@@ -1934,9 +1915,8 @@ void HantekDsoControl::run() {
19341915
}
19351916
break;
19361917
}
1937-
#ifdef DEBUG
1918+
19381919
timestampDebug("Enabling trigger");
1939-
#endif
19401920

19411921
break;
19421922

@@ -1949,9 +1929,8 @@ void HantekDsoControl::run() {
19491929
}
19501930
break;
19511931
}
1952-
#ifdef DEBUG
1932+
19531933
timestampDebug("Forcing trigger");
1954-
#endif
19551934

19561935
break;
19571936

@@ -1961,11 +1940,9 @@ void HantekDsoControl::run() {
19611940
if (errorCode < 0)
19621941
qWarning("Getting sample data failed: %s",
19631942
libUsbErrorString(errorCode).toLocal8Bit().data());
1964-
#ifdef DEBUG
19651943
else
19661944
timestampDebug(
19671945
QString("Received %1 B of sampling data").arg(errorCode));
1968-
#endif
19691946

19701947
// Check if we're in single trigger mode
19711948
if (settings.trigger.mode == Dso::TRIGGERMODE_SINGLE &&
@@ -1978,9 +1955,7 @@ void HantekDsoControl::run() {
19781955
break;
19791956

19801957
default:
1981-
#ifdef DEBUG
19821958
timestampDebug("Roll mode state unknown");
1983-
#endif
19841959
break;
19851960
}
19861961

@@ -1991,19 +1966,17 @@ void HantekDsoControl::run() {
19911966
// Standard mode
19921967
this->rollState = ROLL_STARTSAMPLING;
19931968

1994-
#ifdef DEBUG
1995-
int lastCaptureState = this->captureState;
1996-
#endif
1969+
const int lastCaptureState = this->captureState;
19971970
this->captureState = this->getCaptureState();
19981971
if (this->captureState < 0)
19991972
qWarning(
20001973
"Getting capture state failed: %s",
20011974
libUsbErrorString(this->captureState).toLocal8Bit().data());
2002-
#ifdef DEBUG
1975+
20031976
else if (this->captureState != lastCaptureState)
20041977
timestampDebug(
20051978
QString("Capture state changed to %1").arg(this->captureState));
2006-
#endif
1979+
20071980
switch (this->captureState) {
20081981
case CAPTURE_READY:
20091982
case CAPTURE_READY2250:
@@ -2013,11 +1986,8 @@ void HantekDsoControl::run() {
20131986
if (errorCode < 0)
20141987
qWarning("Getting sample data failed: %s",
20151988
libUsbErrorString(errorCode).toLocal8Bit().data());
2016-
#ifdef DEBUG
20171989
else
2018-
timestampDebug(
2019-
QString("Received %1 B of sampling data").arg(errorCode));
2020-
#endif
1990+
timestampDebug(QString("Received %1 B of sampling data").arg(errorCode));
20211991

20221992
// Check if we're in single trigger mode
20231993
if (settings.trigger.mode == Dso::TRIGGERMODE_SINGLE &&
@@ -2054,9 +2024,8 @@ void HantekDsoControl::run() {
20542024
}
20552025
break;
20562026
}
2057-
#ifdef DEBUG
2027+
20582028
timestampDebug("Enabling trigger");
2059-
#endif
20602029
} else if (this->cycleCounter >= 8 + this->startCycle &&
20612030
settings.trigger.mode == Dso::TRIGGERMODE_AUTO) {
20622031
// Force triggering
@@ -2069,9 +2038,8 @@ void HantekDsoControl::run() {
20692038
}
20702039
break;
20712040
}
2072-
#ifdef DEBUG
2041+
20732042
timestampDebug("Forcing trigger");
2074-
#endif
20752043
}
20762044

20772045
if (this->cycleCounter < 20 ||
@@ -2088,9 +2056,8 @@ void HantekDsoControl::run() {
20882056
}
20892057
break;
20902058
}
2091-
#ifdef DEBUG
2059+
20922060
timestampDebug("Starting to capture");
2093-
#endif
20942061

20952062
this->_samplingStarted = true;
20962063
this->cycleCounter = 0;

openhantek/src/hantek/hantekdsocontrol.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ class HantekDsoControl : public QObject {
4545
const USBDevice* getDevice() const;
4646
const DSOsamples& getLastSamples();
4747

48+
/// \brief Sends bulk/control commands directly.
49+
/// <p>
50+
/// <b>Syntax:</b><br />
51+
/// <br />
52+
/// Bulk command:
53+
/// <pre>send bulk [<em>hex data</em>]</pre>
54+
/// %Control command:
55+
/// <pre>send control [<em>hex code</em>] [<em>hex data</em>]</pre>
56+
/// </p>
57+
/// \param command The command as string (Has to be parsed).
58+
/// \return See ::Dso::ErrorCode.
59+
int stringCommand(QString command);
4860
signals:
4961
void samplingStarted(); ///< The oscilloscope started sampling/waiting for trigger
5062
void samplingStopped(); ///< The oscilloscope stopped sampling/waiting for trigger
@@ -120,8 +132,4 @@ public slots:
120132
int setTriggerSlope(Dso::Slope slope);
121133
double setPretriggerPosition(double position);
122134
int forceTrigger();
123-
124-
#ifdef DEBUG
125-
int stringCommand(QString command);
126-
#endif
127135
};

openhantek/src/hantek/usb/finddevices.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// SPDX-License-Identifier: GPL-2.0+
22

3+
#include "finddevices.h"
4+
35
#include <QList>
46
#include <QCoreApplication>
57
#include <QDebug>
68
#include <QTemporaryFile>
79

8-
#include "finddevices.h"
10+
#include <libusb-1.0/libusb.h>
911
#include "utils/printutils.h"
1012
#include "ezusb.h"
1113

openhantek/src/hantek/usb/finddevices.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
#pragma once
44

5-
#include <libusb-1.0/libusb.h>
65
#include <memory>
76
#include <QString>
87

98
#include "definitions.h"
109
#include "usbdevice.h"
1110

11+
struct libusb_context;
12+
1213
/**
1314
* @brief Search for Hantek devices and connect to the selected one.
1415
*

0 commit comments

Comments
 (0)