X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fatten-pps3xxx%2Fapi.c;h=f08671fb1081b28083601d0113c7afad8b4a0ccd;hb=8f484ca78ef8603f854ad80df02f251631dc1330;hp=1a783b7a456cd75455918ce5c034d9066d2f986c;hpb=53012da658ae94b245240c8a3e115723eede4c7d;p=libsigrok.git diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 1a783b7a..f08671fb 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -182,8 +182,8 @@ static GSList *scan_3203(struct sr_dev_driver *di, GSList *options) return scan(di, options, PPS_3203T_3S); } -static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_get(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; struct sr_channel *ch; @@ -234,56 +234,33 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s return SR_OK; } -static int find_str(const char *str, const char **strings, int array_size) -{ - int idx, i; - - idx = -1; - for (i = 0; i < array_size; i++) { - if (!strcmp(str, strings[i])) { - idx = i; - break; - } - } - - return idx; -} - -static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_set(uint32_t key, GVariant *data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; struct sr_channel *ch; gdouble dval; - int channel, ret, ival; - const char *sval; + int channel, ival; gboolean bval; - ret = SR_OK; devc = sdi->priv; + if (!cg) { switch (key) { case SR_CONF_CHANNEL_CONFIG: - sval = g_variant_get_string(data, NULL); - if ((ival = find_str(sval, ARRAY_AND_SIZE(channel_modes))) == -1) { - ret = SR_ERR_ARG; - break; - } - if (devc->model->channel_modes && (1 << ival) == 0) { - /* Not supported on this model. */ - ret = SR_ERR_ARG; - } + if ((ival = std_str_idx(data, ARRAY_AND_SIZE(channel_modes))) < 0) + return SR_ERR_ARG; + if (devc->model->channel_modes && (1 << ival) == 0) + return SR_ERR_ARG; /* Not supported on this model. */ if (ival == devc->channel_mode_set) - /* Nothing to do. */ - break; + break; /* Nothing to do. */ devc->channel_mode_set = ival; devc->config_dirty = TRUE; break; case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: bval = g_variant_get_boolean(data); if (bval == devc->over_current_protection_set) - /* Nothing to do. */ - break; + break; /* Nothing to do. */ devc->over_current_protection_set = bval; devc->config_dirty = TRUE; break; @@ -299,35 +276,34 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd case SR_CONF_VOLTAGE_TARGET: dval = g_variant_get_double(data); if (dval < 0 || dval > devc->model->channels[channel].voltage[1]) - ret = SR_ERR_ARG; + return SR_ERR_ARG; devc->config[channel].output_voltage_max = dval; devc->config_dirty = TRUE; break; case SR_CONF_CURRENT_LIMIT: dval = g_variant_get_double(data); if (dval < 0 || dval > devc->model->channels[channel].current[1]) - ret = SR_ERR_ARG; + return SR_ERR_ARG; devc->config[channel].output_current_max = dval; devc->config_dirty = TRUE; break; case SR_CONF_ENABLED: bval = g_variant_get_boolean(data); if (bval == devc->config[channel].output_enabled_set) - /* Nothing to do. */ - break; + break; /* Nothing to do. */ devc->config[channel].output_enabled_set = bval; devc->config_dirty = TRUE; break; default: - ret = SR_ERR_NA; + return SR_ERR_NA; } } - return ret; + return SR_OK; } -static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +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; struct sr_channel *ch;