mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-22 14:09:16 +01:00
detection
This commit is contained in:
parent
688c0242c1
commit
999dd244c7
@ -1,5 +1,6 @@
|
|||||||
pub struct DeviceInfo {
|
pub struct DeviceInfo {
|
||||||
pub port: String,
|
pub port: String,
|
||||||
|
pub description: String,
|
||||||
pub serial: String,
|
pub serial: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +78,7 @@ impl Wrapper {
|
|||||||
let result = if devices > 0 {
|
let result = if devices > 0 {
|
||||||
let mut list: Vec<DeviceInfo> = vec![];
|
let mut list: Vec<DeviceInfo> = vec![];
|
||||||
|
|
||||||
|
let mut description = [0i8; 128];
|
||||||
let mut serial = [0i8; 128];
|
let mut serial = [0i8; 128];
|
||||||
|
|
||||||
let mut device = device_list;
|
let mut device = device_list;
|
||||||
@ -88,8 +90,8 @@ impl Wrapper {
|
|||||||
(*device).dev,
|
(*device).dev,
|
||||||
std::ptr::null_mut(),
|
std::ptr::null_mut(),
|
||||||
0,
|
0,
|
||||||
std::ptr::null_mut(),
|
description.as_mut_ptr(),
|
||||||
0,
|
description.len() as i32,
|
||||||
serial.as_mut_ptr(),
|
serial.as_mut_ptr(),
|
||||||
serial.len() as i32,
|
serial.len() as i32,
|
||||||
)
|
)
|
||||||
@ -98,6 +100,9 @@ impl Wrapper {
|
|||||||
if result == 0 {
|
if result == 0 {
|
||||||
list.push(DeviceInfo {
|
list.push(DeviceInfo {
|
||||||
port: format!("i:0x{vendor:04X}:0x{product:04X}:{index}"),
|
port: format!("i:0x{vendor:04X}:0x{product:04X}:{index}"),
|
||||||
|
description: unsafe { std::ffi::CStr::from_ptr(description.as_ptr()) }
|
||||||
|
.to_string_lossy()
|
||||||
|
.into_owned(),
|
||||||
serial: unsafe { std::ffi::CStr::from_ptr(serial.as_ptr()) }
|
serial: unsafe { std::ffi::CStr::from_ptr(serial.as_ptr()) }
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.into_owned(),
|
.into_owned(),
|
||||||
|
@ -553,13 +553,14 @@ pub struct DeviceInfo {
|
|||||||
pub fn list_local_devices() -> Result<Vec<DeviceInfo>, Error> {
|
pub fn list_local_devices() -> Result<Vec<DeviceInfo>, Error> {
|
||||||
const SC64_VID: u16 = 0x0403;
|
const SC64_VID: u16 = 0x0403;
|
||||||
const SC64_PID: u16 = 0x6014;
|
const SC64_PID: u16 = 0x6014;
|
||||||
const SC64_SID: &str = "SC64";
|
const SC64_SERIAL_PREFIX: &str = "SC64";
|
||||||
|
const SC64_DESCRIPTION: &str = "SC64";
|
||||||
|
|
||||||
let mut devices: Vec<DeviceInfo> = Vec::new();
|
let mut devices: Vec<DeviceInfo> = Vec::new();
|
||||||
|
|
||||||
if let Ok(list) = FtdiDevice::list(SC64_VID, SC64_PID) {
|
if let Ok(list) = FtdiDevice::list(SC64_VID, SC64_PID) {
|
||||||
for device in list.into_iter() {
|
for device in list.into_iter() {
|
||||||
if device.serial.starts_with(SC64_SID) {
|
if device.description == SC64_DESCRIPTION {
|
||||||
devices.push(DeviceInfo {
|
devices.push(DeviceInfo {
|
||||||
backend: BackendType::Ftdi,
|
backend: BackendType::Ftdi,
|
||||||
port: format!("{FTDI_PREFIX}{}", device.port),
|
port: format!("{FTDI_PREFIX}{}", device.port),
|
||||||
@ -571,7 +572,9 @@ pub fn list_local_devices() -> Result<Vec<DeviceInfo>, Error> {
|
|||||||
|
|
||||||
if let Ok(list) = SerialDevice::list(SC64_VID, SC64_PID) {
|
if let Ok(list) = SerialDevice::list(SC64_VID, SC64_PID) {
|
||||||
for device in list.into_iter() {
|
for device in list.into_iter() {
|
||||||
if device.serial.starts_with(SC64_SID) {
|
let is_sc64_device = device.description == SC64_DESCRIPTION
|
||||||
|
|| device.serial.starts_with(SC64_SERIAL_PREFIX);
|
||||||
|
if is_sc64_device {
|
||||||
devices.push(DeviceInfo {
|
devices.push(DeviceInfo {
|
||||||
backend: BackendType::Serial,
|
backend: BackendType::Serial,
|
||||||
port: format!("{SERIAL_PREFIX}{}", device.port),
|
port: format!("{SERIAL_PREFIX}{}", device.port),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
pub struct DeviceInfo {
|
pub struct DeviceInfo {
|
||||||
pub port: String,
|
pub port: String,
|
||||||
|
pub description: String,
|
||||||
pub serial: String,
|
pub serial: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,10 +41,11 @@ impl SerialDevice {
|
|||||||
|
|
||||||
for port in serialport::available_ports()? {
|
for port in serialport::available_ports()? {
|
||||||
if let serialport::SerialPortType::UsbPort(info) = port.port_type {
|
if let serialport::SerialPortType::UsbPort(info) = port.port_type {
|
||||||
if info.vid == vendor && info.pid == product && info.serial_number.is_some() {
|
if info.vid == vendor && info.pid == product {
|
||||||
devices.push(DeviceInfo {
|
devices.push(DeviceInfo {
|
||||||
port: port.port_name,
|
port: port.port_name,
|
||||||
serial: info.serial_number.unwrap(),
|
description: info.product.unwrap_or_default(),
|
||||||
|
serial: info.serial_number.unwrap_or_default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user