static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
- GVariantBuilder gvb;
-
if (!cg) {
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
} else {
devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
break;
case SR_CONF_CURRENT_LIMIT:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- g_variant_builder_add_value(&gvb, g_variant_new_double(0.0));
- g_variant_builder_add_value(&gvb, g_variant_new_double(6.0));
- g_variant_builder_add_value(&gvb, g_variant_new_double(0.001)); /* 1mA steps */
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step(0.0, 6.0, 0.001);
break;
default:
return SR_ERR_NA;
{
struct dev_context *devc;
struct sr_channel *ch;
- GVariant *gvar;
- GVariantBuilder gvb;
- int channel, i;
+ int channel;
devc = (sdi) ? sdi->priv : NULL;
devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
break;
case SR_CONF_VOLTAGE_TARGET:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (i = 0; i < 3; i++) {
- gvar = g_variant_new_double(devc->model->channels[channel].voltage[i]);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step_array(devc->model->channels[channel].voltage);
break;
case SR_CONF_CURRENT_LIMIT:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (i = 0; i < 3; i++) {
- gvar = g_variant_new_double(devc->model->channels[channel].current[i]);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step_array(devc->model->channels[channel].current);
break;
default:
return SR_ERR_NA;
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
- GVariant *gvar;
- GVariantBuilder gvb;
- double dval;
- int idx;
devc = (sdi) ? sdi->priv : NULL;
case SR_CONF_DEVICE_OPTIONS:
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_VOLTAGE_TARGET:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (idx = 0; idx < 3; idx++) {
- dval = devc->model->voltage[idx];
- gvar = g_variant_new_double(dval);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step_array(devc->model->voltage);
break;
case SR_CONF_CURRENT_LIMIT:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (idx = 0; idx < 3; idx++) {
- dval = devc->model->current[idx];
- gvar = g_variant_new_double(dval);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step_array(devc->model->current);
break;
default:
return SR_ERR_NA;
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
+ const double *a;
struct dev_context *devc;
- GVariant *gvar;
- GVariantBuilder gvb;
- double dval;
- int idx;
devc = (sdi) ? sdi->priv : NULL;
case SR_CONF_DEVICE_OPTIONS:
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_VOLTAGE_TARGET:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (idx = 0; idx < 3; idx++) {
- if (idx == 1)
- dval = devc->voltage_max_device;
- else
- dval = devc->model->voltage[idx];
- gvar = g_variant_new_double(dval);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ a = devc->model->voltage;
+ *data = std_gvar_min_max_step(a[0], devc->voltage_max_device, a[2]);
break;
case SR_CONF_CURRENT_LIMIT:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (idx = 0; idx < 3; idx++) {
- if (idx == 1)
- dval = devc->current_max_device;
- else
- dval = devc->model->current[idx];
- gvar = g_variant_new_double(dval);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ a = devc->model->current;
+ *data = std_gvar_min_max_step(a[0], devc->current_max_device, a[2]);
break;
default:
return SR_ERR_NA;
const struct sr_channel_group *cg)
{
struct dev_context *devc;
- GVariantBuilder gvb;
devc = (sdi) ? sdi->priv : NULL;
devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
break;
case SR_CONF_VOLTAGE_TARGET:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, write resolution. */
- g_variant_builder_add_value(&gvb, g_variant_new_double(0.0));
- g_variant_builder_add_value(&gvb, g_variant_new_double(devc->model->max_voltage));
- g_variant_builder_add_value(&gvb, g_variant_new_double(0.001));
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step(0.0, devc->model->max_voltage, 0.001);
break;
case SR_CONF_CURRENT_LIMIT:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- g_variant_builder_add_value(&gvb, g_variant_new_double(0.0));
- g_variant_builder_add_value(&gvb, g_variant_new_double(devc->model->max_current));
- g_variant_builder_add_value(&gvb, g_variant_new_double(0.0001));
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step(0.0, devc->model->max_current, 0.0001);
break;
default:
return SR_ERR_NA;
{
struct dev_context *devc;
struct sr_channel *ch;
- int ch_idx, i;
- GVariant *gvar;
- GVariantBuilder gvb;
+ int ch_idx;
devc = (sdi) ? sdi->priv : NULL;
devopts_cg_ch3, ARRAY_SIZE(devopts_cg_ch3), sizeof(uint32_t));
break;
case SR_CONF_VOLTAGE_TARGET:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (i = 0; i < 3; i++) {
- gvar = g_variant_new_double(devc->model->channels[ch_idx].voltage[i]);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step_array(devc->model->channels[ch_idx].voltage);
break;
case SR_CONF_CURRENT_LIMIT:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (i = 0; i < 3; i++) {
- gvar = g_variant_new_double(devc->model->channels[ch_idx].current[i]);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step_array(devc->model->channels[ch_idx].current);
break;
default:
return SR_ERR_NA;
struct dev_context *devc;
struct sr_channel *ch;
const struct channel_spec *ch_spec;
- GVariant *gvar;
- GVariantBuilder gvb;
int i;
const char *s[16];
* specification for use in series or parallel mode.
*/
ch = cg->channels->data;
+ ch_spec = &(devc->device->channels[ch->index]);
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
sizeof(uint32_t));
break;
case SR_CONF_VOLTAGE_TARGET:
- ch_spec = &(devc->device->channels[ch->index]);
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, write resolution. */
- for (i = 0; i < 3; i++) {
- gvar = g_variant_new_double(ch_spec->voltage[i]);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step_array(ch_spec->voltage);
break;
case SR_CONF_OUTPUT_FREQUENCY_TARGET:
- ch_spec = &(devc->device->channels[ch->index]);
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, write resolution. */
- for (i = 0; i < 3; i++) {
- gvar = g_variant_new_double(ch_spec->frequency[i]);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step_array(ch_spec->frequency);
break;
case SR_CONF_CURRENT_LIMIT:
- g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
- /* Min, max, step. */
- for (i = 0; i < 3; i++) {
- ch_spec = &(devc->device->channels[ch->index]);
- gvar = g_variant_new_double(ch_spec->current[i]);
- g_variant_builder_add_value(&gvb, gvar);
- }
- *data = g_variant_builder_end(&gvb);
+ *data = std_gvar_min_max_step_array(ch_spec->current);
break;
default:
return SR_ERR_NA;
SR_PRIV GVariant *std_gvar_tuple_rational(const struct sr_rational *r, unsigned int n);
SR_PRIV GVariant *std_gvar_samplerates(const uint64_t samplerates[], unsigned int n);
SR_PRIV GVariant *std_gvar_samplerates_steps(const uint64_t samplerates[], unsigned int n);
+SR_PRIV GVariant *std_gvar_min_max_step(double min, double max, double step);
+SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3]);
/*--- resource.c ------------------------------------------------------------*/
{
return samplerate_helper(samplerates, n, "samplerate-steps");
}
+
+SR_PRIV GVariant *std_gvar_min_max_step(double min, double max, double step)
+{
+ GVariantBuilder gvb;
+
+ g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
+
+ g_variant_builder_add_value(&gvb, g_variant_new_double(min));
+ g_variant_builder_add_value(&gvb, g_variant_new_double(max));
+ g_variant_builder_add_value(&gvb, g_variant_new_double(step));
+
+ return g_variant_builder_end(&gvb);
+}
+
+SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3])
+{
+ unsigned int i;
+ GVariantBuilder gvb;
+
+ g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
+
+ for (i = 0; i < 3; i++)
+ g_variant_builder_add_value(&gvb, g_variant_new_double(a[i]));
+
+ return g_variant_builder_end(&gvb);
+}