]> sigrok.org Git - pulseview.git/blobdiff - pv/data/signalbase.cpp
Restart min-max-based conversion if min or max change
[pulseview.git] / pv / data / signalbase.cpp
index 514459d283449b9617fbf0353962ff18cc974de5..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)));
+               }
        }
 }
 
@@ -169,7 +185,7 @@ shared_ptr<data::Logic> SignalBase::logic_data() const
        if (channel_type_ == LogicChannel)
                result = dynamic_pointer_cast<Logic>(data_);
 
-       if (((conversion_type_ == A2LConversionByTreshold) ||
+       if (((conversion_type_ == A2LConversionByThreshold) ||
                (conversion_type_ == A2LConversionBySchmittTrigger)))
                result = dynamic_pointer_cast<Logic>(converted_data_);
 
@@ -239,7 +255,7 @@ vector<double> SignalBase::get_conversion_thresholds(const ConversionType t,
        else
                preset = get_current_conversion_preset();
 
-       if (conv_type == A2LConversionByTreshold) {
+       if (conv_type == A2LConversionByThreshold) {
                double thr = 0;
 
                if (preset == -1) {
@@ -295,7 +311,7 @@ vector< pair<QString, int> > SignalBase::get_conversion_presets() const
 {
        vector< pair<QString, int> > presets;
 
-       if (conversion_type_ == A2LConversionByTreshold) {
+       if (conversion_type_ == A2LConversionByThreshold) {
                // Source: http://www.interfacebus.com/voltage_threshold.html
                presets.emplace_back(tr("Signal average"), 0);
                presets.emplace_back(tr("0.9V (for 1.8V CMOS)"), 1);
@@ -373,7 +389,7 @@ void SignalBase::restore_settings(QSettings &settings)
 bool SignalBase::conversion_is_a2l() const
 {
        return ((channel_type_ == AnalogChannel) &&
-               ((conversion_type_ == A2LConversionByTreshold) ||
+               ((conversion_type_ == A2LConversionByThreshold) ||
                (conversion_type_ == A2LConversionBySchmittTrigger)));
 }
 
@@ -427,7 +443,7 @@ void SignalBase::conversion_thread_proc(QObject* segment)
                                // Convert
                                uint64_t i = start_sample;
 
-                               if (conversion_type_ == A2LConversionByTreshold) {
+                               if (conversion_type_ == A2LConversionByThreshold) {
                                        const double threshold = get_conversion_thresholds()[0];
 
                                        // Convert as many sample blocks as we can
@@ -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();
-               }
        }
 }