]> sigrok.org Git - pulseview.git/commitdiff
Restart min-max-based conversion if min or max change
authorSoeren Apel <redacted>
Tue, 1 Aug 2017 18:58:46 +0000 (20:58 +0200)
committerUwe Hermann <redacted>
Thu, 3 Aug 2017 11:06:27 +0000 (13:06 +0200)
pv/data/analog.cpp
pv/data/analog.hpp
pv/data/analogsegment.cpp
pv/data/signalbase.cpp
pv/data/signalbase.hpp

index 854dae3e68eaaec8d71212219365323abcefbbe8..51e7f4953b78370af21b5b8401bf01adf682fad6 100644 (file)
@@ -74,5 +74,10 @@ void Analog::notify_samples_added(QObject* segment, uint64_t start_sample,
        samples_added(segment, start_sample, end_sample);
 }
 
+void Analog::notify_min_max_changed(float min, float max)
+{
+       min_max_changed(min, max);
+}
+
 } // namespace data
 } // namespace pv
index 30860ce18e4a0c4f98590629fd965c8a0326d3de..633c6fba296eb24a47166772fcc11b960b218649 100644 (file)
@@ -56,12 +56,16 @@ public:
        void notify_samples_added(QObject* segment, uint64_t start_sample,
                uint64_t end_sample);
 
+       void notify_min_max_changed(float min, float max);
+
 Q_SIGNALS:
        void samples_cleared();
 
        void samples_added(QObject* segment, uint64_t start_sample,
                uint64_t end_sample);
 
+       void min_max_changed(float min, float max);
+
 private:
        deque< shared_ptr<AnalogSegment> > segments_;
 };
index 6dc2b915b30c4683f766bf97da4f662c44a9c07d..0610a4a800ca426a961950491b1fa05fea920ba4 100644 (file)
@@ -178,6 +178,7 @@ void AnalogSegment::append_payload_to_envelope_levels()
        e0.length = sample_count_ / EnvelopeScaleFactor;
 
        // Calculate min/max values in case we have too few samples for an envelope
+       const float old_min_value = min_value_, old_max_value = max_value_;
        if (sample_count_ < EnvelopeScaleFactor) {
                it = begin_raw_sample_iteration(0);
                for (uint64_t i = 0; i < sample_count_; i++) {
@@ -257,6 +258,10 @@ void AnalogSegment::append_payload_to_envelope_levels()
                        *dest_ptr = sub_sample;
                }
        }
+
+       // Notify if the min or max value changed
+       if ((old_min_value != min_value_) || (old_max_value != max_value_))
+               owner_.min_max_changed(min_value_, max_value_);
 }
 
 } // namespace data
index b455111a89fbbd868dde6e92198dc1418a564153..797bd456817e9e1cb0ef2d4c39e193acbe33b165 100644 (file)
@@ -140,6 +140,14 @@ void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
                        this, SLOT(on_samples_cleared()));
                disconnect(data.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
                        this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t)));
+
+               if (channel_type_ == AnalogChannel) {
+                       shared_ptr<Analog> analog = analog_data();
+                       assert(analog);
+
+                       disconnect(analog.get(), SIGNAL(min_max_changed(float, float)),
+                               this, SLOT(on_min_max_changed(float, float)));
+               }
        }
 
        data_ = data;
@@ -149,6 +157,14 @@ void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
                        this, SLOT(on_samples_cleared()));
                connect(data.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
                        this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t)));
+
+               if (channel_type_ == AnalogChannel) {
+                       shared_ptr<Analog> analog = analog_data();
+                       assert(analog);
+
+                       connect(analog.get(), SIGNAL(min_max_changed(float, float)),
+                               this, SLOT(on_min_max_changed(float, float)));
+               }
        }
 }
 
@@ -560,14 +576,23 @@ void SignalBase::on_samples_added(QObject* segment, uint64_t start_sample,
        samples_added(segment, start_sample, end_sample);
 }
 
+void SignalBase::on_min_max_changed(float min, float max)
+{
+       (void)min;
+       (void)max;
+
+       // Restart conversion if one is enabled and uses an automatic threshold
+       if ((conversion_type_ != NoConversion) &&
+               (get_current_conversion_preset() == 0))
+               start_conversion();
+}
+
 void SignalBase::on_capture_state_changed(int state)
 {
        if (state == Session::Running) {
-               if (conversion_type_ != NoConversion) {
-                       // Restart conversion
-                       stop_conversion();
+               // Restart conversion if one is enabled
+               if (conversion_type_ != NoConversion)
                        start_conversion();
-               }
        }
 }
 
index 67b3f7c485f06daee23b99369fd510051f8fcc85..32085a43b929a68e5223019eb04ec94e81e3e88f 100644 (file)
@@ -279,6 +279,8 @@ private Q_SLOTS:
        void on_samples_added(QObject* segment, uint64_t start_sample,
                uint64_t end_sample);
 
+       void on_min_max_changed(float min, float max);
+
        void on_capture_state_changed(int state);
 
 protected: