X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmanson-hcs-3xxx%2Fapi.c;h=d3e5f8fa70213d94408eda213170e10328e4d3e9;hb=8a174d23427735617d69c7502ed8dcade786bbf9;hp=fad2e8dae6f161c9b7a6cef4a5510d7b17f7554c;hpb=ca95e90fb37f127b3d58d90a8b40ce1ca85641d2;p=libsigrok.git diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index fad2e8da..d3e5f8fa 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -26,6 +26,11 @@ #include "protocol.h" +static const uint32_t drvopts[] = { + /* Device class */ + SR_CONF_POWER_SUPPLY, +}; + static const uint32_t scanopts[] = { SR_CONF_CONN, SR_CONF_SERIALCOMM, @@ -120,8 +125,7 @@ static GSList *scan(GSList *options) if (!serialcomm) serialcomm = "9600/8n1"; - if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) - return NULL; + serial = sr_serial_dev_inst_new(conn, serialcomm); if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; @@ -150,20 +154,15 @@ static GSList *scan(GSList *options) } /* Init device instance, etc. */ - if (!(sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Manson", - models[model_id].name, NULL))) { - sr_err("Failed to create device instance."); - return NULL; - } - + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup("Manson"); + sdi->model = g_strdup(models[model_id].name); sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; sdi->driver = di; - if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"))) { - sr_err("Failed to create channel."); - goto exit_err; - } + ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"); sdi->channels = g_slist_append(sdi->channels, ch); devc = g_malloc0(sizeof(struct dev_context)); @@ -331,15 +330,26 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * (void)cg; + /* Always available (with or without sdi). */ + if (key == SR_CONF_SCAN_OPTIONS) { + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); + return SR_OK; + } + + /* Return drvopts without sdi (and devopts with sdi, see below). */ + if (key == SR_CONF_DEVICE_OPTIONS && !sdi) { + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); + return SR_OK; + } + + /* Every other key needs an sdi. */ if (!sdi) return SR_ERR_ARG; devc = sdi->priv; switch (key) { - case SR_CONF_SCAN_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); - break; case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));