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