]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-6xxx/api.c
hantek-6xxx: add coupling support
[libsigrok.git] / src / hardware / hantek-6xxx / api.c
index 461c08a5d900a5c45591a4b05881f474a92bbbd2..beace1dae6d9fdd4fee9aa5d62ced0b7e6bb19dc 100644 (file)
@@ -43,12 +43,17 @@ static const uint32_t devopts[] = {
 
 static const uint32_t devopts_cg[] = {
        SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
+       SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
 };
 
 static const char *channel_names[] = {
        "CH1", "CH2",
 };
 
+static const char *coupling[] = {
+       "AC", "DC",
+};
+
 static const struct hantek_6xxx_profile dev_profiles[] = {
        {
                0x04b4, 0x6022, 0x04b5, 0x6022,
@@ -103,6 +108,7 @@ static struct sr_dev_inst *hantek_6xxx_dev_new(const struct hantek_6xxx_profile
        for (i = 0; i < NUM_CHANNELS; i++) {
                devc->ch_enabled[i] = TRUE;
                devc->voltage[i] = DEFAULT_VOLTAGE;
+               devc->coupling[i] = DEFAULT_COUPLING;
        }
 
        devc->sample_buf = NULL;
@@ -382,6 +388,9 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
                        vdiv = vdivs[devc->voltage[ch_idx]];
                        *data = g_variant_new("(tt)", vdiv[0], vdiv[1]);
                        break;
+               case SR_CONF_COUPLING:
+                       *data = g_variant_new_string(coupling[devc->coupling[ch_idx]]);
+                       break;
                }
        }
 
@@ -395,6 +404,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        uint64_t p, q;
        int tmp_int, ch_idx, ret;
        unsigned int i;
+       const char *tmp_str;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
@@ -440,6 +450,17 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                        } else
                                ret = SR_ERR_ARG;
                        break;
+               case SR_CONF_COUPLING:
+                       tmp_str = g_variant_get_string(data, NULL);
+                       for (i = 0; coupling[i]; i++) {
+                               if (!strcmp(tmp_str, coupling[i])) {
+                                       devc->coupling[ch_idx] = i;
+                                       break;
+                               }
+                       }
+                       if (coupling[i] == 0)
+                               ret = SR_ERR_ARG;
+                       break;
                default:
                        ret = SR_ERR_NA;
                        break;
@@ -493,6 +514,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                        *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
                                devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
                        break;
+               case SR_CONF_COUPLING:
+                       *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
+                       break;
                case SR_CONF_VDIV:
                        g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                        for (i = 0; i < ARRAY_SIZE(vdivs); i++) {