]> sigrok.org Git - pulseview.git/commitdiff
Implemented HwCap binding
authorJoel Holdsworth <redacted>
Fri, 28 Dec 2012 10:03:51 +0000 (10:03 +0000)
committerJoel Holdsworth <redacted>
Fri, 28 Dec 2012 10:19:38 +0000 (10:19 +0000)
pv/prop/binding/hwcap.cpp
pv/prop/binding/hwcap.h

index c21d458728df3571272166fb3ff7f98f0813a05a..de3c6e9d28cd24eb022bddc4e67c52ae28d29ef8 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <boost/bind.hpp>
+
 #include "hwcap.h"
 
+#include <pv/prop/enum.h>
+
+using namespace boost;
+using namespace std;
+
 namespace pv {
 namespace prop {
 namespace binding {
@@ -27,6 +34,122 @@ namespace binding {
 HwCap::HwCap(struct sr_dev_inst *sdi) :
        _sdi(sdi)
 {
+       const int *hwcaps;
+
+       if ((sr_info_get(sdi->driver, SR_DI_HWCAPS, (const void **)&hwcaps,
+                       sdi) != SR_OK) || !hwcaps)
+               /* Driver supports no device instance options. */
+               return;
+
+       for (int cap = 0; hwcaps[cap]; cap++) {
+               const struct sr_hwcap_option *const hwo =
+                       sr_devopt_get(hwcaps[cap]);
+
+               if (!hwo)
+                       continue;
+
+               switch(hwo->hwcap)
+               {
+               case SR_HWCAP_PATTERN_MODE:
+                       bind_stropt(hwo, SR_DI_PATTERNS,
+                               SR_HWCAP_PATTERN_MODE);
+                       break;
+
+               case SR_HWCAP_BUFFERSIZE:
+                       bind_buffer_size(hwo);
+                       break;
+
+               case SR_HWCAP_TIMEBASE:
+                       bind_time_base(hwo);
+                       break;
+
+               case SR_HWCAP_TRIGGER_SOURCE:
+                       bind_stropt(hwo, SR_DI_TRIGGER_SOURCES,
+                               SR_HWCAP_TRIGGER_SOURCE);
+                       break;
+
+               case SR_HWCAP_FILTER:
+                       bind_stropt(hwo, SR_DI_FILTERS, SR_HWCAP_FILTER);
+                       break;
+
+               case SR_HWCAP_VDIV:
+                       bind_vdiv(hwo);
+                       break;
+
+               case SR_HWCAP_COUPLING:
+                       bind_stropt(hwo, SR_DI_COUPLING, SR_HWCAP_FILTER);
+                       break;
+               }
+       }
+}
+
+void HwCap::expose_enum(const struct sr_hwcap_option *hwo,
+       const vector< pair<const void*, QString> > &values, int opt)
+{
+       _properties.push_back(shared_ptr<Property>(
+               new Enum(QString(hwo->shortname), values,
+                       function<const void* ()>(),
+                       bind(sr_dev_config_set, _sdi, opt, _1))));
+}
+
+void HwCap::bind_stropt(const struct sr_hwcap_option *hwo, int id, int opt)
+{
+       const char **stropts;
+       if (sr_info_get(_sdi->driver, id,
+               (const void **)&stropts, _sdi) != SR_OK)
+               return;
+
+       vector< pair<const void*, QString> > values;
+       for (int i = 0; stropts[i]; i++)
+               values.push_back(make_pair(stropts[i], stropts[i]));
+
+       expose_enum(hwo, values, opt);
+}
+
+void HwCap::bind_buffer_size(const struct sr_hwcap_option *hwo)
+{
+       const uint64_t *sizes;
+       if (sr_info_get(_sdi->driver, SR_DI_BUFFERSIZES,
+                       (const void **)&sizes, _sdi) != SR_OK)
+               return;
+
+       vector< pair<const void*, QString> > values;
+       for (int i = 0; sizes[i]; i++)
+               values.push_back(make_pair(sizes + i,
+                       QString("%1").arg(sizes[i])));
+
+       expose_enum(hwo, values, SR_HWCAP_BUFFERSIZE);
+}
+
+void HwCap::bind_time_base(const struct sr_hwcap_option *hwo)
+{
+       struct sr_rational *timebases;
+       if (sr_info_get(_sdi->driver, SR_DI_TIMEBASES,
+                       (const void **)&timebases, _sdi) != SR_OK)
+               return;
+
+       vector< pair<const void*, QString> > values;
+       for (int i = 0; timebases[i].p && timebases[i].q; i++)
+               values.push_back(make_pair(timebases + i,
+                       QString(sr_period_string(
+                               timebases[i].p * timebases[i].q))));
+
+       expose_enum(hwo, values, SR_HWCAP_TIMEBASE);
+}
+
+void HwCap::bind_vdiv(const struct sr_hwcap_option *hwo)
+{
+       struct sr_rational *vdivs;
+       if (sr_info_get(_sdi->driver, SR_DI_VDIVS,
+                       (const void **)&vdivs, _sdi) != SR_OK)
+               return;
+
+       vector< pair<const void*, QString> > values;
+       for (int i = 0; vdivs[i].p && vdivs[i].q; i++)
+               values.push_back(make_pair(vdivs + i,
+                       QString(sr_voltage_string(vdivs + i))));
+
+       expose_enum(hwo, values, SR_HWCAP_VDIV);
 }
 
 } // binding
index 6848720133f5cc533845ef5e60a3cab61fc8eecd..27c7c1eb8014148773952957d92c9c85b91315c1 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef PULSEVIEW_PV_PROP_BINDING_HWCAP_H
 #define PULSEVIEW_PV_PROP_BINDING_HWCAP_H
 
+#include <QString>
+
 extern "C" {
 #include <libsigrok/libsigrok.h>
 }
@@ -36,6 +38,18 @@ class HwCap : public Binding
 public:
        HwCap(struct sr_dev_inst *sdi);
 
+private:
+       void expose_enum(const struct sr_hwcap_option *hwo,
+               const std::vector<std::pair<const void*, QString> > &values,
+               int opt);
+
+       void bind_stropt(const struct sr_hwcap_option *hwo, int id,
+               int opt);
+
+       void bind_buffer_size(const struct sr_hwcap_option *hwo);
+       void bind_time_base(const struct sr_hwcap_option *hwo);
+       void bind_vdiv(const struct sr_hwcap_option *hwo);
+
 protected:
        const struct sr_dev_inst *_sdi;
 };