tondaj-sl-814: Use software limit helpers
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
91b77e6b1d
commit
2630f97ebb
|
@ -36,6 +36,7 @@ static const uint32_t devopts[] = {
|
||||||
SR_CONF_SOUNDLEVELMETER,
|
SR_CONF_SOUNDLEVELMETER,
|
||||||
SR_CONF_CONTINUOUS,
|
SR_CONF_CONTINUOUS,
|
||||||
SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
|
SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
|
||||||
|
SR_CONF_LIMIT_MSEC | SR_CONF_SET,
|
||||||
};
|
};
|
||||||
|
|
||||||
SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info;
|
SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info;
|
||||||
|
@ -88,6 +89,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
|
||||||
sdi->vendor = g_strdup("Tondaj");
|
sdi->vendor = g_strdup("Tondaj");
|
||||||
sdi->model = g_strdup("SL-814");
|
sdi->model = g_strdup("SL-814");
|
||||||
devc = g_malloc0(sizeof(struct dev_context));
|
devc = g_malloc0(sizeof(struct dev_context));
|
||||||
|
sr_sw_limits_init(&devc->limits);
|
||||||
|
|
||||||
serial = sr_serial_dev_inst_new(conn, serialcomm);
|
serial = sr_serial_dev_inst_new(conn, serialcomm);
|
||||||
|
|
||||||
|
@ -118,15 +120,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
switch (key) {
|
return sr_sw_limits_config_set(&devc->limits, key, data);
|
||||||
case SR_CONF_LIMIT_SAMPLES:
|
|
||||||
devc->limit_samples = g_variant_get_uint64(data);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return SR_ERR_NA;
|
|
||||||
}
|
|
||||||
|
|
||||||
return SR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
|
||||||
|
@ -153,12 +147,15 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
||||||
|
|
||||||
static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
|
struct dev_context *devc = sdi->priv;
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
|
||||||
if (sdi->status != SR_ST_ACTIVE)
|
if (sdi->status != SR_ST_ACTIVE)
|
||||||
return SR_ERR_DEV_CLOSED;
|
return SR_ERR_DEV_CLOSED;
|
||||||
|
|
||||||
std_session_send_df_header(sdi, LOG_PREFIX);
|
std_session_send_df_header(sdi, LOG_PREFIX);
|
||||||
|
|
||||||
|
sr_sw_limits_acquisition_start(&devc->limits);
|
||||||
|
|
||||||
/* Poll every 500ms, or whenever some data comes in. */
|
/* Poll every 500ms, or whenever some data comes in. */
|
||||||
serial = sdi->conn;
|
serial = sdi->conn;
|
||||||
|
|
|
@ -106,7 +106,7 @@ static void decode_packet(struct sr_dev_inst *sdi)
|
||||||
packet.payload = &analog;
|
packet.payload = &analog;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
|
|
||||||
devc->num_samples++;
|
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
|
SR_PRIV int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
|
||||||
|
@ -201,11 +201,8 @@ SR_PRIV int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop acquisition if we acquired enough samples. */
|
if (sr_sw_limits_check(&devc->limits))
|
||||||
if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
|
|
||||||
sr_info("Requested number of samples reached.");
|
|
||||||
sdi->driver->dev_acquisition_stop(sdi);
|
sdi->driver->dev_acquisition_stop(sdi);
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,15 +29,7 @@
|
||||||
|
|
||||||
/** Private, per-device-instance driver context. */
|
/** Private, per-device-instance driver context. */
|
||||||
struct dev_context {
|
struct dev_context {
|
||||||
/** The current sampling limit (in number of samples). */
|
struct sr_sw_limits limits;
|
||||||
uint64_t limit_samples;
|
|
||||||
|
|
||||||
/** The current sampling limit (in ms). */
|
|
||||||
uint64_t limit_msec;
|
|
||||||
|
|
||||||
/** The current number of already received samples. */
|
|
||||||
uint64_t num_samples;
|
|
||||||
|
|
||||||
int state;
|
int state;
|
||||||
|
|
||||||
uint8_t buf[4];
|
uint8_t buf[4];
|
||||||
|
|
Loading…
Reference in New Issue