]> sigrok.org Git - libsigrok.git/commitdiff
colead-slm: Use software limit helpers
authorLars-Peter Clausen <redacted>
Sun, 1 May 2016 11:52:35 +0000 (13:52 +0200)
committerUwe Hermann <redacted>
Mon, 9 May 2016 10:12:14 +0000 (12:12 +0200)
Signed-off-by: Lars-Peter Clausen <redacted>
src/hardware/colead-slm/api.c
src/hardware/colead-slm/protocol.c
src/hardware/colead-slm/protocol.h

index 880c6039f44402f377c21e2d34409dc4cfdb17ab..01da31a96c8dd75f427110a8193e966823f0f3a9 100644 (file)
@@ -85,6 +85,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        sdi->vendor = g_strdup("Colead");
        sdi->model = g_strdup("SL-5868P");
        devc = g_malloc0(sizeof(struct dev_context));
+       sr_sw_limits_init(&devc->limits);
        sdi->conn = sr_serial_dev_inst_new(conn, serialcomm);
        sdi->inst_type = SR_INST_SERIAL;
        sdi->priv = devc;
@@ -111,19 +112,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                return SR_ERR_BUG;
        }
 
-       switch (key) {
-       case SR_CONF_LIMIT_MSEC:
-               /* TODO: not yet implemented */
-               devc->limit_msec = g_variant_get_uint64(data);;
-               break;
-       case SR_CONF_LIMIT_SAMPLES:
-               devc->limit_samples = g_variant_get_uint64(data);
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return sr_sw_limits_config_set(&devc->limits, key, data);
 }
 
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
@@ -150,11 +139,13 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 {
+       struct dev_context *devc = sdi->priv;
        struct sr_serial_dev_inst *serial;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
+       sr_sw_limits_acquisition_start(&devc->limits);
        std_session_send_df_header(sdi, LOG_PREFIX);
 
        /* Poll every 150ms, or whenever some data comes in. */
index c7acc9e3d5b159f36b9f4043c4bc8b1b0b8d59ff..c0494fbec805054a813be2dfed3e94955fe0dfd6 100644 (file)
@@ -171,8 +171,9 @@ static void process_packet(const struct sr_dev_inst *sdi)
        packet.payload = &analog;
        sr_session_send(sdi, &packet);
 
-       devc->num_samples++;
-       if (devc->num_samples >= devc->limit_samples)
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
+
+       if (sr_sw_limits_check(&devc->limits))
                sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi);
 }
 
index ab878e759f2efa42bb5a80ddf029db8639629594..8b298bb7648b132bd901502a0932c7d8d2713525 100644 (file)
@@ -33,14 +33,8 @@ enum {
 
 /** Private, per-device-instance driver context. */
 struct dev_context {
-       /** The current sampling limit (in number of samples). */
-       uint64_t limit_samples;
+       struct sr_sw_limits limits;
 
-       /** The current sampling limit (in ms). */
-       uint64_t limit_msec;
-
-       /** The current number of already received samples. */
-       uint64_t num_samples;
        int state;
        char buf[10];
        int buflen;