medius 3.4.6

Rust library for Medius, replacement firmware for the MAKCU box
Documentation
//! Serial port discovery: USB serial ports filtered to the box by VID/PID.

use crate::types::PortInfo;

pub(crate) const WCH_VID: u16 = 0x1A86;

pub(crate) const CH343_PID: u16 = 0x55D3;

pub(crate) fn find_ports() -> Vec<PortInfo> {
    serialport::available_ports()
        .unwrap_or_default()
        .into_iter()
        .filter_map(|p| match p.port_type {
            serialport::SerialPortType::UsbPort(usb) => Some(PortInfo {
                path: p.port_name,
                vid: usb.vid,
                pid: usb.pid,
                serial: usb.serial_number,
            }),
            _ => None,
        })
        .collect()
}

/// Medius boxes: USB serial ports with the WCH vendor id and CH343 product id.
pub fn find_medius() -> Vec<PortInfo> {
    find_ports()
        .into_iter()
        .filter(|p| p.vid == WCH_VID && p.pid == CH343_PID)
        .collect()
}