]>
Commit | Line | Data |
---|---|---|
bf0edd2b SA |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net> | |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
efdec55a | 18 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
bf0edd2b SA |
19 | */ |
20 | ||
21 | #ifndef PULSEVIEW_PV_DATA_SIGNALBASE_HPP | |
22 | #define PULSEVIEW_PV_DATA_SIGNALBASE_HPP | |
23 | ||
27a3f09b SA |
24 | #include <atomic> |
25 | #include <condition_variable> | |
12ea3616 | 26 | #include <thread> |
52c900ac | 27 | #include <vector> |
12ea3616 | 28 | |
bf0edd2b SA |
29 | #include <QColor> |
30 | #include <QObject> | |
6de38b17 | 31 | #include <QSettings> |
bf0edd2b | 32 | #include <QString> |
932bc246 | 33 | #include <QTimer> |
52c900ac | 34 | #include <QVariant> |
bf0edd2b SA |
35 | |
36 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
37 | ||
27a3f09b SA |
38 | using std::atomic; |
39 | using std::condition_variable; | |
52c900ac | 40 | using std::map; |
27a3f09b | 41 | using std::mutex; |
52c900ac | 42 | using std::pair; |
6f925ba9 | 43 | using std::shared_ptr; |
52c900ac | 44 | using std::vector; |
bf0edd2b SA |
45 | |
46 | namespace sigrok { | |
47 | class Channel; | |
bf0edd2b SA |
48 | } |
49 | ||
50 | namespace pv { | |
51 | namespace data { | |
52 | ||
cbd2a2de | 53 | class Analog; |
bb7dd726 | 54 | class DecoderStack; |
cbd2a2de SA |
55 | class Logic; |
56 | class SignalData; | |
57 | ||
bf0edd2b SA |
58 | class SignalBase : public QObject |
59 | { | |
60 | Q_OBJECT | |
61 | ||
472a80c5 SA |
62 | public: |
63 | enum ChannelType { | |
64845ac2 SA |
64 | AnalogChannel = 1, ///< Analog data |
65 | LogicChannel, ///< Logic data | |
66 | DecodeChannel, ///< Protocol Decoder channel using libsigrokdecode | |
64845ac2 | 67 | MathChannel ///< Virtual channel generated by math operations |
472a80c5 SA |
68 | }; |
69 | ||
12ea3616 SA |
70 | enum ConversionType { |
71 | NoConversion = 0, | |
b9cdbe03 | 72 | A2LConversionByThreshold = 1, |
12ea3616 SA |
73 | A2LConversionBySchmittTrigger = 2 |
74 | }; | |
75 | ||
f0f9c856 SA |
76 | /** |
77 | * Conversion presets range from -1 to n, where 1..n are dependent on | |
78 | * the conversion these presets apply to. -1 and 0 have fixed meanings, | |
79 | * however. | |
80 | */ | |
81 | enum ConversionPreset { | |
82 | NoPreset = -1, ///< Conversion uses custom values | |
83 | DynamicPreset = 0 ///< Conversion uses calculated values | |
84 | }; | |
85 | ||
bf0edd2b SA |
86 | private: |
87 | static const int ColourBGAlpha; | |
bcaf0334 | 88 | static const uint64_t ConversionBlockSize; |
932bc246 | 89 | static const uint32_t ConversionDelay; |
bf0edd2b SA |
90 | |
91 | public: | |
472a80c5 | 92 | SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type); |
12ea3616 | 93 | virtual ~SignalBase(); |
bf0edd2b SA |
94 | |
95 | public: | |
96 | /** | |
97 | * Returns the underlying SR channel. | |
98 | */ | |
6f925ba9 | 99 | shared_ptr<sigrok::Channel> channel() const; |
bf0edd2b SA |
100 | |
101 | /** | |
102 | * Returns enabled status of this channel. | |
103 | */ | |
104 | bool enabled() const; | |
105 | ||
106 | /** | |
107 | * Sets the enabled status of this channel. | |
108 | * @param value Boolean value to set. | |
109 | */ | |
110 | void set_enabled(bool value); | |
111 | ||
112 | /** | |
113 | * Gets the type of this channel. | |
114 | */ | |
472a80c5 | 115 | ChannelType type() const; |
bf0edd2b SA |
116 | |
117 | /** | |
27a3f09b SA |
118 | * Gets the index number of this channel, i.e. a unique ID assigned by |
119 | * the device driver. | |
bf0edd2b SA |
120 | */ |
121 | unsigned int index() const; | |
122 | ||
27a3f09b SA |
123 | /** |
124 | * Returns which bit of a given sample for this signal represents the | |
125 | * signal itself. This is relevant for compound signals like logic, | |
126 | * rather meaningless for everything else but provided in case there | |
127 | * is a conversion active that provides a digital signal using bit #0. | |
128 | */ | |
129 | unsigned int logic_bit_index() const; | |
130 | ||
bf0edd2b SA |
131 | /** |
132 | * Gets the name of this signal. | |
133 | */ | |
134 | QString name() const; | |
135 | ||
050b5a6c SA |
136 | /** |
137 | * Gets the internal name of this signal, i.e. how the device calls it. | |
138 | */ | |
139 | QString internal_name() const; | |
140 | ||
bf0edd2b SA |
141 | /** |
142 | * Sets the name of the signal. | |
143 | */ | |
144 | virtual void set_name(QString name); | |
145 | ||
146 | /** | |
147 | * Get the colour of the signal. | |
148 | */ | |
149 | QColor colour() const; | |
150 | ||
151 | /** | |
152 | * Set the colour of the signal. | |
153 | */ | |
154 | void set_colour(QColor colour); | |
155 | ||
156 | /** | |
157 | * Get the background colour of the signal. | |
158 | */ | |
159 | QColor bgcolour() const; | |
160 | ||
cbd2a2de SA |
161 | /** |
162 | * Sets the internal data object. | |
163 | */ | |
6f925ba9 | 164 | void set_data(shared_ptr<pv::data::SignalData> data); |
cbd2a2de SA |
165 | |
166 | /** | |
167 | * Get the internal data as analog data object in case of analog type. | |
168 | */ | |
6f925ba9 | 169 | shared_ptr<pv::data::Analog> analog_data() const; |
cbd2a2de SA |
170 | |
171 | /** | |
172 | * Get the internal data as logic data object in case of logic type. | |
173 | */ | |
6f925ba9 | 174 | shared_ptr<pv::data::Logic> logic_data() const; |
cbd2a2de | 175 | |
06b6ce26 SA |
176 | /** |
177 | * Queries the kind of conversion performed on this channel. | |
178 | */ | |
179 | ConversionType get_conversion_type() const; | |
180 | ||
12ea3616 SA |
181 | /** |
182 | * Changes the kind of conversion performed on this channel. | |
52c900ac SA |
183 | * |
184 | * Restarts the conversion. | |
12ea3616 SA |
185 | */ |
186 | void set_conversion_type(ConversionType t); | |
187 | ||
52c900ac SA |
188 | /** |
189 | * Returns all currently known conversion options | |
190 | */ | |
191 | map<QString, QVariant> get_conversion_options() const; | |
192 | ||
193 | /** | |
194 | * Sets the value of a particular conversion option | |
195 | * Note: it is not checked whether the option is valid for the | |
196 | * currently conversion. If it's not, it will be silently ignored. | |
197 | * | |
198 | * Does not restart the conversion. | |
199 | * | |
200 | * @return true if the value is different from before, false otherwise | |
201 | */ | |
202 | bool set_conversion_option(QString key, QVariant value); | |
203 | ||
204 | /** | |
205 | * Returns the threshold(s) used for conversions, if applicable. | |
206 | * The resulting thresholds are given for the chosen conversion, so you | |
207 | * can query thresholds also for conversions which aren't currently active. | |
208 | * | |
209 | * If you want the thresholds for the currently active conversion, | |
210 | * call it either with NoConversion or no parameter. | |
211 | * | |
212 | * @param t the type of conversion to obtain the thresholds for, leave | |
213 | * empty or use NoConversion if you want to query the currently | |
214 | * used conversion | |
215 | * | |
216 | * @param always_custom ignore the currently selected preset and always | |
217 | * return the custom values for this conversion, using 0 if those | |
218 | * aren't set | |
219 | * | |
220 | * @return a list of threshold(s) used by the chosen conversion | |
221 | */ | |
222 | vector<double> get_conversion_thresholds( | |
223 | const ConversionType t = NoConversion, const bool always_custom=false) const; | |
224 | ||
225 | /** | |
226 | * Provides all conversion presets available for the currently active | |
227 | * conversion. | |
228 | * | |
229 | * @return a list of description/ID pairs for each preset | |
230 | */ | |
231 | vector<pair<QString, int> > get_conversion_presets() const; | |
232 | ||
233 | /** | |
234 | * Determines the ID of the currently used conversion preset, which is only | |
235 | * valid for the currently available conversion presets. It is therefore | |
236 | * suggested to call @ref get_conversion_presets right before calling this. | |
237 | * | |
238 | * @return the ID of the currently used conversion preset. -1 if no preset | |
239 | * is used. In that case, a user setting is used instead. | |
240 | */ | |
f0f9c856 | 241 | ConversionPreset get_current_conversion_preset() const; |
52c900ac SA |
242 | |
243 | /** | |
244 | * Sets the conversion preset to be used. | |
245 | * | |
246 | * Does not restart the conversion. | |
247 | * | |
248 | * @param id the id of the preset to use | |
249 | */ | |
f0f9c856 | 250 | void set_conversion_preset(ConversionPreset id); |
52c900ac | 251 | |
bb7dd726 | 252 | #ifdef ENABLE_DECODE |
47747218 | 253 | bool is_decode_signal() const; |
bb7dd726 | 254 | #endif |
cbd2a2de | 255 | |
47747218 | 256 | virtual void save_settings(QSettings &settings) const; |
6de38b17 | 257 | |
47747218 | 258 | virtual void restore_settings(QSettings &settings); |
6de38b17 | 259 | |
932bc246 | 260 | void start_conversion(bool delayed_start=false); |
52c900ac | 261 | |
12ea3616 | 262 | private: |
ccccb914 SA |
263 | bool conversion_is_a2l() const; |
264 | ||
12ea3616 | 265 | uint8_t convert_a2l_threshold(float threshold, float value); |
5d9fe823 SA |
266 | uint8_t convert_a2l_schmitt_trigger(float lo_thr, float hi_thr, |
267 | float value, uint8_t &state); | |
12ea3616 | 268 | |
27a3f09b SA |
269 | void conversion_thread_proc(QObject* segment); |
270 | ||
27a3f09b | 271 | void stop_conversion(); |
12ea3616 | 272 | |
bf0edd2b SA |
273 | Q_SIGNALS: |
274 | void enabled_changed(const bool &value); | |
275 | ||
276 | void name_changed(const QString &name); | |
277 | ||
278 | void colour_changed(const QColor &colour); | |
279 | ||
12ea3616 SA |
280 | void conversion_type_changed(const ConversionType t); |
281 | ||
eae3bbbb SA |
282 | void samples_cleared(); |
283 | ||
284 | void samples_added(QObject* segment, uint64_t start_sample, | |
285 | uint64_t end_sample); | |
286 | ||
c6d9cf65 SA |
287 | void min_max_changed(float min, float max); |
288 | ||
12ea3616 SA |
289 | private Q_SLOTS: |
290 | void on_samples_cleared(); | |
291 | ||
292 | void on_samples_added(QObject* segment, uint64_t start_sample, | |
293 | uint64_t end_sample); | |
294 | ||
8e15445c SA |
295 | void on_min_max_changed(float min, float max); |
296 | ||
12ea3616 SA |
297 | void on_capture_state_changed(int state); |
298 | ||
932bc246 SA |
299 | void on_delayed_conversion_start(); |
300 | ||
ad908057 | 301 | protected: |
6f925ba9 | 302 | shared_ptr<sigrok::Channel> channel_; |
472a80c5 | 303 | ChannelType channel_type_; |
6f925ba9 | 304 | shared_ptr<pv::data::SignalData> data_; |
12ea3616 | 305 | shared_ptr<pv::data::SignalData> converted_data_; |
06b6ce26 | 306 | ConversionType conversion_type_; |
52c900ac SA |
307 | map<QString, QVariant> conversion_options_; |
308 | ||
309 | float min_value_, max_value_; | |
cbd2a2de | 310 | |
12ea3616 | 311 | std::thread conversion_thread_; |
27a3f09b SA |
312 | atomic<bool> conversion_interrupt_; |
313 | mutex conversion_input_mutex_; | |
314 | condition_variable conversion_input_cond_; | |
932bc246 | 315 | QTimer delayed_conversion_starter_; |
12ea3616 | 316 | |
050b5a6c | 317 | QString internal_name_, name_; |
bf0edd2b SA |
318 | QColor colour_, bgcolour_; |
319 | }; | |
320 | ||
321 | } // namespace data | |
322 | } // namespace pv | |
323 | ||
324 | #endif // PULSEVIEW_PV_DATA_SIGNALBASE_HPP |