Parse the trigger types supported by the device
authorJoel Holdsworth <joel@airwebreathe.org.uk>
Mon, 27 May 2013 09:58:53 +0000 (10:58 +0100)
committerJoel Holdsworth <joel@airwebreathe.org.uk>
Mon, 27 May 2013 10:06:01 +0000 (11:06 +0100)
pv/view/logicsignal.cpp
pv/view/logicsignal.h

index cca25df282b5328767ce42cd0ead3b4dadb1e302..813bb29eedd94b5af04b3a73a297e3ef2e41f8d8 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"
 
@@ -86,17 +88,37 @@ LogicSignal::~LogicSignal()
 
 const list<QAction*> LogicSignal::get_context_bar_actions()
 {
+       GVariant *gvar;
        list<QAction*> actions;
+
        actions.push_back(&_name_action);
 
-       actions.push_back(&_separator);
+       // 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);
+               }
 
-       actions.push_back(&_trigger_none);
-       actions.push_back(&_trigger_rising);
-       actions.push_back(&_trigger_high);
-       actions.push_back(&_trigger_falling);
-       actions.push_back(&_trigger_low);
-       actions.push_back(&_trigger_change);
+               g_variant_unref(gvar);
+       }
 
        return actions;
 }
@@ -201,5 +223,15 @@ 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;
+               }
+}
+
 } // namespace view
 } // namespace pv
index 62b7c9ab1f9b085f02ed7dcaa43f2f59abb58acf..40babbcaf69a4d6a524101cc6f1e445c78fcca6d 100644 (file)
@@ -72,6 +72,9 @@ private:
                bool level, double samples_per_pixel, double pixels_offset,
                float x_offset, float y_offset);
 
+       static void add_trigger_action(const char *trig_types, char type,
+               QAction *action, std::list<QAction*> &actions);
+
 private:
        boost::shared_ptr<pv::data::Logic> _data;