]> sigrok.org Git - sigrok-cli.git/blobdiff - show.c
show: do print floating point results even if value is zero
[sigrok-cli.git] / show.c
diff --git a/show.c b/show.c
index e62f69746358663190d4a8b625871efd79497119..8fbd0af157a028e959dec593f235c58b0ca4f399 100644 (file)
--- a/show.c
+++ b/show.c
@@ -393,6 +393,7 @@ void show_dev_detail(void)
        gsize num_elements;
        double dlow, dhigh, dcur_low, dcur_high;
        const uint64_t *uint64;
+       uint64_t cur_rate, rate;
        uint64_t p = 0, q = 0, low = 0, high = 0;
        uint64_t tmp_uint64, mask, cur_low, cur_high, cur_p, cur_q;
        GArray *opts;
@@ -403,6 +404,7 @@ void show_dev_detail(void)
        char *tmp_str, *s, c;
        const char **stropts;
        double tmp_flt;
+       gboolean have_tmp_flt;
        const double *fltopts;
 
        if (parse_driver(opt_drv, &driver_from_opt, NULL)) {
@@ -535,6 +537,13 @@ void show_dev_detail(void)
                } else if (key == SR_CONF_SAMPLERATE) {
                        /* Supported samplerates */
                        printf("    %s", srci->id);
+                       cur_rate = ~0ull;
+                       if (maybe_config_get(driver, sdi, channel_group,
+                               SR_CONF_SAMPLERATE, &gvar) == SR_OK) {
+                               if (g_variant_is_of_type(gvar, G_VARIANT_TYPE_UINT64))
+                                       cur_rate = g_variant_get_uint64(gvar);
+                               g_variant_unref(gvar);
+                       }
                        if (maybe_config_list(driver, sdi, channel_group, SR_CONF_SAMPLERATE,
                                        &gvar_dict) != SR_OK) {
                                printf("\n");
@@ -546,9 +555,14 @@ void show_dev_detail(void)
                                                &num_elements, sizeof(uint64_t));
                                printf(" - supported samplerates:\n");
                                for (i = 0; i < num_elements; i++) {
-                                       if (!(s = sr_samplerate_string(uint64[i])))
+                                       rate = uint64[i];
+                                       s = sr_samplerate_string(rate);
+                                       if (!s)
                                                continue;
-                                       printf("      %s\n", s);
+                                       printf("      %s", s);
+                                       if (rate == cur_rate)
+                                               printf(" (current)");
+                                       printf("\n");
                                        g_free(s);
                                }
                                g_variant_unref(gvar_list);
@@ -712,14 +726,16 @@ void show_dev_detail(void)
                } else if (srci->datatype == SR_T_FLOAT) {
                        printf("    %s: ", srci->id);
                        tmp_flt = 0.0;
+                       have_tmp_flt = FALSE;
                        if (maybe_config_get(driver, sdi, channel_group, key,
                                        &gvar) == SR_OK) {
                                tmp_flt = g_variant_get_double(gvar);
+                               have_tmp_flt = TRUE;
                                g_variant_unref(gvar);
                        }
                        if (maybe_config_list(driver, sdi, channel_group, key,
                                        &gvar) != SR_OK) {
-                               if (tmp_flt) {
+                               if (have_tmp_flt) {
                                        /* Can't list, but got a value to show. */
                                        printf("%f (current)", tmp_flt);
                                }
@@ -732,7 +748,7 @@ void show_dev_detail(void)
                                if (i)
                                        printf(", ");
                                printf("%f", fltopts[i]);
-                               if (tmp_flt && fltopts[i] == tmp_flt)
+                               if (have_tmp_flt && fltopts[i] == tmp_flt)
                                        printf(" (current)");
                        }
                        printf("\n");