]> sigrok.org Git - pulseview.git/blobdiff - pv/view/logicsignal.cpp
Added trigger selection handlers
[pulseview.git] / pv / view / logicsignal.cpp
index 7bf43594b602934ef5fca0b284cbbb7873a3a44f..ea138fa76d2b2285e50c588ed26b833c4e1df170 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "logicsignal.h"
 #include "view.h"
+
+#include "pv/sigsession.h"
 #include "pv/data/logic.h"
 #include "pv/data/logicsnapshot.h"
 
@@ -39,7 +41,7 @@ const QColor LogicSignal::EdgeColour(0x80, 0x80, 0x80);
 const QColor LogicSignal::HighColour(0x00, 0xC0, 0x00);
 const QColor LogicSignal::LowColour(0xC0, 0x00, 0x00);
 
-const QColor LogicSignal::LogicSignalColours[10] = {
+const QColor LogicSignal::SignalColours[10] = {
        QColor(0x16, 0x19, 0x1A),       // Black
        QColor(0x8F, 0x52, 0x02),       // Brown
        QColor(0xCC, 0x00, 0x00),       // Red
@@ -52,15 +54,86 @@ const QColor LogicSignal::LogicSignalColours[10] = {
        QColor(0xEE, 0xEE, 0xEC),       // White
 };
 
-LogicSignal::LogicSignal(QString name, shared_ptr<data::Logic> data,
-       int probe_index) :
-       Signal(name),
-       _probe_index(probe_index),
-       _data(data)
+LogicSignal::LogicSignal(pv::SigSession &session, const sr_probe *const probe,
+       shared_ptr<data::Logic> data) :
+       Signal(session, probe),
+       _data(data),
+       _separator(this),
+       _icon_trigger_none(":/icons/trigger-none.svg"),
+       _trigger_none(_icon_trigger_none, tr("No trigger"), this),
+       _icon_trigger_rising(":/icons/trigger-rising.svg"),
+       _trigger_rising(_icon_trigger_rising,
+               tr("Trigger on rising edge"), this),
+       _icon_trigger_high(":/icons/trigger-high.svg"),
+       _trigger_high(_icon_trigger_high,
+               tr("Trigger on high level"), this),
+       _icon_trigger_falling(":/icons/trigger-falling.svg"),
+       _trigger_falling(_icon_trigger_falling,
+               tr("Trigger on falling edge"), this),
+       _icon_trigger_low(":/icons/trigger-low.svg"),
+       _trigger_low(_icon_trigger_low,
+               tr("Trigger on low level"), this),
+       _icon_trigger_change(":/icons/trigger-change.svg"),
+       _trigger_change(_icon_trigger_change,
+               tr("Trigger on rising or falling edge"), this)
 {
-       assert(_probe_index >= 0);
-       _colour = LogicSignalColours[
-               _probe_index % countof(LogicSignalColours)];
+       _colour = SignalColours[probe->index % countof(SignalColours)];
+
+       _separator.setSeparator(true);
+
+       connect(&_trigger_none, SIGNAL(triggered()),
+               this, SLOT(on_trigger_none()));
+       connect(&_trigger_rising, SIGNAL(triggered()),
+               this, SLOT(on_trigger_rising()));
+       connect(&_trigger_high, SIGNAL(triggered()),
+               this, SLOT(on_trigger_high()));
+       connect(&_trigger_falling, SIGNAL(triggered()),
+               this, SLOT(on_trigger_falling()));
+       connect(&_trigger_low, SIGNAL(triggered()),
+               this, SLOT(on_trigger_low()));
+       connect(&_trigger_change, SIGNAL(triggered()),
+               this, SLOT(on_trigger_change()));
+}
+
+LogicSignal::~LogicSignal()
+{
+}
+
+const list<QAction*> LogicSignal::get_context_bar_actions()
+{
+       GVariant *gvar;
+       list<QAction*> actions;
+
+       actions.push_back(&_name_action);
+
+       // Add the trigger actions
+       const sr_dev_inst *const sdi = _session.get_device();
+       if (sr_config_list(sdi->driver, SR_CONF_TRIGGER_TYPE,
+               &gvar, sdi) == SR_OK) {
+               const char *const trig_types =
+                       g_variant_get_string(gvar, NULL);
+
+               if (trig_types && trig_types[0] != '\0') {
+                       actions.push_back(&_separator);
+
+                       actions.push_back(&_trigger_none);
+
+                       add_trigger_action(trig_types, 'r',
+                               &_trigger_rising, actions);
+                       add_trigger_action(trig_types, '1',
+                               &_trigger_high, actions);
+                       add_trigger_action(trig_types, 'f',
+                               &_trigger_falling, actions);
+                       add_trigger_action(trig_types, '0',
+                               &_trigger_low, actions);
+                       add_trigger_action(trig_types, 'c',
+                               &_trigger_change, actions);
+               }
+
+               g_variant_unref(gvar);
+       }
+
+       return actions;
 }
 
 void LogicSignal::paint(QPainter &p, int y, int left, int right,
@@ -72,10 +145,14 @@ void LogicSignal::paint(QPainter &p, int y, int left, int right,
 
        vector< pair<int64_t, bool> > edges;
 
+       assert(_probe);
        assert(scale > 0);
        assert(_data);
        assert(right >= left);
 
+       if (!_probe->enabled)
+               return;
+
        paint_axis(p, y, left, right);
 
        const float high_offset = y - View::SignalHeight + 0.5f;
@@ -105,7 +182,7 @@ void LogicSignal::paint(QPainter &p, int y, int left, int right,
        snapshot->get_subsampled_edges(edges,
                min(max((int64_t)floor(start), (int64_t)0), last_sample),
                min(max((int64_t)ceil(end), (int64_t)0), last_sample),
-               samples_per_pixel / Oversampling, _probe_index);
+               samples_per_pixel / Oversampling, _probe->index);
        assert(edges.size() >= 2);
 
        // Paint the edges
@@ -159,5 +236,63 @@ void LogicSignal::paint_caps(QPainter &p, QLineF *const lines,
        p.drawLines(lines, line - lines);
 }
 
+void LogicSignal::add_trigger_action(const char *trig_types, char type,
+       QAction *action, list<QAction*> &actions)
+{
+       while(*trig_types)
+               if(*trig_types++ == type) {
+                       actions.push_back(action);
+                       break;
+               }
+}
+
+void LogicSignal::set_trigger(char type)
+{
+       const char trigger_type_string[2] = {type, 0};
+       const char *const trigger_string =
+               (type != 0) ? trigger_type_string : NULL;
+
+       const sr_dev_inst *const sdi = _session.get_device();
+       const int probe_count = g_slist_length(sdi->probes);
+       assert(probe_count > 0);
+
+       assert(_probe && _probe->index < probe_count);
+
+       for (int i = 0; i < probe_count; i++) {
+               sr_dev_trigger_set(sdi, i, (i == _probe->index) ?
+                       trigger_string : NULL);
+       }
+}
+
+void LogicSignal::on_trigger_none()
+{
+       set_trigger('\0');      
+}
+
+void LogicSignal::on_trigger_rising()
+{
+       set_trigger('r');       
+}
+
+void LogicSignal::on_trigger_high()
+{
+       set_trigger('1');       
+}
+
+void LogicSignal::on_trigger_falling()
+{
+       set_trigger('f');       
+}
+
+void LogicSignal::on_trigger_low()
+{
+       set_trigger('0');       
+}
+
+void LogicSignal::on_trigger_change()
+{
+       set_trigger('c');       
+}
+
 } // namespace view
 } // namespace pv