hameg-hmo: Reduce unnecessarily high nesting level.

This commit is contained in:
Uwe Hermann 2013-12-03 17:13:50 +01:00
parent 719eff68ad
commit 082972e8c5
1 changed files with 85 additions and 87 deletions

View File

@ -353,12 +353,12 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
return SR_ERR_PROBE_GROUP;
} else if (pg_type == PG_ANALOG) {
for (i = 0; i < model->analog_channels; ++i) {
if (probe_group == &devc->analog_groups[i]) {
if (probe_group != &devc->analog_groups[i])
continue;
*data = g_variant_new_int32(model->num_ydivs);
ret = SR_OK;
break;
}
}
} else {
ret = SR_ERR_NA;
@ -422,7 +422,8 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
case SR_CONF_TRIGGER_SOURCE:
tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->trigger_sources)[i]; i++) {
if (!g_strcmp0(tmp, (*model->trigger_sources)[i])) {
if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
continue;
state->trigger_source = i;
g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_TRIGGER_SOURCE],
@ -431,7 +432,6 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
ret = sr_scpi_send(sdi->conn, command);
break;
}
}
break;
case SR_CONF_VDIV:
if (pg_type == PG_NONE) {
@ -442,10 +442,12 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
g_variant_get(data, "(tt)", &p, &q);
for (i = 0; i < model->num_vdivs; i++) {
if (p == (*model->vdivs)[i][0] &&
q == (*model->vdivs)[i][1]) {
if (p != (*model->vdivs)[i][0] ||
q != (*model->vdivs)[i][1])
continue;
for (j = 1; j <= model->analog_channels; ++j) {
if (probe_group == &devc->analog_groups[j - 1]) {
if (probe_group != &devc->analog_groups[j - 1])
continue;
state->analog_channels[j - 1].vdiv = (float) p / q;
g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV],
@ -457,19 +459,18 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
break;
}
}
ret = SR_OK;
break;
}
}
break;
case SR_CONF_TIMEBASE:
g_variant_get(data, "(tt)", &p, &q);
for (i = 0; i < model->num_timebases; i++) {
if (p == (*model->timebases)[i][0] &&
q == (*model->timebases)[i][1]) {
if (p != (*model->timebases)[i][0] ||
q != (*model->timebases)[i][1])
continue;
state->timebase = (float) p / q;
g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
@ -478,7 +479,6 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
ret = sr_scpi_send(sdi->conn, command);
break;
}
}
break;
case SR_CONF_HORIZ_TRIGGERPOS:
tmp_d = g_variant_get_double(data);
@ -516,9 +516,11 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->coupling_options)[i]; i++) {
if (!strcmp(tmp, (*model->coupling_options)[i])) {
if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
continue;
for (j = 1; j <= model->analog_channels; ++j) {
if (probe_group == &devc->analog_groups[j - 1]) {
if (probe_group != &devc->analog_groups[j - 1])
continue;
state->analog_channels[j-1].coupling = i;
g_snprintf(command, sizeof(command),
@ -530,12 +532,10 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
return SR_ERR;
break;
}
}
ret = SR_OK;
break;
}
}
break;
default:
ret = SR_ERR_NA;
@ -692,7 +692,8 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
probe = l->data;
switch (probe->type) {
case SR_PROBE_ANALOG:
if (probe->enabled != state->analog_channels[probe->index].state) {
if (probe->enabled == state->analog_channels[probe->index].state)
break;
g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_ANALOG_CHAN_STATE],
probe->index + 1, probe->enabled);
@ -700,7 +701,6 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
if (sr_scpi_send(serial, command) != SR_OK)
return SR_ERR;
state->analog_channels[probe->index].state = probe->enabled;
}
break;
case SR_PROBE_LOGIC:
/*
@ -710,7 +710,8 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
if (probe->enabled)
pod_enabled[probe->index < 8 ? 0 : 1] = TRUE;
if (probe->enabled != state->digital_channels[probe->index]) {
if (probe->enabled == state->digital_channels[probe->index])
break;
g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
probe->index, probe->enabled);
@ -719,7 +720,6 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
return SR_ERR;
state->digital_channels[probe->index] = probe->enabled;
}
break;
default:
return SR_ERR;
@ -727,17 +727,15 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
}
for (i = 1; i <= model->digital_pods; ++i) {
if (state->digital_pods[i - 1] != pod_enabled[i - 1]) {
if (state->digital_pods[i - 1] == pod_enabled[i - 1])
continue;
g_snprintf(command, sizeof(command),
(*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
i, pod_enabled[i - 1]);
if (sr_scpi_send(serial, command) != SR_OK)
return SR_ERR;
state->digital_pods[i - 1] = pod_enabled[i - 1];
}
}
g_free(pod_enabled);
@ -761,7 +759,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
for (l = sdi->probes; l; l = l->next) {
probe = l->data;
if (probe->enabled) {
if (!probe->enabled)
continue;
/* Only add a single digital probe. */
if (probe->type != SR_PROBE_LOGIC || !digital_added) {
devc->enabled_probes = g_slist_append(
@ -770,7 +769,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
digital_added = TRUE;
}
}
}
if (!devc->enabled_probes)
return SR_ERR;