]> sigrok.org Git - libsigrok.git/commitdiff
hwdriver: Change TRIGGER_SLOPE setting to string type.
authorDaniel Elstner <redacted>
Sun, 26 Jan 2014 23:22:01 +0000 (00:22 +0100)
committerBert Vermeulen <redacted>
Mon, 27 Jan 2014 19:55:01 +0000 (20:55 +0100)
Drivers interpreted the uint64 values to the SR_CONF_TRIGGER_SLOPE
configuration setting in different ways.  In order to orthogonalize
the API, change the type of the setting to a string with the same
format as uses for logic probes.

hardware/hameg-hmo/api.c
hardware/hantek-dso/api.c
hardware/link-mso19/api.c
hardware/rigol-ds/api.c
hwdriver.c

index 2dd3c011a87712dfc184a19d1ea886db1cdd0112..b63ee51bb8cf4347032e6bb8920c66d77c38e8a0 100644 (file)
@@ -513,7 +513,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
        struct scope_config *model;
        struct scope_state *state;
        const char *tmp;
-       uint64_t p, q, tmp_u64;
+       uint64_t p, q;
        double tmp_d;
        gboolean update_sample_rate;
 
@@ -612,16 +612,16 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
                ret = sr_scpi_send(sdi->conn, command);
                break;
        case SR_CONF_TRIGGER_SLOPE:
-               tmp_u64 = g_variant_get_uint64(data);
+               tmp = g_variant_get_string(data, NULL);
 
-               if (tmp_u64 != 0 && tmp_u64 != 1)
-                       return SR_ERR;
+               if (!tmp || !(tmp[0] == 'f' || tmp[0] == 'r'))
+                       return SR_ERR_ARG;
 
-               state->trigger_slope = tmp_u64;
+               state->trigger_slope = (tmp[0] == 'r') ? 0 : 1;
 
                g_snprintf(command, sizeof(command),
                           (*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SLOPE],
-                          tmp_u64 ? "POS" : "NEG");
+                          (state->trigger_slope == 0) ? "POS" : "NEG");
 
                ret = sr_scpi_send(sdi->conn, command);
                break;
index 3da04264b5279b3c43af0f2ae1da43f0d3a721d1..41c78290ef79b38a77341276de1292ca3cb93a3b 100644 (file)
@@ -478,10 +478,11 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
                devc->limit_frames = g_variant_get_uint64(data);
                break;
        case SR_CONF_TRIGGER_SLOPE:
-               tmp_u64 = g_variant_get_uint64(data);
-               if (tmp_u64 != SLOPE_NEGATIVE && tmp_u64 != SLOPE_POSITIVE)
-                       ret = SR_ERR_ARG;
-               devc->triggerslope = tmp_u64;
+               tmp_str = g_variant_get_string(data, NULL);
+               if (!tmp_str || !(tmp_str[0] == 'f' || tmp_str[0] == 'r'))
+                       return SR_ERR_ARG;
+               devc->triggerslope = (tmp_str[0] == 'r')
+                       ? SLOPE_POSITIVE : SLOPE_NEGATIVE;
                break;
        case SR_CONF_HORIZ_TRIGGERPOS:
                tmp_double = g_variant_get_double(data);
index e283a2cb7fb9cacf94ef2409c18da3c6124eba04..654f876ed853ec454376be525cff2f58f8bfa507 100644 (file)
@@ -302,7 +302,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
 {
        int ret;
        struct dev_context *devc;
-       uint64_t num_samples, slope;
+       uint64_t num_samples;
+       const char *slope;
        int trigger_pos;
        double pos;
 
@@ -334,12 +335,14 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
                ret = SR_OK;
                break;
        case SR_CONF_TRIGGER_SLOPE:
-               slope = g_variant_get_uint64(data);
-               if (slope != SLOPE_NEGATIVE && slope != SLOPE_POSITIVE) {
+               slope = g_variant_get_string(data, NULL);
+
+               if (!slope || !(slope[0] == 'f' || slope[0] == 'r'))
                        sr_err("Invalid trigger slope");
                        ret = SR_ERR_ARG;
                } else {
-                       devc->trigger_slope = slope;
+                       devc->trigger_slope = (slope[0] == 'r')
+                               ? SLOPE_POSITIVE : SLOPE_NEGATIVE;
                        ret = SR_OK;
                }
                break;
index 4fc0cd17b11984bc3756315bc2a2398c450a925c..76c2efc7c811d91fd6c9b9944845d0afc39719b5 100644 (file)
@@ -657,7 +657,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
                const struct sr_probe_group *probe_group)
 {
        struct dev_context *devc;
-       uint64_t tmp_u64, p, q;
+       uint64_t p, q;
        double t_dbl;
        unsigned int i, j;
        int ret;
@@ -682,11 +682,13 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
                devc->limit_frames = g_variant_get_uint64(data);
                break;
        case SR_CONF_TRIGGER_SLOPE:
-               tmp_u64 = g_variant_get_uint64(data);
-               if (tmp_u64 != 0 && tmp_u64 != 1)
-                       return SR_ERR;
+               tmp_str = g_variant_get_string(data, NULL);
+
+               if (!tmp_str || !(tmp_str[0] == 'f' || tmp_str[0] == 'r'))
+                       return SR_ERR_ARG;
+
                g_free(devc->trigger_slope);
-               devc->trigger_slope = g_strdup(tmp_u64 ? "POS" : "NEG");
+               devc->trigger_slope = g_strdup((tmp_str[0] == 'r') ? "POS" : "NEG");
                ret = rigol_ds_config_set(sdi, ":TRIG:EDGE:SLOP %s", devc->trigger_slope);
                break;
        case SR_CONF_HORIZ_TRIGGERPOS:
index 88b6f638e04722903a96ab79164f6f282a36598d..302ffdc5196eba6a19127cc6e7e5bda615942a2b 100644 (file)
@@ -62,7 +62,7 @@ static struct sr_config_info sr_config_info_data[] = {
                "Swap channel order", NULL},
        {SR_CONF_RLE, SR_T_BOOL, "rle",
                "Run Length Encoding", NULL},
-       {SR_CONF_TRIGGER_SLOPE, SR_T_UINT64, "triggerslope",
+       {SR_CONF_TRIGGER_SLOPE, SR_T_CHAR, "triggerslope",
                "Trigger slope", NULL},
        {SR_CONF_TRIGGER_SOURCE, SR_T_CHAR, "triggersource",
                "Trigger source", NULL},