From: Uwe Hermann Date: Fri, 21 Jul 2017 21:27:40 +0000 (+0200) Subject: drivers: Factor out std_gvar_tuple_double(). X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=43995cda362b117ecae790f01e05eb9b43d5e886;p=libsigrok.git drivers: Factor out std_gvar_tuple_double(). --- diff --git a/src/hardware/dreamsourcelab-dslogic/api.c b/src/hardware/dreamsourcelab-dslogic/api.c index fe49d5f3..e57477f3 100644 --- a/src/hardware/dreamsourcelab-dslogic/api.c +++ b/src/hardware/dreamsourcelab-dslogic/api.c @@ -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); diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 7a7c157d..6a1161c9 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -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; } diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 30ed79f5..73af06ea 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -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; diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index fd9fdb10..5566b628 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -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); diff --git a/src/std.c b/src/std.c index c910b417..3561c590 100644 --- 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,