]> sigrok.org Git - pulseview.git/blobdiff - pv/data/signalbase.hpp
SignalBase: Don't use static state
[pulseview.git] / pv / data / signalbase.hpp
index 6667dd76847cab8ce3235c99d6ec19deb73544fb..381716480371f6c5494a618e53aca196c7160787 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef PULSEVIEW_PV_DATA_SIGNALBASE_HPP
 #define PULSEVIEW_PV_DATA_SIGNALBASE_HPP
 
+#include <thread>
+
 #include <QColor>
 #include <QObject>
 #include <QSettings>
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
+using std::shared_ptr;
 
 namespace sigrok {
 class Channel;
-class ChannelType;
 }
 
 namespace pv {
@@ -46,18 +48,33 @@ class SignalBase : public QObject
 {
        Q_OBJECT
 
+public:
+       enum ChannelType {
+               AnalogChannel = 1,
+               LogicChannel,
+               DecodeChannel,
+               A2LChannel,  // Analog converted to logic, joint representation
+               MathChannel
+       };
+
+       enum ConversionType {
+               NoConversion = 0,
+               A2LConversionByTreshold = 1,
+               A2LConversionBySchmittTrigger = 2
+       };
+
 private:
        static const int ColourBGAlpha;
 
 public:
-       SignalBase(std::shared_ptr<sigrok::Channel> channel);
-       virtual ~SignalBase() {}
+       SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type);
+       virtual ~SignalBase();
 
 public:
        /**
         * Returns the underlying SR channel.
         */
-       std::shared_ptr<sigrok::Channel> channel() const;
+       shared_ptr<sigrok::Channel> channel() const;
 
        /**
         * Returns enabled status of this channel.
@@ -73,7 +90,7 @@ public:
        /**
         * Gets the type of this channel.
         */
-       const sigrok::ChannelType *type() const;
+       ChannelType type() const;
 
        /**
         * Gets the index number of this channel.
@@ -113,31 +130,43 @@ public:
        /**
         * Sets the internal data object.
         */
-       void set_data(std::shared_ptr<pv::data::SignalData> data);
+       void set_data(shared_ptr<pv::data::SignalData> data);
 
        /**
         * Get the internal data as analog data object in case of analog type.
         */
-       std::shared_ptr<pv::data::Analog> analog_data() const;
+       shared_ptr<pv::data::Analog> analog_data() const;
 
        /**
         * Get the internal data as logic data object in case of logic type.
         */
-       std::shared_ptr<pv::data::Logic> logic_data() const;
+       shared_ptr<pv::data::Logic> logic_data() const;
+
+       /**
+        * Changes the kind of conversion performed on this channel.
+        */
+       void set_conversion_type(ConversionType t);
 
 #ifdef ENABLE_DECODE
        bool is_decode_signal() const;
 
-       std::shared_ptr<pv::data::DecoderStack> decoder_stack() const;
+       shared_ptr<pv::data::DecoderStack> decoder_stack() const;
 
-       void set_decoder_stack(std::shared_ptr<pv::data::DecoderStack>
-               decoder_stack);
+       void set_decoder_stack(shared_ptr<pv::data::DecoderStack> decoder_stack);
 #endif
 
        void save_settings(QSettings &settings) const;
 
        void restore_settings(QSettings &settings);
 
+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 &state);
+
+       void conversion_thread_proc(QObject* segment, uint64_t start_sample,
+               uint64_t end_sample);
+
 Q_SIGNALS:
        void enabled_changed(const bool &value);
 
@@ -145,14 +174,29 @@ Q_SIGNALS:
 
        void colour_changed(const QColor &colour);
 
+       void conversion_type_changed(const ConversionType t);
+
+private Q_SLOTS:
+       void on_samples_cleared();
+
+       void on_samples_added(QObject* segment, uint64_t start_sample,
+               uint64_t end_sample);
+
+       void on_capture_state_changed(int state);
+
 private:
-       std::shared_ptr<sigrok::Channel> channel_;
-       std::shared_ptr<pv::data::SignalData> data_;
+       shared_ptr<sigrok::Channel> channel_;
+       ChannelType channel_type_;
+       shared_ptr<pv::data::SignalData> data_;
+       shared_ptr<pv::data::SignalData> converted_data_;
+       int conversion_type_;
 
 #ifdef ENABLE_DECODE
-       std::shared_ptr<pv::data::DecoderStack> decoder_stack_;
+       shared_ptr<pv::data::DecoderStack> decoder_stack_;
 #endif
 
+       std::thread conversion_thread_;
+
        QString internal_name_, name_;
        QColor colour_, bgcolour_;
 };