config (partial)

This commit is contained in:
Triss 2021-06-25 03:23:07 +02:00
parent 638bdaec16
commit d70c0bc625
2 changed files with 67 additions and 27 deletions

View File

@ -44,7 +44,7 @@ static const uint32_t devopts[] = {
// * TRIGGER_SLOPE: probably dV/dt thing? so not applicable here
// * OUTPUT_FREQUENCY used in PATTERN_MODE?
// * DATALOG: effect?
SR_CONF_CONN | SR_CONF_GET,
//SR_CONF_CONN | SR_CONF_GET, // TODO: ???
SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET,
//SR_CONF_PATTERN_MODE | SR_CONF_GET | SR_CONF_SET, // TODO: idk how this works
@ -69,6 +69,19 @@ static const uint64_t samplerates[] = {
SR_KHZ(500), SR_KHZ(250), SR_KHZ(100), SR_KHZ(50), SR_KHZ(10)
};
static uint64_t dc_samples_to_msec(struct device_context *dc, uint64_t samples)
{
float msec_per_sample = 1.0f / ((float)dc->samplerate * 0.001f);
return (uint64_t)((float)samples * msec_per_sample);
}
static uint64_t dc_msec_to_samples(struct device_context *dc, uint64_t msec)
{
float samples_per_msec = ((float)dc->samplerate * 0.001f);
return (uint64_t)((float)msec * samples_per_msec);
}
static int dev_clear(struct sr_dev_driver *di)
{
return std_dev_clear_with_callback(di, (std_dev_clear_callback)sq_destroy);
@ -161,7 +174,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
gfree(manuf );
for (i = 0; i < ARRAY_SIZE(channel_names); ++i)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE/*TODO:?*/, channel_names[i]);
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE/* enabled */, channel_names[i]);
return std_scan_complete(di, g_slist_append(NULL, sdi));
}
@ -243,58 +256,85 @@ static int dev_close(struct sr_dev_inst *sdi)
static int config_get(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
int ret;
struct dev_context *dc;
int rv;
dc = sdi->priv;
(void)sdi;
(void)data;
(void)cg;
ret = SR_OK;
rv = SR_OK;
switch (key) {
/* TODO */
case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(dc->samplerate);
break;
case SR_CONF_LIMIT_MSEC:
*data = g_variant_new_uint64(dc_samples_to_msec(dc, dc->limit_samples));
break;
case SR_CONF_LIMIT_SAMPLES:
*data = g_variant_new_uint64(dc->limit_samples);
break;
case SR_CONF_CAPTURE_RATIO:
*data = g_variant_new_uint64(dc->capture_ratio);
break;
default:
return SR_ERR_NA;
rv = SR_ERR_NA;
break;
}
return ret;
return rv;
}
static int config_set(uint32_t key, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
int ret;
struct dev_context *dc;
int rv;
dc = sdi->priv;
(void)sdi;
(void)data;
(void)cg;
ret = SR_OK;
rv = SR_OK;
switch (key) {
/* TODO */
case SR_CONF_SAMPLERATE:
dc->samplerate = g_variant_get_uint64(data);
break;
case SR_CONF_LIMIT_MSEC:
dc->limit_samples = dc_msec_to_samples(dc, g_variant_get_uint64(data));
break;
case SR_CONF_LIMIT_SAMPLES:
dc->limit_samples = g_variant_get_uint64(data);
break;
case SR_CONF_CAPTURE_RATIO:
dc->capture_ratio = g_variant_get_uint64(data);
break;
default:
ret = SR_ERR_NA;
rv = SR_ERR_NA;
break;
}
return ret;
return rv;
}
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
int ret;
int rv;
(void)sdi;
(void)data;
(void)cg;
ret = SR_OK;
rv = SR_OK;
switch (key) {
/* TODO */
case SR_CONF_DEVICE_OPTIONS:
return STD_CONFIG_LIST(key, data, sdi, cg, NO_OPTS, drvopts, devopts);
case SR_CONF_SAMPLERATE:
*data = std_gvar_samplerates(ARRAY_AND_SIZE(samplerates));
break;
default:
return SR_ERR_NA;
rv = SR_ERR_NA;
break;
}
return ret;
return rv;
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -37,9 +37,9 @@ struct dev_context {
/* settings for next capture */
uint64_t samplerate;
uint64_t limit_samples;
uint64_t capture_ratio;
float voltage;
float total_buffer_usage_percent;
float pretrigger_percent;
uint32_t memsize_max;
int devtype; /* 25, 50, 100 or 200 for SQ25, SQ50, and so on */