From: Soeren Apel Date: Thu, 5 Nov 2015 07:51:34 +0000 (+0100) Subject: Fix #685 by adding a special T marker when SR_DT_TRIGGER arrives X-Git-Tag: pulseview-0.3.0~49 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=48257a69ffad409c9893605d99cd6e15161dff4f;hp=3d79f521396c8e908fd237f5328153165099f5c3 Fix #685 by adding a special T marker when SR_DT_TRIGGER arrives --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index ee2227d5..dad9d680 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -116,6 +116,8 @@ MainWindow::MainWindow(DeviceManager &device_manager, , menu_decoders_add_(new pv::widgets::DecoderMenu(this, true)) #endif { + qRegisterMetaType("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() { diff --git a/pv/session.cpp b/pv/session.cpp index 07405fe4..da9c0e9b 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -492,6 +492,27 @@ void Session::feed_in_meta(shared_ptr 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 d : get_data()) { + assert(d); + uint64_t temp_count = 0; + + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &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 device, feed_in_meta(dynamic_pointer_cast(packet->payload())); break; + case SR_DF_TRIGGER: + feed_in_trigger(); + break; + case SR_DF_FRAME_BEGIN: feed_in_frame_begin(); break; diff --git a/pv/session.hpp b/pv/session.hpp index 0a8f018c..f2f8c7c8 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -40,6 +40,8 @@ #include #include +#include "util.hpp" + struct srd_decoder; struct srd_channel; @@ -144,6 +146,8 @@ private: void feed_in_meta(std::shared_ptr meta); + void feed_in_trigger(); + void feed_in_frame_begin(); void feed_in_logic(std::shared_ptr logic); @@ -182,6 +186,8 @@ Q_SIGNALS: void signals_changed(); + void trigger_event(util::Timestamp location); + void frame_began(); void data_received(); diff --git a/pv/view/flag.cpp b/pv/view/flag.cpp index 779ea2ee..380ef327 100644 --- a/pv/view/flag.cpp +++ b/pv/view/flag.cpp @@ -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 diff --git a/pv/view/flag.hpp b/pv/view/flag.hpp index bc82934e..af4c7b9d 100644 --- a/pv/view/flag.hpp +++ b/pv/view/flag.hpp @@ -68,6 +68,8 @@ public: void delete_pressed(); + void drag_by(const QPoint &delta); + private Q_SLOTS: void on_delete(); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 7de1c792..7f9caa4c 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -462,8 +462,14 @@ void View::add_flag(const Timestamp& time) { flags_.push_back(shared_ptr(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 extents = get_time_extents(); diff --git a/pv/view/view.hpp b/pv/view/view.hpp index 95e518a2..9bb42ef1 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -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;