X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Flogicsignal.cpp;h=69c495e609fafd84b8113e274b3d270305240ff8;hp=3a2ec4862dc5d6ae94432e799fcdf8860b5669b8;hb=0dda6fe595932b2e340930104fad8ac4fc574895;hpb=bb3030b34e44733036acdfe5b4d4ec0705146831 diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 3a2ec486..69c495e6 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include #include @@ -30,11 +32,13 @@ #include "view.h" #include -#include +#include #include #include #include +#include + using std::deque; using std::max; using std::min; @@ -42,6 +46,15 @@ using std::pair; using std::shared_ptr; using std::vector; +using sigrok::Channel; +using sigrok::ConfigKey; +using sigrok::Device; +using sigrok::Error; +using sigrok::Trigger; +using sigrok::TriggerStage; +using sigrok::TriggerMatch; +using sigrok::TriggerMatchType; + namespace pv { namespace view { @@ -64,9 +77,13 @@ const QColor LogicSignal::SignalColours[10] = { QColor(0xEE, 0xEE, 0xEC), // White }; -LogicSignal::LogicSignal(shared_ptr dev_inst, - const sr_channel *const probe, shared_ptr data) : - Signal(dev_inst, probe), +LogicSignal::LogicSignal( + pv::SigSession &session, + shared_ptr device, + shared_ptr channel, + shared_ptr data) : + Signal(session, channel), + _device(device), _data(data), _trigger_none(NULL), _trigger_rising(NULL), @@ -75,26 +92,18 @@ LogicSignal::LogicSignal(shared_ptr dev_inst, _trigger_low(NULL), _trigger_change(NULL) { - struct sr_trigger *trigger; - struct sr_trigger_stage *stage; - struct sr_trigger_match *match; - const GSList *l, *m; + shared_ptr trigger; - _colour = SignalColours[probe->index % countof(SignalColours)]; + _colour = SignalColours[channel->index() % countof(SignalColours)]; /* Populate this channel's trigger setting with whatever we * find in the current session trigger, if anything. */ - _trigger_match = 0; - if ((trigger = sr_session_trigger_get(SigSession::_sr_session))) { - for (l = trigger->stages; l && !_trigger_match; l = l->next) { - stage = (struct sr_trigger_stage *)l->data; - for (m = stage->matches; m && !_trigger_match; m = m->next) { - match = (struct sr_trigger_match *)m->data; - if (match->channel == _probe) - _trigger_match = match->match; - } - } - } + _trigger_match = nullptr; + if ((trigger = _session.session()->trigger())) + for (auto stage : trigger->stages()) + for (auto match : stage->matches()) + if (match->channel() == _channel) + _trigger_match = match->type(); } LogicSignal::~LogicSignal() @@ -113,7 +122,7 @@ shared_ptr LogicSignal::logic_data() const void LogicSignal::paint_back(QPainter &p, int left, int right) { - if (_probe->enabled) + if (_channel->enabled()) paint_axis(p, get_y(), left, right); } @@ -125,19 +134,22 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right) vector< pair > edges; - assert(_probe); + assert(_channel); assert(_data); assert(right >= left); + assert(_owner); - assert(_view); - const int y = _v_offset - _view->v_offset(); + const int y = get_y(); + + const View *const view = _owner->view(); + assert(view); - const double scale = _view->scale(); + const double scale = view->scale(); assert(scale > 0); - - const double offset = _view->offset(); - if (!_probe->enabled) + const double offset = view->offset(); + + if (!_channel->enabled()) return; const float high_offset = y - View::SignalHeight + 0.5f; @@ -167,7 +179,7 @@ void LogicSignal::paint_mid(QPainter &p, 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, _channel->index()); assert(edges.size() >= 2); // Paint the edges @@ -251,90 +263,121 @@ void LogicSignal::init_trigger_actions(QWidget *parent) connect(_trigger_change, SIGNAL(triggered()), this, SLOT(on_trigger())); } -QAction* LogicSignal::match_action(int match) +QAction* LogicSignal::match_action(const TriggerMatchType *type) { QAction *action; action = _trigger_none; - switch (match) { - case SR_TRIGGER_ZERO: - action = _trigger_low; - break; - case SR_TRIGGER_ONE: - action = _trigger_high; - break; - case SR_TRIGGER_RISING: - action = _trigger_rising; - break; - case SR_TRIGGER_FALLING: - action = _trigger_falling; - break; - case SR_TRIGGER_EDGE: - action = _trigger_change; - break; + if (type) { + switch (type->id()) { + case SR_TRIGGER_ZERO: + action = _trigger_low; + break; + case SR_TRIGGER_ONE: + action = _trigger_high; + break; + case SR_TRIGGER_RISING: + action = _trigger_rising; + break; + case SR_TRIGGER_FALLING: + action = _trigger_falling; + break; + case SR_TRIGGER_EDGE: + action = _trigger_change; + break; + default: + assert(0); + } } return action; } -int LogicSignal::action_match(QAction *action) +const TriggerMatchType *LogicSignal::action_match(QAction *action) { - int match; - if (action == _trigger_low) - match = SR_TRIGGER_ZERO; + return TriggerMatchType::ZERO; else if (action == _trigger_high) - match = SR_TRIGGER_ONE; + return TriggerMatchType::ONE; else if (action == _trigger_rising) - match = SR_TRIGGER_RISING; + return TriggerMatchType::RISING; else if (action == _trigger_falling) - match = SR_TRIGGER_FALLING; + return TriggerMatchType::FALLING; else if (action == _trigger_change) - match = SR_TRIGGER_EDGE; + return TriggerMatchType::EDGE; else - match = 0; - - return match; + return nullptr; } void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form) { - GVariant *gvar; - gsize num_opts; - const int32_t *trig_matches; - unsigned int i; - bool is_checked; + Glib::VariantContainerBase gvar; + vector trig_types; Signal::populate_popup_form(parent, form); - if (!(gvar = _dev_inst->list_config(NULL, SR_CONF_TRIGGER_MATCH))) + try { + gvar = _device->config_list(ConfigKey::TRIGGER_MATCH); + } catch (Error e) { return; + } _trigger_bar = new QToolBar(parent); init_trigger_actions(_trigger_bar); _trigger_bar->addAction(_trigger_none); - trig_matches = (const int32_t *)g_variant_get_fixed_array(gvar, - &num_opts, sizeof(int32_t)); - for (i = 0; i < num_opts; i++) { - _trigger_bar->addAction(match_action(trig_matches[i])); - is_checked = _trigger_match == trig_matches[i]; - match_action(trig_matches[i])->setChecked(is_checked); + _trigger_none->setChecked(!_trigger_match); + trig_types = + Glib::VariantBase::cast_dynamic>>( + gvar).get(); + for (auto type_id : trig_types) { + auto type = TriggerMatchType::get(type_id); + _trigger_bar->addAction(match_action(type)); + match_action(type)->setChecked(_trigger_match == type); } form->addRow(tr("Trigger"), _trigger_bar); - g_variant_unref(gvar); } +void LogicSignal::modify_trigger() +{ + auto trigger = _session.session()->trigger(); + auto new_trigger = _session.device_manager().context()->create_trigger("pulseview"); + + if (trigger) { + for (auto stage : trigger->stages()) { + const auto &matches = stage->matches(); + if (std::none_of(begin(matches), end(matches), + [&](shared_ptr match) { + return match->channel() != _channel; })) + continue; + + auto new_stage = new_trigger->add_stage(); + for (auto match : stage->matches()) { + if (match->channel() == _channel) + continue; + new_stage->add_match(match->channel(), match->type()); + } + } + } + + if (_trigger_match) + new_trigger->add_stage()->add_match(_channel, _trigger_match); + + _session.session()->set_trigger( + new_trigger->stages().empty() ? nullptr : new_trigger); +} + void LogicSignal::on_trigger() { QAction *action; - match_action(_trigger_match)->setChecked(FALSE); + match_action(_trigger_match)->setChecked(false); action = (QAction *)sender(); - action->setChecked(TRUE); + action->setChecked(true); _trigger_match = action_match(action); + modify_trigger(); } } // namespace view