| 68 | const SERIAL_TIMEOUT: Duration = Duration::from_millis(20); |
| 69 | |
| 70 | fn match_serialdevs( |
| 71 | ports: &[SerialPortInfo], |
| 72 | requested: &Option<String>, |
| 73 | pid: Option<u16>, |
| 74 | ) -> Vec<String> { |
| 75 | if let Some(requested) = requested { |
| 76 | for p in ports { |
| 77 | if requested == &p.port_name { |
| 78 | return vec![p.port_name.clone()]; |
| 79 | } |
| 80 | } |
| 81 | vec![] |
| 82 | } else { |
| 83 | let mut compatible_devs = vec![]; |
| 84 | let pids = if let Some(pid) = pid { |
| 85 | vec![pid] |
| 86 | } else { |
| 87 | // By default accept any type |
| 88 | vec![LED_MATRIX_PID, B1_LCD_PID, 0x22, 0xFF] |
| 89 | }; |
| 90 | // Find all supported Framework devices |
| 91 | for p in ports { |
| 92 | if let SerialPortType::UsbPort(usbinfo) = &p.port_type { |
| 93 | if usbinfo.vid == FRAMEWORK_VID && pids.contains(&usbinfo.pid) { |
| 94 | compatible_devs.push(p.port_name.clone()); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | compatible_devs |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | pub fn find_serialdevs(args: &crate::ClapCli, wait_for_device: bool) -> (Vec<String>, bool) { |
| 103 | let mut serialdevs: Vec<String>; |