From: Gerhard Sittig Date: Sat, 17 Jun 2017 15:58:45 +0000 (+0200) Subject: demo: Unbreak execution with all analog channels disabled X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d91d0b12505c4c9062e0b66775fa9d8431429f49;p=libsigrok.git demo: Unbreak execution with all analog channels disabled The 'demo' driver supports scan options to adjust the number of supported channels, and runtime control for the enabled state of channels. Starting with zero analog channels created (scan option) resulted in a runtime assertion. Creating but disabling analog channels (GUI checkbox, CLI option) resulted in unexpected output for disabled channels. Move the creation of a hash table out of the conditional loop that iterates over created analog channels. Which results in the table's always being valid, and iteration during data acquisition yields no analog output as is expected. This fixes bug #625. --- diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index 1f2e950e..17890f3f 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -135,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. */ @@ -142,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,