@@ -9,12 +9,16 @@ use crate::transport::device::Device;
99use crate :: transport:: error:: Error ;
1010
1111use super :: channel:: NfcChannel ;
12+ #[ cfg( feature = "libnfc" ) ]
13+ use super :: libnfc;
1214#[ cfg( feature = "pcsc" ) ]
1315use super :: pcsc;
1416use super :: { Context , Nfc } ;
1517
1618#[ derive( Debug ) ]
1719enum DeviceInfo {
20+ #[ cfg( feature = "libnfc" ) ]
21+ LibNfc ( libnfc:: Info ) ,
1822 #[ cfg( feature = "pcsc" ) ]
1923 Pcsc ( pcsc:: Info ) ,
2024}
@@ -27,6 +31,8 @@ pub struct NfcDevice {
2731impl fmt:: Display for DeviceInfo {
2832 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2933 match & self {
34+ #[ cfg( feature = "libnfc" ) ]
35+ DeviceInfo :: LibNfc ( info) => write ! ( f, "{}" , info) ,
3036 #[ cfg( feature = "pcsc" ) ]
3137 DeviceInfo :: Pcsc ( info) => write ! ( f, "{}" , info) ,
3238 }
@@ -40,6 +46,13 @@ impl fmt::Display for NfcDevice {
4046}
4147
4248impl NfcDevice {
49+ #[ cfg( feature = "libnfc" ) ]
50+ pub fn new_libnfc ( info : libnfc:: Info ) -> Self {
51+ NfcDevice {
52+ info : DeviceInfo :: LibNfc ( info) ,
53+ }
54+ }
55+
4356 #[ cfg( feature = "pcsc" ) ]
4457 pub fn new_pcsc ( info : pcsc:: Info ) -> Self {
4558 NfcDevice {
@@ -53,6 +66,8 @@ impl NfcDevice {
5366 trace ! ( "nfc channel {:?}" , self ) ;
5467 let ( mut channel, recv) : ( NfcChannel < Context > , mpsc:: Receiver < UxUpdate > ) = match & self . info
5568 {
69+ #[ cfg( feature = "libnfc" ) ]
70+ DeviceInfo :: LibNfc ( info) => info. channel ( ) ,
5671 #[ cfg( feature = "pcsc" ) ]
5772 DeviceInfo :: Pcsc ( info) => info. channel ( ) ,
5873 } ?;
92107pub async fn list_devices ( ) -> Result < Vec < NfcDevice > , Error > {
93108 let mut all_devices = Vec :: new ( ) ;
94109 let list_devices_fns = [
110+ #[ cfg( feature = "libnfc" ) ]
111+ libnfc:: list_devices,
95112 #[ cfg( feature = "pcsc" ) ]
96113 pcsc:: list_devices,
97114 ] ;
0 commit comments