From: Gerhard Sittig Date: Mon, 25 Sep 2023 12:38:58 +0000 (+0200) Subject: devantech-eth008: make request for digital output optional X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a04cd800c9e5f03507986f425e65c4dc1fdd3437;p=libsigrok.git devantech-eth008: make request for digital output optional 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. --- diff --git a/src/hardware/devantech-eth008/protocol.c b/src/hardware/devantech-eth008/protocol.c index e2c3445a..2e79717c 100644 --- a/src/hardware/devantech-eth008/protocol.c +++ b/src/hardware/devantech-eth008/protocol.c @@ -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.