]> sigrok.org Git - libsigrok.git/commitdiff
cem-dt-885x: Support for changing time weighting
authorBert Vermeulen <redacted>
Sat, 15 Jun 2013 11:00:41 +0000 (13:00 +0200)
committerBert Vermeulen <redacted>
Mon, 17 Jun 2013 14:17:39 +0000 (16:17 +0200)
hardware/cem-dt-885x/api.c
hardware/cem-dt-885x/protocol.c
hardware/cem-dt-885x/protocol.h

index 22e6c7a5c03c0d2611cc8e3d942b85ac8d0b7fa1..834e4290d24a153dc0442927e3dfa98326e93c3d 100644 (file)
@@ -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;
        }
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;
+}
index 7bf6ea8e4be0ee7d6ca51f73d3734851188c0044..a2e77e758fbc3d1eb59ceb2e8e9f6d90eaeebc55 100644 (file)
@@ -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