From: Daniel Elstner Date: Sun, 26 Jan 2014 23:22:01 +0000 (+0100) Subject: hwdriver: Change TRIGGER_SLOPE setting to string type. X-Git-Tag: libsigrok-0.3.0~184 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ca9b9f4834f106ba8387cf962a216425e0476de5;p=libsigrok.git hwdriver: Change TRIGGER_SLOPE setting to string type. 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. --- diff --git a/hardware/hameg-hmo/api.c b/hardware/hameg-hmo/api.c index 2dd3c011..b63ee51b 100644 --- a/hardware/hameg-hmo/api.c +++ b/hardware/hameg-hmo/api.c @@ -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; diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index 3da04264..41c78290 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -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); diff --git a/hardware/link-mso19/api.c b/hardware/link-mso19/api.c index e283a2cb..654f876e 100644 --- a/hardware/link-mso19/api.c +++ b/hardware/link-mso19/api.c @@ -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; diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c index 4fc0cd17..76c2efc7 100644 --- a/hardware/rigol-ds/api.c +++ b/hardware/rigol-ds/api.c @@ -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: diff --git a/hwdriver.c b/hwdriver.c index 88b6f638..302ffdc5 100644 --- a/hwdriver.c +++ b/hwdriver.c @@ -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},