From f5bc2b1ee759cbfecc0e91eae61f5035457d94d4 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Fri, 15 Apr 2022 15:51:36 +0800 Subject: [PATCH] add: Reduce the rolling trigger sensitivity of logic analyzer --- DSView/pv/appcontrol.cpp | 12 ++++++++++- DSView/pv/appcontrol.h | 22 +++++++++++++++++---- DSView/pv/dsvdef.cpp | 17 ---------------- DSView/pv/dsvdef.h | 6 +----- DSView/pv/mainframe.cpp | 5 +++-- DSView/pv/mainwindow.cpp | 2 +- DSView/pv/toolbars/titlebar.cpp | 4 +++- DSView/pv/ui/msgbox.cpp | 7 ++++--- DSView/pv/view/viewport.cpp | 23 +++++++++++++++++++++- DSView/pv/view/viewport.h | 9 +++++---- libsigrokdecode4DSL/decoders/example/pd.py | 4 ++-- 11 files changed, 70 insertions(+), 41 deletions(-) diff --git a/DSView/pv/appcontrol.cpp b/DSView/pv/appcontrol.cpp index a5a70b4e..280e9ce4 100644 --- a/DSView/pv/appcontrol.cpp +++ b/DSView/pv/appcontrol.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "devicemanager.h" #include "sigsession.h" @@ -35,7 +36,8 @@ AppControl::AppControl() { sr_ctx = NULL; - + _topWindow = NULL; + _device_manager = new pv::DeviceManager(); _session = new pv::SigSession(_device_manager); } @@ -149,3 +151,11 @@ const char *AppControl::GetLastError() sr_log_loglevel_set(level); srd_log_loglevel_set(level); } + + bool AppControl::TopWindowIsMaximized() + { + if (_topWindow != NULL){ + return _topWindow->isMaximized(); + } + return false; + } diff --git a/DSView/pv/appcontrol.h b/DSView/pv/appcontrol.h index d674024c..82bbd3dd 100644 --- a/DSView/pv/appcontrol.h +++ b/DSView/pv/appcontrol.h @@ -24,6 +24,7 @@ #include struct sr_context; +class QWidget; namespace pv{ class DeviceManager; @@ -54,11 +55,23 @@ public: void SetLogLevel(int level); - inline pv::SigSession* GetSession() - { return _session;} + inline pv::SigSession* GetSession(){ + return _session; + } - inline pv::DeviceManager& GetDeviceManager() - { return *_device_manager;} + inline pv::DeviceManager& GetDeviceManager(){ + return *_device_manager; + } + + inline void SetTopWindow(QWidget *w){ + _topWindow = w; + } + + inline QWidget* GetTopWindow(){ + return _topWindow; + } + + bool TopWindowIsMaximized(); public: std::string _open_file_name; @@ -68,4 +81,5 @@ private: struct sr_context *sr_ctx; pv::DeviceManager *_device_manager; pv::SigSession *_session; + QWidget *_topWindow; }; diff --git a/DSView/pv/dsvdef.cpp b/DSView/pv/dsvdef.cpp index 1e2a4856..dfd42fd8 100644 --- a/DSView/pv/dsvdef.cpp +++ b/DSView/pv/dsvdef.cpp @@ -62,23 +62,6 @@ namespace DecoderDataFormat namespace app { - QWidget* get_app_window_instance(QWidget *ins, bool bSet){ - - static QWidget *g_ins = NULL; - if (bSet){ - g_ins = ins; - } - return g_ins; - } - - bool is_app_top_window(QWidget* w){ - QWidget *top =get_app_window_instance(NULL, NULL); - if (top && top == w){ - return true; - } - return false; - } - void set_utf8(QTextStream &stream){ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) stream.setEncoding(QStringConverter::Utf8); diff --git a/DSView/pv/dsvdef.h b/DSView/pv/dsvdef.h index 6c87ae53..abfb851d 100644 --- a/DSView/pv/dsvdef.h +++ b/DSView/pv/dsvdef.h @@ -53,7 +53,7 @@ class QTextStream; #define RELEASE_ARRAY(a) for (auto ptr : (a)){delete ptr;} (a).clear(); -#define ABS_VAL(x) (x>0?x:-x) +#define ABS_VAL(x) ((x) > 0 ? (x) : -(x)) namespace DecoderDataFormat { @@ -71,10 +71,6 @@ namespace DecoderDataFormat namespace app { - QWidget* get_app_window_instance(QWidget *ins, bool bSet); - - bool is_app_top_window(QWidget* w); - void set_utf8(QTextStream &stream); } diff --git a/DSView/pv/mainframe.cpp b/DSView/pv/mainframe.cpp index adab48f6..03e10548 100644 --- a/DSView/pv/mainframe.cpp +++ b/DSView/pv/mainframe.cpp @@ -47,6 +47,7 @@ #include "dsvdef.h" #include "config/appconfig.h" #include "ui/msgbox.h" +#include "appcontrol.h" #include @@ -61,6 +62,8 @@ MainFrame::MainFrame() _titleBar = NULL; _mainWindow = NULL; + AppControl::Instance()->SetTopWindow(this); + setAttribute(Qt::WA_TranslucentBackground); // Make this a borderless window which can't // be resized or moved via the window system @@ -77,8 +80,6 @@ MainFrame::MainFrame() QIcon icon; icon.addFile(QString::fromUtf8(":/icons/logo.svg"), QSize(), QIcon::Normal, QIcon::Off); setWindowIcon(icon); - - app::get_app_window_instance(this, true); // Title _titleBar = new toolbars::TitleBar(true, this); diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index c8bc5c70..5657b2a0 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -103,7 +103,7 @@ MainWindow::MainWindow(QWidget *parent) : _msg(NULL) { _control = AppControl::Instance(); - _control->GetSession()->set_callback(this); + _control->GetSession()->set_callback(this); _bFirstLoad = true; setup_ui(); diff --git a/DSView/pv/toolbars/titlebar.cpp b/DSView/pv/toolbars/titlebar.cpp index ab2ebfdf..77e97d85 100755 --- a/DSView/pv/toolbars/titlebar.cpp +++ b/DSView/pv/toolbars/titlebar.cpp @@ -32,6 +32,7 @@ #include #include #include "../config/appconfig.h" +#include "../appcontrol.h" #include "../dsvdef.h" @@ -192,7 +193,8 @@ void TitleBar::mousePressEvent(QMouseEvent* event) { int x = event->pos().x(); int y = event->pos().y(); - bool bTopWidow = app::is_app_top_window(_parent); + + bool bTopWidow = AppControl::Instance()->GetTopWindow() == _parent; bool bClick = (x >= 6 && y >= 5 && x <= width() - 6); //top window need resize hit check if (!bTopWidow || bClick ){ diff --git a/DSView/pv/ui/msgbox.cpp b/DSView/pv/ui/msgbox.cpp index 0e456b34..73c6494b 100644 --- a/DSView/pv/ui/msgbox.cpp +++ b/DSView/pv/ui/msgbox.cpp @@ -25,6 +25,7 @@ #include #include #include "../dsvdef.h" +#include "../appcontrol.h" //QMessageBox::information(NULL, "Title", "Content",QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); //QMessageBox::information(NULL, "Title", "Content",QMessageBox::Yes|QMessageBox::No); @@ -40,7 +41,7 @@ void MsgBox::Show(const char *title, const char *text, QWidget *parent) str.append(text); if (parent == NULL){ - parent = app::get_app_window_instance(NULL, false); + parent = AppControl::Instance()->GetTopWindow(); } pv::dialogs::DSMessageBox msg(parent, title); @@ -59,8 +60,8 @@ bool MsgBox::Confirm(const char *text, QWidget *parent) str.append("\n"); str.append(text); - if (parent == NULL){ - parent = app::get_app_window_instance(NULL, false); + if (parent == NULL){ + parent = AppControl::Instance()->GetTopWindow(); } pv::dialogs::DSMessageBox msg(parent, "Question"); diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index 61a5f0c4..a5e60458 100755 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -44,6 +44,7 @@ #include "../config/appconfig.h" #include "../dsvdef.h" +#include "../appcontrol.h" using namespace std; @@ -88,6 +89,7 @@ Viewport::Viewport(View &parent, View_type type) : _edge_hit = false; transfer_started = false; timer_cnt = 0; + _clickX = 0; // drag inertial _drag_strength = 0; @@ -499,6 +501,7 @@ void Viewport::mousePressEvent(QMouseEvent *event) { assert(event); + _clickX = event->globalPos().x(); _mouse_down_point = event->pos(); _mouse_down_offset = _view.offset(); _drag_strength = 0; @@ -757,6 +760,9 @@ void Viewport::mouseMoveEvent(QMouseEvent *event) void Viewport::mouseReleaseEvent(QMouseEvent *event) { assert(event); + + bool quickScroll = AppConfig::Instance()._appOptions.quickScroll; + bool isMaxWindow = AppControl::Instance()->TopWindowIsMaximized(); if (_type != TIME_VIEW){ update(); @@ -769,7 +775,22 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event) _view.session().get_capture_state() == SigSession::Stopped) { //priority 1 //try to quick scroll view... - if (_action_type == NO_ACTION && AppConfig::Instance()._appOptions.quickScroll) { + int curX = event->globalPos().x(); + int moveLong = ABS_VAL(curX - _clickX); + int maxWidth = this->geometry().width(); + float mvk = (float) moveLong / (float)maxWidth; + + if (quickScroll){ + quickScroll = false; + if (isMaxWindow && mvk > 0.5f){ + quickScroll = true; + } + else if (!isMaxWindow && mvk > 0.6f){ + quickScroll = true; + } + } + + if (_action_type == NO_ACTION && quickScroll) { const double strength = _drag_strength*DragTimerInterval*1.0/_elapsed_time.elapsed(); if (_elapsed_time.elapsed() < 200 && abs(_drag_strength) < MinorDragOffsetUp && diff --git a/DSView/pv/view/viewport.h b/DSView/pv/view/viewport.h index bd1e1840..fc244fdb 100755 --- a/DSView/pv/view/viewport.h +++ b/DSView/pv/view/viewport.h @@ -217,10 +217,11 @@ private: int _dso_ym_start; int _dso_ym_end; - int _waiting_trig; - bool _dso_trig_moved; - bool _curs_moved; - bool _xcurs_moved; + int _waiting_trig; + bool _dso_trig_moved; + bool _curs_moved; + bool _xcurs_moved; + int _clickX; }; } // namespace view diff --git a/libsigrokdecode4DSL/decoders/example/pd.py b/libsigrokdecode4DSL/decoders/example/pd.py index c84ec240..0cf0e7c6 100644 --- a/libsigrokdecode4DSL/decoders/example/pd.py +++ b/libsigrokdecode4DSL/decoders/example/pd.py @@ -134,8 +134,8 @@ class Decoder(srd.Decoder): # 解码函数,解码任务开始时由c底层代码调用 # 这里不断循环等待所有采样数据被处理完成 - # 下面的未例代码是想以一对向上边沿和向下边沿,输出它们的样品位置差值, - # 同时奇数次显示第二行,偶数次显示在第一行,我们只要指定了annotations里定义的序号 + # 下面的示例代码是解析某一通道的数据,从向上边沿开始到向下边沿结束,输出它们的样品位置差值, + # 奇数次显示第二行,偶数次显示在第一行,我们只指定annotations里定义的序号 # 软件会自动根据annotation_rows的设置,决定显示在哪一行 def decode(self): # 次数计数