]>
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()); | |
61501398 | 115 | open_actions.push_back(main_window.action_save_selection_as()); |
686d9151 | 116 | |
998b89fd JH |
117 | widgets::ExportMenu *export_menu = new widgets::ExportMenu(this, |
118 | session.device_manager().context(), | |
686d9151 | 119 | open_actions); |
998b89fd JH |
120 | connect(export_menu, |
121 | SIGNAL(format_selected(std::shared_ptr<sigrok::OutputFormat>)), | |
122 | &main_window_, | |
123 | SLOT(export_file(std::shared_ptr<sigrok::OutputFormat>))); | |
124 | ||
125 | save_button->setMenu(export_menu); | |
126 | save_button->setDefaultAction(main_window.action_save_as()); | |
127 | save_button->setPopupMode(QToolButton::MenuButtonPopup); | |
128 | ||
079d39ea JH |
129 | // Device selector menu |
130 | connect(&device_selector_, SIGNAL(device_selected()), | |
131 | this, SLOT(on_device_selected())); | |
132 | ||
168888e2 JH |
133 | // Setup the decoder button |
134 | #ifdef ENABLE_DECODE | |
135 | QToolButton *add_decoder_button = new QToolButton(this); | |
136 | add_decoder_button->setIcon(QIcon::fromTheme("add-decoder", | |
137 | QIcon(":/icons/add-decoder.svg"))); | |
138 | add_decoder_button->setPopupMode(QToolButton::InstantPopup); | |
139 | add_decoder_button->setMenu(main_window_.menu_decoder_add()); | |
140 | #endif | |
141 | ||
c7b03d9d | 142 | // Setup the burger menu |
87f0df9b JH |
143 | QMenu *const menu = new QMenu(this); |
144 | ||
c7b03d9d SA |
145 | QMenu *const menu_view = new QMenu; |
146 | menu_view->setTitle(tr("&View")); | |
147 | menu_view->addAction(main_window.action_view_sticky_scrolling()); | |
148 | ||
87f0df9b JH |
149 | QMenu *const menu_help = new QMenu; |
150 | menu_help->setTitle(tr("&Help")); | |
151 | menu_help->addAction(main_window.action_about()); | |
152 | ||
c7b03d9d SA |
153 | menu->addAction(menu_view->menuAction()); |
154 | menu->addSeparator(); | |
87f0df9b JH |
155 | menu->addAction(menu_help->menuAction()); |
156 | menu->addSeparator(); | |
157 | menu->addAction(main_window.action_quit()); | |
158 | ||
159 | menu_button_.setMenu(menu); | |
160 | menu_button_.setPopupMode(QToolButton::InstantPopup); | |
161 | menu_button_.setIcon(QIcon::fromTheme("menu", | |
162 | QIcon(":/icons/menu.svg"))); | |
163 | ||
164 | // Setup the toolbar | |
ed43ef2e | 165 | addWidget(open_button); |
998b89fd | 166 | addWidget(save_button); |
87f0df9b JH |
167 | addSeparator(); |
168 | addAction(main_window.action_view_zoom_in()); | |
169 | addAction(main_window.action_view_zoom_out()); | |
170 | addAction(main_window.action_view_zoom_fit()); | |
171 | addAction(main_window.action_view_zoom_one_to_one()); | |
172 | addSeparator(); | |
bdf57963 JH |
173 | addAction(main_window.action_view_show_cursors()); |
174 | addSeparator(); | |
87f0df9b | 175 | |
8dbbc7f0 | 176 | connect(&run_stop_button_, SIGNAL(clicked()), |
9f3d12f3 | 177 | this, SLOT(on_run_stop())); |
8dbbc7f0 | 178 | connect(&sample_count_, SIGNAL(value_changed()), |
124d97de | 179 | this, SLOT(on_sample_count_changed())); |
8dbbc7f0 | 180 | connect(&sample_rate_, SIGNAL(value_changed()), |
1198b887 | 181 | this, SLOT(on_sample_rate_changed())); |
dde1a563 | 182 | |
8dbbc7f0 | 183 | sample_count_.show_min_max_step(0, UINT64_MAX, 1); |
215f9499 | 184 | |
2b81ae46 | 185 | set_capture_state(pv::Session::Stopped); |
274d4f13 | 186 | |
8dbbc7f0 | 187 | configure_button_.setIcon(QIcon::fromTheme("configure", |
688ef645 | 188 | QIcon(":/icons/configure.png"))); |
b7b659aa | 189 | |
8dbbc7f0 | 190 | channels_button_.setIcon(QIcon::fromTheme("channels", |
6ac6242b | 191 | QIcon(":/icons/channels.svg"))); |
cdb50f67 | 192 | |
8dbbc7f0 | 193 | run_stop_button_.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
f5798068 | 194 | |
8dbbc7f0 JH |
195 | addWidget(&device_selector_); |
196 | configure_button_action_ = addWidget(&configure_button_); | |
9dd88889 | 197 | channels_button_action_ = addWidget(&channels_button_); |
8dbbc7f0 JH |
198 | addWidget(&sample_count_); |
199 | addWidget(&sample_rate_); | |
9dd88889 | 200 | run_stop_button_action_ = addWidget(&run_stop_button_); |
168888e2 JH |
201 | #ifdef ENABLE_DECODE |
202 | addSeparator(); | |
203 | addWidget(add_decoder_button); | |
204 | #endif | |
40065ab6 | 205 | |
87f0df9b JH |
206 | QWidget *const spacer = new QWidget(); |
207 | spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
208 | addWidget(spacer); | |
209 | ||
210 | addWidget(&menu_button_); | |
211 | ||
8dbbc7f0 JH |
212 | sample_count_.installEventFilter(this); |
213 | sample_rate_.installEventFilter(this); | |
6fb67b27 JH |
214 | } |
215 | ||
079d39ea | 216 | void MainBar::update_device_list() |
18203d86 | 217 | { |
079d39ea | 218 | DeviceManager &mgr = session_.device_manager(); |
da30ecb7 JH |
219 | shared_ptr<devices::Device> selected_device = session_.device(); |
220 | list< shared_ptr<devices::Device> > devs; | |
e8d00928 | 221 | |
079d39ea | 222 | copy(mgr.devices().begin(), mgr.devices().end(), back_inserter(devs)); |
53a7cce4 | 223 | |
079d39ea JH |
224 | if (std::find(devs.begin(), devs.end(), selected_device) == devs.end()) |
225 | devs.push_back(selected_device); | |
e95e8563 | 226 | |
079d39ea | 227 | device_selector_.set_device_list(devs, selected_device); |
e95e8563 | 228 | update_device_config_widgets(); |
18203d86 JH |
229 | } |
230 | ||
6fb67b27 | 231 | |
7c657094 | 232 | void MainBar::set_capture_state(pv::Session::capture_state state) |
6ac96c2e | 233 | { |
8dbbc7f0 JH |
234 | const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_}; |
235 | run_stop_button_.setIcon(*icons[state]); | |
2b81ae46 | 236 | run_stop_button_.setText((state == pv::Session::Stopped) ? |
2b49eeb0 | 237 | tr("Run") : tr("Stop")); |
8dbbc7f0 | 238 | run_stop_button_.setShortcut(QKeySequence(Qt::Key_Space)); |
73e170f9 SA |
239 | |
240 | bool ui_enabled = (state == pv::Session::Stopped) ? true : false; | |
241 | ||
242 | device_selector_.setEnabled(ui_enabled); | |
243 | configure_button_.setEnabled(ui_enabled); | |
244 | channels_button_.setEnabled(ui_enabled); | |
245 | sample_count_.setEnabled(ui_enabled); | |
246 | sample_rate_.setEnabled(ui_enabled); | |
6ac96c2e JH |
247 | } |
248 | ||
7c657094 | 249 | void MainBar::update_sample_rate_selector() |
dde1a563 | 250 | { |
e8d00928 ML |
251 | Glib::VariantContainerBase gvar_dict; |
252 | GVariant *gvar_list; | |
4c60462b | 253 | const uint64_t *elements = nullptr; |
488f5d3f | 254 | gsize num_elements; |
a6ed12bf | 255 | map< const ConfigKey*, std::set<Capability> > keys; |
dde1a563 | 256 | |
9dd88889 JH |
257 | if (updating_sample_rate_) { |
258 | sample_rate_.show_none(); | |
3d4f16af | 259 | return; |
9dd88889 | 260 | } |
3d4f16af | 261 | |
da30ecb7 JH |
262 | const shared_ptr<devices::Device> device = |
263 | device_selector_.selected_device(); | |
e8d00928 | 264 | if (!device) |
ef4d0201 JH |
265 | return; |
266 | ||
8dbbc7f0 JH |
267 | assert(!updating_sample_rate_); |
268 | updating_sample_rate_ = true; | |
1198b887 | 269 | |
da30ecb7 | 270 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
a6ed12bf JH |
271 | |
272 | try { | |
273 | keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS); | |
274 | } catch (Error) {} | |
275 | ||
ed1d9d81 JH |
276 | const auto iter = keys.find(ConfigKey::SAMPLERATE); |
277 | if (iter != keys.end() && | |
278 | (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { | |
c2db8ec3 | 279 | try { |
da30ecb7 | 280 | gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE); |
2ad82c2e | 281 | } catch (const sigrok::Error &e) { |
c2db8ec3 JH |
282 | // Failed to enunmerate samplerate |
283 | (void)e; | |
284 | } | |
285 | } | |
286 | ||
0aff286e | 287 | if (!gvar_dict.gobj()) { |
8dbbc7f0 JH |
288 | sample_rate_.show_none(); |
289 | updating_sample_rate_ = false; | |
dde1a563 | 290 | return; |
1198b887 | 291 | } |
dde1a563 | 292 | |
e8d00928 | 293 | if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(), |
2ad82c2e | 294 | "samplerate-steps", G_VARIANT_TYPE("at")))) { |
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); |
2ad82c2e | 311 | else { |
aafe53af JH |
312 | // When the step is not 1, we cam't make a 1-2-5-10 |
313 | // list of sample rates, because we may not be able to | |
314 | // make round numbers. Therefore in this case, show a | |
315 | // spin box. | |
8dbbc7f0 | 316 | sample_rate_.show_min_max_step(min, max, step); |
aafe53af | 317 | } |
2ad82c2e UH |
318 | } else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(), |
319 | "samplerates", G_VARIANT_TYPE("at")))) { | |
488f5d3f BV |
320 | elements = (const uint64_t *)g_variant_get_fixed_array( |
321 | gvar_list, &num_elements, sizeof(uint64_t)); | |
8dbbc7f0 | 322 | sample_rate_.show_list(elements, num_elements); |
488f5d3f | 323 | g_variant_unref(gvar_list); |
dde1a563 | 324 | } |
8dbbc7f0 | 325 | updating_sample_rate_ = false; |
48888313 JH |
326 | |
327 | update_sample_rate_selector_value(); | |
328 | } | |
329 | ||
7c657094 | 330 | void MainBar::update_sample_rate_selector_value() |
48888313 | 331 | { |
8dbbc7f0 | 332 | if (updating_sample_rate_) |
3d4f16af JH |
333 | return; |
334 | ||
da30ecb7 JH |
335 | const shared_ptr<devices::Device> device = |
336 | device_selector_.selected_device(); | |
e8d00928 | 337 | if (!device) |
19adbc2c JH |
338 | return; |
339 | ||
e8d00928 | 340 | try { |
da30ecb7 | 341 | auto gvar = device->device()->config_get(ConfigKey::SAMPLERATE); |
e8d00928 | 342 | uint64_t samplerate = |
15289d5c | 343 | Glib::VariantBase::cast_dynamic<Glib::Variant<guint64>>(gvar).get(); |
8dbbc7f0 JH |
344 | assert(!updating_sample_rate_); |
345 | updating_sample_rate_ = true; | |
346 | sample_rate_.set_value(samplerate); | |
347 | updating_sample_rate_ = false; | |
e8d00928 | 348 | } catch (Error error) { |
8dd44190 | 349 | qDebug() << "WARNING: Failed to get value of sample rate"; |
eb4008a6 JH |
350 | return; |
351 | } | |
48888313 JH |
352 | } |
353 | ||
7c657094 | 354 | void MainBar::update_sample_count_selector() |
85756012 | 355 | { |
8dbbc7f0 | 356 | if (updating_sample_count_) |
3d4f16af JH |
357 | return; |
358 | ||
da30ecb7 JH |
359 | const shared_ptr<devices::Device> device = |
360 | device_selector_.selected_device(); | |
e8d00928 | 361 | if (!device) |
19adbc2c JH |
362 | return; |
363 | ||
da30ecb7 JH |
364 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
365 | ||
8dbbc7f0 JH |
366 | assert(!updating_sample_count_); |
367 | updating_sample_count_ = true; | |
85756012 | 368 | |
2ad82c2e | 369 | if (!sample_count_supported_) { |
3e7636f9 JH |
370 | sample_count_.show_none(); |
371 | updating_sample_count_ = false; | |
372 | return; | |
373 | } | |
b50ef520 | 374 | |
3e7636f9 JH |
375 | uint64_t sample_count = sample_count_.value(); |
376 | uint64_t min_sample_count = 0; | |
377 | uint64_t max_sample_count = MaxSampleCount; | |
3cbffdcf | 378 | |
3e7636f9 JH |
379 | if (sample_count == 0) |
380 | sample_count = DefaultSampleCount; | |
b50ef520 | 381 | |
da30ecb7 | 382 | const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS); |
ed1d9d81 JH |
383 | const auto iter = keys.find(ConfigKey::LIMIT_SAMPLES); |
384 | if (iter != keys.end() && | |
385 | (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { | |
6454b1e9 JH |
386 | try { |
387 | auto gvar = | |
da30ecb7 | 388 | sr_dev->config_list(ConfigKey::LIMIT_SAMPLES); |
0aff286e | 389 | if (gvar.gobj()) |
6454b1e9 JH |
390 | g_variant_get(gvar.gobj(), "(tt)", |
391 | &min_sample_count, &max_sample_count); | |
2ad82c2e | 392 | } catch (const sigrok::Error &e) { |
6454b1e9 JH |
393 | // Failed to query sample limit |
394 | (void)e; | |
395 | } | |
ed1d9d81 | 396 | } |
1d04852f | 397 | |
3e7636f9 JH |
398 | min_sample_count = min(max(min_sample_count, MinSampleCount), |
399 | max_sample_count); | |
b50ef520 | 400 | |
3e7636f9 JH |
401 | sample_count_.show_125_list( |
402 | min_sample_count, max_sample_count); | |
b50ef520 | 403 | |
3e7636f9 | 404 | try { |
da30ecb7 | 405 | auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES); |
3e7636f9 JH |
406 | sample_count = g_variant_get_uint64(gvar.gobj()); |
407 | if (sample_count == 0) | |
408 | sample_count = DefaultSampleCount; | |
409 | sample_count = min(max(sample_count, MinSampleCount), | |
410 | max_sample_count); | |
411 | } catch (Error error) {} | |
412 | ||
413 | sample_count_.set_value(sample_count); | |
df3c1aa3 | 414 | |
8dbbc7f0 | 415 | updating_sample_count_ = false; |
85756012 ML |
416 | } |
417 | ||
7c657094 | 418 | void MainBar::update_device_config_widgets() |
e95e8563 | 419 | { |
e95e8563 JH |
420 | using namespace pv::popups; |
421 | ||
da30ecb7 JH |
422 | const shared_ptr<devices::Device> device = |
423 | device_selector_.selected_device(); | |
9dd88889 JH |
424 | |
425 | // Hide the widgets if no device is selected | |
426 | channels_button_action_->setVisible(!!device); | |
427 | run_stop_button_action_->setVisible(!!device); | |
428 | if (!device) { | |
429 | configure_button_action_->setVisible(false); | |
430 | sample_count_.show_none(); | |
431 | sample_rate_.show_none(); | |
e95e8563 | 432 | return; |
9dd88889 | 433 | } |
e95e8563 | 434 | |
da30ecb7 JH |
435 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
436 | if (!sr_dev) | |
437 | return; | |
438 | ||
e95e8563 | 439 | // Update the configure popup |
da30ecb7 | 440 | DeviceOptions *const opts = new DeviceOptions(sr_dev, this); |
8dbbc7f0 | 441 | configure_button_action_->setVisible( |
e95e8563 | 442 | !opts->binding().properties().empty()); |
8dbbc7f0 | 443 | configure_button_.set_popup(opts); |
e95e8563 | 444 | |
6ac6242b | 445 | // Update the channels popup |
8dbbc7f0 JH |
446 | Channels *const channels = new Channels(session_, this); |
447 | channels_button_.set_popup(channels); | |
e95e8563 JH |
448 | |
449 | // Update supported options. | |
8dbbc7f0 | 450 | sample_count_supported_ = false; |
e95e8563 | 451 | |
e8d00928 | 452 | try { |
2ad82c2e | 453 | for (auto entry : sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS)) { |
e8d00928 ML |
454 | auto key = entry.first; |
455 | auto capabilities = entry.second; | |
456 | switch (key->id()) { | |
e95e8563 | 457 | case SR_CONF_LIMIT_SAMPLES: |
e8d00928 | 458 | if (capabilities.count(Capability::SET)) |
8dbbc7f0 | 459 | sample_count_supported_ = true; |
e95e8563 JH |
460 | break; |
461 | case SR_CONF_LIMIT_FRAMES: | |
2ad82c2e | 462 | if (capabilities.count(Capability::SET)) { |
da30ecb7 | 463 | sr_dev->config_set(ConfigKey::LIMIT_FRAMES, |
15289d5c | 464 | Glib::Variant<guint64>::create(1)); |
e8d00928 ML |
465 | on_config_changed(); |
466 | } | |
467 | break; | |
468 | default: | |
e95e8563 JH |
469 | break; |
470 | } | |
471 | } | |
e8d00928 | 472 | } catch (Error error) {} |
e95e8563 JH |
473 | |
474 | // Add notification of reconfigure events | |
475 | disconnect(this, SLOT(on_config_changed())); | |
e8d00928 | 476 | connect(&opts->binding(), SIGNAL(config_changed()), |
e95e8563 JH |
477 | this, SLOT(on_config_changed())); |
478 | ||
479 | // Update sweep timing widgets. | |
480 | update_sample_count_selector(); | |
481 | update_sample_rate_selector(); | |
482 | } | |
483 | ||
7c657094 | 484 | void MainBar::commit_sample_count() |
124d97de ML |
485 | { |
486 | uint64_t sample_count = 0; | |
487 | ||
da30ecb7 JH |
488 | const shared_ptr<devices::Device> device = |
489 | device_selector_.selected_device(); | |
e8d00928 | 490 | if (!device) |
19adbc2c JH |
491 | return; |
492 | ||
da30ecb7 JH |
493 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
494 | ||
8dbbc7f0 | 495 | sample_count = sample_count_.value(); |
2ad82c2e | 496 | if (sample_count_supported_) { |
e8d00928 | 497 | try { |
da30ecb7 | 498 | sr_dev->config_set(ConfigKey::LIMIT_SAMPLES, |
15289d5c | 499 | Glib::Variant<guint64>::create(sample_count)); |
449aec3c | 500 | update_sample_count_selector(); |
e8d00928 ML |
501 | } catch (Error error) { |
502 | qDebug() << "Failed to configure sample count."; | |
503 | return; | |
504 | } | |
124d97de | 505 | } |
e13e7879 SA |
506 | |
507 | // Devices with built-in memory might impose limits on certain | |
508 | // configurations, so let's check what sample rate the driver | |
509 | // lets us use now. | |
510 | update_sample_rate_selector(); | |
124d97de ML |
511 | } |
512 | ||
7c657094 | 513 | void MainBar::commit_sample_rate() |
48888313 JH |
514 | { |
515 | uint64_t sample_rate = 0; | |
516 | ||
da30ecb7 JH |
517 | const shared_ptr<devices::Device> device = |
518 | device_selector_.selected_device(); | |
e8d00928 | 519 | if (!device) |
19adbc2c JH |
520 | return; |
521 | ||
da30ecb7 JH |
522 | const shared_ptr<sigrok::Device> sr_dev = device->device(); |
523 | ||
8dbbc7f0 | 524 | sample_rate = sample_rate_.value(); |
f9541bde JH |
525 | if (sample_rate == 0) |
526 | return; | |
527 | ||
e8d00928 | 528 | try { |
da30ecb7 | 529 | sr_dev->config_set(ConfigKey::SAMPLERATE, |
15289d5c | 530 | Glib::Variant<guint64>::create(sample_rate)); |
0e0b6b3e | 531 | update_sample_rate_selector(); |
e8d00928 | 532 | } catch (Error error) { |
48888313 JH |
533 | qDebug() << "Failed to configure samplerate."; |
534 | return; | |
535 | } | |
e13e7879 SA |
536 | |
537 | // Devices with built-in memory might impose limits on certain | |
538 | // configurations, so let's check what sample count the driver | |
539 | // lets us use now. | |
540 | update_sample_count_selector(); | |
dde1a563 JH |
541 | } |
542 | ||
7c657094 | 543 | void MainBar::on_device_selected() |
dde1a563 | 544 | { |
da30ecb7 | 545 | shared_ptr<devices::Device> device = device_selector_.selected_device(); |
e8d00928 | 546 | if (!device) |
19adbc2c JH |
547 | return; |
548 | ||
51cf49fe | 549 | main_window_.select_device(device); |
51d4a9ab | 550 | |
e95e8563 | 551 | update_device_config_widgets(); |
dde1a563 | 552 | } |
51e77110 | 553 | |
7c657094 | 554 | void MainBar::on_sample_count_changed() |
124d97de | 555 | { |
449aec3c SA |
556 | if (!updating_sample_count_) |
557 | commit_sample_count(); | |
124d97de ML |
558 | } |
559 | ||
7c657094 | 560 | void MainBar::on_sample_rate_changed() |
48888313 | 561 | { |
0e0b6b3e SA |
562 | if (!updating_sample_rate_) |
563 | commit_sample_rate(); | |
48888313 JH |
564 | } |
565 | ||
7c657094 | 566 | void MainBar::on_run_stop() |
9f3d12f3 | 567 | { |
b50ef520 | 568 | commit_sample_count(); |
9f3d12f3 | 569 | commit_sample_rate(); |
4e7f5ba8 | 570 | main_window_.run_stop(); |
9f3d12f3 JH |
571 | } |
572 | ||
7c657094 | 573 | void MainBar::on_config_changed() |
82afd5e3 JH |
574 | { |
575 | commit_sample_count(); | |
82afd5e3 | 576 | commit_sample_rate(); |
82afd5e3 JH |
577 | } |
578 | ||
7c657094 | 579 | bool MainBar::eventFilter(QObject *watched, QEvent *event) |
40065ab6 | 580 | { |
2ad82c2e UH |
581 | if (sample_count_supported_ && (watched == &sample_count_ || |
582 | watched == &sample_rate_) && | |
583 | (event->type() == QEvent::ToolTip)) { | |
60d9b99a | 584 | auto sec = pv::util::Timestamp(sample_count_.value()) / sample_rate_.value(); |
40065ab6 | 585 | QHelpEvent *help_event = static_cast<QHelpEvent*>(event); |
62974f45 | 586 | |
3ccf0f7f JS |
587 | QString str = tr("Total sampling time: %1").arg( |
588 | pv::util::format_time_si(sec, pv::util::SIPrefix::unspecified, 0, "s", false)); | |
40065ab6 JS |
589 | QToolTip::showText(help_event->globalPos(), str); |
590 | ||
591 | return true; | |
592 | } | |
593 | ||
594 | return false; | |
595 | } | |
596 | ||
f4c92e1c | 597 | } // namespace toolbars |
51e77110 | 598 | } // namespace pv |