File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ impl HidApi {
166166 pub fn new ( ) -> HidResult < Self > {
167167 let mut init_state = INIT_STATE . lock ( ) . expect ( "HidApi context initialization" ) ;
168168
169- # [ allow ( unused_variables ) ]
169+ let mut list_devices = true ;
170170 if let InitState :: Uninit { device_discovery } = * init_state {
171171 #[ cfg( all( libusb, not( target_os = "freebsd" ) ) ) ]
172172 if !device_discovery {
@@ -176,6 +176,8 @@ impl HidApi {
176176 unsafe { ffi:: libusb_set_option ( std:: ptr:: null_mut ( ) , 2 ) }
177177 }
178178
179+ list_devices = device_discovery;
180+
179181 // Initialize the HID
180182 #[ cfg( hidapi) ]
181183 if unsafe { ffi:: hid_init ( ) } == -1 {
@@ -190,11 +192,17 @@ impl HidApi {
190192 * init_state = InitState :: Init ;
191193 }
192194
193- let mut api = HidApi {
194- device_list : Vec :: with_capacity ( 8 ) ,
195- } ;
196- api. add_devices ( 0 , 0 ) ?;
197- Ok ( api)
195+ if list_devices {
196+ let mut api = Self {
197+ device_list : Vec :: with_capacity ( 8 ) ,
198+ } ;
199+ api. add_devices ( 0 , 0 ) ?;
200+ Ok ( api)
201+ } else {
202+ Ok ( Self {
203+ device_list : Vec :: new ( ) ,
204+ } )
205+ }
198206 }
199207
200208 /// Refresh devices list and information about them (to access them use
You can’t perform that action at this time.
0 commit comments