]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/uni-t-ut32x/api.c
drivers: Factor out std_*_idx*().
[libsigrok.git] / src / hardware / uni-t-ut32x / api.c
index f51249931c211360ffd755a00bb6178c68d70c37..8c11497582c480057600c16f48f741bdb95901d4 100644 (file)
@@ -74,8 +74,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                for (l = usb_devices; l; l = l->next) {
                        sdi = g_malloc0(sizeof(struct sr_dev_inst));
                        sdi->status = SR_ST_INACTIVE;
-                       sdi->vendor = g_strdup(VENDOR);
-                       sdi->model = g_strdup(MODEL);
+                       sdi->vendor = g_strdup("UNI-T");
+                       sdi->model = g_strdup("UT32x");
                        sdi->inst_type = SR_INST_USB;
                        sdi->conn = l->data;
                        for (i = 0; i < ARRAY_SIZE(channel_names); i++)
@@ -149,8 +149,8 @@ static int dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-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;
 
@@ -174,11 +174,11 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
        return SR_OK;
 }
 
-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;
-       const char *tmp_str;
+       int idx;
 
        (void)cg;
 
@@ -189,13 +189,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                devc->limit_samples = g_variant_get_uint64(data);
                break;
        case SR_CONF_DATA_SOURCE:
-               tmp_str = g_variant_get_string(data, NULL);
-               if (!strcmp(tmp_str, "Live"))
-                       devc->data_source = DATA_SOURCE_LIVE;
-               else if (!strcmp(tmp_str, "Memory"))
-                       devc->data_source = DATA_SOURCE_MEMORY;
-               else
-                       return SR_ERR;
+               if ((idx = std_str_idx(data, ARRAY_AND_SIZE(data_sources))) < 0)
+                       return SR_ERR_ARG;
+               devc->data_source = idx;
                break;
        default:
                return SR_ERR_NA;
@@ -204,8 +200,8 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        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)
 {
        switch (key) {
        case SR_CONF_SCAN_OPTIONS: