]> sigrok.org Git - pulseview.git/commitdiff
Added a binding for SR_CONF_SAMPLERATE
authorJoel Holdsworth <redacted>
Sun, 3 Mar 2013 16:33:16 +0000 (16:33 +0000)
committerJoel Holdsworth <redacted>
Sun, 3 Mar 2013 18:15:31 +0000 (18:15 +0000)
pv/prop/binding/deviceoptions.cpp
pv/prop/binding/deviceoptions.h
pv/prop/double.cpp

index bc367673ed44330e8b89e0e32ae7b495d95dd3bc..9db50dd0548f55c7fd2eeb11bd7ddd52846cc83f 100644 (file)
 #include <boost/bind.hpp>
 
 #include <QDebug>
+#include <QObject>
 
 #include "deviceoptions.h"
 
+#include <pv/prop/double.h>
 #include <pv/prop/enum.h>
 
 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<Property>(
                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<Property>(
+                       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<const void*, QString> > 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<Property>(
+                       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
index b622d9379665a014283bb05eea7799907bd97910..23db4f719bf4cec09812f01db01e859103f54000 100644 (file)
@@ -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;
 };
index fdd9a44c06828ff64cf44d67a1b29e4b18268b99..d7c79ca7db19ce6481d3b8293c06848fcd5364d0 100644 (file)
@@ -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;
 }