X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdata%2Fsignalbase.cpp;h=fe7c584b62b4eab7c58e2383b77989f0bd0194da;hp=514459d283449b9617fbf0353962ff18cc974de5;hb=f0f9c8566ba4992e3a3b71afd521da3278f37b7b;hpb=52c900ac8626b33cfd55485b4474fb5160524d33 diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index 514459d2..fe7c584b 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -140,6 +140,14 @@ void SignalBase::set_data(shared_ptr 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_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 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_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 SignalBase::logic_data() const if (channel_type_ == LogicChannel) result = dynamic_pointer_cast(data_); - if (((conversion_type_ == A2LConversionByTreshold) || + if (((conversion_type_ == A2LConversionByThreshold) || (conversion_type_ == A2LConversionBySchmittTrigger))) result = dynamic_pointer_cast(converted_data_); @@ -228,33 +244,33 @@ vector SignalBase::get_conversion_thresholds(const ConversionType t, { vector result; ConversionType conv_type = t; - int preset; + ConversionPreset preset; // Use currently active conversion if no conversion type was supplied if (conv_type == NoConversion) conv_type = conversion_type_; if (always_custom) - preset = -1; + preset = NoPreset; else preset = get_current_conversion_preset(); - if (conv_type == A2LConversionByTreshold) { + if (conv_type == A2LConversionByThreshold) { double thr = 0; - if (preset == -1) { + if (preset == NoPreset) { auto thr_iter = conversion_options_.find("threshold_value"); if (thr_iter != conversion_options_.end()) thr = (thr_iter->second).toDouble(); } - if (preset == 0) + if (preset == DynamicPreset) thr = (min_value_ + max_value_) * 0.5; // middle between min and max - if (preset == 1) thr = 0.9; - if (preset == 2) thr = 1.8; - if (preset == 3) thr = 2.5; - if (preset == 4) thr = 1.5; + if ((int)preset == 1) thr = 0.9; + if ((int)preset == 2) thr = 1.8; + if ((int)preset == 3) thr = 2.5; + if ((int)preset == 4) thr = 1.5; result.push_back(thr); } @@ -262,7 +278,7 @@ vector SignalBase::get_conversion_thresholds(const ConversionType t, if (conv_type == A2LConversionBySchmittTrigger) { double thr_lo = 0, thr_hi = 0; - if (preset == -1) { + if (preset == NoPreset) { auto thr_lo_iter = conversion_options_.find("threshold_value_low"); if (thr_lo_iter != conversion_options_.end()) thr_lo = (thr_lo_iter->second).toDouble(); @@ -272,17 +288,17 @@ vector SignalBase::get_conversion_thresholds(const ConversionType t, thr_hi = (thr_hi_iter->second).toDouble(); } - if (preset == 0) { + if (preset == DynamicPreset) { const double amplitude = max_value_ - min_value_; const double center = min_value_ + (amplitude / 2); thr_lo = center - (amplitude * 0.15); // 15% margin thr_hi = center + (amplitude * 0.15); // 15% margin } - if (preset == 1) { thr_lo = 0.3; thr_hi = 1.2; } - if (preset == 2) { thr_lo = 0.7; thr_hi = 2.5; } - if (preset == 3) { thr_lo = 1.3; thr_hi = 3.7; } - if (preset == 4) { thr_lo = 0.8; thr_hi = 2.0; } + if ((int)preset == 1) { thr_lo = 0.3; thr_hi = 1.2; } + if ((int)preset == 2) { thr_lo = 0.7; thr_hi = 2.5; } + if ((int)preset == 3) { thr_lo = 1.3; thr_hi = 3.7; } + if ((int)preset == 4) { thr_lo = 0.8; thr_hi = 2.0; } result.push_back(thr_lo); result.push_back(thr_hi); @@ -295,7 +311,7 @@ vector< pair > SignalBase::get_conversion_presets() const { vector< pair > 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); @@ -316,18 +332,18 @@ vector< pair > SignalBase::get_conversion_presets() const return presets; } -int SignalBase::get_current_conversion_preset() const +SignalBase::ConversionPreset SignalBase::get_current_conversion_preset() const { auto preset = conversion_options_.find("preset"); if (preset != conversion_options_.end()) - return (preset->second).toInt(); + return (ConversionPreset)((preset->second).toInt()); - return -1; + return NoPreset; } -void SignalBase::set_conversion_preset(int id) +void SignalBase::set_conversion_preset(ConversionPreset id) { - conversion_options_["preset"] = id; + conversion_options_["preset"] = (int)id; } #ifdef ENABLE_DECODE @@ -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 a calculated threshold + if ((conversion_type_ != NoConversion) && + (get_current_conversion_preset() == DynamicPreset)) + 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(); - } } }