Skip to content

Commit

Permalink
close #45; ctrl scroll wheel zooms, scroll wheel shifts zoom range
Browse files Browse the repository at this point in the history
Signed-off-by: Martin <[email protected]>
  • Loading branch information
Ho-Ro committed Jun 23, 2020
1 parent 1dad788 commit df55001
Show file tree
Hide file tree
Showing 22 changed files with 179 additions and 104 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ include(cmake/CPackInfos.cmake)
if(MSVC)
add_compile_options(/W4 -D_CRT_SECURE_NO_WARNINGS)
else()
add_compile_options(-Wall -Wextra -pedantic -Wno-psabi)
add_compile_options(-Wall -Wextra -pedantic)
endif()

# Silence nasty warnings "parameter passing for argument of type ... changed in GCC 7.1"
if(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-Wno-psabi)
endif()

# enable extra feature(s)
Expand Down
2 changes: 1 addition & 1 deletion openhantek/src/OH_BUILD.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Do not edit, will be re-created at each commit!
#define OH_BUILD "20200620 build 707"
#define OH_BUILD "20200623 build 709"
2 changes: 1 addition & 1 deletion openhantek/src/OH_VERSION.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// define the version that is shown on top of the program
// if undefined (for development commits) the build will be shown by OpenHantek

#define OH_VERSION "3.1.1-rc1"
#define OH_VERSION "3.1.1-rc2"

#ifdef OH_VERSION
#undef VERSION
Expand Down
21 changes: 15 additions & 6 deletions openhantek/src/configdialog/DsoConfigScopePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,30 @@ DsoConfigScopePage::DsoConfigScopePage( DsoSettings *settings, QWidget *parent )
defaultSettingsCheckBox = new QCheckBox( tr( "Apply default settings after next restart" ) );
defaultSettingsCheckBox->setChecked( 0 == settings->configVersion );
saveNowButton = new QPushButton( tr( "Save settings now" ) );

configurationLayout = new QVBoxLayout();
configurationLayout->addWidget( saveOnExitCheckBox, 0 );
configurationLayout->addWidget( defaultSettingsCheckBox, 1 );
configurationLayout->addWidget( saveNowButton, 2 );
hasACmodificationCheckBox =
new QCheckBox( tr( "Scope has hardware modification for AC coupling (restart needed to apply the change)" ) );
hasACmodificationCheckBox->setChecked( settings->scope.hasACmodification );

configurationLayout = new QGridLayout();
configurationLayout->addWidget( saveOnExitCheckBox, 0, 0 );
configurationLayout->addWidget( saveNowButton, 0, 1 );
configurationLayout->addWidget( defaultSettingsCheckBox, 1, 0, 1, 2 );
if ( settings->scope.hasACcoupling ) {
hasACmodificationCheckBox->setChecked( true ); // check but do not show the box
} else {
configurationLayout->addWidget( hasACmodificationCheckBox, 2, 0, 1, 2 ); // show it
}

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


mainLayout = new QVBoxLayout();
mainLayout->addWidget( configurationGroup );
mainLayout->addWidget( horizontalGroup );
mainLayout->addWidget( graphGroup );
mainLayout->addWidget( exportGroup );
mainLayout->addWidget( cursorsGroup );
mainLayout->addWidget( configurationGroup );
mainLayout->addStretch( 1 );

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

/// \brief Saves the new settings.
void DsoConfigScopePage::saveSettings() {
settings->scope.hasACmodification = hasACmodificationCheckBox->isChecked();
settings->scope.horizontal.maxTimebase = maxTimebaseSiSpinBox->value();
settings->scope.horizontal.acquireInterval = acquireIntervalSiSpinBox->value();
settings->view.interpolation = Dso::InterpolationMode( interpolationComboBox->currentIndex() );
Expand Down
3 changes: 2 additions & 1 deletion openhantek/src/configdialog/DsoConfigScopePage.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class DsoConfigScopePage : public QWidget {
QComboBox *cursorsComboBox;

QGroupBox *configurationGroup;
QVBoxLayout *configurationLayout;
QGridLayout *configurationLayout;
QCheckBox *hasACmodificationCheckBox;
QCheckBox *saveOnExitCheckBox;
QCheckBox *defaultSettingsCheckBox;
QPushButton *saveNowButton;
Expand Down
4 changes: 2 additions & 2 deletions openhantek/src/docks/VoltageDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ template < typename... Args > struct SELECT {

VoltageDock::VoltageDock( DsoSettingsScope *scope, const Dso::ControlSpecification *spec, QWidget *parent, Qt::WindowFlags flags )
: QDockWidget( tr( "Voltage" ), parent, flags ), scope( scope ), spec( spec ) {

// Initialize lists for comboboxes
for ( Dso::Coupling c : spec->couplings )
couplingStrings.append( Dso::couplingString( c ) );
if ( c == Dso::Coupling::DC || scope->hasACcoupling || scope->hasACmodification )
couplingStrings.append( Dso::couplingString( c ) );

for ( auto e : Dso::MathModeEnum ) {
modeStrings.append( Dso::mathModeString( e ) );
Expand Down
8 changes: 6 additions & 2 deletions openhantek/src/dsosettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <QSettings>

#include "dsosettings.h"

#include "dsowidget.h"

/// \brief Set the number of channels.
Expand All @@ -15,6 +14,7 @@ DsoSettings::DsoSettings( const Dso::ControlSpecification *deviceSpecification )
// Add new channels to the list
unsigned char trace_hue[] = {60, 240, 0, 120}; // yellow, blue, red, green
unsigned index = 0;
scope.hasACcoupling = deviceSpecification->hasACcoupling;
while ( scope.spectrum.size() < deviceSpecification->channels ) {
// Spectrum
DsoSettingsScopeSpectrum newSpectrum;
Expand Down Expand Up @@ -139,14 +139,17 @@ void DsoSettings::load() {
}
// Voltage
bool defaultConfig = deviceSpecification->isDemoDevice; // use default channel setting in demo mode
if ( storeSettings->contains( "hasACmodification" ) )
scope.hasACmodification = storeSettings->value( "hasACmodification" ).toBool();
for ( ChannelID channel = 0; channel < scope.voltage.size(); ++channel ) {
storeSettings->beginGroup( QString( "voltage%1" ).arg( channel ) );
if ( storeSettings->contains( "gainStepIndex" ) )
scope.voltage[ channel ].gainStepIndex = storeSettings->value( "gainStepIndex" ).toUInt();
if ( storeSettings->contains( "couplingOrMathIndex" ) ) {
scope.voltage[ channel ].couplingOrMathIndex = storeSettings->value( "couplingOrMathIndex" ).toUInt();
if ( channel < deviceSpecification->channels )
if ( scope.voltage[ channel ].couplingOrMathIndex >= deviceSpecification->couplings.size() )
if ( scope.voltage[ channel ].couplingOrMathIndex >= deviceSpecification->couplings.size() ||
( !scope.hasACcoupling && !scope.hasACmodification ) )
scope.voltage[ channel ].couplingOrMathIndex = 0; // set to default if out of range
}
if ( storeSettings->contains( "inverted" ) )
Expand Down Expand Up @@ -306,6 +309,7 @@ void DsoSettings::save() {
storeSettings->endGroup(); // spectrum%1
}
// Voltage
storeSettings->setValue( "hasACmodification", scope.hasACmodification );
for ( ChannelID channel = 0; channel < scope.voltage.size(); ++channel ) {
storeSettings->beginGroup( QString( "voltage%1" ).arg( channel ) );
storeSettings->setValue( "gainStepIndex", scope.voltage[ channel ].gainStepIndex );
Expand Down
57 changes: 47 additions & 10 deletions openhantek/src/glscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ GlScope::GlScope( DsoSettingsScope *scope, DsoSettingsView *view, QWidget *paren
GlScope::~GlScope() { /* virtual destructor necessary */
}

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

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

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

void GlScope::mouseReleaseEvent( QMouseEvent *event ) {
if ( !( zoomed && selectedCursor == 0 ) && event->button() == Qt::LeftButton ) {
QPointF position = eventToPosition( event );
QPointF position = posToPosition( event->pos() );
if ( selectedMarker < 2 ) {
// qDebug() << "mouseReleaseEvent";
cursorInfo[ selectedCursor ]->pos[ selectedMarker ] = position;
Expand All @@ -185,13 +185,13 @@ void GlScope::mouseReleaseEvent( QMouseEvent *event ) {
void GlScope::mouseDoubleClickEvent( QMouseEvent *event ) {
if ( !( zoomed && selectedCursor == 0 ) && ( event->buttons() & Qt::LeftButton ) != 0 ) {
// left double click positions two markers left and right of clicked pos with zoom=100
QPointF position = eventToPosition( event );
QPointF position = posToPosition( event->pos() );
if ( selectedMarker == NO_MARKER ) {
// User double clicked outside the snap area of any marker
QPointF p = QPointF( 0.5, 0 ); // 10x zoom
if ( event->modifiers() & Qt::SHIFT ) // 100x zoom
QPointF p = QPointF( 0.5, 0 ); // 10x zoom
if ( event->modifiers() & Qt::CTRL ) // 100x zoom
p /= 10;
if ( event->modifiers() & Qt::CTRL ) // center at trigger position
if ( event->modifiers() & Qt::SHIFT ) // center at trigger position
position = QPointF( 10 * scope->trigger.offset - 5, 0 );
// move 1st marker left of current position.
cursorInfo[ selectedCursor ]->pos[ 0 ] = position - p;
Expand All @@ -212,6 +212,43 @@ void GlScope::mouseDoubleClickEvent( QMouseEvent *event ) {
event->accept();
}


void GlScope::wheelEvent( QWheelEvent *event ) {
static std::vector< int > zoomList = {1, 2, 5, 10, 20, 50, 100, 200, 500};
if ( !( zoomed && selectedCursor == 0 ) ) {
if ( selectedMarker == NO_MARKER ) {
double step = event->angleDelta().y() / 1200.0; // one click = 0.1
// qDebug() << "wheeelEvent" << selectedCursor << event->globalPos() << step;
double &m1 = cursorInfo[ selectedCursor ]->pos[ 0 ].rx();
double &m2 = cursorInfo[ selectedCursor ]->pos[ 1 ].rx();
if ( m1 > m2 )
std::swap( m1, m2 );
double dm = m2 - m1;
if ( event->modifiers() & Qt::CTRL ) { // zoom in/out
if ( ( step > 0 && dm <= 1 ) || ( step < 0 && dm < 1 ) )
step *= 0.1;
if ( dm >= 3 * step ) {
m1 += step;
m2 -= step;
}
} else {
if ( step < 0 ) { // shift zoom range left ..
step = qMax( step, MARGIN_LEFT - m1 ); // .. until m1 == MARGIN_LEFT
} else { // shift zoom range right ..
step = qMin( step, MARGIN_RIGHT - m2 ); // .. until m2 == MARGIN_RIGHT
}
m1 += step;
m2 += step;
}
}
emit markerMoved( selectedCursor, 0 );
emit markerMoved( selectedCursor, 1 );
selectedMarker = NO_MARKER;
}
event->accept();
}


void GlScope::paintEvent( QPaintEvent *event ) {
if ( shaderCompileSuccess ) {
QOpenGLWidget::paintEvent( event );
Expand Down
3 changes: 2 additions & 1 deletion openhantek/src/glscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class GlScope : public QOpenGLWidget {
void mouseMoveEvent( QMouseEvent *event ) override;
void mouseReleaseEvent( QMouseEvent *event ) override;
void mouseDoubleClickEvent( QMouseEvent *event ) override;
void wheelEvent( QWheelEvent *event ) override;
void paintEvent( QPaintEvent *event ) override;

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

Expand Down
23 changes: 15 additions & 8 deletions openhantek/src/hantekdso/capturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ unsigned Capturing::getRealSamples() {


unsigned Capturing::getDemoSamples() {
const uint8_t V_zero = 0x80; // ADC = 0V
const int8_t V_plus_1 = 25; // ADC = 1V
const int8_t V_plus_2 = 50; // ADC = 2V
const int8_t V_minus_2 = -50; // ADC = -2V
const uint8_t binaryOffset = 0x80; // ADC format: binary offset
const int8_t V_zero = 0; // ADC = 0V
const int8_t V_plus_1 = 25; // ADC = 1V
const int8_t V_plus_2 = 50; // ADC = 2V
const int8_t V_minus_1 = -25; // ADC = -1V
const int8_t V_minus_2 = -50; // ADC = -2V
const int gain1 = int( gainValue[ 0 ] );
const int gain2 = int( gainValue[ 1 ] );
static int ch1 = 0;
Expand All @@ -182,21 +184,26 @@ unsigned Capturing::getDemoSamples() {
deltaT = int( round( deltaT * samplerate / 10e6 ) );
const unsigned packetLength = 512 * 78; // 50 blocks for one screen width of 20000
unsigned block = 0;
dp->resize( rawSamplesize, V_zero );
dp->resize( rawSamplesize, binaryOffset );
auto end = dp->end();
unsigned packet = 0;
// bool couplingAC1 = hdc->scope->coupling( 0, hdc->specification ) == Dso::Coupling::AC;
bool couplingAC2 = hdc->scope->coupling( 1, hdc->specification ) == Dso::Coupling::AC;
for ( auto it = dp->begin(); it != end; ++it ) {
if ( ++counter >= deltaT ) {
counter = 0;
if ( --ch1 < V_minus_2 ) {
ch1 = V_plus_2;
ch2 = ch2 <= V_plus_1 ? V_plus_2 : 0;
if ( couplingAC2 )
ch2 = ch2 <= V_zero ? V_plus_1 : V_minus_1; // -1V <-> +1V
else
ch2 = ch2 <= V_plus_1 ? V_plus_2 : V_zero; // 0V <-> 2V
}
}
*it = uint8_t( qBound( 0, ch1 * gain1 + V_zero, 0xFF ) ); // simulate clipping
*it = uint8_t( qBound( 0, ch1 * gain1 + binaryOffset, 0xFF ) ); // clip if outside 8bit range
++received;
if ( 2 == channels ) {
*++it = uint8_t( qBound( 0, ch2 * gain2 + V_zero, 0xFF ) ); // simulate clipping
*++it = uint8_t( qBound( 0, ch2 * gain2 + binaryOffset, 0xFF ) ); // clip ..
++received;
}
if ( ( block += channels ) >= packetLength ) {
Expand Down
1 change: 1 addition & 0 deletions openhantek/src/hantekdso/controlspecification.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct ControlSpecification {
std::vector< Coupling > couplings = {Dso::Coupling::DC, Dso::Coupling::AC};
std::vector< TriggerMode > triggerModes = {TriggerMode::NONE, TriggerMode::AUTO, TriggerMode::NORMAL, TriggerMode::SINGLE};
int fixedUSBinLength = 0;
bool hasACcoupling = false;

QList< double > calfreqSteps;
};
Expand Down
1 change: 1 addition & 0 deletions openhantek/src/hantekdso/models/modelDDS120.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ static void initSpecifications( Dso::ControlSpecification &specification ) {


specification.couplings = {Dso::Coupling::DC, Dso::Coupling::AC};
specification.hasACcoupling = true; // DDS120 has AC coupling
specification.triggerModes = {
Dso::TriggerMode::NONE,
Dso::TriggerMode::AUTO,
Expand Down
8 changes: 7 additions & 1 deletion openhantek/src/hantekdso/models/modelDEMO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ static void initSpecifications( Dso::ControlSpecification &specification ) {
{48e6, 48, 1} //
};

specification.couplings = {Dso::Coupling::DC};
// AC requires AC/DC HW mod like DDS120, enable with "cmake -D HANTEK_AC=1 .." or config option
specification.couplings = {Dso::Coupling::DC, Dso::Coupling::AC};
#ifdef HANTEK_AC
specification.hasACcoupling = true;
#else
specification.hasACcoupling = false;
#endif
specification.triggerModes = {
Dso::TriggerMode::NONE,
Dso::TriggerMode::AUTO,
Expand Down
7 changes: 4 additions & 3 deletions openhantek/src/hantekdso/models/modelDSO6022.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ static void initSpecifications( Dso::ControlSpecification &specification ) {
{48e6, 48, 1} //
};

#ifdef HANTEK_AC
// requires AC/DC HW mod like DDS120, enable with "cmake -D HANTEK_AC=1 .."
// AC requires AC/DC HW mod like DDS120, enable with "cmake -D HANTEK_AC=1 .." or config option
specification.couplings = {Dso::Coupling::DC, Dso::Coupling::AC};
#ifdef HANTEK_AC
specification.hasACcoupling = true;
#else
specification.couplings = {Dso::Coupling::DC};
specification.hasACcoupling = false;
#endif
specification.triggerModes = {
Dso::TriggerMode::NONE,
Expand Down
Loading

0 comments on commit df55001

Please sign in to comment.