X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fkecheng-kc-330b%2Fapi.c;h=9fb9a0a74939158054bac5009a09a34d7e51e98e;hb=58ffcf97121453fb53e885338e23e54c7ed78659;hp=02c83e4c055c12322670c5df21a60f7aad7f3f90;hpb=7e463623382e1f574fde150b3fc88a65eaebb578;p=libsigrok.git diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 02c83e4c..9fb9a0a7 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -22,11 +22,13 @@ #include "protocol.h" #define USB_CONN "1041.8101" -#define VENDOR "Kecheng" #define USB_INTERFACE 0 -static const uint32_t devopts[] = { +static const uint32_t drvopts[] = { SR_CONF_SOUNDLEVELMETER, +}; + +static const uint32_t devopts[] = { SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, SR_CONF_SAMPLE_INTERVAL | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, @@ -47,18 +49,15 @@ SR_PRIV const uint64_t kecheng_kc_330b_sample_intervals[][2] = { }; static const char *weight_freq[] = { - "A", - "C", + "A", "C", }; static const char *weight_time[] = { - "F", - "S", + "F", "S", }; static const char *data_sources[] = { - "Live", - "Memory", + "Live", "Memory", }; static int scan_kecheng(struct sr_dev_driver *di, @@ -122,7 +121,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) continue; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; - sdi->vendor = g_strdup(VENDOR); + sdi->vendor = g_strdup("Kecheng"); sdi->model = model; /* Already g_strndup()'d. */ sdi->inst_type = SR_INST_USB; sdi->conn = l->data; @@ -183,8 +182,7 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - /* Nothing to do. */ - return SR_OK; + return SR_ERR_BUG; /* This allows a frontend to configure the device without ever * doing an acquisition step. */ @@ -195,7 +193,6 @@ static int dev_close(struct sr_dev_inst *sdi) libusb_release_interface(usb->devhdl, USB_INTERFACE); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } @@ -255,13 +252,12 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd struct dev_context *devc; uint64_t p, q; unsigned int i; - int tmp, ret; + int tmp; const char *tmp_str; (void)cg; devc = sdi->priv; - ret = SR_OK; switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); @@ -278,7 +274,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd break; } if (i == ARRAY_SIZE(kecheng_kc_330b_sample_intervals)) - ret = SR_ERR_ARG; + return SR_ERR_ARG; break; case SR_CONF_SPL_WEIGHT_FREQ: tmp_str = g_variant_get_string(data, NULL); @@ -315,45 +311,29 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd devc->config_dirty = TRUE; 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) { - GVariant *tuple, *rational[2]; - GVariantBuilder gvb; - unsigned int i; - - (void)sdi; - (void)cg; - switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); - break; + return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); case SR_CONF_SAMPLE_INTERVAL: - g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); - for (i = 0; i < ARRAY_SIZE(kecheng_kc_330b_sample_intervals); i++) { - rational[0] = g_variant_new_uint64(kecheng_kc_330b_sample_intervals[i][0]); - rational[1] = g_variant_new_uint64(kecheng_kc_330b_sample_intervals[i][1]); - tuple = g_variant_new_tuple(rational, 2); - g_variant_builder_add_value(&gvb, tuple); - } - *data = g_variant_builder_end(&gvb); + *data = std_gvar_tuple_array(ARRAY_AND_SIZE(kecheng_kc_330b_sample_intervals)); break; case SR_CONF_SPL_WEIGHT_FREQ: - *data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq)); + *data = g_variant_new_strv(ARRAY_AND_SIZE(weight_freq)); break; case SR_CONF_SPL_WEIGHT_TIME: - *data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time)); + *data = g_variant_new_strv(ARRAY_AND_SIZE(weight_time)); break; case SR_CONF_DATA_SOURCE: - *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources)); + *data = g_variant_new_strv(ARRAY_AND_SIZE(data_sources)); break; default: return SR_ERR_NA; @@ -496,7 +476,7 @@ static struct sr_dev_driver kecheng_kc_330b_driver_info = { .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, - .dev_clear = NULL, + .dev_clear = std_dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list,