libfprint_rs/device/
fp_device.rs1use glib::translate::{FromGlibPtrFull, FromGlibPtrNone, ToGlibPtr};
2
3use super::{
4 FpDevice,
5 enums::{FpDeviceFeature, FpFingerStatus, FpScanType},
6};
7
8impl FpDevice {
9 pub fn driver(&self) -> String {
11 unsafe {
12 let driver = libfprint_sys::fp_device_get_driver(self.to_glib_none().0);
13 glib::GString::from_glib_none(driver).to_string()
14 }
15 }
16 pub fn device_id(&self) -> String {
18 unsafe {
19 let driver = libfprint_sys::fp_device_get_device_id(self.to_glib_none().0);
20 glib::GString::from_glib_none(driver).to_string()
21 }
22 }
23 pub fn name(&self) -> String {
25 unsafe {
26 let name = libfprint_sys::fp_device_get_name(self.to_glib_none().0);
27 glib::GString::from_glib_full(name).to_string()
28 }
29 }
30 pub fn scan_type(&self) -> FpScanType {
32 let scan_type = unsafe { libfprint_sys::fp_device_get_scan_type(self.to_glib_none().0) };
33 match scan_type {
34 libfprint_sys::FpScanType_FP_SCAN_TYPE_PRESS => FpScanType::Press,
35 libfprint_sys::FpScanType_FP_SCAN_TYPE_SWIPE => FpScanType::Swipe,
36 _ => panic!("Unknown scan type"),
37 }
38 }
39 pub fn nr_enroll_stage(&self) -> i32 {
41 unsafe { libfprint_sys::fp_device_get_nr_enroll_stages(self.to_glib_none().0) }
42 }
43 pub fn finger_status(&self) -> FpFingerStatus {
45 let status = unsafe { libfprint_sys::fp_device_get_finger_status(self.to_glib_none().0) };
46 match status {
47 libfprint_sys::FpFingerStatusFlags_FP_FINGER_STATUS_NONE => FpFingerStatus::None,
48 libfprint_sys::FpFingerStatusFlags_FP_FINGER_STATUS_NEEDED => FpFingerStatus::Needed,
49 libfprint_sys::FpFingerStatusFlags_FP_FINGER_STATUS_PRESENT => FpFingerStatus::Present,
50 _ => panic!("Unknown finger status"),
51 }
52 }
53 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
54 pub fn features(&self) -> Vec<FpDeviceFeature> {
56 let mut features = Vec::new();
58 let x = unsafe { libfprint_sys::fp_device_get_features(self.to_glib_none().0) };
59 if x == 0 {
60 return vec![FpDeviceFeature::None];
61 } else {
62 (0..31).for_each(|i| {
63 let mask = 1 << i;
64 if (mask & x) > 0
65 && let Ok(feature) = FpDeviceFeature::try_from(2_u32.pow(i))
66 {
67 features.push(feature);
68 }
69 });
70 }
71 features
72 }
73 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
74 pub fn has_feature(&self, feature: FpDeviceFeature) -> bool {
76 let res =
77 unsafe { libfprint_sys::fp_device_has_feature(self.to_glib_none().0, feature as u32) };
78 res == glib::ffi::GTRUE
79 }
80 pub fn is_open(&self) -> bool {
82 unsafe { libfprint_sys::fp_device_is_open(self.to_glib_none().0) == glib::ffi::GTRUE }
83 }
84}