]>
Commit | Line | Data |
---|---|---|
d4984fe7 | 1 | /* |
b3f22de0 | 2 | * This file is part of the PulseView project. |
d4984fe7 | 3 | * |
079d39ea | 4 | * Copyright (C) 2012-2015 Joel Holdsworth <joel@airwebreathe.org.uk> |
d4984fe7 JH |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
09f5d123 | 21 | #include <extdef.h> |
dde1a563 | 22 | |
079d39ea JH |
23 | #include <algorithm> |
24 | #include <cassert> | |
215f9499 | 25 | |
dde1a563 | 26 | #include <QAction> |
48888313 | 27 | #include <QDebug> |
40065ab6 | 28 | #include <QHelpEvent> |
87f0df9b | 29 | #include <QMenu> |
40065ab6 | 30 | #include <QToolTip> |
dde1a563 | 31 | |
7c657094 | 32 | #include "mainbar.hpp" |
d4984fe7 | 33 | |
2acdb232 | 34 | #include <pv/devicemanager.hpp> |
da30ecb7 | 35 | #include <pv/devices/hardwaredevice.hpp> |
4e7f5ba8 | 36 | #include <pv/mainwindow.hpp> |
2acdb232 JH |
37 | #include <pv/popups/deviceoptions.hpp> |
38 | #include <pv/popups/channels.hpp> | |
39 | #include <pv/util.hpp> | |
998b89fd | 40 | #include <pv/widgets/exportmenu.hpp> |
ed43ef2e | 41 | #include <pv/widgets/importmenu.hpp> |
cdb50f67 | 42 | |
fe3a1c21 | 43 | #include <libsigrokcxx/libsigrokcxx.hpp> |
e8d00928 | 44 | |
079d39ea JH |
45 | using std::back_inserter; |
46 | using std::copy; | |
47 | using std::list; | |
19adbc2c | 48 | using std::map; |
b50ef520 JH |
49 | using std::max; |
50 | using std::min; | |
f9abf97e | 51 | using std::shared_ptr; |
819f4c25 | 52 | using std::string; |
079d39ea | 53 | using std::vector; |
dd63af74 | 54 | |
e8d00928 ML |
55 | using sigrok::Capability; |
56 | using sigrok::ConfigKey; | |
e8d00928 | 57 | using sigrok::Error; |
ed43ef2e | 58 | using sigrok::InputFormat; |
e8d00928 | 59 | |
51e77110 | 60 | namespace pv { |
f4c92e1c | 61 | namespace toolbars { |
51e77110 | 62 | |
7c657094 JH |
63 | const uint64_t MainBar::MinSampleCount = 100ULL; |
64 | const uint64_t MainBar::MaxSampleCount = 1000000000000ULL; | |
65 | const uint64_t MainBar::DefaultSampleCount = 1000000; | |
09f5d123 | 66 | |
7c657094 | 67 | MainBar::MainBar(Session &session, MainWindow &main_window) : |
4e7f5ba8 | 68 | QToolBar("Sampling Bar", &main_window), |
8dbbc7f0 | 69 | session_(session), |
4e7f5ba8 | 70 | main_window_(main_window), |
079d39ea JH |
71 | device_selector_(this, session.device_manager(), |
72 | main_window.action_connect()), | |
8dbbc7f0 | 73 | configure_button_(this), |
4c60462b | 74 | configure_button_action_(nullptr), |
8dbbc7f0 | 75 | channels_button_(this), |
9dd88889 | 76 | channels_button_action_(nullptr), |
8dbbc7f0 JH |
77 | sample_count_(" samples", this), |
78 | sample_rate_("Hz", this), | |
79 | updating_sample_rate_(false), | |
80 | updating_sample_count_(false), | |
81 | sample_count_supported_(false), | |
82 | icon_red_(":/icons/status-red.svg"), | |
83 | icon_green_(":/icons/status-green.svg"), | |
84 | icon_grey_(":/icons/status-grey.svg"), | |
87f0df9b | 85 | run_stop_button_(this), |
9dd88889 | 86 | run_stop_button_action_(nullptr), |
87f0df9b | 87 | menu_button_(this) |
6fb67b27 | 88 | { |
7c657094 | 89 | setObjectName(QString::fromUtf8("MainBar")); |
0c7cdea2 | 90 | |
f2dbf150 JH |
91 | setMovable(false); |
92 | setFloatable(false); | |
758f6023 | 93 | setContextMenuPolicy(Qt::PreventContextMenu); |
f2dbf150 | 94 | |
ed43ef2e JH |
95 | // Open button |
96 | QToolButton *const open_button = new QToolButton(this); | |
97 | ||
98 | widgets::ImportMenu *import_menu = new widgets::ImportMenu(this, | |
99 | session.device_manager().context(), | |
100 | main_window.action_open()); | |
101 | connect(import_menu, | |
102 | SIGNAL(format_selected(std::shared_ptr<sigrok::InputFormat>)), | |
103 | &main_window_, | |
104 | SLOT(import_file(std::shared_ptr<sigrok::InputFormat>))); | |
105 | ||
106 | open_button->setMenu(import_menu); | |
107 | open_button->setDefaultAction(main_window.action_open()); | |
108 | open_button->setPopupMode(QToolButton::MenuButtonPopup); | |
109 | ||
998b89fd JH |
110 | // Save button |
111 | QToolButton *const save_button = new QToolButton(this); | |
112 | ||
686d9151 SA |
113 | vector<QAction *> open_actions; |
114 | open_actions.push_back(main_window.action_save_as()); | |
115 | ||
998b89fd JH |
116 | widgets::ExportMenu *export_menu = new widgets::ExportMenu(this, |
117 | session.device_manager().context(), | |
686d9151 | 118 | open_actions); |
998b89fd JH |
119 | connect(export_menu, |
120 | SIGNAL(format_selected(std::shared_ptr<sigrok::OutputFormat>)), | |
121 | &main_window_, | |
122 | SLOT(export_file(std::shared_ptr<sigrok::OutputFormat>))); | |
123 | ||
124 | save_button->setMenu(export_menu); | |
125 | save_button->setDefaultAction(main_window.action_save_as()); | |
126 | save_button->setPopupMode(QToolButton::MenuButtonPopup); | |
127 | ||
079d39ea JH |
128 | // Device selector menu |
129 | connect(&device_selector_, SIGNAL(device_selected()), | |
130 | this, SLOT(on_device_selected())); | |
131 | ||
168888e2 JH |
132 | // Setup the decoder button |
133 | #ifdef ENABLE_DECODE | |
134 | QToolButton *add_decoder_button = new QToolButton(this); | |
135 | add_decoder_button->setIcon(QIcon::fromTheme("add-decoder", | |
136 | QIcon(":/icons/add-decoder.svg"))); | |
137 | add_decoder_button->setPopupMode(QToolButton::InstantPopup); | |
138 | add_decoder_button->setMenu(main_window_.menu_decoder_add()); | |
139 | #endif | |
140 | ||
c7b03d9d | 141 | // Setup the burger menu |
87f0df9b JH |
142 | QMenu *const menu = new QMenu(this); |
143 | ||
c7b03d9d SA |
144 | QMenu *const menu_view = new QMenu; |
145 | menu_view->setTitle(tr("&View")); | |
146 | menu_view->addAction(main_window.action_view_sticky_scrolling()); | |
147 | ||
87f0df9b JH |
148 | QMenu *const menu_help = new QMenu; |
149 | menu_help->setTitle(tr("&Help")); | |
150 | menu_help->addAction(main_window.action_about()); | |
151 | ||
c7b03d9d SA |
152 | menu->addAction(menu_view->menuAction()); |
153 | menu->addSeparator(); | |
87f0df9b JH |
154 | menu->addAction(menu_help->menuAction()); |
155 | menu->addSeparator(); | |
156 | menu->addAction(main_window.action_quit()); | |
157 | ||
158 | menu_button_.setMenu(menu); | |
159 | menu_button_.setPopupMode(QToolButton::InstantPopup); | |
160 | menu_button_.setIcon(QIcon::fromTheme("menu", | |
161 | QIcon(":/icons/menu.svg"))); | |
162 | ||
163 | // Setup the toolbar | |
ed43ef2e | 164 | addWidget(open_button); |
998b89fd | 165 | addWidget(save_button); |
87f0df9b JH |
166 | addSeparator(); |
167 | addAction(main_window.action_view_zoom_in()); | |
168 | addAction(main_window.action_view_zoom_out()); | |
169 | addAction(main_window.action_view_zoom_fit()); | |
170 | addAction(main_window.action_view_zoom_one_to_one()); | |
171 | addSeparator(); | |
bdf57963 JH |
172 | addAction(main_window.action_view_show_cursors()); |
173 | addSeparator(); | |
87f0df9b | 174 | |
8dbbc7f0 | 175 | connect(&run_stop_button_, SIGNAL(clicked()), |
9f3d12f3 | 176 | this, SLOT(on_run_stop())); |
8dbbc7f0 | 177 | connect(&sample_count_, SIGNAL(value_changed()), |
124d97de | 178 | this, SLOT(on_sample_count_changed())); |
8dbbc7f0 | 179 | connect(&sample_rate_, SIGNAL(value_changed()), |
1198b887 | 180 | this, SLOT(on_sample_rate_changed())); |
dde1a563 | 181 | |
8dbbc7f0 | 182 | sample_count_.show_min_max_step(0, UINT64_MAX, 1); |
215f9499 | 183 | |
2b81ae46 | 184 | set_capture_state(pv::Session::Stopped); |
274d4f13 | 185 | |
8dbbc7f0 | 186 | configure_button_.setIcon(QIcon::fromTheme("configure", |
688ef645 | 187 | QIcon(":/icons/configure.png"))); |
b7b659aa | 188 | |
8dbbc7f0 | 189 | channels_button_.setIcon(QIcon::fromTheme("channels", |
6ac6242b | 190 | QIcon(":/icons/channels.svg"))); |
cdb50f67 | 191 | |
8dbbc7f0 | 192 | run_stop_button_.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
f5798068 | 193 | |
8dbbc7f0 JH |
194 | addWidget(&device_selector_); |
195 | configure_button_action_ = addWidget(&configure_button_); | |
9dd88889 | 196 | channels_button_action_ = addWidget(&channels_button_); |
8dbbc7f0 JH |
197 | addWidget(&sample_count_); |
198 | addWidget(&sample_rate_); | |
9dd88889 | 199 | run_stop_button_action_ = addWidget(&run_stop_button_); |
168888e2 JH |
200 | #ifdef ENABLE_DECODE |
201 | addSeparator(); | |
202 | addWidget(add_decoder_button); | |
203 | #endif | |
40065ab6 | 204 | |
87f0df9b JH |
205 | QWidget *const spacer = new QWidget(); |
206 | spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
207 | addWidget(spacer); | |
208 | ||
209 | addWidget(&menu_button_); | |
210 | ||
8dbbc7f0 JH |
211 | sample_count_.installEventFilter(this); |
212 | sample_rate_.installEventFilter(this); | |
6fb67b27 JH |
213 | } |
214 | ||
079d39ea | 215 | void MainBar::update_device_list() |
18203d86 | 216 | { |
079d39ea | 217 | DeviceManager &mgr = session_.device_manager(); |
da30ecb7 JH |
218 | shared_ptr<devices::Device> selected_device = session_.device(); |
219 | list< shared_ptr<devices::Device> > devs; | |
e8d00928 | 220 | |
079d39ea | 221 | copy(mgr.devices().begin(), mgr.devices().end(), back_inserter(devs)); |
53a7cce4 | 222 | |
079d39ea JH |
223 | if (std::find(devs.begin(), devs.end(), selected_device) == devs.end()) |
224 | devs.push_back(selected_device); | |
e95e8563 | 225 | |
079d39ea | 226 | device_selector_.set_device_list(devs, selected_device); |
e95e8563 | 227 | update_device_config_widgets(); |
18203d86 JH |
228 | } |
229 | ||
6fb67b27 | 230 | |
7c657094 | 231 | void MainBar::set_capture_state(pv::Session::capture_state state) |
6ac96c2e | 232 | { |
8dbbc7f0 JH |
233 | const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_}; |
234 | run_stop_button_.setIcon(*icons[state]); | |
2b81ae46 | 235 | run_stop_button_.setText((state == pv::Session::Stopped) ? |
2b49eeb0 | 236 | tr("Run") : tr("Stop")); |
8dbbc7f0 | 237 | run_stop_button_.setShortcut(QKeySequence(Qt::Key_Space)); |
73e170f9 SA |
238 | |
239 | bool ui_enabled = (state == pv::Session::Stopped) ? true : false; | |
240 | ||
241 | device_selector_.setEnabled(ui_enabled); | |
242 | configure_button_.setEnabled(ui_enabled); | |
243 | channels_button_.setEnabled(ui_enabled); | |
244 | sample_count_.setEnabled(ui_enabled); | |
245 | sample_rate_.setEnabled(ui_enabled); | |
6ac96c2e JH |
246 | } |
247 | ||
7c657094 | 248 | void MainBar::update_sample_rate_selector() |
dde1a563 | 249 | { |
e8d00928 ML |
250 | Glib::VariantContainerBase gvar_dict; |
251 | GVariant *gvar_list; | |
4c60462b | 252 | const uint64_t *elements = nullptr; |
488f5d3f | 253 | gsize num_elements; |
a6ed12bf | 254 | map< const ConfigKey*, std::set<Capability> > keys; |
dde1a563 | 255 | |
9dd88889 JH |
256 | if (updating_sample_rate_) { |
257 | sample_rate_.show_none(); | |
3d4f16af | 258 | return; |
9dd88889 | 259 | } |
3d4f16af | 260 | |
da30ecb7 JH |
261 | const shared_ptr<devices::Device> device = |
262 | device_selector_.selected_device(); | |
e8d00928 | 263 | if (!device) |
ef4d0201 JH |
264 | return; |
265 | ||
8dbbc7f0 JH |
266 | assert(!updating_sample_rate_); |
267 | updating_sample_rate_ = true; | |
1198b887 | 268 | |
da30ecb7 | 269 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
a6ed12bf JH |
270 | |
271 | try { | |
272 | keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS); | |
273 | } catch (Error) {} | |
274 | ||
ed1d9d81 JH |
275 | const auto iter = keys.find(ConfigKey::SAMPLERATE); |
276 | if (iter != keys.end() && | |
277 | (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { | |
c2db8ec3 | 278 | try { |
da30ecb7 | 279 | gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE); |
c2db8ec3 JH |
280 | } catch(const sigrok::Error &e) { |
281 | // Failed to enunmerate samplerate | |
282 | (void)e; | |
283 | } | |
284 | } | |
285 | ||
0aff286e | 286 | if (!gvar_dict.gobj()) { |
8dbbc7f0 JH |
287 | sample_rate_.show_none(); |
288 | updating_sample_rate_ = false; | |
dde1a563 | 289 | return; |
1198b887 | 290 | } |
dde1a563 | 291 | |
e8d00928 | 292 | if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(), |
1198b887 JH |
293 | "samplerate-steps", G_VARIANT_TYPE("at")))) |
294 | { | |
488f5d3f BV |
295 | elements = (const uint64_t *)g_variant_get_fixed_array( |
296 | gvar_list, &num_elements, sizeof(uint64_t)); | |
aafe53af JH |
297 | |
298 | const uint64_t min = elements[0]; | |
299 | const uint64_t max = elements[1]; | |
300 | const uint64_t step = elements[2]; | |
301 | ||
488f5d3f | 302 | g_variant_unref(gvar_list); |
aafe53af JH |
303 | |
304 | assert(min > 0); | |
305 | assert(max > 0); | |
306 | assert(max > min); | |
307 | assert(step > 0); | |
308 | ||
309 | if (step == 1) | |
8dbbc7f0 | 310 | sample_rate_.show_125_list(min, max); |
aafe53af JH |
311 | else |
312 | { | |
313 | // When the step is not 1, we cam't make a 1-2-5-10 | |
314 | // list of sample rates, because we may not be able to | |
315 | // make round numbers. Therefore in this case, show a | |
316 | // spin box. | |
8dbbc7f0 | 317 | sample_rate_.show_min_max_step(min, max, step); |
aafe53af | 318 | } |
dde1a563 | 319 | } |
e8d00928 | 320 | else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(), |
488f5d3f | 321 | "samplerates", G_VARIANT_TYPE("at")))) |
dde1a563 | 322 | { |
488f5d3f BV |
323 | elements = (const uint64_t *)g_variant_get_fixed_array( |
324 | gvar_list, &num_elements, sizeof(uint64_t)); | |
8dbbc7f0 | 325 | sample_rate_.show_list(elements, num_elements); |
488f5d3f | 326 | g_variant_unref(gvar_list); |
dde1a563 | 327 | } |
8dbbc7f0 | 328 | updating_sample_rate_ = false; |
48888313 JH |
329 | |
330 | update_sample_rate_selector_value(); | |
331 | } | |
332 | ||
7c657094 | 333 | void MainBar::update_sample_rate_selector_value() |
48888313 | 334 | { |
8dbbc7f0 | 335 | if (updating_sample_rate_) |
3d4f16af JH |
336 | return; |
337 | ||
da30ecb7 JH |
338 | const shared_ptr<devices::Device> device = |
339 | device_selector_.selected_device(); | |
e8d00928 | 340 | if (!device) |
19adbc2c JH |
341 | return; |
342 | ||
e8d00928 | 343 | try { |
da30ecb7 | 344 | auto gvar = device->device()->config_get(ConfigKey::SAMPLERATE); |
e8d00928 | 345 | uint64_t samplerate = |
15289d5c | 346 | Glib::VariantBase::cast_dynamic<Glib::Variant<guint64>>(gvar).get(); |
8dbbc7f0 JH |
347 | assert(!updating_sample_rate_); |
348 | updating_sample_rate_ = true; | |
349 | sample_rate_.set_value(samplerate); | |
350 | updating_sample_rate_ = false; | |
e8d00928 | 351 | } catch (Error error) { |
8dd44190 | 352 | qDebug() << "WARNING: Failed to get value of sample rate"; |
eb4008a6 JH |
353 | return; |
354 | } | |
48888313 JH |
355 | } |
356 | ||
7c657094 | 357 | void MainBar::update_sample_count_selector() |
85756012 | 358 | { |
8dbbc7f0 | 359 | if (updating_sample_count_) |
3d4f16af JH |
360 | return; |
361 | ||
da30ecb7 JH |
362 | const shared_ptr<devices::Device> device = |
363 | device_selector_.selected_device(); | |
e8d00928 | 364 | if (!device) |
19adbc2c JH |
365 | return; |
366 | ||
da30ecb7 JH |
367 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
368 | ||
8dbbc7f0 JH |
369 | assert(!updating_sample_count_); |
370 | updating_sample_count_ = true; | |
85756012 | 371 | |
3e7636f9 | 372 | if (!sample_count_supported_) |
df3c1aa3 | 373 | { |
3e7636f9 JH |
374 | sample_count_.show_none(); |
375 | updating_sample_count_ = false; | |
376 | return; | |
377 | } | |
b50ef520 | 378 | |
3e7636f9 JH |
379 | uint64_t sample_count = sample_count_.value(); |
380 | uint64_t min_sample_count = 0; | |
381 | uint64_t max_sample_count = MaxSampleCount; | |
3cbffdcf | 382 | |
3e7636f9 JH |
383 | if (sample_count == 0) |
384 | sample_count = DefaultSampleCount; | |
b50ef520 | 385 | |
da30ecb7 | 386 | const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS); |
ed1d9d81 JH |
387 | const auto iter = keys.find(ConfigKey::LIMIT_SAMPLES); |
388 | if (iter != keys.end() && | |
389 | (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { | |
6454b1e9 JH |
390 | try { |
391 | auto gvar = | |
da30ecb7 | 392 | sr_dev->config_list(ConfigKey::LIMIT_SAMPLES); |
0aff286e | 393 | if (gvar.gobj()) |
6454b1e9 JH |
394 | g_variant_get(gvar.gobj(), "(tt)", |
395 | &min_sample_count, &max_sample_count); | |
396 | } catch(const sigrok::Error &e) { | |
397 | // Failed to query sample limit | |
398 | (void)e; | |
399 | } | |
ed1d9d81 | 400 | } |
1d04852f | 401 | |
3e7636f9 JH |
402 | min_sample_count = min(max(min_sample_count, MinSampleCount), |
403 | max_sample_count); | |
b50ef520 | 404 | |
3e7636f9 JH |
405 | sample_count_.show_125_list( |
406 | min_sample_count, max_sample_count); | |
b50ef520 | 407 | |
3e7636f9 | 408 | try { |
da30ecb7 | 409 | auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES); |
3e7636f9 JH |
410 | sample_count = g_variant_get_uint64(gvar.gobj()); |
411 | if (sample_count == 0) | |
412 | sample_count = DefaultSampleCount; | |
413 | sample_count = min(max(sample_count, MinSampleCount), | |
414 | max_sample_count); | |
415 | } catch (Error error) {} | |
416 | ||
417 | sample_count_.set_value(sample_count); | |
df3c1aa3 | 418 | |
8dbbc7f0 | 419 | updating_sample_count_ = false; |
85756012 ML |
420 | } |
421 | ||
7c657094 | 422 | void MainBar::update_device_config_widgets() |
e95e8563 | 423 | { |
e95e8563 JH |
424 | using namespace pv::popups; |
425 | ||
da30ecb7 JH |
426 | const shared_ptr<devices::Device> device = |
427 | device_selector_.selected_device(); | |
9dd88889 JH |
428 | |
429 | // Hide the widgets if no device is selected | |
430 | channels_button_action_->setVisible(!!device); | |
431 | run_stop_button_action_->setVisible(!!device); | |
432 | if (!device) { | |
433 | configure_button_action_->setVisible(false); | |
434 | sample_count_.show_none(); | |
435 | sample_rate_.show_none(); | |
e95e8563 | 436 | return; |
9dd88889 | 437 | } |
e95e8563 | 438 | |
da30ecb7 JH |
439 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
440 | if (!sr_dev) | |
441 | return; | |
442 | ||
e95e8563 | 443 | // Update the configure popup |
da30ecb7 | 444 | DeviceOptions *const opts = new DeviceOptions(sr_dev, this); |
8dbbc7f0 | 445 | configure_button_action_->setVisible( |
e95e8563 | 446 | !opts->binding().properties().empty()); |
8dbbc7f0 | 447 | configure_button_.set_popup(opts); |
e95e8563 | 448 | |
6ac6242b | 449 | // Update the channels popup |
8dbbc7f0 JH |
450 | Channels *const channels = new Channels(session_, this); |
451 | channels_button_.set_popup(channels); | |
e95e8563 JH |
452 | |
453 | // Update supported options. | |
8dbbc7f0 | 454 | sample_count_supported_ = false; |
e95e8563 | 455 | |
e8d00928 | 456 | try { |
da30ecb7 | 457 | for (auto entry : sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS)) |
e95e8563 | 458 | { |
e8d00928 ML |
459 | auto key = entry.first; |
460 | auto capabilities = entry.second; | |
461 | switch (key->id()) { | |
e95e8563 | 462 | case SR_CONF_LIMIT_SAMPLES: |
e8d00928 | 463 | if (capabilities.count(Capability::SET)) |
8dbbc7f0 | 464 | sample_count_supported_ = true; |
e95e8563 JH |
465 | break; |
466 | case SR_CONF_LIMIT_FRAMES: | |
e8d00928 ML |
467 | if (capabilities.count(Capability::SET)) |
468 | { | |
da30ecb7 | 469 | sr_dev->config_set(ConfigKey::LIMIT_FRAMES, |
15289d5c | 470 | Glib::Variant<guint64>::create(1)); |
e8d00928 ML |
471 | on_config_changed(); |
472 | } | |
473 | break; | |
474 | default: | |
e95e8563 JH |
475 | break; |
476 | } | |
477 | } | |
e8d00928 | 478 | } catch (Error error) {} |
e95e8563 JH |
479 | |
480 | // Add notification of reconfigure events | |
481 | disconnect(this, SLOT(on_config_changed())); | |
e8d00928 | 482 | connect(&opts->binding(), SIGNAL(config_changed()), |
e95e8563 JH |
483 | this, SLOT(on_config_changed())); |
484 | ||
485 | // Update sweep timing widgets. | |
486 | update_sample_count_selector(); | |
487 | update_sample_rate_selector(); | |
488 | } | |
489 | ||
7c657094 | 490 | void MainBar::commit_sample_count() |
124d97de ML |
491 | { |
492 | uint64_t sample_count = 0; | |
493 | ||
da30ecb7 JH |
494 | const shared_ptr<devices::Device> device = |
495 | device_selector_.selected_device(); | |
e8d00928 | 496 | if (!device) |
19adbc2c JH |
497 | return; |
498 | ||
da30ecb7 JH |
499 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
500 | ||
8dbbc7f0 | 501 | sample_count = sample_count_.value(); |
8dbbc7f0 | 502 | if (sample_count_supported_) |
e8d00928 ML |
503 | { |
504 | try { | |
da30ecb7 | 505 | sr_dev->config_set(ConfigKey::LIMIT_SAMPLES, |
15289d5c | 506 | Glib::Variant<guint64>::create(sample_count)); |
449aec3c | 507 | update_sample_count_selector(); |
e8d00928 ML |
508 | } catch (Error error) { |
509 | qDebug() << "Failed to configure sample count."; | |
510 | return; | |
511 | } | |
124d97de | 512 | } |
e13e7879 SA |
513 | |
514 | // Devices with built-in memory might impose limits on certain | |
515 | // configurations, so let's check what sample rate the driver | |
516 | // lets us use now. | |
517 | update_sample_rate_selector(); | |
124d97de ML |
518 | } |
519 | ||
7c657094 | 520 | void MainBar::commit_sample_rate() |
48888313 JH |
521 | { |
522 | uint64_t sample_rate = 0; | |
523 | ||
da30ecb7 JH |
524 | const shared_ptr<devices::Device> device = |
525 | device_selector_.selected_device(); | |
e8d00928 | 526 | if (!device) |
19adbc2c JH |
527 | return; |
528 | ||
da30ecb7 JH |
529 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
530 | ||
8dbbc7f0 | 531 | sample_rate = sample_rate_.value(); |
f9541bde JH |
532 | if (sample_rate == 0) |
533 | return; | |
534 | ||
e8d00928 | 535 | try { |
da30ecb7 | 536 | sr_dev->config_set(ConfigKey::SAMPLERATE, |
15289d5c | 537 | Glib::Variant<guint64>::create(sample_rate)); |
0e0b6b3e | 538 | update_sample_rate_selector(); |
e8d00928 | 539 | } catch (Error error) { |
48888313 JH |
540 | qDebug() << "Failed to configure samplerate."; |
541 | return; | |
542 | } | |
e13e7879 SA |
543 | |
544 | // Devices with built-in memory might impose limits on certain | |
545 | // configurations, so let's check what sample count the driver | |
546 | // lets us use now. | |
547 | update_sample_count_selector(); | |
dde1a563 JH |
548 | } |
549 | ||
7c657094 | 550 | void MainBar::on_device_selected() |
dde1a563 | 551 | { |
da30ecb7 | 552 | shared_ptr<devices::Device> device = device_selector_.selected_device(); |
e8d00928 | 553 | if (!device) |
19adbc2c JH |
554 | return; |
555 | ||
51cf49fe | 556 | main_window_.select_device(device); |
51d4a9ab | 557 | |
e95e8563 | 558 | update_device_config_widgets(); |
dde1a563 | 559 | } |
51e77110 | 560 | |
7c657094 | 561 | void MainBar::on_sample_count_changed() |
124d97de | 562 | { |
449aec3c SA |
563 | if (!updating_sample_count_) |
564 | commit_sample_count(); | |
124d97de ML |
565 | } |
566 | ||
7c657094 | 567 | void MainBar::on_sample_rate_changed() |
48888313 | 568 | { |
0e0b6b3e SA |
569 | if (!updating_sample_rate_) |
570 | commit_sample_rate(); | |
48888313 JH |
571 | } |
572 | ||
7c657094 | 573 | void MainBar::on_run_stop() |
9f3d12f3 | 574 | { |
b50ef520 | 575 | commit_sample_count(); |
9f3d12f3 | 576 | commit_sample_rate(); |
4e7f5ba8 | 577 | main_window_.run_stop(); |
9f3d12f3 JH |
578 | } |
579 | ||
7c657094 | 580 | void MainBar::on_config_changed() |
82afd5e3 JH |
581 | { |
582 | commit_sample_count(); | |
82afd5e3 | 583 | commit_sample_rate(); |
82afd5e3 JH |
584 | } |
585 | ||
7c657094 | 586 | bool MainBar::eventFilter(QObject *watched, QEvent *event) |
40065ab6 | 587 | { |
8dbbc7f0 | 588 | if ((watched == &sample_count_ || watched == &sample_rate_) && |
40065ab6 | 589 | (event->type() == QEvent::ToolTip)) { |
60d9b99a | 590 | auto sec = pv::util::Timestamp(sample_count_.value()) / sample_rate_.value(); |
40065ab6 | 591 | QHelpEvent *help_event = static_cast<QHelpEvent*>(event); |
62974f45 | 592 | |
3ccf0f7f JS |
593 | QString str = tr("Total sampling time: %1").arg( |
594 | pv::util::format_time_si(sec, pv::util::SIPrefix::unspecified, 0, "s", false)); | |
40065ab6 JS |
595 | QToolTip::showText(help_event->globalPos(), str); |
596 | ||
597 | return true; | |
598 | } | |
599 | ||
600 | return false; | |
601 | } | |
602 | ||
f4c92e1c | 603 | } // namespace toolbars |
51e77110 | 604 | } // namespace pv |