]> sigrok.org Git - libsigrok.git/commitdiff
drivers: Start counting at 0 for some loops.
authorUwe Hermann <redacted>
Thu, 3 Aug 2017 20:22:40 +0000 (22:22 +0200)
committerUwe Hermann <redacted>
Sun, 6 Aug 2017 15:31:46 +0000 (17:31 +0200)
src/hardware/hameg-hmo/api.c
src/hardware/lecroy-xstream/api.c
src/hardware/yokogawa-dlm/api.c

index 7619f18485e1efc9f8a82e43dbd22f1db3cd7c75..9cb4dc8efabda1939687a9114926e15c9764135c 100644 (file)
@@ -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;
        }
 
index 62cb967b560ad8530ad96bf034df43c387d68018..a9d9e044b653a9bbb0bf3ad4dbca0962de5b2a0f 100644 (file)
@@ -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;
index c3574a906ff9d2c5762d1da47ec582be722c4265..5e554608dc850689a2dd5ec934b6368dd66b568e 100644 (file)
@@ -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;