]> sigrok.org Git - libsigrok.git/commitdiff
hantek-4032l: Set new pwm threshold handling.
authorAndrej Valek <redacted>
Tue, 22 May 2018 20:33:12 +0000 (22:33 +0200)
committerUwe Hermann <redacted>
Tue, 5 Jun 2018 15:16:39 +0000 (17:16 +0200)
Calculate threshold values from <-6.0;6.0> range.

Signed-off-by: Andrej Valek <redacted>
src/hardware/hantek-4032l/api.c
src/hardware/hantek-4032l/protocol.h

index 33c55c692270a31afbd9881a61b09675b2e48798..0e2a0213f4fc0c553ebefd6870a1f27adfe1374b 100644 (file)
@@ -39,7 +39,7 @@ static const uint32_t devopts[] = {
        SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_TRIGGER_MATCH | SR_CONF_LIST,
        SR_CONF_CONN | SR_CONF_GET,
-       SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_SET | SR_CONF_LIST,
+       SR_CONF_VOLTAGE_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
 };
 
 static const int32_t trigger_matches[] = {
@@ -210,13 +210,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                /* Initialize command packet. */
                devc->cmd_pkt.magic = H4032L_CMD_PKT_MAGIC;
-               devc->cmd_pkt.pwm_a = h4032l_voltage2pwm(2.5);
-               devc->cmd_pkt.pwm_b = h4032l_voltage2pwm(2.5);
                devc->cmd_pkt.sample_size = 16384;
 
                devc->status = H4032L_STATUS_IDLE;
 
                devc->capture_ratio = 5;
+               devc->cur_threshold = 2.5;
 
                sdi->priv = devc;
                devices = g_slist_append(devices, sdi);
@@ -298,6 +297,9 @@ static int config_get(uint32_t key, GVariant **data,
        (void)cg;
 
        switch (key) {
+       case SR_CONF_VOLTAGE_THRESHOLD:
+               *data = std_gvar_tuple_double(devc->cur_threshold, devc->cur_threshold);
+               break;
        case SR_CONF_SAMPLERATE:
                *data = g_variant_new_uint64(samplerates_hw[devc->cmd_pkt.sample_rate]);
                break;
@@ -364,10 +366,9 @@ static int config_set(uint32_t key, GVariant *data,
                        break;
                }
        case SR_CONF_VOLTAGE_THRESHOLD: {
-                       double d1, d2;
-                       g_variant_get(data, "(dd)", &d1, &d2);
-                       devc->cmd_pkt.pwm_a = h4032l_voltage2pwm(d1);
-                       devc->cmd_pkt.pwm_b = h4032l_voltage2pwm(d2);
+                       double low, high;
+                       g_variant_get(data, "(dd)", &low, &high);
+                       devc->cur_threshold = (low+high)/2.0;
                        break;
                }
        default:
@@ -391,7 +392,7 @@ static int config_list(uint32_t key, GVariant **data,
                *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
                break;
        case SR_CONF_VOLTAGE_THRESHOLD:
-               *data = std_gvar_tuple_double(2.5, 2.5);
+               *data = std_gvar_min_max_step_thresholds(-6.0, 6.0, 0.1);
                break;
        case SR_CONF_LIMIT_SAMPLES:
                *data = std_gvar_tuple_u64(H4043L_NUM_SAMPLES_MIN, H4032L_NUM_SAMPLES_MAX);
@@ -420,6 +421,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        cmd_pkt->pre_trigger_size = (cmd_pkt->sample_size * devc->capture_ratio) / 100;
        devc->trigger_pos = cmd_pkt->pre_trigger_size;
 
+       /* Set pwm channel values. */
+       devc->cmd_pkt.pwm_a = h4032l_voltage2pwm(devc->cur_threshold);
+       devc->cmd_pkt.pwm_b = devc->cmd_pkt.pwm_a;
+
        cmd_pkt->trig_flags.enable_trigger1 = 0;
        cmd_pkt->trig_flags.enable_trigger2 = 0;
        cmd_pkt->trig_flags.trigger_and_logic = 0;
index 8665c8f08e83efab5139f5a523731885a73835c0..f2ea313de301ff7aaa460b0eb22c7cb7f4a3572d 100644 (file)
@@ -136,6 +136,7 @@ struct dev_context {
        uint8_t buffer[512];
        uint64_t capture_ratio;
        uint32_t trigger_pos;
+       double cur_threshold;
        uint32_t fpga_version;
 };