]> sigrok.org Git - libsigrok.git/commitdiff
demo: optionally accept frame limit spec at scan time
authorGerhard Sittig <redacted>
Thu, 3 May 2018 19:51:46 +0000 (21:51 +0200)
committerGerhard Sittig <redacted>
Sun, 13 May 2018 18:03:21 +0000 (20:03 +0200)
Allow developers to specify the (default) number of frames at compile
time (default to "off" as before). Accept the frame limit spec at scan()
time as well. This is useful when applications don't run config_set() at
runtime.

Tested with:
$ pulseview -d demo:logic_channels=0:analog_channels=1:limit_frames=4

src/hardware/demo/api.c
src/hardware/demo/protocol.h

index 052878da292849ab1e9b0b9dff2ea54316c3f754..a44aa0985141bf11a13d15005f29790f94247c61 100644 (file)
@@ -50,6 +50,7 @@ static const char *logic_pattern_str[] = {
 static const uint32_t scanopts[] = {
        SR_CONF_NUM_LOGIC_CHANNELS,
        SR_CONF_NUM_ANALOG_CHANNELS,
+       SR_CONF_LIMIT_FRAMES,
 };
 
 static const uint32_t drvopts[] = {
@@ -97,10 +98,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        struct analog_gen *ag;
        GSList *l;
        int num_logic_channels, num_analog_channels, pattern, i;
+       uint64_t limit_frames;
        char channel_name[16];
 
        num_logic_channels = DEFAULT_NUM_LOGIC_CHANNELS;
        num_analog_channels = DEFAULT_NUM_ANALOG_CHANNELS;
+       limit_frames = DEFAULT_LIMIT_FRAMES;
        for (l = options; l; l = l->next) {
                src = l->data;
                switch (src->key) {
@@ -110,6 +113,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                case SR_CONF_NUM_ANALOG_CHANNELS:
                        num_analog_channels = g_variant_get_int32(src->data);
                        break;
+               case SR_CONF_LIMIT_FRAMES:
+                       limit_frames = g_variant_get_uint64(src->data);
+                       break;
                }
        }
 
@@ -126,6 +132,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        devc->all_logic_channels_mask--;
        devc->logic_pattern = DEFAULT_LOGIC_PATTERN;
        devc->num_analog_channels = num_analog_channels;
+       devc->limit_frames = limit_frames;
 
        if (num_logic_channels > 0) {
                /* Logic channels, all in one channel group. */
index c61d0ee65a900c27e0a16c1a573f35c634c1c277..d21d0d6a359c9a26f2cd92d42e7a63650afdd94b 100644 (file)
@@ -35,6 +35,7 @@
 #define ANALOG_BUFSIZE                 4096
 /* This is a development feature: it starts a new frame every n samples. */
 #define SAMPLES_PER_FRAME              1000UL
+#define DEFAULT_LIMIT_FRAMES           0
 
 /* Logic patterns we can generate. */
 enum logic_pattern_type {