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
+94 -24
View File
@@ -31,8 +31,10 @@ struct _FpiDeviceEgisEtu905
{
FpDevice parent;
FpiSsm *task_ssm;
FpiSsm *identify_cancel_ssm;
GPtrArray *enrolled_ids;
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);
@@ -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_cb (FpDevice *device,
guchar *buffer_in,
gsize length_in,
GError *error);
static void
egis_etu905_finger_on_sensor_cb (FpiUsbTransfer *transfer,
FpDevice *device,
@@ -1324,22 +1331,86 @@ egis_etu905_identify_check_cb (FpDevice *device,
fpi_ssm_next_state (self->task_ssm);
}
static void egis_etu905_identify_cancel_run_state (FpiSsm *ssm,
FpDevice *device);
static void
egis_etu905_identify_send_cancel_result_cb (FpDevice *device,
guchar *buffer_in,
gsize length_in,
GError *error)
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,
gsize length_in,
GError *error)
{
FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device);
if (error)
{
fpi_ssm_mark_failed (self->task_ssm, error);
return;
}
fpi_ssm_mark_failed (self->identify_cancel_ssm, error);
else
fpi_ssm_next_state (self->identify_cancel_ssm);
}
/* Advance to complete state */
fpi_ssm_next_state (self->task_ssm);
static void
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
@@ -1374,6 +1445,7 @@ egis_etu905_identify_run_state (FpiSsm *ssm,
break;
case IDENTIFY_SENSOR_IDENTIFY:
self->identify_started = TRUE;
egis_etu905_exec_cmd (device, cmd_sensor_identify, G_N_ELEMENTS (cmd_sensor_identify),
egis_etu905_task_ssm_next_state_cb);
break;
@@ -1393,16 +1465,10 @@ egis_etu905_identify_run_state (FpiSsm *ssm,
egis_etu905_identify_check_cb);
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:
egis_etu905_exec_cmd (device, cmd_sensor_reset, G_N_ELEMENTS (cmd_sensor_reset),
egis_etu905_task_ssm_next_state_cb);
egis_etu905_exec_cmd_full (device, cmd_sensor_reset, G_N_ELEMENTS (cmd_sensor_reset),
egis_etu905_task_ssm_next_state_cb,
NULL);
break;
/*
@@ -1429,6 +1495,7 @@ egis_etu905_identify (FpDevice *device)
FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device);
g_assert (self->task_ssm == NULL);
self->identify_started = FALSE;
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);
}
@@ -1712,11 +1779,14 @@ egis_etu905_cancel (FpDevice *device)
}
else if (action == FPI_DEVICE_ACTION_IDENTIFY)
{
egis_etu905_exec_cmd_full (device,
cmd_identify_cancel,
G_N_ELEMENTS (cmd_identify_cancel),
egis_etu905_cancel_cb,
NULL);
FpiDeviceEgisEtu905 *self = FPI_DEVICE_EGIS_ETU905 (device);
g_assert (self->identify_cancel_ssm == 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
{
+7 -1
View File
@@ -141,7 +141,6 @@ typedef enum {
IDENTIFY_WAIT_FINGER,
IDENTIFY_SENSOR_CHECK,
IDENTIFY_CHECK,
IDENTIFY_SEND_CANCEL_RESULT,
IDENTIFY_COMPLETE_SENSOR_RESET,
IDENTIFY_COMPLETE,
IDENTIFY_STATES,
@@ -180,3 +179,10 @@ typedef enum {
DELETE_DELETE,
DELETE_STATES,
} DeleteStates;
typedef enum {
CANCEL_SENSOR_RESET,
CANCEL_SEND_CANCEL,
CANCEL_SEND_CANCEL_RESULT,
CANCEL_STATES,
} CancelStates;
Binary file not shown.
+30 -22
View File
@@ -39,7 +39,8 @@ def identify_done(dev, res):
identified = True
identify_match, identify_print = dev.identify_finish(res)
print("MATCH FOUND!" if identify_match else "NO MATCH FOUND")
assert identify_match.equal(identify_print)
if identify_match:
assert identify_match.equal(identify_print)
# List
print("--- LISTING ---")
@@ -64,6 +65,28 @@ prints2 = len(stored)
print(f"--- LIST DONE: Found {prints2} prints after enroll---")
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
print("--- TESTING CANCELLATION ---")
deserialized_prints = []
@@ -92,27 +115,11 @@ while not identify_cancelled:
print(f"--- CANCELLATION TEST DONE, result: {cancel_result} ---")
del deserialized_prints
# 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 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 ---")
# Close and reopen device to ensure clean state after cancellation
print("--- REOPENING DEVICE ---")
d.close_sync()
d.open_sync()
print("--- DEVICE REOPENED ---")
# Delete
print("--- DELETING ---")
@@ -135,3 +142,4 @@ d.close_sync()
del d
del c
+193 -171
View File
File diff suppressed because one or more lines are too long