enroll/
enroll.rs

1use std::sync::{Arc, Mutex};
2
3use libfprint_rs::{FpContext, FpDevice, FpFinger, FpPrint};
4
5fn main() {
6    // Get context
7    let ctx = FpContext::new();
8    // Collect connected devices
9    let devices = ctx.devices();
10
11    // Get the first connected device
12    let dev = devices.first().unwrap();
13
14    // Open the device to start operations
15    dev.open_sync(None).unwrap();
16
17    // Create a template print
18    let template = FpPrint::new(dev);
19    template.set_finger(FpFinger::RightRing);
20    template.set_username("test");
21
22    // User data that we will use on the callback function,
23    // to mutate the value of a counter, it must be wrapped in an Arc<Mutex<T>>
24    let counter = Arc::new(Mutex::new(0));
25
26    // Get the new print from the user
27    let _new_print = dev
28        .enroll_sync(template, None, Some(progress_cb), Some(counter.clone()))
29        .unwrap();
30
31    // Get the total of time the enroll callback was called
32    println!("Total enroll stages: {}", counter.lock().unwrap());
33}
34
35pub fn progress_cb(
36    _device: &FpDevice,
37    enroll_stage: i32,
38    _print: Option<FpPrint>,
39    _error: Option<glib::Error>,
40    data: &Option<Arc<Mutex<i32>>>,
41) {
42    if let Some(data) = data {
43        let mut d = data.lock().unwrap();
44        *d += 1;
45    }
46    println!("Enroll stage: {}", enroll_stage);
47}