]> sigrok.org Git - pulseview.git/commitdiff
Sampling bar now commits the sample rate into the device instance
authorJoel Holdsworth <redacted>
Sun, 3 Mar 2013 17:41:19 +0000 (17:41 +0000)
committerJoel Holdsworth <redacted>
Sun, 3 Mar 2013 18:15:31 +0000 (18:15 +0000)
pv/samplingbar.cpp
pv/samplingbar.h

index 877957847b099c0ffefc4b55cbabb760b884f635..6eea6d78040af5b8be211e5037294a1e819139bc 100644 (file)
@@ -25,6 +25,7 @@
 #include <libsigrok/libsigrok.h>
 
 #include <QAction>
+#include <QDebug>
 
 #include "samplingbar.h"
 
@@ -104,7 +105,12 @@ SamplingBar::SamplingBar(QWidget *parent) :
        addWidget(&_run_stop_button);
 
        update_device_selector();
+
        update_sample_rate_selector();
+       connect(&_sample_rate_list, SIGNAL(currentIndexChanged(int)),
+               this, SLOT(on_sample_rate_changed()));
+       connect(&_sample_rate_value, SIGNAL(valueChanged(double)),
+               this, SLOT(on_sample_rate_changed()));
 }
 
 struct sr_dev_inst* SamplingBar::get_selected_device() const
@@ -126,25 +132,6 @@ uint64_t SamplingBar::get_record_length() const
        return _record_length_selector.itemData(index).value<uint64_t>();
 }
 
-uint64_t SamplingBar::get_sample_rate() const
-{
-       assert(_sample_rate_value_action);
-       assert(_sample_rate_list_action);
-
-       if (_sample_rate_value_action->isVisible())
-               return (uint64_t)_sample_rate_value.value();
-       else if (_sample_rate_list_action->isVisible())
-       {
-               const int index = _sample_rate_list.currentIndex();
-               if (index < 0)
-                       return 0;
-
-               return _sample_rate_list.itemData(index).value<uint64_t>();
-       }
-
-       return 0;
-}
-
 void SamplingBar::set_sampling(bool sampling)
 {
        _run_stop_button.setIcon(sampling ? _icon_green : _icon_grey);
@@ -215,6 +202,63 @@ void SamplingBar::update_sample_rate_selector()
                _sample_rate_list.show();
                _sample_rate_list_action->setVisible(true);
        }
+
+       update_sample_rate_selector_value();
+}
+
+void SamplingBar::update_sample_rate_selector_value()
+{
+       sr_dev_inst *const sdi = get_selected_device();
+       assert(sdi);
+
+        uint64_t *samplerate = NULL;
+        if(sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
+                (const void**)&samplerate, sdi) != SR_OK) {
+                qDebug() <<
+                        "WARNING: Failed to get value of sample rate";
+                return;
+        }
+
+       assert(_sample_rate_value_action);
+       assert(_sample_rate_list_action);
+
+       if (_sample_rate_value_action->isVisible())
+               _sample_rate_value.setValue(*samplerate);
+       else 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);
+       }
+}
+
+void SamplingBar::commit_sample_rate()
+{
+       uint64_t sample_rate = 0;
+
+       sr_dev_inst *const sdi = get_selected_device();
+       assert(sdi);
+
+       assert(_sample_rate_value_action);
+       assert(_sample_rate_list_action);
+
+       if (_sample_rate_value_action->isVisible())
+               sample_rate = (uint64_t)_sample_rate_value.value();
+       else 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>();
+       }
+
+       // Set the samplerate
+       if (sr_config_set(sdi, SR_CONF_SAMPLERATE,
+               &sample_rate) != SR_OK) {
+               qDebug() << "Failed to configure samplerate.";
+               return;
+       }
 }
 
 void SamplingBar::on_device_selected()
@@ -222,13 +266,22 @@ void SamplingBar::on_device_selected()
        update_sample_rate_selector();
 }
 
+void SamplingBar::on_sample_rate_changed()
+{
+       commit_sample_rate();
+}
+
 void SamplingBar::configure()
 {
+       commit_sample_rate();
+
        sr_dev_inst *const sdi = get_selected_device();
        assert(sdi);
 
        pv::dialogs::DeviceOptions dlg(this, sdi);
        dlg.exec();
+
+       update_sample_rate_selector_value();
 }
 
 } // namespace pv
index 446d98ed495fcf23e017f44c1ab98c3d7cf5706c..ade457e5cc56db0a73f0004c63b57a13ff05754e 100644 (file)
@@ -45,7 +45,6 @@ public:
 
        struct sr_dev_inst* get_selected_device() const;
        uint64_t get_record_length() const;
-       uint64_t get_sample_rate() const;
 
        void set_sampling(bool sampling);
 
@@ -55,9 +54,12 @@ signals:
 private:
        void update_device_selector();
        void update_sample_rate_selector();
+       void update_sample_rate_selector_value();
+       void commit_sample_rate();
 
 private slots:
        void on_device_selected();
+       void on_sample_rate_changed();
        void configure();
 
 private: