]> sigrok.org Git - libsigrok.git/blobdiff - hardware/lascar-el-usb/protocol.c
Replace 'probe' with 'channel' in most places.
[libsigrok.git] / hardware / lascar-el-usb / protocol.c
index d63027443c3964585ab67315e9eebd8a225a1b93..eeb22199f36fdfe2dd74e17afed64fa6b5548d2c 100644 (file)
@@ -55,7 +55,7 @@ static const struct elusb_profile profiles[] = {
 };
 
 
-SR_PRIV libusb_device_handle *lascar_open(struct libusb_device *dev)
+static libusb_device_handle *lascar_open(struct libusb_device *dev)
 {
        libusb_device_handle *dev_hdl;
        int ret;
@@ -202,7 +202,7 @@ cleanup:
        return *configlen ? SR_OK : SR_ERR;
 }
 
-SR_PRIV int lascar_save_config(libusb_device_handle *dev_hdl,
+static int lascar_save_config(libusb_device_handle *dev_hdl,
                unsigned char *config, int configlen)
 {
        struct drv_context *drvc;
@@ -293,7 +293,7 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
        struct dev_context *devc;
        const struct elusb_profile *profile;
        struct sr_dev_inst *sdi;
-       struct sr_probe *probe;
+       struct sr_channel *ch;
        int modelid, i;
        char firmware[5];
 
@@ -328,9 +328,23 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
                        return NULL;
                sdi->driver = di;
 
-               if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
-                       return NULL;
-               sdi->probes = g_slist_append(NULL, probe);
+               if (profile->logformat == LOG_TEMP_RH) {
+                       /* Model this as two channels: temperature and humidity. */
+                       if (!(ch = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "Temp")))
+                               return NULL;
+                       sdi->channels = g_slist_append(NULL, ch);
+                       if (!(ch = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "Hum")))
+                               return NULL;
+                       sdi->channels = g_slist_append(sdi->channels, ch);
+               } else if (profile->logformat == LOG_CO) {
+                       if (!(ch = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "CO")))
+                               return NULL;
+                       sdi->channels = g_slist_append(NULL, ch);
+               } else {
+                       if (!(ch = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
+                               return NULL;
+                       sdi->channels = g_slist_append(NULL, ch);
+               }
 
                if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
                        return NULL;
@@ -384,12 +398,12 @@ static void lascar_el_usb_dispatch(struct sr_dev_inst *sdi, unsigned char *buf,
        struct dev_context *devc;
        struct sr_datafeed_packet packet;
        struct sr_datafeed_analog analog;
+       struct sr_channel *ch;
        float *temp, *rh;
        uint16_t s;
        int samples, samples_left, i, j;
 
        devc = sdi->priv;
-       analog.probes = sdi->probes;
 
        samples = buflen / devc->sample_size;
        samples_left = devc->logged_samples - devc->rcvd_samples;
@@ -421,24 +435,34 @@ static void lascar_el_usb_dispatch(struct sr_dev_inst *sdi, unsigned char *buf,
                }
                analog.num_samples = j;
 
-               analog.mq = SR_MQ_TEMPERATURE;
-               if (devc->temp_unit == 1)
-                       analog.unit = SR_UNIT_FAHRENHEIT;
-               else
-                       analog.unit = SR_UNIT_CELSIUS;
-               analog.data = temp;
-               sr_session_send(devc->cb_data, &packet);
+               ch = sdi->channels->data;
+               if (ch->enabled) {
+                       analog.channels = g_slist_append(NULL, ch);
+                       analog.mq = SR_MQ_TEMPERATURE;
+                       if (devc->temp_unit == 1)
+                               analog.unit = SR_UNIT_FAHRENHEIT;
+                       else
+                               analog.unit = SR_UNIT_CELSIUS;
+                       analog.data = temp;
+                       sr_session_send(devc->cb_data, &packet);
+               }
+
+               ch = sdi->channels->next->data;
+               if (ch->enabled) {
+                       analog.channels = g_slist_append(NULL, ch);
+                       analog.mq = SR_MQ_RELATIVE_HUMIDITY;
+                       analog.unit = SR_UNIT_PERCENTAGE;
+                       analog.data = rh;
+                       sr_session_send(devc->cb_data, &packet);
+               }
 
-               analog.mq = SR_MQ_RELATIVE_HUMIDITY;
-               analog.unit = SR_UNIT_PERCENTAGE;
-               analog.data = rh;
-               sr_session_send(devc->cb_data, &packet);
                g_free(temp);
                g_free(rh);
                break;
        case LOG_CO:
                packet.type = SR_DF_ANALOG;
                packet.payload = &analog;
+               analog.channels = sdi->channels;
                analog.num_samples = samples;
                analog.mq = SR_MQ_CARBON_MONOXIDE;
                analog.unit = SR_UNIT_CONCENTRATION;
@@ -464,24 +488,18 @@ static void lascar_el_usb_dispatch(struct sr_dev_inst *sdi, unsigned char *buf,
 
 SR_PRIV int lascar_el_usb_handle_events(int fd, int revents, void *cb_data)
 {
-       struct dev_context *devc;
        struct drv_context *drvc = di->priv;
        struct sr_datafeed_packet packet;
        struct sr_dev_inst *sdi;
        struct timeval tv;
-       int i;
 
        (void)fd;
        (void)revents;
 
        sdi = cb_data;
-       devc = sdi->priv;
 
        if (sdi->status == SR_ST_STOPPING) {
-               for (i = 0; devc->usbfd[i] != -1; i++)
-                       sr_source_remove(devc->usbfd[i]);
-
-               sdi->driver->dev_close(sdi);
+               usb_source_remove(drvc->sr_ctx);
 
                packet.type = SR_DF_END;
                sr_session_send(cb_data, &packet);
@@ -508,7 +526,7 @@ SR_PRIV void lascar_el_usb_receive_transfer(struct libusb_transfer *transfer)
        switch (transfer->status) {
        case LIBUSB_TRANSFER_NO_DEVICE:
                /* USB device was unplugged. */
-               hw_dev_acquisition_stop(sdi, sdi);
+               dev_acquisition_stop(sdi, sdi);
                return;
        case LIBUSB_TRANSFER_COMPLETED:
        case LIBUSB_TRANSFER_TIMED_OUT: /* We may have received some data though */
@@ -527,7 +545,7 @@ SR_PRIV void lascar_el_usb_receive_transfer(struct libusb_transfer *transfer)
                                devc->rcvd_bytes, devc->log_size,
                                devc->rcvd_samples, devc->logged_samples);
                if (devc->rcvd_bytes >= devc->log_size)
-                       hw_dev_acquisition_stop(sdi, sdi);
+                       dev_acquisition_stop(sdi, sdi);
        }
 
        if (sdi->status == SR_ST_ACTIVE) {
@@ -537,7 +555,7 @@ SR_PRIV void lascar_el_usb_receive_transfer(struct libusb_transfer *transfer)
                               libusb_error_name(ret));
                        g_free(transfer->buffer);
                        libusb_free_transfer(transfer);
-                       hw_dev_acquisition_stop(sdi, sdi);
+                       dev_acquisition_stop(sdi, sdi);
                }
        } else {
                /* This was the last transfer we're going to receive, so
@@ -571,10 +589,13 @@ static int set_flags(unsigned char *configblock, int flags)
 SR_PRIV int lascar_is_logging(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
+       struct sr_usb_dev_inst *usb;
        int dummy, flags, ret;
 
        devc = sdi->priv;
-       if (lascar_get_config(devc->usb->devhdl, devc->config, &dummy) != SR_OK)
+       usb = sdi->conn;
+
+       if (lascar_get_config(usb->devhdl, devc->config, &dummy) != SR_OK)
                return -1;
 
        flags = get_flags(devc->config);
@@ -589,10 +610,13 @@ SR_PRIV int lascar_is_logging(const struct sr_dev_inst *sdi)
 SR_PRIV int lascar_start_logging(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
+       struct sr_usb_dev_inst *usb;
        int len, flags, ret;
 
        devc = sdi->priv;
-       if (lascar_get_config(devc->usb->devhdl, devc->config, &len) != SR_OK)
+       usb = sdi->conn;
+
+       if (lascar_get_config(usb->devhdl, devc->config, &len) != SR_OK)
                return SR_ERR;
 
        /* Turn on logging. */
@@ -603,7 +627,7 @@ SR_PRIV int lascar_start_logging(const struct sr_dev_inst *sdi)
        /* Start logging in 0 seconds. */
        memset(devc->config + 24, 0, 4);
 
-       ret = lascar_save_config(devc->usb->devhdl, devc->config, len);
+       ret = lascar_save_config(usb->devhdl, devc->config, len);
        sr_info("Started internal logging.");
 
        return ret;
@@ -612,19 +636,21 @@ SR_PRIV int lascar_start_logging(const struct sr_dev_inst *sdi)
 SR_PRIV int lascar_stop_logging(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
+       struct sr_usb_dev_inst *usb;
        int len, flags, ret;
 
        devc = sdi->priv;
-       if (lascar_get_config(devc->usb->devhdl, devc->config, &len) != SR_OK)
+       usb = sdi->conn;
+
+       if (lascar_get_config(usb->devhdl, devc->config, &len) != SR_OK)
                return SR_ERR;
 
        flags = get_flags(devc->config);
        flags &= ~0x0100;
        set_flags(devc->config, flags);
 
-       ret = lascar_save_config(devc->usb->devhdl, devc->config, len);
+       ret = lascar_save_config(usb->devhdl, devc->config, len);
        sr_info("Stopped internal logging.");
 
        return ret;
 }
-