From: Soeren Apel Date: Wed, 7 Feb 2018 09:51:30 +0000 (+0100) Subject: Session/View: Save triggers in a list and use it X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7ea2a4ff0765fdad34b84e4b4631d6f3f5588714;p=pulseview.git Session/View: Save triggers in a list and use it --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 52b62508..91e38729 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -174,9 +174,9 @@ shared_ptr MainWindow::add_view(const QString &title, connect(close_btn, SIGNAL(clicked(bool)), this, SLOT(on_view_close_clicked())); - connect(&session, SIGNAL(trigger_event(util::Timestamp)), + connect(&session, SIGNAL(trigger_event(int, util::Timestamp)), qobject_cast(v.get()), - SLOT(trigger_event(util::Timestamp))); + SLOT(trigger_event(int, util::Timestamp))); if (type == views::ViewTypeTrace) { views::trace::View *tv = diff --git a/pv/session.cpp b/pv/session.cpp index c18575ad..ca72e9b0 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -567,6 +567,8 @@ void Session::start_capture(function error_handler) for (const shared_ptr d : all_signal_data_) d->clear(); + trigger_list_.clear(); + // Revert name back to default name (e.g. "Session 1") for real devices // as the (possibly saved) data is gone. File devices keep their name. shared_ptr hw_device = @@ -689,6 +691,17 @@ uint32_t Session::get_segment_count() const return value; } +vector Session::get_triggers(uint32_t segment_id) const +{ + vector result; + + for (pair entry : trigger_list_) + if (entry.first == segment_id) + result.push_back(entry.second); + + return result; +} + const unordered_set< shared_ptr > Session::signalbases() const { return signalbases_; @@ -917,6 +930,7 @@ void Session::sample_thread_proc(function error_handler) cur_analog_segments_.clear(); } highest_segment_id_ = -1; + frame_began_ = false; try { device_->start(); @@ -1066,7 +1080,13 @@ void Session::feed_in_trigger() } } - trigger_event(sample_count / get_samplerate()); + // If no frame began then this is a trigger for a new segment + const uint32_t segment_id = + (frame_began_) ? highest_segment_id_ : (highest_segment_id_ + 1); + + util::Timestamp timestamp = sample_count / get_samplerate(); + trigger_list_.emplace_back(segment_id, timestamp); + trigger_event(segment_id, timestamp); } void Session::feed_in_frame_begin() @@ -1094,8 +1114,7 @@ void Session::feed_in_frame_end() cur_analog_segments_.clear(); } - if (frame_began_) - frame_began_ = false; + frame_began_ = false; signal_segment_completed(); } diff --git a/pv/session.hpp b/pv/session.hpp index 19fd9938..9148ba9b 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -165,6 +165,8 @@ public: uint32_t get_segment_count() const; + vector get_triggers(uint32_t segment_id) const; + void register_view(shared_ptr view); void deregister_view(shared_ptr view); @@ -224,7 +226,7 @@ Q_SIGNALS: void name_changed(); - void trigger_event(util::Timestamp location); + void trigger_event(int segment_id, util::Timestamp location); void new_segment(int new_segment_id); void segment_completed(int segment_id); @@ -253,6 +255,9 @@ private: unordered_set< shared_ptr > signalbases_; unordered_set< shared_ptr > all_signal_data_; + /// trigger_list_ contains pairs of values. + vector< std::pair > trigger_list_; + mutable recursive_mutex data_mutex_; shared_ptr logic_data_; uint64_t cur_samplerate_; diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 9cd90be8..00a1c239 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -541,6 +541,10 @@ void View::set_current_segment(uint32_t segment_id) for (shared_ptr dt : decode_traces_) dt->set_current_segment(current_segment_); + trigger_markers_.clear(); + for (util::Timestamp timestamp : session_.get_triggers(segment_id)) + trigger_markers_.push_back(make_shared(*this, timestamp)); + viewport_->update(); segment_changed(segment_id); @@ -558,6 +562,8 @@ Trace::SegmentDisplayMode View::segment_display_mode() const void View::set_segment_display_mode(Trace::SegmentDisplayMode mode) { + trigger_markers_.clear(); + segment_display_mode_ = mode; for (shared_ptr signal : signals_) @@ -826,8 +832,12 @@ void View::restack_all_trace_tree_items() i->animate_to_layout_v_offset(); } -void View::trigger_event(util::Timestamp location) +void View::trigger_event(int segment_id, util::Timestamp location) { + // TODO This doesn't work if we're showing multiple segments at once + if ((uint32_t)segment_id != current_segment_) + return; + // Set up ruler_shift if the Key_View_TriggerIsZeroTime option is set. GlobalSettings settings; bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool(); diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 45149897..fb097b01 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -329,7 +329,7 @@ Q_SIGNALS: void segment_display_mode_changed(int mode, bool segment_selectable); public Q_SLOTS: - void trigger_event(util::Timestamp location); + void trigger_event(int segment_id, util::Timestamp location); private: void get_scroll_layout(double &length, pv::util::Timestamp &offset) const; diff --git a/pv/views/viewbase.cpp b/pv/views/viewbase.cpp index 8311f122..caed41ee 100644 --- a/pv/views/viewbase.cpp +++ b/pv/views/viewbase.cpp @@ -123,8 +123,9 @@ void ViewBase::restore_settings(QSettings &settings) (void)settings; } -void ViewBase::trigger_event(util::Timestamp location) +void ViewBase::trigger_event(int segment_id, util::Timestamp location) { + (void)segment_id; (void)location; } diff --git a/pv/views/viewbase.hpp b/pv/views/viewbase.hpp index 0a7605db..5d7d2adb 100644 --- a/pv/views/viewbase.hpp +++ b/pv/views/viewbase.hpp @@ -92,7 +92,7 @@ public: virtual void restore_settings(QSettings &settings); public Q_SLOTS: - virtual void trigger_event(util::Timestamp location); + virtual void trigger_event(int segment_id, util::Timestamp location); virtual void signals_changed(); virtual void capture_state_updated(int state); virtual void on_new_segment(int new_segment_id);