File tree Expand file tree Collapse file tree 1 file changed +17
-15
lines changed
Expand file tree Collapse file tree 1 file changed +17
-15
lines changed Original file line number Diff line number Diff line change @@ -112,19 +112,21 @@ pub async fn gatt_list_devices() -> Result<Vec<super::commands::AvailableDevice>
112112 . await
113113 . expect ( "GET DEVICES!" )
114114 . take_until ( async_std:: task:: sleep ( Duration :: from_secs ( 2 ) ) )
115- . filter_map ( |d| ready ( d. ok ( ) ) )
116- . filter_map ( move |device| async move {
117- if device. is_connected ( ) . await {
118- let label = device. name_async ( ) . await . unwrap_or ( "Unknown" . to_string ( ) ) ;
119- let id = serde_json:: to_string ( & device. id ( ) ) . unwrap ( ) ;
120-
121- Some ( super :: commands:: AvailableDevice { label, id } )
122- } else {
123- None
124- }
125- } )
126- . collect :: < Vec < _ > > ( )
127- . await ;
128-
129- Ok ( devices)
115+ . filter_map ( |d| ready ( d. ok ( ) ) ) ;
116+
117+ futures:: pin_mut!( devices) ;
118+
119+ let mut ret = vec ! [ ] ;
120+ while let Some ( device) = devices. next ( ) . await {
121+ if let Ok ( ( ) ) = adapter. connect_device ( & device) . await {
122+ let label = device. name_async ( ) . await . unwrap_or ( "Unknown" . to_string ( ) ) ;
123+ let id = serde_json:: to_string ( & device. id ( ) ) . unwrap ( ) ;
124+
125+ ret. push ( super :: commands:: AvailableDevice { label, id } ) ;
126+ } else {
127+ println ! ( "Device isn't connected: {:?}" , device) ;
128+ }
129+ }
130+
131+ Ok ( ret)
130132}
You can’t perform that action at this time.
0 commit comments