]>
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 SA |
26 | #include <thread> |
27 | ||
bf0edd2b SA |
28 | #include <QColor> |
29 | #include <QObject> | |
6de38b17 | 30 | #include <QSettings> |
bf0edd2b SA |
31 | #include <QString> |
32 | ||
33 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
34 | ||
27a3f09b SA |
35 | using std::atomic; |
36 | using std::condition_variable; | |
37 | using std::mutex; | |
6f925ba9 | 38 | using std::shared_ptr; |
bf0edd2b SA |
39 | |
40 | namespace sigrok { | |
41 | class Channel; | |
bf0edd2b SA |
42 | } |
43 | ||
44 | namespace pv { | |
45 | namespace data { | |
46 | ||
cbd2a2de | 47 | class Analog; |
bb7dd726 | 48 | class DecoderStack; |
cbd2a2de SA |
49 | class Logic; |
50 | class SignalData; | |
51 | ||
bf0edd2b SA |
52 | class SignalBase : public QObject |
53 | { | |
54 | Q_OBJECT | |
55 | ||
472a80c5 SA |
56 | public: |
57 | enum ChannelType { | |
58 | AnalogChannel = 1, | |
59 | LogicChannel, | |
60 | DecodeChannel, | |
61 | A2LChannel, // Analog converted to logic, joint representation | |
62 | MathChannel | |
63 | }; | |
64 | ||
12ea3616 SA |
65 | enum ConversionType { |
66 | NoConversion = 0, | |
67 | A2LConversionByTreshold = 1, | |
68 | A2LConversionBySchmittTrigger = 2 | |
69 | }; | |
70 | ||
bf0edd2b SA |
71 | private: |
72 | static const int ColourBGAlpha; | |
bcaf0334 | 73 | static const uint64_t ConversionBlockSize; |
bf0edd2b SA |
74 | |
75 | public: | |
472a80c5 | 76 | SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type); |
12ea3616 | 77 | virtual ~SignalBase(); |
bf0edd2b SA |
78 | |
79 | public: | |
80 | /** | |
81 | * Returns the underlying SR channel. | |
82 | */ | |
6f925ba9 | 83 | shared_ptr<sigrok::Channel> channel() const; |
bf0edd2b SA |
84 | |
85 | /** | |
86 | * Returns enabled status of this channel. | |
87 | */ | |
88 | bool enabled() const; | |
89 | ||
90 | /** | |
91 | * Sets the enabled status of this channel. | |
92 | * @param value Boolean value to set. | |
93 | */ | |
94 | void set_enabled(bool value); | |
95 | ||
96 | /** | |
97 | * Gets the type of this channel. | |
98 | */ | |
472a80c5 | 99 | ChannelType type() const; |
bf0edd2b SA |
100 | |
101 | /** | |
27a3f09b SA |
102 | * Gets the index number of this channel, i.e. a unique ID assigned by |
103 | * the device driver. | |
bf0edd2b SA |
104 | */ |
105 | unsigned int index() const; | |
106 | ||
27a3f09b SA |
107 | /** |
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. | |
112 | */ | |
113 | unsigned int logic_bit_index() const; | |
114 | ||
bf0edd2b SA |
115 | /** |
116 | * Gets the name of this signal. | |
117 | */ | |
118 | QString name() const; | |
119 | ||
050b5a6c SA |
120 | /** |
121 | * Gets the internal name of this signal, i.e. how the device calls it. | |
122 | */ | |
123 | QString internal_name() const; | |
124 | ||
bf0edd2b SA |
125 | /** |
126 | * Sets the name of the signal. | |
127 | */ | |
128 | virtual void set_name(QString name); | |
129 | ||
130 | /** | |
131 | * Get the colour of the signal. | |
132 | */ | |
133 | QColor colour() const; | |
134 | ||
135 | /** | |
136 | * Set the colour of the signal. | |
137 | */ | |
138 | void set_colour(QColor colour); | |
139 | ||
140 | /** | |
141 | * Get the background colour of the signal. | |
142 | */ | |
143 | QColor bgcolour() const; | |
144 | ||
cbd2a2de SA |
145 | /** |
146 | * Sets the internal data object. | |
147 | */ | |
6f925ba9 | 148 | void set_data(shared_ptr<pv::data::SignalData> data); |
cbd2a2de SA |
149 | |
150 | /** | |
151 | * Get the internal data as analog data object in case of analog type. | |
152 | */ | |
6f925ba9 | 153 | shared_ptr<pv::data::Analog> analog_data() const; |
cbd2a2de SA |
154 | |
155 | /** | |
156 | * Get the internal data as logic data object in case of logic type. | |
157 | */ | |
6f925ba9 | 158 | shared_ptr<pv::data::Logic> logic_data() const; |
cbd2a2de | 159 | |
12ea3616 SA |
160 | /** |
161 | * Changes the kind of conversion performed on this channel. | |
162 | */ | |
163 | void set_conversion_type(ConversionType t); | |
164 | ||
bb7dd726 | 165 | #ifdef ENABLE_DECODE |
47747218 | 166 | bool is_decode_signal() const; |
bb7dd726 | 167 | #endif |
cbd2a2de | 168 | |
47747218 | 169 | virtual void save_settings(QSettings &settings) const; |
6de38b17 | 170 | |
47747218 | 171 | virtual void restore_settings(QSettings &settings); |
6de38b17 | 172 | |
12ea3616 SA |
173 | private: |
174 | uint8_t convert_a2l_threshold(float threshold, float value); | |
5d9fe823 SA |
175 | uint8_t convert_a2l_schmitt_trigger(float lo_thr, float hi_thr, |
176 | float value, uint8_t &state); | |
12ea3616 | 177 | |
27a3f09b SA |
178 | void conversion_thread_proc(QObject* segment); |
179 | ||
180 | void start_conversion(); | |
181 | void stop_conversion(); | |
12ea3616 | 182 | |
bf0edd2b SA |
183 | Q_SIGNALS: |
184 | void enabled_changed(const bool &value); | |
185 | ||
186 | void name_changed(const QString &name); | |
187 | ||
188 | void colour_changed(const QColor &colour); | |
189 | ||
12ea3616 SA |
190 | void conversion_type_changed(const ConversionType t); |
191 | ||
eae3bbbb SA |
192 | void samples_cleared(); |
193 | ||
194 | void samples_added(QObject* segment, uint64_t start_sample, | |
195 | uint64_t end_sample); | |
196 | ||
12ea3616 SA |
197 | private Q_SLOTS: |
198 | void on_samples_cleared(); | |
199 | ||
200 | void on_samples_added(QObject* segment, uint64_t start_sample, | |
201 | uint64_t end_sample); | |
202 | ||
203 | void on_capture_state_changed(int state); | |
204 | ||
ad908057 | 205 | protected: |
6f925ba9 | 206 | shared_ptr<sigrok::Channel> channel_; |
472a80c5 | 207 | ChannelType channel_type_; |
6f925ba9 | 208 | shared_ptr<pv::data::SignalData> data_; |
12ea3616 SA |
209 | shared_ptr<pv::data::SignalData> converted_data_; |
210 | int conversion_type_; | |
cbd2a2de | 211 | |
12ea3616 | 212 | std::thread conversion_thread_; |
27a3f09b SA |
213 | atomic<bool> conversion_interrupt_; |
214 | mutex conversion_input_mutex_; | |
215 | condition_variable conversion_input_cond_; | |
12ea3616 | 216 | |
050b5a6c | 217 | QString internal_name_, name_; |
bf0edd2b SA |
218 | QColor colour_, bgcolour_; |
219 | }; | |
220 | ||
221 | } // namespace data | |
222 | } // namespace pv | |
223 | ||
224 | #endif // PULSEVIEW_PV_DATA_SIGNALBASE_HPP |