lib: Add fpi_ssm_next_state_timeout_cb() helper
To be used in 5 drivers.
This commit is contained in:
parent
f2bc826a20
commit
50166e88c0
8 changed files with 30 additions and 67 deletions
|
@ -165,6 +165,7 @@ fpi_ssm_start
|
|||
fpi_ssm_start_subsm
|
||||
|
||||
fpi_ssm_next_state
|
||||
fpi_ssm_next_state_timeout_cb
|
||||
fpi_ssm_jump_to_state
|
||||
fpi_ssm_mark_completed
|
||||
fpi_ssm_mark_failed
|
||||
|
|
|
@ -583,13 +583,6 @@ static void elan_capture(struct fp_img_dev *dev)
|
|||
fpi_ssm_start(ssm, capture_complete);
|
||||
}
|
||||
|
||||
static void
|
||||
fpi_ssm_next_state_async(struct fp_dev *dev,
|
||||
void *data)
|
||||
{
|
||||
fpi_ssm_next_state((fpi_ssm *)data);
|
||||
}
|
||||
|
||||
/* this function needs to have elandev->background and elandev->last_read to be
|
||||
* the calibration mean */
|
||||
static int elan_need_calibration(struct elan_dev *elandev)
|
||||
|
@ -680,7 +673,7 @@ static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da
|
|||
if (elandev->calib_status == 0x00
|
||||
&& elandev->last_read[0] == 0x01)
|
||||
elandev->calib_status = 0x01;
|
||||
if (!fpi_timeout_add(50, fpi_ssm_next_state_async, _dev, ssm))
|
||||
if (!fpi_timeout_add(50, fpi_ssm_next_state_timeout_cb, _dev, ssm))
|
||||
fpi_ssm_mark_failed(ssm, -ETIME);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -520,15 +520,6 @@ another_scan(struct fp_dev *dev,
|
|||
fpi_ssm_jump_to_state(ssm, SSM_TURN_ON);
|
||||
}
|
||||
|
||||
/* Another SSM stub to continue after waiting for probable vdev->active changes */
|
||||
static void
|
||||
scan_completed(struct fp_dev *dev,
|
||||
void *data)
|
||||
{
|
||||
fpi_ssm *ssm = data;
|
||||
fpi_ssm_next_state(ssm);
|
||||
}
|
||||
|
||||
/* Main SSM loop */
|
||||
static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
{
|
||||
|
@ -652,7 +643,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
|||
clear_data(vdev);
|
||||
|
||||
/* Wait for probable vdev->active changing */
|
||||
fpi_timeout_add(VFS_SSM_TIMEOUT, scan_completed, _dev, ssm);
|
||||
fpi_timeout_add(VFS_SSM_TIMEOUT, fpi_ssm_next_state_timeout_cb, _dev, ssm);
|
||||
break;
|
||||
|
||||
case SSM_NEXT_RECEIVE:
|
||||
|
|
|
@ -105,9 +105,6 @@ struct vfs101_dev
|
|||
/* Ignore usb error */
|
||||
int ignore_error;
|
||||
|
||||
/* Timeout */
|
||||
fpi_timeout *timeout;
|
||||
|
||||
/* Loop counter */
|
||||
int counter;
|
||||
|
||||
|
@ -470,32 +467,13 @@ async_load(fpi_ssm *ssm,
|
|||
}
|
||||
}
|
||||
|
||||
/* Callback of asynchronous sleep */
|
||||
static void
|
||||
async_sleep_cb(struct fp_dev *dev,
|
||||
void *data)
|
||||
{
|
||||
fpi_ssm *ssm = data;
|
||||
struct vfs101_dev *vdev = FP_INSTANCE_DATA(dev);
|
||||
|
||||
/* Cleanup timeout */
|
||||
vdev->timeout = NULL;
|
||||
|
||||
fpi_ssm_next_state(ssm);
|
||||
}
|
||||
|
||||
/* Submit asynchronous sleep */
|
||||
static void
|
||||
async_sleep(unsigned int msec,
|
||||
fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev)
|
||||
{
|
||||
struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
|
||||
/* Add timeout */
|
||||
vdev->timeout = fpi_timeout_add(msec, async_sleep_cb, FP_DEV(dev), ssm);
|
||||
|
||||
if (vdev->timeout == NULL)
|
||||
if (fpi_timeout_add(msec, fpi_ssm_next_state_timeout_cb, FP_DEV(dev), ssm) == NULL)
|
||||
{
|
||||
/* Failed to add timeout */
|
||||
fp_err("failed to add timeout");
|
||||
|
@ -1505,7 +1483,7 @@ static void dev_deactivate(struct fp_img_dev *dev)
|
|||
vdev->active = FALSE;
|
||||
|
||||
/* Handle eventualy existing events */
|
||||
while (vdev->transfer || vdev->timeout)
|
||||
while (vdev->transfer)
|
||||
fp_handle_events();
|
||||
|
||||
/* Notify deactivate complete */
|
||||
|
|
|
@ -26,28 +26,14 @@
|
|||
|
||||
/************************** GENERIC STUFF *************************************/
|
||||
|
||||
/* Callback of asynchronous sleep */
|
||||
static void
|
||||
async_sleep_cb(struct fp_dev *dev,
|
||||
void *data)
|
||||
{
|
||||
fpi_ssm *ssm = data;
|
||||
|
||||
fpi_ssm_next_state(ssm);
|
||||
}
|
||||
|
||||
/* Submit asynchronous sleep */
|
||||
static void
|
||||
async_sleep(unsigned int msec,
|
||||
fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev)
|
||||
{
|
||||
fpi_timeout *timeout;
|
||||
|
||||
/* Add timeout */
|
||||
timeout = fpi_timeout_add(msec, async_sleep_cb, FP_DEV(dev), ssm);
|
||||
|
||||
if (timeout == NULL) {
|
||||
if (fpi_timeout_add(msec, fpi_ssm_next_state_timeout_cb, FP_DEV(dev), ssm) == NULL) {
|
||||
/* Failed to add timeout */
|
||||
fp_err("failed to add timeout");
|
||||
fpi_imgdev_session_error(dev, -ETIME);
|
||||
|
|
|
@ -472,15 +472,6 @@ static int capture_chunk_async(struct vfs5011_data *data,
|
|||
return libusb_submit_transfer(data->flying_transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
async_sleep_cb(struct fp_dev *dev,
|
||||
void *data)
|
||||
{
|
||||
fpi_ssm *ssm = data;
|
||||
|
||||
fpi_ssm_next_state(ssm);
|
||||
}
|
||||
|
||||
/*
|
||||
* Device initialization. Windows driver only does it when the device is
|
||||
* plugged in, but it doesn't harm to do this every time before scanning the
|
||||
|
@ -721,7 +712,7 @@ static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
|||
break;
|
||||
|
||||
case DEV_ACTIVATE_DATA_COMPLETE:
|
||||
timeout = fpi_timeout_add(1, async_sleep_cb, _dev, ssm);
|
||||
timeout = fpi_timeout_add(1, fpi_ssm_next_state_timeout_cb, _dev, ssm);
|
||||
|
||||
if (timeout == NULL) {
|
||||
/* Failed to add timeout */
|
||||
|
|
|
@ -249,6 +249,28 @@ void fpi_ssm_next_state(fpi_ssm *machine)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fpi_ssm_next_state_timeout_cb:
|
||||
* @dev: a struct #fp_dev
|
||||
* @data: a pointer to an #fpi_ssm state machine
|
||||
*
|
||||
* Same as fpi_ssm_next_state(), but to be used as a callback
|
||||
* for an fpi_timeout_add() callback, when the state change needs
|
||||
* to happen after a timeout.
|
||||
*
|
||||
* Make sure to pass the #fpi_ssm as the `user_data` argument
|
||||
* for that fpi_timeout_add() call.
|
||||
*/
|
||||
void
|
||||
fpi_ssm_next_state_timeout_cb(struct fp_dev *dev,
|
||||
void *data)
|
||||
{
|
||||
g_return_if_fail (dev != NULL);
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
fpi_ssm_next_state(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* fpi_ssm_jump_to_state:
|
||||
* @machine: an #fpi_ssm state machine
|
||||
|
|
|
@ -76,6 +76,7 @@ void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child);
|
|||
|
||||
/* for drivers */
|
||||
void fpi_ssm_next_state(fpi_ssm *machine);
|
||||
void fpi_ssm_next_state_timeout_cb(struct fp_dev *dev, void *data);
|
||||
void fpi_ssm_jump_to_state(fpi_ssm *machine, int state);
|
||||
void fpi_ssm_mark_completed(fpi_ssm *machine);
|
||||
void fpi_ssm_mark_failed(fpi_ssm *machine, int error);
|
||||
|
|
Loading…
Reference in a new issue