From e82536c7b1ec6a23dffdb97a55550d31365e8ce4 Mon Sep 17 00:00:00 2001 From: DreamSourceLab Date: Sat, 26 May 2018 21:53:53 +0800 Subject: [PATCH] Improve autoset function under DSO mode --- DSView/pv/dock/dsotriggerdock.cpp | 8 +++ DSView/pv/dock/dsotriggerdock.h | 3 ++ DSView/pv/mainwindow.cpp | 2 + DSView/pv/toolbars/samplingbar.cpp | 5 ++ DSView/pv/toolbars/samplingbar.h | 1 + DSView/pv/view/dsosignal.cpp | 85 +++++++++++++++++++++--------- DSView/pv/view/dsosignal.h | 12 +++-- DSView/pv/view/signal.h | 2 + DSView/pv/view/view.cpp | 5 ++ DSView/pv/view/view.h | 3 ++ DSView/pv/view/viewport.cpp | 9 ++++ libsigrok4DSL/hardware/DSL/dsl.h | 2 +- 12 files changed, 108 insertions(+), 29 deletions(-) diff --git a/DSView/pv/dock/dsotriggerdock.cpp b/DSView/pv/dock/dsotriggerdock.cpp index 6fb2f41c..fc844f22 100644 --- a/DSView/pv/dock/dsotriggerdock.cpp +++ b/DSView/pv/dock/dsotriggerdock.cpp @@ -178,6 +178,14 @@ void DsoTriggerDock::paintEvent(QPaintEvent *) // style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } +void DsoTriggerDock::auto_trig(int index) +{ + source_group->button(DSO_TRIGGER_AUTO)->setChecked(true); + channel_comboBox->setCurrentIndex(index); + source_changed(); + channel_changed(index); +} + void DsoTriggerDock::pos_changed(int pos) { int ret; diff --git a/DSView/pv/dock/dsotriggerdock.h b/DSView/pv/dock/dsotriggerdock.h index bdc23595..ee8401c4 100644 --- a/DSView/pv/dock/dsotriggerdock.h +++ b/DSView/pv/dock/dsotriggerdock.h @@ -54,6 +54,9 @@ public: signals: void set_trig_pos(int percent); +public slots: + void auto_trig(int index); + private slots: void pos_changed(int pos); void hold_changed(int hold); diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 51f760b2..0f14d991 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -184,6 +184,8 @@ void MainWindow::setup_ui() SLOT(hide_calibration())); connect(_dso_trigger_widget, SIGNAL(set_trig_pos(int)), _view, SLOT(set_trig_pos(int))); + connect(_view, SIGNAL(auto_trig(int)), _dso_trigger_widget, + SLOT(auto_trig(int))); setIconSize(QSize(40,40)); addToolBar(_sampling_bar); diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 5517d96d..2b9f5b0b 100644 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -578,6 +578,11 @@ void SamplingBar::on_samplecount_sel(int index) sample_count_changed(); } +double SamplingBar::get_hori_res() +{ + return _sample_count.itemData(_sample_count.currentIndex()).value(); +} + double SamplingBar::hori_knob(int dir) { double hori_res = -1; diff --git a/DSView/pv/toolbars/samplingbar.h b/DSView/pv/toolbars/samplingbar.h index eb1670f3..35707536 100644 --- a/DSView/pv/toolbars/samplingbar.h +++ b/DSView/pv/toolbars/samplingbar.h @@ -90,6 +90,7 @@ public: double hori_knob(int dir); double commit_hori_res(); + double get_hori_res(); public slots: void set_sample_rate(uint64_t sample_rate); diff --git a/DSView/pv/view/dsosignal.cpp b/DSView/pv/view/dsosignal.cpp index 2a6318f3..ac0babaf 100644 --- a/DSView/pv/view/dsosignal.cpp +++ b/DSView/pv/view/dsosignal.cpp @@ -33,6 +33,7 @@ #include #include +#include using namespace boost; using namespace std; @@ -201,11 +202,11 @@ bool DsoSignal::go_vDialPre() _scale *= pre_vdiv/_vDial->get_value(); update_vpos(); _view->update_calibration(); - _view->set_update(_viewport, true); - _view->update(); + //_view->set_update(_viewport, true); + //_view->update(); return true; } else { - _autoV = false; + autoV_end(); return false; } } @@ -223,11 +224,11 @@ bool DsoSignal::go_vDialNext() _scale *= pre_vdiv/_vDial->get_value(); update_vpos(); _view->update_calibration(); - _view->set_update(_viewport, true); - _view->update(); + //_view->set_update(_viewport, true); + //_view->update(); return true; } else { - _autoV = false; + autoV_end(); return false; } } @@ -947,23 +948,13 @@ void DsoSignal::paint_type_options(QPainter &p, int right, const QPoint pt) p.drawText(x1_rect, Qt::AlignCenter | Qt::AlignVCenter, "x1"); } -bool DsoSignal::mouse_double_click(int right, const QPoint pt) -{ - int y = get_zero_vpos(); - const QRectF label_rect = Trace::get_rect("label", y, right); - if (label_rect.contains(pt)) { - this->auto_set(); - return true; - } - return false; -} - bool DsoSignal::mouse_press(int right, const QPoint pt) { int y = get_y(); const QRectF vDial_rect = get_rect(DSO_VDIAL, y, right); const QRectF chEn_rect = get_rect(DSO_CHEN, y, right); const QRectF acdc_rect = get_rect(DSO_ACDC, y, right); + const QRectF auto_rect = get_rect(DSO_AUTO, y, right); const QRectF x1_rect = get_rect(DSO_X1, y, right); const QRectF x10_rect = get_rect(DSO_X10, y, right); const QRectF x100_rect = get_rect(DSO_X100, y, right); @@ -985,6 +976,8 @@ bool DsoSignal::mouse_press(int right, const QPoint pt) set_acCoupling((get_acCoupling()+1)%2); else set_acCoupling((get_acCoupling()+1)%2); + } else if (auto_rect.contains(pt)) { + auto_start(); } else if (x1_rect.contains(pt)) { set_factor(1); } else if (x10_rect.contains(pt)) { @@ -1160,26 +1153,70 @@ void DsoSignal::paint_measure(QPainter &p) } p.setRenderHint(QPainter::Antialiasing, antialiasing); - if (_autoV) { + if (_view->session().get_capture_state() == SigSession::Stopped) { + if (_autoV) + autoV_end(); + if (_autoH) + autoH_end(); + } + + if (_autoV && !_view->session().get_data_lock()) { + set_zero_vrate(0.5, true); const uint8_t vscale = abs(_max - _min); if (_max == 0xff || _min == 0x00 || vscale > 0xCC) { go_vDialNext(); } else if (vscale > 0x33) { - _autoV = false; + autoV_end(); } else { go_vDialPre(); } } + + if (_autoH && !_view->session().get_data_lock()) { + const double hori_res = _view->get_hori_res(); + if (_period < 1.5*hori_res) { + _view->zoom(1); + } else if (_period > 6*hori_res) { + _view->zoom(-1); + } else { + autoH_end(); + } + } } -void DsoSignal::auto_set() +void DsoSignal::autoV_end() { - if (_autoV | _autoH) { - _autoV = false; - _autoH = false; - } else { + _autoV = false; + _view->auto_trig(get_index()); + _trig_value = (_min+_max)/2; + set_trig_vpos(get_trig_vpos(), true); + _view->set_update(_viewport, true); + _view->update(); +} + +void DsoSignal::autoH_end() +{ + _autoH = false; + _view->set_update(_viewport, true); + _view->update(); +} + +void DsoSignal::auto_end() +{ + if (_autoV) + autoV_end(); + if (_autoH) + autoH_end(); +} + +void DsoSignal::auto_start() +{ + if (_autoV || _autoH) + return; + if (_view->session().get_capture_state() == SigSession::Running) { _autoV = true; _autoH = true; + QTimer::singleShot(AutoTime, this, SLOT(auto_end())); } } diff --git a/DSView/pv/view/dsosignal.h b/DSView/pv/view/dsosignal.h index e43e638d..eea5d3a8 100644 --- a/DSView/pv/view/dsosignal.h +++ b/DSView/pv/view/dsosignal.h @@ -40,7 +40,7 @@ namespace view { class DsoSignal : public Signal { - //Q_OBJECT + Q_OBJECT private: static const QColor SignalColours[4]; @@ -61,6 +61,7 @@ private: static const int TrigMargin = 16; static const int RefreshShort = 200; static const int RefreshLong = 800; + static const int AutoTime = 10000; public: enum DsoSetRegions { @@ -129,7 +130,9 @@ public: /** * auto set the vertical and Horizontal scale */ - void auto_set(); + void auto_start(); + void autoV_end(); + void autoH_end(); /** * Gets the mid-Y position of this signal. @@ -182,12 +185,13 @@ public: QRectF get_rect(DsoSetRegions type, int y, int right); - bool mouse_double_click(int right, const QPoint pt); - bool mouse_press(int right, const QPoint pt); bool mouse_wheel(int right, const QPoint pt, const int shift); +public slots: + void auto_end(); + protected: void paint_type_options(QPainter &p, int right, const QPoint pt); diff --git a/DSView/pv/view/signal.h b/DSView/pv/view/signal.h index 944fa7c9..59288962 100644 --- a/DSView/pv/view/signal.h +++ b/DSView/pv/view/signal.h @@ -52,6 +52,8 @@ namespace view { class Signal : public Trace { + Q_OBJECT + private: diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index efa5703a..492c0edf 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -252,6 +252,11 @@ void View::set_all_update(bool need_update) viewport->set_need_update(need_update); } +double View::get_hori_res() +{ + return _sampling_bar->get_hori_res(); +} + void View::update_hori_res() { if (_session.get_device()->dev_inst()->mode == DSO) diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index 032f21d6..92b3ffbd 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -184,6 +184,7 @@ public: int get_view_height(); void update_hori_res(); + double get_hori_res(); QString get_measure(QString option); @@ -209,6 +210,8 @@ signals: void resize(); + void auto_trig(int index); + private: void get_scroll_layout(int64_t &length, int64_t &offset) const; diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index 00a93975..b5ab9aa8 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -902,6 +902,15 @@ void Viewport::wheelEvent(QWheelEvent *event) } } + const vector< boost::shared_ptr > sigs(_view.session().get_signals()); + BOOST_FOREACH(const boost::shared_ptr s, sigs) { + assert(s); + boost::shared_ptr dsoSig; + if (dsoSig = dynamic_pointer_cast(s)) { + dsoSig->auto_end(); + } + } + measure(); } diff --git a/libsigrok4DSL/hardware/DSL/dsl.h b/libsigrok4DSL/hardware/DSL/dsl.h index c21f219e..0cc1e0cd 100644 --- a/libsigrok4DSL/hardware/DSL/dsl.h +++ b/libsigrok4DSL/hardware/DSL/dsl.h @@ -187,7 +187,7 @@ #define DSCOPEC20_DEFAULT_VGAIN3 0x143D00 #define DSCOPEC20_DEFAULT_VGAIN4 0xAFC00 #define DSCOPEC20_DEFAULT_VGAIN5 0x7C000 -#define DSCOPEC20_DEFAULT_VGAIN6 0x55000 +#define DSCOPEC20_DEFAULT_VGAIN6 0x54E00 #define DSCOPEC20_DEFAULT_VGAIN7 0x2DD00 #define CALI_VGAIN_RANGE 100