uni-t-ut32x: use common code for sw limits, minor data type fixup (data source)

This commit is contained in:
Gerhard Sittig 2017-10-05 23:16:50 +02:00 committed by Uwe Hermann
parent bf700f679a
commit 9e11197246
3 changed files with 19 additions and 21 deletions

View File

@ -32,6 +32,7 @@ static const uint32_t drvopts[] = {
static const uint32_t devopts[] = {
SR_CONF_CONTINUOUS,
SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
SR_CONF_DATA_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
};
@ -83,7 +84,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
channel_names[i]);
devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc;
devc->limit_samples = 0;
sr_sw_limits_init(&devc->limits);
devc->data_source = DEFAULT_DATA_SOURCE;
devices = g_slist_append(devices, sdi);
}
@ -159,13 +160,10 @@ static int config_get(uint32_t key, GVariant **data,
devc = sdi->priv;
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
*data = g_variant_new_uint64(devc->limit_samples);
break;
case SR_CONF_LIMIT_MSEC:
return sr_sw_limits_config_get(&devc->limits, key, data);
case SR_CONF_DATA_SOURCE:
if (devc->data_source == DATA_SOURCE_LIVE)
*data = g_variant_new_string("Live");
else
*data = g_variant_new_string("Memory");
*data = g_variant_new_string(data_sources[devc->data_source]);
break;
default:
return SR_ERR_NA;
@ -186,8 +184,8 @@ static int config_set(uint32_t key, GVariant *data,
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
devc->limit_samples = g_variant_get_uint64(data);
break;
case SR_CONF_LIMIT_MSEC:
return sr_sw_limits_config_set(&devc->limits, key, data);
case SR_CONF_DATA_SOURCE:
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(data_sources))) < 0)
return SR_ERR_ARG;
@ -230,7 +228,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
devc = sdi->priv;
usb = sdi->conn;
devc->num_samples = 0;
sr_sw_limits_acquisition_start(&devc->limits);
devc->packet_len = 0;
/* Configure serial port parameters on USB-UART interface

View File

@ -136,11 +136,13 @@ static void process_packet(struct sr_dev_inst *sdi)
}
}
/* We count packets even if the temperature was invalid. This way
* a sample limit on "Memory" data source still works: unused
* memory slots come through as "----" measurements. */
devc->num_samples++;
if (devc->limit_samples && devc->num_samples >= devc->limit_samples)
/*
* We count packets even if the measurement was invalid. This way
* a sample limit on "Memory" data source still works: Unused
* memory slots come through as "----" measurements.
*/
sr_sw_limits_update_samples_read(&devc->limits, 1);
if (sr_sw_limits_check(&devc->limits))
sr_dev_acquisition_stop(sdi);
}

View File

@ -35,22 +35,20 @@
#define EP_IN (0x80 | 2)
#define EP_OUT 2
enum {
enum ut32x_data_source {
DATA_SOURCE_LIVE,
DATA_SOURCE_MEMORY,
};
enum {
enum ut32x_cmd_code {
CMD_GET_LIVE = 1,
CMD_STOP = 2,
CMD_GET_STORED = 7,
};
struct dev_context {
uint64_t limit_samples;
gboolean data_source;
uint64_t num_samples;
struct sr_sw_limits limits;
enum ut32x_data_source data_source;
unsigned char buf[8];
struct libusb_transfer *xfer;