cem-dt-885x: Support for max/min hold modes

This commit is contained in:
Bert Vermeulen 2013-06-16 12:14:09 +02:00
parent 9fd6bc2054
commit a90e480cdc
3 changed files with 95 additions and 3 deletions

View File

@ -35,6 +35,8 @@ static const int32_t hwcaps[] = {
SR_CONF_DATALOG,
SR_CONF_SPL_WEIGHT_FREQ,
SR_CONF_SPL_WEIGHT_TIME,
SR_CONF_HOLD_MAX,
SR_CONF_HOLD_MIN,
};
static const char *weight_freq[] = {
@ -171,12 +173,13 @@ static int cleanup(void)
static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
int tmp;
int tmp, ret;
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
ret = SR_OK;
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
*data = g_variant_new_uint64(devc->limit_samples);
@ -202,18 +205,26 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
else
return SR_ERR;
break;
case SR_CONF_HOLD_MAX:
if ((ret = cem_dt_885x_holdmode_get(sdi, &tmp)) == SR_OK)
*data = g_variant_new_boolean(tmp == SR_MQFLAG_MAX);
break;
case SR_CONF_HOLD_MIN:
if ((ret = cem_dt_885x_holdmode_get(sdi, &tmp)) == SR_OK)
*data = g_variant_new_boolean(tmp == SR_MQFLAG_MIN);
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return ret;
}
static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
uint64_t tmp_u64;
int ret;
int tmp, ret;
const char *tmp_str;
if (sdi->status != SR_ST_ACTIVE)
@ -262,6 +273,14 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
else
return SR_ERR_ARG;
break;
case SR_CONF_HOLD_MAX:
tmp = g_variant_get_boolean(data) ? SR_MQFLAG_MAX : 0;
ret = cem_dt_885x_holdmode_set(sdi, tmp);
break;
case SR_CONF_HOLD_MIN:
tmp = g_variant_get_boolean(data) ? SR_MQFLAG_MIN : 0;
ret = cem_dt_885x_holdmode_set(sdi, tmp);
break;
default:
ret = SR_ERR_NA;
}

View File

@ -523,3 +523,72 @@ SR_PRIV int cem_dt_885x_weight_time_set(const struct sr_dev_inst *sdi, int timew
return ret;
}
SR_PRIV int cem_dt_885x_holdmode_get(const struct sr_dev_inst *sdi,
gboolean *holdmode)
{
struct dev_context *devc;
char tokens[5];
devc = sdi->priv;
if (devc->cur_mqflags == 0) {
tokens[0] = TOKEN_HOLD_MAX;
tokens[1] = TOKEN_HOLD_MIN;
tokens[2] = TOKEN_HOLD_NONE;
tokens[3] = -1;
if (wait_for_token(sdi, tokens, 0) != SR_OK)
return SR_ERR;
if (devc->token == TOKEN_HOLD_MAX)
devc->cur_mqflags = SR_MQFLAG_MAX;
else if (devc->token == TOKEN_HOLD_MIN)
devc->cur_mqflags = SR_MQFLAG_MIN;
}
*holdmode = devc->cur_mqflags & (SR_MQFLAG_MAX | SR_MQFLAG_MIN);
return SR_OK;
}
SR_PRIV int cem_dt_885x_holdmode_set(const struct sr_dev_inst *sdi, int holdmode)
{
struct dev_context *devc;
int cur_setting, ret;
char tokens[5];
devc = sdi->priv;
/* The toggle below needs the desired state in first position. */
if (holdmode == SR_MQFLAG_MAX) {
tokens[0] = TOKEN_HOLD_MAX;
tokens[1] = TOKEN_HOLD_MIN;
tokens[2] = TOKEN_HOLD_NONE;
} else if (holdmode == SR_MQFLAG_MIN) {
tokens[0] = TOKEN_HOLD_MIN;
tokens[1] = TOKEN_HOLD_MAX;
tokens[2] = TOKEN_HOLD_NONE;
} else {
tokens[0] = TOKEN_HOLD_NONE;
tokens[1] = TOKEN_HOLD_MAX;
tokens[2] = TOKEN_HOLD_MIN;
}
tokens[3] = -1;
if (devc->cur_mqflags == 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;
} else {
cur_setting = devc->cur_mqflags & (SR_MQFLAG_MAX | SR_MQFLAG_MIN);
if (cur_setting == holdmode)
/* Already set correctly. */
return SR_OK;
}
/* 51ms timeout seems to work best for this. */
ret = cem_dt_885x_toggle(sdi, CMD_TOGGLE_HOLD_MAX_MIN, tokens, 51);
return ret;
}

View File

@ -70,6 +70,7 @@ enum {
CMD_TOGGLE_RECORDING = 0x55,
CMD_TOGGLE_WEIGHT_FREQ = 0x99,
CMD_TOGGLE_WEIGHT_TIME = 0x77,
CMD_TOGGLE_HOLD_MAX_MIN = 0x11,
};
/** Private, per-device-instance driver context. */
@ -110,5 +111,8 @@ 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);
SR_PRIV int cem_dt_885x_holdmode_get(const struct sr_dev_inst *sdi,
gboolean *holdmode);
SR_PRIV int cem_dt_885x_holdmode_set(const struct sr_dev_inst *sdi, int holdmode);
#endif