From: Bert Vermeulen Date: Sun, 16 Jun 2013 11:23:58 +0000 (+0200) Subject: cem-dt-885x: Fix datalog on/off setting in max/min hold mode X-Git-Tag: libsigrok-0.2.1~53 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0cd9107dfb6fc36d816fd93a7b45dc2e0a990578;p=libsigrok.git cem-dt-885x: Fix datalog on/off setting in max/min hold mode As it turns out, the device randomly decides to send no logging state info when max hold or min hold mode is enabled. --- diff --git a/hardware/cem-dt-885x/api.c b/hardware/cem-dt-885x/api.c index f2329c38..64055914 100644 --- a/hardware/cem-dt-885x/api.c +++ b/hardware/cem-dt-885x/api.c @@ -185,7 +185,8 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi) *data = g_variant_new_uint64(devc->limit_samples); break; case SR_CONF_DATALOG: - *data = g_variant_new_boolean(cem_dt_885x_recording_get(sdi)); + if ((ret = cem_dt_885x_recording_get(sdi, &tmp)) == SR_OK) + *data = g_variant_new_boolean(tmp); break; case SR_CONF_SPL_WEIGHT_FREQ: tmp = cem_dt_885x_weight_freq_get(sdi); @@ -243,13 +244,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi) ret = SR_OK; break; case SR_CONF_DATALOG: - if (g_variant_get_boolean(data)) { - /* Start logging. */ - ret = cem_dt_885x_recording_set(sdi, TRUE); - } else { - /* Stop logging. */ - ret = cem_dt_885x_recording_set(sdi, FALSE); - } + ret = cem_dt_885x_recording_set(sdi, g_variant_get_boolean(data)); break; case SR_CONF_SPL_WEIGHT_FREQ: tmp_str = g_variant_get_string(data, NULL); diff --git a/hardware/cem-dt-885x/protocol.c b/hardware/cem-dt-885x/protocol.c index 173117b6..33fe1405 100644 --- a/hardware/cem-dt-885x/protocol.c +++ b/hardware/cem-dt-885x/protocol.c @@ -343,26 +343,28 @@ SR_PRIV int cem_dt_885x_toggle(const struct sr_dev_inst *sdi, uint8_t cmd, return SR_OK; } -SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi) +SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi, + int *state) { struct dev_context *devc; char tokens[5]; devc = sdi->priv; - if (devc->recording == -1) { /* Didn't pick up device state yet. */ tokens[0] = TOKEN_RECORDING_ON; tokens[1] = TOKEN_RECORDING_OFF; tokens[2] = -1; - if (wait_for_token(sdi, tokens, 0) != SR_OK) + if (wait_for_token(sdi, tokens, 510) != SR_OK) return SR_ERR; } + *state = devc->token == TOKEN_RECORDING_ON; - return devc->token == TOKEN_RECORDING_ON; + return SR_OK; } -SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean start) +SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, + gboolean state) { struct dev_context *devc; int ret; @@ -371,7 +373,7 @@ SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean st devc = sdi->priv; /* The toggle below needs the desired state in first position. */ - if (start) { + if (state) { tokens[0] = TOKEN_RECORDING_ON; tokens[1] = TOKEN_RECORDING_OFF; } else { @@ -387,7 +389,7 @@ SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean st if (devc->token == tokens[0]) /* Nothing to do. */ return SR_OK; - } else if (devc->recording == start) + } else if (devc->recording == state) /* Nothing to do. */ return SR_OK; diff --git a/hardware/cem-dt-885x/protocol.h b/hardware/cem-dt-885x/protocol.h index 49fe55d3..a7d6203b 100644 --- a/hardware/cem-dt-885x/protocol.h +++ b/hardware/cem-dt-885x/protocol.h @@ -106,7 +106,8 @@ enum { SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data); SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean start); -SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi); +SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi, + int *state); 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);