From 7a1da33198c0c4d9f982a147e5a49a128446eca8 Mon Sep 17 00:00:00 2001 From: Bert Vermeulen Date: Sun, 12 Jan 2014 22:36:39 +0100 Subject: [PATCH] demo: Split supported device options by probe group. --- hardware/demo/demo.c | 73 +++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 4e760e35..9d3ae4b5 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -113,20 +113,23 @@ struct dev_context { GSList *analog_probe_groups; }; -static const int32_t hwopts[] = { +static const int32_t scanopts[] = { SR_CONF_NUM_LOGIC_PROBES, SR_CONF_NUM_ANALOG_PROBES, }; -static const int hwcaps[] = { +static const int devopts[] = { SR_CONF_LOGIC_ANALYZER, SR_CONF_DEMO_DEV, SR_CONF_SAMPLERATE, - SR_CONF_PATTERN_MODE, SR_CONF_LIMIT_SAMPLES, SR_CONF_LIMIT_MSEC, }; +static const int devopts_pg[] = { + SR_CONF_PATTERN_MODE, +}; + static const uint64_t samplerates[] = { SR_HZ(1), SR_GHZ(1), @@ -430,33 +433,55 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_probe_group *probe_group) { + struct sr_probe *probe; GVariant *gvar; GVariantBuilder gvb; (void)sdi; - (void)probe_group; - switch (key) { - case SR_CONF_SCAN_OPTIONS: + if (key == SR_CONF_SCAN_OPTIONS) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); - break; - case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); - break; - case SR_CONF_SAMPLERATE: - g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); - gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates, - ARRAY_SIZE(samplerates), sizeof(uint64_t)); - g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar); - *data = g_variant_builder_end(&gvb); - break; - case SR_CONF_PATTERN_MODE: - *data = g_variant_new_strv(logic_pattern_str, ARRAY_SIZE(logic_pattern_str)); - break; - default: - return SR_ERR_NA; + scanopts, ARRAY_SIZE(scanopts), sizeof(int32_t)); + return SR_OK; + } + + if (!sdi) + return SR_ERR_ARG; + + if (!probe_group) { + switch (key) { + case SR_CONF_DEVICE_OPTIONS: + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + devopts, ARRAY_SIZE(devopts), sizeof(int32_t)); + break; + case SR_CONF_SAMPLERATE: + g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); + gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates, + ARRAY_SIZE(samplerates), sizeof(uint64_t)); + g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar); + *data = g_variant_builder_end(&gvb); + break; + default: + return SR_ERR_NA; + } + } else { + probe = probe_group->probes->data; + switch (key) { + case SR_CONF_DEVICE_OPTIONS: + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, + devopts_pg, ARRAY_SIZE(devopts_pg), sizeof(int32_t)); + break; + case SR_CONF_PATTERN_MODE: + if (probe->type == SR_PROBE_LOGIC) + *data = g_variant_new_strv(logic_pattern_str, + ARRAY_SIZE(logic_pattern_str)); + else + *data = g_variant_new_strv(analog_pattern_str, + ARRAY_SIZE(analog_pattern_str)); + break; + default: + return SR_ERR_NA; + } } return SR_OK;