egis_etu905: Fix cancel operation to trigger template update

This commit is contained in:
Jason Huang
2026-07-25 21:21:50 +00:00
committed by Marco Trevisan
parent b8154bf466
commit 68aa38ed9d
5 changed files with 324 additions and 218 deletions
+91 -21
View File
@@ -31,8 +31,10 @@ struct _FpiDeviceEgisEtu905
{ {
FpDevice parent; FpDevice parent;
FpiSsm *task_ssm; FpiSsm *task_ssm;
FpiSsm *identify_cancel_ssm;
GPtrArray *enrolled_ids; GPtrArray *enrolled_ids;
gint max_enroll_stages; gint max_enroll_stages;
gboolean identify_started; /* TRUE after cmd_sensor_identify is sent */
}; };
G_DEFINE_TYPE (FpiDeviceEgisEtu905, fpi_device_egis_etu905, FP_TYPE_DEVICE); G_DEFINE_TYPE (FpiDeviceEgisEtu905, fpi_device_egis_etu905, FP_TYPE_DEVICE);
@@ -80,6 +82,11 @@ static void egis_etu905_exec_cmd_full (FpDevice *device,
static void egis_etu905_cancel (FpDevice *device); static void egis_etu905_cancel (FpDevice *device);
static void egis_etu905_cancel_cb (FpDevice *device,
guchar *buffer_in,
gsize length_in,
GError *error);
static void static void
egis_etu905_finger_on_sensor_cb (FpiUsbTransfer *transfer, egis_etu905_finger_on_sensor_cb (FpiUsbTransfer *transfer,
FpDevice *device, FpDevice *device,
@@ -1324,8 +1331,23 @@ egis_etu905_identify_check_cb (FpDevice *device,
fpi_ssm_next_state (self->task_ssm); fpi_ssm_next_state (self->task_ssm);
} }
static void egis_etu905_identify_cancel_run_state (FpiSsm *ssm,
FpDevice *device);
static void static void
egis_etu905_identify_send_cancel_result_cb (FpDevice *device, egis_etu905_identify_cancel_ssm_done (FpiSsm *ssm,
FpDevice *device,
GError *error)
{
FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device);
self->identify_cancel_ssm = NULL;
egis_etu905_cancel_cb (device, NULL, 0, error);
}
static void
egis_etu905_identify_cancel_next_state_cb (FpDevice *device,
guchar *buffer_in, guchar *buffer_in,
gsize length_in, gsize length_in,
GError *error) GError *error)
@@ -1333,13 +1355,62 @@ egis_etu905_identify_send_cancel_result_cb (FpDevice *device,
FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device); FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device);
if (error) if (error)
{ fpi_ssm_mark_failed (self->identify_cancel_ssm, error);
fpi_ssm_mark_failed (self->task_ssm, error); else
return; fpi_ssm_next_state (self->identify_cancel_ssm);
} }
/* Advance to complete state */ static void
fpi_ssm_next_state (self->task_ssm); egis_etu905_identify_cancel_run_state (FpiSsm *ssm,
FpDevice *device)
{
FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device);
switch (fpi_ssm_get_cur_state (ssm))
{
case CANCEL_SENSOR_RESET:
/* Reset sensor to ensure device is in a clean state.
* Use NULL cancellable to ensure this command reaches the device. */
egis_etu905_exec_cmd_full (device, cmd_sensor_reset,
G_N_ELEMENTS (cmd_sensor_reset),
egis_etu905_identify_cancel_next_state_cb,
NULL);
break;
case CANCEL_SEND_CANCEL:
/* Send cmd_identify_cancel to trigger firmware template update.
* Only send if identify was actually started (cmd_sensor_identify was sent).
* Use NULL cancellable to ensure this command reaches the device. */
if (self->identify_started)
{
egis_etu905_exec_cmd_full (device, cmd_identify_cancel,
G_N_ELEMENTS (cmd_identify_cancel),
egis_etu905_identify_cancel_next_state_cb,
NULL);
}
else
{
fpi_ssm_next_state (ssm);
}
break;
case CANCEL_SEND_CANCEL_RESULT:
/* Retrieve the cancel result after template update is triggered.
* Only send if identify was actually started.
* Use NULL cancellable to ensure this command reaches the device. */
if (self->identify_started)
{
egis_etu905_exec_cmd_full (device, cmd_identify_cancel_result,
G_N_ELEMENTS (cmd_identify_cancel_result),
egis_etu905_identify_cancel_next_state_cb,
NULL);
}
else
{
fpi_ssm_next_state (ssm);
}
break;
}
} }
static void static void
@@ -1374,6 +1445,7 @@ egis_etu905_identify_run_state (FpiSsm *ssm,
break; break;
case IDENTIFY_SENSOR_IDENTIFY: case IDENTIFY_SENSOR_IDENTIFY:
self->identify_started = TRUE;
egis_etu905_exec_cmd (device, cmd_sensor_identify, G_N_ELEMENTS (cmd_sensor_identify), egis_etu905_exec_cmd (device, cmd_sensor_identify, G_N_ELEMENTS (cmd_sensor_identify),
egis_etu905_task_ssm_next_state_cb); egis_etu905_task_ssm_next_state_cb);
break; break;
@@ -1393,16 +1465,10 @@ egis_etu905_identify_run_state (FpiSsm *ssm,
egis_etu905_identify_check_cb); egis_etu905_identify_check_cb);
break; break;
case IDENTIFY_SEND_CANCEL_RESULT:
egis_etu905_exec_cmd (device,
cmd_identify_cancel_result,
G_N_ELEMENTS (cmd_identify_cancel_result),
egis_etu905_identify_send_cancel_result_cb);
break;
case IDENTIFY_COMPLETE_SENSOR_RESET: case IDENTIFY_COMPLETE_SENSOR_RESET:
egis_etu905_exec_cmd (device, cmd_sensor_reset, G_N_ELEMENTS (cmd_sensor_reset), egis_etu905_exec_cmd_full (device, cmd_sensor_reset, G_N_ELEMENTS (cmd_sensor_reset),
egis_etu905_task_ssm_next_state_cb); egis_etu905_task_ssm_next_state_cb,
NULL);
break; break;
/* /*
@@ -1429,6 +1495,7 @@ egis_etu905_identify (FpDevice *device)
FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device); FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device);
g_assert (self->task_ssm == NULL); g_assert (self->task_ssm == NULL);
self->identify_started = FALSE;
self->task_ssm = fpi_ssm_new (device, egis_etu905_identify_run_state, IDENTIFY_STATES); self->task_ssm = fpi_ssm_new (device, egis_etu905_identify_run_state, IDENTIFY_STATES);
fpi_ssm_start (self->task_ssm, egis_etu905_task_ssm_done); fpi_ssm_start (self->task_ssm, egis_etu905_task_ssm_done);
} }
@@ -1712,11 +1779,14 @@ egis_etu905_cancel (FpDevice *device)
} }
else if (action == FPI_DEVICE_ACTION_IDENTIFY) else if (action == FPI_DEVICE_ACTION_IDENTIFY)
{ {
egis_etu905_exec_cmd_full (device, FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device);
cmd_identify_cancel,
G_N_ELEMENTS (cmd_identify_cancel), g_assert (self->identify_cancel_ssm == NULL);
egis_etu905_cancel_cb,
NULL); self->identify_cancel_ssm = fpi_ssm_new (device,
egis_etu905_identify_cancel_run_state,
CANCEL_STATES);
fpi_ssm_start (self->identify_cancel_ssm, egis_etu905_identify_cancel_ssm_done);
} }
else else
{ {
+7 -1
View File
@@ -141,7 +141,6 @@ typedef enum {
IDENTIFY_WAIT_FINGER, IDENTIFY_WAIT_FINGER,
IDENTIFY_SENSOR_CHECK, IDENTIFY_SENSOR_CHECK,
IDENTIFY_CHECK, IDENTIFY_CHECK,
IDENTIFY_SEND_CANCEL_RESULT,
IDENTIFY_COMPLETE_SENSOR_RESET, IDENTIFY_COMPLETE_SENSOR_RESET,
IDENTIFY_COMPLETE, IDENTIFY_COMPLETE,
IDENTIFY_STATES, IDENTIFY_STATES,
@@ -180,3 +179,10 @@ typedef enum {
DELETE_DELETE, DELETE_DELETE,
DELETE_STATES, DELETE_STATES,
} DeleteStates; } DeleteStates;
typedef enum {
CANCEL_SENSOR_RESET,
CANCEL_SEND_CANCEL,
CANCEL_SEND_CANCEL_RESULT,
CANCEL_STATES,
} CancelStates;
Binary file not shown.
+29 -21
View File
@@ -39,6 +39,7 @@ def identify_done(dev, res):
identified = True identified = True
identify_match, identify_print = dev.identify_finish(res) identify_match, identify_print = dev.identify_finish(res)
print("MATCH FOUND!" if identify_match else "NO MATCH FOUND") print("MATCH FOUND!" if identify_match else "NO MATCH FOUND")
if identify_match:
assert identify_match.equal(identify_print) assert identify_match.equal(identify_print)
# List # List
@@ -64,6 +65,28 @@ prints2 = len(stored)
print(f"--- LIST DONE: Found {prints2} prints after enroll---") print(f"--- LIST DONE: Found {prints2} prints after enroll---")
assert (prints2 - prints1) == 1 assert (prints2 - prints1) == 1
# Verify
print("--- VERIFYING ---")
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE
verify_res, verify_print = d.verify_sync(p)
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE
print(f"--- VERIFY DONE: Result {verify_res} ---")
# Identify
print("--- ASYNC IDENTIFYING ---")
identified = False
deserialized_prints = []
for sp in stored:
deserialized_prints.append(FPrint.Print.deserialize(sp.serialize()))
assert deserialized_prints[-1].equal(p)
d.identify(deserialized_prints, callback=identify_done)
del deserialized_prints
while not identified:
ctx.iteration(True)
print("--- IDENTIFY DONE ---")
# Cancel test - start async identify and cancel it # Cancel test - start async identify and cancel it
print("--- TESTING CANCELLATION ---") print("--- TESTING CANCELLATION ---")
deserialized_prints = [] deserialized_prints = []
@@ -92,27 +115,11 @@ while not identify_cancelled:
print(f"--- CANCELLATION TEST DONE, result: {cancel_result} ---") print(f"--- CANCELLATION TEST DONE, result: {cancel_result} ---")
del deserialized_prints del deserialized_prints
# Verify # Close and reopen device to ensure clean state after cancellation
print("--- VERIFYING ---") print("--- REOPENING DEVICE ---")
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE d.close_sync()
verify_res, verify_print = d.verify_sync(p) d.open_sync()
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE print("--- DEVICE REOPENED ---")
print(f"--- VERIFY DONE: Result {verify_res} ---")
# Identify
print("--- ASYNC IDENTIFYING ---")
identified = False
deserialized_prints = []
for p in stored:
deserialized_prints.append(FPrint.Print.deserialize(p.serialize()))
assert deserialized_prints[-1].equal(p)
d.identify(deserialized_prints, callback=identify_done)
del deserialized_prints
while not identified:
ctx.iteration(True)
print("--- IDENTIFY DONE ---")
# Delete # Delete
print("--- DELETING ---") print("--- DELETING ---")
@@ -135,3 +142,4 @@ d.close_sync()
del d del d
del c del c
+193 -171
View File
File diff suppressed because one or more lines are too long