drivers: Start counting at 0 for some loops.

This commit is contained in:
Uwe Hermann 2017-08-03 22:22:40 +02:00
parent b3fd09937c
commit d1ac53ccd5
3 changed files with 28 additions and 28 deletions

View File

@ -287,15 +287,15 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0) if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 1; j <= model->analog_channels; j++) { for (j = 0; j < model->analog_channels; j++) {
if (cg != devc->analog_groups[j - 1]) if (cg != devc->analog_groups[j])
continue; continue;
state->analog_channels[j - 1].vdiv = idx; state->analog_channels[j].vdiv = idx;
g_ascii_formatd(float_str, sizeof(float_str), "%E", g_ascii_formatd(float_str, sizeof(float_str), "%E",
(float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]); (float) (*model->vdivs)[idx][0] / (*model->vdivs)[idx][1]);
g_snprintf(command, sizeof(command), g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV], (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV],
j, float_str); j + 1, float_str);
if (sr_scpi_send(sdi->conn, command) != SR_OK || if (sr_scpi_send(sdi->conn, command) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
@ -344,13 +344,13 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 1; j <= model->analog_channels; j++) { for (j = 0; j <= model->analog_channels; j++) {
if (cg != devc->analog_groups[j - 1]) if (cg != devc->analog_groups[j])
continue; continue;
state->analog_channels[j - 1].coupling = idx; state->analog_channels[j].coupling = idx;
g_snprintf(command, sizeof(command), g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_COUPLING], (*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 || if (sr_scpi_send(sdi->conn, command) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; 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++) { for (i = 0; i < model->digital_pods; i++) {
if (state->digital_pods[i - 1] == pod_enabled[i - 1]) if (state->digital_pods[i] == pod_enabled[i])
continue; continue;
g_snprintf(command, sizeof(command), g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE], (*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) if (sr_scpi_send(scpi, command) != SR_OK)
return SR_ERR; return SR_ERR;
state->digital_pods[i - 1] = pod_enabled[i - 1]; state->digital_pods[i] = pod_enabled[i];
setup_changed = TRUE; setup_changed = TRUE;
} }

View File

@ -241,12 +241,12 @@ static int config_set(uint32_t key, GVariant *data,
case SR_CONF_VDIV: case SR_CONF_VDIV:
if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0) if ((idx = std_u64_tuple_idx(data, *model->vdivs, model->num_vdivs)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 1; j <= model->analog_channels; j++) { for (j = 0; j < model->analog_channels; j++) {
if (cg != devc->analog_groups[j - 1]) if (cg != devc->analog_groups[j])
continue; continue;
state->analog_channels[j - 1].vdiv = idx; state->analog_channels[j].vdiv = idx;
g_snprintf(command, sizeof(command), 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 || if (sr_scpi_send(sdi->conn, command) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
@ -290,12 +290,12 @@ static int config_set(uint32_t key, GVariant *data,
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 1; j <= model->analog_channels; j++) { for (j = 0; j < model->analog_channels; j++) {
if (cg != devc->analog_groups[j - 1]) if (cg != devc->analog_groups[j])
continue; continue;
state->analog_channels[j - 1].coupling = idx; state->analog_channels[j].coupling = idx;
g_snprintf(command, sizeof(command), "C%d:COUPLING %s", 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 || if (sr_scpi_send(sdi->conn, command) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;

View File

@ -320,13 +320,13 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(dlm_vdivs))) < 0) if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(dlm_vdivs))) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 1; j <= model->analog_channels; j++) { for (j = 0; j < model->analog_channels; j++) {
if (cg != devc->analog_groups[j - 1]) if (cg != devc->analog_groups[j])
continue; continue;
state->analog_states[j - 1].vdiv = idx; state->analog_states[j].vdiv = idx;
g_ascii_formatd(float_str, sizeof(float_str), g_ascii_formatd(float_str, sizeof(float_str),
"%E", (float) dlm_vdivs[idx][0] / dlm_vdivs[idx][1]); "%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) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break; break;
@ -370,11 +370,11 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0) if ((idx = std_str_idx(data, *model->coupling_options, model->num_coupling_options)) < 0)
return SR_ERR_ARG; return SR_ERR_ARG;
for (j = 1; j <= model->analog_channels; j++) { for (j = 0; j <= model->analog_channels; j++) {
if (cg != devc->analog_groups[j - 1]) if (cg != devc->analog_groups[j])
continue; continue;
state->analog_states[j - 1].coupling = idx; state->analog_states[j].coupling = idx;
if (dlm_analog_chan_coupl_set(sdi->conn, j, (*model->coupling_options)[idx]) != SR_OK || if (dlm_analog_chan_coupl_set(sdi->conn, j + 1, (*model->coupling_options)[idx]) != SR_OK ||
sr_scpi_get_opc(sdi->conn) != SR_OK) sr_scpi_get_opc(sdi->conn) != SR_OK)
return SR_ERR; return SR_ERR;
break; break;