]> sigrok.org Git - libsigrok.git/commitdiff
drivers: Factor out std_gvar_min_max_step_thresholds().
authorUwe Hermann <redacted>
Thu, 20 Jul 2017 21:09:15 +0000 (23:09 +0200)
committerUwe Hermann <redacted>
Fri, 21 Jul 2017 14:54:05 +0000 (16:54 +0200)
src/hardware/dreamsourcelab-dslogic/api.c
src/hardware/zeroplus-logic-cube/api.c
src/libsigrok-internal.h
src/std.c

index c8bdb6d123fdb25102b27efa165ea0c04d3af2cf..41f8a737965170eff2859be24626851e39ba8007 100644 (file)
@@ -555,7 +555,6 @@ static int config_list(uint32_t key, GVariant **data,
        GVariant *gvar, *range[2];
        GVariantBuilder gvb;
        unsigned int i;
-       double v;
 
        devc = (sdi) ? sdi->priv : NULL;
 
@@ -564,23 +563,18 @@ static int config_list(uint32_t key, GVariant **data,
        case SR_CONF_DEVICE_OPTIONS:
                return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_VOLTAGE_THRESHOLD:
-               g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                if (!strcmp(devc->profile->model, "DSLogic")) {
+                       g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                        for (i = 0; i < ARRAY_SIZE(voltage_thresholds); i++) {
                                range[0] = g_variant_new_double(voltage_thresholds[i].low);
                                range[1] = g_variant_new_double(voltage_thresholds[i].high);
                                gvar = g_variant_new_tuple(range, 2);
                                g_variant_builder_add_value(&gvb, gvar);
                        }
+                       *data = g_variant_builder_end(&gvb);
                } else {
-                       for (v = 0.0; v <= 5.0; v += 0.1) {
-                               range[0] = g_variant_new_double(v);
-                               range[1] = g_variant_new_double(v);
-                               gvar = g_variant_new_tuple(range, 2);
-                               g_variant_builder_add_value(&gvb, gvar);
-                       }
+                       *data = std_gvar_min_max_step_thresholds(0.0, 5.0, 0.1);
                }
-               *data = g_variant_builder_end(&gvb);
                break;
        case SR_CONF_SAMPLERATE:
                *data = std_gvar_samplerates(devc->samplerates, devc->num_samplerates);
index e8cdefdb18cf8555994a7aa019a137672ba65458..dd0e66d5de91e48306284fc478927f0b7c274449 100644 (file)
@@ -391,10 +391,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
-       GVariant *gvar, *grange[2];
-       GVariantBuilder gvb;
-       double v;
-       GVariant *range[2];
+       GVariant *grange[2];
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
@@ -417,14 +414,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                                sizeof(int32_t));
                break;
        case SR_CONF_VOLTAGE_THRESHOLD:
-               g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
-               for (v = -6.0; v <= 6.0; v += 0.1) {
-                       range[0] = g_variant_new_double(v);
-                       range[1] = g_variant_new_double(v);
-                       gvar = g_variant_new_tuple(range, 2);
-                       g_variant_builder_add_value(&gvb, gvar);
-               }
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_min_max_step_thresholds(-6.0, 6.0, 0.1);
                break;
        case SR_CONF_LIMIT_SAMPLES:
                if (!sdi)
index 61858ebb95107b76b9f00c15d282ff6497d83c24..112ee4600d8cc61b1cdc49cf947d55e51766a3d2 100644 (file)
@@ -962,6 +962,7 @@ SR_PRIV GVariant *std_gvar_samplerates(const uint64_t samplerates[], unsigned in
 SR_PRIV GVariant *std_gvar_samplerates_steps(const uint64_t samplerates[], unsigned int n);
 SR_PRIV GVariant *std_gvar_min_max_step(double min, double max, double step);
 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);
 
 
 /*--- resource.c ------------------------------------------------------------*/
index 5748ba02eb9c62b869c693f60eac2d5942aa6ed2..45cc3a49acf9b3ea25cae96513d095313b89f97d 100644 (file)
--- a/src/std.c
+++ b/src/std.c
@@ -627,3 +627,22 @@ SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3])
 
        return g_variant_builder_end(&gvb);
 }
+
+SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double min, const double max, const double step)
+{
+       double d;
+       GVariant *gvar, *range[2];
+       GVariantBuilder gvb;
+
+       g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
+
+       for (d = min; d <= max; d += step) {
+               range[0] = g_variant_new_double(d);
+               range[1] = g_variant_new_double(d);
+
+               gvar = g_variant_new_tuple(range, 2);
+               g_variant_builder_add_value(&gvb, gvar);
+       }
+
+       return g_variant_builder_end(&gvb);
+}