]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/testo/api.c
Simplify a few config_set() callbacks.
[libsigrok.git] / src / hardware / testo / api.c
index 3ceb08698d9ff24c8b7f86cb0fd3fb2d68a15c7c..64d292dd3488b2a0d928a834bfb65976b1c80130 100644 (file)
@@ -23,7 +23,6 @@
 #define SERIALCOMM "115200/8n1"
 
 SR_PRIV struct sr_dev_driver testo_driver_info;
-static struct sr_dev_driver *di = &testo_driver_info;
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data);
 
 static const uint32_t scanopts[] = {
@@ -37,17 +36,18 @@ static const uint32_t devopts[] = {
        SR_CONF_LIMIT_MSEC | SR_CONF_SET,
 };
 
-unsigned char TESTO_x35_REQUEST[] = { 0x12, 0, 0, 0, 1, 1, 0x55, 0xd1, 0xb7 };
-struct testo_model models[] = {
+static const uint8_t TESTO_x35_REQUEST[] = { 0x12, 0, 0, 0, 1, 1, 0x55, 0xd1, 0xb7 };
+
+static const struct testo_model models[] = {
        { "435", 9, TESTO_x35_REQUEST },
 };
 
-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;
@@ -124,8 +124,10 @@ static GSList *scan(GSList *options)
                if (strcmp(product, "testo 435/635/735"))
                        continue;
 
-               sdi = sr_dev_inst_new(SR_ST_INACTIVE, "Testo",
-                               "435/635/735", NULL);
+               sdi = g_malloc0(sizeof(struct sr_dev_inst));
+               sdi->status = SR_ST_INACTIVE;
+               sdi->vendor = g_strdup("Testo");
+               sdi->model = g_strdup("435/635/735");
                sdi->driver = di;
                sdi->inst_type = SR_INST_USB;
                sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
@@ -147,18 +149,19 @@ 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;
 }
 
-static int dev_clear(void)
+static int dev_clear(const struct sr_dev_driver *di)
 {
        return std_dev_clear(di, NULL);
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
 {
+       struct sr_dev_driver *di = sdi->driver;
        struct drv_context *drvc = di->priv;
        struct sr_usb_dev_inst *usb;
        libusb_device **devlist;
@@ -209,6 +212,7 @@ static int dev_open(struct sr_dev_inst *sdi)
 
 static int dev_close(struct sr_dev_inst *sdi)
 {
+       struct sr_dev_driver *di = sdi->driver;
        struct sr_usb_dev_inst *usb;
 
        if (!di->priv) {
@@ -229,7 +233,7 @@ static int dev_close(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int cleanup(void)
+static int cleanup(const struct sr_dev_driver *di)
 {
        int ret;
        struct drv_context *drvc;
@@ -237,9 +241,8 @@ static int cleanup(void)
        if (!(drvc = di->priv))
                return SR_OK;
 
-       ret = dev_clear();
+       ret = dev_clear(di);
        g_free(drvc);
-       di->priv = NULL;
 
        return ret;
 }
@@ -270,6 +273,7 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
 static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
+       struct sr_dev_driver *di = sdi->driver;
        struct dev_context *devc;
        gint64 now;
        int ret;
@@ -291,13 +295,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                devc->limit_msec = g_variant_get_uint64(data);
                now = g_get_monotonic_time() / 1000;
                devc->end_time = now + devc->limit_msec;
-               sr_dbg("Setting time limit to %" PRIu64 "ms.",
-                      devc->limit_msec);
                break;
        case SR_CONF_LIMIT_SAMPLES:
                devc->limit_samples = g_variant_get_uint64(data);
-               sr_dbg("Setting sample limit to %" PRIu64 ".",
-                      devc->limit_samples);
                break;
        default:
                ret = SR_ERR_NA;
@@ -413,8 +413,9 @@ SR_PRIV void receive_transfer(struct libusb_transfer *transfer)
 
 static int handle_events(int fd, int revents, void *cb_data)
 {
+       struct sr_dev_driver *di;
        struct dev_context *devc;
-       struct drv_context *drvc = di->priv;
+       struct drv_context *drvc;
        struct sr_datafeed_packet packet;
        struct sr_dev_inst *sdi;
        struct timeval tv;
@@ -425,6 +426,8 @@ static int handle_events(int fd, int revents, void *cb_data)
 
        sdi = cb_data;
        devc = sdi->priv;
+       di = sdi->driver;
+       drvc = di->priv;
 
        if (devc->limit_msec) {
                now = g_get_monotonic_time() / 1000;
@@ -450,6 +453,7 @@ static int handle_events(int fd, int revents, void *cb_data)
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 {
+       struct sr_dev_driver *di = sdi->driver;
        struct drv_context *drvc;
        struct dev_context *devc;
        struct sr_usb_dev_inst *usb;
@@ -503,6 +507,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
+       struct sr_dev_driver *di = sdi->driver;
        (void)cb_data;
 
        if (!di->priv) {