From: Joel Holdsworth Date: Sat, 30 Jun 2012 08:41:08 +0000 (+0100) Subject: Added sample rate selector X-Git-Tag: pulseview-0.1.0~331 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=dde1a56346815349ed4e3cc1c5c63c2ffbc6c7b7;p=pulseview.git Added sample rate selector --- diff --git a/samplingbar.cpp b/samplingbar.cpp index 43b6e5e9..c411f3c1 100644 --- a/samplingbar.cpp +++ b/samplingbar.cpp @@ -18,19 +18,33 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + extern "C" { #include } +#include + #include "samplingbar.h" SamplingBar::SamplingBar(QWidget *parent) : QToolBar("Sampling Bar", parent), - _device_selector(this) + _device_selector(this), + _sample_rate_list(this) { + connect(&_device_selector, SIGNAL(currentIndexChanged (int)), + this, SLOT(on_device_selected())); + + _sample_rate_value.setDecimals(0); + _sample_rate_value.setSuffix("Hz"); + addWidget(&_device_selector); + _sample_rate_list_action = addWidget(&_sample_rate_list); + _sample_rate_value_action = addWidget(&_sample_rate_value); update_device_selector(); + update_sample_rate_selector(); } struct sr_dev_inst* SamplingBar::get_selected_device() const @@ -43,6 +57,25 @@ struct sr_dev_inst* SamplingBar::get_selected_device() const 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 = _device_selector.currentIndex(); + if(index < 0) + return 0; + + return _device_selector.itemData(index).value(); + } + + return 0; +} + void SamplingBar::update_device_selector() { GSList *devices = NULL; @@ -73,3 +106,43 @@ void SamplingBar::update_device_selector() g_slist_free(devices); } + +void SamplingBar::update_sample_rate_selector() +{ + const sr_dev_inst *const sdi = get_selected_device(); + const struct sr_samplerates *samplerates; + + assert(_sample_rate_value_action); + assert(_sample_rate_list_action); + + if (sr_info_get(sdi->driver, SR_DI_SAMPLERATES, + (const void **)&samplerates, sdi) != SR_OK) + return; + + _sample_rate_list_action->setVisible(false); + _sample_rate_value_action->setVisible(false); + + if (samplerates->step) + { + _sample_rate_value.setRange( + samplerates->low, samplerates->high); + _sample_rate_value.setSingleStep(samplerates->step); + _sample_rate_value_action->setVisible(true); + } + else + { + _sample_rate_list.clear(); + for (const uint64_t *rate = samplerates->list; + *rate; rate++) + _sample_rate_list.addItem( + sr_samplerate_string(*rate), + qVariantFromValue(*rate)); + _sample_rate_list.show(); + _sample_rate_list_action->setVisible(true); + } +} + +void SamplingBar::on_device_selected() +{ + update_sample_rate_selector(); +} diff --git a/samplingbar.h b/samplingbar.h index 99957f97..d183dabd 100644 --- a/samplingbar.h +++ b/samplingbar.h @@ -21,8 +21,14 @@ #ifndef SAMPLINGBAR_H #define SAMPLINGBAR_H +#include + #include +#include #include +#include + +class QAction; class SamplingBar : public QToolBar { @@ -32,12 +38,22 @@ public: SamplingBar(QWidget *parent); struct sr_dev_inst* get_selected_device() const; + uint64_t get_sample_rate() const; private: void update_device_selector(); + void update_sample_rate_selector(); + +private slots: + void on_device_selected(); private: QComboBox _device_selector; + + QComboBox _sample_rate_list; + QAction *_sample_rate_list_action; + QDoubleSpinBox _sample_rate_value; + QAction *_sample_rate_value_action; }; #endif // SAMPLINGBAR_H