]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/agilent-dmm/api.c
drivers: Factor out std_*_idx*().
[libsigrok.git] / src / hardware / agilent-dmm / api.c
index d38cdf0c56a0dbcd65611231fedc3a25757a2fc6..293b5f84c4336919916a113bdc08f05b737dfa42 100644 (file)
@@ -51,11 +51,7 @@ static const uint64_t samplerates[] = {
 };
 
 static const char *data_sources[] = {
-       "Live",
-       "Log-Hand",
-       "Log-Trig",
-       "Log-Auto",
-       "Log-Export",
+       "Live", "Log-Hand", "Log-Trig", "Log-Auto", "Log-Export",
 };
 
 extern const struct agdmm_job agdmm_jobs_live[];
@@ -187,8 +183,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        return std_scan_complete(di, devices);
 }
 
-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;
        int ret;
@@ -216,14 +212,12 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
        return ret;
 }
 
-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;
        uint64_t samplerate;
-       const char *tmp_str;
-       unsigned int i;
-       int ret;
+       int ret, idx;
 
        (void)cg;
 
@@ -242,17 +236,11 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        case SR_CONF_LIMIT_MSEC:
                ret = sr_sw_limits_config_set(&devc->limits, key, data);
                break;
-       case SR_CONF_DATA_SOURCE: {
-               tmp_str = g_variant_get_string(data, NULL);
-               for (i = 0; i < ARRAY_SIZE(data_sources); i++)
-                       if (!strcmp(tmp_str, data_sources[i])) {
-                               devc->data_source = i;
-                               break;
-                       }
-               if (i == ARRAY_SIZE(data_sources))
-                       return SR_ERR;
+       case SR_CONF_DATA_SOURCE:
+               if ((idx = std_str_idx(data, ARRAY_AND_SIZE(data_sources))) < 0)
+                       return SR_ERR_ARG;
+               devc->data_source = idx;
                break;
-       }
        default:
                ret = SR_ERR_NA;
        }
@@ -260,25 +248,18 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        return ret;
 }
 
-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)
 {
-       GVariant *gvar;
-       GVariantBuilder gvb;
-
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
        case SR_CONF_DEVICE_OPTIONS:
                return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
-               g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
-               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
-                               ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates_steps(ARRAY_AND_SIZE(samplerates));
                break;
        case SR_CONF_DATA_SOURCE:
-               *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
+               *data = g_variant_new_strv(ARRAY_AND_SIZE(data_sources));
                break;
        default:
                return SR_ERR_NA;