X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fsaleae-logic16%2Fapi.c;h=e66d845b9f6d41189fa4dddbaed8bcd517cba7b9;hb=50ccb36f201bd6b2326822f585c01498fe6fd86a;hp=ecb2953b1b56616105564c881378e5076da9293d;hpb=9fb9afb573193a6614c45e3a040a3c92c713523a;p=libsigrok.git diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index ecb2953b..e66d845b 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -77,7 +77,7 @@ static const struct { { VOLTAGE_RANGE_5_V, }, }; -static const struct voltage_threshold volt_thresholds[] = { +static const double volt_thresholds[][2] = { { 0.7, 1.4 }, { 1.4, 3.6 }, }; @@ -403,7 +403,6 @@ static int config_get(uint32_t key, GVariant **data, { struct dev_context *devc; struct sr_usb_dev_inst *usb; - char str[128]; int ret; unsigned int i; @@ -419,8 +418,7 @@ static int config_get(uint32_t key, GVariant **data, /* Device still needs to re-enumerate after firmware * upload, so we don't know its (future) address. */ return SR_ERR; - snprintf(str, 128, "%d.%d", usb->bus, usb->address); - *data = g_variant_new_string(str); + *data = g_variant_new_printf("%d.%d", usb->bus, usb->address); break; case SR_CONF_SAMPLERATE: if (!sdi) @@ -443,7 +441,7 @@ static int config_get(uint32_t key, GVariant **data, if (devc->selected_voltage_range != volt_thresholds_ranges[i].range) continue; - *data = std_gvar_tuple_double(volt_thresholds[i].low, volt_thresholds[i].high); + *data = std_gvar_tuple_double(volt_thresholds[i][0], volt_thresholds[i][1]); ret = SR_OK; break; } @@ -459,9 +457,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - gdouble low, high; - int ret; - unsigned int i; + int ret, idx; (void)cg; @@ -480,17 +476,9 @@ static int config_set(uint32_t key, GVariant *data, ret = (devc->capture_ratio > 100) ? SR_ERR : SR_OK; break; case SR_CONF_VOLTAGE_THRESHOLD: - g_variant_get(data, "(dd)", &low, &high); - ret = SR_ERR_ARG; - for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++) { - if (fabs(volt_thresholds[i].low - low) < 0.1 && - fabs(volt_thresholds[i].high - high) < 0.1) { - devc->selected_voltage_range = - volt_thresholds_ranges[i].range; - ret = SR_OK; - break; - } - } + if ((idx = std_double_tuple_idx(data, ARRAY_AND_SIZE(volt_thresholds))) < 0) + return SR_ERR_ARG; + devc->selected_voltage_range = volt_thresholds_ranges[idx].range; break; default: ret = SR_ERR_NA;