]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-dso/api.c
drivers: Use g_variant_new_printf() where possible.
[libsigrok.git] / src / hardware / hantek-dso / api.c
index f00d8b6c9bbb248eb065f06651434b3e9d4a6fd3..22788e0eb6f14a8722e44c1eeda95ca4ae14fc2e 100644 (file)
@@ -144,21 +144,16 @@ static const uint64_t vdivs[][2] = {
 };
 
 static const char *trigger_sources[] = {
-       "CH1",
-       "CH2",
-       "EXT",
+       "CH1", "CH2", "EXT",
        /* TODO: forced */
 };
 
 static const char *trigger_slopes[] = {
-       "r",
-       "f",
+       "r", "f",
 };
 
 static const char *coupling[] = {
-       "AC",
-       "DC",
-       "GND",
+       "AC", "DC", "GND",
 };
 
 static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof)
@@ -397,12 +392,11 @@ 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;
        struct sr_usb_dev_inst *usb;
-       char str[128];
        const char *s;
        const uint64_t *vdiv;
        int ch_idx;
@@ -430,8 +424,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                                /* Device still needs to re-enumerate after firmware
                                 * upload, so we don't know its (future) address. */
                                return SR_ERR;
-                       snprintf(str, 128, "%d.%d", usb->bus, usb->address);
-                       *data = g_variant_new_string(str);
+                       *data = g_variant_new_printf("%d.%d", usb->bus, usb->address);
                        break;
                case SR_CONF_TIMEBASE:
                        *data = g_variant_new("(tt)", timebases[devc->timebase][0],
@@ -477,8 +470,8 @@ 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;
        double tmp_double;
@@ -591,8 +584,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)
 {
        struct dev_context *devc;
 
@@ -608,7 +601,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                        *data = std_gvar_array_u64(devc->profile->buffersizes, NUM_BUFFER_SIZES);
                        break;
                case SR_CONF_TIMEBASE:
-                       *data = std_gvar_tuple_array(&timebases, ARRAY_SIZE(timebases));
+                       *data = std_gvar_tuple_array(ARRAY_AND_SIZE(timebases));
                        break;
                case SR_CONF_TRIGGER_SOURCE:
                        *data = g_variant_new_strv(ARRAY_AND_SIZE(trigger_sources));
@@ -628,7 +621,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                        *data = g_variant_new_strv(ARRAY_AND_SIZE(coupling));
                        break;
                case SR_CONF_VDIV:
-                       *data = std_gvar_tuple_array(&vdivs, ARRAY_SIZE(vdivs));
+                       *data = std_gvar_tuple_array(ARRAY_AND_SIZE(vdivs));
                        break;
                default:
                        return SR_ERR_NA;