Skip to content

Commit 62967ed

Browse files
Add measure of edge distance between channels
1 parent 6f63024 commit 62967ed

9 files changed

+189
-26
lines changed

DSView/pv/mainwindow.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ void MainWindow::setup_ui()
184184
SLOT(hide_calibration()));
185185
connect(_dso_trigger_widget, SIGNAL(set_trig_pos(int)), _view,
186186
SLOT(set_trig_pos(int)));
187-
connect(_sampling_bar, SIGNAL(hori_res_changed(double)), _view,
188-
SLOT(hori_res_changed(double)));
189187

190188
setIconSize(QSize(40,40));
191189
addToolBar(_sampling_bar);

DSView/pv/toolbars/samplingbar.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -578,20 +578,22 @@ void SamplingBar::on_samplecount_sel(int index)
578578
sample_count_changed();
579579
}
580580

581-
void SamplingBar::hori_knob(int dir)
581+
double SamplingBar::hori_knob(int dir)
582582
{
583+
double hori_res = -1;
583584
if (0 == dir) {
584-
commit_hori_res();
585+
hori_res = commit_hori_res();
585586
} else if ((dir > 0) && (_sample_count.currentIndex() > 0)) {
586587
_sample_count.setCurrentIndex(_sample_count.currentIndex() - 1);
587-
commit_hori_res();
588+
hori_res = commit_hori_res();
588589
} else if ((dir < 0) && (_sample_count.currentIndex() < _sample_count.count() - 1)) {
589590
_sample_count.setCurrentIndex(_sample_count.currentIndex() + 1);
590-
commit_hori_res();
591+
hori_res = commit_hori_res();
591592
}
593+
return hori_res;
592594
}
593595

594-
void SamplingBar::commit_hori_res()
596+
double SamplingBar::commit_hori_res()
595597
{
596598
const double hori_res = _sample_count.itemData(
597599
_sample_count.currentIndex()).value<double>();
@@ -608,7 +610,7 @@ void SamplingBar::commit_hori_res()
608610
g_variant_unref(gvar);
609611
} else {
610612
qDebug() << "ERROR: config_get SR_CONF_MAX_DSO_SAMPLERATE failed.";
611-
return;
613+
return -1;
612614
}
613615

614616
const uint64_t sample_rate = min((uint64_t)(sample_limit * SR_SEC(1) /
@@ -622,7 +624,7 @@ void SamplingBar::commit_hori_res()
622624
dev_inst->set_config(NULL, NULL, SR_CONF_TIMEBASE,
623625
g_variant_new_uint64(hori_res));
624626

625-
hori_res_changed(hori_res);
627+
return hori_res;
626628
}
627629

628630
void SamplingBar::commit_settings()

DSView/pv/toolbars/samplingbar.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class SamplingBar : public QToolBar
8888

8989
void enable_instant(bool enable);
9090

91-
void hori_knob(int dir);
92-
void commit_hori_res();
91+
double hori_knob(int dir);
92+
double commit_hori_res();
9393

9494
public slots:
9595
void set_sample_rate(uint64_t sample_rate);
@@ -102,7 +102,6 @@ public slots:
102102
void sample_count_changed();
103103
void show_calibration();
104104
void hide_calibration();
105-
void hori_res_changed(double hori_res);
106105

107106
private:
108107
void update_sample_rate_selector_value();

DSView/pv/view/logicsignal.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,59 @@ bool LogicSignal::measure(const QPointF &p, uint64_t &index0, uint64_t &index1,
356356
return false;
357357
}
358358

359+
bool LogicSignal::edge(const QPointF &p, uint64_t &index, int radius) const
360+
{
361+
uint64_t pre_index, nxt_index;
362+
const float gap = abs(p.y() - get_y());
363+
if (gap < get_totalHeight() * 0.5) {
364+
const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots =
365+
_data->get_snapshots();
366+
if (snapshots.empty())
367+
return false;
368+
369+
const boost::shared_ptr<pv::data::LogicSnapshot> &snapshot =
370+
snapshots.front();
371+
if (snapshot->empty() || !snapshot->has_data(_probe->index))
372+
return false;
373+
374+
const uint64_t end = snapshot->get_sample_count() - 1;
375+
const
376+
double pos = _data->samplerate() * _view->scale() * (_view->offset() + p.x());
377+
index = floor(pos + 0.5);
378+
if (index > end)
379+
return false;
380+
381+
bool sample = snapshot->get_sample(index, get_index());
382+
if (index == 0)
383+
pre_index = index;
384+
else {
385+
index--;
386+
if (snapshot->get_pre_edge(index, sample, 1, get_index()))
387+
pre_index = index;
388+
else
389+
pre_index = 0;
390+
}
391+
392+
sample = snapshot->get_sample(index, get_index());
393+
index++;
394+
if (snapshot->get_nxt_edge(index, sample, end, 1, get_index()))
395+
nxt_index = index;
396+
else
397+
nxt_index = 0;
398+
399+
if (pre_index == 0 || nxt_index == 0)
400+
return false;
401+
402+
if (pos - pre_index > nxt_index - pos)
403+
index = nxt_index;
404+
else
405+
index = pre_index;
406+
407+
if (radius > abs((index-pos) / _view->scale() / _data->samplerate()))
408+
return true;
409+
}
410+
return false;
411+
}
359412

360413
bool LogicSignal::edges(const QPointF &p, uint64_t start, uint64_t &rising, uint64_t &falling) const
361414
{

DSView/pv/view/logicsignal.h

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class LogicSignal : public Signal
9898

9999
bool measure(const QPointF &p, uint64_t &index0, uint64_t &index1, uint64_t &index2) const;
100100

101+
bool edge(const QPointF &p, uint64_t &index, int radius) const;
102+
101103
bool edges(const QPointF &p, uint64_t start, uint64_t &rising, uint64_t &falling) const;
102104

103105
bool edges(uint64_t end, uint64_t start, uint64_t &rising, uint64_t &falling) const;

DSView/pv/view/view.cpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ void View::set_all_update(bool need_update)
254254

255255
void View::update_hori_res()
256256
{
257-
_sampling_bar->hori_knob(0);
257+
if (_session.get_device()->dev_inst()->mode == DSO)
258+
_sampling_bar->hori_knob(0);
258259

259260
const uint64_t final_limit = _session.get_device()->get_sample_limit();
260261
_trig_cursor->set_index(_trig_cursor->index() * 1.0 / _session.cur_samplelimits() * final_limit);
@@ -276,10 +277,16 @@ void View::zoom(double steps, int offset)
276277
_session.get_instant())
277278
return;
278279

280+
double hori_res = -1;
279281
if(steps > 0.5)
280-
_sampling_bar->hori_knob(-1);
282+
hori_res = _sampling_bar->hori_knob(-1);
281283
else if (steps < -0.5)
282-
_sampling_bar->hori_knob(1);
284+
hori_res = _sampling_bar->hori_knob(1);
285+
286+
if (hori_res > 0) {
287+
const double scale = hori_res * DS_CONF_DSO_HDIVS / SR_SEC(1) / get_view_width();
288+
_scale = max(min(scale, _maxscale), _minscale);
289+
}
283290
}
284291

285292
_offset = floor((_offset + offset) * (_preScale / _scale) - offset);
@@ -294,15 +301,6 @@ void View::zoom(double steps, int offset)
294301
//}
295302
}
296303

297-
void View::hori_res_changed(double hori_res)
298-
{
299-
if (hori_res > 0) {
300-
const double scale = hori_res * DS_CONF_DSO_HDIVS / SR_SEC(1) / get_view_width();
301-
set_scale_offset(scale, this->offset());
302-
}
303-
}
304-
305-
306304
void View::set_scale_offset(double scale, int64_t offset)
307305
{
308306
//if (_session.get_capture_state() == SigSession::Stopped) {
@@ -949,6 +947,15 @@ QString View::get_cm_delta(int index1, int index2)
949947
return _ruler->format_real_time(delta_sample, _session.cur_samplerate());
950948
}
951949

950+
QString View::get_index_delta(uint64_t start, uint64_t end)
951+
{
952+
if (start == end)
953+
return "0";
954+
955+
uint64_t delta_sample = (start > end) ? start - end : end - start;
956+
return _ruler->format_real_time(delta_sample, _session.cur_samplerate());
957+
}
958+
952959
uint64_t View::get_cursor_samples(int index)
953960
{
954961
assert(index < (int)_cursorList.size());

DSView/pv/view/view.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class View : public QScrollArea {
175175
uint64_t get_cursor_samples(int index);
176176
QString get_cm_time(int index);
177177
QString get_cm_delta(int index1, int index2);
178+
QString get_index_delta(uint64_t start, uint64_t end);
178179

179180
void on_state_changed(bool stop);
180181

@@ -240,8 +241,6 @@ public slots:
240241
void repeat_unshow();
241242
// -- repeat
242243
void repeat_show();
243-
// -- hori resolution
244-
void hori_res_changed(double hori_res);
245244

246245
private slots:
247246

DSView/pv/view/viewport.cpp

+96
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Viewport::Viewport(View &parent, View_type type) :
8282
_mm_freq = "#####";
8383
_mm_duty = "#####";
8484
_measure_en = true;
85+
_edge_hit = false;
8586
transfer_started = false;
8687
timer_cnt = 0;
8788

@@ -641,6 +642,30 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
641642
}
642643

643644
// priority 2
645+
if (_action_type == NO_ACTION) {
646+
if (_mouse_down_point.x() == event->pos().x()) {
647+
const vector< boost::shared_ptr<Signal> > sigs(_view.session().get_signals());
648+
BOOST_FOREACH(const boost::shared_ptr<Signal> s, sigs) {
649+
assert(s);
650+
boost::shared_ptr<view::LogicSignal> logicSig;
651+
if ((logicSig = dynamic_pointer_cast<view::LogicSignal>(s))) {
652+
if (logicSig->edge(event->pos(), _edge_start, 10)) {
653+
_action_type = LOGIC_JUMP;
654+
const double samples_per_pixel = _view.session().cur_samplerate() * _view.scale();
655+
_cur_preX = _edge_start / samples_per_pixel - _view.offset();
656+
_cur_preY = logicSig->get_y();
657+
_cur_preY_top = logicSig->get_y() - logicSig->get_totalHeight()/2 - 12;
658+
_cur_preY_bottom = logicSig->get_y() + logicSig->get_totalHeight()/2 + 2;
659+
_cur_aftX = _cur_preX;
660+
_cur_aftY = _cur_preY;
661+
break;
662+
}
663+
}
664+
}
665+
}
666+
}
667+
668+
// priority 3
644669
if (_action_type == NO_ACTION) {
645670
if (_mouse_down_point.x() == event->pos().x()) {
646671
const vector< boost::shared_ptr<Signal> > sigs(_view.session().get_signals());
@@ -738,6 +763,11 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
738763
_action_type = NO_ACTION;
739764
_edge_rising = 0;
740765
_edge_falling = 0;
766+
} else if (_action_type == LOGIC_JUMP) {
767+
_action_type = NO_ACTION;
768+
_edge_rising = 0;
769+
_edge_falling = 0;
770+
_edge_hit = false;
741771
} else if (_action_type == LOGIC_MOVE) {
742772
if (_mouse_down_point == event->pos()) {
743773
_drag_strength = 0;
@@ -884,6 +914,10 @@ void Viewport::leaveEvent(QEvent *)
884914
_edge_rising = 0;
885915
_edge_falling = 0;
886916
_action_type = NO_ACTION;
917+
} else if (_action_type == LOGIC_JUMP) {
918+
_edge_rising = 0;
919+
_edge_falling = 0;
920+
_action_type = NO_ACTION;
887921
} else if (_action_type == LOGIC_MOVE) {
888922
_drag_strength = 0;
889923
_drag_timer.stop();
@@ -975,6 +1009,18 @@ void Viewport::measure()
9751009

9761010
break;
9771011
}
1012+
} else if (_action_type == LOGIC_JUMP) {
1013+
const double samples_per_pixel = _view.session().cur_samplerate() * _view.scale();
1014+
if (logicSig->edge(_view.hover_point(), _edge_end, 10)) {
1015+
_cur_aftX = _edge_end / samples_per_pixel - _view.offset();
1016+
_cur_aftY = logicSig->get_y();
1017+
_edge_hit = true;
1018+
break;
1019+
}
1020+
_cur_preX = _edge_start / samples_per_pixel - _view.offset();
1021+
_cur_aftX = _view.hover_point().x();
1022+
_cur_aftY = _view.hover_point().y();
1023+
_edge_hit = false;
9781024
}
9791025
} else if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)) {
9801026
if (_measure_en && dsoSig->measure(_view.hover_point())) {
@@ -1287,6 +1333,56 @@ void Viewport::paintMeasure(QPainter &p)
12871333
p.drawText(measure3_rect, Qt::AlignRight | Qt::AlignVCenter, _em_falling);
12881334

12891335
}
1336+
1337+
if (_action_type == LOGIC_JUMP) {
1338+
p.setPen(QColor(238, 178, 17, 255));
1339+
const QPoint pre_points[] = {
1340+
QPoint(_cur_preX, _cur_preY),
1341+
QPoint(_cur_preX-1, _cur_preY-1),
1342+
QPoint(_cur_preX+1, _cur_preY-1),
1343+
QPoint(_cur_preX-1, _cur_preY+1),
1344+
QPoint(_cur_preX+1, _cur_preY+1),
1345+
QPoint(_cur_preX-2, _cur_preY-2),
1346+
QPoint(_cur_preX+2, _cur_preY-2),
1347+
QPoint(_cur_preX-2, _cur_preY+2),
1348+
QPoint(_cur_preX+2, _cur_preY+2),
1349+
};
1350+
p.drawPoints(pre_points, countof(pre_points));
1351+
if (abs(_cur_aftX - _cur_preX) + abs(_cur_aftY - _cur_preY) > 20) {
1352+
if (_edge_hit) {
1353+
const QPoint aft_points[] = {
1354+
QPoint(_cur_aftX, _cur_aftY),
1355+
QPoint(_cur_aftX-1, _cur_aftY-1),
1356+
QPoint(_cur_aftX+1, _cur_aftY-1),
1357+
QPoint(_cur_aftX-1, _cur_aftY+1),
1358+
QPoint(_cur_aftX+1, _cur_aftY+1),
1359+
QPoint(_cur_aftX-2, _cur_aftY-2),
1360+
QPoint(_cur_aftX+2, _cur_aftY-2),
1361+
QPoint(_cur_aftX-2, _cur_aftY+2),
1362+
QPoint(_cur_aftX+2, _cur_aftY+2),
1363+
};
1364+
p.drawPoints(aft_points, countof(aft_points));
1365+
1366+
int64_t delta = max(_edge_start, _edge_end) - min(_edge_start, _edge_end);
1367+
QString delta_text = _view.get_index_delta(_edge_start, _edge_end) +
1368+
"/" + QString::number(delta);
1369+
QFontMetrics fm = this->fontMetrics();
1370+
const int rectW = fm.width(delta_text);
1371+
const int rectY = (_cur_aftY >= _cur_preY) ? _cur_preY_top : _cur_preY_bottom;
1372+
const int rectX = (_cur_aftX >= _cur_preX) ? _cur_preX : _cur_preX - rectW;
1373+
QRectF jump_rect = QRectF(rectX, rectY, rectW, 10);
1374+
p.drawText(jump_rect, Qt::AlignCenter | Qt::AlignVCenter, delta_text);
1375+
1376+
}
1377+
1378+
QPainterPath path(QPoint(_cur_preX, _cur_preY));
1379+
QPoint c1((_cur_preX+_cur_aftX)/2, _cur_preY);
1380+
QPoint c2((_cur_preX+_cur_aftX)/2, _cur_aftY);
1381+
path.cubicTo(c1, c2, QPoint(_cur_aftX, _cur_aftY));
1382+
p.drawPath(path);
1383+
1384+
}
1385+
}
12901386
}
12911387

12921388
QString Viewport::get_measure(QString option)

DSView/pv/view/viewport.h

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Viewport : public QWidget
6868
LOGIC_EDGE,
6969
LOGIC_MOVE,
7070
LOGIC_ZOOM,
71+
LOGIC_JUMP,
7172

7273
DSO_XM_STEP0,
7374
DSO_XM_STEP1,
@@ -158,6 +159,11 @@ public slots:
158159
int64_t _cur_aftX;
159160
int64_t _cur_thdX;
160161
int _cur_midY;
162+
int _cur_preY;
163+
int _cur_preY_top;
164+
int _cur_preY_bottom;
165+
int _cur_aftY;
166+
bool _edge_hit;
161167
QString _mm_width;
162168
QString _mm_period;
163169
QString _mm_freq;
@@ -166,6 +172,7 @@ public slots:
166172
uint64_t _edge_rising;
167173
uint64_t _edge_falling;
168174
uint64_t _edge_start;
175+
uint64_t _edge_end;
169176
QString _em_rising;
170177
QString _em_falling;
171178
QString _em_edges;

0 commit comments

Comments
 (0)