]> sigrok.org Git - pulseview.git/commitdiff
Session/View: Save triggers in a list and use it
authorSoeren Apel <redacted>
Wed, 7 Feb 2018 09:51:30 +0000 (10:51 +0100)
committerSoeren Apel <redacted>
Wed, 7 Feb 2018 18:41:56 +0000 (19:41 +0100)
pv/mainwindow.cpp
pv/session.cpp
pv/session.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp
pv/views/viewbase.cpp
pv/views/viewbase.hpp

index 52b625086d4830df551f5a302e61cb1d3db30b5f..91e38729167d98135b8d9755ecdc315042820217 100644 (file)
@@ -174,9 +174,9 @@ shared_ptr<views::ViewBase> 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<views::ViewBase*>(v.get()),
-               SLOT(trigger_event(util::Timestamp)));
+               SLOT(trigger_event(int, util::Timestamp)));
 
        if (type == views::ViewTypeTrace) {
                views::trace::View *tv =
index c18575ad415559a8e66fa0fae7a6b65774a53c59..ca72e9b0d670fed6a14da47d4c7c2ce79946c078 100644 (file)
@@ -567,6 +567,8 @@ void Session::start_capture(function<void (const QString)> error_handler)
        for (const shared_ptr<data::SignalData> 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<devices::HardwareDevice> hw_device =
@@ -689,6 +691,17 @@ uint32_t Session::get_segment_count() const
        return value;
 }
 
+vector<util::Timestamp> Session::get_triggers(uint32_t segment_id) const
+{
+       vector<util::Timestamp> result;
+
+       for (pair<uint32_t, util::Timestamp> entry : trigger_list_)
+               if (entry.first == segment_id)
+                       result.push_back(entry.second);
+
+       return result;
+}
+
 const unordered_set< shared_ptr<data::SignalBase> > Session::signalbases() const
 {
        return signalbases_;
@@ -917,6 +930,7 @@ void Session::sample_thread_proc(function<void (const QString)> 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();
 }
index 19fd993872edc04ba8bae3ca8ad11568dce9a894..9148ba9bdcaafd8985f5b1f7c833f87d3b1e81f0 100644 (file)
@@ -165,6 +165,8 @@ public:
 
        uint32_t get_segment_count() const;
 
+       vector<util::Timestamp> get_triggers(uint32_t segment_id) const;
+
        void register_view(shared_ptr<views::ViewBase> view);
 
        void deregister_view(shared_ptr<views::ViewBase> 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<data::SignalBase> > signalbases_;
        unordered_set< shared_ptr<data::SignalData> > all_signal_data_;
 
+       /// trigger_list_ contains pairs of <segment_id, timestamp> values.
+       vector< std::pair<uint32_t, util::Timestamp> > trigger_list_;
+
        mutable recursive_mutex data_mutex_;
        shared_ptr<data::Logic> logic_data_;
        uint64_t cur_samplerate_;
index 9cd90be83015bafd4f709dc9d7a376418d11e56c..00a1c23968c0eb255b2f2b4a9957ce63242569e2 100644 (file)
@@ -541,6 +541,10 @@ void View::set_current_segment(uint32_t segment_id)
        for (shared_ptr<DecodeTrace> 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<TriggerMarker>(*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> 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();
index 4514989765b9603d4b8809c1eaa0c3a209fc3783..fb097b01cfb604fb9893d4d50390ca7b64e5100f 100644 (file)
@@ -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;
index 8311f122faa54e253b62bc11aca652d196b7c1ec..caed41eecb56daf0d3b58b1102e90d091c1f7ecb 100644 (file)
@@ -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;
 }
 
index 0a7605db153f822693aff9ae6c709265d86cd887..5d7d2adbb181a7cdaca7913404ea3ab3f07fa75e 100644 (file)
@@ -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);