Skip to content

Commit df55001

Browse files
committed
close #45; ctrl scroll wheel zooms, scroll wheel shifts zoom range
Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
1 parent 1dad788 commit df55001

22 files changed

+179
-104
lines changed

CMakeLists.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ include(cmake/CPackInfos.cmake)
2121
if(MSVC)
2222
add_compile_options(/W4 -D_CRT_SECURE_NO_WARNINGS)
2323
else()
24-
add_compile_options(-Wall -Wextra -pedantic -Wno-psabi)
24+
add_compile_options(-Wall -Wextra -pedantic)
25+
endif()
26+
27+
# Silence nasty warnings "parameter passing for argument of type ... changed in GCC 7.1"
28+
if(CMAKE_COMPILER_IS_GNUCXX)
29+
add_compile_options(-Wno-psabi)
2530
endif()
2631

2732
# enable extra feature(s)

openhantek/src/OH_BUILD.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Do not edit, will be re-created at each commit!
2-
#define OH_BUILD "20200620 build 707"
2+
#define OH_BUILD "20200623 build 709"

openhantek/src/OH_VERSION.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// define the version that is shown on top of the program
22
// if undefined (for development commits) the build will be shown by OpenHantek
33

4-
#define OH_VERSION "3.1.1-rc1"
4+
#define OH_VERSION "3.1.1-rc2"
55

66
#ifdef OH_VERSION
77
#undef VERSION

openhantek/src/configdialog/DsoConfigScopePage.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,30 @@ DsoConfigScopePage::DsoConfigScopePage( DsoSettings *settings, QWidget *parent )
7979
defaultSettingsCheckBox = new QCheckBox( tr( "Apply default settings after next restart" ) );
8080
defaultSettingsCheckBox->setChecked( 0 == settings->configVersion );
8181
saveNowButton = new QPushButton( tr( "Save settings now" ) );
82-
83-
configurationLayout = new QVBoxLayout();
84-
configurationLayout->addWidget( saveOnExitCheckBox, 0 );
85-
configurationLayout->addWidget( defaultSettingsCheckBox, 1 );
86-
configurationLayout->addWidget( saveNowButton, 2 );
82+
hasACmodificationCheckBox =
83+
new QCheckBox( tr( "Scope has hardware modification for AC coupling (restart needed to apply the change)" ) );
84+
hasACmodificationCheckBox->setChecked( settings->scope.hasACmodification );
85+
86+
configurationLayout = new QGridLayout();
87+
configurationLayout->addWidget( saveOnExitCheckBox, 0, 0 );
88+
configurationLayout->addWidget( saveNowButton, 0, 1 );
89+
configurationLayout->addWidget( defaultSettingsCheckBox, 1, 0, 1, 2 );
90+
if ( settings->scope.hasACcoupling ) {
91+
hasACmodificationCheckBox->setChecked( true ); // check but do not show the box
92+
} else {
93+
configurationLayout->addWidget( hasACmodificationCheckBox, 2, 0, 1, 2 ); // show it
94+
}
8795

8896
configurationGroup = new QGroupBox( tr( "Configuration" ) );
8997
configurationGroup->setLayout( configurationLayout );
9098

9199

92100
mainLayout = new QVBoxLayout();
93-
mainLayout->addWidget( configurationGroup );
94101
mainLayout->addWidget( horizontalGroup );
95102
mainLayout->addWidget( graphGroup );
96103
mainLayout->addWidget( exportGroup );
97104
mainLayout->addWidget( cursorsGroup );
105+
mainLayout->addWidget( configurationGroup );
98106
mainLayout->addStretch( 1 );
99107

100108
setLayout( mainLayout );
@@ -103,6 +111,7 @@ DsoConfigScopePage::DsoConfigScopePage( DsoSettings *settings, QWidget *parent )
103111

104112
/// \brief Saves the new settings.
105113
void DsoConfigScopePage::saveSettings() {
114+
settings->scope.hasACmodification = hasACmodificationCheckBox->isChecked();
106115
settings->scope.horizontal.maxTimebase = maxTimebaseSiSpinBox->value();
107116
settings->scope.horizontal.acquireInterval = acquireIntervalSiSpinBox->value();
108117
settings->view.interpolation = Dso::InterpolationMode( interpolationComboBox->currentIndex() );

openhantek/src/configdialog/DsoConfigScopePage.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class DsoConfigScopePage : public QWidget {
5353
QComboBox *cursorsComboBox;
5454

5555
QGroupBox *configurationGroup;
56-
QVBoxLayout *configurationLayout;
56+
QGridLayout *configurationLayout;
57+
QCheckBox *hasACmodificationCheckBox;
5758
QCheckBox *saveOnExitCheckBox;
5859
QCheckBox *defaultSettingsCheckBox;
5960
QPushButton *saveNowButton;

openhantek/src/docks/VoltageDock.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ template < typename... Args > struct SELECT {
2323

2424
VoltageDock::VoltageDock( DsoSettingsScope *scope, const Dso::ControlSpecification *spec, QWidget *parent, Qt::WindowFlags flags )
2525
: QDockWidget( tr( "Voltage" ), parent, flags ), scope( scope ), spec( spec ) {
26-
2726
// Initialize lists for comboboxes
2827
for ( Dso::Coupling c : spec->couplings )
29-
couplingStrings.append( Dso::couplingString( c ) );
28+
if ( c == Dso::Coupling::DC || scope->hasACcoupling || scope->hasACmodification )
29+
couplingStrings.append( Dso::couplingString( c ) );
3030

3131
for ( auto e : Dso::MathModeEnum ) {
3232
modeStrings.append( Dso::mathModeString( e ) );

openhantek/src/dsosettings.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <QSettings>
77

88
#include "dsosettings.h"
9-
109
#include "dsowidget.h"
1110

1211
/// \brief Set the number of channels.
@@ -15,6 +14,7 @@ DsoSettings::DsoSettings( const Dso::ControlSpecification *deviceSpecification )
1514
// Add new channels to the list
1615
unsigned char trace_hue[] = {60, 240, 0, 120}; // yellow, blue, red, green
1716
unsigned index = 0;
17+
scope.hasACcoupling = deviceSpecification->hasACcoupling;
1818
while ( scope.spectrum.size() < deviceSpecification->channels ) {
1919
// Spectrum
2020
DsoSettingsScopeSpectrum newSpectrum;
@@ -139,14 +139,17 @@ void DsoSettings::load() {
139139
}
140140
// Voltage
141141
bool defaultConfig = deviceSpecification->isDemoDevice; // use default channel setting in demo mode
142+
if ( storeSettings->contains( "hasACmodification" ) )
143+
scope.hasACmodification = storeSettings->value( "hasACmodification" ).toBool();
142144
for ( ChannelID channel = 0; channel < scope.voltage.size(); ++channel ) {
143145
storeSettings->beginGroup( QString( "voltage%1" ).arg( channel ) );
144146
if ( storeSettings->contains( "gainStepIndex" ) )
145147
scope.voltage[ channel ].gainStepIndex = storeSettings->value( "gainStepIndex" ).toUInt();
146148
if ( storeSettings->contains( "couplingOrMathIndex" ) ) {
147149
scope.voltage[ channel ].couplingOrMathIndex = storeSettings->value( "couplingOrMathIndex" ).toUInt();
148150
if ( channel < deviceSpecification->channels )
149-
if ( scope.voltage[ channel ].couplingOrMathIndex >= deviceSpecification->couplings.size() )
151+
if ( scope.voltage[ channel ].couplingOrMathIndex >= deviceSpecification->couplings.size() ||
152+
( !scope.hasACcoupling && !scope.hasACmodification ) )
150153
scope.voltage[ channel ].couplingOrMathIndex = 0; // set to default if out of range
151154
}
152155
if ( storeSettings->contains( "inverted" ) )
@@ -306,6 +309,7 @@ void DsoSettings::save() {
306309
storeSettings->endGroup(); // spectrum%1
307310
}
308311
// Voltage
312+
storeSettings->setValue( "hasACmodification", scope.hasACmodification );
309313
for ( ChannelID channel = 0; channel < scope.voltage.size(); ++channel ) {
310314
storeSettings->beginGroup( QString( "voltage%1" ).arg( channel ) );
311315
storeSettings->setValue( "gainStepIndex", scope.voltage[ channel ].gainStepIndex );

openhantek/src/glscope.cpp

+47-10
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ GlScope::GlScope( DsoSettingsScope *scope, DsoSettingsView *view, QWidget *paren
8585
GlScope::~GlScope() { /* virtual destructor necessary */
8686
}
8787

88-
QPointF GlScope::eventToPosition( QMouseEvent *event ) {
89-
QPointF position( double( event->x() - width() / 2 ) * DIVS_TIME / double( width() ),
90-
double( height() / 2 - event->y() ) * DIVS_VOLTAGE / double( height() ) );
88+
QPointF GlScope::posToPosition( QPoint pos ) {
89+
QPointF position( double( pos.x() - width() / 2 ) * DIVS_TIME / double( width() ),
90+
double( height() / 2 - pos.y() ) * DIVS_VOLTAGE / double( height() ) );
9191
if ( zoomed ) {
9292
double m1 = scope->getMarker( 0 );
9393
double m2 = scope->getMarker( 1 );
@@ -100,7 +100,7 @@ QPointF GlScope::eventToPosition( QMouseEvent *event ) {
100100

101101
void GlScope::mousePressEvent( QMouseEvent *event ) {
102102
if ( !( zoomed && selectedCursor == 0 ) && event->button() == Qt::LeftButton ) {
103-
QPointF position = eventToPosition( event );
103+
QPointF position = posToPosition( event->pos() );
104104
selectedMarker = NO_MARKER;
105105
DsoSettingsScopeCursor *cursor = cursorInfo[ selectedCursor ];
106106
// Capture nearest marker located within snap area (+/- 1% of full scale).
@@ -151,7 +151,7 @@ void GlScope::mousePressEvent( QMouseEvent *event ) {
151151

152152
void GlScope::mouseMoveEvent( QMouseEvent *event ) {
153153
if ( !( zoomed && selectedCursor == 0 ) && ( event->buttons() & Qt::LeftButton ) != 0 ) {
154-
QPointF position = eventToPosition( event );
154+
QPointF position = posToPosition( event->pos() );
155155
if ( selectedMarker == NO_MARKER ) {
156156
// qDebug() << "mouseMoveEvent";
157157
// User started draging outside the snap area of any marker:
@@ -171,7 +171,7 @@ void GlScope::mouseMoveEvent( QMouseEvent *event ) {
171171

172172
void GlScope::mouseReleaseEvent( QMouseEvent *event ) {
173173
if ( !( zoomed && selectedCursor == 0 ) && event->button() == Qt::LeftButton ) {
174-
QPointF position = eventToPosition( event );
174+
QPointF position = posToPosition( event->pos() );
175175
if ( selectedMarker < 2 ) {
176176
// qDebug() << "mouseReleaseEvent";
177177
cursorInfo[ selectedCursor ]->pos[ selectedMarker ] = position;
@@ -185,13 +185,13 @@ void GlScope::mouseReleaseEvent( QMouseEvent *event ) {
185185
void GlScope::mouseDoubleClickEvent( QMouseEvent *event ) {
186186
if ( !( zoomed && selectedCursor == 0 ) && ( event->buttons() & Qt::LeftButton ) != 0 ) {
187187
// left double click positions two markers left and right of clicked pos with zoom=100
188-
QPointF position = eventToPosition( event );
188+
QPointF position = posToPosition( event->pos() );
189189
if ( selectedMarker == NO_MARKER ) {
190190
// User double clicked outside the snap area of any marker
191-
QPointF p = QPointF( 0.5, 0 ); // 10x zoom
192-
if ( event->modifiers() & Qt::SHIFT ) // 100x zoom
191+
QPointF p = QPointF( 0.5, 0 ); // 10x zoom
192+
if ( event->modifiers() & Qt::CTRL ) // 100x zoom
193193
p /= 10;
194-
if ( event->modifiers() & Qt::CTRL ) // center at trigger position
194+
if ( event->modifiers() & Qt::SHIFT ) // center at trigger position
195195
position = QPointF( 10 * scope->trigger.offset - 5, 0 );
196196
// move 1st marker left of current position.
197197
cursorInfo[ selectedCursor ]->pos[ 0 ] = position - p;
@@ -212,6 +212,43 @@ void GlScope::mouseDoubleClickEvent( QMouseEvent *event ) {
212212
event->accept();
213213
}
214214

215+
216+
void GlScope::wheelEvent( QWheelEvent *event ) {
217+
static std::vector< int > zoomList = {1, 2, 5, 10, 20, 50, 100, 200, 500};
218+
if ( !( zoomed && selectedCursor == 0 ) ) {
219+
if ( selectedMarker == NO_MARKER ) {
220+
double step = event->angleDelta().y() / 1200.0; // one click = 0.1
221+
// qDebug() << "wheeelEvent" << selectedCursor << event->globalPos() << step;
222+
double &m1 = cursorInfo[ selectedCursor ]->pos[ 0 ].rx();
223+
double &m2 = cursorInfo[ selectedCursor ]->pos[ 1 ].rx();
224+
if ( m1 > m2 )
225+
std::swap( m1, m2 );
226+
double dm = m2 - m1;
227+
if ( event->modifiers() & Qt::CTRL ) { // zoom in/out
228+
if ( ( step > 0 && dm <= 1 ) || ( step < 0 && dm < 1 ) )
229+
step *= 0.1;
230+
if ( dm >= 3 * step ) {
231+
m1 += step;
232+
m2 -= step;
233+
}
234+
} else {
235+
if ( step < 0 ) { // shift zoom range left ..
236+
step = qMax( step, MARGIN_LEFT - m1 ); // .. until m1 == MARGIN_LEFT
237+
} else { // shift zoom range right ..
238+
step = qMin( step, MARGIN_RIGHT - m2 ); // .. until m2 == MARGIN_RIGHT
239+
}
240+
m1 += step;
241+
m2 += step;
242+
}
243+
}
244+
emit markerMoved( selectedCursor, 0 );
245+
emit markerMoved( selectedCursor, 1 );
246+
selectedMarker = NO_MARKER;
247+
}
248+
event->accept();
249+
}
250+
251+
215252
void GlScope::paintEvent( QPaintEvent *event ) {
216253
if ( shaderCompileSuccess ) {
217254
QOpenGLWidget::paintEvent( event );

openhantek/src/glscope.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class GlScope : public QOpenGLWidget {
7070
void mouseMoveEvent( QMouseEvent *event ) override;
7171
void mouseReleaseEvent( QMouseEvent *event ) override;
7272
void mouseDoubleClickEvent( QMouseEvent *event ) override;
73+
void wheelEvent( QWheelEvent *event ) override;
7374
void paintEvent( QPaintEvent *event ) override;
7475

7576
/// \brief Draw the grid.
@@ -82,7 +83,7 @@ class GlScope : public QOpenGLWidget {
8283
void drawVoltageChannelGraph( ChannelID channel, Graph &graph, int historyIndex );
8384
void drawHistogramChannelGraph( ChannelID channel, Graph &graph, int historyIndex );
8485
void drawSpectrumChannelGraph( ChannelID channel, Graph &graph, int historyIndex );
85-
QPointF eventToPosition( QMouseEvent *event );
86+
QPointF posToPosition( QPoint pos );
8687
signals:
8788
void markerMoved( unsigned cursorIndex, unsigned marker );
8889

openhantek/src/hantekdso/capturing.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ unsigned Capturing::getRealSamples() {
159159

160160

161161
unsigned Capturing::getDemoSamples() {
162-
const uint8_t V_zero = 0x80; // ADC = 0V
163-
const int8_t V_plus_1 = 25; // ADC = 1V
164-
const int8_t V_plus_2 = 50; // ADC = 2V
165-
const int8_t V_minus_2 = -50; // ADC = -2V
162+
const uint8_t binaryOffset = 0x80; // ADC format: binary offset
163+
const int8_t V_zero = 0; // ADC = 0V
164+
const int8_t V_plus_1 = 25; // ADC = 1V
165+
const int8_t V_plus_2 = 50; // ADC = 2V
166+
const int8_t V_minus_1 = -25; // ADC = -1V
167+
const int8_t V_minus_2 = -50; // ADC = -2V
166168
const int gain1 = int( gainValue[ 0 ] );
167169
const int gain2 = int( gainValue[ 1 ] );
168170
static int ch1 = 0;
@@ -182,21 +184,26 @@ unsigned Capturing::getDemoSamples() {
182184
deltaT = int( round( deltaT * samplerate / 10e6 ) );
183185
const unsigned packetLength = 512 * 78; // 50 blocks for one screen width of 20000
184186
unsigned block = 0;
185-
dp->resize( rawSamplesize, V_zero );
187+
dp->resize( rawSamplesize, binaryOffset );
186188
auto end = dp->end();
187189
unsigned packet = 0;
190+
// bool couplingAC1 = hdc->scope->coupling( 0, hdc->specification ) == Dso::Coupling::AC;
191+
bool couplingAC2 = hdc->scope->coupling( 1, hdc->specification ) == Dso::Coupling::AC;
188192
for ( auto it = dp->begin(); it != end; ++it ) {
189193
if ( ++counter >= deltaT ) {
190194
counter = 0;
191195
if ( --ch1 < V_minus_2 ) {
192196
ch1 = V_plus_2;
193-
ch2 = ch2 <= V_plus_1 ? V_plus_2 : 0;
197+
if ( couplingAC2 )
198+
ch2 = ch2 <= V_zero ? V_plus_1 : V_minus_1; // -1V <-> +1V
199+
else
200+
ch2 = ch2 <= V_plus_1 ? V_plus_2 : V_zero; // 0V <-> 2V
194201
}
195202
}
196-
*it = uint8_t( qBound( 0, ch1 * gain1 + V_zero, 0xFF ) ); // simulate clipping
203+
*it = uint8_t( qBound( 0, ch1 * gain1 + binaryOffset, 0xFF ) ); // clip if outside 8bit range
197204
++received;
198205
if ( 2 == channels ) {
199-
*++it = uint8_t( qBound( 0, ch2 * gain2 + V_zero, 0xFF ) ); // simulate clipping
206+
*++it = uint8_t( qBound( 0, ch2 * gain2 + binaryOffset, 0xFF ) ); // clip ..
200207
++received;
201208
}
202209
if ( ( block += channels ) >= packetLength ) {

openhantek/src/hantekdso/controlspecification.h

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct ControlSpecification {
6666
std::vector< Coupling > couplings = {Dso::Coupling::DC, Dso::Coupling::AC};
6767
std::vector< TriggerMode > triggerModes = {TriggerMode::NONE, TriggerMode::AUTO, TriggerMode::NORMAL, TriggerMode::SINGLE};
6868
int fixedUSBinLength = 0;
69+
bool hasACcoupling = false;
6970

7071
QList< double > calfreqSteps;
7172
};

openhantek/src/hantekdso/models/modelDDS120.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ static void initSpecifications( Dso::ControlSpecification &specification ) {
129129

130130

131131
specification.couplings = {Dso::Coupling::DC, Dso::Coupling::AC};
132+
specification.hasACcoupling = true; // DDS120 has AC coupling
132133
specification.triggerModes = {
133134
Dso::TriggerMode::NONE,
134135
Dso::TriggerMode::AUTO,

openhantek/src/hantekdso/models/modelDEMO.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ static void initSpecifications( Dso::ControlSpecification &specification ) {
109109
{48e6, 48, 1} //
110110
};
111111

112-
specification.couplings = {Dso::Coupling::DC};
112+
// AC requires AC/DC HW mod like DDS120, enable with "cmake -D HANTEK_AC=1 .." or config option
113+
specification.couplings = {Dso::Coupling::DC, Dso::Coupling::AC};
114+
#ifdef HANTEK_AC
115+
specification.hasACcoupling = true;
116+
#else
117+
specification.hasACcoupling = false;
118+
#endif
113119
specification.triggerModes = {
114120
Dso::TriggerMode::NONE,
115121
Dso::TriggerMode::AUTO,

openhantek/src/hantekdso/models/modelDSO6022.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,12 @@ static void initSpecifications( Dso::ControlSpecification &specification ) {
130130
{48e6, 48, 1} //
131131
};
132132

133-
#ifdef HANTEK_AC
134-
// requires AC/DC HW mod like DDS120, enable with "cmake -D HANTEK_AC=1 .."
133+
// AC requires AC/DC HW mod like DDS120, enable with "cmake -D HANTEK_AC=1 .." or config option
135134
specification.couplings = {Dso::Coupling::DC, Dso::Coupling::AC};
135+
#ifdef HANTEK_AC
136+
specification.hasACcoupling = true;
136137
#else
137-
specification.couplings = {Dso::Coupling::DC};
138+
specification.hasACcoupling = false;
138139
#endif
139140
specification.triggerModes = {
140141
Dso::TriggerMode::NONE,

0 commit comments

Comments
 (0)