]> sigrok.org Git - libsigrok.git/commitdiff
hantek-dso: support for SR_HWCAP_FILTER
authorBert Vermeulen <redacted>
Tue, 15 May 2012 20:41:00 +0000 (22:41 +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

index ba55e86805be572c80f1aa4fb95902a02614d9ef..898bccec597ff3648174874a0922a02dcdc679de 100644 (file)
@@ -48,6 +48,7 @@ static int capabilities[] = {
        SR_HWCAP_TRIGGER_SOURCE,
        SR_HWCAP_TRIGGER_SLOPE,
        SR_HWCAP_HORIZ_TRIGGERPOS,
+       SR_HWCAP_FILTER,
        0,
 };
 
@@ -101,6 +102,13 @@ static char *trigger_sources[] = {
        NULL
 };
 
+static char *filter_targets[] = {
+       "CH1",
+       "CH2",
+       /* TODO: "TRIGGER", */
+       NULL
+};
+
 SR_PRIV libusb_context *usb_context = NULL;
 SR_PRIV GSList *dev_insts = NULL;
 
@@ -354,6 +362,9 @@ static void *hw_get_device_info(int dev_index, int dev_info_id)
        case SR_DI_TRIGGER_SOURCES:
                info = trigger_sources;
                break;
+       case SR_DI_FILTERS:
+               info = filter_targets;
+               break;
        /* TODO remove this */
        case SR_DI_CUR_SAMPLERATE:
                info = &tmp;
@@ -387,7 +398,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value)
        float tmp_float;
        uint64_t tmp_u64;
        int ret, i;
-       char *tmp_str;
+       char *tmp_str, **targets;
 
        if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
                return SR_ERR;
@@ -452,6 +463,26 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value)
                if (trigger_sources[i] == 0)
                        ret = SR_ERR_ARG;
                break;
+       case SR_HWCAP_FILTER:
+               ctx->filter_ch1 = ctx->filter_ch2 = ctx->filter_trigger = 0;
+               targets = g_strsplit(value, ",", 0);
+               for (i = 0; targets[i]; i++) {
+                       if (targets[i] == '\0')
+                               /* Empty filter string can be used to clear them all. */
+                               ;
+                       else if (!strcmp(targets[i], "CH1"))
+                               ctx->filter_ch1 = TRUE;
+                       else if (!strcmp(targets[i], "CH2"))
+                               ctx->filter_ch2 = TRUE;
+                       else if (!strcmp(targets[i], "TRIGGER"))
+                               ctx->filter_trigger = TRUE;
+                       else {
+                               sr_err("invalid filter target %s", targets[i]);
+                               ret = SR_ERR_ARG;
+                       }
+               }
+               g_strfreev(targets);
+               break;
        default:
                ret = SR_ERR_ARG;
        }
index aa5fe239051b9bce606e1d2a23ffe1c2ad604ed8..3f65eed9c7d3ba85cbdf7120d7c05cd2fcf38cf7 100644 (file)
@@ -338,17 +338,24 @@ SR_PRIV int dso_set_filters(struct context *ctx)
        int ret, tmp;
        uint8_t cmdstring[8];
 
-       sr_dbg("hantek-dso: sending CMD_SET_FILTERS");
+       sr_dbg("hantek-dso: preparing CMD_SET_FILTERS");
 
        memset(cmdstring, 0, sizeof(cmdstring));
        cmdstring[0] = CMD_SET_FILTERS;
        cmdstring[1] = 0x0f;
-       if (ctx->filter_ch1)
+       if (ctx->filter_ch1) {
+               sr_dbg("hantek-dso: turning on CH1 filter");
                cmdstring[2] |= 0x80;
-       if (ctx->filter_ch2)
+       }
+       if (ctx->filter_ch2) {
+               sr_dbg("hantek-dso: turning on CH2 filter");
                cmdstring[2] |= 0x40;
-       if (ctx->filter_trigger)
+       }
+       if (ctx->filter_trigger) {
+               /* TODO: supported on the DSO-2090? */
+               sr_dbg("hantek-dso: turning on trigger filter");
                cmdstring[2] |= 0x20;
+       }
 
        if (send_begin(ctx) != SR_OK)
                return SR_ERR;
@@ -360,6 +367,7 @@ SR_PRIV int dso_set_filters(struct context *ctx)
                sr_err("Failed to set filters: %d", ret);
                return SR_ERR;
        }
+       sr_dbg("hantek-dso: sent CMD_SET_FILTERS");
 
        return SR_OK;
 }