lecroy-xstream: Use array-based approach for timebases/vdivs.
This makes the driver more consistent with the rest of the code-base and allows us to use the new array helpers in a few more places.
This commit is contained in:
parent
692716f5d1
commit
76f0fa5dfb
|
@ -154,8 +154,8 @@ static int config_get(uint32_t key, GVariant **data,
|
|||
break;
|
||||
case SR_CONF_TIMEBASE:
|
||||
*data = g_variant_new("(tt)",
|
||||
model->timebases[state->timebase].p,
|
||||
model->timebases[state->timebase].q);
|
||||
(*model->timebases)[state->timebase][0],
|
||||
(*model->timebases)[state->timebase][1]);
|
||||
break;
|
||||
case SR_CONF_NUM_VDIV:
|
||||
for (i = 0; i < model->analog_channels; i++) {
|
||||
|
@ -169,8 +169,8 @@ static int config_get(uint32_t key, GVariant **data,
|
|||
if (cg != devc->analog_groups[i])
|
||||
continue;
|
||||
*data = g_variant_new("(tt)",
|
||||
model->vdivs[state->analog_channels[i].vdiv].p,
|
||||
model->vdivs[state->analog_channels[i].vdiv].q);
|
||||
(*model->vdivs)[state->analog_channels[i].vdiv][0],
|
||||
(*model->vdivs)[state->analog_channels[i].vdiv][1]);
|
||||
}
|
||||
break;
|
||||
case SR_CONF_TRIGGER_SOURCE:
|
||||
|
@ -212,8 +212,7 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
const struct scope_config *model;
|
||||
struct scope_state *state;
|
||||
const char *tmp;
|
||||
int64_t p;
|
||||
uint64_t q;
|
||||
uint64_t p, q;
|
||||
double tmp_d;
|
||||
gboolean update_sample_rate;
|
||||
|
||||
|
@ -251,7 +250,7 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
g_variant_get(data, "(tt)", &p, &q);
|
||||
|
||||
for (i = 0; i < model->num_vdivs; i++) {
|
||||
if (p != model->vdivs[i].p || q != model->vdivs[i].q)
|
||||
if (p != (*model->vdivs)[i][0] || q != (*model->vdivs)[i][1])
|
||||
continue;
|
||||
for (j = 1; j <= model->analog_channels; j++) {
|
||||
if (cg != devc->analog_groups[j - 1])
|
||||
|
@ -275,8 +274,8 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
g_variant_get(data, "(tt)", &p, &q);
|
||||
|
||||
for (i = 0; i < model->num_timebases; i++) {
|
||||
if (p != model->timebases[i].p ||
|
||||
q != model->timebases[i].q)
|
||||
if (p != (*model->timebases)[i][0] ||
|
||||
q != (*model->timebases)[i][1])
|
||||
continue;
|
||||
state->timebase = i;
|
||||
g_snprintf(command, sizeof(command),
|
||||
|
@ -295,8 +294,8 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
|
||||
state->horiz_triggerpos = tmp_d;
|
||||
tmp_d = -(tmp_d - 0.5) *
|
||||
((double)model->timebases[state->timebase].p /
|
||||
model->timebases[state->timebase].q)
|
||||
((double)(*model->timebases)[state->timebase][0] /
|
||||
(*model->timebases)[state->timebase][1])
|
||||
* model->num_xdivs;
|
||||
|
||||
g_snprintf(command, sizeof(command), "TRIG POS %e S", tmp_d);
|
||||
|
@ -388,12 +387,12 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
case SR_CONF_TIMEBASE:
|
||||
if (!model)
|
||||
return SR_ERR_ARG;
|
||||
*data = std_gvar_tuple_rational(model->timebases, model->num_timebases);
|
||||
*data = std_gvar_tuple_array(*model->timebases, model->num_timebases);
|
||||
break;
|
||||
case SR_CONF_VDIV:
|
||||
if (!model)
|
||||
return SR_ERR_ARG;
|
||||
*data = std_gvar_tuple_rational(model->vdivs, model->num_vdivs);
|
||||
*data = std_gvar_tuple_array(*model->vdivs, model->num_vdivs);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -90,7 +90,7 @@ static const char *trigger_sources[] = {
|
|||
"C1", "C2", "C3", "C4", "LINE", "EXT",
|
||||
};
|
||||
|
||||
static const struct sr_rational timebases[] = {
|
||||
static const uint64_t timebases[][2] = {
|
||||
/* picoseconds */
|
||||
{ 20, 1000000000000 },
|
||||
{ 50, 1000000000000 },
|
||||
|
@ -140,7 +140,7 @@ static const struct sr_rational timebases[] = {
|
|||
{ 1000, 1 },
|
||||
};
|
||||
|
||||
static const struct sr_rational vdivs[] = {
|
||||
static const uint64_t vdivs[][2] = {
|
||||
/* millivolts */
|
||||
{ 1, 1000 },
|
||||
{ 2, 1000 },
|
||||
|
@ -180,10 +180,10 @@ static const struct scope_config scope_models[] = {
|
|||
.trigger_slopes = &scope_trigger_slopes,
|
||||
.num_trigger_slopes = ARRAY_SIZE(scope_trigger_slopes),
|
||||
|
||||
.timebases = timebases,
|
||||
.timebases = &timebases,
|
||||
.num_timebases = ARRAY_SIZE(timebases),
|
||||
|
||||
.vdivs = vdivs,
|
||||
.vdivs = &vdivs,
|
||||
.num_vdivs = ARRAY_SIZE(vdivs),
|
||||
|
||||
.num_xdivs = 10,
|
||||
|
@ -198,16 +198,16 @@ static void scope_state_dump(const struct scope_config *config,
|
|||
char *tmp;
|
||||
|
||||
for (i = 0; i < config->analog_channels; i++) {
|
||||
tmp = sr_voltage_string(config->vdivs[state->analog_channels[i].vdiv].p,
|
||||
config->vdivs[state->analog_channels[i].vdiv].q);
|
||||
tmp = sr_voltage_string((*config->vdivs)[state->analog_channels[i].vdiv][0],
|
||||
(*config->vdivs)[state->analog_channels[i].vdiv][1]);
|
||||
sr_info("State of analog channel %d -> %s : %s (coupling) %s (vdiv) %2.2e (offset)",
|
||||
i + 1, state->analog_channels[i].state ? "On" : "Off",
|
||||
(*config->coupling_options)[state->analog_channels[i].coupling],
|
||||
tmp, state->analog_channels[i].vertical_offset);
|
||||
}
|
||||
|
||||
tmp = sr_period_string(config->timebases[state->timebase].p,
|
||||
config->timebases[state->timebase].q);
|
||||
tmp = sr_period_string((*config->timebases)[state->timebase][0],
|
||||
(*config->timebases)[state->timebase][1]);
|
||||
sr_info("Current timebase: %s", tmp);
|
||||
g_free(tmp);
|
||||
|
||||
|
@ -247,16 +247,18 @@ static int scope_state_get_array_option(const char *resp,
|
|||
*
|
||||
* @return SR_ERR on any parsing error, SR_OK otherwise.
|
||||
*/
|
||||
static int array_float_get(gchar *value, const struct sr_rational *aval,
|
||||
static int array_float_get(gchar *value, const uint64_t array[][2],
|
||||
int array_len, unsigned int *result)
|
||||
{
|
||||
struct sr_rational rval;
|
||||
struct sr_rational aval;
|
||||
|
||||
if (sr_parse_rational(value, &rval) != SR_OK)
|
||||
return SR_ERR;
|
||||
|
||||
for (int i = 0; i < array_len; i++) {
|
||||
if (sr_rational_eq(&rval, aval + i)) {
|
||||
sr_rational_set(&aval, array[i][0], array[i][1]);
|
||||
if (sr_rational_eq(&rval, &aval)) {
|
||||
*result = i;
|
||||
return SR_OK;
|
||||
}
|
||||
|
|
|
@ -47,10 +47,10 @@ struct scope_config {
|
|||
const char *(*trigger_slopes)[];
|
||||
const uint8_t num_trigger_slopes;
|
||||
|
||||
const struct sr_rational *timebases;
|
||||
const uint64_t (*timebases)[][2];
|
||||
const uint8_t num_timebases;
|
||||
|
||||
const struct sr_rational *vdivs;
|
||||
const uint64_t (*vdivs)[][2];
|
||||
const uint8_t num_vdivs;
|
||||
|
||||
const uint8_t num_xdivs;
|
||||
|
|
Loading…
Reference in New Issue