]> sigrok.org Git - pulseview.git/commitdiff
DecodeSignal: Provide conversion data container sooner
authorSoeren Apel <redacted>
Tue, 23 May 2017 16:41:20 +0000 (18:41 +0200)
committerUwe Hermann <redacted>
Wed, 5 Jul 2017 22:37:08 +0000 (00:37 +0200)
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.

pv/data/signalbase.cpp
pv/data/signalbase.hpp

index 09e4400e20a9d1584ca88dc6caa7d8974ddd3bb4..173610d945e7b66ff5ce3e1b45e05b1c821a3b2e 100644 (file)
@@ -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<Logic>(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<AnalogSegment*>(segment);
 
-                       // Create the logic data container if needed
-                       shared_ptr<Logic> logic_data;
-                       if (!converted_data_) {
-                               logic_data = make_shared<Logic>(1);  // Contains only one channel
-                               converted_data_ = logic_data;
-                       } else
-                                logic_data = dynamic_pointer_cast<Logic>(converted_data_);
+                       const shared_ptr<Logic> logic_data = dynamic_pointer_cast<Logic>(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> analog_data = dynamic_pointer_cast<Analog>(data_);
 
                if (analog_data->analog_segments().size() > 0) {
index 322bdf48e8c3a026d2156aa6ab75e05b024e9935..468a2032812cba3b7611f1d6cf5dcfa718fe0bc5 100644 (file)
@@ -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);