drivers: Use array-based approach in some places.

This allows us to use the new array helpers in a few more places.
This commit is contained in:
Uwe Hermann 2017-08-01 21:12:04 +02:00
parent 373e92a491
commit 692716f5d1
9 changed files with 75 additions and 52 deletions

View File

@ -276,7 +276,7 @@ static int config_set(uint32_t key, GVariant *data,
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
tmp = g_variant_get_string(data, NULL); tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->trigger_sources)[i]; i++) { for (i = 0; i < model->num_trigger_sources; i++) {
if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0) if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
continue; continue;
state->trigger_source = i; state->trigger_source = i;
@ -342,7 +342,7 @@ static int config_set(uint32_t key, GVariant *data,
break; break;
case SR_CONF_TRIGGER_SLOPE: case SR_CONF_TRIGGER_SLOPE:
tmp = g_variant_get_string(data, NULL); tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->trigger_slopes)[i]; i++) { for (i = 0; i < model->num_trigger_slopes; i++) {
if (g_strcmp0(tmp, (*model->trigger_slopes)[i]) != 0) if (g_strcmp0(tmp, (*model->trigger_slopes)[i]) != 0)
continue; continue;
state->trigger_slope = i; state->trigger_slope = i;
@ -360,7 +360,7 @@ static int config_set(uint32_t key, GVariant *data,
tmp = g_variant_get_string(data, NULL); tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->coupling_options)[i]; i++) { for (i = 0; i < model->num_coupling_options; i++) {
if (strcmp(tmp, (*model->coupling_options)[i]) != 0) if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
continue; continue;
for (j = 1; j <= model->analog_channels; j++) { for (j = 1; j <= model->analog_channels; j++) {
@ -430,20 +430,17 @@ static int config_list(uint32_t key, GVariant **data,
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
if (cg_type == CG_NONE) if (cg_type == CG_NONE)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
*data = g_variant_new_strv(*model->coupling_options, *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
g_strv_length((char **)*model->coupling_options));
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
if (!model) if (!model)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new_strv(*model->trigger_sources, *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
g_strv_length((char **)*model->trigger_sources));
break; break;
case SR_CONF_TRIGGER_SLOPE: case SR_CONF_TRIGGER_SLOPE:
if (!model) if (!model)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new_strv(*model->trigger_slopes, *data = g_variant_new_strv(*model->trigger_slopes, model->num_trigger_slopes);
g_strv_length((char **)*model->trigger_slopes));
break; break;
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
if (!model) if (!model)

View File

@ -80,28 +80,24 @@ static const char *coupling_options[] = {
"DC", // DC with 50 Ohm termination "DC", // DC with 50 Ohm termination
"DCL", // DC with 1 MOhm termination "DCL", // DC with 1 MOhm termination
"GND", "GND",
NULL,
}; };
static const char *scope_trigger_slopes[] = { static const char *scope_trigger_slopes[] = {
"POS", "POS",
"NEG", "NEG",
"EITH", "EITH",
NULL,
}; };
static const char *compact2_trigger_sources[] = { static const char *compact2_trigger_sources[] = {
"CH1", "CH2", "CH1", "CH2",
"LINE", "EXT", "PATT", "BUS1", "BUS2", "LINE", "EXT", "PATT", "BUS1", "BUS2",
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
NULL,
}; };
static const char *compact4_trigger_sources[] = { static const char *compact4_trigger_sources[] = {
"CH1", "CH2", "CH3", "CH4", "CH1", "CH2", "CH3", "CH4",
"LINE", "EXT", "PATT", "BUS1", "BUS2", "LINE", "EXT", "PATT", "BUS1", "BUS2",
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
NULL,
}; };
static const char *compact4_dig16_trigger_sources[] = { static const char *compact4_dig16_trigger_sources[] = {
@ -109,7 +105,6 @@ static const char *compact4_dig16_trigger_sources[] = {
"LINE", "EXT", "PATT", "BUS1", "BUS2", "LINE", "EXT", "PATT", "BUS1", "BUS2",
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
"D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15", "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
NULL,
}; };
static const uint64_t timebases[][2] = { static const uint64_t timebases[][2] = {
@ -199,8 +194,13 @@ static const struct scope_config scope_models[] = {
.num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
.coupling_options = &coupling_options, .coupling_options = &coupling_options,
.num_coupling_options = ARRAY_SIZE(coupling_options),
.trigger_sources = &compact2_trigger_sources, .trigger_sources = &compact2_trigger_sources,
.num_trigger_sources = ARRAY_SIZE(compact2_trigger_sources),
.trigger_slopes = &scope_trigger_slopes, .trigger_slopes = &scope_trigger_slopes,
.num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
.timebases = &timebases, .timebases = &timebases,
.num_timebases = ARRAY_SIZE(timebases), .num_timebases = ARRAY_SIZE(timebases),
@ -229,8 +229,13 @@ static const struct scope_config scope_models[] = {
.num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
.coupling_options = &coupling_options, .coupling_options = &coupling_options,
.num_coupling_options = ARRAY_SIZE(coupling_options),
.trigger_sources = &compact4_trigger_sources, .trigger_sources = &compact4_trigger_sources,
.num_trigger_sources = ARRAY_SIZE(compact4_trigger_sources),
.trigger_slopes = &scope_trigger_slopes, .trigger_slopes = &scope_trigger_slopes,
.num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
.timebases = &timebases, .timebases = &timebases,
.num_timebases = ARRAY_SIZE(timebases), .num_timebases = ARRAY_SIZE(timebases),
@ -259,8 +264,13 @@ static const struct scope_config scope_models[] = {
.num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog), .num_devopts_cg_analog = ARRAY_SIZE(devopts_cg_analog),
.coupling_options = &coupling_options, .coupling_options = &coupling_options,
.num_coupling_options = ARRAY_SIZE(coupling_options),
.trigger_sources = &compact4_dig16_trigger_sources, .trigger_sources = &compact4_dig16_trigger_sources,
.num_trigger_sources = ARRAY_SIZE(compact4_dig16_trigger_sources),
.trigger_slopes = &scope_trigger_slopes, .trigger_slopes = &scope_trigger_slopes,
.num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
.timebases = &timebases, .timebases = &timebases,
.num_timebases = ARRAY_SIZE(timebases), .num_timebases = ARRAY_SIZE(timebases),
@ -316,7 +326,7 @@ static void scope_state_dump(const struct scope_config *config,
} }
static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi, static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi,
const char *command, const char *(*array)[], int *result) const char *command, const char *(*array)[], unsigned int n, int *result)
{ {
char *tmp; char *tmp;
unsigned int i; unsigned int i;
@ -326,7 +336,7 @@ static int scope_state_get_array_option(struct sr_scpi_dev_inst *scpi,
return SR_ERR; return SR_ERR;
} }
for (i = 0; (*array)[i]; i++) { for (i = 0; i < n; i++) {
if (!g_strcmp0(tmp, (*array)[i])) { if (!g_strcmp0(tmp, (*array)[i])) {
*result = i; *result = i;
g_free(tmp); g_free(tmp);
@ -420,6 +430,7 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
i + 1); i + 1);
if (scope_state_get_array_option(scpi, command, config->coupling_options, if (scope_state_get_array_option(scpi, command, config->coupling_options,
config->num_coupling_options,
&state->analog_channels[i].coupling) != SR_OK) &state->analog_channels[i].coupling) != SR_OK)
return SR_ERR; return SR_ERR;
@ -584,12 +595,14 @@ SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi)
if (scope_state_get_array_option(sdi->conn, if (scope_state_get_array_option(sdi->conn,
(*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE], (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SOURCE],
config->trigger_sources, &state->trigger_source) != SR_OK) config->trigger_sources, config->num_trigger_sources,
&state->trigger_source) != SR_OK)
return SR_ERR; return SR_ERR;
if (scope_state_get_array_option(sdi->conn, if (scope_state_get_array_option(sdi->conn,
(*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE], (*config->scpi_dialect)[SCPI_CMD_GET_TRIGGER_SLOPE],
config->trigger_slopes, &state->trigger_slope) != SR_OK) config->trigger_slopes, config->num_trigger_slopes,
&state->trigger_slope) != SR_OK)
return SR_ERR; return SR_ERR;
if (hmo_update_sample_rate(sdi) != SR_OK) if (hmo_update_sample_rate(sdi) != SR_OK)

View File

@ -56,6 +56,7 @@ struct scope_config {
const uint8_t num_trigger_sources; const uint8_t num_trigger_sources;
const char *(*trigger_slopes)[]; const char *(*trigger_slopes)[];
const uint8_t num_trigger_slopes;
const uint64_t (*timebases)[][2]; const uint64_t (*timebases)[][2];
const uint8_t num_timebases; const uint8_t num_timebases;

View File

@ -235,7 +235,7 @@ static int config_set(uint32_t key, GVariant *data,
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
tmp = g_variant_get_string(data, NULL); tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->trigger_sources)[i]; i++) { for (i = 0; i < model->num_trigger_sources; i++) {
if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0) if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
continue; continue;
state->trigger_source = i; state->trigger_source = i;
@ -305,7 +305,7 @@ static int config_set(uint32_t key, GVariant *data,
break; break;
case SR_CONF_TRIGGER_SLOPE: case SR_CONF_TRIGGER_SLOPE:
tmp = g_variant_get_string(data, NULL); tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->trigger_slopes)[i]; i++) { for (i = 0; i < model->num_trigger_slopes; i++) {
if (g_strcmp0(tmp, (*model->trigger_slopes)[i]) != 0) if (g_strcmp0(tmp, (*model->trigger_slopes)[i]) != 0)
continue; continue;
state->trigger_slope = i; state->trigger_slope = i;
@ -320,7 +320,7 @@ static int config_set(uint32_t key, GVariant *data,
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
tmp = g_variant_get_string(data, NULL); tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->coupling_options)[i]; i++) { for (i = 0; i < model->num_coupling_options; i++) {
if (strcmp(tmp, (*model->coupling_options)[i]) != 0) if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
continue; continue;
for (j = 1; j <= model->analog_channels; j++) { for (j = 1; j <= model->analog_channels; j++) {
@ -373,20 +373,17 @@ static int config_list(uint32_t key, GVariant **data,
*data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog)); *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog));
break; break;
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
*data = g_variant_new_strv(*model->coupling_options, *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
g_strv_length((char **)*model->coupling_options));
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
if (!model) if (!model)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new_strv(*model->trigger_sources, *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
g_strv_length((char **)*model->trigger_sources));
break; break;
case SR_CONF_TRIGGER_SLOPE: case SR_CONF_TRIGGER_SLOPE:
if (!model) if (!model)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new_strv(*model->trigger_slopes, *data = g_variant_new_strv(*model->trigger_slopes, model->num_trigger_slopes);
g_strv_length((char **)*model->trigger_slopes));
break; break;
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
if (!model) if (!model)

View File

@ -80,15 +80,14 @@ static const char *coupling_options[] = {
"D1M", // DC with 1 MOhm termination "D1M", // DC with 1 MOhm termination
"GND", "GND",
"OVL", "OVL",
NULL,
}; };
static const char *scope_trigger_slopes[] = { static const char *scope_trigger_slopes[] = {
"POS", "NEG", NULL, "POS", "NEG",
}; };
static const char *trigger_sources[] = { static const char *trigger_sources[] = {
"C1", "C2", "C3", "C4", "LINE", "EXT", NULL, "C1", "C2", "C3", "C4", "LINE", "EXT",
}; };
static const struct sr_rational timebases[] = { static const struct sr_rational timebases[] = {
@ -173,8 +172,13 @@ static const struct scope_config scope_models[] = {
.analog_names = &scope_analog_channel_names, .analog_names = &scope_analog_channel_names,
.coupling_options = &coupling_options, .coupling_options = &coupling_options,
.num_coupling_options = ARRAY_SIZE(coupling_options),
.trigger_sources = &trigger_sources, .trigger_sources = &trigger_sources,
.num_trigger_sources = ARRAY_SIZE(trigger_sources),
.trigger_slopes = &scope_trigger_slopes, .trigger_slopes = &scope_trigger_slopes,
.num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
.timebases = timebases, .timebases = timebases,
.num_timebases = ARRAY_SIZE(timebases), .num_timebases = ARRAY_SIZE(timebases),
@ -218,11 +222,11 @@ static void scope_state_dump(const struct scope_config *config,
} }
static int scope_state_get_array_option(const char *resp, static int scope_state_get_array_option(const char *resp,
const char *(*array)[], int *result) const char *(*array)[], unsigned int n, int *result)
{ {
unsigned int i; unsigned int i;
for (i = 0; (*array)[i]; i++) { for (i = 0; i < n; i++) {
if (!g_strcmp0(resp, (*array)[i])) { if (!g_strcmp0(resp, (*array)[i])) {
*result = i; *result = i;
return SR_OK; return SR_OK;
@ -302,6 +306,7 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
if (scope_state_get_array_option(tmp_str, config->coupling_options, if (scope_state_get_array_option(tmp_str, config->coupling_options,
config->num_coupling_options,
&state->analog_channels[i].coupling) != SR_OK) &state->analog_channels[i].coupling) != SR_OK)
return SR_ERR; return SR_ERR;
@ -383,7 +388,7 @@ SR_PRIV int lecroy_xstream_state_get(struct sr_dev_inst *sdi)
i++; i++;
} }
if (!trig_source || scope_state_get_array_option(trig_source, config->trigger_sources, &state->trigger_source) != SR_OK) if (!trig_source || scope_state_get_array_option(trig_source, config->trigger_sources, config->num_trigger_sources, &state->trigger_source) != SR_OK)
return SR_ERR; return SR_ERR;
g_snprintf(command, sizeof(command), "%s:TRIG_SLOPE?", trig_source); g_snprintf(command, sizeof(command), "%s:TRIG_SLOPE?", trig_source);
@ -391,7 +396,7 @@ SR_PRIV int lecroy_xstream_state_get(struct sr_dev_inst *sdi)
return SR_ERR; return SR_ERR;
if (scope_state_get_array_option(tmp_str, if (scope_state_get_array_option(tmp_str,
config->trigger_slopes, &state->trigger_slope) != SR_OK) config->trigger_slopes, config->num_trigger_slopes, &state->trigger_slope) != SR_OK)
return SR_ERR; return SR_ERR;
if (sr_scpi_get_float(sdi->conn, "TRIG_DELAY?", &state->horiz_triggerpos) != SR_OK) if (sr_scpi_get_float(sdi->conn, "TRIG_DELAY?", &state->horiz_triggerpos) != SR_OK)

View File

@ -45,6 +45,7 @@ struct scope_config {
const uint8_t num_trigger_sources; const uint8_t num_trigger_sources;
const char *(*trigger_slopes)[]; const char *(*trigger_slopes)[];
const uint8_t num_trigger_slopes;
const struct sr_rational *timebases; const struct sr_rational *timebases;
const uint8_t num_timebases; const uint8_t num_timebases;

View File

@ -311,7 +311,7 @@ static int config_set(uint32_t key, GVariant *data,
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
tmp = g_variant_get_string(data, NULL); tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->trigger_sources)[i]; i++) { for (i = 0; i < model->num_trigger_sources; i++) {
if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0) if (g_strcmp0(tmp, (*model->trigger_sources)[i]) != 0)
continue; continue;
state->trigger_source = i; state->trigger_source = i;
@ -381,7 +381,7 @@ static int config_set(uint32_t key, GVariant *data,
tmp = g_variant_get_string(data, NULL); tmp = g_variant_get_string(data, NULL);
for (i = 0; (*model->coupling_options)[i]; i++) { for (i = 0; i < model->num_coupling_options; i++) {
if (strcmp(tmp, (*model->coupling_options)[i]) != 0) if (strcmp(tmp, (*model->coupling_options)[i]) != 0)
continue; continue;
for (j = 1; j <= model->analog_channels; j++) { for (j = 1; j <= model->analog_channels; j++) {
@ -444,12 +444,10 @@ static int config_list(uint32_t key, GVariant **data,
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
if (!model) if (!model)
return SR_ERR_ARG; return SR_ERR_ARG;
*data = g_variant_new_strv(*model->trigger_sources, *data = g_variant_new_strv(*model->trigger_sources, model->num_trigger_sources);
g_strv_length((char **)*model->trigger_sources));
return SR_OK; return SR_OK;
case SR_CONF_TRIGGER_SLOPE: case SR_CONF_TRIGGER_SLOPE:
*data = g_variant_new_strv(dlm_trigger_slopes, *data = g_variant_new_strv(ARRAY_AND_SIZE(dlm_trigger_slopes));
g_strv_length((char **)dlm_trigger_slopes));
return SR_OK; return SR_OK;
case SR_CONF_NUM_HDIV: case SR_CONF_NUM_HDIV:
*data = g_variant_new_uint32(model->num_xdivs); *data = g_variant_new_uint32(model->num_xdivs);
@ -474,8 +472,7 @@ static int config_list(uint32_t key, GVariant **data,
case SR_CONF_COUPLING: case SR_CONF_COUPLING:
if (cg_type == CG_NONE) if (cg_type == CG_NONE)
return SR_ERR_CHANNEL_GROUP; return SR_ERR_CHANNEL_GROUP;
*data = g_variant_new_strv(*model->coupling_options, *data = g_variant_new_strv(*model->coupling_options, model->num_coupling_options);
g_strv_length((char **)*model->coupling_options));
break; break;
case SR_CONF_VDIV: case SR_CONF_VDIV:
if (cg_type == CG_NONE) if (cg_type == CG_NONE)

View File

@ -24,12 +24,10 @@
static const char *coupling_options[] = { static const char *coupling_options[] = {
"AC", "DC", "DC50", "GND", "AC", "DC", "DC50", "GND",
NULL,
}; };
static const char *trigger_sources_2ch[] = { static const char *trigger_sources_2ch[] = {
"1", "2", "LINE", "EXT", "1", "2", "LINE", "EXT",
NULL,
}; };
/* TODO: Is BITx handled correctly or is Dx required? */ /* TODO: Is BITx handled correctly or is Dx required? */
@ -37,13 +35,11 @@ static const char *trigger_sources_4ch[] = {
"1", "2", "3", "4", "1", "2", "3", "4",
"LINE", "EXT", "BIT1", "LINE", "EXT", "BIT1",
"BIT2", "BIT3", "BIT4", "BIT5", "BIT6", "BIT7", "BIT8", "BIT2", "BIT3", "BIT4", "BIT5", "BIT6", "BIT7", "BIT8",
NULL,
}; };
/* Note: Values must correlate to the trigger_slopes values. */ /* Note: Values must correlate to the trigger_slopes values. */
const char *dlm_trigger_slopes[3] = { const char *dlm_trigger_slopes[2] = {
"r", "f", "r", "f",
NULL,
}; };
const uint64_t dlm_timebases[36][2] = { const uint64_t dlm_timebases[36][2] = {
@ -138,7 +134,10 @@ static const struct scope_config scope_models[] = {
.digital_names = &scope_digital_channel_names_8, .digital_names = &scope_digital_channel_names_8,
.coupling_options = &coupling_options, .coupling_options = &coupling_options,
.num_coupling_options = ARRAY_SIZE(coupling_options),
.trigger_sources = &trigger_sources_2ch, .trigger_sources = &trigger_sources_2ch,
.num_trigger_sources = ARRAY_SIZE(trigger_sources_2ch),
.num_xdivs = 10, .num_xdivs = 10,
.num_ydivs = 8, .num_ydivs = 8,
@ -154,7 +153,10 @@ static const struct scope_config scope_models[] = {
.digital_names = &scope_digital_channel_names_8, .digital_names = &scope_digital_channel_names_8,
.coupling_options = &coupling_options, .coupling_options = &coupling_options,
.num_coupling_options = ARRAY_SIZE(coupling_options),
.trigger_sources = &trigger_sources_4ch, .trigger_sources = &trigger_sources_4ch,
.num_trigger_sources = ARRAY_SIZE(trigger_sources_4ch),
.num_xdivs = 10, .num_xdivs = 10,
.num_ydivs = 8, .num_ydivs = 8,
@ -172,7 +174,10 @@ static const struct scope_config scope_models[] = {
.digital_names = NULL, .digital_names = NULL,
.coupling_options = &coupling_options, .coupling_options = &coupling_options,
.num_coupling_options = ARRAY_SIZE(coupling_options),
.trigger_sources = &trigger_sources_4ch, .trigger_sources = &trigger_sources_4ch,
.num_trigger_sources = ARRAY_SIZE(trigger_sources_4ch),
.num_xdivs = 10, .num_xdivs = 10,
.num_ydivs = 8, .num_ydivs = 8,
@ -188,7 +193,10 @@ static const struct scope_config scope_models[] = {
.digital_names = &scope_digital_channel_names_32, .digital_names = &scope_digital_channel_names_32,
.coupling_options = &coupling_options, .coupling_options = &coupling_options,
.num_coupling_options = ARRAY_SIZE(coupling_options),
.trigger_sources = &trigger_sources_4ch, .trigger_sources = &trigger_sources_4ch,
.num_trigger_sources = ARRAY_SIZE(trigger_sources_4ch),
.num_xdivs = 10, .num_xdivs = 10,
.num_ydivs = 8, .num_ydivs = 8,
@ -204,7 +212,10 @@ static const struct scope_config scope_models[] = {
.digital_names = &scope_digital_channel_names_32, .digital_names = &scope_digital_channel_names_32,
.coupling_options = &coupling_options, .coupling_options = &coupling_options,
.num_coupling_options = ARRAY_SIZE(coupling_options),
.trigger_sources = &trigger_sources_4ch, .trigger_sources = &trigger_sources_4ch,
.num_trigger_sources = ARRAY_SIZE(trigger_sources_4ch),
.num_xdivs = 10, .num_xdivs = 10,
.num_ydivs = 8, .num_ydivs = 8,
@ -271,13 +282,13 @@ static void scope_state_dump(const struct scope_config *config,
* @return SR_ERR when value couldn't be found, SR_OK otherwise. * @return SR_ERR when value couldn't be found, SR_OK otherwise.
*/ */
static int array_option_get(char *value, const char *(*array)[], static int array_option_get(char *value, const char *(*array)[],
int *result) unsigned int n, int *result)
{ {
unsigned int i; unsigned int i;
*result = -1; *result = -1;
for (i = 0; (*array)[i]; i++) for (i = 0; i < n; i++)
if (!g_strcmp0(value, (*array)[i])) { if (!g_strcmp0(value, (*array)[i])) {
*result = i; *result = i;
break; break;
@ -425,6 +436,7 @@ static int analog_channel_state_get(const struct sr_dev_inst *sdi,
} }
if (array_option_get(response, config->coupling_options, if (array_option_get(response, config->coupling_options,
config->num_coupling_options,
&state->analog_states[i].coupling) != SR_OK) { &state->analog_states[i].coupling) != SR_OK) {
g_free(response); g_free(response);
return SR_ERR; return SR_ERR;
@ -660,7 +672,7 @@ SR_PRIV int dlm_scope_state_query(struct sr_dev_inst *sdi)
} }
if (array_option_get(response, config->trigger_sources, if (array_option_get(response, config->trigger_sources,
&state->trigger_source) != SR_OK) { config->num_trigger_sources, &state->trigger_source) != SR_OK) {
g_free(response); g_free(response);
return SR_ERR; return SR_ERR;
} }

View File

@ -49,7 +49,7 @@ enum trigger_slopes {
SLOPE_NEGATIVE SLOPE_NEGATIVE
}; };
extern const char *dlm_trigger_slopes[3]; extern const char *dlm_trigger_slopes[2];
extern const uint64_t dlm_timebases[36][2]; extern const uint64_t dlm_timebases[36][2];
extern const uint64_t dlm_vdivs[17][2]; extern const uint64_t dlm_vdivs[17][2];