]> sigrok.org Git - libsigrok.git/commitdiff
brymen-bm86x: support channel selection (enable/disable channels)
authorGerhard Sittig <redacted>
Fri, 18 Aug 2017 19:43:42 +0000 (21:43 +0200)
committerUwe Hermann <redacted>
Sat, 19 Aug 2017 17:21:54 +0000 (19:21 +0200)
The previous implementation unconditionally submitted analog data
whenever values could get extracted out of received serial packets.
This commit checks the channels' enabled state before submission. Care
is taken to obey the user's acquisition limits, exclusively counting
submitted not received values.

src/hardware/brymen-bm86x/protocol.c

index f9b2bde1b4b1e024cf3d0773bd3dd8e43db70a39..345fad57fcb49e0a2146006d0374a6b4d401c808 100644 (file)
@@ -214,6 +214,8 @@ static void brymen_bm86x_handle_packet(const struct sr_dev_inst *sdi,
        struct sr_analog_encoding encoding[2];
        struct sr_analog_meaning meaning[2];
        struct sr_analog_spec spec[2];
+       struct sr_channel *channel;
+       int sent_ch1, sent_ch2;
        float floatval[2];
 
        devc = sdi->priv;
@@ -223,30 +225,35 @@ static void brymen_bm86x_handle_packet(const struct sr_dev_inst *sdi,
        sr_analog_init(&analog[1], &encoding[1], &meaning[1], &spec[1], 0);
 
        brymen_bm86x_parse(buf, floatval, analog);
+       sent_ch1 = sent_ch2 = 0;
 
-       if (analog[0].meaning->mq != 0) {
+       channel = sdi->channels->data;
+       if (analog[0].meaning->mq != 0 && channel->enabled) {
                /* Got a measurement. */
+               sent_ch1 = 1;
                analog[0].num_samples = 1;
                analog[0].data = &floatval[0];
-               analog[0].meaning->channels = g_slist_append(NULL, sdi->channels->data);
+               analog[0].meaning->channels = g_slist_append(NULL, channel);
                packet.type = SR_DF_ANALOG;
                packet.payload = &analog[0];
                sr_session_send(sdi, &packet);
                g_slist_free(analog[0].meaning->channels);
        }
 
-       if (analog[1].meaning->mq != 0) {
+       channel = sdi->channels->next->data;
+       if (analog[1].meaning->mq != 0 && channel->enabled) {
                /* Got a measurement. */
+               sent_ch2 = 1;
                analog[1].num_samples = 1;
                analog[1].data = &floatval[1];
-               analog[1].meaning->channels = g_slist_append(NULL, sdi->channels->next->data);
+               analog[1].meaning->channels = g_slist_append(NULL, channel);
                packet.type = SR_DF_ANALOG;
                packet.payload = &analog[1];
                sr_session_send(sdi, &packet);
                g_slist_free(analog[1].meaning->channels);
        }
 
-       if (analog[0].meaning->mq != 0 || analog[1].meaning->mq != 0)
+       if (sent_ch1 || sent_ch2)
                sr_sw_limits_update_samples_read(&devc->sw_limits, 1);
 }