forked from Ivasoft/DSView
Add DSLogic hardware support
This commit is contained in:
@@ -64,9 +64,11 @@ AnalogSignal::~AnalogSignal()
|
||||
}
|
||||
|
||||
void AnalogSignal::set_data(boost::shared_ptr<data::Logic> _logic_data,
|
||||
boost::shared_ptr<data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<data::Group> _group_data)
|
||||
{
|
||||
(void)_dso_data;
|
||||
(void)_logic_data;
|
||||
(void)_group_data;
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
void del_decoder();
|
||||
|
||||
void set_data(boost::shared_ptr<pv::data::Logic> _logic_data,
|
||||
boost::shared_ptr<pv::data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<pv::data::Group> _group_data);
|
||||
|
||||
|
||||
220
DSLogic-gui/pv/view/dsosignal.cpp
Normal file
220
DSLogic-gui/pv/view/dsosignal.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* This file is part of the DSLogic-gui project.
|
||||
* DSLogic-gui is based on PulseView.
|
||||
*
|
||||
* Copyright (C) 2013 DreamSourceLab <dreamsourcelab@dreamsourcelab.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#include <extdef.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "dsosignal.h"
|
||||
#include "pv/data/dso.h"
|
||||
#include "pv/data/dsosnapshot.h"
|
||||
|
||||
using namespace boost;
|
||||
using namespace std;
|
||||
|
||||
namespace pv {
|
||||
namespace view {
|
||||
|
||||
const QColor DsoSignal::SignalColours[4] = {
|
||||
QColor(17, 133, 209, 255), // dsBlue
|
||||
QColor(238, 178, 17, 255), // dsYellow
|
||||
QColor(213, 15, 37, 255), // dsRed
|
||||
QColor(0, 153, 37, 255) // dsGreen
|
||||
};
|
||||
|
||||
const float DsoSignal::EnvelopeThreshold = 256.0f;
|
||||
|
||||
DsoSignal::DsoSignal(QString name, shared_ptr<data::Dso> data,
|
||||
int probe_index, int order) :
|
||||
Signal(name, probe_index, DS_DSO, order),
|
||||
_data(data)
|
||||
{
|
||||
_colour = SignalColours[probe_index % countof(SignalColours)];
|
||||
_scale = _signalHeight * 1.0f / 256;
|
||||
}
|
||||
|
||||
DsoSignal::~DsoSignal()
|
||||
{
|
||||
}
|
||||
|
||||
void DsoSignal::set_data(boost::shared_ptr<data::Logic> _logic_data,
|
||||
boost::shared_ptr<data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<data::Group> _group_data)
|
||||
{
|
||||
(void)_analog_data;
|
||||
(void)_logic_data;
|
||||
(void)_group_data;
|
||||
|
||||
assert(_dso_data);
|
||||
|
||||
_data = _dso_data;
|
||||
}
|
||||
|
||||
void DsoSignal::set_scale(float scale)
|
||||
{
|
||||
_scale = scale;
|
||||
}
|
||||
|
||||
void DsoSignal::paint(QPainter &p, int y, int left, int right, double scale,
|
||||
double offset)
|
||||
{
|
||||
assert(scale > 0);
|
||||
assert(_data);
|
||||
assert(right >= left);
|
||||
|
||||
//paint_axis(p, y, left, right);
|
||||
|
||||
const deque< shared_ptr<pv::data::DsoSnapshot> > &snapshots =
|
||||
_data->get_snapshots();
|
||||
if (snapshots.empty())
|
||||
return;
|
||||
|
||||
_scale = _signalHeight * 1.0f / 256;
|
||||
const shared_ptr<pv::data::DsoSnapshot> &snapshot =
|
||||
snapshots.front();
|
||||
|
||||
if ((unsigned int)get_index() >= snapshot->get_channel_num())
|
||||
return;
|
||||
|
||||
const double pixels_offset = offset / scale;
|
||||
const double samplerate = _data->get_samplerate();
|
||||
const double start_time = _data->get_start_time();
|
||||
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 = samplerate * (offset - start_time);
|
||||
const double end = start + samples_per_pixel * (right - left);
|
||||
|
||||
const int64_t start_sample = min(max((int64_t)floor(start),
|
||||
(int64_t)0), last_sample);
|
||||
const int64_t end_sample = min(max((int64_t)ceil(end) + 1,
|
||||
(int64_t)0), last_sample);
|
||||
|
||||
if (samples_per_pixel < EnvelopeThreshold)
|
||||
paint_trace(p, snapshot, y, left,
|
||||
start_sample, end_sample,
|
||||
pixels_offset, samples_per_pixel);
|
||||
else
|
||||
paint_envelope(p, snapshot, y, left,
|
||||
start_sample, end_sample,
|
||||
pixels_offset, samples_per_pixel);
|
||||
}
|
||||
|
||||
void DsoSignal::paint_trace(QPainter &p,
|
||||
const shared_ptr<pv::data::DsoSnapshot> &snapshot,
|
||||
int y, int left, const int64_t start, const int64_t end,
|
||||
const double pixels_offset, const double samples_per_pixel)
|
||||
{
|
||||
const int64_t sample_count = end - start;
|
||||
|
||||
if (sample_count > 0) {
|
||||
const uint16_t *const samples = snapshot->get_samples(start, end);
|
||||
assert(samples);
|
||||
|
||||
p.setPen(_colour);
|
||||
//p.setPen(QPen(_colour, 3, Qt::SolidLine));
|
||||
|
||||
QPointF *points = new QPointF[sample_count];
|
||||
QPointF *point = points;
|
||||
|
||||
for (int64_t sample = start; sample != end; sample++) {
|
||||
const float x = (sample / samples_per_pixel - pixels_offset) + left;
|
||||
uint16_t offset = samples[sample - start];
|
||||
*point++ = QPointF(x,
|
||||
y - ((get_index() == 0) ? offset & 0x00ff : offset >> 8) * _scale);
|
||||
}
|
||||
|
||||
p.drawPolyline(points, point - points);
|
||||
|
||||
//delete[] samples;
|
||||
delete[] points;
|
||||
}
|
||||
}
|
||||
|
||||
void DsoSignal::paint_envelope(QPainter &p,
|
||||
const shared_ptr<pv::data::DsoSnapshot> &snapshot,
|
||||
int y, int left, const int64_t start, const int64_t end,
|
||||
const double pixels_offset, const double samples_per_pixel)
|
||||
{
|
||||
using namespace Qt;
|
||||
using pv::data::DsoSnapshot;
|
||||
|
||||
DsoSnapshot::EnvelopeSection e;
|
||||
snapshot->get_envelope_section(e, start, end, samples_per_pixel, get_index());
|
||||
|
||||
if (e.length < 2)
|
||||
return;
|
||||
|
||||
p.setPen(QPen(NoPen));
|
||||
//p.setPen(QPen(_colour, 2, Qt::SolidLine));
|
||||
p.setBrush(_colour);
|
||||
|
||||
QRectF *const rects = new QRectF[e.length];
|
||||
QRectF *rect = rects;
|
||||
|
||||
for(uint64_t sample = 0; sample < e.length-1; sample++) {
|
||||
const float x = ((e.scale * sample + e.start) /
|
||||
samples_per_pixel - pixels_offset) + left;
|
||||
const DsoSnapshot::EnvelopeSample *const s =
|
||||
e.samples + sample;
|
||||
|
||||
// We overlap this sample with the next so that vertical
|
||||
// gaps do not appear during steep rising or falling edges
|
||||
const float b = y - max(s->max, (s+1)->min) * _scale;
|
||||
const float t = y - min(s->min, (s+1)->max) * _scale;
|
||||
|
||||
float h = b - t;
|
||||
if(h >= 0.0f && h <= 1.0f)
|
||||
h = 1.0f;
|
||||
if(h <= 0.0f && h >= -1.0f)
|
||||
h = -1.0f;
|
||||
|
||||
*rect++ = QRectF(x, t, 1.0f, h);
|
||||
}
|
||||
|
||||
p.drawRects(rects, e.length);
|
||||
|
||||
delete[] rects;
|
||||
//delete[] e.samples;
|
||||
}
|
||||
|
||||
const std::vector< std::pair<uint64_t, bool> > DsoSignal::cur_edges() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DsoSignal::set_decoder(pv::decoder::Decoder *decoder)
|
||||
{
|
||||
(void)decoder;
|
||||
}
|
||||
|
||||
decoder::Decoder *DsoSignal::get_decoder()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void DsoSignal::del_decoder()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace view
|
||||
} // namespace pv
|
||||
101
DSLogic-gui/pv/view/dsosignal.h
Normal file
101
DSLogic-gui/pv/view/dsosignal.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* This file is part of the DSLogic-gui project.
|
||||
* DSLogic-gui is based on PulseView.
|
||||
*
|
||||
* Copyright (C) 2013 DreamSourceLab <dreamsourcelab@dreamsourcelab.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DSLOGIC_PV_DSOSIGNAL_H
|
||||
#define DSLOGIC_PV_DSOSIGNAL_H
|
||||
|
||||
#include "signal.h"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
namespace pv {
|
||||
|
||||
namespace data {
|
||||
class Logic;
|
||||
class Dso;
|
||||
class Analog;
|
||||
class DsoSnapshot;
|
||||
}
|
||||
|
||||
namespace view {
|
||||
|
||||
class DsoSignal : public Signal
|
||||
{
|
||||
private:
|
||||
static const QColor SignalColours[4];
|
||||
|
||||
static const float EnvelopeThreshold;
|
||||
|
||||
public:
|
||||
DsoSignal(QString name,
|
||||
boost::shared_ptr<pv::data::Dso> data, int probe_index, int order);
|
||||
|
||||
virtual ~DsoSignal();
|
||||
|
||||
void set_scale(float scale);
|
||||
|
||||
/**
|
||||
* Paints the signal with a QPainter
|
||||
* @param p the QPainter to paint into.
|
||||
* @param y the y-coordinate to draw the signal at.
|
||||
* @param left the x-coordinate of the left edge of the signal.
|
||||
* @param right the x-coordinate of the right edge of the signal.
|
||||
* @param scale the scale in seconds per pixel.
|
||||
* @param offset the time to show at the left hand edge of
|
||||
* the view in seconds.
|
||||
**/
|
||||
void paint(QPainter &p, int y, int left, int right, double scale,
|
||||
double offset);
|
||||
|
||||
const std::vector< std::pair<uint64_t, bool> > cur_edges() const;
|
||||
|
||||
void set_decoder(pv::decoder::Decoder *decoder);
|
||||
|
||||
pv::decoder::Decoder* get_decoder();
|
||||
|
||||
void del_decoder();
|
||||
|
||||
void set_data(boost::shared_ptr<pv::data::Logic> _logic_data,
|
||||
boost::shared_ptr<pv::data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<pv::data::Group> _group_data);
|
||||
|
||||
private:
|
||||
void paint_trace(QPainter &p,
|
||||
const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot,
|
||||
int y, int left, const int64_t start, const int64_t end,
|
||||
const double pixels_offset, const double samples_per_pixel);
|
||||
|
||||
void paint_envelope(QPainter &p,
|
||||
const boost::shared_ptr<pv::data::DsoSnapshot> &snapshot,
|
||||
int y, int left, const int64_t start, const int64_t end,
|
||||
const double pixels_offset, const double samples_per_pixel);
|
||||
|
||||
private:
|
||||
boost::shared_ptr<pv::data::Dso> _data;
|
||||
float _scale;
|
||||
};
|
||||
|
||||
} // namespace view
|
||||
} // namespace pv
|
||||
|
||||
#endif // DSLOGIC_PV_DSOSIGNAL_H
|
||||
@@ -58,10 +58,12 @@ GroupSignal::~GroupSignal()
|
||||
}
|
||||
|
||||
void GroupSignal::set_data(boost::shared_ptr<data::Logic> _logic_data,
|
||||
boost::shared_ptr<data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<data::Group> _group_data)
|
||||
{
|
||||
(void)_logic_data;
|
||||
(void)_dso_data;
|
||||
(void)_analog_data;
|
||||
|
||||
assert(_group_data);
|
||||
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
void del_decoder();
|
||||
|
||||
void set_data(boost::shared_ptr<pv::data::Logic> _logic_data,
|
||||
boost::shared_ptr<pv::data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<pv::data::Group> _group_data);
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ void Header::paintEvent(QPaintEvent*)
|
||||
w, s->get_old_v_offset() - v_offset - s->get_signalHeight());
|
||||
painter.drawLine(0, s->get_old_v_offset() - v_offset,
|
||||
w, s->get_old_v_offset() - v_offset);
|
||||
} else {
|
||||
} else if (s->get_type() == Signal::DS_LOGIC){
|
||||
painter.drawLine(0, s->get_old_v_offset() - v_offset + 10,
|
||||
w, s->get_old_v_offset() - v_offset + 10);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ void Header::paintEvent(QPaintEvent*)
|
||||
w, s->get_v_offset() - v_offset);
|
||||
painter.drawLine(0, s->get_v_offset() - v_offset - s->get_signalHeight(),
|
||||
w, s->get_v_offset() - v_offset - s->get_signalHeight());
|
||||
} else {
|
||||
} else if (s->get_type() == Signal::DS_LOGIC) {
|
||||
painter.drawLine(0, s->get_v_offset() - v_offset + 10,
|
||||
w, s->get_v_offset() - v_offset + 10);
|
||||
}
|
||||
|
||||
@@ -82,9 +82,11 @@ LogicSignal::~LogicSignal()
|
||||
}
|
||||
|
||||
void LogicSignal::set_data(boost::shared_ptr<data::Logic> _logic_data,
|
||||
boost::shared_ptr<data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<data::Group> _group_data)
|
||||
{
|
||||
(void)_dso_data;
|
||||
(void)_analog_data;
|
||||
(void)_group_data;
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ public:
|
||||
virtual ~LogicSignal();
|
||||
|
||||
void set_data(boost::shared_ptr<pv::data::Logic> _logic_data,
|
||||
boost::shared_ptr<pv::data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<pv::data::Group> _group_data);
|
||||
/**
|
||||
|
||||
@@ -55,10 +55,11 @@ ProtocolSignal::~ProtocolSignal()
|
||||
{
|
||||
}
|
||||
|
||||
void ProtocolSignal::set_data(boost::shared_ptr<data::Logic> _logic_data,
|
||||
void ProtocolSignal::set_data(boost::shared_ptr<data::Logic> _logic_data, boost::shared_ptr<data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<data::Group> _group_data)
|
||||
{
|
||||
(void)_dso_data;
|
||||
(void)_analog_data;
|
||||
(void)_group_data;
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
virtual ~ProtocolSignal();
|
||||
|
||||
void set_data(boost::shared_ptr<pv::data::Logic> _logic_data,
|
||||
boost::shared_ptr<pv::data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<pv::data::Group> _group_data);
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace pv {
|
||||
namespace data {
|
||||
class SignalData;
|
||||
class Logic;
|
||||
class Dso;
|
||||
class Analog;
|
||||
class Group;
|
||||
}
|
||||
@@ -76,7 +77,7 @@ public:
|
||||
static const QColor dsLightRed;
|
||||
static const QPen SignalAxisPen;
|
||||
|
||||
enum {DS_LOGIC = 0, DS_ANALOG, DS_GROUP, DS_PROTOCOL};
|
||||
enum {DS_LOGIC = 0, DS_ANALOG, DS_GROUP, DS_PROTOCOL, DS_DSO};
|
||||
|
||||
protected:
|
||||
Signal(QString name, int index, int type, int order);
|
||||
@@ -187,6 +188,7 @@ public:
|
||||
virtual void del_decoder() = 0;
|
||||
|
||||
virtual void set_data(boost::shared_ptr<pv::data::Logic> _logic_data,
|
||||
boost::shared_ptr<pv::data::Dso> _dso_data,
|
||||
boost::shared_ptr<pv::data::Analog> _analog_data,
|
||||
boost::shared_ptr<pv::data::Group> _group_data) = 0;
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ void Viewport::paintEvent(QPaintEvent *event)
|
||||
(void)event;
|
||||
|
||||
using pv::view::Signal;
|
||||
|
||||
int i, j;
|
||||
QStyleOption o;
|
||||
o.initFrom(this);
|
||||
QPainter p(this);
|
||||
@@ -118,7 +118,7 @@ void Viewport::paintEvent(QPaintEvent *event)
|
||||
paintProgress(p);
|
||||
break;
|
||||
}
|
||||
} else if (_view.session().get_device()->mode == ANALOG) {
|
||||
} else {
|
||||
paintSignals(p);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,6 @@ void Viewport::paintEvent(QPaintEvent *event)
|
||||
p.setPen(Signal::dsGray);
|
||||
const double sigY = s->get_v_offset() - _view.v_offset();
|
||||
|
||||
int i, j;
|
||||
if (s->get_type() == Signal::DS_ANALOG) {
|
||||
p.drawLine(0, sigY, width(), sigY);
|
||||
const double spanY = (s->get_signalHeight()) * 1.0f / NumSpanY;
|
||||
@@ -152,11 +151,39 @@ void Viewport::paintEvent(QPaintEvent *event)
|
||||
p.drawLine(0 + spanX * i, sigY,
|
||||
0 + spanX * i, sigY - s->get_signalHeight());
|
||||
}
|
||||
} else {
|
||||
} else if (s->get_type() == Signal::DS_LOGIC) {
|
||||
p.drawLine(0, sigY + 10, width(), sigY + 10);
|
||||
}
|
||||
}
|
||||
|
||||
if (_view.session().get_device()->mode == DSO) {
|
||||
|
||||
p.setPen(Signal::dsGray);
|
||||
p.setPen(Qt::DotLine);
|
||||
|
||||
const double spanY =height() * 1.0f / 8;
|
||||
for (i = 1; i < 9; i++) {
|
||||
const double posY = spanY * i;
|
||||
p.drawLine(0, posY, width(), posY);
|
||||
const double miniSpanY = spanY / 5;
|
||||
for (j = 1; j < 5; j++) {
|
||||
p.drawLine(width() / 2.0f - 10, posY - miniSpanY * j,
|
||||
width() / 2.0f + 10, posY - miniSpanY * j);
|
||||
}
|
||||
}
|
||||
const double spanX = width() * 1.0f / 10;
|
||||
for (i = 1; i < 11; i++) {
|
||||
const double posX = spanX * i;
|
||||
p.drawLine(posX, 0,
|
||||
posX, height());
|
||||
const double miniSpanX = spanX / 5;
|
||||
for (j = 1; j < 5; j++) {
|
||||
p.drawLine(posX - miniSpanX * j, height() / 2.0f - 10,
|
||||
posX - miniSpanX * j, height() / 2.0f + 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p.end();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user