]> sigrok.org Git - pulseview.git/commitdiff
Added initial sampling support
authorJoel Holdsworth <redacted>
Sat, 30 Jun 2012 11:06:24 +0000 (12:06 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:59:06 +0000 (13:59 +0100)
mainwindow.cpp
mainwindow.h
samplingbar.cpp
samplingbar.h
sigsession.cpp
sigsession.h

index 04f852d92fe053f85b2be6815bc43a567dc6fe7f..50847e2ac1268108b48ee1a0945c28966a39fcda 100644 (file)
@@ -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());
+}
index 3ae04c43956a31043535fd72d3da894633d85624..6ae608ccb822fe32ef1d0752306cccf71b3defdd 100644 (file)
@@ -53,6 +53,8 @@ private slots:
        void on_actionOpen_triggered();
 
        void on_actionAbout_triggered();
+
+       void run_stop();
 };
 
 #endif // MAINWINDOW_H
index c411f3c15260dfda8adcefc7e9322c6cfbba6318..acb106466b961e7084667b053d9bea6cb8d90ac8 100644 (file)
@@ -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();
index d183dabdebdf55060847128e0f922872dd23f69a..e7738656b168c55fb60b50308e267ee28af57cc3 100644 (file)
@@ -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
index e6288e7c0cf64f4331ce1e8fcd160aec3f87c9ef..aecd21c2c3b5c5231c9407156edd24cad52acfc0 100644 (file)
@@ -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<Signal> >& SigSession::get_signals()
 {
        return _signals;
index a08ba8129914ae0f61c6031d28b858a32cd0b1d0..851ca963ec0db1843077c8c45d6fb0080b6d14b0 100644 (file)
@@ -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<Signal> >&
                get_signals();