From: Joel Holdsworth Date: Mon, 27 May 2013 09:58:53 +0000 (+0100) Subject: Parse the trigger types supported by the device X-Git-Tag: pulseview-0.2.0~337 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=0a78bcaf5e2e7c8da02868716609b3410f5a1ab9 Parse the trigger types supported by the device --- diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index cca25df2..813bb29e 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -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 LogicSignal::get_context_bar_actions() { + GVariant *gvar; list 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 &actions) +{ + while(*trig_types) + if(*trig_types++ == type) { + actions.push_back(action); + break; + } +} + } // namespace view } // namespace pv diff --git a/pv/view/logicsignal.h b/pv/view/logicsignal.h index 62b7c9ab..40babbca 100644 --- a/pv/view/logicsignal.h +++ b/pv/view/logicsignal.h @@ -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 &actions); + private: boost::shared_ptr _data;