X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Ffx2lafw%2Fapi.c;h=adcc246ac41ebe535c70c4c22a749635885975b5;hb=697fb6ddfc2522b2e6d35511c7837e2c61d8ae73;hp=b1909428692144ac9f12d9c3c33b0d801d919b37;hpb=463160cbca37367ef94dfead0c64531d82b83ab8;p=libsigrok.git diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index b1909428..adcc246a 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -113,7 +113,7 @@ static const uint32_t devopts[] = { SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET, }; -static const int32_t soft_trigger_matches[] = { +static const int32_t trigger_matches[] = { SR_TRIGGER_ZERO, SR_TRIGGER_ONE, SR_TRIGGER_RISING, @@ -449,7 +449,6 @@ static int config_get(uint32_t key, GVariant **data, { struct dev_context *devc; struct sr_usb_dev_inst *usb; - char str[128]; (void)cg; @@ -467,8 +466,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_LIMIT_SAMPLES: *data = g_variant_new_uint64(devc->limit_samples); @@ -490,8 +488,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; - uint64_t arg; - int i, ret; + int idx, ret; (void)cg; @@ -504,15 +501,9 @@ static int config_set(uint32_t key, GVariant *data, switch (key) { case SR_CONF_SAMPLERATE: - arg = g_variant_get_uint64(data); - for (i = 0; i < devc->num_samplerates; i++) { - if (devc->samplerates[i] == arg) { - devc->cur_samplerate = arg; - break; - } - } - if (i == devc->num_samplerates) - ret = SR_ERR_ARG; + if ((idx = std_u64_idx(data, devc->samplerates, devc->num_samplerates)) < 0) + return SR_ERR_ARG; + devc->cur_samplerate = devc->samplerates[idx]; break; case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); @@ -543,9 +534,7 @@ static int config_list(uint32_t key, GVariant **data, *data = std_gvar_samplerates(devc->samplerates, devc->num_samplerates); break; case SR_CONF_TRIGGER_MATCH: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches), - sizeof(int32_t)); + *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches)); break; default: return SR_ERR_NA;