forked from Ivasoft/DSView
v0.4 release
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <QApplication>
|
||||
|
||||
#include "filebar.h"
|
||||
#include "../device/devinst.h"
|
||||
|
||||
#include <deque>
|
||||
|
||||
@@ -80,23 +81,14 @@ FileBar::FileBar(SigSession &session, QWidget *parent) :
|
||||
|
||||
void FileBar::on_actionOpen_triggered()
|
||||
{
|
||||
// Show the dialog
|
||||
const QString file_name = QFileDialog::getOpenFileName(
|
||||
this, tr("Open File"), "",
|
||||
tr("DSLogic Sessions (*.dsl)"));
|
||||
this, tr("Open File"), "", tr(
|
||||
"DSLogic Sessions (*.dsl)"));
|
||||
if (!file_name.isEmpty())
|
||||
load_file(file_name);
|
||||
}
|
||||
|
||||
void FileBar::load_file(QString file_name)
|
||||
{
|
||||
const QString errorMessage(
|
||||
QString("Failed to load file %1").arg(file_name));
|
||||
const QString infoMessage;
|
||||
_session.load_file(file_name.toStdString(),
|
||||
boost::bind(&FileBar::session_error, this,
|
||||
errorMessage, infoMessage));
|
||||
}
|
||||
|
||||
void FileBar::session_error(
|
||||
const QString text, const QString info_text)
|
||||
{
|
||||
@@ -118,23 +110,31 @@ void FileBar::show_session_error(
|
||||
|
||||
void FileBar::on_actionSave_triggered()
|
||||
{
|
||||
//save();
|
||||
int unit_size;
|
||||
uint64_t length;
|
||||
void* buf = _session.get_buf(unit_size, length);
|
||||
if (buf != NULL) {
|
||||
const QString file_name = QFileDialog::getSaveFileName(
|
||||
this, tr("Save File"), "",
|
||||
tr("DSLogic Session (*.dsl)"));
|
||||
if (!file_name.isEmpty()) {
|
||||
_session.save_file(file_name.toStdString());
|
||||
}
|
||||
} else {
|
||||
if (!buf) {
|
||||
QMessageBox msg(this);
|
||||
msg.setText("File Save");
|
||||
msg.setInformativeText("No Data to Save!");
|
||||
msg.setStandardButtons(QMessageBox::Ok);
|
||||
msg.setIcon(QMessageBox::Warning);
|
||||
msg.exec();
|
||||
} else if (_session.get_device()->dev_inst()->mode != LOGIC) {
|
||||
QMessageBox msg(this);
|
||||
msg.setText("File Save");
|
||||
msg.setInformativeText("DSLogic currently only support saving logic data to file!");
|
||||
msg.setStandardButtons(QMessageBox::Ok);
|
||||
msg.setIcon(QMessageBox::Warning);
|
||||
msg.exec();
|
||||
}else {
|
||||
const QString file_name = QFileDialog::getSaveFileName(
|
||||
this, tr("Save File"), "",
|
||||
tr("DSLogic Session (*.dsl)"));
|
||||
if (!file_name.isEmpty()) {
|
||||
_session.save_file(file_name.toStdString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,8 @@ void FileBar::on_actionCapture_triggered()
|
||||
void FileBar::enable_toggle(bool enable)
|
||||
{
|
||||
_file_button.setDisabled(!enable);
|
||||
_file_button.setIcon(enable ? QIcon(":/icons/file.png") :
|
||||
QIcon(":/icons/file_dis.png"));
|
||||
}
|
||||
|
||||
} // namespace toolbars
|
||||
|
||||
@@ -43,13 +43,15 @@ public:
|
||||
void enable_toggle(bool enable);
|
||||
|
||||
private:
|
||||
void load_file(QString file_name);
|
||||
|
||||
void session_error(
|
||||
const QString text, const QString info_text);
|
||||
void show_session_error(
|
||||
const QString text, const QString info_text);
|
||||
|
||||
signals:
|
||||
void load_file(QString);
|
||||
void save();
|
||||
void on_screenShot();
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
#include "logobar.h"
|
||||
#include "../dialogs/about.h"
|
||||
@@ -52,6 +54,15 @@ LogoBar::LogoBar(SigSession &session, QWidget *parent) :
|
||||
_logo_button.addAction(_about);
|
||||
connect(_about, SIGNAL(triggered()), this, SLOT(on_actionAbout_triggered()));
|
||||
|
||||
_wiki = new QAction(this);
|
||||
_wiki->setText(QApplication::translate(
|
||||
"File", "&Wiki", 0, QApplication::UnicodeUTF8));
|
||||
_wiki->setIcon(QIcon::fromTheme("file",
|
||||
QIcon(":/icons/wiki.png")));
|
||||
_wiki->setObjectName(QString::fromUtf8("actionWiki"));
|
||||
_logo_button.addAction(_wiki);
|
||||
connect(_wiki, SIGNAL(triggered()), this, SLOT(on_actionWiki_triggered()));
|
||||
|
||||
_logo_button.setPopupMode(QToolButton::InstantPopup);
|
||||
_logo_button.setIcon(QIcon(":/icons/logo_noColor.png"));
|
||||
|
||||
@@ -97,6 +108,12 @@ void LogoBar::on_actionAbout_triggered()
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
void LogoBar::on_actionWiki_triggered()
|
||||
{
|
||||
QDesktopServices::openUrl(
|
||||
QUrl(QLatin1String("http://www.dreamsourcelab.com/wiki")));
|
||||
}
|
||||
|
||||
void LogoBar::enable_toggle(bool enable)
|
||||
{
|
||||
_logo_button.setDisabled(!enable);
|
||||
|
||||
@@ -45,7 +45,6 @@ public:
|
||||
void dslogic_connected(bool conn);
|
||||
|
||||
private:
|
||||
void load_file(QString file_name);
|
||||
void session_error(
|
||||
const QString text, const QString info_text);
|
||||
void show_session_error(
|
||||
@@ -55,6 +54,7 @@ signals:
|
||||
|
||||
private slots:
|
||||
void on_actionAbout_triggered();
|
||||
void on_actionWiki_triggered();
|
||||
|
||||
private:
|
||||
bool _enable;
|
||||
@@ -63,6 +63,7 @@ private:
|
||||
QToolButton _logo_button;
|
||||
|
||||
QAction *_about;
|
||||
QAction *_wiki;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -35,7 +35,15 @@
|
||||
|
||||
#include "samplingbar.h"
|
||||
|
||||
using namespace std;
|
||||
#include "../devicemanager.h"
|
||||
#include "../device/devinst.h"
|
||||
#include "../dialogs/deviceoptions.h"
|
||||
|
||||
using boost::shared_ptr;
|
||||
using std::map;
|
||||
using std::max;
|
||||
using std::min;
|
||||
using std::string;
|
||||
|
||||
namespace pv {
|
||||
namespace toolbars {
|
||||
@@ -84,93 +92,153 @@ const uint64_t SamplingBar::DSLogic_RecordLengths[15] = {
|
||||
|
||||
const uint64_t SamplingBar::DSLogic_DefaultRecordLength = 16777216;
|
||||
|
||||
SamplingBar::SamplingBar(QWidget *parent) :
|
||||
SamplingBar::SamplingBar(SigSession &session, QWidget *parent) :
|
||||
QToolBar("Sampling Bar", parent),
|
||||
_record_length_selector(this),
|
||||
_sample_rate_list(this),
|
||||
_session(session),
|
||||
_enable(true),
|
||||
_device_selector(this),
|
||||
_updating_device_selector(false),
|
||||
_configure_button(this),
|
||||
_sample_count(this),
|
||||
_sample_rate(this),
|
||||
_updating_sample_rate(false),
|
||||
_updating_sample_count(false),
|
||||
_icon_stop(":/icons/stop.png"),
|
||||
_icon_start(":/icons/start.png"),
|
||||
_run_stop_button(this)
|
||||
_icon_instant(":/icons/instant.png"),
|
||||
_run_stop_button(this),
|
||||
_instant_button(this),
|
||||
_instant(false)
|
||||
{
|
||||
setMovable(false);
|
||||
|
||||
connect(&_device_selector, SIGNAL(currentIndexChanged (int)),
|
||||
this, SLOT(on_device_selected()));
|
||||
connect(&_configure_button, SIGNAL(clicked()),
|
||||
this, SLOT(on_configure()));
|
||||
connect(&_run_stop_button, SIGNAL(clicked()),
|
||||
this, SLOT(on_run_stop()));
|
||||
connect(&_instant_button, SIGNAL(clicked()),
|
||||
this, SLOT(on_instant_stop()));
|
||||
|
||||
_configure_button.setIcon(QIcon::fromTheme("configure",
|
||||
QIcon(":/icons/params.png")));
|
||||
_run_stop_button.setIcon(_icon_start);
|
||||
_instant_button.setIcon(_icon_instant);
|
||||
|
||||
// for (size_t i = 0; i < countof(RecordLengths); i++)
|
||||
// {
|
||||
// const uint64_t &l = RecordLengths[i];
|
||||
// char *const text = ds_si_string_u64(l, " samples");
|
||||
// _record_length_selector.addItem(QString(text),
|
||||
// _sample_count.addItem(QString(text),
|
||||
// qVariantFromValue(l));
|
||||
// g_free(text);
|
||||
|
||||
// if (l == DefaultRecordLength)
|
||||
// _record_length_selector.setCurrentIndex(i);
|
||||
// _sample_count.setCurrentIndex(i);
|
||||
// }
|
||||
_record_length_selector.setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
_sample_count.setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
set_sampling(false);
|
||||
|
||||
//_run_stop_button.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
_run_stop_button.setObjectName(tr("run_stop_button"));
|
||||
|
||||
addWidget(new QLabel(tr(" ")));
|
||||
addWidget(&_record_length_selector);
|
||||
addWidget(new QLabel(tr(" @ ")));
|
||||
_sample_rate_list_action = addWidget(&_sample_rate_list);
|
||||
addWidget(&_run_stop_button);
|
||||
connect(&_sample_rate, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(on_samplerate_sel(int)));
|
||||
|
||||
connect(&_sample_rate_list, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(on_sample_rate_changed()));
|
||||
addWidget(new QLabel(tr(" ")));
|
||||
addWidget(&_device_selector);
|
||||
addWidget(&_configure_button);
|
||||
addWidget(&_sample_count);
|
||||
addWidget(new QLabel(tr(" @ ")));
|
||||
addWidget(&_sample_rate);
|
||||
addWidget(&_run_stop_button);
|
||||
addWidget(&_instant_button);
|
||||
}
|
||||
|
||||
void SamplingBar::set_device(struct sr_dev_inst *sdi)
|
||||
void SamplingBar::set_device_list(
|
||||
const std::list< shared_ptr<pv::device::DevInst> > &devices,
|
||||
shared_ptr<pv::device::DevInst> selected)
|
||||
{
|
||||
assert(sdi);
|
||||
_sdi = sdi;
|
||||
if (strcmp(sdi->driver->name, "DSLogic") == 0) {
|
||||
_record_length_selector.clear();
|
||||
for (size_t i = 0; i < countof(DSLogic_RecordLengths); i++)
|
||||
{
|
||||
const uint64_t &l = DSLogic_RecordLengths[i];
|
||||
char *const text = sr_iec_string_u64(l, " samples");
|
||||
_record_length_selector.addItem(QString(text),
|
||||
qVariantFromValue(l));
|
||||
g_free(text);
|
||||
int selected_index = -1;
|
||||
|
||||
if (l == DSLogic_DefaultRecordLength)
|
||||
_record_length_selector.setCurrentIndex(i);
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < countof(RecordLengths); i++)
|
||||
{
|
||||
const uint64_t &l = RecordLengths[i];
|
||||
char *const text = sr_si_string_u64(l, " samples");
|
||||
_record_length_selector.addItem(QString(text),
|
||||
qVariantFromValue(l));
|
||||
g_free(text);
|
||||
assert(selected);
|
||||
|
||||
if (l == DefaultRecordLength)
|
||||
_record_length_selector.setCurrentIndex(i);
|
||||
}
|
||||
_updating_device_selector = true;
|
||||
|
||||
_device_selector.clear();
|
||||
_device_selector_map.clear();
|
||||
|
||||
BOOST_FOREACH (shared_ptr<pv::device::DevInst> dev_inst, devices) {
|
||||
assert(dev_inst);
|
||||
const string title = dev_inst->format_device_title();
|
||||
const void *id = dev_inst->get_id();
|
||||
assert(id);
|
||||
|
||||
if (selected == dev_inst)
|
||||
selected_index = _device_selector.count();
|
||||
|
||||
_device_selector_map[id] = dev_inst;
|
||||
_device_selector.addItem(title.c_str(),
|
||||
qVariantFromValue((void*)id));
|
||||
}
|
||||
|
||||
// The selected device should have been in the list
|
||||
assert(selected_index != -1);
|
||||
_device_selector.setCurrentIndex(selected_index);
|
||||
|
||||
update_sample_rate_selector();
|
||||
update_sample_count_selector();
|
||||
update_scale();
|
||||
|
||||
_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()
|
||||
{
|
||||
int ret;
|
||||
shared_ptr<pv::device::DevInst> dev_inst = get_selected_device();
|
||||
assert(dev_inst);
|
||||
|
||||
pv::dialogs::DeviceOptions dlg(this, dev_inst->dev_inst());
|
||||
ret = dlg.exec();
|
||||
if (ret == QDialog::Accepted)
|
||||
device_updated();
|
||||
}
|
||||
|
||||
uint64_t SamplingBar::get_record_length() const
|
||||
{
|
||||
const int index = _record_length_selector.currentIndex();
|
||||
const int index = _sample_count.currentIndex();
|
||||
if (index < 0)
|
||||
return 0;
|
||||
|
||||
return _record_length_selector.itemData(index).value<uint64_t>();
|
||||
return _sample_count.itemData(index).value<uint64_t>();
|
||||
}
|
||||
|
||||
void SamplingBar::set_record_length(uint64_t length)
|
||||
{
|
||||
for (int i = 0; i < _record_length_selector.count(); i++) {
|
||||
if (length == _record_length_selector.itemData(
|
||||
for (int i = 0; i < _sample_count.count(); i++) {
|
||||
if (length == _sample_count.itemData(
|
||||
i).value<uint64_t>()) {
|
||||
_record_length_selector.setCurrentIndex(i);
|
||||
_sample_count.setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -178,26 +246,43 @@ void SamplingBar::set_record_length(uint64_t length)
|
||||
|
||||
void SamplingBar::set_sampling(bool sampling)
|
||||
{
|
||||
_run_stop_button.setIcon(sampling ? _icon_stop : _icon_start);
|
||||
//_run_stop_button.setText(sampling ? " Stop" : "Start");
|
||||
if (_instant)
|
||||
_instant_button.setIcon(sampling ? _icon_stop : _icon_instant);
|
||||
else
|
||||
_run_stop_button.setIcon(sampling ? _icon_stop : _icon_start);
|
||||
|
||||
if (!sampling) {
|
||||
_run_stop_button.setEnabled(true);
|
||||
_instant_button.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void SamplingBar::set_sample_rate(uint64_t sample_rate)
|
||||
{
|
||||
for (int i = 0; i < _sample_rate_list.count(); i++) {
|
||||
if (sample_rate == _sample_rate_list.itemData(
|
||||
i).value<uint64_t>()) {
|
||||
_sample_rate_list.setCurrentIndex(i);
|
||||
// Set the samplerate
|
||||
if (sr_config_set(_sdi, SR_CONF_SAMPLERATE,
|
||||
g_variant_new_uint64(sample_rate)) != SR_OK) {
|
||||
qDebug() << "Failed to configure samplerate.";
|
||||
return;
|
||||
}
|
||||
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);
|
||||
// commit the samplerate
|
||||
commit_sample_rate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SamplingBar::set_sample_limit(uint64_t sample_limit)
|
||||
{
|
||||
for (int i = 0; i < _sample_count.count(); i++) {
|
||||
uint64_t cur_index_sample_limit = _sample_count.itemData(
|
||||
i).value<uint64_t>();
|
||||
if (sample_limit <= cur_index_sample_limit) {
|
||||
_sample_count.setCurrentIndex(i);
|
||||
// commit the samplecount
|
||||
commit_sample_count();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SamplingBar::update_sample_rate_selector()
|
||||
@@ -205,134 +290,266 @@ void SamplingBar::update_sample_rate_selector()
|
||||
GVariant *gvar_dict, *gvar_list;
|
||||
const uint64_t *elements = NULL;
|
||||
gsize num_elements;
|
||||
//QAction *selector_action = NULL;
|
||||
|
||||
assert(_sample_rate_list_action);
|
||||
if (_updating_sample_rate)
|
||||
return;
|
||||
|
||||
if (!_sdi)
|
||||
return;
|
||||
const shared_ptr<device::DevInst> dev_inst = get_selected_device();
|
||||
if (!dev_inst)
|
||||
return;
|
||||
|
||||
if (sr_config_list(_sdi->driver, SR_CONF_SAMPLERATE,
|
||||
&gvar_dict, _sdi) != SR_OK)
|
||||
return;
|
||||
assert(!_updating_sample_rate);
|
||||
_updating_sample_rate = true;
|
||||
|
||||
_sample_rate_list_action->setVisible(false);
|
||||
if (!(gvar_dict = dev_inst->list_config(NULL, SR_CONF_SAMPLERATE)))
|
||||
{
|
||||
_sample_rate.clear();
|
||||
_sample_rate.show();
|
||||
_updating_sample_rate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
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));
|
||||
_sample_rate_list.clear();
|
||||
_sample_rate.clear();
|
||||
|
||||
for (unsigned int i = 0; i < num_elements; i++)
|
||||
{
|
||||
char *const s = sr_samplerate_string(elements[i]);
|
||||
_sample_rate_list.addItem(QString(s),
|
||||
_sample_rate.addItem(QString(s),
|
||||
qVariantFromValue(elements[i]));
|
||||
g_free(s);
|
||||
}
|
||||
|
||||
_sample_rate_list.show();
|
||||
_sample_rate.show();
|
||||
g_variant_unref(gvar_list);
|
||||
|
||||
//selector_action = _sample_rate_list_action;
|
||||
}
|
||||
_updating_sample_rate = false;
|
||||
|
||||
g_variant_unref(gvar_dict);
|
||||
_sample_rate_list_action->setVisible(true);
|
||||
update_sample_rate_selector_value();
|
||||
}
|
||||
|
||||
void SamplingBar::update_sample_rate_selector_value()
|
||||
{
|
||||
GVariant *gvar;
|
||||
uint64_t samplerate;
|
||||
if (_updating_sample_rate)
|
||||
return;
|
||||
|
||||
assert(_sdi);
|
||||
const uint64_t samplerate = get_selected_device()->get_sample_rate();
|
||||
|
||||
if (sr_config_get(_sdi->driver, SR_CONF_SAMPLERATE,
|
||||
&gvar, _sdi) != SR_OK) {
|
||||
qDebug() <<
|
||||
"WARNING: Failed to get value of sample rate";
|
||||
return;
|
||||
}
|
||||
samplerate = g_variant_get_uint64(gvar);
|
||||
g_variant_unref(gvar);
|
||||
assert(!_updating_sample_rate);
|
||||
_updating_sample_rate = true;
|
||||
|
||||
assert(_sample_rate_list_action);
|
||||
for (int i = 0; i < _sample_rate.count(); i++)
|
||||
if (samplerate == _sample_rate.itemData(
|
||||
i).value<uint64_t>())
|
||||
_sample_rate.setCurrentIndex(i);
|
||||
|
||||
if (_sample_rate_list_action->isVisible())
|
||||
{
|
||||
for (int i = 0; i < _sample_rate_list.count(); i++)
|
||||
if (samplerate == _sample_rate_list.itemData(
|
||||
i).value<uint64_t>())
|
||||
_sample_rate_list.setCurrentIndex(i);
|
||||
}
|
||||
_updating_sample_rate = false;
|
||||
}
|
||||
|
||||
void SamplingBar::commit_sample_rate()
|
||||
{
|
||||
GVariant *gvar;
|
||||
uint64_t sample_rate = 0;
|
||||
uint64_t last_sample_rate = 0;
|
||||
|
||||
assert(_sdi);
|
||||
if (_updating_sample_rate)
|
||||
return;
|
||||
|
||||
assert(_sample_rate_list_action);
|
||||
assert(!_updating_sample_rate);
|
||||
_updating_sample_rate = true;
|
||||
|
||||
if (_sample_rate_list_action->isVisible())
|
||||
{
|
||||
const int index = _sample_rate_list.currentIndex();
|
||||
if (index >= 0)
|
||||
sample_rate = _sample_rate_list.itemData(
|
||||
index).value<uint64_t>();
|
||||
}
|
||||
const int index = _sample_rate.currentIndex();
|
||||
if (index >= 0)
|
||||
sample_rate = _sample_rate.itemData(
|
||||
index).value<uint64_t>();
|
||||
|
||||
if (sample_rate == 0)
|
||||
return;
|
||||
|
||||
// Get last samplerate
|
||||
if (sr_config_get(_sdi->driver, SR_CONF_SAMPLERATE,
|
||||
&gvar, _sdi) != SR_OK) {
|
||||
qDebug() <<
|
||||
"WARNING: Failed to get value of sample rate";
|
||||
return;
|
||||
}
|
||||
last_sample_rate = g_variant_get_uint64(gvar);
|
||||
g_variant_unref(gvar);
|
||||
last_sample_rate = get_selected_device()->get_sample_rate();
|
||||
|
||||
// Set the samplerate
|
||||
if (sr_config_set(_sdi, SR_CONF_SAMPLERATE,
|
||||
g_variant_new_uint64(sample_rate)) != SR_OK) {
|
||||
qDebug() << "Failed to configure samplerate.";
|
||||
return;
|
||||
}
|
||||
get_selected_device()->set_config(NULL, NULL,
|
||||
SR_CONF_SAMPLERATE,
|
||||
g_variant_new_uint64(sample_rate));
|
||||
|
||||
if (last_sample_rate != sample_rate)
|
||||
update_scale();
|
||||
|
||||
_updating_sample_rate = false;
|
||||
}
|
||||
|
||||
void SamplingBar::on_samplerate_sel(int index)
|
||||
{
|
||||
uint64_t sample_rate = 0;
|
||||
uint64_t last_sample_rate = 0;
|
||||
|
||||
if (index >= 0)
|
||||
sample_rate = _sample_rate.itemData(
|
||||
index).value<uint64_t>();
|
||||
|
||||
const sr_dev_inst* _sdi = get_selected_device()->dev_inst();
|
||||
assert(_sdi);
|
||||
|
||||
// Get last samplerate
|
||||
last_sample_rate = get_selected_device()->get_sample_rate();
|
||||
|
||||
if (strcmp(_sdi->driver->name, "DSLogic") == 0 && _sdi->mode != DSO) {
|
||||
if ((last_sample_rate == SR_MHZ(200)&& sample_rate != SR_MHZ(200)) ||
|
||||
(last_sample_rate != SR_MHZ(200) && sample_rate == SR_MHZ(200)) ||
|
||||
(last_sample_rate == SR_MHZ(400)&& sample_rate != SR_MHZ(400)) ||
|
||||
(last_sample_rate != SR_MHZ(400) && sample_rate == SR_MHZ(400)))
|
||||
device_reload();
|
||||
(last_sample_rate != SR_MHZ(400) && sample_rate == SR_MHZ(400))) {
|
||||
|
||||
// Set the samplerate
|
||||
get_selected_device()->set_config(NULL, NULL,
|
||||
SR_CONF_SAMPLERATE,
|
||||
g_variant_new_uint64(sample_rate));
|
||||
device_updated();
|
||||
update_scale();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SamplingBar::on_sample_rate_changed()
|
||||
void SamplingBar::update_sample_count_selector()
|
||||
{
|
||||
commit_sample_rate();
|
||||
GVariant *gvar_dict, *gvar_list;
|
||||
const uint64_t *elements = NULL;
|
||||
gsize num_elements;
|
||||
|
||||
if (_updating_sample_count)
|
||||
return;
|
||||
|
||||
const shared_ptr<device::DevInst> dev_inst = get_selected_device();
|
||||
if (!dev_inst)
|
||||
return;
|
||||
|
||||
assert(!_updating_sample_count);
|
||||
_updating_sample_count = true;
|
||||
|
||||
if (!(gvar_dict = dev_inst->list_config(NULL, SR_CONF_LIMIT_SAMPLES)))
|
||||
{
|
||||
_sample_count.clear();
|
||||
_sample_count.show();
|
||||
_updating_sample_count = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((gvar_list = g_variant_lookup_value(gvar_dict,
|
||||
"samplecounts", G_VARIANT_TYPE("at"))))
|
||||
{
|
||||
elements = (const uint64_t *)g_variant_get_fixed_array(
|
||||
gvar_list, &num_elements, sizeof(uint64_t));
|
||||
_sample_count.clear();
|
||||
|
||||
for (unsigned int i = 0; i < num_elements; i++)
|
||||
{
|
||||
char *const s = sr_samplecount_string(elements[i]);
|
||||
_sample_count.addItem(QString(s),
|
||||
qVariantFromValue(elements[i]));
|
||||
g_free(s);
|
||||
}
|
||||
|
||||
_sample_count.show();
|
||||
g_variant_unref(gvar_list);
|
||||
}
|
||||
|
||||
_updating_sample_count = false;
|
||||
|
||||
g_variant_unref(gvar_dict);
|
||||
update_sample_count_selector_value();
|
||||
}
|
||||
|
||||
void SamplingBar::update_sample_count_selector_value()
|
||||
{
|
||||
if (_updating_sample_count)
|
||||
return;
|
||||
|
||||
const uint64_t samplecount = get_selected_device()->get_sample_limit();
|
||||
|
||||
assert(!_updating_sample_count);
|
||||
_updating_sample_count = true;
|
||||
|
||||
for (int i = 0; i < _sample_count.count(); i++)
|
||||
if (samplecount == _sample_count.itemData(
|
||||
i).value<uint64_t>())
|
||||
_sample_count.setCurrentIndex(i);
|
||||
|
||||
_updating_sample_count = false;
|
||||
}
|
||||
|
||||
void SamplingBar::commit_sample_count()
|
||||
{
|
||||
uint64_t sample_count = 0;
|
||||
uint64_t last_sample_count = 0;
|
||||
|
||||
if (_updating_sample_count)
|
||||
return;
|
||||
|
||||
assert(!_updating_sample_count);
|
||||
_updating_sample_count = true;
|
||||
|
||||
|
||||
const int index = _sample_count.currentIndex();
|
||||
if (index >= 0)
|
||||
sample_count = _sample_count.itemData(
|
||||
index).value<uint64_t>();
|
||||
|
||||
if (sample_count == 0)
|
||||
return;
|
||||
|
||||
// Get last samplecount
|
||||
last_sample_count = get_selected_device()->get_sample_limit();
|
||||
|
||||
// Set the samplecount
|
||||
get_selected_device()->set_config(NULL, NULL,
|
||||
SR_CONF_LIMIT_SAMPLES,
|
||||
g_variant_new_uint64(sample_count));
|
||||
|
||||
_updating_sample_count = false;
|
||||
|
||||
if (sample_count != last_sample_count)
|
||||
update_scale();
|
||||
}
|
||||
|
||||
void SamplingBar::on_run_stop()
|
||||
{
|
||||
commit_sample_rate();
|
||||
commit_sample_count();
|
||||
_instant = false;
|
||||
run_stop();
|
||||
}
|
||||
|
||||
void SamplingBar::on_instant_stop()
|
||||
{
|
||||
commit_sample_rate();
|
||||
commit_sample_count();
|
||||
_instant = true;
|
||||
instant_stop();
|
||||
}
|
||||
|
||||
void SamplingBar::on_device_selected()
|
||||
{
|
||||
if (_updating_device_selector)
|
||||
return;
|
||||
|
||||
const shared_ptr<device::DevInst> dev_inst = get_selected_device();
|
||||
if (!dev_inst)
|
||||
return;
|
||||
|
||||
_session.set_device(dev_inst);
|
||||
|
||||
device_selected();
|
||||
}
|
||||
|
||||
void SamplingBar::enable_toggle(bool enable)
|
||||
{
|
||||
_record_length_selector.setDisabled(!enable);
|
||||
_sample_rate_list.setDisabled(!enable);
|
||||
_sample_count.setDisabled(!enable);
|
||||
_sample_rate.setDisabled(!enable);
|
||||
}
|
||||
|
||||
void SamplingBar::enable_run_stop(bool enable)
|
||||
@@ -340,5 +557,10 @@ void SamplingBar::enable_run_stop(bool enable)
|
||||
_run_stop_button.setDisabled(!enable);
|
||||
}
|
||||
|
||||
void SamplingBar::enable_instant(bool enable)
|
||||
{
|
||||
_instant_button.setDisabled(!enable);
|
||||
}
|
||||
|
||||
} // namespace toolbars
|
||||
} // namespace pv
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QToolBar>
|
||||
@@ -34,10 +37,23 @@
|
||||
|
||||
#include <libsigrok4DSLogic/libsigrok.h>
|
||||
|
||||
#include "../sigsession.h"
|
||||
|
||||
struct st_dev_inst;
|
||||
class QAction;
|
||||
|
||||
namespace pv {
|
||||
|
||||
class SigSession;
|
||||
|
||||
namespace device {
|
||||
class DevInst;
|
||||
}
|
||||
|
||||
namespace dialogs {
|
||||
class deviceoptions;
|
||||
}
|
||||
|
||||
namespace toolbars {
|
||||
|
||||
class SamplingBar : public QToolBar
|
||||
@@ -51,46 +67,76 @@ private:
|
||||
static const uint64_t DSLogic_DefaultRecordLength;
|
||||
|
||||
public:
|
||||
SamplingBar(QWidget *parent);
|
||||
SamplingBar(SigSession &session, QWidget *parent);
|
||||
|
||||
void set_device_list(const std::list< boost::shared_ptr<pv::device::DevInst> > &devices,
|
||||
boost::shared_ptr<pv::device::DevInst> selected);
|
||||
|
||||
boost::shared_ptr<pv::device::DevInst> get_selected_device() const;
|
||||
|
||||
uint64_t get_record_length() const;
|
||||
void set_record_length(uint64_t length);
|
||||
|
||||
void set_sampling(bool sampling);
|
||||
void update_sample_rate_selector();
|
||||
void set_sample_rate(uint64_t sample_rate);
|
||||
|
||||
void set_device(struct sr_dev_inst *sdi);
|
||||
|
||||
void enable_toggle(bool enable);
|
||||
|
||||
void enable_run_stop(bool enable);
|
||||
|
||||
void enable_instant(bool enable);
|
||||
|
||||
public slots:
|
||||
void set_sample_rate(uint64_t sample_rate);
|
||||
void set_sample_limit(uint64_t sample_limit);
|
||||
|
||||
signals:
|
||||
void run_stop();
|
||||
void device_reload();
|
||||
void instant_stop();
|
||||
void device_selected();
|
||||
void device_updated();
|
||||
void update_scale();
|
||||
|
||||
private:
|
||||
void update_sample_rate_selector();
|
||||
void update_sample_rate_selector_value();
|
||||
void update_sample_count_selector();
|
||||
void update_sample_count_selector_value();
|
||||
void commit_sample_rate();
|
||||
void commit_sample_count();
|
||||
|
||||
private slots:
|
||||
void on_sample_rate_changed();
|
||||
void on_run_stop();
|
||||
void on_instant_stop();
|
||||
void on_device_selected();
|
||||
void on_samplerate_sel(int index);
|
||||
|
||||
public slots:
|
||||
void on_configure();
|
||||
|
||||
private:
|
||||
SigSession &_session;
|
||||
|
||||
bool _enable;
|
||||
|
||||
struct sr_dev_inst *_sdi;
|
||||
QComboBox _device_selector;
|
||||
std::map<const void*, boost::weak_ptr<device::DevInst> >
|
||||
_device_selector_map;
|
||||
bool _updating_device_selector;
|
||||
|
||||
QComboBox _record_length_selector;
|
||||
QToolButton _configure_button;
|
||||
|
||||
QComboBox _sample_rate_list;
|
||||
QAction *_sample_rate_list_action;
|
||||
QComboBox _sample_count;
|
||||
QComboBox _sample_rate;
|
||||
bool _updating_sample_rate;
|
||||
bool _updating_sample_count;
|
||||
|
||||
QIcon _icon_stop;
|
||||
QIcon _icon_start;
|
||||
QIcon _icon_instant;
|
||||
QToolButton _run_stop_button;
|
||||
QToolButton _instant_button;
|
||||
|
||||
bool _instant;
|
||||
};
|
||||
|
||||
} // namespace toolbars
|
||||
|
||||
@@ -50,7 +50,9 @@ TrigBar::TrigBar(QWidget *parent) :
|
||||
_trig_button.setCheckable(true);
|
||||
_protocol_button.setIcon(QIcon::fromTheme("trig",
|
||||
QIcon(":/icons/protocol.png")));
|
||||
#ifdef ENABLE_DECODE
|
||||
_protocol_button.setCheckable(true);
|
||||
#endif
|
||||
_measure_button.setIcon(QIcon::fromTheme("trig",
|
||||
QIcon(":/icons/measure.png")));
|
||||
_measure_button.setCheckable(true);
|
||||
@@ -90,6 +92,35 @@ void TrigBar::enable_toggle(bool enable)
|
||||
_protocol_button.setDisabled(!enable);
|
||||
_measure_button.setDisabled(!enable);
|
||||
_search_button.setDisabled(!enable);
|
||||
|
||||
_trig_button.setIcon(enable ? QIcon::fromTheme("trig", QIcon(":/icons/trigger.png")) :
|
||||
QIcon::fromTheme("trig", QIcon(":/icons/trigger_dis.png")));
|
||||
_protocol_button.setIcon(enable ? QIcon::fromTheme("trig", QIcon(":/icons/protocol.png")) :
|
||||
QIcon::fromTheme("trig", QIcon(":/icons/protocol_dis.png")));
|
||||
_measure_button.setIcon(enable ? QIcon::fromTheme("trig", QIcon(":/icons/measure.png")) :
|
||||
QIcon::fromTheme("trig", QIcon(":/icons/measure_dis.png")));
|
||||
_search_button.setIcon(enable ? QIcon::fromTheme("trig", QIcon(":/icons/search-bar.png")) :
|
||||
QIcon::fromTheme("trig", QIcon(":/icons/search-bar_dis.png")));
|
||||
}
|
||||
|
||||
void TrigBar::close_all()
|
||||
{
|
||||
if (_trig_button.isChecked()) {
|
||||
_trig_button.setChecked(false);
|
||||
on_trigger(false);
|
||||
}
|
||||
if (_protocol_button.isChecked()) {
|
||||
_protocol_button.setChecked(false);
|
||||
on_protocol(false);
|
||||
}
|
||||
if (_measure_button.isChecked()) {
|
||||
_measure_button.setChecked(false);
|
||||
on_measure(false);
|
||||
}
|
||||
if(_search_button.isChecked()) {
|
||||
_search_button.setChecked(false);
|
||||
on_search(false);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace toolbars
|
||||
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
|
||||
void enable_toggle(bool enable);
|
||||
|
||||
void close_all();
|
||||
|
||||
signals:
|
||||
void on_protocol(bool visible);
|
||||
void on_trigger(bool visible);
|
||||
|
||||
Reference in New Issue
Block a user