samplingbar.cpp 34.5 KB
Newer Older
DreamSourceLab's avatar
DreamSourceLab committed
1
/*
DreamSourceLab's avatar
DreamSourceLab committed
2 3
 * This file is part of the DSView project.
 * DSView is based on PulseView.
DreamSourceLab's avatar
DreamSourceLab committed
4
 *
5
 * Copyright (C) 2013 DreamSourceLab <support@dreamsourcelab.com>
DreamSourceLab's avatar
DreamSourceLab committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

22 23
#include "samplingbar.h"

DreamSourceLab's avatar
DreamSourceLab committed
24 25 26
#include <extdef.h>
#include <assert.h>
#include <boost/foreach.hpp>
27
#include <libusb.h>
DreamSourceLab's avatar
DreamSourceLab committed
28 29 30 31

#include <QAction>
#include <QDebug>
#include <QLabel>
32
#include <QAbstractItemView>
33
#include <QApplication>
DreamSourceLab's avatar
DreamSourceLab committed
34

DreamSourceLab's avatar
DreamSourceLab committed
35 36 37
#include "../devicemanager.h"
#include "../device/devinst.h"
#include "../dialogs/deviceoptions.h"
DreamSourceLab's avatar
DreamSourceLab committed
38
#include "../dialogs/waitingdialog.h"
39
#include "../dialogs/dsmessagebox.h"
DreamSourceLab's avatar
DreamSourceLab committed
40
#include "../view/dsosignal.h"
41
#include "../dialogs/interval.h"
DreamSourceLab's avatar
DreamSourceLab committed
42

DreamSourceLab's avatar
DreamSourceLab committed
43
using namespace boost;
DreamSourceLab's avatar
DreamSourceLab committed
44 45 46 47 48
using boost::shared_ptr;
using std::map;
using std::max;
using std::min;
using std::string;
DreamSourceLab's avatar
DreamSourceLab committed
49 50 51 52

namespace pv {
namespace toolbars {

53 54
const QString SamplingBar::RLEString = tr("(RLE)");
const QString SamplingBar::DIVString = tr(" / div");
DreamSourceLab's avatar
DreamSourceLab committed
55

DreamSourceLab's avatar
DreamSourceLab committed
56
SamplingBar::SamplingBar(SigSession &session, QWidget *parent) :
DreamSourceLab's avatar
DreamSourceLab committed
57
	QToolBar("Sampling Bar", parent),
DreamSourceLab's avatar
DreamSourceLab committed
58 59
    _session(session),
    _enable(true),
60
    _sampling(false),
61
    _device_type(this),
DreamSourceLab's avatar
DreamSourceLab committed
62 63 64 65 66 67 68 69 70
    _device_selector(this),
    _updating_device_selector(false),
    _configure_button(this),
    _sample_count(this),
    _sample_rate(this),
    _updating_sample_rate(false),
    _updating_sample_count(false),
    _run_stop_button(this),
    _instant_button(this),
71
    _mode_button(this),
DreamSourceLab's avatar
DreamSourceLab committed
72
    _instant(false)
DreamSourceLab's avatar
DreamSourceLab committed
73 74
{
    setMovable(false);
Andy Dneg's avatar
Andy Dneg committed
75 76
    setContentsMargins(0,0,0,0);
    setIconSize(QSize(40, 28));
77 78
    layout()->setMargin(0);
    layout()->setSpacing(0);
DreamSourceLab's avatar
DreamSourceLab committed
79

DreamSourceLab's avatar
DreamSourceLab committed
80 81 82 83
    connect(&_device_selector, SIGNAL(currentIndexChanged (int)),
        this, SLOT(on_device_selected()));
    connect(&_configure_button, SIGNAL(clicked()),
        this, SLOT(on_configure()));
DreamSourceLab's avatar
DreamSourceLab committed
84
	connect(&_run_stop_button, SIGNAL(clicked()),
85
        this, SLOT(on_run_stop()), Qt::DirectConnection);
DreamSourceLab's avatar
DreamSourceLab committed
86 87 88
    connect(&_instant_button, SIGNAL(clicked()),
        this, SLOT(on_instant_stop()));

89
    _mode_button.setPopupMode(QToolButton::InstantPopup);
DreamSourceLab's avatar
DreamSourceLab committed
90

91 92
    _device_selector.setSizeAdjustPolicy(QComboBox::AdjustToContents);
    _sample_rate.setSizeAdjustPolicy(QComboBox::AdjustToContents);
DreamSourceLab's avatar
DreamSourceLab committed
93
    _sample_count.setSizeAdjustPolicy(QComboBox::AdjustToContents);
94 95
    _device_selector.setMaximumWidth(ComboBoxMaxWidth);

DreamSourceLab's avatar
DreamSourceLab committed
96 97
    connect(&_sample_count, SIGNAL(currentIndexChanged(int)),
        this, SLOT(on_samplecount_sel(int)));
DreamSourceLab's avatar
DreamSourceLab committed
98 99 100 101

    //_run_stop_button.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    _run_stop_button.setObjectName(tr("run_stop_button"));

DreamSourceLab's avatar
DreamSourceLab committed
102 103 104
    connect(&_sample_rate, SIGNAL(currentIndexChanged(int)),
        this, SLOT(on_samplerate_sel(int)));

105 106 107
    QWidget *leftMargin = new QWidget(this);
    leftMargin->setFixedWidth(4);
    addWidget(leftMargin);
Andy Dneg's avatar
Andy Dneg committed
108

109 110
    _device_type.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    addWidget(&_device_type);
DreamSourceLab's avatar
DreamSourceLab committed
111
    addWidget(&_device_selector);
Andy Dneg's avatar
Andy Dneg committed
112
    _configure_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
DreamSourceLab's avatar
DreamSourceLab committed
113
    addWidget(&_configure_button);
Andy Dneg's avatar
Andy Dneg committed
114

DreamSourceLab's avatar
DreamSourceLab committed
115
    addWidget(&_sample_count);
DreamSourceLab's avatar
DreamSourceLab committed
116
    addWidget(new QLabel(tr(" @ ")));
DreamSourceLab's avatar
DreamSourceLab committed
117
    addWidget(&_sample_rate);
118 119 120 121 122 123 124 125 126 127 128

    _action_single = new QAction(this);
    connect(_action_single, SIGNAL(triggered()), this, SLOT(on_mode()));

    _action_repeat = new QAction(this);
    connect(_action_repeat, SIGNAL(triggered()), this, SLOT(on_mode()));

    _mode_menu = new QMenu(this);
    _mode_menu->addAction(_action_single);
    _mode_menu->addAction(_action_repeat);
    _mode_button.setMenu(_mode_menu);
Andy Dneg's avatar
Andy Dneg committed
129 130

    _mode_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
131 132
    _mode_action = addWidget(&_mode_button);

Andy Dneg's avatar
Andy Dneg committed
133
    _run_stop_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
DreamSourceLab's avatar
DreamSourceLab committed
134
    _run_stop_action = addWidget(&_run_stop_button);
Andy Dneg's avatar
Andy Dneg committed
135
    _instant_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
DreamSourceLab's avatar
DreamSourceLab committed
136
    _instant_action = addWidget(&_instant_button);
Andy Dneg's avatar
Andy Dneg committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

    set_sampling(false);
    //retranslateUi();
}

void SamplingBar::changeEvent(QEvent *event)
{
    if (event->type() == QEvent::LanguageChange)
        retranslateUi();
    else if (event->type() == QEvent::StyleChange)
        reStyle();
    QToolBar::changeEvent(event);
}

void SamplingBar::retranslateUi()
{
153 154 155 156 157 158 159
    shared_ptr<pv::device::DevInst> dev_inst = get_selected_device();
    if (dev_inst && dev_inst->dev_inst()) {
        if (dev_inst->name().contains("virtual-demo"))
            _device_type.setText(tr("Demo"));
        else if (dev_inst->name().contains("virtual"))
            _device_type.setText(tr("File"));
        else {
160
            int usb_speed = LIBUSB_SPEED_HIGH;
161 162 163 164 165 166 167 168 169 170 171 172 173
            GVariant *gvar = dev_inst->get_config(NULL, NULL, SR_CONF_USB_SPEED);
            if (gvar != NULL) {
                usb_speed = g_variant_get_int32(gvar);
                g_variant_unref(gvar);
            }
            if (usb_speed == LIBUSB_SPEED_HIGH)
                _device_type.setText(tr("USB 2.0"));
            else if (usb_speed == LIBUSB_SPEED_SUPER)
                _device_type.setText(tr("USB 3.0"));
            else
                _device_type.setText(tr("USB UNKNOWN"));
        }
    }
Andy Dneg's avatar
Andy Dneg committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
    _configure_button.setText(tr("Options"));
    _mode_button.setText(tr("Mode"));
    if (_instant) {
        if (_session.get_device() &&
            _session.get_device()->dev_inst()->mode == DSO)
            _instant_button.setText(_sampling ? tr("Stop") : tr("Single"));
        else
            _instant_button.setText(_sampling ? tr("Stop") : tr("Instant"));
        _run_stop_button.setText(tr("Start"));
    } else {
        _run_stop_button.setText(_sampling ? tr("Stop") : tr("Start"));
        if (_session.get_device() &&
            _session.get_device()->dev_inst()->mode == DSO)
            _instant_button.setText(tr("Single"));
        else
            _instant_button.setText(tr("Instant"));
    }

    _action_single->setText(tr("&Single"));
    _action_repeat->setText(tr("&Repetitive"));
}

void SamplingBar::reStyle()
{
    QString iconPath = ":/icons/" + qApp->property("Style").toString();

200 201 202 203 204 205 206
    shared_ptr<pv::device::DevInst> dev_inst = get_selected_device();
    if (dev_inst && dev_inst->dev_inst()) {
        if (dev_inst->name().contains("virtual-demo"))
            _device_type.setIcon(QIcon(":/icons/demo.png"));
        else if (dev_inst->name().contains("virtual"))
            _device_type.setIcon(QIcon(":/icons/data.png"));
        else {
207
            int usb_speed = LIBUSB_SPEED_HIGH;
208 209 210 211 212 213 214 215 216 217 218 219
            GVariant *gvar = dev_inst->get_config(NULL, NULL, SR_CONF_USB_SPEED);
            if (gvar != NULL) {
                usb_speed = g_variant_get_int32(gvar);
                g_variant_unref(gvar);
            }
            if (usb_speed == LIBUSB_SPEED_SUPER)
                _device_type.setIcon(QIcon(":/icons/usb3.png"));
            else
                _device_type.setIcon(QIcon(":/icons/usb2.png"));

        }
    }
Andy Dneg's avatar
Andy Dneg committed
220 221 222 223 224 225 226 227
    _configure_button.setIcon(QIcon(iconPath+"/params.png"));
    _mode_button.setIcon(_session.get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.png") :
                                                                             QIcon(iconPath+"/moder.png"));
    _run_stop_button.setIcon(_sampling ? QIcon(iconPath+"/stop.png") :
                                         QIcon(iconPath+"/start.png"));
    _instant_button.setIcon(QIcon(iconPath+"/instant.png"));
    _action_single->setIcon(QIcon(iconPath+"/oneloop.png"));
    _action_repeat->setIcon(QIcon(iconPath+"/repeat.png"));
DreamSourceLab's avatar
DreamSourceLab committed
228 229
}

DreamSourceLab's avatar
DreamSourceLab committed
230 231 232
void SamplingBar::set_device_list(
    const std::list< shared_ptr<pv::device::DevInst> > &devices,
    shared_ptr<pv::device::DevInst> selected)
DreamSourceLab's avatar
DreamSourceLab committed
233
{
DreamSourceLab's avatar
DreamSourceLab committed
234 235 236 237 238 239 240 241 242 243 244
    int selected_index = -1;

    assert(selected);

    _updating_device_selector = true;

    _device_selector.clear();
    _device_selector_map.clear();

    BOOST_FOREACH (shared_ptr<pv::device::DevInst> dev_inst, devices) {
        assert(dev_inst);
245
        const QString title = dev_inst->format_device_title();
DreamSourceLab's avatar
DreamSourceLab committed
246 247 248 249 250 251 252
        const void *id = dev_inst->get_id();
        assert(id);

        if (selected == dev_inst)
            selected_index = _device_selector.count();

        _device_selector_map[id] = dev_inst;
253
        _device_selector.addItem(title,
DreamSourceLab's avatar
DreamSourceLab committed
254
            qVariantFromValue((void*)id));
DreamSourceLab's avatar
DreamSourceLab committed
255
    }
256 257 258
    int width = _device_selector.sizeHint().width();
    _device_selector.setFixedWidth(min(width+15, _device_selector.maximumWidth()));
    _device_selector.view()->setMinimumWidth(width+30);
DreamSourceLab's avatar
DreamSourceLab committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288

    // The selected device should have been in the list
    assert(selected_index != -1);
    _device_selector.setCurrentIndex(selected_index);

    update_sample_rate_selector();

    _updating_device_selector = false;
}

shared_ptr<pv::device::DevInst> SamplingBar::get_selected_device() const
{
    const int index = _device_selector.currentIndex();
    if (index < 0)
        return shared_ptr<pv::device::DevInst>();

    const void *const id =
        _device_selector.itemData(index).value<void*>();
    assert(id);

    map<const void*, boost::weak_ptr<device::DevInst> >::
        const_iterator iter = _device_selector_map.find(id);
    if (iter == _device_selector_map.end())
        return shared_ptr<pv::device::DevInst>();

    return shared_ptr<pv::device::DevInst>((*iter).second);
}

void SamplingBar::on_configure()
{
289 290
    hide_calibration();

DreamSourceLab's avatar
DreamSourceLab committed
291 292 293 294
    int  ret;
    shared_ptr<pv::device::DevInst> dev_inst = get_selected_device();
    assert(dev_inst);

DreamSourceLab's avatar
DreamSourceLab committed
295
    pv::dialogs::DeviceOptions dlg(this, dev_inst);
DreamSourceLab's avatar
DreamSourceLab committed
296
    ret = dlg.exec();
DreamSourceLab's avatar
DreamSourceLab committed
297
    if (ret == QDialog::Accepted) {
DreamSourceLab's avatar
DreamSourceLab committed
298
        device_updated();
DreamSourceLab's avatar
DreamSourceLab committed
299
        update_sample_rate_selector();
DreamSourceLab's avatar
DreamSourceLab committed
300

301 302 303 304 305 306
        GVariant* gvar;
        if (dev_inst->dev_inst()->mode == DSO) {
            gvar = dev_inst->get_config(NULL, NULL, SR_CONF_ZERO);
            if (gvar != NULL) {
                bool zero = g_variant_get_boolean(gvar);
                g_variant_unref(gvar);
307
                if (zero) {
308
                    zero_adj();
309 310
                    return;
                }
311 312 313 314 315 316 317 318
            }

            gvar = dev_inst->get_config(NULL, NULL, SR_CONF_CALI);
            if (gvar != NULL) {
                bool cali = g_variant_get_boolean(gvar);
                g_variant_unref(gvar);
                if (cali) {
                    show_calibration();
319
                    return;
320 321 322
                }
            }
        }
323 324 325 326 327 328 329 330
        gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST);
        if (gvar != NULL) {
            bool test = g_variant_get_boolean(gvar);
            g_variant_unref(gvar);
            if (test) {
                update_sample_rate_selector_value();
                _sample_count.setDisabled(true);
                _sample_rate.setDisabled(true);
331
            } else {
332
                _sample_count.setDisabled(false);
333 334
                if (dev_inst->dev_inst()->mode != DSO)
                    _sample_rate.setDisabled(false);
335
            }
DreamSourceLab's avatar
DreamSourceLab committed
336 337 338 339 340 341 342 343 344
        }
    }
}

void SamplingBar::zero_adj()
{
    boost::shared_ptr<view::DsoSignal> dsoSig;
    BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals())
    {
345
        if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)))
DreamSourceLab's avatar
DreamSourceLab committed
346 347
            dsoSig->set_enable(true);
    }
Andy Dneg's avatar
Andy Dneg committed
348 349 350 351 352 353 354 355
    const int index_back = _sample_count.currentIndex();
    int i = 0;
    for (i = 0; i < _sample_count.count(); i++)
        if (_sample_count.itemData(i).value<uint64_t>() == ZeroTimeBase)
            break;
    _sample_count.setCurrentIndex(i);
    commit_hori_res();

DreamSourceLab's avatar
DreamSourceLab committed
356 357
    run_stop();

DreamSourceLab's avatar
DreamSourceLab committed
358 359
    pv::dialogs::WaitingDialog wait(this, _session, SR_CONF_ZERO);
    if (wait.start() == QDialog::Rejected) {
360 361
        BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals())
        {
362
            if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)))
363 364 365
                dsoSig->commit_settings();
        }
    }
DreamSourceLab's avatar
DreamSourceLab committed
366

367
    if (_session.get_capture_state() == pv::SigSession::Running)
368
        on_run_stop();
Andy Dneg's avatar
Andy Dneg committed
369 370 371

    _sample_count.setCurrentIndex(index_back);
    commit_hori_res();
DreamSourceLab's avatar
DreamSourceLab committed
372 373
}

374 375 376 377 378 379 380 381 382 383
bool SamplingBar::get_sampling() const
{
    return _sampling;
}

bool SamplingBar::get_instant() const
{
    return _instant;
}

DreamSourceLab's avatar
DreamSourceLab committed
384 385
void SamplingBar::set_sampling(bool sampling)
{
386 387
    lock_guard<boost::recursive_mutex> lock(_sampling_mutex);
    _sampling = sampling;
Andy Dneg's avatar
Andy Dneg committed
388 389
    QString iconPath = ":/icons/" + qApp->property("Style").toString();

390
    if (_instant) {
Andy Dneg's avatar
Andy Dneg committed
391
        _instant_button.setIcon(sampling ? QIcon(iconPath+"/stop.png") : QIcon(iconPath+"/instant.png"));
392
    } else {
Andy Dneg's avatar
Andy Dneg committed
393
        _run_stop_button.setIcon(sampling ? QIcon(iconPath+"/stop.png") : QIcon(iconPath+"/start.png"));
394
    }
DreamSourceLab's avatar
DreamSourceLab committed
395 396

    if (!sampling) {
397 398
        enable_run_stop(true);
        enable_instant(true);
DreamSourceLab's avatar
DreamSourceLab committed
399 400
    } else {
        if (_instant)
401
            enable_instant(true);
DreamSourceLab's avatar
DreamSourceLab committed
402
        else
403
            enable_run_stop(true);
DreamSourceLab's avatar
DreamSourceLab committed
404
    }
DreamSourceLab's avatar
DreamSourceLab committed
405

406
    _mode_button.setEnabled(!sampling);
Andy Dneg's avatar
Andy Dneg committed
407 408
    _mode_button.setIcon(_session.get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.png") :
                                                                             QIcon(iconPath+"/moder.png"));
DreamSourceLab's avatar
DreamSourceLab committed
409
    _configure_button.setEnabled(!sampling);
Andy Dneg's avatar
Andy Dneg committed
410 411 412
    _device_selector.setEnabled(!sampling);

    retranslateUi();
DreamSourceLab's avatar
DreamSourceLab committed
413 414
}

DreamSourceLab's avatar
v0.3  
DreamSourceLab committed
415 416
void SamplingBar::set_sample_rate(uint64_t sample_rate)
{
DreamSourceLab's avatar
DreamSourceLab committed
417 418 419 420 421 422 423 424
    for (int i = _sample_rate.count() - 1; i >= 0; i--) {
        uint64_t cur_index_sample_rate = _sample_rate.itemData(
                    i).value<uint64_t>();
        if (sample_rate >= cur_index_sample_rate) {
            _sample_rate.setCurrentIndex(i);
            break;
        }
    }
425
    commit_settings();
DreamSourceLab's avatar
v0.3  
DreamSourceLab committed
426 427
}

DreamSourceLab's avatar
DreamSourceLab committed
428 429 430 431 432 433
void SamplingBar::update_sample_rate_selector()
{
	GVariant *gvar_dict, *gvar_list;
	const uint64_t *elements = NULL;
	gsize num_elements;

DreamSourceLab's avatar
DreamSourceLab committed
434 435
    if (_updating_sample_rate)
        return;
DreamSourceLab's avatar
DreamSourceLab committed
436

DreamSourceLab's avatar
DreamSourceLab committed
437 438
    disconnect(&_sample_rate, SIGNAL(currentIndexChanged(int)),
        this, SLOT(on_samplerate_sel(int)));
DreamSourceLab's avatar
DreamSourceLab committed
439 440 441
    const shared_ptr<device::DevInst> dev_inst = get_selected_device();
    if (!dev_inst)
        return;
DreamSourceLab's avatar
DreamSourceLab committed
442

DreamSourceLab's avatar
DreamSourceLab committed
443 444
    assert(!_updating_sample_rate);
    _updating_sample_rate = true;
DreamSourceLab's avatar
DreamSourceLab committed
445

DreamSourceLab's avatar
DreamSourceLab committed
446 447 448 449 450 451 452
    if (!(gvar_dict = dev_inst->list_config(NULL, SR_CONF_SAMPLERATE)))
    {
        _sample_rate.clear();
        _sample_rate.show();
        _updating_sample_rate = false;
        return;
    }
DreamSourceLab's avatar
DreamSourceLab committed
453 454 455 456 457 458

    if ((gvar_list = g_variant_lookup_value(gvar_dict,
			"samplerates", G_VARIANT_TYPE("at"))))
	{
		elements = (const uint64_t *)g_variant_get_fixed_array(
				gvar_list, &num_elements, sizeof(uint64_t));
DreamSourceLab's avatar
DreamSourceLab committed
459
        _sample_rate.clear();
DreamSourceLab's avatar
DreamSourceLab committed
460 461 462 463

		for (unsigned int i = 0; i < num_elements; i++)
		{
			char *const s = sr_samplerate_string(elements[i]);
DreamSourceLab's avatar
DreamSourceLab committed
464
            _sample_rate.addItem(QString(s),
DreamSourceLab's avatar
DreamSourceLab committed
465 466 467 468
				qVariantFromValue(elements[i]));
			g_free(s);
		}

DreamSourceLab's avatar
DreamSourceLab committed
469
        _sample_rate.show();
DreamSourceLab's avatar
DreamSourceLab committed
470 471
		g_variant_unref(gvar_list);
	}
472 473 474 475

    _sample_rate.setMinimumWidth(_sample_rate.sizeHint().width()+15);
    _sample_rate.view()->setMinimumWidth(_sample_rate.sizeHint().width()+30);

DreamSourceLab's avatar
DreamSourceLab committed
476
    _updating_sample_rate = false;
DreamSourceLab's avatar
DreamSourceLab committed
477
	g_variant_unref(gvar_dict);
DreamSourceLab's avatar
DreamSourceLab committed
478

DreamSourceLab's avatar
DreamSourceLab committed
479
    update_sample_rate_selector_value();
DreamSourceLab's avatar
DreamSourceLab committed
480 481
    connect(&_sample_rate, SIGNAL(currentIndexChanged(int)),
        this, SLOT(on_samplerate_sel(int)));
482 483

    update_sample_count_selector();
DreamSourceLab's avatar
DreamSourceLab committed
484 485 486 487
}

void SamplingBar::update_sample_rate_selector_value()
{
DreamSourceLab's avatar
DreamSourceLab committed
488 489
    if (_updating_sample_rate)
        return;
DreamSourceLab's avatar
DreamSourceLab committed
490

DreamSourceLab's avatar
DreamSourceLab committed
491
    const uint64_t samplerate = get_selected_device()->get_sample_rate();
DreamSourceLab's avatar
DreamSourceLab committed
492

DreamSourceLab's avatar
DreamSourceLab committed
493 494
    assert(!_updating_sample_rate);
    _updating_sample_rate = true;
DreamSourceLab's avatar
DreamSourceLab committed
495

496 497 498 499 500 501 502 503
    if (samplerate != _sample_rate.itemData(
                _sample_rate.currentIndex()).value<uint64_t>()) {
        for (int i = _sample_rate.count() - 1; i >= 0; i--) {
            if (samplerate >= _sample_rate.itemData(
                i).value<uint64_t>()) {
                _sample_rate.setCurrentIndex(i);
                break;
            }
DreamSourceLab's avatar
DreamSourceLab committed
504 505
        }
    }
506

DreamSourceLab's avatar
DreamSourceLab committed
507
    _updating_sample_rate = false;
DreamSourceLab's avatar
DreamSourceLab committed
508 509
}

DreamSourceLab's avatar
DreamSourceLab committed
510 511
void SamplingBar::on_samplerate_sel(int index)
{
512 513 514 515
    (void)index;
    const shared_ptr<device::DevInst> dev_inst = get_selected_device();
    if (dev_inst->dev_inst()->mode != DSO)
        update_sample_count_selector();
DreamSourceLab's avatar
DreamSourceLab committed
516 517
}

DreamSourceLab's avatar
DreamSourceLab committed
518
void SamplingBar::update_sample_count_selector()
DreamSourceLab's avatar
DreamSourceLab committed
519
{
520
    bool stream_mode = false;
DreamSourceLab's avatar
DreamSourceLab committed
521
    uint64_t hw_depth = 0;
522
    uint64_t sw_depth;
523
    uint64_t rle_depth = 0;
524
    uint64_t max_timebase = 0;
525
    uint64_t min_timebase = SR_NS(10);
526 527
    double pre_duration = SR_SEC(1);
    double duration;
528
    bool rle_support = false;
DreamSourceLab's avatar
DreamSourceLab committed
529 530 531 532

    if (_updating_sample_count)
        return;

DreamSourceLab's avatar
DreamSourceLab committed
533 534 535
    disconnect(&_sample_count, SIGNAL(currentIndexChanged(int)),
        this, SLOT(on_samplecount_sel(int)));

DreamSourceLab's avatar
DreamSourceLab committed
536 537 538
    assert(!_updating_sample_count);
    _updating_sample_count = true;

539
    const shared_ptr<device::DevInst> dev_inst = get_selected_device();
540 541 542 543 544
    GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_STREAM);
    if (gvar != NULL) {
        stream_mode = g_variant_get_boolean(gvar);
        g_variant_unref(gvar);
    }
545
    gvar = dev_inst->get_config(NULL, NULL, SR_CONF_HW_DEPTH);
546
    if (gvar != NULL) {
547
        hw_depth = g_variant_get_uint64(gvar);
548 549 550
        g_variant_unref(gvar);
    }

551
    if (dev_inst->dev_inst()->mode == LOGIC) {
552
        #if defined(__x86_64__) || defined(_M_X64)
553
            sw_depth = LogicMaxSWDepth64;
554 555 556
        #elif defined(__i386) || defined(_M_IX86)
            int ch_num = _session.get_ch_num(SR_CHANNEL_LOGIC);
            if (ch_num <= 0)
557
                sw_depth = LogicMaxSWDepth32;
558
            else
559
                sw_depth = LogicMaxSWDepth32 / ch_num;
560
        #endif
561 562 563
    } else {
        sw_depth = AnalogMaxSWDepth;
    }
564

565 566 567 568 569 570 571 572
    if (dev_inst->dev_inst()->mode == LOGIC)  {
        gvar = dev_inst->get_config(NULL, NULL, SR_CONF_RLE_SUPPORT);
        if (gvar != NULL) {
            rle_support = g_variant_get_boolean(gvar);
            g_variant_unref(gvar);
        }
        if (rle_support)
            rle_depth = min(hw_depth*SR_KB(1), sw_depth);
573 574 575 576 577 578
    } else if (dev_inst->dev_inst()->mode == DSO) {
        gvar = dev_inst->get_config(NULL, NULL, SR_CONF_MAX_TIMEBASE);
        if (gvar != NULL) {
            max_timebase = g_variant_get_uint64(gvar);
            g_variant_unref(gvar);
        }
579 580 581 582 583
        gvar = dev_inst->get_config(NULL, NULL, SR_CONF_MIN_TIMEBASE);
        if (gvar != NULL) {
            min_timebase = g_variant_get_uint64(gvar);
            g_variant_unref(gvar);
        }
584 585
    }

586 587 588 589 590 591
    if (0 != _sample_count.count())
        pre_duration = _sample_count.itemData(
                    _sample_count.currentIndex()).value<double>();
    _sample_count.clear();
    const uint64_t samplerate = _sample_rate.itemData(
                _sample_rate.currentIndex()).value<uint64_t>();
592
    const double hw_duration = hw_depth / (samplerate * (1.0 / SR_SEC(1)));
593
    if (dev_inst->dev_inst()->mode == DSO)
594
        duration = max_timebase;
595 596
    else if (stream_mode)
        duration = sw_depth / (samplerate * (1.0 / SR_SEC(1)));
597 598
    else if (rle_support)
        duration = rle_depth / (samplerate * (1.0 / SR_SEC(1)));
599
    else
600
        duration = hw_duration;
601

602
    assert(duration > 0);
603 604
    bool not_last = true;
    do {
605
        QString suffix = (dev_inst->dev_inst()->mode == DSO) ? DIVString :
606
                         (!stream_mode && duration > hw_duration) ? RLEString : "";
607
        char *const s = sr_time_string(duration);
608
        _sample_count.addItem(QString(s) + suffix,
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
            qVariantFromValue(duration));
        g_free(s);

        double unit;
        if (duration >= SR_DAY(1))
            unit = SR_DAY(1);
        else if (duration >= SR_HOUR(1))
            unit = SR_HOUR(1);
        else if (duration >= SR_MIN(1))
            unit = SR_MIN(1);
        else
            unit = 1;
        const double log10_duration = pow(10,
                                          floor(log10(duration / unit)));
        if (duration > 5 * log10_duration * unit)
            duration = 5 * log10_duration * unit;
        else if (duration > 2 * log10_duration * unit)
            duration = 2 * log10_duration * unit;
        else if (duration > log10_duration * unit)
            duration = log10_duration * unit;
        else
            duration = log10_duration > 1 ? duration * 0.5 :
                       (unit == SR_DAY(1) ? SR_HOUR(20) :
                        unit == SR_HOUR(1) ? SR_MIN(50) :
                        unit == SR_MIN(1) ? SR_SEC(50) : duration * 0.5);
DreamSourceLab's avatar
DreamSourceLab committed
634

635
        if (dev_inst->dev_inst()->mode == DSO)
636
            not_last = duration >= min_timebase;
637 638 639
        else if (dev_inst->dev_inst()->mode == ANALOG)
            not_last = (duration >= SR_MS(100)) &&
                       (duration / SR_SEC(1) * samplerate >= SR_KB(1));
640 641 642
        else
            not_last = (duration / SR_SEC(1) * samplerate >= SR_KB(1));
    } while(not_last);
DreamSourceLab's avatar
DreamSourceLab committed
643

644 645 646 647 648 649 650 651 652 653 654 655 656
    _updating_sample_count = true;
    if (pre_duration > _sample_count.itemData(0).value<double>())
        _sample_count.setCurrentIndex(0);
    else if (pre_duration < _sample_count.itemData(_sample_count.count()-1).value<double>())
        _sample_count.setCurrentIndex(_sample_count.count()-1);
    else {
        for (int i = 0; i < _sample_count.count(); i++)
            if (pre_duration >= _sample_count.itemData(
                i).value<double>()) {
                _sample_count.setCurrentIndex(i);
                break;
            }
    }
DreamSourceLab's avatar
DreamSourceLab committed
657
    _updating_sample_count = false;
DreamSourceLab's avatar
DreamSourceLab committed
658

DreamSourceLab's avatar
DreamSourceLab committed
659
    update_sample_count_selector_value();
660
    on_samplecount_sel(_sample_count.currentIndex());
DreamSourceLab's avatar
DreamSourceLab committed
661 662
    connect(&_sample_count, SIGNAL(currentIndexChanged(int)),
        this, SLOT(on_samplecount_sel(int)));
DreamSourceLab's avatar
DreamSourceLab committed
663 664 665 666 667 668 669
}

void SamplingBar::update_sample_count_selector_value()
{
    if (_updating_sample_count)
        return;

670
    GVariant* gvar;
DreamSourceLab's avatar
DreamSourceLab committed
671 672 673 674 675 676 677 678 679 680 681
    double duration;
    const shared_ptr<device::DevInst> dev_inst = get_selected_device();
    if (dev_inst->dev_inst()->mode == DSO) {
        gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TIMEBASE);
        if (gvar != NULL) {
            duration = g_variant_get_uint64(gvar);
            g_variant_unref(gvar);
        } else {
            qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed.";
            return;
        }
682
    } else {
DreamSourceLab's avatar
DreamSourceLab committed
683 684 685 686 687 688 689 690 691 692
        gvar = dev_inst->get_config(NULL, NULL, SR_CONF_LIMIT_SAMPLES);
        if (gvar != NULL) {
            duration = g_variant_get_uint64(gvar);
            g_variant_unref(gvar);
        } else {
            qDebug() << "ERROR: config_get SR_CONF_TIMEBASE failed.";
            return;
        }
        const uint64_t samplerate = dev_inst->get_sample_rate();
        duration = duration / samplerate * SR_SEC(1);
693
    }
DreamSourceLab's avatar
DreamSourceLab committed
694 695 696
    assert(!_updating_sample_count);
    _updating_sample_count = true;

DreamSourceLab's avatar
DreamSourceLab committed
697
    if (duration != _sample_count.itemData(
698
                _sample_count.currentIndex()).value<double>()) {
DreamSourceLab's avatar
DreamSourceLab committed
699 700
        for (int i = 0; i < _sample_count.count(); i++) {
            if (duration >= _sample_count.itemData(
701 702 703 704 705
                i).value<double>()) {
                _sample_count.setCurrentIndex(i);
                break;
            }
        }
706
    }
707

DreamSourceLab's avatar
DreamSourceLab committed
708 709 710
    _updating_sample_count = false;
}

711
void SamplingBar::on_samplecount_sel(int index)
DreamSourceLab's avatar
DreamSourceLab committed
712
{
713
    (void)index;
DreamSourceLab's avatar
DreamSourceLab committed
714

715 716 717
    const shared_ptr<device::DevInst> dev_inst = get_selected_device();
    if (dev_inst->dev_inst()->mode == DSO)
        commit_hori_res();
718
    duration_changed();
719
}
DreamSourceLab's avatar
DreamSourceLab committed
720

721 722 723 724 725
double SamplingBar::get_hori_res()
{
    return _sample_count.itemData(_sample_count.currentIndex()).value<double>();
}

726
double SamplingBar::hori_knob(int dir)
727
{
728
    double hori_res = -1;
729 730 731
    disconnect(&_sample_count, SIGNAL(currentIndexChanged(int)),
        this, SLOT(on_samplecount_sel(int)));

732
    if (0 == dir) {
733
        hori_res = commit_hori_res();
734 735
    } else if ((dir > 0) && (_sample_count.currentIndex() > 0)) {
        _sample_count.setCurrentIndex(_sample_count.currentIndex() - 1);
736
        hori_res = commit_hori_res();
737 738
    } else if ((dir < 0) && (_sample_count.currentIndex() < _sample_count.count() - 1)) {
        _sample_count.setCurrentIndex(_sample_count.currentIndex() + 1);
739
        hori_res = commit_hori_res();
740
    }
741 742 743 744

    connect(&_sample_count, SIGNAL(currentIndexChanged(int)),
        this, SLOT(on_samplecount_sel(int)));

745
    return hori_res;
746
}
DreamSourceLab's avatar
DreamSourceLab committed
747

748
double SamplingBar::commit_hori_res()
749 750 751
{
    const double hori_res = _sample_count.itemData(
                           _sample_count.currentIndex()).value<double>();
DreamSourceLab's avatar
DreamSourceLab committed
752

753 754 755 756 757 758 759 760 761 762
    const shared_ptr<device::DevInst> dev_inst = get_selected_device();
    const uint64_t sample_limit = dev_inst->get_sample_limit();
    GVariant* gvar;
    uint64_t max_sample_rate;
    gvar = dev_inst->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLERATE);
    if (gvar != NULL) {
        max_sample_rate = g_variant_get_uint64(gvar);
        g_variant_unref(gvar);
    } else {
        qDebug() << "ERROR: config_get SR_CONF_MAX_DSO_SAMPLERATE failed.";
763
        return -1;
764
    }
DreamSourceLab's avatar
DreamSourceLab committed
765

766 767 768
    const uint64_t sample_rate = min((uint64_t)(sample_limit * SR_SEC(1) /
                                                (hori_res * DS_CONF_DSO_HDIVS)),
                                     (uint64_t)(max_sample_rate /
769
                                                (_session.get_ch_num(SR_CHANNEL_DSO) ? _session.get_ch_num(SR_CHANNEL_DSO) : 1)));
770
    set_sample_rate(sample_rate);
DreamSourceLab's avatar
DreamSourceLab committed
771

772 773
    dev_inst->set_config(NULL, NULL, SR_CONF_TIMEBASE,
                         g_variant_new_uint64(hori_res));
DreamSourceLab's avatar
DreamSourceLab committed
774

775
    return hori_res;
776
}
777

778 779
void SamplingBar::commit_settings()
{
Andy Dneg's avatar
Andy Dneg committed
780
    bool test = false;
781
    const shared_ptr<device::DevInst> dev_inst = get_selected_device();
Andy Dneg's avatar
Andy Dneg committed
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
    if (dev_inst && dev_inst->owner()) {
        GVariant *gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST);
        if (gvar != NULL) {
            test = g_variant_get_boolean(gvar);
            g_variant_unref(gvar);
        }
    }

    if (test) {
        update_sample_rate_selector_value();
        update_sample_count_selector_value();
    } else {
        const double sample_duration = _sample_count.itemData(
                _sample_count.currentIndex()).value<double>();
        const uint64_t sample_rate = _sample_rate.itemData(
                _sample_rate.currentIndex()).value<uint64_t>();
798

Andy Dneg's avatar
Andy Dneg committed
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
        const shared_ptr<device::DevInst> dev_inst = get_selected_device();
        if (dev_inst) {
            if (sample_rate != dev_inst->get_sample_rate())
                dev_inst->set_config(NULL, NULL,
                                     SR_CONF_SAMPLERATE,
                                     g_variant_new_uint64(sample_rate));
            if (dev_inst->dev_inst()->mode != DSO) {
                const uint64_t sample_count = ((uint64_t)ceil(sample_duration / SR_SEC(1) *
                                                    sample_rate) + 1023ULL) & ~1023ULL;
                if (sample_count != dev_inst->get_sample_limit())
                    dev_inst->set_config(NULL, NULL,
                                         SR_CONF_LIMIT_SAMPLES,
                                         g_variant_new_uint64(sample_count));

                bool rle_mode = _sample_count.currentText().contains(RLEString);
                dev_inst->set_config(NULL, NULL,
                                     SR_CONF_RLE,
                                     g_variant_new_boolean(rle_mode));
            }
818 819
        }
    }
DreamSourceLab's avatar
DreamSourceLab committed
820 821 822 823
}

void SamplingBar::on_run_stop()
{
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
    if (get_sampling() || _session.isRepeating()) {
        _session.set_repeating(false);
        bool wait_upload = false;
        if (_session.get_run_mode() != SigSession::Repetitive) {
            GVariant *gvar = get_selected_device()->get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD);
            if (gvar != NULL) {
                wait_upload = g_variant_get_boolean(gvar);
                g_variant_unref(gvar);
            }
        }
        if (!wait_upload) {
            _session.stop_capture();
            _session.capture_state_changed(SigSession::Stopped);
        }
    } else {
        enable_run_stop(false);
        enable_instant(false);
841
        commit_settings();
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
        _instant = false;
        const shared_ptr<device::DevInst> dev_inst = get_selected_device();
        if (!dev_inst)
            return;
        if (dev_inst->dev_inst()->mode == DSO) {
            GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_ZERO);
            if (gvar != NULL) {
                bool zero = g_variant_get_boolean(gvar);
                g_variant_unref(gvar);
                if (zero) {
                    dialogs::DSMessageBox msg(this);
                    msg.mBox()->setText(tr("Auto Calibration"));
                    msg.mBox()->setInformativeText(tr("Please adjust zero skew and save the result!"));
                    //msg.setStandardButtons(QMessageBox::Ok);
                    msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole);
                    msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole);
                    msg.mBox()->setIcon(QMessageBox::Warning);
                    if (msg.exec()) {
                        zero_adj();
                    } else {
                        dev_inst->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false));
                        enable_run_stop(true);
                        enable_instant(true);
                    }
                    return;
867
                }
868
            }
DreamSourceLab's avatar
DreamSourceLab committed
869
        }
870
        run_stop();
DreamSourceLab's avatar
DreamSourceLab committed
871
    }
DreamSourceLab's avatar
DreamSourceLab committed
872 873
}

DreamSourceLab's avatar
DreamSourceLab committed
874 875
void SamplingBar::on_instant_stop()
{
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
    if (get_sampling()) {
        _session.set_repeating(false);
        bool wait_upload = false;
        if (_session.get_run_mode() != SigSession::Repetitive) {
            GVariant *gvar = get_selected_device()->get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD);
            if (gvar != NULL) {
                wait_upload = g_variant_get_boolean(gvar);
                g_variant_unref(gvar);
            }
        }
        if (!wait_upload) {
            _session.stop_capture();
            _session.capture_state_changed(SigSession::Stopped);
        }
    } else {
        enable_run_stop(false);
        enable_instant(false);
893
        commit_settings();
894 895 896 897 898 899 900 901 902 903 904 905
        _instant = true;
        const shared_ptr<device::DevInst> dev_inst = get_selected_device();
        if (!dev_inst)
            return;
        if (dev_inst->dev_inst()->mode == DSO) {
            GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_ZERO);
            if (gvar != NULL) {
                bool zero = g_variant_get_boolean(gvar);
                g_variant_unref(gvar);
                if (zero) {
                    dialogs::DSMessageBox msg(this);
                    msg.mBox()->setText(tr("Auto Calibration"));
DreamSourceLab's avatar
DreamSourceLab committed
906
                    msg.mBox()->setInformativeText(tr("Auto Calibration program will be started. Don't connect any probes. It can take a while!"));
907 908 909 910 911 912 913 914 915 916 917 918
                    //msg.mBox()->setStandardButtons(QMessageBox::Ok);
                    msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole);
                    msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole);
                    msg.mBox()->setIcon(QMessageBox::Warning);
                    if (msg.exec()) {
                        zero_adj();
                    } else {
                        dev_inst->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false));
                        enable_run_stop(true);
                        enable_instant(true);
                    }
                    return;
919
                }
920
            }
DreamSourceLab's avatar
DreamSourceLab committed
921
        }
922
        instant_stop();
DreamSourceLab's avatar
DreamSourceLab committed
923
    }
DreamSourceLab's avatar
DreamSourceLab committed
924 925 926 927 928 929 930
}

void SamplingBar::on_device_selected()
{
    if (_updating_device_selector)
        return;

931
    _session.stop_capture();
Andy Dneg's avatar
Andy Dneg committed
932
    _session.session_save();
933

DreamSourceLab's avatar
DreamSourceLab committed
934 935 936 937
    const shared_ptr<device::DevInst> dev_inst = get_selected_device();
    if (!dev_inst)
        return;

DreamSourceLab's avatar
DreamSourceLab committed
938 939 940
    try {
        _session.set_device(dev_inst);
    } catch(QString e) {
941
        show_session_error(tr("Failed to select ") + dev_inst->dev_inst()->model, e);
DreamSourceLab's avatar
DreamSourceLab committed
942
    }
DreamSourceLab's avatar
DreamSourceLab committed
943 944 945
    device_selected();
}

DreamSourceLab's avatar
DreamSourceLab committed
946 947
void SamplingBar::enable_toggle(bool enable)
{
DreamSourceLab's avatar
DreamSourceLab committed
948 949 950 951 952 953 954 955 956 957 958
    bool test = false;
    const shared_ptr<device::DevInst> dev_inst = get_selected_device();
    if (dev_inst && dev_inst->owner()) {
        GVariant *gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST);
        if (gvar != NULL) {
            test = g_variant_get_boolean(gvar);
            g_variant_unref(gvar);
        }
    }
    if (!test) {
        _sample_count.setDisabled(!enable);
959 960 961 962
        if (dev_inst->dev_inst()->mode == DSO)
            _sample_rate.setDisabled(true);
        else
            _sample_rate.setDisabled(!enable);
963 964 965
    } else {
        _sample_count.setDisabled(true);
        _sample_rate.setDisabled(true);
DreamSourceLab's avatar
DreamSourceLab committed
966
    }
967 968 969 970 971

    if (_session.get_device()->name() == "virtual-session") {
        _sample_count.setDisabled(true);
        _sample_rate.setDisabled(true);
    }
DreamSourceLab's avatar
DreamSourceLab committed
972 973 974 975 976 977 978
}

void SamplingBar::enable_run_stop(bool enable)
{
    _run_stop_button.setDisabled(!enable);
}

DreamSourceLab's avatar
DreamSourceLab committed
979 980 981 982 983
void SamplingBar::enable_instant(bool enable)
{
    _instant_button.setDisabled(!enable);
}

DreamSourceLab's avatar
DreamSourceLab committed
984 985 986
void SamplingBar::show_session_error(
    const QString text, const QString info_text)
{
987 988 989 990 991
    dialogs::DSMessageBox msg(this);
    msg.mBox()->setText(text);
    msg.mBox()->setInformativeText(info_text);
    msg.mBox()->setStandardButtons(QMessageBox::Ok);
    msg.mBox()->setIcon(QMessageBox::Warning);
DreamSourceLab's avatar
DreamSourceLab committed
992 993 994
    msg.exec();
}

DreamSourceLab's avatar
DreamSourceLab committed
995 996
void SamplingBar::reload()
{
Andy Dneg's avatar
Andy Dneg committed
997
    QString iconPath = ":/icons/" + qApp->property("Style").toString();
DreamSourceLab's avatar
DreamSourceLab committed
998
    if (_session.get_device()->dev_inst()->mode == LOGIC) {
999 1000 1001
        if (_session.get_device()->name() == "virtual-session") {
            _mode_action->setVisible(false);
        } else {
Andy Dneg's avatar
Andy Dneg committed
1002 1003
            _mode_button.setIcon(_session.get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.png") :
                                                                                     QIcon(iconPath+"/moder.png"));
1004 1005
            _mode_action->setVisible(true);
        }
DreamSourceLab's avatar
DreamSourceLab committed
1006 1007 1008 1009
        _run_stop_action->setVisible(true);
        _instant_action->setVisible(true);
        enable_toggle(true);
    } else if (_session.get_device()->dev_inst()->mode == ANALOG) {
1010
        _mode_action->setVisible(false);
DreamSourceLab's avatar
DreamSourceLab committed
1011 1012 1013 1014
        _run_stop_action->setVisible(true);
        _instant_action->setVisible(false);
        enable_toggle(true);
    } else if (_session.get_device()->dev_inst()->mode == DSO) {
1015
        _mode_action->setVisible(false);
DreamSourceLab's avatar
DreamSourceLab committed
1016 1017
        _run_stop_action->setVisible(true);
        _instant_action->setVisible(true);
1018
        enable_toggle(true);
DreamSourceLab's avatar
DreamSourceLab committed
1019
    }
1020

Andy Dneg's avatar
Andy Dneg committed
1021
    retranslateUi();
1022
    reStyle();
DreamSourceLab's avatar
DreamSourceLab committed
1023 1024 1025
    update();
}

1026 1027
void SamplingBar::on_mode()
{
Andy Dneg's avatar
Andy Dneg committed
1028
    QString iconPath = ":/icons/" + qApp->property("Style").toString();
1029 1030
    QAction *act = qobject_cast<QAction *>(sender());
    if (act == _action_single) {
Andy Dneg's avatar
Andy Dneg committed
1031
        _mode_button.setIcon(QIcon(iconPath+"/modes.png"));
1032 1033
        _session.set_run_mode(pv::SigSession::Single);
    } else if (act == _action_repeat) {
Andy Dneg's avatar
Andy Dneg committed
1034
        _mode_button.setIcon(QIcon(iconPath+"/moder.png"));
1035 1036 1037 1038 1039 1040
        pv::dialogs::Interval interval_dlg(_session, this);
        interval_dlg.exec();
        _session.set_run_mode(pv::SigSession::Repetitive);
    }
}

DreamSourceLab's avatar
DreamSourceLab committed
1041 1042
} // namespace toolbars
} // namespace pv