]> sigrok.org Git - libsigrok.git/blobdiff - hardware/cem-dt-885x/protocol.c
cem-dt-885x: Support for changing time weighting
[libsigrok.git] / hardware / cem-dt-885x / protocol.c
index c2def3e310e5540e49f03ad0fd6b557621895e21..e9a92bc95fa4697fc68a23088381c5c33709827e 100644 (file)
@@ -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;
+}