Skip to content

Commit

Permalink
elanspi: add capture timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
mincrmatt12 committed Jun 21, 2021
1 parent a4959e8 commit e1cdfb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 19 additions & 1 deletion libfprint/drivers/elanspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct _FpiDeviceElanSpi

/* generic temp info for async reading */
guint8 sensor_status;
gint64 capture_timeout;

/* background / calibration parameters */
guint16 *bg_image;
Expand Down Expand Up @@ -456,6 +457,7 @@ elanspi_capture_old_handler (FpiSsm *ssm, FpDevice *dev)
case ELANSPI_CAPTOLD_WRITE_CAPTURE:
/* reset capture state */
self->old_data.line_ptr = 0;
self->capture_timeout = g_get_monotonic_time () + ELANSPI_OLD_CAPTURE_TIMEOUT_USEC;
xfer = elanspi_do_capture (self);
xfer->ssm = ssm;
fpi_spi_transfer_submit (xfer, NULL, fpi_ssm_spi_transfer_cb, NULL);
Expand All @@ -471,6 +473,13 @@ elanspi_capture_old_handler (FpiSsm *ssm, FpDevice *dev)
/* is the sensor ready? */
if (!(self->sensor_status & 4))
{
/* has the timeout expired? */
if (g_get_monotonic_time () > self->capture_timeout)
{
/* end with a timeout */
fpi_ssm_mark_failed (ssm, g_error_new (G_IO_ERROR, G_IO_ERROR_TIMED_OUT, "timed out waiting for new line"));
return;
}
/* check again */
fpi_ssm_jump_to_state (ssm, ELANSPI_CAPTOLD_CHECK_LINEREADY);
return;
Expand Down Expand Up @@ -622,7 +631,6 @@ elanspi_calibrate_old_handler (FpiSsm *ssm, FpDevice *dev)
return;

case ELANSPI_CALIBOLD_DACFINE_WRITE_DAC1:
/* todo add a timeout to this code */
mean_value = elanspi_mean_image (self, self->last_image);
if (mean_value >= ELANSPI_MIN_OLD_STAGE2_CALBIRATION_MEAN && mean_value <= ELANSPI_MAX_OLD_STAGE2_CALBIRATION_MEAN)
{
Expand Down Expand Up @@ -707,8 +715,11 @@ elanspi_capture_hv_handler (FpiSsm *ssm, FpDevice *dev)
case ELANSPI_CAPTHV_WRITE_CAPTURE:
/* reset capture state */
self->old_data.line_ptr = 0;
self->capture_timeout = g_get_monotonic_time () + ELANSPI_HV_CAPTURE_TIMEOUT_USEC;
xfer = elanspi_do_capture (self);
xfer->ssm = ssm;
/* these are specifically cancellable because they don't leave the device at some aribtrary line offset, since
* these devices only send entire images */
fpi_spi_transfer_submit (xfer, fpi_device_get_cancellable (dev), fpi_ssm_spi_transfer_cb, NULL);
return;

Expand All @@ -722,6 +733,13 @@ elanspi_capture_hv_handler (FpiSsm *ssm, FpDevice *dev)
/* is the sensor ready? */
if (!(self->sensor_status & 4))
{
/* has the timeout expired? */
if (g_get_monotonic_time () > self->capture_timeout)
{
/* end with a timeout */
fpi_ssm_mark_failed (ssm, g_error_new (G_IO_ERROR, G_IO_ERROR_TIMED_OUT, "timed out waiting for image"));
return;
}
/* check again */
fpi_ssm_jump_to_state (ssm, ELANSPI_CAPTHV_CHECK_READY);
return;
Expand Down
3 changes: 3 additions & 0 deletions libfprint/drivers/elanspi.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,6 @@ static const FpIdEntry elanspi_id_table[] = {
#define ELANSPI_HV_SENSOR_FRAME_DELAY 23

#define ELANSPI_OTP_TIMEOUT_USEC (12 * 1000)

#define ELANSPI_OLD_CAPTURE_TIMEOUT_USEC (100 * 1000)
#define ELANSPI_HV_CAPTURE_TIMEOUT_USEC (50 * 1000)

0 comments on commit e1cdfb8

Please sign in to comment.