X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fprop%2Fbinding%2Fdeviceoptions.cpp;h=39e12816fd2e3243c22bfeaaea4ca0410235b179;hp=b6f2f13605e54b15a34330637e0cf53cf82d44e7;hb=d23445348bf04a698e062a3b917360313ecbcaad;hpb=3820592a018c777727a6e65bd754d113742f4462 diff --git a/pv/prop/binding/deviceoptions.cpp b/pv/prop/binding/deviceoptions.cpp index b6f2f136..39e12816 100644 --- a/pv/prop/binding/deviceoptions.cpp +++ b/pv/prop/binding/deviceoptions.cpp @@ -20,135 +20,170 @@ #include +#include + +#include + #include "deviceoptions.h" +#include +#include +#include #include +#include -using namespace boost; -using namespace std; +#include + +using boost::bind; +using std::function; +using boost::optional; +using std::make_pair; +using std::pair; +using std::shared_ptr; +using std::string; +using std::vector; namespace pv { namespace prop { namespace binding { -DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) : - _sdi(sdi) +DeviceOptions::DeviceOptions(shared_ptr dev_inst, + const sr_channel_group *group) : + _dev_inst(dev_inst), + _group(group) { - const int *options; + assert(dev_inst); + + GVariant *gvar_opts; + gsize num_opts; - if ((sr_config_list(sdi->driver, SR_CONF_DEVICE_OPTIONS, - (const void **)&options, sdi) != SR_OK) || !options) + if (!(gvar_opts = dev_inst->list_config(group, SR_CONF_DEVICE_OPTIONS))) /* Driver supports no device instance options. */ return; - for (int cap = 0; options[cap]; cap++) { + const int *const options = (const int32_t *)g_variant_get_fixed_array( + gvar_opts, &num_opts, sizeof(int32_t)); + for (unsigned int i = 0; i < num_opts; i++) { const struct sr_config_info *const info = - sr_config_info_get(options[cap]); + sr_config_info_get(options[i]); if (!info) continue; - switch(info->key) + const int key = info->key; + GVariant *const gvar_list = dev_inst->list_config(group, key); + + const QString name = QString::fromUtf8(info->name); + + switch(key) { - case SR_CONF_PATTERN_MODE: - bind_stropt(info, SR_CONF_PATTERN_MODE); + case SR_CONF_SAMPLERATE: + // Sample rate values are not bound because they are shown + // in the SamplingBar break; - case SR_CONF_BUFFERSIZE: - bind_buffer_size(info); + case SR_CONF_CAPTURE_RATIO: + bind_int(name, key, "%", pair(0, 100)); break; - case SR_CONF_TIMEBASE: - bind_time_base(info); + case SR_CONF_PATTERN_MODE: + case SR_CONF_BUFFERSIZE: + case SR_CONF_TRIGGER_SOURCE: + case SR_CONF_TRIGGER_SLOPE: + case SR_CONF_FILTER: + case SR_CONF_COUPLING: + case SR_CONF_CLOCK_EDGE: + bind_enum(name, key, gvar_list); break; - case SR_CONF_TRIGGER_SOURCE: - bind_stropt(info, SR_CONF_TRIGGER_SOURCE); + case SR_CONF_EXTERNAL_CLOCK: + case SR_CONF_RLE: + bind_bool(name, key); break; - case SR_CONF_FILTER: - bind_stropt(info, SR_CONF_FILTER); + case SR_CONF_TIMEBASE: + bind_enum(name, key, gvar_list, print_timebase); break; case SR_CONF_VDIV: - bind_vdiv(info); + bind_enum(name, key, gvar_list, print_vdiv); break; - case SR_CONF_COUPLING: - bind_stropt(info, SR_CONF_FILTER); + case SR_CONF_VOLTAGE_THRESHOLD: + bind_enum(name, key, gvar_list, print_voltage_threshold); break; } + + if (gvar_list) + g_variant_unref(gvar_list); } + g_variant_unref(gvar_opts); } -void DeviceOptions::expose_enum(const struct sr_config_info *info, - const vector< pair > &values, int key) +void DeviceOptions::bind_bool(const QString &name, int key) { - _properties.push_back(shared_ptr( - new Enum(QString(info->name), values, - function(), - bind(sr_config_set, _sdi, key, _1)))); + assert(_dev_inst); + _properties.push_back(shared_ptr(new Bool(name, + bind(&device::DevInst::get_config, _dev_inst, _group, key), + bind(&device::DevInst::set_config, _dev_inst, + _group, key, _1)))); } -void DeviceOptions::bind_stropt( - const struct sr_config_info *info, int key) +void DeviceOptions::bind_enum(const QString &name, int key, + GVariant *const gvar_list, function printer) { - const char **stropts; - if (sr_config_list(_sdi->driver, key, - (const void **)&stropts, _sdi) != SR_OK) + GVariant *gvar; + GVariantIter iter; + vector< pair > values; + + assert(_dev_inst); + if (!gvar_list) { + qDebug() << "Config key " << key << " was listed, but no " + "options were given"; return; + } - vector< pair > values; - for (int i = 0; stropts[i]; i++) - values.push_back(make_pair(stropts[i], stropts[i])); + g_variant_iter_init (&iter, gvar_list); + while ((gvar = g_variant_iter_next_value (&iter))) + values.push_back(make_pair(gvar, printer(gvar))); - expose_enum(info, values, key); + _properties.push_back(shared_ptr(new Enum(name, values, + bind(&device::DevInst::get_config, _dev_inst, _group, key), + bind(&device::DevInst::set_config, _dev_inst, + _group, key, _1)))); } -void DeviceOptions::bind_buffer_size(const struct sr_config_info *info) +void DeviceOptions::bind_int(const QString &name, int key, QString suffix, + optional< std::pair > range) { - 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]))); + assert(_dev_inst); - expose_enum(info, values, SR_CONF_BUFFERSIZE); + _properties.push_back(shared_ptr(new Int(name, suffix, range, + bind(&device::DevInst::get_config, _dev_inst, _group, key), + bind(&device::DevInst::set_config, _dev_inst, _group, key, _1)))); } -void DeviceOptions::bind_time_base(const struct sr_config_info *info) +QString DeviceOptions::print_timebase(GVariant *const gvar) { - 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); + uint64_t p, q; + g_variant_get(gvar, "(tt)", &p, &q); + return QString::fromUtf8(sr_period_string(p * q)); } -void DeviceOptions::bind_vdiv(const struct sr_config_info *info) +QString DeviceOptions::print_vdiv(GVariant *const gvar) { - 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)))); + uint64_t p, q; + g_variant_get(gvar, "(tt)", &p, &q); + return QString::fromUtf8(sr_voltage_string(p, q)); +} - expose_enum(info, values, SR_CONF_VDIV); +QString DeviceOptions::print_voltage_threshold(GVariant *const gvar) +{ + gdouble lo, hi; + char buf[64]; + g_variant_get(gvar, "(dd)", &lo, &hi); + snprintf(buf, sizeof(buf), "L<%.1fV H>%.1fV", lo, hi); + return QString::fromUtf8(buf); } } // binding