Struct libfprint_rs::FpDevice
source · pub struct FpDevice<'a> { /* private fields */ }
Expand description
Fingerpint device routines. You can interact with fingerprint devices using this struct.
Examples:
use libfprint_rs::FpContext;
let context = FpContext::new();
let devices = context.get_devices();
let device = devices.iter().next().unwrap();
device.open().unwrap();
let name = device.get_name().unwrap();
println!("Device name: {}", name);
Implementations§
source§impl<'a> FpDevice<'a>
impl<'a> FpDevice<'a>
sourcepub fn identify<T>(
&self,
prints: Vec<FpPrint<'_>>,
callback_fn: Option<FpMatchCb<T>>,
user_data: Option<T>,
matched_print: Option<&mut FpPrint<'_>>,
new_print: Option<&mut FpPrint<'_>>
) -> Result<(), GError<'static>>
pub fn identify<T>( &self, prints: Vec<FpPrint<'_>>, callback_fn: Option<FpMatchCb<T>>, user_data: Option<T>, matched_print: Option<&mut FpPrint<'_>>, new_print: Option<&mut FpPrint<'_>> ) -> Result<(), GError<'static>>
Identify a print from a given vector of prints.
Example:
use libfprint_rs::{device::FpDevice, error::GError, print::FpPrint, context::FpContext};
let ctx = FpContext::new();
let dev = ctx.get_devices().iter().next().unwrap();
fn callback_function(
device: &FpDevice, // The fingerprint scanner device
matched_print: Option<FpPrint>, // The matched print, if any.
new_print: FpPrint, // New print scanned.
error: Option<GError>, // Optinal error in case of an error.
match_data: &Option<()> // User data can be any data type.
)
{
if matched_print.is_some() {
println!("Found matched print!");
}
}
let prints: Vec<FpPrint> = function_to_get_prints(&dev);
dev.identify(prints, Some(callback_function), None::<()>, None, None);
Example with mutation
If you want to mutate the data inside match_data
you can use Rc<RefCell<T>>
:
use std::{cell::RefCell, rc::Rc};
use libfprint_rs::{device::FpDevice, error::GError, print::FpPrint, context::FpContext};
let ctx = FpContext::new();
let dev = ctx.get_devices().iter().next().unwrap();
struct UserData {
count: u32,
name: String,
}
fn callback_fn(
device: &FpDevice, // The fingerprint scanner device
matched_print: Option<FpPrint>, // The matched print, if any.
new_print: FpPrint, // New print scanned.
error: Option<GError>, // Optinal error in case of an error.
match_data: &Option<Rc<RefCell<UserData>>>, // User data can be any data type.
)
{
if let Some(user_data) = match_data {
user_data.borrow_mut().count += 1;
// Mutate the user data
}
println!("Found matched print!");
}
let user_data = Rc::new(RefCell::new(UserData { count: 304, name: "Donda".into() }));
dev.identify(prints, Some(callback_fn), Some(user_data), None, None);
println!("{}", user_data.borrow().count);
sourcepub fn enroll<T>(
&self,
template_print: FpPrint<'_>,
callback_fn: Option<FpEnrollProgress<T>>,
user_data: Option<T>
) -> Result<FpPrint<'static>, GError<'static>>
pub fn enroll<T>( &self, template_print: FpPrint<'_>, callback_fn: Option<FpEnrollProgress<T>>, user_data: Option<T> ) -> Result<FpPrint<'static>, GError<'static>>
Enroll a new print. Template print is a print with relevant metadata filled in.
Example:
use libfprint_rs::{device::FpDevice, error::GError, print::FpPrint, context::FpContext};
let ctx = FpContext::new();
let dev = ctx.get_devices().iter().next().unwrap();
fn callback_fn(
device: &FpDevice,
completed_stages: i32,
print: FpPrint,
error: Option<GError>,
user_data: &Option<()>
) {
if error.is_none() {
println!("Enrolling: {} of {}", completed_stages, device.get_nr_enroll_stages() );
}
}
dev.open().unwrap();
let template_print = FpPrint::new(&dev);
dev.enroll(template_print, Some(callback_fn), None::<()>);
Example with mutation
If you want to mutate the data inside user_data
you can use Rc<RefCell<T>>
:
use std::{cell::RefCell, rc::Rc};
use libfprint_rs::{device::FpDevice, error::GError, print::FpPrint, context::FpContext};
let ctx = FpContext::new();
let dev = ctx.get_devices().iter().next().unwrap();
struct UserData {
count: u32,
name: String,
}
fn callback_fn(
device: &FpDevice,
completed_stages: i32,
print: FpPrint,
error: Option<GError>,
user_data: &Option<Rc<RefCell<UserData>>>
) {
if let Some(user_data) = user_data {
user_data.borrow_mut().count += 1;
// Mutate the user data
}
println!("Enrolling: {} of {}", completed_stages, device.get_nr_enroll_stages() );
}
let user_data = Rc::new(RefCell::new(UserData { count: 304, name: "Donda".into() }));
let template_print = FpPrint::new(&dev);
dev.enroll(template_print, Some(callback_fn), Some(user_data));
println!("{}", user_data.borrow().count);
sourcepub fn verify<T>(
&self,
enrolled_print: FpPrint<'_>,
callback_fn: Option<FpMatchCb<T>>,
match_data: Option<T>,
scanned_print: Option<&mut FpPrint<'_>>
) -> Result<(), GError<'static>>
pub fn verify<T>( &self, enrolled_print: FpPrint<'_>, callback_fn: Option<FpMatchCb<T>>, match_data: Option<T>, scanned_print: Option<&mut FpPrint<'_>> ) -> Result<(), GError<'static>>
Verify a given print.
Example:
use libfprint_rs::{device::FpDevice, error::GError, print::FpPrint, context::FpContext};
let ctx = FpContext::new();
let dev = ctx.get_devices().iter().next().unwrap();
fn match_callback_fn(
device: &FpDevice, // The fingerprint scanner device
matched_print: Option<FpPrint>, // The matched print, if any.
new_print: FpPrint, // New print scanned.
error: Option<GError>, // Error, if any.
match_data: &Option<()> // User data to pass to this function.
)
{
if matched_print.is_some() {
println!("Found matched print!");
}
}
// This dummy fn gets an existing print
let enrolled_print = get_enrolled_print();
// Where we saved the new scanned print
let mut scanned_print = FpPrint::new(&dev);
dev.verify(enrolled_print, Some(match_callback_fn), None::<()>, Some(&mut scanned_print));
sourcepub fn get_nr_enroll_stages(&self) -> i32
pub fn get_nr_enroll_stages(&self) -> i32
Retrieves the number of enroll stages for this device.
sourcepub fn get_finger_status(&self) -> FpFingerStatusFlags
pub fn get_finger_status(&self) -> FpFingerStatusFlags
Retrieves the finger status flags for the device. This can be used by the UI to present the relevant feedback, although it is not guaranteed to be a relevant value when not performing any action.
pub fn get_features(&self) -> Vec<FpDeviceFeature>
pub fn get_driver(&self) -> &str
pub fn get_device_id(&self) -> &str
sourcepub fn get_scan_type(&self) -> FpScanType
pub fn get_scan_type(&self) -> FpScanType
Retrieves the scan type of the device (FpScanType
)
sourcepub fn has_feature(&self, features: FpDeviceFeature) -> bool
pub fn has_feature(&self, features: FpDeviceFeature) -> bool
Checks if the FpDevice
supports the requested FpDeviceFeature
.
pub fn is_open(&self) -> bool
sourcepub fn delete_print(&self, print: FpPrint<'_>) -> Result<(), GError<'_>>
pub fn delete_print(&self, print: FpPrint<'_>) -> Result<(), GError<'_>>
Delete a print from the device. This only makes sense on devices that store prints on-chip, but is safe to always call.
pub fn list_prints(&self)
sourcepub fn clear_storage(&self) -> Result<(), GError<'_>>
pub fn clear_storage(&self) -> Result<(), GError<'_>>
Deletes all prints from the device. This only makes sense on devices that store prints on-chip, but is safe to always call.