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[] = { static const uint32_t devopts[] = {
SR_CONF_CONTINUOUS, SR_CONF_CONTINUOUS,
SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, 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, 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]); channel_names[i]);
devc = g_malloc0(sizeof(struct dev_context)); devc = g_malloc0(sizeof(struct dev_context));
sdi->priv = devc; sdi->priv = devc;
devc->limit_samples = 0; sr_sw_limits_init(&devc->limits);
devc->data_source = DEFAULT_DATA_SOURCE; devc->data_source = DEFAULT_DATA_SOURCE;
devices = g_slist_append(devices, sdi); devices = g_slist_append(devices, sdi);
} }
@ -159,13 +160,10 @@ static int config_get(uint32_t key, GVariant **data,
devc = sdi->priv; devc = sdi->priv;
switch (key) { switch (key) {
case SR_CONF_LIMIT_SAMPLES: case SR_CONF_LIMIT_SAMPLES:
*data = g_variant_new_uint64(devc->limit_samples); case SR_CONF_LIMIT_MSEC:
break; return sr_sw_limits_config_get(&devc->limits, key, data);
case SR_CONF_DATA_SOURCE: case SR_CONF_DATA_SOURCE:
if (devc->data_source == DATA_SOURCE_LIVE) *data = g_variant_new_string(data_sources[devc->data_source]);
*data = g_variant_new_string("Live");
else
*data = g_variant_new_string("Memory");
break; break;
default: default:
return SR_ERR_NA; return SR_ERR_NA;
@ -186,8 +184,8 @@ static int config_set(uint32_t key, GVariant *data,
switch (key) { switch (key) {
case SR_CONF_LIMIT_SAMPLES: case SR_CONF_LIMIT_SAMPLES:
devc->limit_samples = g_variant_get_uint64(data); case SR_CONF_LIMIT_MSEC:
break; return sr_sw_limits_config_set(&devc->limits, key, data);
case SR_CONF_DATA_SOURCE: case SR_CONF_DATA_SOURCE:
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(data_sources))) < 0) if ((idx = std_str_idx(data, ARRAY_AND_SIZE(data_sources))) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
@ -230,7 +228,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
devc = sdi->priv; devc = sdi->priv;
usb = sdi->conn; usb = sdi->conn;
devc->num_samples = 0; sr_sw_limits_acquisition_start(&devc->limits);
devc->packet_len = 0; devc->packet_len = 0;
/* Configure serial port parameters on USB-UART interface /* 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 * We count packets even if the measurement was invalid. This way
* memory slots come through as "----" measurements. */ * a sample limit on "Memory" data source still works: Unused
devc->num_samples++; * memory slots come through as "----" measurements.
if (devc->limit_samples && devc->num_samples >= devc->limit_samples) */
sr_sw_limits_update_samples_read(&devc->limits, 1);
if (sr_sw_limits_check(&devc->limits))
sr_dev_acquisition_stop(sdi); sr_dev_acquisition_stop(sdi);
} }

View File

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