From: Bert Vermeulen Date: Sat, 15 Jun 2013 11:00:41 +0000 (+0200) Subject: cem-dt-885x: Support for changing time weighting X-Git-Tag: libsigrok-0.2.1~56 X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=1487ce4fbc0368058d16d42666fd8703e976f072;p=libsigrok.git cem-dt-885x: Support for changing time weighting --- diff --git a/hardware/cem-dt-885x/api.c b/hardware/cem-dt-885x/api.c index 22e6c7a5..834e4290 100644 --- a/hardware/cem-dt-885x/api.c +++ b/hardware/cem-dt-885x/api.c @@ -34,6 +34,7 @@ static const int32_t hwcaps[] = { SR_CONF_CONTINUOUS, SR_CONF_DATALOG, SR_CONF_SPL_WEIGHT_FREQ, + SR_CONF_SPL_WEIGHT_TIME, }; static const char *weight_freq[] = { @@ -41,6 +42,11 @@ static const char *weight_freq[] = { "C", }; +static const char *weight_time[] = { + "F", + "S", +}; + SR_PRIV struct sr_dev_driver cem_dt_885x_driver_info; static struct sr_dev_driver *di = &cem_dt_885x_driver_info; @@ -187,6 +193,15 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi) else return SR_ERR; break; + case SR_CONF_SPL_WEIGHT_TIME: + tmp = cem_dt_885x_weight_time_get(sdi); + if (tmp == SR_MQFLAG_SPL_TIME_WEIGHT_F) + *data = g_variant_new_string("F"); + else if (tmp == SR_MQFLAG_SPL_TIME_WEIGHT_S) + *data = g_variant_new_string("S"); + else + return SR_ERR; + break; default: return SR_ERR_NA; } @@ -236,6 +251,17 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi) else return SR_ERR_ARG; break; + case SR_CONF_SPL_WEIGHT_TIME: + tmp_str = g_variant_get_string(data, NULL); + if (!strcmp(tmp_str, "F")) + ret = cem_dt_885x_weight_time_set(sdi, + SR_MQFLAG_SPL_TIME_WEIGHT_F); + else if (!strcmp(tmp_str, "S")) + ret = cem_dt_885x_weight_time_set(sdi, + SR_MQFLAG_SPL_TIME_WEIGHT_S); + else + return SR_ERR_ARG; + break; default: ret = SR_ERR_NA; } @@ -262,6 +288,9 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) case SR_CONF_SPL_WEIGHT_FREQ: *data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq)); break; + case SR_CONF_SPL_WEIGHT_TIME: + *data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time)); + break; default: return SR_ERR_NA; } diff --git a/hardware/cem-dt-885x/protocol.c b/hardware/cem-dt-885x/protocol.c index c2def3e3..e9a92bc9 100644 --- a/hardware/cem-dt-885x/protocol.c +++ b/hardware/cem-dt-885x/protocol.c @@ -460,3 +460,66 @@ SR_PRIV int cem_dt_885x_weight_freq_set(const struct sr_dev_inst *sdi, int freqw return ret; } + +SR_PRIV int cem_dt_885x_weight_time_get(const struct sr_dev_inst *sdi) +{ + struct dev_context *devc; + int cur_setting; + char tokens[5]; + + devc = sdi->priv; + + cur_setting = devc->cur_mqflags & (SR_MQFLAG_SPL_TIME_WEIGHT_F | SR_MQFLAG_SPL_TIME_WEIGHT_S); + if (cur_setting == 0) { + /* Didn't pick up device state yet. */ + tokens[0] = TOKEN_WEIGHT_TIME_FAST; + tokens[1] = TOKEN_WEIGHT_TIME_SLOW; + tokens[2] = -1; + if (wait_for_token(sdi, tokens, 0) != SR_OK) + return SR_ERR; + if (devc->token == TOKEN_WEIGHT_TIME_FAST) + return SR_MQFLAG_SPL_TIME_WEIGHT_F; + else + return SR_MQFLAG_SPL_TIME_WEIGHT_S; + } else + return cur_setting; + +} + +SR_PRIV int cem_dt_885x_weight_time_set(const struct sr_dev_inst *sdi, int timew) +{ + struct dev_context *devc; + int cur_setting, ret; + char tokens[5]; + + devc = sdi->priv; + + cur_setting = devc->cur_mqflags & (SR_MQFLAG_SPL_TIME_WEIGHT_F | SR_MQFLAG_SPL_TIME_WEIGHT_S); + if (cur_setting == timew) + /* Already set to this time weighting. */ + return SR_OK; + + /* The toggle below needs the desired state in first position. */ + if (timew == SR_MQFLAG_SPL_TIME_WEIGHT_F) { + tokens[0] = TOKEN_WEIGHT_TIME_FAST; + tokens[1] = TOKEN_WEIGHT_TIME_SLOW; + } else { + tokens[0] = TOKEN_WEIGHT_TIME_SLOW; + tokens[1] = TOKEN_WEIGHT_TIME_FAST; + } + tokens[2] = -1; + + if (cur_setting == 0) { + /* Didn't pick up device state yet. */ + if (wait_for_token(sdi, tokens, 0) != SR_OK) + return SR_ERR; + if (devc->token == tokens[0]) + /* Nothing to do. */ + return SR_OK; + } + + /* 51ms timeout seems to work best for this. */ + ret = cem_dt_885x_toggle(sdi, CMD_TOGGLE_WEIGHT_TIME, tokens, 51); + + return ret; +} diff --git a/hardware/cem-dt-885x/protocol.h b/hardware/cem-dt-885x/protocol.h index 7bf6ea8e..a2e77e75 100644 --- a/hardware/cem-dt-885x/protocol.h +++ b/hardware/cem-dt-885x/protocol.h @@ -69,6 +69,7 @@ enum { enum { CMD_TOGGLE_RECORDING = 0x55, CMD_TOGGLE_WEIGHT_FREQ = 0x99, + CMD_TOGGLE_WEIGHT_TIME = 0x77, }; /** Private, per-device-instance driver context. */ @@ -107,5 +108,7 @@ SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean st SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi); SR_PRIV int cem_dt_885x_weight_freq_get(const struct sr_dev_inst *sdi); SR_PRIV int cem_dt_885x_weight_freq_set(const struct sr_dev_inst *sdi, int freqw); +SR_PRIV int cem_dt_885x_weight_time_get(const struct sr_dev_inst *sdi); +SR_PRIV int cem_dt_885x_weight_time_set(const struct sr_dev_inst *sdi, int timew); #endif