]>
Commit | Line | Data |
---|---|---|
f4e57597 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/>. |
f4e57597 SA |
19 | */ |
20 | ||
21 | #ifdef ENABLE_DECODE | |
22 | #include <libsigrokdecode/libsigrokdecode.h> | |
23 | #endif | |
24 | ||
25 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
26 | ||
27 | #include "pv/session.hpp" | |
28 | #include "pv/util.hpp" | |
8c339741 | 29 | #include "pv/data/segment.hpp" |
f4e57597 SA |
30 | |
31 | using std::shared_ptr; | |
32 | ||
33 | namespace pv { | |
34 | namespace views { | |
35 | ||
baf867ed | 36 | const char* ViewTypeNames[ViewTypeCount] = { |
03408f5f | 37 | "Trace View", |
baf867ed | 38 | #ifdef ENABLE_DECODE |
121307b3 | 39 | "Binary Decoder Output View" |
baf867ed SA |
40 | #endif |
41 | }; | |
42 | ||
5ed05b69 SA |
43 | const int ViewBase::MaxViewAutoUpdateRate = 25; // No more than 25 Hz |
44 | ||
a24412db | 45 | ViewBase::ViewBase(Session &session, bool is_main_view, QMainWindow *parent) : |
5a206446 | 46 | // Note: Place defaults in ViewBase::reset_view_state(), not here |
79926d3f | 47 | QWidget(parent), |
143d322d | 48 | session_(session), |
5a206446 | 49 | is_main_view_(is_main_view) |
f4e57597 SA |
50 | { |
51 | (void)parent; | |
52 | ||
53 | connect(&session_, SIGNAL(signals_changed()), | |
54 | this, SLOT(signals_changed())); | |
55 | connect(&session_, SIGNAL(capture_state_changed(int)), | |
56 | this, SLOT(capture_state_updated(int))); | |
4e86ec70 SA |
57 | connect(&session_, SIGNAL(new_segment(int)), |
58 | this, SLOT(on_new_segment(int))); | |
5ed05b69 SA |
59 | |
60 | connect(&delayed_view_updater_, SIGNAL(timeout()), | |
61 | this, SLOT(perform_delayed_view_update())); | |
62 | delayed_view_updater_.setSingleShot(true); | |
63 | delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate); | |
f4e57597 SA |
64 | } |
65 | ||
0a952555 SA |
66 | bool ViewBase::is_main_view() const |
67 | { | |
68 | return is_main_view_; | |
69 | } | |
70 | ||
5a206446 SA |
71 | void ViewBase::reset_view_state() |
72 | { | |
5a206446 SA |
73 | current_segment_ = 0; |
74 | } | |
75 | ||
f4e57597 SA |
76 | Session& ViewBase::session() |
77 | { | |
78 | return session_; | |
79 | } | |
80 | ||
81 | const Session& ViewBase::session() const | |
82 | { | |
83 | return session_; | |
84 | } | |
85 | ||
86 | void ViewBase::clear_signals() | |
87 | { | |
03408f5f | 88 | clear_signalbases(); |
f4e57597 SA |
89 | } |
90 | ||
533b67b7 | 91 | vector< shared_ptr<data::SignalBase> > ViewBase::signalbases() const |
5ed05b69 SA |
92 | { |
93 | return signalbases_; | |
94 | } | |
95 | ||
96 | void ViewBase::clear_signalbases() | |
97 | { | |
f4ab4b5c | 98 | for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) { |
5ed05b69 SA |
99 | disconnect(signalbase.get(), SIGNAL(samples_cleared()), |
100 | this, SLOT(on_data_updated())); | |
7f894d95 SA |
101 | disconnect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)), |
102 | this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t))); | |
5ed05b69 SA |
103 | } |
104 | ||
105 | signalbases_.clear(); | |
106 | } | |
107 | ||
108 | void ViewBase::add_signalbase(const shared_ptr<data::SignalBase> signalbase) | |
109 | { | |
533b67b7 | 110 | signalbases_.push_back(signalbase); |
5ed05b69 SA |
111 | |
112 | connect(signalbase.get(), SIGNAL(samples_cleared()), | |
113 | this, SLOT(on_data_updated())); | |
7f894d95 SA |
114 | connect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)), |
115 | this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t))); | |
5ed05b69 SA |
116 | } |
117 | ||
f4e57597 SA |
118 | #ifdef ENABLE_DECODE |
119 | void ViewBase::clear_decode_signals() | |
120 | { | |
e77de61f | 121 | decode_signals_.clear(); |
f4e57597 SA |
122 | } |
123 | ||
ad908057 | 124 | void ViewBase::add_decode_signal(shared_ptr<data::DecodeSignal> signal) |
f4e57597 | 125 | { |
533b67b7 | 126 | decode_signals_.push_back(signal); |
f4e57597 SA |
127 | } |
128 | ||
ad908057 | 129 | void ViewBase::remove_decode_signal(shared_ptr<data::DecodeSignal> signal) |
f4e57597 | 130 | { |
533b67b7 SA |
131 | decode_signals_.erase(std::remove_if( |
132 | decode_signals_.begin(), decode_signals_.end(), | |
133 | [&](shared_ptr<data::DecodeSignal> s) { return s == signal; }), | |
134 | decode_signals_.end()); | |
f4e57597 SA |
135 | } |
136 | #endif | |
137 | ||
138 | void ViewBase::save_settings(QSettings &settings) const | |
139 | { | |
140 | (void)settings; | |
141 | } | |
142 | ||
143 | void ViewBase::restore_settings(QSettings &settings) | |
144 | { | |
145 | (void)settings; | |
146 | } | |
147 | ||
7ea2a4ff | 148 | void ViewBase::trigger_event(int segment_id, util::Timestamp location) |
f4e57597 | 149 | { |
7ea2a4ff | 150 | (void)segment_id; |
f4e57597 SA |
151 | (void)location; |
152 | } | |
153 | ||
154 | void ViewBase::signals_changed() | |
155 | { | |
156 | } | |
157 | ||
4e86ec70 SA |
158 | void ViewBase::on_new_segment(int new_segment_id) |
159 | { | |
160 | (void)new_segment_id; | |
161 | } | |
162 | ||
558ad6ce SA |
163 | void ViewBase::on_segment_completed(int new_segment_id) |
164 | { | |
165 | (void)new_segment_id; | |
166 | } | |
167 | ||
f4e57597 SA |
168 | void ViewBase::capture_state_updated(int state) |
169 | { | |
170 | (void)state; | |
171 | } | |
172 | ||
5ed05b69 SA |
173 | void ViewBase::perform_delayed_view_update() |
174 | { | |
175 | } | |
176 | ||
7f894d95 | 177 | void ViewBase::on_samples_added(uint64_t segment_id, uint64_t start_sample, |
8c339741 SA |
178 | uint64_t end_sample) |
179 | { | |
180 | (void)start_sample; | |
181 | (void)end_sample; | |
182 | ||
7f894d95 | 183 | if (segment_id != current_segment_) |
8c339741 SA |
184 | return; |
185 | ||
186 | if (!delayed_view_updater_.isActive()) | |
187 | delayed_view_updater_.start(); | |
188 | } | |
189 | ||
5ed05b69 | 190 | void ViewBase::on_data_updated() |
f4e57597 | 191 | { |
5ed05b69 SA |
192 | if (!delayed_view_updater_.isActive()) |
193 | delayed_view_updater_.start(); | |
f4e57597 SA |
194 | } |
195 | ||
870ea3db | 196 | } // namespace views |
f4e57597 | 197 | } // namespace pv |