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