]> sigrok.org Git - libsigrok.git/commitdiff
hantek-4032l: Fix default threshold value selection (FP workaround).
authorAndrej Valek <redacted>
Thu, 23 Aug 2018 18:48:43 +0000 (20:48 +0200)
committerUwe Hermann <redacted>
Mon, 3 Sep 2018 23:39:06 +0000 (01:39 +0200)
Take value from generated array of range instead of using a hard-coded value.

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

index 729a85da6204910c1298ab2f2a16146de060cea5..6ee46dee0642972ce16bb954fdcd705d93234d38 100644 (file)
@@ -261,8 +261,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                devc->external_clock = FALSE;
                devc->clock_edge = H4032L_CLOCK_EDGE_TYPE_RISE;
 
-               devc->cur_threshold[0] = 2.5;
-               devc->cur_threshold[1] = 2.5;
+               /* Create array of thresholds from min to max. */
+               GVariant *thresholds = std_gvar_min_max_step_thresholds(
+                       H4032L_THR_VOLTAGE_MIN, H4032L_THR_VOLTAGE_MAX,
+                       H4032L_THR_VOLTAGE_STEP);
+               /* Take default threshold value from array (FP workaround). */
+               g_variant_get_child(thresholds, H4032L_THR_VOLTAGE_DEFAULT,
+                       "(dd)", &devc->cur_threshold[0], &devc->cur_threshold[1]);
 
                sdi->priv = devc;
                devices = g_slist_append(devices, sdi);
@@ -468,7 +473,8 @@ 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_min_max_step_thresholds(-6.0, 6.0, 0.1);
+               *data = std_gvar_min_max_step_thresholds(H4032L_THR_VOLTAGE_MIN,
+                       H4032L_THR_VOLTAGE_MAX, H4032L_THR_VOLTAGE_STEP);
                break;
        case SR_CONF_LIMIT_SAMPLES:
                *data = std_gvar_tuple_u64(H4043L_NUM_SAMPLES_MIN, H4032L_NUM_SAMPLES_MAX);
index 15a0951cb0885726bfb03335491b492f6552b821..f0e46d376ea1f66cdef1db9fb4cf5e0e5733e5d5 100644 (file)
 #define H4043L_NUM_SAMPLES_MIN (2 * 1024)
 #define H4032L_NUM_SAMPLES_MAX (64 * 1024 * 1024)
 
+#define H4032L_THR_VOLTAGE_MIN -6.0
+#define H4032L_THR_VOLTAGE_MAX 6.0
+#define H4032L_THR_VOLTAGE_STEP 0.1
+/*
+ * Array index of the default voltage threshold value (2.5V):
+ * (|min| / step) + (default / step) = (|-6.0| / 0.1) + (2.5 / 0.1) = 85
+ */
+#define H4032L_THR_VOLTAGE_DEFAULT 85
+
 #define H4032L_CMD_PKT_MAGIC 0x017f
 #define H4032L_STATUS_PACKET_MAGIC 0x2B1A037F
 #define H4032L_START_PACKET_MAGIC 0x2B1A027F