]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/motech-lps-30x/api.c
Simplify channel creation.
[libsigrok.git] / src / hardware / motech-lps-30x / api.c
index 40bb2d9578873a0baa4f5708f714d07309d3eda6..d54b267c884acc6d773211989b5c2591556858f6 100644 (file)
@@ -43,6 +43,12 @@ SR_PRIV int lps_query_status(struct sr_dev_inst* sdi);
 
 #define VENDOR_MOTECH "Motech"
 
+/** Driver capabilities generic. */
+static const uint32_t drvopts[] = {
+       /* Device class */
+       SR_CONF_POWER_SUPPLY,
+};
+
 /** Driver scanning options. */
 static const uint32_t scanopts[] = {
        SR_CONF_CONN,
@@ -396,8 +402,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
                serialcomm = SERIALCOMM;
 
        /* Init serial port. */
-       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)
                goto exit_err;
@@ -444,7 +449,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
                Therefore just print an error message, but do not exit with error. */
                sr_err("Failed to query for hardware version: %d %s", errno, strerror(errno));
 
-       sdi = sr_dev_inst_new();
+       sdi = g_malloc0(sizeof(struct sr_dev_inst));
        sdi->status = SR_ST_INACTIVE;
        sdi->vendor = g_strdup(VENDOR_MOTECH);
        sdi->model = g_strdup(models[modelid].modelstr);
@@ -465,8 +470,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
        /* Setup channels and channel groups. */
        for (cnt = 0; cnt < models[modelid].num_channels; cnt++) {
                snprintf(channel, sizeof(channel), "CH%d", cnt + 1);
-               ch = sr_channel_new(cnt, SR_CHANNEL_ANALOG, TRUE, channel);
-               sdi->channels = g_slist_append(sdi->channels, ch);
+               ch = sr_channel_new(sdi, cnt, SR_CHANNEL_ANALOG, TRUE, channel);
 
                devc->channel_status[cnt].info = g_slist_append(NULL, ch);
 
@@ -738,6 +742,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
                                                  scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
                return SR_OK;
+       case SR_CONF_DEVICE_OPTIONS:
+               if (sdi != NULL)
+                       break;
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
+               return SR_OK;
        default:
                if (sdi == NULL)
                        return SR_ERR_ARG;