2 * Example fingerprint enrollment program
3 * Enrolls your right index finger and saves the print to disk
4 * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <libfprint/fprint.h>
27 struct fp_dscv_dev
*discover_device(struct fp_dscv_dev
**discovered_devs
)
29 struct fp_dscv_dev
*ddev
= NULL
;
32 for (i
= 0; ddev
= discovered_devs
[i
]; i
++) {
33 const struct fp_driver
*drv
= fp_dscv_dev_get_driver(ddev
);
34 printf("Found device claimed by %s driver\n",
35 fp_driver_get_full_name(drv
));
42 struct fp_print_data
*enroll(struct fp_dev
*dev
) {
43 struct fp_print_data
*enrolled_print
= NULL
;
46 printf("You will need to successfully scan your finger %d times to "
47 "complete the process.\n", fp_dev_get_nr_enroll_stages(dev
));
51 printf("\nScan your finger now.\n");
52 r
= fp_enroll_finger(dev
, &enrolled_print
);
54 printf("Enroll failed with error %d\n", r
);
58 case FP_ENROLL_COMPLETE
:
59 printf("Enroll complete!\n");
62 printf("Enroll failed, something wen't wrong :(\n");
65 printf("Enroll stage passed. Yay!\n");
68 printf("Didn't quite catch that. Please try again.\n");
70 case FP_ENROLL_RETRY_TOO_SHORT
:
71 printf("Your swipe was too short, please try again.\n");
73 case FP_ENROLL_RETRY_CENTER_FINGER
:
74 printf("Didn't catch that, please center your finger on the "
75 "sensor and try again.\n");
77 case FP_ENROLL_RETRY_REMOVE_FINGER
:
78 printf("Scan failed, please remove your finger and then try "
82 } while (r
!= FP_ENROLL_COMPLETE
);
84 if (!enrolled_print
) {
85 fprintf(stderr
, "Enroll complete but no print?\n");
89 printf("Enrollment completed!\n\n");
90 return enrolled_print
;
96 struct fp_dscv_dev
*ddev
;
97 struct fp_dscv_dev
**discovered_devs
;
99 struct fp_print_data
*data
;
101 printf("This program will enroll your right index finger, "
102 "unconditionally overwriting any right-index print that was enrolled "
103 "previously. If you want to continue, press enter, otherwise hit "
109 fprintf(stderr
, "Failed to initialize libfprint\n");
113 discovered_devs
= fp_discover_devs();
114 if (!discovered_devs
) {
115 fprintf(stderr
, "Could not discover devices\n");
119 ddev
= discover_device(discovered_devs
);
121 fprintf(stderr
, "No devices detected.\n");
125 dev
= fp_dev_open(ddev
);
126 fp_dscv_devs_free(discovered_devs
);
128 fprintf(stderr
, "Could not open device.\n");
132 printf("Opened device. It's now time to enroll your finger.\n\n");
137 r
= fp_print_data_save(data
, RIGHT_INDEX
);
139 fprintf(stderr
, "Data save failed, code %d\n", r
);
141 fp_print_data_free(data
);