From: Joel Holdsworth Date: Sun, 3 Mar 2013 17:41:19 +0000 (+0000) Subject: Sampling bar now commits the sample rate into the device instance X-Git-Tag: pulseview-0.1.0~106 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=488883133fefe0af41737cea9b2fc9eb114042b8;p=pulseview.git Sampling bar now commits the sample rate into the device instance --- diff --git a/pv/samplingbar.cpp b/pv/samplingbar.cpp index 87795784..6eea6d78 100644 --- a/pv/samplingbar.cpp +++ b/pv/samplingbar.cpp @@ -25,6 +25,7 @@ #include #include +#include #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 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(); - } - - 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()) + _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(); + } + + // 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 diff --git a/pv/samplingbar.h b/pv/samplingbar.h index 446d98ed..ade457e5 100644 --- a/pv/samplingbar.h +++ b/pv/samplingbar.h @@ -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: