From: Joel Holdsworth Date: Tue, 5 Jun 2012 08:19:43 +0000 (+0100) Subject: Parse logic signals X-Git-Tag: pulseview-0.1.0~346 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=e3f65ace22c6bcd371967302f8d01d0769e3a23f Parse logic signals --- diff --git a/logicsignal.cpp b/logicsignal.cpp index 48a95701..7a86b7c6 100644 --- a/logicsignal.cpp +++ b/logicsignal.cpp @@ -27,3 +27,13 @@ LogicSignal::LogicSignal(QString name, boost::shared_ptr data, { assert(_probe_index >= 0); } + +void LogicSignal::paint(QGLWidget &widget, const QRect &rect) +{ + glColor3f(1,0,0); + glBegin(GL_POLYGON); + glVertex2f(rect.left(), rect.top()); + glVertex2f(rect.right(), rect.top()); + glVertex2f(rect.right(), rect.bottom()); + glEnd(); +} diff --git a/logicsignal.h b/logicsignal.h index 9daf6500..91c70ab2 100644 --- a/logicsignal.h +++ b/logicsignal.h @@ -30,6 +30,8 @@ public: LogicSignal(QString name, boost::shared_ptr data, int probe_index); + void paint(QGLWidget &widget, const QRect &rect); + private: int _probe_index; }; diff --git a/signal.h b/signal.h index 47e1dc91..ee051dca 100644 --- a/signal.h +++ b/signal.h @@ -19,7 +19,11 @@ */ #include + +#include +#include #include + #include class SignalData; @@ -32,6 +36,8 @@ protected: public: QString get_name() const; + virtual void paint(QGLWidget &widget, const QRect &rect) = 0; + protected: QString _name; boost::shared_ptr _data; diff --git a/sigsession.cpp b/sigsession.cpp index 9b9798e0..e6288e7c 100644 --- a/sigsession.cpp +++ b/sigsession.cpp @@ -22,12 +22,14 @@ #include "logicdata.h" #include "logicdatasnapshot.h" +#include "logicsignal.h" #include #include using namespace boost; +using namespace std; // TODO: This should not be necessary SigSession* SigSession::session = NULL; @@ -55,6 +57,11 @@ void SigSession::loadFile(const std::string &name) } } +vector< shared_ptr >& SigSession::get_signals() +{ + return _signals; +} + void SigSession::dataFeedIn(const struct sr_dev_inst *sdi, struct sr_datafeed_packet *packet) { @@ -63,19 +70,38 @@ void SigSession::dataFeedIn(const struct sr_dev_inst *sdi, switch (packet->type) { case SR_DF_HEADER: + _signals.clear(); break; case SR_DF_META_LOGIC: { assert(packet->payload); - _logic_data.reset(new LogicData( - *(sr_datafeed_meta_logic*)packet->payload)); + const sr_datafeed_meta_logic &meta_logic = + *(sr_datafeed_meta_logic*)packet->payload; + // Create an empty LogiData for coming data snapshots + _logic_data.reset(new LogicData(meta_logic)); assert(_logic_data); if(!_logic_data) break; + // Add the signals + for (int i = 0; i < meta_logic.num_probes; i++) + { + const sr_probe *const probe = + (const sr_probe*)g_slist_nth_data( + sdi->probes, i); + if(probe->enabled) + { + boost::shared_ptr signal( + new LogicSignal(probe->name, + _logic_data, + probe->index)); + _signals.push_back(signal); + } + } + break; } diff --git a/sigsession.h b/sigsession.h index f91a2b92..a08ba812 100644 --- a/sigsession.h +++ b/sigsession.h @@ -23,9 +23,8 @@ #include -#include -#include #include +#include #include @@ -48,6 +47,9 @@ public: void loadFile(const std::string &name); + std::vector< boost::shared_ptr >& + get_signals(); + private: void dataFeedIn(const struct sr_dev_inst *sdi, struct sr_datafeed_packet *packet); @@ -56,7 +58,7 @@ private: struct sr_datafeed_packet *packet); private: - std::list< boost::shared_ptr > _signals; + std::vector< boost::shared_ptr > _signals; boost::shared_ptr _logic_data; boost::shared_ptr _cur_logic_snapshot; diff --git a/sigview.cpp b/sigview.cpp index b682cce9..565e67e2 100644 --- a/sigview.cpp +++ b/sigview.cpp @@ -21,6 +21,14 @@ #include "sigview.h" #include "sigsession.h" +#include "signal.h" + +#include + +using namespace boost; +using namespace std; + +const int SigView::SignalHeight = 50; SigView::SigView(SigSession &session, QWidget *parent) : QGLWidget(parent), @@ -55,10 +63,20 @@ void SigView::resizeGL(int width, int height) void SigView::paintGL() { glClear(GL_COLOR_BUFFER_BIT); + + QRect rect(0, 0, width(), SignalHeight); + const vector< shared_ptr > &sigs = + _session.get_signals(); + BOOST_FOREACH(const shared_ptr s, sigs) + { + assert(s); + s->paint(*this, rect); + rect.translate(0, SignalHeight); + } } void SigView::dataUpdated() { - printf("Data Updated\n"); + update(); } diff --git a/sigview.h b/sigview.h index 780d765a..b43ae9a5 100644 --- a/sigview.h +++ b/sigview.h @@ -29,6 +29,10 @@ class SigSession; class SigView : public QGLWidget { Q_OBJECT + +private: + static const int SignalHeight; + public: explicit SigView(SigSession &session, QWidget *parent = 0);