drivers: Factor out std_gvar_min_max_step{,_array}().
This commit is contained in:
parent
463160cbca
commit
54d471f498
|
@ -150,8 +150,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
|||
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 {
|
||||
|
@ -161,12 +159,7 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
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;
|
||||
|
|
|
@ -332,9 +332,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
{
|
||||
struct dev_context *devc;
|
||||
struct sr_channel *ch;
|
||||
GVariant *gvar;
|
||||
GVariantBuilder gvb;
|
||||
int channel, i;
|
||||
int channel;
|
||||
|
||||
devc = (sdi) ? sdi->priv : NULL;
|
||||
|
||||
|
@ -366,22 +364,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
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;
|
||||
|
|
|
@ -271,10 +271,6 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
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;
|
||||
|
||||
|
@ -283,24 +279,10 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
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;
|
||||
|
|
|
@ -266,11 +266,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
|||
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;
|
||||
|
||||
|
@ -279,30 +276,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
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;
|
||||
|
|
|
@ -360,7 +360,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
const struct sr_channel_group *cg)
|
||||
{
|
||||
struct dev_context *devc;
|
||||
GVariantBuilder gvb;
|
||||
|
||||
devc = (sdi) ? sdi->priv : NULL;
|
||||
|
||||
|
@ -373,20 +372,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
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;
|
||||
|
|
|
@ -652,9 +652,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
{
|
||||
struct dev_context *devc;
|
||||
struct sr_channel *ch;
|
||||
int ch_idx, i;
|
||||
GVariant *gvar;
|
||||
GVariantBuilder gvb;
|
||||
int ch_idx;
|
||||
|
||||
devc = (sdi) ? sdi->priv : NULL;
|
||||
|
||||
|
@ -691,22 +689,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
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;
|
||||
|
|
|
@ -514,8 +514,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
struct dev_context *devc;
|
||||
struct sr_channel *ch;
|
||||
const struct channel_spec *ch_spec;
|
||||
GVariant *gvar;
|
||||
GVariantBuilder gvb;
|
||||
int i;
|
||||
const char *s[16];
|
||||
|
||||
|
@ -560,6 +558,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
* 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:
|
||||
|
@ -568,34 +567,13 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
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;
|
||||
|
|
|
@ -960,6 +960,8 @@ SR_PRIV GVariant *std_gvar_tuple_array(const uint64_t (*a)[][2], unsigned int n)
|
|||
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 ------------------------------------------------------------*/
|
||||
|
|
26
src/std.c
26
src/std.c
|
@ -601,3 +601,29 @@ SR_PRIV GVariant *std_gvar_samplerates_steps(const uint64_t samplerates[], unsig
|
|||
{
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue