From: Bert Vermeulen Date: Thu, 20 Mar 2014 23:50:30 +0000 (+0100) Subject: Add support for setting double ranges. X-Git-Tag: sigrok-cli-0.5.0~20 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=426d0cdaa91051c30d45055b3c10662fd392ea5a;p=sigrok-cli.git Add support for setting double ranges. This is used for SR_CONF_VOLTAGE_THRESHOLD. --- diff --git a/session.c b/session.c index 3d0e251..65c4c60 100644 --- 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 2eaa69d..d546376 100644 --- 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 */