Fix wave shake when measure high frequency signals @ dso mode

This commit is contained in:
DreamSourceLab 2020-01-09 21:48:39 +08:00
parent 7328b0b2cc
commit 235a863b3a
18 changed files with 213 additions and 126 deletions

View File

@ -130,7 +130,7 @@ SigSession::SigSession(DeviceManager &device_manager) :
_group_data.reset(new data::Group());
_group_cnt = 0;
connect(&_feed_timer, SIGNAL(timeout()), this, SLOT(data_unlock()));
connect(&_feed_timer, SIGNAL(timeout()), this, SLOT(feed_timeout()));
}
SigSession::~SigSession()
@ -353,6 +353,7 @@ void SigSession::capture_init()
set_cur_samplelimits(_dev_inst->get_sample_limit());
_data_updated = false;
_trigger_flag = false;
_trigger_ch = 0;
_hw_replied = false;
if (_dev_inst->dev_inst()->mode != LOGIC)
_feed_timer.start(FeedInterval);
@ -591,7 +592,6 @@ void SigSession::check_update()
{
boost::lock_guard<boost::mutex> lock(_data_mutex);
//data_unlock(); unlock after wave rendering
if (_capture_state != Running)
return;
@ -883,7 +883,7 @@ void SigSession::refresh(int holdtime)
//_cur_analog_snapshot.reset();
}
QTimer::singleShot(holdtime, this, SLOT(data_unlock()));
QTimer::singleShot(holdtime, this, SLOT(feed_timeout()));
//data_updated();
_data_updated = true;
}
@ -1039,6 +1039,12 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso)
_cur_dso_snapshot->append_payload(dso);
}
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _signals) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)) && (dsoSig->enabled()))
dsoSig->paint_prepare();
}
if (dso.num_samples != 0) {
// update current sample rate
set_cur_snap_samplerate(_dev_inst->get_sample_rate());
@ -1073,6 +1079,7 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso)
}
_trigger_flag = dso.trig_flag;
_trigger_ch = dso.trig_ch;
receive_data(dso.num_samples);
if (!_instant)
@ -1597,6 +1604,11 @@ bool SigSession::trigd() const
return _trigger_flag;
}
uint8_t SigSession::trigd_ch() const
{
return _trigger_ch;
}
void SigSession::nodata_timeout()
{
GVariant *gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_TRIGGER_SOURCE);
@ -1607,6 +1619,15 @@ void SigSession::nodata_timeout()
}
}
void SigSession::feed_timeout()
{
data_unlock();
if (!_data_updated) {
if (++_noData_cnt >= (WaitShowTime/FeedInterval))
nodata_timeout();
}
}
boost::shared_ptr<data::Snapshot> SigSession::get_snapshot(int type)
{
if (type == SR_CHANNEL_LOGIC)

View File

@ -23,6 +23,7 @@
#ifndef DSVIEW_PV_SIGSESSION_H
#define DSVIEW_PV_SIGSESSION_H
#include <libsigrok4DSL/libsigrok.h>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
@ -46,7 +47,6 @@
#include <QtConcurrent/QtConcurrent>
#include <QJsonObject>
#include <libsigrok4DSL/libsigrok.h>
#include <libusb.h>
#include "view/mathtrace.h"
@ -231,6 +231,7 @@ public:
void math_disable();
bool trigd() const;
uint8_t trigd_ch() const;
boost::shared_ptr<data::Snapshot> get_snapshot(int type);
@ -348,6 +349,7 @@ private:
QDateTime _session_time;
uint64_t _trigger_pos;
bool _trigger_flag;
uint8_t _trigger_ch;
bool _hw_replied;
error_state _error;
@ -427,6 +429,7 @@ private slots:
void data_lock();
void data_unlock();
void nodata_timeout();
void feed_timeout();
void repeat_update();
private:

View File

@ -57,7 +57,7 @@ Cursor::Cursor(View &view, QColor color, uint64_t index) :
{
}
QRect Cursor::get_label_rect(const QRect &rect, bool &visible) const
QRect Cursor::get_label_rect(const QRect &rect, bool &visible, bool has_hoff) const
{
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
const double cur_offset = _index / samples_per_pixel;
@ -66,7 +66,7 @@ QRect Cursor::get_label_rect(const QRect &rect, bool &visible) const
visible = false;
return QRect(-1, -1, 0, 0);
}
const int64_t x = _index/samples_per_pixel - _view.offset();
const int64_t x = _view.index2pixel(_index, has_hoff);
const QSize label_size(
_text_size.width() + View::LabelPadding.width() * 2,
@ -131,13 +131,13 @@ void Cursor::paint_label(QPainter &p, const QRect &rect,
}
void Cursor::paint_fix_label(QPainter &p, const QRect &rect,
unsigned int prefix, QChar label, QColor color)
unsigned int prefix, QChar label, QColor color, bool has_hoff)
{
using pv::view::Ruler;
bool visible;
compute_text_size(p, prefix);
const QRect r(get_label_rect(rect, visible));
const QRect r(get_label_rect(rect, visible, has_hoff));
if (!visible)
return;

View File

@ -64,7 +64,7 @@ public:
* @param rect The rectangle of the ruler client area.
* @return Returns the label rectangle.
*/
QRect get_label_rect(const QRect &rect, bool &visible) const;
QRect get_label_rect(const QRect &rect, bool &visible, bool has_hoff = true) const;
QRect get_close_rect(const QRect &rect) const;
@ -78,7 +78,7 @@ public:
unsigned int prefix, int index);
void paint_fix_label(QPainter &p, const QRect &rect,
unsigned int prefix, QChar label, QColor color);
unsigned int prefix, QChar label, QColor color, bool has_hoff);
private:
void compute_text_size(QPainter &p, unsigned int prefix);

View File

@ -701,6 +701,58 @@ QRect DsoSignal::get_view_rect() const
_viewport->height() - UpMargin - DownMargin);
}
void DsoSignal::paint_prepare()
{
assert(_view);
const deque< boost::shared_ptr<pv::data::DsoSnapshot> > &snapshots =
_data->get_snapshots();
if (snapshots.empty())
return;
const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot =
snapshots.front();
if (snapshot->empty())
return;
if (!snapshot->has_data(get_index()))
return;
const uint16_t enabled_channels = snapshot->get_channel_num();
if (_view->session().trigd()) {
if (get_index() == _view->session().trigd_ch()) {
uint8_t slope = DSO_TRIGGER_RISING;
GVariant *gvar = _view->session().get_device()->get_config(NULL, NULL, SR_CONF_TRIGGER_SLOPE);
if (gvar != NULL) {
slope = g_variant_get_byte(gvar);
g_variant_unref(gvar);
}
int64_t trig_index = _view->get_trig_cursor()->index();
if (trig_index >= (int64_t)snapshot->get_sample_count())
return;
const uint8_t *const trig_samples = snapshot->get_samples(0, 0, get_index());
for (uint16_t i = 0; i < TrigHRng; i++) {
const int64_t i0 = (trig_index - i - 1)*enabled_channels;
const int64_t i1 = (trig_index - i)*enabled_channels;
if (i1 < 0)
break;
const uint8_t t0 = trig_samples[i0];
const uint8_t t1 = trig_samples[i1];
if((slope == DSO_TRIGGER_RISING && t0 >= _trig_value && t1 <= _trig_value) ||
(slope == DSO_TRIGGER_FALLING && t0 <= _trig_value && t1 >= _trig_value)) {
const double xoff = (t1 == t0) ? 0 : (_trig_value - t0) * 1.0 / (t1 - t0);
_view->set_trig_hoff(i + 1 - xoff);
break;
}
}
}
//if (_view->trig_hoff() == 0 && trig_samples[3] != _trig_value)
// _view->set_trig_hoff(0);
} else {
_view->set_trig_hoff(0);
}
}
void DsoSignal::paint_back(QPainter &p, int left, int right, QColor fore, QColor back)
{
assert(_view);
@ -818,7 +870,7 @@ void DsoSignal::paint_mid(QPainter &p, int left, int right, QColor fore, QColor
//const double samplerate = _view->session().cur_snap_samplerate();
const int64_t last_sample = max((int64_t)(snapshot->get_sample_count() - 1), (int64_t)0);
const double samples_per_pixel = samplerate * scale;
const double start = offset * samples_per_pixel;
const double start = offset * samples_per_pixel - _view->trig_hoff();
const double end = start + samples_per_pixel * width;
const int64_t start_sample = min(max((int64_t)floor(start),
@ -999,10 +1051,11 @@ void DsoSignal::paint_trace(QPainter &p,
float top = get_view_rect().top();
float bottom = get_view_rect().bottom();
float x = (start / samples_per_pixel - pixels_offset) + left;
double pixels_per_sample = 1.0/samples_per_pixel;
uint8_t value;
int64_t sample_end = sample_count*num_channels;
float x = (start / samples_per_pixel - pixels_offset) + left + _view->trig_hoff()*pixels_per_sample;
for (int64_t sample = 0; sample < sample_end; sample+=num_channels) {
value = samples[sample];
const float y = min(max(top, zeroY + (value - hw_offset) * _scale), bottom);
@ -1045,7 +1098,7 @@ void DsoSignal::paint_envelope(QPainter &p,
float bottom = get_view_rect().bottom();
for(uint64_t sample = 0; sample < e.length-1; sample++) {
const float x = ((e.scale * sample + e.start) /
samples_per_pixel - pixels_offset) + left;
samples_per_pixel - pixels_offset) + left + _view->trig_hoff()/samples_per_pixel;
const DsoSnapshot::EnvelopeSample *const s =
e.samples + sample;
@ -1401,6 +1454,7 @@ void DsoSignal::auto_start()
_view->session().data_auto_lock(AutoLock);
_autoV = true;
_autoH = true;
_view->auto_trig(get_index());
QTimer::singleShot(AutoTime, &_view->session(), SLOT(auto_end()));
}
}
@ -1428,13 +1482,7 @@ bool DsoSignal::measure(const QPointF &p)
if (snapshot->empty())
return false;
const double scale = _view->scale();
assert(scale > 0);
const int64_t pixels_offset = _view->offset();
const double samplerate = _view->session().cur_snap_samplerate();
const double samples_per_pixel = samplerate * scale;
_hover_index = floor((p.x() + pixels_offset) * samples_per_pixel+0.5);
_hover_index = _view->pixel2index(p.x());
if (_hover_index >= snapshot->get_sample_count())
return false;
@ -1471,12 +1519,6 @@ QPointF DsoSignal::get_point(uint64_t index, float &value)
if (snapshot->empty())
return pt;
const double scale = _view->scale();
assert(scale > 0);
const int64_t pixels_offset = _view->offset();
const double samplerate = _view->session().cur_snap_samplerate();
const double samples_per_pixel = samplerate * scale;
if (index >= snapshot->get_sample_count())
return pt;
@ -1484,7 +1526,7 @@ QPointF DsoSignal::get_point(uint64_t index, float &value)
const float top = get_view_rect().top();
const float bottom = get_view_rect().bottom();
const int hw_offset = get_hw_offset();
const float x = (index / samples_per_pixel - pixels_offset);
const float x = _view->index2pixel(index);
const float y = min(max(top, get_zero_vpos() + (value - hw_offset)* _scale), bottom);
pt = QPointF(x, y);

View File

@ -63,6 +63,8 @@ private:
static const int AutoTime = 10000;
static const int AutoLock = 3;
static const int TrigHRng = 2;
public:
enum DsoSetRegions {
DSO_NONE = -1,
@ -166,6 +168,11 @@ public:
double value2ratio(int value) const;
double pos2ratio(int pos) const;
/**
* paint prepare
**/
void paint_prepare();
/**
* Paints the background layer of the trace with a QPainter
* @param p the QPainter to paint into.

View File

@ -222,7 +222,7 @@ void MathTrace::paint_mid(QPainter &p, int left, int right, QColor fore, QColor
const double samplerate = _math_stack->samplerate();
const int64_t last_sample = max((int64_t)(_math_stack->get_sample_num() - 1), (int64_t)0);
const double samples_per_pixel = samplerate * scale;
const double start = offset * samples_per_pixel;
const double start = offset * samples_per_pixel - _view->trig_hoff();
const double end = start + samples_per_pixel * width;
const int64_t start_sample = min(max((int64_t)floor(start),
@ -287,7 +287,7 @@ void MathTrace::paint_trace(QPainter &p,
double top = get_view_rect().top();
double bottom = get_view_rect().bottom();
float x = (start / samples_per_pixel - pixels_offset) + left;
float x = (start / samples_per_pixel - pixels_offset) + left + _view->trig_hoff()/samples_per_pixel;
double pixels_per_sample = 1.0/samples_per_pixel;
for (int64_t index = 0; index < sample_count; index++) {
@ -326,7 +326,7 @@ void MathTrace::paint_envelope(QPainter &p,
double bottom = get_view_rect().bottom();
for(uint64_t sample = 0; sample < e.length-1; sample++) {
const float x = ((e.scale * sample + e.start) /
samples_per_pixel - pixels_offset) + left;
samples_per_pixel - pixels_offset) + left + _view->trig_hoff()/samples_per_pixel;
const data::MathStack::EnvelopeSample *const s =
e.samples + sample;
@ -458,13 +458,7 @@ bool MathTrace::measure(const QPointF &p)
if (!window.contains(p))
return false;
const double scale = _view->scale();
assert(scale > 0);
const int64_t pixels_offset = _view->offset();
const double samplerate = _view->session().cur_snap_samplerate();
const double samples_per_pixel = samplerate * scale;
_hover_index = floor((p.x() + pixels_offset) * samples_per_pixel+0.5);
_hover_index = _view->pixel2index(p.x());
if (_hover_index >= _math_stack->get_sample_num())
return false;
@ -477,16 +471,10 @@ QPointF MathTrace::get_point(uint64_t index, float &value)
{
QPointF pt = QPointF(0, 0);
const double scale = _view->scale();
assert(scale > 0);
const int64_t pixels_offset = _view->offset();
const double samplerate = _view->session().cur_snap_samplerate();
const double samples_per_pixel = samplerate * scale;
const float top = get_view_rect().top();
const float bottom = get_view_rect().bottom();
const float zeroP = _zero_vrate * get_view_rect().height() + top;
const float x = (index / samples_per_pixel - pixels_offset);
const float x = _view->index2pixel(index);
value = *_math_stack->get_math(index);
float y = min(max(top, zeroP - (value * _scale)), bottom);

View File

@ -194,8 +194,7 @@ void Ruler::mouseMoveEvent(QMouseEvent *e)
(void)e;
if (_grabbed_marker) {
_grabbed_marker->set_index((_view.offset() + _view.hover_point().x()) *
_view.scale() * _view.session().cur_snap_samplerate());
_grabbed_marker->set_index(_view.pixel2index(_view.hover_point().x()));
_view.cursor_moving();
_curs_moved = true;
}
@ -253,7 +252,7 @@ void Ruler::mouseReleaseEvent(QMouseEvent *event)
_cursor_sel_visible = true;
} else {
int overCursor;
uint64_t index = (_view.offset() + _cursor_sel_x + 0.5) * _view.scale() * _view.session().cur_snap_samplerate();
uint64_t index = _view.pixel2index(_cursor_sel_x);
overCursor = in_cursor_sel_rect(event->pos());
if (overCursor == 0) {
_view.add_cursor(CursorColor[_view.get_cursorList().size() % 8], index);
@ -440,10 +439,10 @@ void Ruler::draw_logic_tick_mark(QPainter &p)
}
}
if (_view.trig_cursor_shown()) {
_view.get_trig_cursor()->paint_fix_label(p, rect(), prefix, 'T', _view.get_trig_cursor()->colour());
_view.get_trig_cursor()->paint_fix_label(p, rect(), prefix, 'T', _view.get_trig_cursor()->colour(), false);
}
if (_view.search_cursor_shown()) {
_view.get_search_cursor()->paint_fix_label(p, rect(), prefix, 'S', _view.get_search_cursor()->colour());
_view.get_search_cursor()->paint_fix_label(p, rect(), prefix, 'S', _view.get_search_cursor()->colour(), true);
}
}

View File

@ -78,12 +78,9 @@ void TimeMarker::set_index(uint64_t index)
time_changed();
}
void TimeMarker::paint(QPainter &p, const QRect &rect, const bool highlight, int order)
void TimeMarker::paint(QPainter &p, const QRect &rect, const bool highlight, int order, bool trig_hoff)
{
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
const double scale = _view.scale();
const double samples_per_pixel = sample_rate * scale;
const int64_t x = _index/samples_per_pixel - _view.offset();
const int64_t x = _view.index2pixel(_index, trig_hoff);
if (x <= rect.right()) {
QColor color = (order == -1) ? _colour : Ruler::CursorColor[order%8];
p.setPen((_grabbed | highlight) ? QPen(color.lighter(), 2, Qt::DashLine) : QPen(color, 1, Qt::DashLine));

View File

@ -84,7 +84,7 @@ public:
* @param p The painter to draw with.
* @param rect The rectangle of the viewport client area.
*/
virtual void paint(QPainter &p, const QRect &rect, const bool highlight, int order);
virtual void paint(QPainter &p, const QRect &rect, const bool highlight, int order, bool trig_hoff = true);
/**
* Gets the marker label rectangle.
@ -92,7 +92,7 @@ public:
* @param visible is this marker in visible area
* @return Returns the label rectangle.
*/
virtual QRect get_label_rect(const QRect &rect, bool &visible) const = 0;
virtual QRect get_label_rect(const QRect &rect, bool &visible, bool has_hoff = true) const = 0;
/**
* Paints the marker's label to the ruler.
@ -103,9 +103,6 @@ public:
virtual void paint_label(QPainter &p, const QRect &rect,
unsigned int prefix, int index) = 0;
virtual void paint_fix_label(QPainter &p, const QRect &rect,
unsigned int prefix, QChar label, QColor color) = 0;
signals:
void time_changed();

View File

@ -211,6 +211,13 @@ pv::view::Viewport* Trace::get_viewport() const
return _viewport;
}
void Trace::paint_prepare()
{
assert(_view);
_view->set_trig_hoff(0);
}
void Trace::paint_back(QPainter &p, int left, int right, QColor fore, QColor back)
{
(void)back;

View File

@ -153,6 +153,11 @@ public:
virtual void set_viewport(pv::view::Viewport *viewport);
pv::view::Viewport* get_viewport() const;
/**
* Paints prepare
**/
virtual void paint_prepare();
/**
* Paints the background layer of the trace with a QPainter
* @param p the QPainter to paint into.

View File

@ -90,6 +90,7 @@ View::View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget
_offset(0),
_preOffset(0),
_updating_scroll(false),
_trig_hoff(0),
_show_cursors(false),
_search_hit(false),
_show_xcursors(false),
@ -229,6 +230,16 @@ int64_t View::offset() const
return _offset;
}
double View::trig_hoff() const
{
return _trig_hoff;
}
void View::set_trig_hoff(double hoff)
{
_trig_hoff = hoff;
}
double View::get_minscale() const
{
return _minscale;
@ -251,6 +262,7 @@ void View::capture_init()
set_scale_offset(_maxscale, 0);
status_clear();
_trig_time_setted = false;
_trig_hoff = 0;
}
void View::zoom(double steps)
@ -1275,5 +1287,25 @@ void View::set_back(bool ready)
_back_ready = ready;
}
double View::index2pixel(uint64_t index, bool has_hoff)
{
const double samples_per_pixel = session().cur_snap_samplerate() * scale();
double pixels;
if (has_hoff)
pixels = index/samples_per_pixel - offset() + trig_hoff()/samples_per_pixel;
else
pixels = index/samples_per_pixel - offset();
return pixels;
}
uint64_t View::pixel2index(double pixel)
{
const double samples_per_pixel = session().cur_snap_samplerate() * scale();
uint64_t index = (pixel + offset()) * samples_per_pixel - trig_hoff();
return index;
}
} // namespace view
} // namespace pv

View File

@ -118,6 +118,12 @@ public:
int64_t offset() const;
int v_offset() const;
/**
* trigger position fix
*/
double trig_hoff() const;
void set_trig_hoff(double hoff);
int64_t get_min_offset();
int64_t get_max_offset();
@ -227,6 +233,12 @@ public:
bool back_ready() const;
void set_back(bool ready);
/*
* untils
*/
double index2pixel(uint64_t index, bool has_hoff = true);
uint64_t pixel2index(double pixel);
signals:
void hover_point_changed();
@ -351,6 +363,9 @@ private:
int _signalHeight;
bool _updating_scroll;
// trigger position fix
double _trig_hoff;
bool _show_cursors;
std::list<Cursor*> _cursorList;
Cursor *_trig_cursor;

View File

@ -231,12 +231,11 @@ void Viewport::paintSignals(QPainter &p, QColor fore, QColor back)
// plot cursors
//const QRect xrect = QRect(rect().left(), rect().top(), _view.get_view_width(), rect().height());
const QRect xrect = _view.get_view_rect();
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
if (_view.cursors_shown() && _type == TIME_VIEW) {
list<Cursor*>::iterator i = _view.get_cursorList().begin();
int index = 0;
while (i != _view.get_cursorList().end()) {
const int64_t cursorX = (*i)->index()/samples_per_pixel - _view.offset();
const int64_t cursorX = _view.index2pixel((*i)->index());
if (xrect.contains(_view.hover_point().x(), _view.hover_point().y()) &&
qAbs(cursorX - _view.hover_point().x()) <= HitCursorMargin)
(*i)->paint(p, xrect, 1, index);
@ -286,10 +285,10 @@ void Viewport::paintSignals(QPainter &p, QColor fore, QColor back)
if (_type == TIME_VIEW) {
if (_view.trig_cursor_shown()) {
_view.get_trig_cursor()->paint(p, xrect, 0, -1);
_view.get_trig_cursor()->paint(p, xrect, 0, -1, false);
}
if (_view.search_cursor_shown()) {
const int64_t searchX = _view.get_search_cursor()->index()/samples_per_pixel - _view.offset();
const int64_t searchX = _view.index2pixel(_view.get_search_cursor()->index());
if (xrect.contains(_view.hover_point().x(), _view.hover_point().y()) &&
qAbs(searchX - _view.hover_point().x()) <= HitCursorMargin)
_view.get_search_cursor()->paint(p, xrect, 1, -1);
@ -492,7 +491,7 @@ void Viewport::mousePressEvent(QMouseEvent *event)
_action_type = LOGIC_ZOOM;
} else if (_view.session().get_device()->dev_inst()->mode == DSO) {
if (_hover_hit) {
const int64_t index = (_view.offset() + event->pos().x()) * _view.scale() * _view.session().cur_snap_samplerate();
const int64_t index = _view.pixel2index(event->pos().x());
_view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], index);
_view.show_cursors(true);
}
@ -520,10 +519,8 @@ void Viewport::mousePressEvent(QMouseEvent *event)
if (_action_type == NO_ACTION &&
event->button() == Qt::LeftButton) {
uint64_t sample_rate = _view.session().cur_snap_samplerate();
const double samples_per_pixel = sample_rate * _view.scale();
if (_action_type == NO_ACTION && _view.search_cursor_shown()) {
const int64_t searchX = _view.get_search_cursor()->index()/samples_per_pixel - _view.offset();
const int64_t searchX = _view.index2pixel(_view.get_search_cursor()->index());
if (_view.get_search_cursor()->grabbed()) {
_view.get_ruler()->rel_grabbed_cursor();
} else if (qAbs(searchX - event->pos().x()) <= HitCursorMargin) {
@ -534,7 +531,7 @@ void Viewport::mousePressEvent(QMouseEvent *event)
if (_action_type == NO_ACTION && _view.cursors_shown()) {
list<Cursor*>::iterator i = _view.get_cursorList().begin();
while (i != _view.get_cursorList().end()) {
const int64_t cursorX = (*i)->index()/samples_per_pixel - _view.offset();
const int64_t cursorX = _view.index2pixel((*i)->index());
if ((*i)->grabbed()) {
_view.get_ruler()->rel_grabbed_cursor();
} else if (qAbs(cursorX - event->pos().x()) <= HitCursorMargin) {
@ -645,7 +642,6 @@ void Viewport::mouseMoveEvent(QMouseEvent *event)
}
}
if (_action_type == CURS_MOVE) {
uint64_t sample_rate = _view.session().cur_snap_samplerate();
TimeMarker* grabbed_marker = _view.get_ruler()->get_grabbed_cursor();
if (grabbed_marker) {
int curX = _view.hover_point().x();
@ -670,12 +666,10 @@ void Viewport::mouseMoveEvent(QMouseEvent *event)
}
}
const double cur_time = (_view.offset() + curX) * _view.scale();
const double pos = cur_time * sample_rate;
const double pos = _view.pixel2index(curX);
const double pos_delta = pos - (uint64_t)pos;
const double samples_per_pixel = sample_rate * _view.scale();
const double curP = index0 / samples_per_pixel - _view.offset();
const double curN = index1 / samples_per_pixel - _view.offset();
const double curP = _view.index2pixel(index0);
const double curN = _view.index2pixel(index1);
if (logic && (curX - curP < SnapMinSpace || curN - curX < SnapMinSpace)) {
if (curX - curP < curN - curX)
grabbed_marker->set_index(index0);
@ -742,7 +736,6 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
assert(event);
if (_type == TIME_VIEW) {
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
if ((_action_type == NO_ACTION) &&
(event->button() == Qt::LeftButton)) {
if (_view.session().get_device()->dev_inst()->mode == LOGIC &&
@ -773,8 +766,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
if ((logicSig = dynamic_pointer_cast<view::LogicSignal>(s))) {
if (logicSig->edge(event->pos(), _edge_start, 10)) {
_action_type = LOGIC_JUMP;
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
_cur_preX = _edge_start / samples_per_pixel - _view.offset();
_cur_preX = _view.index2pixel(_edge_start);
_cur_preY = logicSig->get_y();
_cur_preY_top = logicSig->get_y() - logicSig->get_totalHeight()/2 - 12;
_cur_preY_bottom = logicSig->get_y() + logicSig->get_totalHeight()/2 + 2;
@ -795,7 +787,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
assert(s);
if (abs(event->pos().y() - s->get_y()) < _view.get_signalHeight()) {
_action_type = LOGIC_EDGE;
_edge_start = (_view.offset() + event->pos().x()) * _view.scale() * _view.session().cur_snap_samplerate();
_edge_start = _view.pixel2index(event->pos().x());
break;
}
}
@ -838,7 +830,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
}
} else if (_action_type == DSO_XM_STEP1) {
if (event->button() == Qt::LeftButton) {
_dso_xm_index[1] = (event->pos().x() + _view.offset()) * samples_per_pixel;
_dso_xm_index[1] = _view.pixel2index(event->pos().x());
const uint64_t max_index = max(_dso_xm_index[0], _dso_xm_index[1]);
_dso_xm_index[0] = min(_dso_xm_index[0], _dso_xm_index[1]);
_dso_xm_index[1] = max_index;
@ -850,7 +842,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event)
}
} else if (_action_type == DSO_XM_STEP2) {
if (event->button() == Qt::LeftButton) {
_dso_xm_index[2] = (event->pos().x() + _view.offset()) * samples_per_pixel;
_dso_xm_index[2] = _view.pixel2index(event->pos().x());
uint64_t max_index = max(_dso_xm_index[1], _dso_xm_index[2]);
_dso_xm_index[1] = min(_dso_xm_index[1], _dso_xm_index[2]);
_dso_xm_index[2] = max_index;
@ -956,18 +948,16 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
}
}
}
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
const double curX = event->pos().x();
const double samples_per_pixel = sample_rate * _view.scale();
const double curP = index0 / samples_per_pixel - _view.offset();
const double curN = index1 / samples_per_pixel - _view.offset();
const double curP = _view.index2pixel(index0);
const double curN = _view.index2pixel(index1);
if (logic && (curX - curP < SnapMinSpace || curN - curX < SnapMinSpace)) {
if (curX - curP < curN - curX)
index = index0;
else
index = index1;
} else {
index = (_view.offset() + curX) * _view.scale() * sample_rate;;
index = _view.pixel2index(curX);
}
_view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], index);
_view.show_cursors(true);
@ -983,36 +973,18 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event)
BOOST_FOREACH(const boost::shared_ptr<Signal> s, _view.session().get_signals()) {
assert(s);
if (s->get_view_rect().contains(event->pos())) {
uint64_t sample_rate = _view.session().cur_snap_samplerate();
double scale = _view.scale();
const double samples_per_pixel = sample_rate * scale;
_dso_xm_index[0] = (event->pos().x() + _view.offset()) * samples_per_pixel;
_dso_xm_index[0] = _view.pixel2index(event->pos().x());
_dso_xm_y = event->pos().y();
_action_type = DSO_XM_STEP0;
}
break;
}
}
// } else if (_view.session().get_device()->dev_inst()->mode == DSO) {
// if (event->button() == Qt::RightButton) {
// double ypos = (event->pos().y() - _view.get_view_rect().top()) * 1.0 / _view.get_view_height();
// _view.add_xcursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], ypos, ypos);
// _view.show_xcursors(true);
// }
// } else if (event->button() == Qt::LeftButton) {
// uint64_t index;
// const uint64_t sample_rate = _view.session().cur_snap_samplerate();
// const double curX = event->pos().x();
// index = (_view.offset() + curX) * _view.scale() * sample_rate;;
// _view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], index);
// _view.show_cursors(true);
// }
} else if (_view.session().get_device()->dev_inst()->mode == ANALOG) {
if (event->button() == Qt::LeftButton) {
uint64_t index;
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
const double curX = event->pos().x();
index = (_view.offset() + curX) * _view.scale() * sample_rate;;
index = _view.pixel2index(curX);
_view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], index);
_view.show_cursors(true);
}
@ -1140,10 +1112,9 @@ void Viewport::measure()
_mm_period = _thd_sample != 0 ? _view.get_ruler()->format_real_time(_thd_sample - _cur_sample, sample_rate) : "#####";
_mm_freq = _thd_sample != 0 ? _view.get_ruler()->format_real_freq(_thd_sample - _cur_sample, sample_rate) : "#####";
const double samples_per_pixel = sample_rate * _view.scale();
_cur_preX = _cur_sample / samples_per_pixel - _view.offset();
_cur_aftX = _nxt_sample / samples_per_pixel - _view.offset();
_cur_thdX = _thd_sample / samples_per_pixel - _view.offset();
_cur_preX = _view.index2pixel(_cur_sample);
_cur_aftX = _view.index2pixel(_nxt_sample);
_cur_thdX = _view.index2pixel(_thd_sample);
_cur_midY = logicSig->get_y();
_mm_duty = _thd_sample != 0 ? QString::number((_nxt_sample - _cur_sample) * 100.0 / (_thd_sample - _cur_sample), 'f', 2)+"%" :
@ -1158,8 +1129,7 @@ void Viewport::measure()
}
} else if (_action_type == LOGIC_EDGE) {
if (logicSig->edges(_view.hover_point(), _edge_start, _edge_rising, _edge_falling)) {
const double samples_per_pixel = sample_rate * _view.scale();
_cur_preX = _edge_start / samples_per_pixel - _view.offset();
_cur_preX = _view.index2pixel(_edge_start);
_cur_aftX = _view.hover_point().x();
_cur_midY = logicSig->get_y() - logicSig->get_totalHeight()/2 - 5;
@ -1170,17 +1140,16 @@ void Viewport::measure()
break;
}
} else if (_action_type == LOGIC_JUMP) {
const double samples_per_pixel = _view.session().cur_snap_samplerate() * _view.scale();
if (logicSig->edge(_view.hover_point(), _edge_end, 10)) {
_cur_aftX = _edge_end / samples_per_pixel - _view.offset();
_cur_aftX = _view.index2pixel(_edge_end);
_cur_aftY = logicSig->get_y();
_edge_hit = true;
break;
} else {
_cur_preX = _edge_start / samples_per_pixel - _view.offset();
_cur_preX = _view.index2pixel(_edge_start);
_cur_aftX = _view.hover_point().x();
_cur_aftY = _view.hover_point().y();
_edge_end = (_cur_aftX + _view.offset()) * samples_per_pixel;
_edge_end = _view.pixel2index(_cur_aftX);
_edge_hit = false;
}
}
@ -1320,9 +1289,7 @@ void Viewport::paintMeasure(QPainter &p, QColor fore, QColor back)
p.setPen(QPen(dsoSig->get_colour(), 1, Qt::DotLine));
const int text_height = p.boundingRect(0, 0, INT_MAX, INT_MAX,
Qt::AlignLeft | Qt::AlignTop, "W").height();
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
const int64_t x = (_dso_ym_index / (sample_rate * _view.scale())) -
_view.offset();
const int64_t x = _view.index2pixel(_dso_ym_index);
p.drawLine(x-10, _dso_ym_start,
x+10, _dso_ym_start);
p.drawLine(x, _dso_ym_start,
@ -1380,8 +1347,7 @@ void Viewport::paintMeasure(QPainter &p, QColor fore, QColor back)
dso_xm_stage = 3;
for (int i = 0; i < dso_xm_stage; i++) {
x[i] = (_dso_xm_index[i] / (sample_rate * _view.scale())) -
_view.offset();
x[i] = _view.index2pixel(_dso_xm_index[i]);
}
measure_line_count = 0;
if (dso_xm_stage > 0) {
@ -1644,9 +1610,8 @@ void Viewport::show_contextmenu(const QPoint& pos)
void Viewport::add_cursor_y()
{
uint64_t index;
const uint64_t sample_rate = _view.session().cur_snap_samplerate();
//const double curX = _menu_pos.x();
index = (_view.offset() + _cur_preX) * _view.scale() * sample_rate;;
index = _view.pixel2index(_cur_preX);
_view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], index);
_view.show_cursors(true);
}

View File

@ -1048,7 +1048,8 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
for(l = sdi->channels; l; l = l->next) {
struct sr_channel *probe = (struct sr_channel *)l->data;
probe->vpos_trans = devc->profile->dev_caps.default_pwmtrans;
probe->comb_comp = devc->profile->dev_caps.default_comb_comp;
//probe->comb_comp = devc->profile->dev_caps.default_comb_comp;
//probe->digi_fgain = 0;
if (probe->vga_ptr != NULL) {
for (i = 0; devc->profile->dev_caps.vdivs[i]; i++) {
for (j = 0; j < ARRAY_SIZE(vga_defaults); j++) {
@ -1206,6 +1207,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
} else if (id == SR_CONF_PROBE_COMB_COMP) {
ch->comb_comp = g_variant_get_int16(data);
ret = dsl_wr_dso(sdi, dso_cmd_gen(sdi, ch, SR_CONF_PROBE_VDIV));
ret = dsl_wr_dso(sdi, dso_cmd_gen(sdi, ch, SR_CONF_PROBE_OFFSET));
if (ret == SR_OK)
sr_dbg("%s: setting COMB_COMP of channel %d to %d mv",
__func__, ch->index, ch->comb_comp);

View File

@ -728,8 +728,9 @@ SR_PRIV int dsl_fpga_arm(const struct sr_dev_inst *sdi)
setting.count_header = 0x0302;
setting.trig_pos_header = 0x0502;
setting.trig_glb_header = 0x0701;
setting.ch_en_header = 0x0801;
setting.dso_count_header = 0x0902;
setting.dso_count_header = 0x0802;
setting.ch_en_header = 0x0a02;
setting.fgain_header = 0x0c01;
setting.trig_header = 0x40a0;
setting.end_sync = 0xfa5afa5a;
@ -1760,9 +1761,11 @@ static void get_measure(const struct sr_dev_inst *sdi, uint8_t *buf, uint32_t of
devc->mstatus.vlen = *((const uint32_t*)buf + offset/2 + 2/2) & 0x0fffffff;
devc->mstatus.stream_mode = (*((const uint32_t*)buf + offset/2 + 2/2) & 0x80000000) != 0;
devc->mstatus.measure_valid = *((const uint32_t*)buf + offset/2 + 2/2) & 0x40000000;
devc->mstatus.sample_divider = *((const uint32_t*)buf + offset/2 + 4/2) & 0x0fffffff;
devc->mstatus.sample_divider = *((const uint32_t*)buf + offset/2 + 4/2) & 0x00ffffff;
devc->mstatus.sample_divider_tog = (*((const uint32_t*)buf + offset/2 + 4/2) & 0x80000000) != 0;
devc->mstatus.trig_flag = (*((const uint32_t*)buf + offset/2 + 4/2) & 0x40000000) != 0;
devc->mstatus.trig_ch = (*((const uint8_t*)buf + offset*2 + 5*2+1) & 0x38) >> 3;
devc->mstatus.trig_offset = *((const uint8_t*)buf + offset*2 + 5*2+1) & 0x07;
devc->mstatus.ch0_max = *((const uint8_t*)buf + offset*2 + 33*2);
devc->mstatus.ch0_min = *((const uint8_t*)buf + offset*2 + 33*2+1);

View File

@ -387,6 +387,8 @@ struct sr_datafeed_dso {
gboolean samplerate_tog;
/** trig flag */
gboolean trig_flag;
/** trig channel */
uint8_t trig_ch;
/** The analog value(s). The data is interleaved according to
* the probes list. */
void *data;
@ -703,6 +705,8 @@ struct sr_status {
uint32_t sample_divider;
gboolean sample_divider_tog;
gboolean trig_flag;
uint8_t trig_ch;
uint8_t trig_offset;
uint8_t ch0_max;
uint8_t ch0_min;