From: Soeren Apel Date: Tue, 23 May 2017 16:41:20 +0000 (+0200) Subject: DecodeSignal: Provide conversion data container sooner X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ccccb91439b9de48a7bcc76c6fa45d1dc166a297;p=pulseview.git DecodeSignal: Provide conversion data container sooner Before, the converted_data_ container was only created once we had sample data coming in. This meant that it wasn't possible to assign a converted signal to a decoder. With this change, the data container is created even when there is no data to fill it with, allowing logic_data() to return a valid result and in turn allowing the user to assign the signal to a decoder. --- diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index 09e4400e..173610d9 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -185,6 +185,13 @@ void SignalBase::set_conversion_type(ConversionType t) conversion_type_ = t; + // Re-create an empty container + // so that the signal is recognized as providing logic data + // and thus can be assigned to a decoder + if (conversion_is_a2l()) + if (!converted_data_) + converted_data_ = make_shared(1); // Contains only one channel + start_conversion(); conversion_type_changed(t); @@ -229,6 +236,13 @@ uint8_t SignalBase::convert_a2l_schmitt_trigger(float lo_thr, float hi_thr, return state; } +bool SignalBase::conversion_is_a2l() const +{ + return ((channel_type_ == AnalogChannel) && + ((conversion_type_ == A2LConversionByTreshold) || + (conversion_type_ == A2LConversionBySchmittTrigger))); +} + void SignalBase::conversion_thread_proc(QObject* segment) { // TODO Support for multiple segments is missing @@ -237,19 +251,11 @@ void SignalBase::conversion_thread_proc(QObject* segment) start_sample = end_sample = 0; do { - if ((channel_type_ == AnalogChannel) && - ((conversion_type_ == A2LConversionByTreshold) || - (conversion_type_ == A2LConversionBySchmittTrigger))) { + if (conversion_is_a2l()) { AnalogSegment *asegment = qobject_cast(segment); - // Create the logic data container if needed - shared_ptr logic_data; - if (!converted_data_) { - logic_data = make_shared(1); // Contains only one channel - converted_data_ = logic_data; - } else - logic_data = dynamic_pointer_cast(converted_data_); + const shared_ptr logic_data = dynamic_pointer_cast(converted_data_); // Create the initial logic data segment if needed if (logic_data->segments().size() == 0) { @@ -339,10 +345,7 @@ void SignalBase::start_conversion() { stop_conversion(); - if ((channel_type_ == AnalogChannel) && - ((conversion_type_ == A2LConversionByTreshold) || - (conversion_type_ == A2LConversionBySchmittTrigger))) { - + if (conversion_is_a2l()) { shared_ptr analog_data = dynamic_pointer_cast(data_); if (analog_data->analog_segments().size() > 0) { diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index 322bdf48..468a2032 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -171,6 +171,8 @@ public: virtual void restore_settings(QSettings &settings); private: + bool conversion_is_a2l() const; + uint8_t convert_a2l_threshold(float threshold, float value); uint8_t convert_a2l_schmitt_trigger(float lo_thr, float hi_thr, float value, uint8_t &state);