<div dir="ltr">I think it would be better if libfprint simply called dev_activate each time it needed an image, including each enroll step, and then called dev_deactivate when it's done. Drivers should know whether they need to reactivate or not. But this will require changes to all the drivers of the devices that return images... which should actually amount to a few deleted lines.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 16, 2018 at 3:57 AM Marco Trevisan (Treviño) <<a href="mailto:mail@3v1n0.net">mail@3v1n0.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">When a device has this flag set, it has to be re-activated at<br>
each enroll step, without performing any other cleanup.<br>
<br>
This allows to solve this such case in a cleaner way inside<br>
drivers.<br>
---<br>
 libfprint/fp_internal.h |  1 +<br>
 libfprint/imgdev.c      | 30 +++++++++++++++++++++++++++---<br>
 2 files changed, 28 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h<br>
index 74c5f7f..ea46b1e 100644<br>
--- a/libfprint/fp_internal.h<br>
+++ b/libfprint/fp_internal.h<br>
@@ -232,6 +232,7 @@ enum fp_print_data_type<br>
fpi_driver_get_data_type(struct fp_driver *drv);<br>
  /* flags for fp_img_driver.flags */<br>
 #define FP_IMGDRV_SUPPORTS_UNCONDITIONAL_CAPTURE (1 << 0)<br>
+#define FP_IMGDRV_NEEDS_REACTIVATION_BETWEEN_ENROLLS (1 << 1)<br>
  struct fp_img_driver {<br>
        struct fp_driver driver;<br>
diff --git a/libfprint/imgdev.c b/libfprint/imgdev.c<br>
index 4408c23..20a1559 100644<br>
--- a/libfprint/imgdev.c<br>
+++ b/libfprint/imgdev.c<br>
@@ -27,6 +27,9 @@<br>
 #define BOZORTH3_DEFAULT_THRESHOLD 40<br>
 #define IMG_ENROLL_STAGES 5<br>
 +static int dev_activate(struct fp_img_dev *imgdev, enum<br>
fp_imgdev_state state);<br>
+static void dev_deactivate(struct fp_img_dev *imgdev);<br>
+<br>
 static int img_dev_open(struct fp_dev *dev, unsigned long driver_data)<br>
 {<br>
        struct fp_img_dev *imgdev = g_malloc0(sizeof(*imgdev));<br>
@@ -124,6 +127,7 @@ void fpi_imgdev_report_finger_status(struct<br>
fp_img_dev *imgdev,<br>
        int r = imgdev->action_result;<br>
        struct fp_print_data *data = imgdev->acquire_data;<br>
        struct fp_img *img = imgdev->acquire_img;<br>
+       struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv);<br>
        fp_dbg(present ? "finger on sensor" : "finger removed");<br>
 @@ -158,8 +162,14 @@ void fpi_imgdev_report_finger_status(struct<br>
fp_img_dev *imgdev,<br>
                if (imgdev->action == IMG_ACTION_ENROLL &&<br>
                    r > 0 && r != FP_ENROLL_COMPLETE && r != FP_ENROLL_FAIL) {<br>
                        imgdev->action_result = 0;<br>
-                       imgdev->action_state = IMG_ACQUIRE_STATE_AWAIT_FINGER_ON;<br>
-                       dev_change_state(imgdev, IMGDEV_STATE_AWAIT_FINGER_ON);<br>
+<br>
+                       if (imgdrv->flags & FP_IMGDRV_NEEDS_REACTIVATION_BETWEEN_ENROLLS) {<br>
+                               imgdev->action_state = IMG_ACQUIRE_STATE_DEACTIVATING;<br>
+                               dev_deactivate(imgdev);<br>
+                       } else {<br>
+                               imgdev->action_state = IMG_ACQUIRE_STATE_AWAIT_FINGER_ON;<br>
+                               dev_change_state(imgdev, IMGDEV_STATE_AWAIT_FINGER_ON);<br>
+                       }<br>
                }<br>
                break;<br>
        case IMG_ACTION_VERIFY:<br>
@@ -332,11 +342,16 @@ void fpi_imgdev_session_error(struct fp_img_dev<br>
*imgdev, int error)<br>
  void fpi_imgdev_activate_complete(struct fp_img_dev *imgdev, int status)<br>
 {<br>
+       struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv);<br>
+<br>
        fp_dbg("status %d", status);<br>
        switch (imgdev->action) {<br>
        case IMG_ACTION_ENROLL:<br>
-               fpi_drvcb_enroll_started(imgdev->dev, status);<br>
+               if (!(imgdrv->flags & FP_IMGDRV_NEEDS_REACTIVATION_BETWEEN_ENROLLS) ||<br>
+                   imgdev->dev->state != DEV_STATE_ENROLLING) {<br>
+                       fpi_drvcb_enroll_started(imgdev->dev, status);<br>
+               }<br>
                break;<br>
        case IMG_ACTION_VERIFY:<br>
                fpi_drvcb_verify_started(imgdev->dev, status);<br>
@@ -360,10 +375,19 @@ void fpi_imgdev_activate_complete(struct<br>
fp_img_dev *imgdev, int status)<br>
  void fpi_imgdev_deactivate_complete(struct fp_img_dev *imgdev)<br>
 {<br>
+       struct fp_img_driver *imgdrv = fpi_driver_to_img_driver(imgdev->dev->drv);<br>
+<br>
        fp_dbg("");<br>
        switch (imgdev->action) {<br>
        case IMG_ACTION_ENROLL:<br>
+               if ((imgdrv->flags & FP_IMGDRV_NEEDS_REACTIVATION_BETWEEN_ENROLLS) &&<br>
+                       imgdev->dev->state == DEV_STATE_ENROLLING) {<br>
+                       imgdev->action_state = IMG_ACQUIRE_STATE_ACTIVATING;<br>
+                       dev_activate(imgdev, IMGDEV_STATE_AWAIT_FINGER_ON);<br>
+                       return;<br>
+               }<br>
+<br>
                fpi_drvcb_enroll_stopped(imgdev->dev);<br>
                break;<br>
        case IMG_ACTION_VERIFY:<br>
--<br>
2.7.4<br>
<br>
_______________________________________________<br>
fprint mailing list<br>
<a href="mailto:fprint@lists.freedesktop.org" target="_blank">fprint@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/fprint" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/fprint</a><br>
</blockquote></div>