demo: Properly handle logic vs. analog when setting the pattern.

This commit is contained in:
Bert Vermeulen 2014-01-12 23:31:23 +01:00
parent 7a1da33198
commit 2388ae860c
1 changed files with 67 additions and 53 deletions

View File

@ -41,9 +41,8 @@
/* Size of the analog pattern space per channel. */ /* Size of the analog pattern space per channel. */
#define ANALOG_BUFSIZE 4096 #define ANALOG_BUFSIZE 4096
/* Patterns we can generate */ /* Logic patterns we can generate. */
enum { enum {
/* Logic */
/** /**
* Spells "sigrok" across 8 probes using '0's (with '1's as * Spells "sigrok" across 8 probes using '0's (with '1's as
* "background") when displayed using the 'bits' output format. * "background") when displayed using the 'bits' output format.
@ -66,8 +65,10 @@ enum {
/** All probes have a high logic state. */ /** All probes have a high logic state. */
PATTERN_ALL_HIGH, PATTERN_ALL_HIGH,
};
/* Analog */ /* Analog patterns we can generate. */
enum {
/** /**
* Square wave. * Square wave.
*/ */
@ -106,6 +107,7 @@ struct dev_context {
/* Logic */ /* Logic */
int32_t num_logic_probes; int32_t num_logic_probes;
unsigned int logic_unitsize; unsigned int logic_unitsize;
/* There is only ever one logic probe group, so its pattern goes here. */
uint8_t logic_pattern; uint8_t logic_pattern;
unsigned char logic_data[LOGIC_BUFSIZE]; unsigned char logic_data[LOGIC_BUFSIZE];
/* Analog */ /* Analog */
@ -319,8 +321,12 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_probe_group *probe_group) const struct sr_probe_group *probe_group)
{ {
struct dev_context *devc; struct dev_context *devc;
struct sr_probe *probe;
struct analog_gen *ag;
int pattern;
(void)probe_group; if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv; devc = sdi->priv;
switch (id) { switch (id) {
@ -334,7 +340,18 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
*data = g_variant_new_uint64(devc->limit_msec); *data = g_variant_new_uint64(devc->limit_msec);
break; break;
case SR_CONF_PATTERN_MODE: case SR_CONF_PATTERN_MODE:
*data = g_variant_new_string(logic_pattern_str[devc->logic_pattern]); if (!probe_group)
return SR_ERR_PROBE_GROUP;
probe = probe_group->probes->data;
if (probe->type == SR_PROBE_LOGIC) {
pattern = devc->logic_pattern;
*data = g_variant_new_string(logic_pattern_str[pattern]);
} else if (probe->type == SR_PROBE_ANALOG) {
ag = probe_group->priv;
pattern = ag->pattern;
*data = g_variant_new_string(analog_pattern_str[pattern]);
} else
return SR_ERR_BUG;
break; break;
case SR_CONF_NUM_LOGIC_PROBES: case SR_CONF_NUM_LOGIC_PROBES:
*data = g_variant_new_int32(devc->num_logic_probes); *data = g_variant_new_int32(devc->num_logic_probes);
@ -353,9 +370,8 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
const struct sr_probe_group *probe_group) const struct sr_probe_group *probe_group)
{ {
struct dev_context *devc; struct dev_context *devc;
struct sr_probe_group *pg; struct sr_probe *probe;
GSList *l; int pattern, ret;
int logic_pattern, analog_pattern, ret;
unsigned int i; unsigned int i;
const char *stropt; const char *stropt;
@ -364,66 +380,62 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
if (sdi->status != SR_ST_ACTIVE) if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED; return SR_ERR_DEV_CLOSED;
ret = SR_ERR; ret = SR_OK;
if (id == SR_CONF_SAMPLERATE) { switch (id) {
case SR_CONF_SAMPLERATE:
devc->cur_samplerate = g_variant_get_uint64(data); devc->cur_samplerate = g_variant_get_uint64(data);
sr_dbg("Setting samplerate to %" PRIu64, devc->cur_samplerate); sr_dbg("Setting samplerate to %" PRIu64, devc->cur_samplerate);
ret = SR_OK; break;
} else if (id == SR_CONF_LIMIT_SAMPLES) { case SR_CONF_LIMIT_SAMPLES:
devc->limit_msec = 0; devc->limit_msec = 0;
devc->limit_samples = g_variant_get_uint64(data); devc->limit_samples = g_variant_get_uint64(data);
sr_dbg("Setting sample limit to %" PRIu64, devc->limit_samples); sr_dbg("Setting sample limit to %" PRIu64, devc->limit_samples);
ret = SR_OK; break;
} else if (id == SR_CONF_LIMIT_MSEC) { case SR_CONF_LIMIT_MSEC:
/* TODO: convert to limit_samples */
devc->limit_msec = g_variant_get_uint64(data); devc->limit_msec = g_variant_get_uint64(data);
devc->limit_samples = 0; devc->limit_samples = 0;
sr_dbg("Setting time limit to %" PRIu64"ms", devc->limit_msec); sr_dbg("Setting time limit to %" PRIu64"ms", devc->limit_msec);
ret = SR_OK; break;
} else if (id == SR_CONF_PATTERN_MODE) { case SR_CONF_PATTERN_MODE:
if (!probe_group)
return SR_ERR_PROBE_GROUP;
stropt = g_variant_get_string(data, NULL); stropt = g_variant_get_string(data, NULL);
logic_pattern = analog_pattern = -1; probe = probe_group->probes->data;
/* Is it a logic pattern? */ pattern = -1;
for (i = 0; i < ARRAY_SIZE(logic_pattern_str); i++) { if (probe->type == SR_PROBE_LOGIC) {
if (!strcmp(stropt, logic_pattern_str[i])) { for (i = 0; i < ARRAY_SIZE(logic_pattern_str); i++) {
logic_pattern = i; if (!strcmp(stropt, logic_pattern_str[i])) {
break; pattern = i;
}
}
if (logic_pattern == -1) {
/* Is it an analog pattern? */
for (i = 0; i < ARRAY_SIZE(analog_pattern_str); i++) {
if (!strcmp(stropt, analog_pattern_str[i])) {
analog_pattern = i;
break; break;
} }
} }
} if (pattern == -1)
if (logic_pattern > -1) { return SR_ERR_ARG;
devc->logic_pattern = logic_pattern; devc->logic_pattern = pattern;
/* Might as well do this now. */
if (logic_pattern == PATTERN_ALL_LOW) /* Might as well do this now, these are static. */
if (pattern == PATTERN_ALL_LOW)
memset(devc->logic_data, 0x00, LOGIC_BUFSIZE); memset(devc->logic_data, 0x00, LOGIC_BUFSIZE);
else if (logic_pattern == PATTERN_ALL_HIGH) else if (pattern == PATTERN_ALL_HIGH)
memset(devc->logic_data, 0xff, LOGIC_BUFSIZE); memset(devc->logic_data, 0xff, LOGIC_BUFSIZE);
ret = SR_OK; sr_dbg("Setting logic pattern to %s",
sr_dbg("Setting logic pattern to %s", logic_pattern_str[logic_pattern]); logic_pattern_str[pattern]);
} else if (analog_pattern > -1) { } else if (probe->type == SR_PROBE_ANALOG) {
sr_dbg("Setting analog pattern to %s", analog_pattern_str[analog_pattern]); for (i = 0; i < ARRAY_SIZE(analog_pattern_str); i++) {
if (probe_group) if (!strcmp(stropt, analog_pattern_str[i])) {
set_analog_pattern(probe_group, analog_pattern); pattern = i;
else { break;
/* No probe group specified, apply pattern to all of them. */
for (l = sdi->probe_groups; l; l = l->next) {
pg = l->data;
set_analog_pattern(pg, analog_pattern);
} }
ret = SR_OK;
} }
} else { if (pattern == -1)
ret = SR_ERR; return SR_ERR_ARG;
} sr_dbg("Setting analog pattern to %s",
} else { analog_pattern_str[pattern]);
set_analog_pattern(probe_group, pattern);
} else
return SR_ERR_BUG;
break;
default:
ret = SR_ERR_NA; ret = SR_ERR_NA;
} }
@ -475,9 +487,11 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
if (probe->type == SR_PROBE_LOGIC) if (probe->type == SR_PROBE_LOGIC)
*data = g_variant_new_strv(logic_pattern_str, *data = g_variant_new_strv(logic_pattern_str,
ARRAY_SIZE(logic_pattern_str)); ARRAY_SIZE(logic_pattern_str));
else else if (probe->type == SR_PROBE_ANALOG)
*data = g_variant_new_strv(analog_pattern_str, *data = g_variant_new_strv(analog_pattern_str,
ARRAY_SIZE(analog_pattern_str)); ARRAY_SIZE(analog_pattern_str));
else
return SR_ERR_BUG;
break; break;
default: default:
return SR_ERR_NA; return SR_ERR_NA;