From: Joel Holdsworth Date: Sat, 30 Jun 2012 11:06:24 +0000 (+0100) Subject: Added initial sampling support X-Git-Tag: pulseview-0.1.0~330 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=274d4f133825cddfc6a42438dd47899db20c7d97;p=pulseview.git Added initial sampling support --- diff --git a/mainwindow.cpp b/mainwindow.cpp index 04f852d9..50847e2a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -48,6 +48,8 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); _sampling_bar = new SamplingBar(this); + connect(_sampling_bar, SIGNAL(run_stop()), this, + SLOT(run_stop())); addToolBar(_sampling_bar); view = new SigView(session, this); @@ -72,3 +74,10 @@ void MainWindow::on_actionAbout_triggered() About dlg(this); dlg.exec(); } + +void MainWindow::run_stop() +{ + session.start_capture( + _sampling_bar->get_selected_device(), + _sampling_bar->get_sample_rate()); +} diff --git a/mainwindow.h b/mainwindow.h index 3ae04c43..6ae608cc 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -53,6 +53,8 @@ private slots: void on_actionOpen_triggered(); void on_actionAbout_triggered(); + + void run_stop(); }; #endif // MAINWINDOW_H diff --git a/samplingbar.cpp b/samplingbar.cpp index c411f3c1..acb10646 100644 --- a/samplingbar.cpp +++ b/samplingbar.cpp @@ -31,17 +31,22 @@ extern "C" { SamplingBar::SamplingBar(QWidget *parent) : QToolBar("Sampling Bar", parent), _device_selector(this), - _sample_rate_list(this) + _sample_rate_list(this), + _run_stop_button(this) { + connect(&_run_stop_button, SIGNAL(clicked()), this, SIGNAL(run_stop())); connect(&_device_selector, SIGNAL(currentIndexChanged (int)), this, SLOT(on_device_selected())); _sample_rate_value.setDecimals(0); _sample_rate_value.setSuffix("Hz"); + _run_stop_button.setText("Run"); + addWidget(&_device_selector); _sample_rate_list_action = addWidget(&_sample_rate_list); _sample_rate_value_action = addWidget(&_sample_rate_value); + addWidget(&_run_stop_button); update_device_selector(); update_sample_rate_selector(); diff --git a/samplingbar.h b/samplingbar.h index d183dabd..e7738656 100644 --- a/samplingbar.h +++ b/samplingbar.h @@ -40,6 +40,9 @@ public: struct sr_dev_inst* get_selected_device() const; uint64_t get_sample_rate() const; +signals: + void run_stop(); + private: void update_device_selector(); void update_sample_rate_selector(); @@ -54,6 +57,8 @@ private: QAction *_sample_rate_list_action; QDoubleSpinBox _sample_rate_value; QAction *_sample_rate_value_action; + + QToolButton _run_stop_button; }; #endif // SAMPLINGBAR_H diff --git a/sigsession.cpp b/sigsession.cpp index e6288e7c..aecd21c2 100644 --- a/sigsession.cpp +++ b/sigsession.cpp @@ -57,6 +57,42 @@ void SigSession::loadFile(const std::string &name) } } +void SigSession::start_capture(struct sr_dev_inst *sdi, + uint64_t sample_rate) +{ + sr_session_new(); + sr_session_datafeed_callback_add(dataFeedInProc); + + if (sr_session_dev_add(sdi) != SR_OK) { + qDebug() << "Failed to use device."; + sr_session_destroy(); + return; + } + + uint64_t limit_samples = 10000; + if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES, + &limit_samples) != SR_OK) { + qDebug() << "Failed to configure time-based sample limit."; + sr_session_destroy(); + return; + } + + if (sr_dev_config_set(sdi, SR_HWCAP_SAMPLERATE, + &sample_rate) != SR_OK) { + qDebug() << "Failed to configure samplerate."; + sr_session_destroy(); + return; + } + + if (sr_session_start() != SR_OK) { + qDebug() << "Failed to start session."; + return; + } + + sr_session_run(); + sr_session_destroy(); +} + vector< shared_ptr >& SigSession::get_signals() { return _signals; diff --git a/sigsession.h b/sigsession.h index a08ba812..851ca963 100644 --- a/sigsession.h +++ b/sigsession.h @@ -47,6 +47,8 @@ public: void loadFile(const std::string &name); + void start_capture(struct sr_dev_inst* sdi, uint64_t sample_rate); + std::vector< boost::shared_ptr >& get_signals();