uni-t-ut32x: use common code for sw limits, minor data type fixup (data source)
authorGerhard Sittig <gerhard.sittig@gmx.net>
Thu, 5 Oct 2017 21:16:50 +0000 (23:16 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Sun, 13 Jan 2019 18:34:10 +0000 (19:34 +0100)
src/hardware/uni-t-ut32x/api.c
src/hardware/uni-t-ut32x/protocol.c
src/hardware/uni-t-ut32x/protocol.h

index b49080d..fe54350 100644 (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
index 6e04dd9..1d4324b 100644 (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);
 }
 
index 59f81ea..acc453e 100644 (file)
 #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;