]> sigrok.org Git - sigrok-cli.git/commitdiff
show: use getter result to determine "current" presence (voltage range)
authorGerhard Sittig <redacted>
Sun, 6 Feb 2022 20:32:28 +0000 (21:32 +0100)
committerGerhard Sittig <redacted>
Sun, 6 Feb 2022 20:32:28 +0000 (21:32 +0100)
Improve the condition which presents the "(current)" decoration when
voltage ranges are listed in --show output. Use an explicit boolean
which is derived from the config getter's return code. Avoid "forcing"
a comparison against a zero value, which can be a valid item in the list
of supported voltages.

This is similar to commit 0171a4a7a49f. See more context (-U10) for the
motivation of the change. Was observed with the kingst-la2016 driver.

show.c

diff --git a/show.c b/show.c
index 5243e53cc07aad1817b37cbd2bb2132a57ce83ac..85b440989212f04d2480f68bb242c155117c5b0f 100644 (file)
--- a/show.c
+++ b/show.c
@@ -418,7 +418,7 @@ void show_dev_detail(void)
        char *tmp_str, *s, c;
        const char **stropts;
        double tmp_flt;
-       gboolean have_tmp_flt;
+       gboolean have_tmp_flt, have_curr;
        const double *fltopts;
 
        if (parse_driver(opt_drv, &driver_from_opt, NULL)) {
@@ -718,12 +718,11 @@ void show_dev_detail(void)
                                continue;
                        }
 
+                       have_curr = FALSE;
                        if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
                                g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
                                g_variant_unref(gvar);
-                       } else {
-                               dcur_low = 0;
-                               dcur_high = 0;
+                               have_curr = TRUE;
                        }
 
                        num_elements = g_variant_n_children(gvar_list);
@@ -734,6 +733,8 @@ void show_dev_detail(void)
                                if (i)
                                        printf(", ");
                                printf("%.1f-%.1f", dlow, dhigh);
+                               if (!have_curr)
+                                       continue;
                                if (dlow == dcur_low && dhigh == dcur_high)
                                        printf(" (current)");
                        }