Skip to content

Commit 0415321

Browse files
committed
new command line options; fast screenshot; doc update
cmd line options --resetSettings, --verbose: Reset persistent settings, start with default values Verbose tracing of the program startup steps (debugging support) make screenshot/hardcopy with default name (date_time.png) without asking Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
1 parent dcac3f7 commit 0415321

17 files changed

+436
-269
lines changed

README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
[![GitHub commits since latest release](https://img.shields.io/github/commits-since/OpenHantek/OpenHantek6022/latest?color=blue)](https://github.com/OpenHantek/OpenHantek6022/commits/master)
66

77
[![GitHub CI](https://github.com/OpenHantek/OpenHantek6022/actions/workflows/build_check.yml/badge.svg)](https://github.com/OpenHantek/OpenHantek6022/actions/workflows/build_check.yml)
8-
[![CodeFactor](https://www.codefactor.io/repository/github/openhantek/openhantek6022/badge)](https://www.codefactor.io/repository/github/openhantek/openhantek6022)
98

109
OpenHantek6022 is a free software for **Hantek DSO6022** USB digital signal oscilloscopes that is actively developed on
1110
[github.com/OpenHantek/OpenHantek6022](https://github.com/OpenHantek/OpenHantek6022) - but only for Hantek 6022BE/BL and compatible scopes (Voltcraft, Darkwire, Protek, Acetech, etc.).
@@ -90,7 +89,7 @@ that builds and packages OpenHantek6022 for:
9089
* Windows (MSVS-2019)
9190

9291
[![GitHub CI](https://github.com/OpenHantek/OpenHantek6022/actions/workflows/build_check.yml/badge.svg)](https://github.com/OpenHantek/OpenHantek6022/actions/workflows/build_check.yml)
93-
This status badge here (and on top of this page) show the build status.
92+
This status badge here (and on top) show the build status.
9493

9594
## Building OpenHantek6022 from source
9695
The preferred way to run OpenHantek is to build it from source on your system,
@@ -108,20 +107,20 @@ To make building for Linux even easier, I provide two shell scripts:
108107
If you make small changes to the local source code, it is sufficient to call `make -j4` or `fakeroot make -j4 package` in the `build` directory.
109108

110109
## Install prebuilt binary packages
111-
* Download Linux (built on Ubuntu 1804 LTS), Raspberry Pi (Debian stable), FreeBSD (12.1), macOS (Catalina) and Windows (Visual Studio 2019) packages for your convenience from the [Releases](https://github.com/OpenHantek/OpenHantek6022/releases) page.
112-
* If you want to follow ongoing development, packages built from the last commit are available in the [unstable release](https://github.com/OpenHantek/OpenHantek6022/releases/tag/unstable).
110+
* Download Linux (built on Ubuntu 1804 LTS), Raspberry Pi (Debian stable), FreeBSD (12.1), macOS (Catalina 10.15) and Windows (Visual Studio 2019) packages for your convenience from the [Releases](https://github.com/OpenHantek/OpenHantek6022/releases) page.
111+
* If you want to follow ongoing development, packages built from a fairly recent commit are available in the [unstable release](https://github.com/OpenHantek/OpenHantek6022/releases/tag/unstable).
113112
* For RPi4 see also [issue #28](https://github.com/OpenHantek/OpenHantek6022/issues/28).
114113
* These binary packages are built on stable operating system versions and require an up-to-date system.
115114
* As I develop on a *Debian stable* system my preferred (native) package format is `*.deb`.
116-
The program itself and the `*.deb` package is tested on my local system for completeness and correctness.
117-
The prebuilt packages are not tested, neither is the installation of the `*.rpm` packages.
115+
The program itself and the `*.deb` package built on my local system is tested for completeness and correctness.
116+
The precompiled packages are only randomly tested - if at all - and the installation of the `*.rpm` packages is untested.
118117
* To install the downloaded `*.deb` package, open a terminal window, go to the package directory and enter the command (as root) `apt install ./openhantek_..._amd64.deb`.
119118
This command will automatically install all dependencies of the program as well.
120119
* For installation of `*.rpm` packages follow similar rules, e.g. `dnf install ./openhantek-...-1.x86_64.rpm`.
121120
* The `*.tar.gz` achives contain the same files as the `*.deb` and `*.rpm` packages for quick testing - do not use for a permanent intallation. Do not report any issues about the `*.tar.gz`!
122121
* Get macOS packages from [macports](https://www.macports.org/ports.php?by=name&substr=openhantek) - thx [ra1nb0w](https://github.com/ra1nb0w).
123122
* Get [Fedora rpm packages](https://pkgs.org/download/openhantek) - thx [Vascom](https://github.com/Vascom).
124-
* Download [(untested) builds from last commit](https://ci.appveyor.com/project/Ho-Ro/openhantek6022). Select the preferred `Image` and go to `Artifacts`.
123+
* Download [(untested) builds from last commit(s)](https://github.com/OpenHantek/OpenHantek6022/actions/workflows/build_check.yml). Select the preferred `workflow run` and go to `Artifacts`.
125124

126125
## Run OpenHantek6022
127126
On a Linux system start the program via the menu entry *OpenHantek (Digital Storage Oscilloscope)* or from a terminal window as `OpenHantek`.

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 "20210418 - commit 891"
2+
#define OH_BUILD "20210423 - commit 892"

openhantek/src/OH_VERSION.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// next line shall define either OH_VERSION or LAST_OH_VERSION
99
//
10-
#define OH_VERSION "3.2.2"
10+
#define LAST_OH_VERSION "3.2.2"
1111

1212

1313
// do not edit below

openhantek/src/dsosettings.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
/// \brief Set the number of channels.
1111
/// \param channels The new channel count, that will be applied to lists.
12-
DsoSettings::DsoSettings( const ScopeDevice *scopeDevice )
12+
DsoSettings::DsoSettings( const ScopeDevice *scopeDevice, bool resetSettings )
1313
: deviceName( scopeDevice->getModel()->name ), deviceID( scopeDevice->getSerialNumber() ),
14-
deviceSpecification( scopeDevice->getModel()->spec() ) {
14+
deviceSpecification( scopeDevice->getModel()->spec() ), resetSettings( resetSettings ) {
1515

1616
// Add new channels to the list
1717
int voltage_hue[] = {60, 210, 0, 120}; // yellow, lightblue, red, green
@@ -51,6 +51,11 @@ DsoSettings::DsoSettings( const ScopeDevice *scopeDevice )
5151
view.print.spectrum.push_back( QColor::fromHsv( 320, 0xff, 0xff ) );
5252

5353
// create an unique storage for this device based on device name and serial number
54+
// individual device settings location:
55+
// Linux, Unix: $HOME/.config/OpenHantek/<deviceName>_<deviceID>.conf
56+
// macOS: $HOME/Library/Preferences/org.openhantek.<deviceName>_<deviceID>.plist
57+
// Windows: HKEY_CURRENT_USER\Software\OpenHantek\<deviceName>_<deviceID>
58+
// more info: https://doc.qt.io/qt-5/qsettings.html#platform-specific-notes
5459
storeSettings =
5560
std::unique_ptr< QSettings >( new QSettings( QCoreApplication::organizationName(), deviceName + "_" + deviceID ) );
5661
// and get the persistent settings
@@ -73,7 +78,7 @@ bool DsoSettings::setFilename( const QString &filename ) {
7378
// called by "DsoSettings::DsoSettings" and explicitely by "ui->actionOpen"
7479
void DsoSettings::load() {
7580
// Start with default configuration?
76-
if ( storeSettings->value( "configuration/version", 0 ).toUInt() < CONFIG_VERSION ) {
81+
if ( resetSettings || storeSettings->value( "configuration/version", 0 ).toUInt() < CONFIG_VERSION ) {
7782
// incompatible change or config reset by user
7883
storeSettings->clear(); // start with a clean config storage
7984
QSettings().clear(); // and a clean global storage

openhantek/src/dsosettings.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DsoSettings {
2222
Q_DECLARE_TR_FUNCTIONS( DsoSettings )
2323

2424
public:
25-
explicit DsoSettings( const ScopeDevice *scopeDevice );
25+
explicit DsoSettings( const ScopeDevice *scopeDevice, bool resetSettings = false );
2626
bool setFilename( const QString &filename );
2727

2828
DsoSettingsScope scope; ///< All oscilloscope related settings
@@ -47,4 +47,5 @@ class DsoSettings {
4747
std::unique_ptr< QSettings > storeSettings;
4848
const Dso::ControlSpecification *deviceSpecification;
4949
void setDefaultConfig();
50+
bool resetSettings = false;
5051
};

openhantek/src/main.cpp

+94-25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QCommandLineParser>
55
#include <QDebug>
66
#include <QDesktopWidget>
7+
#include <QElapsedTimer>
78
#include <QLibraryInfo>
89
#include <QLocale>
910
#include <QStyleFactory>
@@ -48,11 +49,6 @@
4849
#include "exporting/exporterprocessor.h"
4950
#include "exporting/exporterregistry.h"
5051
#include "exporting/exportjson.h"
51-
// legacy img and pdf export is replaced by MainWindow::screenshot()
52-
#ifdef LEGACYEXPORT
53-
#include "exporting/exportimage.h"
54-
#include "exporting/exportprint.h"
55-
#endif
5652

5753
// GUI
5854
#include "iconfont/QtAwesome.h"
@@ -75,9 +71,21 @@ using namespace Hantek;
7571

7672
/// \brief Initialize resources and translations and show the main window.
7773
int main( int argc, char *argv[] ) {
78-
#ifndef Q_OS_WIN
79-
unsetenv( "LANGUAGE" ); // this ENV variable hides the LANG=xx setting, not available under Windows
74+
75+
#ifdef Q_OS_WIN
76+
// Win: close "extra" console window but if started from cmd.exe use this console
77+
if ( FreeConsole() && AttachConsole( ATTACH_PARENT_PROCESS ) ) {
78+
freopen( "CONOUT$", "w", stdout );
79+
freopen( "CONOUT$", "w", stderr );
80+
}
81+
#else
82+
// this ENV variable hides the LANG=xx setting, fkt. not available under Windows
83+
unsetenv( "LANGUAGE" );
8084
#endif
85+
86+
QElapsedTimer startupTime;
87+
startupTime.start(); // time tracking for verbose startup
88+
8189
//////// Set application information ////////
8290
QCoreApplication::setOrganizationName( "OpenHantek" );
8391
QCoreApplication::setOrganizationDomain( "openhantek.org" );
@@ -88,24 +96,23 @@ int main( int argc, char *argv[] ) {
8896
QCoreApplication::setAttribute( Qt::AA_EnableHighDpiScaling, true );
8997
#endif
9098

91-
#ifdef Q_OS_WIN
92-
// close "extra" console window but if started from cmd.exe use this console
93-
if ( FreeConsole() && AttachConsole( ATTACH_PARENT_PROCESS ) ) {
94-
freopen( "CONOUT$", "w", stdout );
95-
freopen( "CONOUT$", "w", stderr );
96-
}
97-
#endif
98-
9999
bool demoMode = false;
100100
bool useGLES = false;
101101
bool useGLSL120 = false;
102102
bool useGLSL150 = false;
103103
bool useLocale = true;
104+
bool verboseStartup = false;
105+
bool resetSettings = false;
104106
QString font = defaultFont; // defined in viewsettings.h
105107
int fontSize = defaultFontSize; // defined in viewsettings.h
106108
int condensed = defaultCondensed; // defined in viewsettings.h
107109

108-
{ // do this once at program start ...
110+
{ // do this early at program start ...
111+
// get font size settings:
112+
// Linux, Unix: $HOME/.config/OpenHantek/OpenHantek6022.conf
113+
// macOS: $HOME/Library/Preferences/org.openhantek.OpenHantek6022.plist
114+
// Windows: HKEY_CURRENT_USER\Software\OpenHantek\OpenHantek6022"
115+
// more info: https://doc.qt.io/qt-5/qsettings.html#platform-specific-notes
109116
QSettings storeSettings;
110117
storeSettings.beginGroup( "view" );
111118
if ( storeSettings.contains( "fontSize" ) )
@@ -135,6 +142,10 @@ int main( int argc, char *argv[] ) {
135142
QCommandLineOption condensedOption(
136143
{"c", "condensed"}, QString( "Set the font condensed value (default = %1)" ).arg( condensed ), "Condensed" );
137144
p.addOption( condensedOption );
145+
QCommandLineOption resetSettingsOption( "resetSettings", "Reset persistent settings, start with default" );
146+
p.addOption( resetSettingsOption );
147+
QCommandLineOption verboseOption( "verbose", "Verbose tracing of the program startup steps" );
148+
p.addOption( verboseOption );
138149
p.process( parserApp );
139150
demoMode = p.isSet( demoModeOption );
140151
useGLES = p.isSet( useGlesOption );
@@ -147,22 +158,28 @@ int main( int argc, char *argv[] ) {
147158
useGLSL120 = p.isSet( useGLSL120Option );
148159
useGLSL150 = p.isSet( useGLSL150Option );
149160
useLocale = !p.isSet( intOption );
161+
verboseStartup = p.isSet( verboseOption );
162+
resetSettings = p.isSet( resetSettingsOption );
150163
} // ... and forget the no more needed variables
151164

152165
#ifdef Q_PROCESSOR_ARM
153166
// HACK: Raspberry Pi crashes with OpenGL, use always OpenGLES
154167
useGLES = true;
155168
#endif
156169

157-
GlScope::useQSurfaceFormat( useGLES ? QSurfaceFormat::OpenGLES : QSurfaceFormat::OpenGL );
158-
if ( useGLSL120 )
159-
GlScope::useOpenGLSLversion( 120 );
160-
else if ( useGLSL150 )
161-
GlScope::useOpenGLSLversion( 150 );
170+
if ( verboseStartup ) {
171+
qDebug() << startupTime.elapsed() << "ms:"
172+
<< "OpenHantek6022 - version" << VERSION;
173+
qDebug() << startupTime.elapsed() << "ms:"
174+
<< "create openHantekApplication";
175+
}
162176
QApplication openHantekApplication( argc, argv );
163177

164178
// Qt5 linux default ("Breeze", "Windows" or "Fusion")
165179
#ifndef Q_OS_MACOS
180+
if ( verboseStartup )
181+
qDebug() << startupTime.elapsed() << "ms:"
182+
<< "set \"Fusion\" style";
166183
openHantekApplication.setStyle( QStyleFactory::create( "Fusion" ) ); // smaller widgets allow stacking of all docks
167184
#endif
168185

@@ -175,13 +192,19 @@ int main( int argc, char *argv[] ) {
175192
// usermod -a -G audio <your_user_name>
176193
// or set the limits only for your user in /etc/security/limits.d:
177194
// <your_user_name> - rtprio 99
195+
if ( verboseStartup )
196+
qDebug() << startupTime.elapsed() << "ms:"
197+
<< "set RT FIFO scheduler";
178198
struct sched_param schedParam;
179199
schedParam.sched_priority = 9; // set RT priority level 10
180200
sched_setscheduler( 0, SCHED_FIFO, &schedParam ); // and RT FIFO scheduler
181-
// but ignore any error if user has no realtime rights
201+
// but ignore any error if user has no realtime rights
182202
#endif
183203

184204
//////// Load translations ////////
205+
if ( verboseStartup )
206+
qDebug() << startupTime.elapsed() << "ms:"
207+
<< "load translations for locale" << QLocale().name();
185208
QTranslator qtTranslator;
186209
QTranslator openHantekTranslator;
187210
if ( useLocale && QLocale().name() != "en_US" ) { // somehow Qt on MacOS uses the german translation for en_US?!
@@ -200,6 +223,9 @@ int main( int argc, char *argv[] ) {
200223
std::unique_ptr< ScopeDevice > scopeDevice = nullptr;
201224

202225
if ( !demoMode ) {
226+
if ( verboseStartup )
227+
qDebug() << startupTime.elapsed() << "ms:"
228+
<< "init libusb";
203229
int error = libusb_init( &context );
204230
if ( error ) {
205231
SelectSupportedDevice().showLibUSBFailedDialogModel( error );
@@ -209,6 +235,9 @@ int main( int argc, char *argv[] ) {
209235
libusb_setlocale( QLocale().name().toLocal8Bit().constData() );
210236

211237
// SelectSupportedDevive returns a real device unless demoMode is true
238+
if ( verboseStartup )
239+
qDebug() << startupTime.elapsed() << "ms:"
240+
<< "show splash screen";
212241
scopeDevice = SelectSupportedDevice().showSelectDeviceModal( context );
213242
if ( scopeDevice && scopeDevice->isDemoDevice() ) {
214243
demoMode = true;
@@ -229,8 +258,14 @@ int main( int argc, char *argv[] ) {
229258

230259
// Here we have either a connected scope device or a demo device w/o hardware
231260
const DSOModel *model = scopeDevice->getModel();
261+
if ( verboseStartup )
262+
qDebug() << startupTime.elapsed() << "ms:"
263+
<< "use device" << scopeDevice->getModel()->name << "serial number" << scopeDevice->getSerialNumber();
232264

233265
//////// Create DSO control object and move it to a separate thread ////////
266+
if ( verboseStartup )
267+
qDebug() << startupTime.elapsed() << "ms:"
268+
<< "create DSO control thread";
234269
QThread dsoControlThread;
235270
dsoControlThread.setObjectName( "dsoControlThread" );
236271
HantekDsoControl dsoControl( scopeDevice.get(), model );
@@ -245,9 +280,15 @@ int main( int argc, char *argv[] ) {
245280
const Dso::ControlSpecification *spec = model->spec();
246281

247282
//////// Create settings object specific to this scope, use unique serial number ////////
248-
DsoSettings settings( scopeDevice.get() );
283+
if ( verboseStartup )
284+
qDebug() << startupTime.elapsed() << "ms:"
285+
<< "create settings object";
286+
DsoSettings settings( scopeDevice.get(), resetSettings );
249287

250288
//////// Create exporters ////////
289+
if ( verboseStartup )
290+
qDebug() << startupTime.elapsed() << "ms:"
291+
<< "create exporters";
251292
ExporterRegistry exportRegistry( spec, &settings );
252293
ExporterCSV exporterCSV;
253294
ExporterJSON exporterJSON;
@@ -256,6 +297,9 @@ int main( int argc, char *argv[] ) {
256297
exportRegistry.registerExporter( &exporterJSON );
257298

258299
//////// Create post processing objects ////////
300+
if ( verboseStartup )
301+
qDebug() << startupTime.elapsed() << "ms:"
302+
<< "create post processing objects";
259303
QThread postProcessingThread;
260304
postProcessingThread.setObjectName( "postProcessingThread" );
261305
PostProcessing postProcessing( settings.scope.countChannels() );
@@ -274,9 +318,17 @@ int main( int argc, char *argv[] ) {
274318
QObject::connect( &postProcessing, &PostProcessing::processingFinished, &exportRegistry, &ExporterRegistry::input,
275319
Qt::DirectConnection );
276320

277-
//////// Create main window ////////
321+
if ( verboseStartup )
322+
qDebug() << startupTime.elapsed() << "ms:"
323+
<< "setup OpenGL";
324+
GlScope::useQSurfaceFormat( useGLES ? QSurfaceFormat::OpenGLES : QSurfaceFormat::OpenGL );
325+
if ( useGLSL120 )
326+
GlScope::useOpenGLSLversion( 120 );
327+
else if ( useGLSL150 )
328+
GlScope::useOpenGLSLversion( 150 );
278329

279-
// Apply the font size and style settings for the scope application
330+
//////// Prepare visual appearance ////////
331+
// prepare the font size and style settings for the scope application
280332
QFont appFont = openHantekApplication.font();
281333
if ( 0 == fontSize ) { // option -s0 -> use system font size
282334
fontSize = qBound( 6, appFont.pointSize(), 24 ); // values < 6 do not scale correctly
@@ -287,10 +339,18 @@ int main( int argc, char *argv[] ) {
287339
appFont.setStretch( condensed );
288340
appFont.setPointSize( fontSize ); // scales the widgets accordingly
289341
// apply new font settings for the scope application
342+
if ( verboseStartup )
343+
qDebug() << startupTime.elapsed() << "ms:"
344+
<< "set" << appFont;
290345
openHantekApplication.setFont( appFont );
291346
openHantekApplication.setFont( appFont, "QWidget" ); // on some systems the 2nd argument is required
292347

293348
iconFont->initFontAwesome();
349+
350+
//////// Create main window ////////
351+
if ( verboseStartup )
352+
qDebug() << startupTime.elapsed() << "ms:"
353+
<< "create main window";
294354
MainWindow openHantekMainWindow( &dsoControl, &settings, &exportRegistry );
295355
QObject::connect( &postProcessing, &PostProcessing::processingFinished, &openHantekMainWindow, &MainWindow::showNewData );
296356
QObject::connect( &exportRegistry, &ExporterRegistry::exporterProgressChanged, &openHantekMainWindow,
@@ -300,15 +360,24 @@ int main( int argc, char *argv[] ) {
300360
openHantekMainWindow.show();
301361

302362
//////// Start DSO thread and go into GUI main loop
363+
if ( verboseStartup )
364+
qDebug() << startupTime.elapsed() << "ms:"
365+
<< "start DSO control thread";
303366
dsoControl.enableSampling( true );
304367
postProcessingThread.start();
305368
dsoControlThread.start();
306369
Capturing capturing( &dsoControl );
307370
capturing.start();
308371

372+
if ( verboseStartup )
373+
qDebug() << startupTime.elapsed() << "ms:"
374+
<< "execute GUI main loop";
309375
int appStatus = openHantekApplication.exec();
310376

311377
//////// Application closed, clean up step by step ////////
378+
if ( verboseStartup )
379+
qDebug() << startupTime.elapsed() << "ms:"
380+
<< "application closed, clean up";
312381

313382
std::cout << std::unitbuf; // enable automatic flushing
314383
std::cout << "OpenHantek6022 ";

0 commit comments

Comments
 (0)