Skip to content

Commit

Permalink
show: do print floating point results even if value is zero
Browse files Browse the repository at this point in the history
The availability of a configuration value with floating point data type
was determined by checking its value for being zero. Which prevents the
display of valid data. See the 'offset' in this example:

  $ sigrok-cli -d demo -g Analog --show

Track the current value's availability in a boolean variable. Do print
values even if they are zero.
  • Loading branch information
gsigh committed May 23, 2020
1 parent 917c8f8 commit 0171a4a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions show.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,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)) {
Expand Down Expand Up @@ -725,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);
}
Expand All @@ -745,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");
Expand Down

0 comments on commit 0171a4a

Please sign in to comment.