From: Uwe Hermann Date: Thu, 3 Aug 2017 20:22:40 +0000 (+0200) Subject: drivers: Start counting at 0 for some loops. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d1ac53ccd5a5cf3b40539bb26509321cbc7df6b7;p=libsigrok.git drivers: Start counting at 0 for some loops. --- diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 7619f184..9cb4dc8e 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -287,15 +287,15 @@ static int config_set(uint32_t key, GVariant *data, return SR_ERR_CHANNEL_GROUP; if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0) return SR_ERR_ARG; - for (j = 1; j <= model->analog_channels; j++) { - if (cg != devc->analog_groups[j - 1]) + for (j = 0; j < model->analog_channels; j++) { + if (cg != devc->analog_groups[j]) continue; - state->analog_channels[j - 1].vdiv = idx; + state->analog_channels[j].vdiv = idx; g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]); g_snprintf(command, sizeof(command), (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV], - j, float_str); + j + 1, float_str); if (sr_scpi_send(sdi->conn, command) != SR_OK || sr_scpi_get_opc(sdi->conn) != SR_OK) return SR_ERR; @@ -344,13 +344,13 @@ static int config_set(uint32_t key, GVariant *data, return SR_ERR_CHANNEL_GROUP; if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) return SR_ERR_ARG; - for (j = 1; j <= model->analog_channels; j++) { - if (cg != devc->analog_groups[j - 1]) + for (j = 0; j <= model->analog_channels; j++) { + if (cg != devc->analog_groups[j]) continue; - state->analog_channels[j - 1].coupling = idx; + state->analog_channels[j].coupling = idx; g_snprintf(command, sizeof(command), (*model->scpi_dialect)[SCPI_CMD_SET_COUPLING], - j, (*model->coupling_options)[idx]); + j + 1, (*model->coupling_options)[idx]); if (sr_scpi_send(sdi->conn, command) != SR_OK || sr_scpi_get_opc(sdi->conn) != SR_OK) return SR_ERR; @@ -582,15 +582,15 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi) } } - for (i = 1; i <= model->digital_pods; i++) { - if (state->digital_pods[i - 1] == pod_enabled[i - 1]) + for (i = 0; i < model->digital_pods; i++) { + if (state->digital_pods[i] == pod_enabled[i]) continue; g_snprintf(command, sizeof(command), (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE], - i, pod_enabled[i - 1]); + i + 1, pod_enabled[i]); if (sr_scpi_send(scpi, command) != SR_OK) return SR_ERR; - state->digital_pods[i - 1] = pod_enabled[i - 1]; + state->digital_pods[i] = pod_enabled[i]; setup_changed = TRUE; } diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 62cb967b..a9d9e044 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -241,12 +241,12 @@ static int config_set(uint32_t key, GVariant *data, case SR_CONF_VDIV: if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0) return SR_ERR_ARG; - for (j = 1; j <= model->analog_channels; j++) { - if (cg != devc->analog_groups[j - 1]) + for (j = 0; j < model->analog_channels; j++) { + if (cg != devc->analog_groups[j]) continue; - state->analog_channels[j - 1].vdiv = idx; + state->analog_channels[j].vdiv = idx; g_snprintf(command, sizeof(command), - "C%d:VDIV %E", j, (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]); + "C%d:VDIV %E", j + 1, (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]); if (sr_scpi_send(sdi->conn, command) != SR_OK || sr_scpi_get_opc(sdi->conn) != SR_OK) return SR_ERR; @@ -290,12 +290,12 @@ static int config_set(uint32_t key, GVariant *data, case SR_CONF_COUPLING: if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) return SR_ERR_ARG; - for (j = 1; j <= model->analog_channels; j++) { - if (cg != devc->analog_groups[j - 1]) + for (j = 0; j < model->analog_channels; j++) { + if (cg != devc->analog_groups[j]) continue; - state->analog_channels[j - 1].coupling = idx; + state->analog_channels[j].coupling = idx; g_snprintf(command, sizeof(command), "C%d:COUPLING %s", - j, (*model->coupling_options)[idx]); + j + 1, (*model->coupling_options)[idx]); if (sr_scpi_send(sdi->conn, command) != SR_OK || sr_scpi_get_opc(sdi->conn) != SR_OK) return SR_ERR; diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index c3574a90..5e554608 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -320,13 +320,13 @@ static int config_set(uint32_t key, GVariant *data, return SR_ERR_CHANNEL_GROUP; if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(dlm_vdivs))) < 0) return SR_ERR_ARG; - for (j = 1; j <= model->analog_channels; j++) { - if (cg != devc->analog_groups[j - 1]) + for (j = 0; j < model->analog_channels; j++) { + if (cg != devc->analog_groups[j]) continue; - state->analog_states[j - 1].vdiv = idx; + state->analog_states[j].vdiv = idx; g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) dlm_vdivs[idx][0] / dlm_vdivs[idx][1]); - if (dlm_analog_chan_vdiv_set(sdi->conn, j, float_str) != SR_OK || + if (dlm_analog_chan_vdiv_set(sdi->conn, j + 1, float_str) != SR_OK || sr_scpi_get_opc(sdi->conn) != SR_OK) return SR_ERR; break; @@ -370,11 +370,11 @@ static int config_set(uint32_t key, GVariant *data, return SR_ERR_CHANNEL_GROUP; if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) return SR_ERR_ARG; - for (j = 1; j <= model->analog_channels; j++) { - if (cg != devc->analog_groups[j - 1]) + for (j = 0; j <= model->analog_channels; j++) { + if (cg != devc->analog_groups[j]) continue; - state->analog_states[j - 1].coupling = idx; - if (dlm_analog_chan_coupl_set(sdi->conn, j, (*model->coupling_options)[idx]) != SR_OK || + state->analog_states[j].coupling = idx; + if (dlm_analog_chan_coupl_set(sdi->conn, j + 1, (*model->coupling_options)[idx]) != SR_OK || sr_scpi_get_opc(sdi->conn) != SR_OK) return SR_ERR; break;