X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fpipistrello-ols%2Fapi.c;h=1d1388bae3bdc174488dc58677132ea5743498e2;hb=8eadb70a37946c268d9bef312478096e96009c3d;hp=29ba0fed9980ee4177824a13521e4a29ff97d980;hpb=53012da658ae94b245240c8a3e115723eede4c7d;p=libsigrok.git diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 29ba0fed..1d1388ba 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -195,8 +195,8 @@ static int dev_clear(const struct sr_dev_driver *di) return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper); } -static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_get(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; @@ -206,6 +206,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s return SR_ERR_ARG; devc = sdi->priv; + switch (key) { case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(devc->cur_samplerate); @@ -237,13 +238,12 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s return SR_OK; } -static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +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; uint16_t flag; uint64_t tmp_u64; - int ret; const char *stropt; (void)cg; @@ -255,21 +255,15 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd tmp_u64 = g_variant_get_uint64(data); if (tmp_u64 < samplerates[0] || tmp_u64 > samplerates[1]) return SR_ERR_SAMPLERATE; - ret = p_ols_set_samplerate(sdi, g_variant_get_uint64(data)); - break; + return p_ols_set_samplerate(sdi, g_variant_get_uint64(data)); case SR_CONF_LIMIT_SAMPLES: tmp_u64 = g_variant_get_uint64(data); if (tmp_u64 < MIN_NUM_SAMPLES) return SR_ERR; devc->limit_samples = tmp_u64; - ret = SR_OK; break; case SR_CONF_CAPTURE_RATIO: devc->capture_ratio = g_variant_get_uint64(data); - if (devc->capture_ratio < 0 || devc->capture_ratio > 100) - ret = SR_ERR; - else - ret = SR_OK; break; case SR_CONF_EXTERNAL_CLOCK: if (g_variant_get_boolean(data)) { @@ -279,23 +273,21 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd sr_info("Disabled external clock."); devc->flag_reg &= ~FLAG_CLOCK_EXTERNAL; } - ret = SR_OK; break; case SR_CONF_PATTERN_MODE: stropt = g_variant_get_string(data, NULL); - ret = SR_OK; flag = 0xffff; if (!strcmp(stropt, STR_PATTERN_NONE)) { sr_info("Disabling test modes."); flag = 0x0000; - }else if (!strcmp(stropt, STR_PATTERN_INTERNAL)) { + } else if (!strcmp(stropt, STR_PATTERN_INTERNAL)) { sr_info("Enabling internal test mode."); flag = FLAG_INTERNAL_TEST_MODE; } else if (!strcmp(stropt, STR_PATTERN_EXTERNAL)) { sr_info("Enabling external test mode."); flag = FLAG_EXTERNAL_TEST_MODE; } else { - ret = SR_ERR; + return SR_ERR; } if (flag != 0xffff) { devc->flag_reg &= ~(FLAG_INTERNAL_TEST_MODE | FLAG_EXTERNAL_TEST_MODE); @@ -310,9 +302,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd sr_info("Disabling channel swapping."); devc->flag_reg &= ~FLAG_SWAP_CHANNELS; } - ret = SR_OK; break; - case SR_CONF_RLE: if (g_variant_get_boolean(data)) { sr_info("Enabling RLE."); @@ -321,20 +311,18 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd sr_info("Disabling RLE."); devc->flag_reg &= ~FLAG_RLE; } - ret = SR_OK; break; default: - ret = SR_ERR_NA; + return SR_ERR_NA; } - return ret; + return SR_OK; } -static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_list(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - GVariant *grange[2]; int num_pols_changrp, i; switch (key) { @@ -371,12 +359,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * /* 3 channel groups takes as many bytes as 4 channel groups */ if (num_pols_changrp == 3) num_pols_changrp = 4; - grange[0] = g_variant_new_uint64(MIN_NUM_SAMPLES); - if (num_pols_changrp) - grange[1] = g_variant_new_uint64(devc->max_samplebytes / num_pols_changrp); - else - grange[1] = g_variant_new_uint64(MIN_NUM_SAMPLES); - *data = g_variant_new_tuple(grange, 2); + + *data = std_gvar_tuple_u64(MIN_NUM_SAMPLES, + (num_pols_changrp) ? devc->max_samplebytes / num_pols_changrp : MIN_NUM_SAMPLES); break; default: return SR_ERR_NA;