]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/motech-lps-30x/api.c
Removal of sdi->index, step 4: fix trivial sr_dev_inst_new() calls
[libsigrok.git] / src / hardware / motech-lps-30x / api.c
index ae08317a0ae4348520669ab4de61fd5ade5d9e5a..79a32aa4336ada0c9efb9080ad936b151ae756b4 100644 (file)
@@ -44,36 +44,36 @@ SR_PRIV int lps_query_status(struct sr_dev_inst* sdi);
 #define VENDOR_MOTECH "Motech"
 
 /** Driver scanning options. */
-static const int32_t hwopts[] = {
+static const uint32_t scanopts[] = {
        SR_CONF_CONN,
        SR_CONF_SERIALCOMM,
 };
 
 /** Hardware capabilities generic. */
-static const int32_t hwcaps[] = {
+static const uint32_t devopts[] = {
        /* Device class */
        SR_CONF_POWER_SUPPLY,
        /* Aquisition modes. */
-       SR_CONF_LIMIT_SAMPLES,
-       SR_CONF_LIMIT_MSEC,
        SR_CONF_CONTINUOUS,
+       SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
        /* Device configuration */
-       SR_CONF_OUTPUT_CHANNEL_CONFIG,
+       SR_CONF_OUTPUT_CHANNEL_CONFIG | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
 };
 
 /** Hardware capabilities channel 1, 2. */
-static const int32_t hwcaps_ch12[] = {
-       SR_CONF_OUTPUT_VOLTAGE,
-       SR_CONF_OUTPUT_VOLTAGE_MAX,
-       SR_CONF_OUTPUT_CURRENT,
-       SR_CONF_OUTPUT_CURRENT_MAX,
-       SR_CONF_OUTPUT_ENABLED,
+static const uint32_t devopts_ch12[] = {
+       SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
+       SR_CONF_OUTPUT_VOLTAGE_MAX | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+       SR_CONF_OUTPUT_CURRENT | SR_CONF_GET,
+       SR_CONF_OUTPUT_CURRENT_MAX | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+       SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
 };
 
 /** Hardware capabilities channel 3. (LPS-304/305 only). */
-static const int32_t hwcaps_ch3[] = {
-       SR_CONF_OUTPUT_VOLTAGE,
-       SR_CONF_OUTPUT_ENABLED,
+static const uint32_t devopts_ch3[] = {
+       SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
+       SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
 };
 
 static const char *channel_modes[] = {
@@ -146,7 +146,7 @@ SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char* fmt, va_l
 
        sr_spew("lps_send_va: \"%s\"", buf);
 
-       retc = serial_write_nonblocking(serial, buf, strlen(buf));
+       retc = serial_write_blocking(serial, buf, strlen(buf));
 
        if (retc < 0)
                return SR_ERR;
@@ -399,7 +399,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o
        if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
                return NULL;
 
-       if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
+       if (serial_open(serial, SERIAL_RDWR) != SR_OK)
                goto exit_err;
 
        /* Query and verify model string. */
@@ -444,7 +444,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(0, SR_ST_INACTIVE, VENDOR_MOTECH, models[modelid].modelstr, verstr);
+       sdi = sr_dev_inst_new(SR_ST_INACTIVE, VENDOR_MOTECH, models[modelid].modelstr, verstr);
        sdi->driver = drv;
        sdi->inst_type = SR_INST_SERIAL;
        sdi->conn = serial;
@@ -540,7 +540,7 @@ static int cleanup(void)
        return dev_clear_lps301();
 }
 
-static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
+static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
@@ -595,7 +595,7 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
-static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
+static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
@@ -717,7 +717,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
-static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
+static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
@@ -731,8 +731,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
        /* Driver options, no device instance necessary. */
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
-                                                 hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+                                                 scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
                return SR_OK;
        default:
                if (sdi == NULL)
@@ -741,12 +741,12 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
                devc = sdi->priv;
        }
 
-       /* Device options, independant from channel groups. */
+       /* Device options, independent from channel groups. */
        if (cg == NULL) {
                switch (key) {
                case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
-                                                         hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
+                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
                        return SR_OK;
                case SR_CONF_OUTPUT_CHANNEL_CONFIG:
                        if (devc->model->modelid <= LPS_303) {
@@ -769,11 +769,11 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
                if ((ch_idx == 0) || (ch_idx == 1)) /* CH1, CH2 */
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
-                                 hwcaps_ch12, ARRAY_SIZE(hwcaps_ch12), sizeof(int32_t));
+                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+                                 devopts_ch12, ARRAY_SIZE(devopts_ch12), sizeof(uint32_t));
                else /* Must be CH3 */
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
-                                 hwcaps_ch3, ARRAY_SIZE(hwcaps_ch3), sizeof(int32_t));
+                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+                                 devopts_ch3, ARRAY_SIZE(devopts_ch3), sizeof(uint32_t));
                break;
        case SR_CONF_OUTPUT_VOLTAGE_MAX:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);