X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fcem-dt-885x%2Fapi.c;h=1e4998028294bd1532920f84c25a72ec58ea6fd1;hb=4f840ce965b1c30c5ab75afecc56193cbaf5c1b3;hp=4cd0ccb6e745986ab9f82b323a64086be708e0f9;hpb=d7125bfa1ea1bc06c9df74d1aff6c4d50c62080c;p=libsigrok.git diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index 4cd0ccb6..1e499802 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -28,13 +28,13 @@ static const uint32_t scanopts[] = { SR_CONF_CONN, }; -static const uint32_t devopts[] = { +static const uint32_t drvopts[] = { SR_CONF_SOUNDLEVELMETER, - SR_CONF_CONTINUOUS, - SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, }; -static const uint32_t devopts_global[] = { +static const uint32_t devopts[] = { + SR_CONF_CONTINUOUS | SR_CONF_SET, + SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, SR_CONF_SPL_WEIGHT_FREQ | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_SPL_WEIGHT_TIME | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_SPL_MEASUREMENT_RANGE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, @@ -67,22 +67,20 @@ static const char *data_sources[] = { "Memory", }; SR_PRIV struct sr_dev_driver cem_dt_885x_driver_info; -static struct sr_dev_driver *di = &cem_dt_885x_driver_info; -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; struct sr_serial_dev_inst *serial; struct sr_dev_inst *sdi; - struct sr_channel *ch; GSList *l, *devices; gint64 start; const char *conn; @@ -97,8 +95,7 @@ static GSList *scan(GSList *options) if (!conn) return NULL; - if (!(serial = sr_serial_dev_inst_new(conn, SERIALCOMM))) - return NULL; + serial = sr_serial_dev_inst_new(conn, SERIALCOMM); if (serial_open(serial, SERIAL_RDONLY) != SR_OK) return NULL; @@ -109,29 +106,21 @@ static GSList *scan(GSList *options) while (g_get_monotonic_time() - start < MAX_SCAN_TIME) { if (serial_read_nonblocking(serial, &c, 1) == 1 && c == 0xa5) { /* Found one. */ - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "CEM", - "DT-885x", NULL))) - return NULL; - - if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { - sr_dbg("Device context malloc failed."); - return NULL; - } + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("CEM"); + sdi->model = g_strdup("DT-885x"); + devc = g_malloc0(sizeof(struct dev_context)); devc->cur_mqflags = 0; devc->recording = -1; devc->cur_meas_range = 0; devc->cur_data_source = DATA_SOURCE_LIVE; devc->enable_data_source_memory = FALSE; - - if (!(sdi->conn = sr_serial_dev_inst_new(conn, SERIALCOMM))) - return NULL; - + sdi->conn = sr_serial_dev_inst_new(conn, SERIALCOMM); sdi->inst_type = SR_INST_SERIAL; sdi->priv = devc; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "SPL"))) - return NULL; - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); break; @@ -145,7 +134,7 @@ static GSList *scan(GSList *options) return devices; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } @@ -163,7 +152,7 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } @@ -349,7 +338,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * break; case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); + drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); break; default: return SR_ERR_NA; @@ -358,7 +347,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * switch (key) { case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts_global, ARRAY_SIZE(devopts_global), sizeof(uint32_t)); + devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); case SR_CONF_SPL_WEIGHT_FREQ: *data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq)); break;