void DeviceOptions::bind_samplerate(const QString &name,
	GVariant *const gvar_list)
{
	GVariant *gvar_list_samplerates;

	assert(gvar_list);

	if ((gvar_list_samplerates = g_variant_lookup_value(gvar_list,
			"samplerate-steps", G_VARIANT_TYPE("at"))))
	{
		gsize num_elements;
		const uint64_t *const elements =
			(const uint64_t *)g_variant_get_fixed_array(
				gvar_list_samplerates, &num_elements, sizeof(uint64_t));

		assert(num_elements == 3);

		_properties.push_back(boost::shared_ptr<Property>(
			new Double(name, 0, QObject::tr("Hz"),
				make_pair((double)elements[0], (double)elements[1]),
						(double)elements[2],
				bind(samplerate_double_getter, _sdi),
				bind(samplerate_double_setter, _sdi, _1))));

		g_variant_unref(gvar_list_samplerates);
	}
	else if ((gvar_list_samplerates = g_variant_lookup_value(gvar_list,
			"samplerates", G_VARIANT_TYPE("at"))))
	{
		bind_enum(name, SR_CONF_SAMPLERATE,
			gvar_list_samplerates, print_samplerate);
		g_variant_unref(gvar_list_samplerates);
	}
}
Beispiel #2
0
Decoder::Decoder(
	shared_ptr<pv::data::DecoderStack> decoder_stack,
	shared_ptr<data::decode::Decoder> decoder) :
	decoder_stack_(decoder_stack),
	decoder_(decoder)
{
	assert(decoder_);

	const srd_decoder *const dec = decoder_->decoder();
	assert(dec);

	for (GSList *l = dec->options; l; l = l->next) {
		const srd_decoder_option *const opt =
			(srd_decoder_option*)l->data;

		const QString name = QString::fromUtf8(opt->desc);

		const Property::Getter get = [&, opt]() {
			return getter(opt->id); };
		const Property::Setter set = [&, opt](Glib::VariantBase value) {
			setter(opt->id, value); };

		shared_ptr<Property> prop;

		if (opt->values)
			prop = bind_enum(name, "", opt, get, set);
		else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("d")))
			prop = shared_ptr<Property>(new Double(name, "", 2, "",
				none, none, get, set));
		else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x")))
			prop = shared_ptr<Property>(
				new Int(name, "", "", none, get, set));
		else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s")))
			prop = shared_ptr<Property>(
				new String(name, "", get, set));
		else
			continue;

		properties_.push_back(prop);
	}
}
Beispiel #3
0
DeviceOptions::DeviceOptions(shared_ptr<pv::device::DevInst> dev_inst,
	const sr_channel_group *group) :
	_dev_inst(dev_inst),
	_group(group)
{
	assert(dev_inst);

	GVariant *gvar_opts;
	gsize num_opts;

	if (!(gvar_opts = dev_inst->list_config(group, SR_CONF_DEVICE_OPTIONS)))
		/* Driver supports no device instance options. */
		return;

	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[i]);

		if (!info)
			continue;

		const int key = info->key;
		GVariant *const gvar_list = dev_inst->list_config(group, key);

		const QString name = QString::fromUtf8(info->name);

		const Property::Getter get = [&, key]() {
			return _dev_inst->get_config(_group, key); };
		const Property::Setter set = [&, key](GVariant *value) {
			_dev_inst->set_config(_group, key, value); };

		switch(key)
		{
		case SR_CONF_SAMPLERATE:
			// Sample rate values are not bound because they are shown
			// in the SamplingBar
			break;

		case SR_CONF_CAPTURE_RATIO:
			bind_int(name, "%", pair<int64_t, int64_t>(0, 100),
				get, set);
			break;

		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, get, set);
			break;

		case SR_CONF_EXTERNAL_CLOCK:
		case SR_CONF_RLE:
			bind_bool(name, get, set);
			break;

		case SR_CONF_TIMEBASE:
			bind_enum(name, key, gvar_list,
				get, set, print_timebase);
			break;

		case SR_CONF_VDIV:
			bind_enum(name, key, gvar_list, get, set, print_vdiv);
			break;

		case SR_CONF_VOLTAGE_THRESHOLD:
			bind_enum(name, key, gvar_list,
				get, set, print_voltage_threshold);
			break;
		}

		if (gvar_list)
			g_variant_unref(gvar_list);
	}
	g_variant_unref(gvar_opts);
}
DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) :
	_sdi(sdi)
{
	GVariant *gvar_opts, *gvar_list;
	gsize num_opts;

    if ((sr_config_list(sdi->driver, SR_CONF_DEVICE_CONFIGS,
		&gvar_opts, sdi) != SR_OK))
		/* Driver supports no device instance options. */
		return;

	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[i]);

		if (!info)
			continue;

		const int key = info->key;

		if(sr_config_list(_sdi->driver, key, &gvar_list, _sdi) != SR_OK)
			gvar_list = NULL;

		const QString name(info->name);

		switch(key)
		{
		case SR_CONF_SAMPLERATE:
			bind_samplerate(name, gvar_list);
			break;

		case SR_CONF_CAPTURE_RATIO:
			bind_int(name, key, "%", pair<int64_t, int64_t>(0, 100));
			break;

        case SR_CONF_DEVICE_MODE:
		case SR_CONF_PATTERN_MODE:
		case SR_CONF_BUFFERSIZE:
		case SR_CONF_TRIGGER_SOURCE:
		case SR_CONF_FILTER:
		case SR_CONF_COUPLING:
			bind_enum(name, key, gvar_list);
			break;

		case SR_CONF_RLE:
			bind_bool(name, key);
			break;

        case SR_CONF_CLOCK_TYPE:
            bind_bool(name, key);
            break;

		case SR_CONF_TIMEBASE:
			bind_enum(name, key, gvar_list, print_timebase);
			break;

		case SR_CONF_VDIV:
			bind_enum(name, key, gvar_list, print_vdiv);
			break;
		}

		if (gvar_list)
			g_variant_unref(gvar_list);
	}
	g_variant_unref(gvar_opts);
}
DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) :
	_sdi(sdi)
{
	GVariant *gvar_opts, *gvar_list;
	gsize num_opts;

    if ((sr_config_list(sdi->driver, sdi, NULL, SR_CONF_DEVICE_CONFIGS,
        &gvar_opts) != SR_OK))
		/* Driver supports no device instance options. */
		return;

	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[i]);

		if (!info)
			continue;

		const int key = info->key;

        if(sr_config_list(_sdi->driver, _sdi, NULL, key, &gvar_list) != SR_OK)
			gvar_list = NULL;

        const QString name(info->label);

		switch(key)
		{
		case SR_CONF_SAMPLERATE:
			bind_samplerate(name, gvar_list);
			break;

		case SR_CONF_CAPTURE_RATIO:
			bind_int(name, key, "%", pair<int64_t, int64_t>(0, 100));
			break;

		case SR_CONF_PATTERN_MODE:
		case SR_CONF_BUFFERSIZE:
		case SR_CONF_TRIGGER_SOURCE:
		case SR_CONF_FILTER:
        case SR_CONF_COUPLING:
        case SR_CONF_EN_CH:
        case SR_CONF_OPERATION_MODE:
        case SR_CONF_THRESHOLD:
        case SR_CONF_ZERO:
        case SR_CONF_STREAM:
        case SR_CONF_TEST:
        case SR_CONF_STATUS:
        case SR_CONF_FACTOR:
			bind_enum(name, key, gvar_list);
			break;

        case SR_CONF_VTH:
            bind_double(name, key, "V", pair<double, double>(0.0, 5.0), 1, 0.1);
            break;

		case SR_CONF_RLE:
			bind_bool(name, key);
			break;

        case SR_CONF_CLOCK_TYPE:
        case SR_CONF_CLOCK_EDGE:
        case SR_CONF_INSTANT:
        case SR_CONF_DATALOCK:
            bind_bool(name, key);
            break;

		case SR_CONF_TIMEBASE:
			bind_enum(name, key, gvar_list, print_timebase);
			break;

        case SR_CONF_VDIV:
			bind_enum(name, key, gvar_list, print_vdiv);
            break;
        default:
            gvar_list = NULL;
		}

		if (gvar_list)
			g_variant_unref(gvar_list);
	}
	g_variant_unref(gvar_opts);
}