]> sigrok.org Git - libsigrok.git/commitdiff
devantech-eth008: make request for digital output optional
authorGerhard Sittig <redacted>
Mon, 25 Sep 2023 12:38:58 +0000 (14:38 +0200)
committerGerhard Sittig <redacted>
Mon, 25 Sep 2023 17:30:18 +0000 (19:30 +0200)
This is for consistency with other optional features like digital input
and analog input. Only transmit digital output related requests to the
firmware when the model supports it.

See whitespace ignoring diff for the essence.

src/hardware/devantech-eth008/protocol.c

index e2c3445a966a4e99551aa3300ab0f03351eb14a5..2e79717c9db05b45c590f6a4da9315813f67569f 100644 (file)
@@ -291,33 +291,35 @@ SR_PRIV int devantech_eth008_cache_state(const struct sr_dev_inst *sdi)
        if (!devc)
                return SR_ERR_ARG;
 
-       /* Unconditionally get the state of digital output. */
-       rx_size = devc->model->width_do;
-       if (rx_size > sizeof(rsp))
-               return SR_ERR_NA;
+       /* Get the state of digital outputs when the model supports them. */
+       if (devc->model->ch_count_do) {
+               rx_size = devc->model->width_do;
+               if (rx_size > sizeof(rsp))
+                       return SR_ERR_NA;
 
-       wrptr = req;
-       write_u8_inc(&wrptr, CMD_DIGITAL_GET_OUTPUTS);
-       ret = send_then_recv(serial, req, wrptr - req, rsp, rx_size);
-       if (ret != SR_OK)
-               return ret;
-       rdptr = rsp;
+               wrptr = req;
+               write_u8_inc(&wrptr, CMD_DIGITAL_GET_OUTPUTS);
+               ret = send_then_recv(serial, req, wrptr - req, rsp, rx_size);
+               if (ret != SR_OK)
+                       return ret;
+               rdptr = rsp;
 
-       switch (rx_size) {
-       case 1:
-               have = read_u8_inc(&rdptr);
-               break;
-       case 2:
-               have = read_u16le_inc(&rdptr);
-               break;
-       case 3:
-               have = read_u24le_inc(&rdptr);
-               break;
-       default:
-               return SR_ERR_NA;
+               switch (rx_size) {
+               case 1:
+                       have = read_u8_inc(&rdptr);
+                       break;
+               case 2:
+                       have = read_u16le_inc(&rdptr);
+                       break;
+               case 3:
+                       have = read_u24le_inc(&rdptr);
+                       break;
+               default:
+                       return SR_ERR_NA;
+               }
+               have &= devc->mask_do;
+               devc->curr_do = have;
        }
-       have &= devc->mask_do;
-       devc->curr_do = have;
 
        /*
         * Get the state of digital inputs when the model supports them.