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