]> sigrok.org Git - sigrok-cli.git/commitdiff
Add support for setting double ranges.
authorBert Vermeulen <redacted>
Thu, 20 Mar 2014 23:50:30 +0000 (00:50 +0100)
committerBert Vermeulen <redacted>
Thu, 20 Mar 2014 23:50:30 +0000 (00:50 +0100)
This is used for SR_CONF_VOLTAGE_THRESHOLD.

session.c
show.c

index 3d0e25182e2db4121c3de1cabaf14617680882fa..65c4c60c51b6a8f5ff8a9f27ccede18189e802c4 100644 (file)
--- a/session.c
+++ b/session.c
@@ -416,7 +416,7 @@ void datafeed_in(const struct sr_dev_inst *sdi,
 int opt_to_gvar(char *key, char *value, struct sr_config *src)
 {
        const struct sr_config_info *srci;
-       double tmp_double;
+       double tmp_double, dlow, dhigh;
        uint64_t tmp_u64, p, q, low, high;
        GVariant *rational[2], *range[2];
        gboolean tmp_bool;
@@ -486,6 +486,16 @@ int opt_to_gvar(char *key, char *value, struct sr_config *src)
                        src->data = g_variant_new_tuple(range, 2);
                }
                break;
+       case SR_T_DOUBLE_RANGE:
+               if (sscanf(value, "%lf-%lf", &dlow, &dhigh) != 2) {
+                       ret = -1;
+                       break;
+               } else {
+                       range[0] = g_variant_new_double(dlow);
+                       range[1] = g_variant_new_double(dhigh);
+                       src->data = g_variant_new_tuple(range, 2);
+               }
+               break;
        default:
                ret = -1;
        }
diff --git a/show.c b/show.c
index 2eaa69d70bedc1d4374fc6c6c4c46e4762439111..d546376cd6b1275045183d1607bb934a3bde6b7b 100644 (file)
--- a/show.c
+++ b/show.c
@@ -204,6 +204,7 @@ void show_dev_detail(void)
        GSList *devices, *pgl, *prl;
        GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
        gsize num_opts, num_elements;
+       double dlow, dhigh, dcur_low, dcur_high;
        const uint64_t *uint64, p, q, low, high;
        uint64_t cur_low, cur_high;
        const int32_t *opts;
@@ -478,6 +479,36 @@ void show_dev_detail(void)
                        } else
                                printf("on, off\n");
 
+               } else if (srci->datatype == SR_T_DOUBLE_RANGE) {
+                       printf("    %s: ", srci->id);
+                       if (sr_config_list(sdi->driver, sdi, probe_group, srci->key,
+                                       &gvar_list) != SR_OK) {
+                               printf("\n");
+                               continue;
+                       }
+
+                       if (sr_config_get(sdi->driver, sdi, NULL, srci->key, &gvar) == SR_OK) {
+                               g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
+                               g_variant_unref(gvar);
+                       } else {
+                               dcur_low = 0;
+                               dcur_high = 0;
+                       }
+
+                       num_elements = g_variant_n_children(gvar_list);
+                       for (i = 0; i < num_elements; i++) {
+                               gvar = g_variant_get_child_value(gvar_list, i);
+                               g_variant_get(gvar, "(dd)", &dlow, &dhigh);
+                               g_variant_unref(gvar);
+                               if (i)
+                                       printf(", ");
+                               printf("%.1f-%.1f", dlow, dhigh);
+                               if (dlow == dcur_low && dhigh == dcur_high)
+                                       printf(" (current)");
+                       }
+                       printf("\n");
+                       g_variant_unref(gvar_list);
+
                } else {
 
                        /* Everything else */