]> sigrok.org Git - pulseview.git/commitdiff
Fix #685 by adding a special T marker when SR_DT_TRIGGER arrives
authorSoeren Apel <redacted>
Thu, 5 Nov 2015 07:51:34 +0000 (08:51 +0100)
committerUwe Hermann <redacted>
Thu, 5 Nov 2015 20:36:19 +0000 (21:36 +0100)
pv/mainwindow.cpp
pv/session.cpp
pv/session.hpp
pv/view/flag.cpp
pv/view/flag.hpp
pv/view/view.cpp
pv/view/view.hpp

index ee2227d55782d957b3fb08e00f3961819759d464..dad9d680241ad4d59f4352c6dd80863d13b73cbd 100644 (file)
@@ -116,6 +116,8 @@ MainWindow::MainWindow(DeviceManager &device_manager,
        , menu_decoders_add_(new pv::widgets::DecoderMenu(this, true))
 #endif
 {
+       qRegisterMetaType<util::Timestamp>("util::Timestamp");
+
        setup_ui();
        restore_ui_settings();
        if (open_file_name.empty())
@@ -532,12 +534,15 @@ void MainWindow::setup_ui()
                SLOT(capture_state_changed(int)));
        connect(&session_, SIGNAL(device_selected()), this,
                SLOT(device_selected()));
+       connect(&session_, SIGNAL(trigger_event(util::Timestamp)), view_,
+               SLOT(trigger_event(util::Timestamp)));
 
        // Setup view_ events
        connect(view_, SIGNAL(sticky_scrolling_changed(bool)), this,
                SLOT(sticky_scrolling_changed(bool)));
        connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)), this,
                SLOT(always_zoom_to_fit_changed(bool)));
+
 }
 
 void MainWindow::select_init_device() {
index 07405fe4ba79de4a0003c9d08070ed47406c23a0..da9c0e9bb4af998abf3a3303eb525536245b3ba9 100644 (file)
@@ -492,6 +492,27 @@ void Session::feed_in_meta(shared_ptr<Meta> meta)
        signals_changed();
 }
 
+void Session::feed_in_trigger()
+{
+       // The channel containing most samples should be most accurate
+       uint64_t sample_count = 0;
+
+       for (const shared_ptr<pv::data::SignalData> d : get_data()) {
+               assert(d);
+               uint64_t temp_count = 0;
+
+               const vector< shared_ptr<pv::data::Segment> > segments =
+                       d->segments();
+               for (const shared_ptr<pv::data::Segment> &s : segments)
+                       temp_count += s->get_sample_count();
+
+               if (temp_count > sample_count)
+                       sample_count = temp_count;
+       }
+
+       trigger_event(sample_count / get_samplerate());
+}
+
 void Session::feed_in_frame_begin()
 {
        if (cur_logic_segment_ || !cur_analog_segments_.empty())
@@ -616,6 +637,10 @@ void Session::data_feed_in(shared_ptr<sigrok::Device> device,
                feed_in_meta(dynamic_pointer_cast<Meta>(packet->payload()));
                break;
 
+       case SR_DF_TRIGGER:
+               feed_in_trigger();
+               break;
+
        case SR_DF_FRAME_BEGIN:
                feed_in_frame_begin();
                break;
index 0a8f018cbc1216a898d63d0393f80236cca486f7..f2f8c7c8e26549be7e6ba8a5e5977c3faf6b10f2 100644 (file)
@@ -40,6 +40,8 @@
 #include <QObject>
 #include <QString>
 
+#include "util.hpp"
+
 struct srd_decoder;
 struct srd_channel;
 
@@ -144,6 +146,8 @@ private:
 
        void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
 
+       void feed_in_trigger();
+
        void feed_in_frame_begin();
 
        void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
@@ -182,6 +186,8 @@ Q_SIGNALS:
 
        void signals_changed();
 
+       void trigger_event(util::Timestamp location);
+
        void frame_began();
 
        void data_received();
index 779ea2eec24cd8d5088b2675f9ede6978c682ba1..380ef3273091b1f4d8d29f1bc68a5dd296e581da 100644 (file)
@@ -108,5 +108,15 @@ void Flag::on_text_changed(const QString &text)
        view_.time_item_appearance_changed(true, false);
 }
 
+void Flag::drag_by(const QPoint &delta)
+{
+       // Treat trigger markers as immovable
+       if (text_ == "T")
+               return;
+
+       TimeMarker::drag_by(delta);
+}
+
+
 } // namespace view
 } // namespace pv
index bc82934e161e5829d5d025f515931c5817a60268..af4c7b9d15012ee89e691dfee9eeea13c1c20c90 100644 (file)
@@ -68,6 +68,8 @@ public:
 
        void delete_pressed();
 
+       void drag_by(const QPoint &delta);
+
 private Q_SLOTS:
        void on_delete();
 
index 7de1c792c06fa9880eee2d295e4cc8fc9672ef19..7f9caa4cb50e69fb63f50e621d5dad01adbebc99 100644 (file)
@@ -462,8 +462,14 @@ void View::add_flag(const Timestamp& time)
 {
        flags_.push_back(shared_ptr<Flag>(new Flag(*this, time,
                QString("%1").arg(next_flag_text_))));
+
        next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
                (next_flag_text_ + 1);
+
+       // Skip 'T' (for trigger) as it's treated special
+       if (next_flag_text_ == 'T')
+               next_flag_text_ += 1;
+
        time_item_appearance_changed(true, true);
 }
 
@@ -518,6 +524,16 @@ void View::restack_all_trace_tree_items()
                i->animate_to_layout_v_offset();
 }
 
+void View::trigger_event(util::Timestamp location)
+{
+       char next_flag_text = next_flag_text_;
+
+       next_flag_text_ = 'T';
+       add_flag(location);
+
+       next_flag_text_ = next_flag_text;
+}
+
 void View::get_scroll_layout(double &length, Timestamp &offset) const
 {
        const pair<Timestamp, Timestamp> extents = get_time_extents();
index 95e518a274db8c11314ca22808bbea6fd0831108..9bb42ef14ea6e239500482698c81f95994c94cc9 100644 (file)
@@ -238,6 +238,9 @@ Q_SIGNALS:
        /// Emitted when the time_unit changed.
        void time_unit_changed();
 
+public Q_SLOTS:
+       void trigger_event(util::Timestamp location);
+
 private:
        void get_scroll_layout(double &length, pv::util::Timestamp &offset) const;