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