]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/demo/api.c
demo: Don't generate analog output data for disabled channels
[libsigrok.git] / src / hardware / demo / api.c
index 96f5c07818b114e726a9d164f2576cd147667f83..645ef5f2317744a3f019cb033528c5a9306266fe 100644 (file)
 #include "protocol.h"
 
 #define DEFAULT_NUM_LOGIC_CHANNELS     8
-#define DEFAULT_NUM_ANALOG_CHANNELS    4
+#define DEFAULT_LOGIC_PATTERN          PATTERN_SIGROK
 
+#define DEFAULT_NUM_ANALOG_CHANNELS    4
 #define DEFAULT_ANALOG_AMPLITUDE       10
 
+/* Note: No spaces allowed because of sigrok-cli. */
 static const char *logic_pattern_str[] = {
        "sigrok",
        "random",
        "incremental",
+       "walking-one",
+       "walking-zero",
        "all-low",
        "all-high",
+       "squid",
 };
 
 static const uint32_t drvopts[] = {
@@ -114,7 +119,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        devc->cur_samplerate = SR_KHZ(200);
        devc->num_logic_channels = num_logic_channels;
        devc->logic_unitsize = (devc->num_logic_channels + 7) / 8;
-       devc->logic_pattern = PATTERN_SIGROK;
+       devc->logic_pattern = DEFAULT_LOGIC_PATTERN;
        devc->num_analog_channels = num_analog_channels;
 
        if (num_logic_channels > 0) {
@@ -130,6 +135,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        }
 
        /* Analog channels, channel groups and pattern generators. */
+       devc->ch_ag = g_hash_table_new(g_direct_hash, g_direct_equal);
        if (num_analog_channels > 0) {
                pattern = 0;
                /* An "Analog" channel group with all analog channels in it. */
@@ -137,7 +143,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                acg->name = g_strdup("Analog");
                sdi->channel_groups = g_slist_append(sdi->channel_groups, acg);
 
-               devc->ch_ag = g_hash_table_new(g_direct_hash, g_direct_equal);
                for (i = 0; i < num_analog_channels; i++) {
                        snprintf(channel_name, 16, "A%d", i);
                        ch = sr_channel_new(sdi, i + num_logic_channels, SR_CHANNEL_ANALOG,
@@ -152,6 +157,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                        /* Every channel gets a generator struct. */
                        ag = g_malloc(sizeof(struct analog_gen));
+                       ag->ch = ch;
                        ag->amplitude = DEFAULT_ANALOG_AMPLITUDE;
                        sr_analog_init(&ag->packet, &ag->encoding, &ag->meaning, &ag->spec, 2);
                        ag->packet.meaning->channels = cg->channels;
@@ -472,6 +478,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        /* We use this timestamp to decide how many more samples to send. */
        devc->start_us = g_get_monotonic_time();
        devc->spent_us = 0;
+       devc->step = 0;
 
        return SR_OK;
 }