]> sigrok.org Git - pulseview.git/commitdiff
SignalBase: Don't use static state
authorSoeren Apel <redacted>
Thu, 23 Mar 2017 20:52:51 +0000 (21:52 +0100)
committerSoeren Apel <redacted>
Thu, 23 Mar 2017 20:52:51 +0000 (21:52 +0100)
It's used across all SessionBase instances, d'oh.
Let's not do this.

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

index ff66100718d38cdb7d8e30f8e5814f9d0cb0e089..9894fdb4b1473eea638ef29da7e4c47145f45ebb 100644 (file)
@@ -240,10 +240,9 @@ uint8_t SignalBase::convert_a2l_threshold(float threshold, float value)
        return (value >= threshold) ? 1 : 0;
 }
 
-uint8_t SignalBase::convert_a2l_schmitt_trigger(float lo_thr, float hi_thr, float value)
+uint8_t SignalBase::convert_a2l_schmitt_trigger(float lo_thr, float hi_thr,
+       float value, uint8_t &state)
 {
-       static uint8_t state = 0;
-
        if (value < lo_thr)
                state = 0;
        else if (value > hi_thr)
@@ -325,12 +324,13 @@ void SignalBase::conversion_thread_proc(QObject* segment, uint64_t start_sample,
                        const float amplitude = max_v - min_v;
                        const float lo_thr = min_v + (amplitude * 0.1);  // 10% above min
                        const float hi_thr = max_v - (amplitude * 0.1);  // 10% below max
+                       uint8_t state = 0;  // TODO Use value of logic sample n-1 instead of 0
 
                        // Convert as many sample blocks as we can
                        while ((end_sample - i) > block_size) {
                                const float* asamples = asegment->get_samples(i, i + block_size);
                                for (uint32_t j = 0; j < block_size; j++)
-                                       lsamples.push_back(convert_a2l_schmitt_trigger(lo_thr, hi_thr, asamples[j]));
+                                       lsamples.push_back(convert_a2l_schmitt_trigger(lo_thr, hi_thr, asamples[j], state));
                                lsegment->append_payload(lsamples.data(), lsamples.size());
                                i += block_size;
                                lsamples.clear();
@@ -340,7 +340,7 @@ void SignalBase::conversion_thread_proc(QObject* segment, uint64_t start_sample,
                        // Convert remaining samples
                        const float* asamples = asegment->get_samples(i, end_sample);
                        for (uint32_t j = 0; j < (end_sample - i); j++)
-                               lsamples.push_back(convert_a2l_schmitt_trigger(lo_thr, hi_thr, asamples[j]));
+                               lsamples.push_back(convert_a2l_schmitt_trigger(lo_thr, hi_thr, asamples[j], state));
                        lsegment->append_payload(lsamples.data(), lsamples.size());
                        delete[] asamples;
                }
index b29c6b56558d3dffb74cd22429d20a6b80efb7a9..381716480371f6c5494a618e53aca196c7160787 100644 (file)
@@ -161,7 +161,8 @@ public:
 
 private:
        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 convert_a2l_schmitt_trigger(float lo_thr, float hi_thr,
+               float value, uint8_t &state);
 
        void conversion_thread_proc(QObject* segment, uint64_t start_sample,
                uint64_t end_sample);