]> sigrok.org Git - libsigrok.git/commitdiff
hantek-dso: fix channel selection
authorBert Vermeulen <redacted>
Tue, 1 May 2012 18:35:04 +0000 (20:35 +0200)
committerBert Vermeulen <redacted>
Wed, 30 May 2012 21:56:12 +0000 (23:56 +0200)
hardware/hantek-dso/api.c
hardware/hantek-dso/dso.c
hardware/hantek-dso/dso.h

index d1b98078607e5fadd8d89259a21ae78bf24c9c33..002beaaf8b2168cfd82cee410fdb5b39e9f2c32e 100644 (file)
@@ -92,7 +92,6 @@ static struct sr_dev_inst *dso_dev_new(int index, struct dso_profile *prof)
        ctx->voffset_ch1 = DEFAULT_VERT_OFFSET;
        ctx->voffset_ch2 = DEFAULT_VERT_OFFSET;
        ctx->voffset_trigger = DEFAULT_VERT_TRIGGERPOS;
-       ctx->selected_channel = DEFAULT_SELECTED_CHANNEL;
        ctx->framesize = DEFAULT_FRAMESIZE;
        ctx->triggerslope = SLOPE_POSITIVE;
        ctx->triggersource = DEFAULT_TRIGGER_SOURCE;
@@ -108,11 +107,12 @@ static int configure_probes(struct context *ctx, GSList *probes)
        struct sr_probe *probe;
        GSList *l;
 
+       ctx->ch1_enabled = ctx->ch2_enabled = FALSE;
        for (l = probes; l; l = l->next) {
                probe = (struct sr_probe *)l->data;
-               if (probe->index == 0)
+               if (probe->index == 1)
                        ctx->ch1_enabled = probe->enabled;
-               else if (probe->index == 1)
+               else if (probe->index == 2)
                        ctx->ch2_enabled = probe->enabled;
        }
 
@@ -372,7 +372,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
        struct sr_datafeed_analog analog;
        struct context *ctx;
        float ch1, ch2;
-       int i;
+       int num_probes, data_offset, i;
 
        ctx = transfer->user_data;
        sr_dbg("hantek-dso: receive_transfer(): status %d received %d bytes",
@@ -385,17 +385,27 @@ static void receive_transfer(struct libusb_transfer *transfer)
        ctx->current_transfer += transfer->actual_length;
        sr_dbg("hantek-dso: got %d of %d in frame", ctx->current_transfer, ctx->framesize * 2);
 
+       num_probes = (ctx->ch1_enabled && ctx->ch2_enabled) ? 2 : 1;
        packet.type = SR_DF_ANALOG;
        packet.payload = &analog;
+       /* TODO: support for 5xxx series 9-bit samples */
        analog.num_samples = transfer->actual_length / 2;
-       analog.data = g_try_malloc(analog.num_samples * sizeof(float) * ctx->profile->num_probes);
+       analog.data = g_try_malloc(analog.num_samples * sizeof(float) * num_probes);
+       data_offset = 0;
        for (i = 0; i < analog.num_samples; i++) {
-               /* Hardcoded for two channels, since the order/encoding is specific. */
+               /* The device always sends data for both channels. If a channel
+                * is disabled, it contains a copy of the enabled channel's
+                * data. However, we only send the requested channels to the bus.
+                */
                /* TODO: support for 5xxx series 9-bit samples */
-               ch2 = (*(transfer->buffer + i * 2) / 255.0);
-               ch1 = (*(transfer->buffer + i * 2 + 1) / 255.0);
-               analog.data[i * ctx->profile->num_probes] = ch1;
-               analog.data[i * ctx->profile->num_probes + 1] = ch2;
+               if (ctx->ch1_enabled) {
+                       ch1 = (*(transfer->buffer + i * 2 + 1) / 255.0);
+                       analog.data[data_offset++] = ch1;
+               }
+               if (ctx->ch2_enabled) {
+                       ch2 = (*(transfer->buffer + i * 2) / 255.0);
+                       analog.data[data_offset++] = ch2;
+               }
        }
        g_free(transfer->buffer);
        libusb_free_transfer(transfer);
@@ -408,6 +418,7 @@ static void receive_transfer(struct libusb_transfer *transfer)
 
                if (ctx->limit_frames && ++ctx->num_frames == ctx->limit_frames) {
                        /* Terminate session */
+                       /* TODO: don't leave pending USB transfers hanging */
                        packet.type = SR_DF_END;
                        sr_session_send(ctx->cb_data, &packet);
                } else {
index 278b2ebef021094a8d41bea16dd49c8a45aeb3b2..ab6d09ecb8a8332fb7b464a819f146284322a507 100644 (file)
@@ -253,9 +253,9 @@ SR_PRIV int dso_set_trigger_samplerate(struct context *ctx)
        }
        cmdstring[2] |= tmp & 0x07;
 cmdstring[2] = 0x45;
-       /* Selected channel */
-       cmdstring[3] = (ctx->selected_channel & 0x03) << 6;
-cmdstring[3] = 0x02;
+       /* Enabled channels */
+       tmp = (((ctx->ch2_enabled ? 1 : 0) << 1) + (ctx->ch1_enabled ? 1 : 0)) - 1;
+       cmdstring[3] = tmp;
 
        /* TODO: Fast rates channel */
        cmdstring[3] |= 0 << 5;
index 1bd93734c8be3d6aa8807446d5a02751e00db32b..1a0c69deb4326ee2884b704e13cebbc2b4f528a0 100644 (file)
@@ -37,7 +37,6 @@
 #define DEFAULT_TIMEBASE           TIME_1ms
 #define DEFAULT_TRIGGER_SOURCE     TRIGGER_CH1
 #define DEFAULT_COUPLING           COUPLING_AC
-#define DEFAULT_SELECTED_CHANNEL   SELECT_CH1CH2
 /* Halfway between min and max = 0V */
 #define DEFAULT_HORIZ_TRIGGERPOS   0x1400
 
@@ -123,12 +122,6 @@ enum trigger_sources {
        TRIGGER_EXT10
 };
 
-enum selected_channels {
-       SELECT_CH1 = 0,
-       SELECT_CH2,
-       SELECT_CH1CH2
-};
-
 enum capturestates {
        CAPTURE_EMPTY = 0,
        CAPTURE_FILLING = 1,
@@ -194,7 +187,6 @@ struct context {
        float voffset_ch2;
        float voffset_trigger;
        uint16_t channel_levels[2][9][2];
-       int selected_channel;
        int framesize;
        gboolean filter_ch1;
        gboolean filter_ch2;