From 215f9499495716d6a33b53b0fa9cac47f0e43fbd Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 7 Jul 2012 09:41:17 +0100 Subject: [PATCH] Added record length selector --- mainwindow.cpp | 1 + samplingbar.cpp | 35 +++++++++++++++++++++++++++++++++++ samplingbar.h | 6 ++++++ sigsession.cpp | 5 ++--- sigsession.h | 3 ++- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 510e552a..3390e183 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -79,5 +79,6 @@ void MainWindow::run_stop() { _session.start_capture( _sampling_bar->get_selected_device(), + _sampling_bar->get_record_length(), _sampling_bar->get_sample_rate()); } diff --git a/samplingbar.cpp b/samplingbar.cpp index acb10646..711f6f4e 100644 --- a/samplingbar.cpp +++ b/samplingbar.cpp @@ -20,6 +20,8 @@ #include +#include + extern "C" { #include } @@ -28,9 +30,24 @@ extern "C" { #include "samplingbar.h" +const uint64_t SamplingBar::RecordLengths[11] = { + 1000000, + 2000000, + 5000000, + 10000000, + 25000000, + 50000000, + 100000000, + 250000000, + 500000000, + 1000000000, + 10000000000 +}; + SamplingBar::SamplingBar(QWidget *parent) : QToolBar("Sampling Bar", parent), _device_selector(this), + _record_length_selector(this), _sample_rate_list(this), _run_stop_button(this) { @@ -41,9 +58,18 @@ SamplingBar::SamplingBar(QWidget *parent) : _sample_rate_value.setDecimals(0); _sample_rate_value.setSuffix("Hz"); + BOOST_FOREACH(uint64_t l, RecordLengths) + { + char *const text = sr_si_string_u64(l, " samples"); + _record_length_selector.addItem(QString(text), + qVariantFromValue(l)); + g_free(text); + } + _run_stop_button.setText("Run"); addWidget(&_device_selector); + addWidget(&_record_length_selector); _sample_rate_list_action = addWidget(&_sample_rate_list); _sample_rate_value_action = addWidget(&_sample_rate_value); addWidget(&_run_stop_button); @@ -62,6 +88,15 @@ struct sr_dev_inst* SamplingBar::get_selected_device() const index).value(); } +uint64_t SamplingBar::get_record_length() const +{ + const int index = _record_length_selector.currentIndex(); + if(index < 0) + return 0; + + return _record_length_selector.itemData(index).value(); +} + uint64_t SamplingBar::get_sample_rate() const { assert(_sample_rate_value_action); diff --git a/samplingbar.h b/samplingbar.h index e7738656..ad269624 100644 --- a/samplingbar.h +++ b/samplingbar.h @@ -34,10 +34,14 @@ class SamplingBar : public QToolBar { Q_OBJECT +private: + static const uint64_t RecordLengths[11]; + public: SamplingBar(QWidget *parent); struct sr_dev_inst* get_selected_device() const; + uint64_t get_record_length() const; uint64_t get_sample_rate() const; signals: @@ -53,6 +57,8 @@ private slots: private: QComboBox _device_selector; + QComboBox _record_length_selector; + QComboBox _sample_rate_list; QAction *_sample_rate_list_action; QDoubleSpinBox _sample_rate_value; diff --git a/sigsession.cpp b/sigsession.cpp index 21c5624b..16b84f14 100644 --- a/sigsession.cpp +++ b/sigsession.cpp @@ -58,7 +58,7 @@ void SigSession::load_file(const std::string &name) } void SigSession::start_capture(struct sr_dev_inst *sdi, - uint64_t sample_rate) + uint64_t record_length, uint64_t sample_rate) { sr_session_new(); sr_session_datafeed_callback_add(data_feed_in_proc); @@ -69,9 +69,8 @@ void SigSession::start_capture(struct sr_dev_inst *sdi, return; } - uint64_t limit_samples = 10000; if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES, - &limit_samples) != SR_OK) { + &record_length) != SR_OK) { qDebug() << "Failed to configure time-based sample limit."; sr_session_destroy(); return; diff --git a/sigsession.h b/sigsession.h index 24726dfe..bf262bbf 100644 --- a/sigsession.h +++ b/sigsession.h @@ -47,7 +47,8 @@ public: void load_file(const std::string &name); - void start_capture(struct sr_dev_inst* sdi, uint64_t sample_rate); + void start_capture(struct sr_dev_inst* sdi, uint64_t record_length, + uint64_t sample_rate); std::vector< boost::shared_ptr >& get_signals(); -- 2.30.2