2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #ifndef PULSEVIEW_PV_DATA_SIGNALBASE_HPP
22 #define PULSEVIEW_PV_DATA_SIGNALBASE_HPP
25 #include <condition_variable>
33 #include <libsigrokcxx/libsigrokcxx.hpp>
36 using std::condition_variable;
38 using std::shared_ptr;
52 class SignalBase : public QObject
61 A2LChannel, // Analog converted to logic, joint representation
67 A2LConversionByTreshold = 1,
68 A2LConversionBySchmittTrigger = 2
72 static const int ColourBGAlpha;
73 static const uint64_t ConversionBlockSize;
76 SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type);
77 virtual ~SignalBase();
81 * Returns the underlying SR channel.
83 shared_ptr<sigrok::Channel> channel() const;
86 * Returns enabled status of this channel.
91 * Sets the enabled status of this channel.
92 * @param value Boolean value to set.
94 void set_enabled(bool value);
97 * Gets the type of this channel.
99 ChannelType type() const;
102 * Gets the index number of this channel, i.e. a unique ID assigned by
105 unsigned int index() const;
108 * Returns which bit of a given sample for this signal represents the
109 * signal itself. This is relevant for compound signals like logic,
110 * rather meaningless for everything else but provided in case there
111 * is a conversion active that provides a digital signal using bit #0.
113 unsigned int logic_bit_index() const;
116 * Gets the name of this signal.
118 QString name() const;
121 * Gets the internal name of this signal, i.e. how the device calls it.
123 QString internal_name() const;
126 * Sets the name of the signal.
128 virtual void set_name(QString name);
131 * Get the colour of the signal.
133 QColor colour() const;
136 * Set the colour of the signal.
138 void set_colour(QColor colour);
141 * Get the background colour of the signal.
143 QColor bgcolour() const;
146 * Sets the internal data object.
148 void set_data(shared_ptr<pv::data::SignalData> data);
151 * Get the internal data as analog data object in case of analog type.
153 shared_ptr<pv::data::Analog> analog_data() const;
156 * Get the internal data as logic data object in case of logic type.
158 shared_ptr<pv::data::Logic> logic_data() const;
161 * Changes the kind of conversion performed on this channel.
163 void set_conversion_type(ConversionType t);
166 bool is_decode_signal() const;
169 virtual void save_settings(QSettings &settings) const;
171 virtual void restore_settings(QSettings &settings);
174 bool conversion_is_a2l() const;
176 uint8_t convert_a2l_threshold(float threshold, float value);
177 uint8_t convert_a2l_schmitt_trigger(float lo_thr, float hi_thr,
178 float value, uint8_t &state);
180 void conversion_thread_proc(QObject* segment);
182 void start_conversion();
183 void stop_conversion();
186 void enabled_changed(const bool &value);
188 void name_changed(const QString &name);
190 void colour_changed(const QColor &colour);
192 void conversion_type_changed(const ConversionType t);
194 void samples_cleared();
196 void samples_added(QObject* segment, uint64_t start_sample,
197 uint64_t end_sample);
200 void on_samples_cleared();
202 void on_samples_added(QObject* segment, uint64_t start_sample,
203 uint64_t end_sample);
205 void on_capture_state_changed(int state);
208 shared_ptr<sigrok::Channel> channel_;
209 ChannelType channel_type_;
210 shared_ptr<pv::data::SignalData> data_;
211 shared_ptr<pv::data::SignalData> converted_data_;
212 int conversion_type_;
214 std::thread conversion_thread_;
215 atomic<bool> conversion_interrupt_;
216 mutex conversion_input_mutex_;
217 condition_variable conversion_input_cond_;
219 QString internal_name_, name_;
220 QColor colour_, bgcolour_;
226 #endif // PULSEVIEW_PV_DATA_SIGNALBASE_HPP