From: Joel Holdsworth Date: Sun, 3 Mar 2013 16:33:16 +0000 (+0000) Subject: Added a binding for SR_CONF_SAMPLERATE X-Git-Tag: pulseview-0.1.0~108 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=9f6af8bd3a6bc12f9b32b91cd2a173a8a7763f5c;p=pulseview.git Added a binding for SR_CONF_SAMPLERATE --- diff --git a/pv/prop/binding/deviceoptions.cpp b/pv/prop/binding/deviceoptions.cpp index bc367673..9db50dd0 100644 --- a/pv/prop/binding/deviceoptions.cpp +++ b/pv/prop/binding/deviceoptions.cpp @@ -21,9 +21,11 @@ #include #include +#include #include "deviceoptions.h" +#include #include using namespace boost; @@ -52,6 +54,10 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) : switch(info->key) { + case SR_CONF_SAMPLERATE: + bind_samplerate(info); + break; + case SR_CONF_PATTERN_MODE: bind_stropt(info, SR_CONF_PATTERN_MODE); break; @@ -88,7 +94,7 @@ void DeviceOptions::expose_enum(const struct sr_config_info *info, { _properties.push_back(shared_ptr( new Enum(QString(info->name), values, - bind(getter, _sdi, key), + bind(enum_getter, _sdi, key), bind(sr_config_set, _sdi, key, _1)))); } @@ -107,6 +113,38 @@ void DeviceOptions::bind_stropt( expose_enum(info, values, key); } +void DeviceOptions::bind_samplerate(const struct sr_config_info *info) +{ + const struct sr_samplerates *samplerates; + + if (sr_config_list(_sdi->driver, SR_CONF_SAMPLERATE, + (const void **)&samplerates, _sdi) != SR_OK) + return; + + if (samplerates->step) { + _properties.push_back(shared_ptr( + new Double(QString(info->name), + 0, QObject::tr("Hz"), + make_pair((double)samplerates->low, + (double)samplerates->high), + (double)samplerates->step, + bind(samplerate_value_getter, _sdi), + bind(samplerate_value_setter, _sdi, _1)))); + } else { + vector< pair > values; + for (const uint64_t *rate = samplerates->list; + *rate; rate++) + values.push_back(make_pair( + (const void*)rate, + QString(sr_samplerate_string(*rate)))); + + _properties.push_back(shared_ptr( + new Enum(QString(info->name), values, + bind(samplerate_list_getter, _sdi), + bind(samplerate_list_setter, _sdi, _1)))); + } +} + void DeviceOptions::bind_buffer_size(const struct sr_config_info *info) { const uint64_t *sizes; @@ -165,6 +203,66 @@ const void* DeviceOptions::enum_getter( return data; } +double DeviceOptions::samplerate_value_getter( + const struct sr_dev_inst *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 0.0; + } + return (double)*samplerate; +} + +void DeviceOptions::samplerate_value_setter( + struct sr_dev_inst *sdi, double value) +{ + uint64_t samplerate = value; + if(sr_config_set(sdi, SR_CONF_SAMPLERATE, + &samplerate) != SR_OK) + qDebug() << + "WARNING: Failed to set value of sample rate"; +} + +const void* DeviceOptions::samplerate_list_getter( + const struct sr_dev_inst *sdi) +{ + const struct sr_samplerates *samplerates; + uint64_t *samplerate = NULL; + + if (sr_config_list(sdi->driver, SR_CONF_SAMPLERATE, + (const void **)&samplerates, sdi) != SR_OK) { + qDebug() << + "WARNING: Failed to get enumerate sample rates"; + return NULL; + } + + if(sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, + (const void**)&samplerate, sdi) != SR_OK || + !samplerate) { + qDebug() << + "WARNING: Failed to get value of sample rate"; + return NULL; + } + + for (const uint64_t *rate = samplerates->list; *rate; rate++) + if(*rate == *samplerate) + return (const void*)rate; + + return NULL; +} + +void DeviceOptions::samplerate_list_setter( + struct sr_dev_inst *sdi, const void *value) +{ + if (sr_config_set(sdi, SR_CONF_SAMPLERATE, + (uint64_t*)value) != SR_OK) + qDebug() << + "WARNING: Failed to set value of sample rate"; +} + } // binding } // prop } // pv diff --git a/pv/prop/binding/deviceoptions.h b/pv/prop/binding/deviceoptions.h index b622d937..23db4f71 100644 --- a/pv/prop/binding/deviceoptions.h +++ b/pv/prop/binding/deviceoptions.h @@ -43,6 +43,7 @@ private: void bind_stropt(const struct sr_config_info *info, int key); + void bind_samplerate(const struct sr_config_info *info); void bind_buffer_size(const struct sr_config_info *info); void bind_time_base(const struct sr_config_info *info); void bind_vdiv(const struct sr_config_info *info); @@ -51,6 +52,16 @@ private: static const void* enum_getter( const struct sr_dev_inst *sdi, int key); + static double samplerate_value_getter( + const struct sr_dev_inst *sdi); + static void samplerate_value_setter( + struct sr_dev_inst *sdi, double value); + + static const void* samplerate_list_getter( + const struct sr_dev_inst *sdi); + static void samplerate_list_setter( + struct sr_dev_inst *sdi, const void* value); + protected: struct sr_dev_inst *const _sdi; }; diff --git a/pv/prop/double.cpp b/pv/prop/double.cpp index fdd9a44c..d7c79ca7 100644 --- a/pv/prop/double.cpp +++ b/pv/prop/double.cpp @@ -61,6 +61,8 @@ QWidget* Double::get_widget(QWidget *parent) if(_step) _spin_box->setSingleStep(*_step); + _spin_box->setValue(_getter ? _getter() : 0.0); + return _spin_box; }