X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fmanson-hcs-3xxx%2Fapi.c;h=d3e5f8fa70213d94408eda213170e10328e4d3e9;hb=b1a7ca3b605a8a7e7ce97dfc9eb211e9b3a5c918;hp=6be41b9fd9b67460d98fffbe78c5ef20b3fcd6f5;hpb=0af636bed97c174bea46e61e961eaa1b0b162e0f;p=libsigrok.git diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index 6be41b9f..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,7 +154,7 @@ static GSList *scan(GSList *options) } /* Init device instance, etc. */ - sdi = sr_dev_inst_new(); + 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); @@ -158,10 +162,7 @@ static GSList *scan(GSList *options) 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)); @@ -329,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));