]> sigrok.org Git - libsigrok.git/commitdiff
drivers: Factor out std_gvar_tuple_double().
authorUwe Hermann <redacted>
Fri, 21 Jul 2017 21:27:40 +0000 (23:27 +0200)
committerUwe Hermann <redacted>
Mon, 31 Jul 2017 14:23:31 +0000 (16:23 +0200)
src/hardware/dreamsourcelab-dslogic/api.c
src/hardware/saleae-logic16/api.c
src/hardware/zeroplus-logic-cube/api.c
src/libsigrok-internal.h
src/std.c

index fe49d5f325f68ac0dec57946165fd539f548bebe..e57477f3f6da074a4c268f0f5187a3b88d0a1f21 100644 (file)
@@ -383,7 +383,6 @@ static int config_get(uint32_t key, GVariant **data,
 {
        struct dev_context *devc;
        struct sr_usb_dev_inst *usb;
-       GVariant *range[2];
        unsigned int i, voltage_range;
        char str[128];
 
@@ -415,16 +414,11 @@ static int config_get(uint32_t key, GVariant **data,
                                        voltage_range = i;
                                        break;
                                }
-
-                       range[0] = g_variant_new_double(
-                               voltage_thresholds[voltage_range].low);
-                       range[1] = g_variant_new_double(
-                               voltage_thresholds[voltage_range].high);
+                       *data = std_gvar_tuple_double(voltage_thresholds[voltage_range].low,
+                                       voltage_thresholds[voltage_range].high);
                } else {
-                       range[0] = g_variant_new_double(devc->cur_threshold);
-                       range[1] = g_variant_new_double(devc->cur_threshold);
+                       *data = std_gvar_tuple_double(devc->cur_threshold, devc->cur_threshold);
                }
-               *data = g_variant_new_tuple(range, 2);
                break;
        case SR_CONF_LIMIT_SAMPLES:
                *data = g_variant_new_uint64(devc->limit_samples);
index 7a7c157d780ad25f2049a4c417660707e66394f3..6a1161c9bf8715d14ac73888c6042ce06ac64f94 100644 (file)
@@ -400,7 +400,6 @@ static int config_get(uint32_t key, GVariant **data,
 {
        struct dev_context *devc;
        struct sr_usb_dev_inst *usb;
-       GVariant *range[2];
        char str[128];
        int ret;
        unsigned int i;
@@ -441,9 +440,7 @@ static int config_get(uint32_t key, GVariant **data,
                        if (devc->selected_voltage_range !=
                            volt_thresholds[i].range)
                                continue;
-                       range[0] = g_variant_new_double(volt_thresholds[i].low);
-                       range[1] = g_variant_new_double(volt_thresholds[i].high);
-                       *data = g_variant_new_tuple(range, 2);
+                       *data = std_gvar_tuple_double(volt_thresholds[i].low, volt_thresholds[i].high);
                        ret = SR_OK;
                        break;
                }
index 30ed79f50309afbfc92c756d3a08690e7856c7a2..73af06ea0dc7a58d062cc775a4b7a26e448c93d4 100644 (file)
@@ -331,7 +331,6 @@ 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;
-       GVariant *range[2];
 
        (void)cg;
 
@@ -348,9 +347,7 @@ static int config_get(uint32_t key, GVariant **data,
                *data = g_variant_new_uint64(devc->capture_ratio);
                break;
        case SR_CONF_VOLTAGE_THRESHOLD:
-               range[0] = g_variant_new_double(devc->cur_threshold);
-               range[1] = g_variant_new_double(devc->cur_threshold);
-               *data = g_variant_new_tuple(range, 2);
+               *data = std_gvar_tuple_double(devc->cur_threshold, devc->cur_threshold);
                break;
        default:
                return SR_ERR_NA;
index fd9fdb102ef9aed66bd4c04e1370d01646ea54f5..5566b6288b4d7cc770effd71d7e7b4fa88141315 100644 (file)
@@ -965,6 +965,7 @@ SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3]);
 SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double dmin, const double dmax, const double dstep);
 
 SR_PRIV GVariant *std_gvar_tuple_u64(uint64_t low, uint64_t high);
+SR_PRIV GVariant *std_gvar_tuple_double(double low, double high);
 
 SR_PRIV GVariant *std_gvar_array_i32(const int32_t *a, unsigned int n);
 SR_PRIV GVariant *std_gvar_array_u32(const uint32_t *a, unsigned int n);
index c910b417638f52b065fa57aba75816bb0e31fefb..3561c590bbe60d0d74f58de55ab1ca53b583e809 100644 (file)
--- a/src/std.c
+++ b/src/std.c
@@ -657,6 +657,16 @@ SR_PRIV GVariant *std_gvar_tuple_u64(uint64_t low, uint64_t high)
        return g_variant_new_tuple(range, 2);
 }
 
+SR_PRIV GVariant *std_gvar_tuple_double(double low, double high)
+{
+       GVariant *range[2];
+
+       range[0] = g_variant_new_double(low);
+       range[1] = g_variant_new_double(high);
+
+       return g_variant_new_tuple(range, 2);
+}
+
 SR_PRIV GVariant *std_gvar_array_i32(const int32_t *a, unsigned int n)
 {
        return g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,