]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-6xxx/api.c
testo: Convert to SR_DF_ANALOG.
[libsigrok.git] / src / hardware / hantek-6xxx / api.c
index 1227e7b9e24cb11dde2ca161ef0a4e5632f28993..8848c9138576c8cf1330154ddf3bf6d900510d68 100644 (file)
@@ -78,13 +78,11 @@ static int read_channel(const struct sr_dev_inst *sdi, uint32_t amount);
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi);
 
-static struct sr_dev_inst *hantek_6xxx_dev_new(struct sr_dev_driver *di,
-       const struct hantek_6xxx_profile *prof)
+static struct sr_dev_inst *hantek_6xxx_dev_new(const struct hantek_6xxx_profile *prof)
 {
        struct sr_dev_inst *sdi;
        struct sr_channel *ch;
        struct sr_channel_group *cg;
-       struct drv_context *drvc;
        struct dev_context *devc;
        unsigned int i;
 
@@ -92,7 +90,6 @@ static struct sr_dev_inst *hantek_6xxx_dev_new(struct sr_dev_driver *di,
        sdi->status = SR_ST_INITIALIZING;
        sdi->vendor = g_strdup(prof->vendor);
        sdi->model = g_strdup(prof->model);
-       sdi->driver = di;
 
        for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
                ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
@@ -119,8 +116,6 @@ static struct sr_dev_inst *hantek_6xxx_dev_new(struct sr_dev_driver *di,
        devc->samplerate = DEFAULT_SAMPLERATE;
 
        sdi->priv = devc;
-       drvc = sdi->driver->context;
-       drvc->instances = g_slist_append(drvc->instances, sdi);
 
        return sdi;
 }
@@ -222,7 +217,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                                /* Device matches the pre-firmware profile. */
                                prof = &dev_profiles[j];
                                sr_dbg("Found a %s %s.", prof->vendor, prof->model);
-                               sdi = hantek_6xxx_dev_new(di, prof);
+                               sdi = hantek_6xxx_dev_new(prof);
                                sdi->connection_id = g_strdup(connection_id);
                                devices = g_slist_append(devices, sdi);
                                devc = sdi->priv;
@@ -241,7 +236,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                                /* Device matches the post-firmware profile. */
                                prof = &dev_profiles[j];
                                sr_dbg("Found a %s %s.", prof->vendor, prof->model);
-                               sdi = hantek_6xxx_dev_new(di, prof);
+                               sdi = hantek_6xxx_dev_new(prof);
                                sdi->connection_id = g_strdup(connection_id);
                                sdi->status = SR_ST_INACTIVE;
                                devices = g_slist_append(devices, sdi);
@@ -258,7 +253,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        }
        libusb_free_device_list(devlist, 1);
 
-       return devices;
+       return std_scan_complete(di, devices);
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
@@ -547,7 +542,10 @@ static void send_chunk(struct sr_dev_inst *sdi, unsigned char *buf,
                int num_samples)
 {
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog_old analog;
+       struct sr_datafeed_analog analog;
+       struct sr_analog_encoding encoding;
+       struct sr_analog_meaning meaning;
+       struct sr_analog_spec spec;
        struct dev_context *devc = sdi->priv;
        int num_channels, data_offset, i;
 
@@ -559,15 +557,17 @@ static void send_chunk(struct sr_dev_inst *sdi, unsigned char *buf,
        const gboolean ch1_ena = !!devc->ch_enabled[0];
        const gboolean ch2_ena = !!devc->ch_enabled[1];
 
+       sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
+
        num_channels = (ch1_ena && ch2_ena) ? 2 : 1;
-       packet.type = SR_DF_ANALOG_OLD;
+       packet.type = SR_DF_ANALOG;
        packet.payload = &analog;
 
-       analog.channels = devc->enabled_channels;
+       analog.meaning->channels = devc->enabled_channels;
        analog.num_samples = num_samples;
-       analog.mq = SR_MQ_VOLTAGE;
-       analog.unit = SR_UNIT_VOLT;
-       analog.mqflags = 0;
+       analog.meaning->mq = SR_MQ_VOLTAGE;
+       analog.meaning->unit = SR_UNIT_VOLT;
+       analog.meaning->mqflags = 0;
 
        analog.data = g_try_malloc(analog.num_samples * sizeof(float) * num_channels);
        if (!analog.data) {
@@ -590,9 +590,9 @@ static void send_chunk(struct sr_dev_inst *sdi, unsigned char *buf,
                 * represents 5V peak-to-peak where 0 = -2.5V and 255 = +2.5V.
                 */
                if (ch1_ena)
-                       analog.data[data_offset++] = (ch1_bit * *(buf + i * 2) - ch1_center);
+                       ((float *)analog.data)[data_offset++] = (ch1_bit * *(buf + i * 2) - ch1_center);
                if (ch2_ena)
-                       analog.data[data_offset++] = (ch2_bit * *(buf + i * 2 + 1) - ch2_center);
+                       ((float *)analog.data)[data_offset++] = (ch2_bit * *(buf + i * 2 + 1) - ch2_center);
        }
 
        sr_session_send(sdi, &packet);
@@ -744,7 +744,7 @@ static int handle_event(int fd, int revents, void *cb_data)
                 */
                usb_source_remove(sdi->session, drvc->sr_ctx);
 
-               std_session_send_df_end(sdi, LOG_PREFIX);
+               std_session_send_df_end(sdi);
 
                devc->dev_state = IDLE;
 
@@ -773,7 +773,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        if (hantek_6xxx_init(sdi) != SR_OK)
                return SR_ERR;
 
-       std_session_send_df_header(sdi, LOG_PREFIX);
+       std_session_send_df_header(sdi);
 
        devc->samp_received = 0;
        devc->dev_state = FLUSH;
@@ -803,7 +803,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-SR_PRIV struct sr_dev_driver hantek_6xxx_driver_info = {
+static struct sr_dev_driver hantek_6xxx_driver_info = {
        .name = "hantek-6xxx",
        .longname = "Hantek 6xxx",
        .api_version = 1,
@@ -821,3 +821,4 @@ SR_PRIV struct sr_dev_driver hantek_6xxx_driver_info = {
        .dev_acquisition_stop = dev_acquisition_stop,
        .context = NULL,
 };
+SR_REGISTER_DEV_DRIVER(hantek_6xxx_driver_info);