]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hameg-hmo/api.c
hameg-hmo: Don't hardcode POD/channel numbers.
[libsigrok.git] / src / hardware / hameg-hmo / api.c
index f3e587f04c3a8c48d450e455988c04dc62659f77..e5808fb362735ce9a20ceeb92afdc56e2c183cc6 100644 (file)
@@ -415,7 +415,7 @@ static int config_set(uint32_t key, GVariant *data,
                if (model->logic_threshold_for_pod)
                        i = j + 1;
                else
-                       i = j * 8;
+                       i = j * DIGITAL_CHANNELS_PER_POD;
                g_snprintf(command, sizeof(command),
                           (*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_THRESHOLD],
                           i, (*model->logic_threshold)[idx]);
@@ -442,7 +442,7 @@ static int config_set(uint32_t key, GVariant *data,
                if (model->logic_threshold_for_pod)
                        idx = j + 1;
                else
-                       idx = j * 8;
+                       idx = j * DIGITAL_CHANNELS_PER_POD;
                /* Try to support different dialects exhaustively. */
                for (i = 0; i < model->num_logic_threshold; i++) {
                        if (!strcmp("USER2", (*model->logic_threshold)[i])) {
@@ -595,7 +595,7 @@ SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
        case SR_CHANNEL_LOGIC:
                g_snprintf(command, sizeof(command),
                           (*model->scpi_dialect)[SCPI_CMD_GET_DIG_DATA],
-                          ch->index < 8 ? 1 : 2);
+                          ch->index / DIGITAL_CHANNELS_PER_POD + 1);
                break;
        default:
                sr_err("Invalid channel type.");
@@ -632,7 +632,7 @@ static int hmo_check_channels(GSList *channels)
                                enabled_chan[idx] = TRUE;
                        break;
                case SR_CHANNEL_LOGIC:
-                       idx = ch->index / 8;
+                       idx = ch->index / DIGITAL_CHANNELS_PER_POD;
                        if (idx < ARRAY_SIZE(enabled_pod))
                                enabled_pod[idx] = TRUE;
                        break;
@@ -697,10 +697,10 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi)
                case SR_CHANNEL_LOGIC:
                        /*
                         * A digital POD needs to be enabled for every group of
-                        * 8 channels.
+                        * DIGITAL_CHANNELS_PER_POD channels.
                         */
                        if (ch->enabled)
-                               pod_enabled[ch->index < 8 ? 0 : 1] = TRUE;
+                               pod_enabled[ch->index / DIGITAL_CHANNELS_PER_POD] = TRUE;
 
                        if (ch->enabled == state->digital_channels[ch->index])
                                break;
@@ -778,7 +778,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                if (!ch->enabled)
                        continue;
                /* Only add a single digital channel per group (pod). */
-               group = ch->index / 8;
+               group = ch->index / DIGITAL_CHANNELS_PER_POD;
                if (ch->type != SR_CHANNEL_LOGIC || !digital_added[group]) {
                        devc->enabled_channels = g_slist_append(
                                        devc->enabled_channels, ch);