X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fprop%2Fbinding%2Fhwcap.cpp;h=cb689879bdaa026c985a28b8245c620a9e4f315d;hp=c21d458728df3571272166fb3ff7f98f0813a05a;hb=10b1be9216fa6235d370707750dd761d786347f7;hpb=cf47ef78b6366286f6f32673ffabe0595591418d diff --git a/pv/prop/binding/hwcap.cpp b/pv/prop/binding/hwcap.cpp index c21d4587..cb689879 100644 --- a/pv/prop/binding/hwcap.cpp +++ b/pv/prop/binding/hwcap.cpp @@ -18,8 +18,15 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "hwcap.h" +#include + +using namespace boost; +using namespace std; + namespace pv { namespace prop { namespace binding { @@ -27,6 +34,120 @@ namespace binding { HwCap::HwCap(struct sr_dev_inst *sdi) : _sdi(sdi) { + const int *options; + + if ((sr_config_list(sdi->driver, SR_CONF_DEVICE_OPTIONS, + (const void **)&options, sdi) != SR_OK) || !options) + /* Driver supports no device instance options. */ + return; + + for (int cap = 0; options[cap]; cap++) { + const struct sr_config_info *const info = + sr_config_info_get(options[cap]); + + if (!info) + continue; + + switch(info->key) + { + case SR_CONF_PATTERN_MODE: + bind_stropt(info, SR_CONF_PATTERN_MODE); + break; + + case SR_CONF_BUFFERSIZE: + bind_buffer_size(info); + break; + + case SR_CONF_TIMEBASE: + bind_time_base(info); + break; + + case SR_CONF_TRIGGER_SOURCE: + bind_stropt(info, SR_CONF_TRIGGER_SOURCE); + break; + + case SR_CONF_FILTER: + bind_stropt(info, SR_CONF_FILTER); + break; + + case SR_CONF_VDIV: + bind_vdiv(info); + break; + + case SR_CONF_COUPLING: + bind_stropt(info, SR_CONF_FILTER); + break; + } + } +} + +void HwCap::expose_enum(const struct sr_config_info *info, + const vector< pair > &values, int key) +{ + _properties.push_back(shared_ptr( + new Enum(QString(info->name), values, + function(), + bind(sr_config_set, _sdi, key, _1)))); +} + +void HwCap::bind_stropt(const struct sr_config_info *info, int key) +{ + const char **stropts; + if (sr_config_list(_sdi->driver, key, + (const void **)&stropts, _sdi) != SR_OK) + return; + + vector< pair > values; + for (int i = 0; stropts[i]; i++) + values.push_back(make_pair(stropts[i], stropts[i])); + + expose_enum(info, values, key); +} + +void HwCap::bind_buffer_size(const struct sr_config_info *info) +{ + const uint64_t *sizes; + if (sr_config_list(_sdi->driver, SR_CONF_BUFFERSIZE, + (const void **)&sizes, _sdi) != SR_OK) + return; + + vector< pair > values; + for (int i = 0; sizes[i]; i++) + values.push_back(make_pair(sizes + i, + QString("%1").arg(sizes[i]))); + + expose_enum(info, values, SR_CONF_BUFFERSIZE); +} + +void HwCap::bind_time_base(const struct sr_config_info *info) +{ + struct sr_rational *timebases; + if (sr_config_list(_sdi->driver, SR_CONF_TIMEBASE, + (const void **)&timebases, _sdi) != SR_OK) + return; + + vector< pair > 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(info, values, SR_CONF_TIMEBASE); +} + +void HwCap::bind_vdiv(const struct sr_config_info *info) +{ + struct sr_rational *vdivs; + if (sr_config_list(_sdi->driver, SR_CONF_VDIV, + (const void **)&vdivs, _sdi) != SR_OK) + return; + + vector< pair > 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(info, values, SR_CONF_VDIV); } } // binding