mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Create rog-platform, refactor rogcc ipc-file handling
- Create new rog-platform crate to manage all i/o in a universal way + kbd-led handling + platform handling (asus-nb-wmi) + hidraw + usbraw - Refactor how ROGCC handles IPC for background open, run-in-bg
This commit is contained in:
48
rog-platform/src/usb_raw.rs
Normal file
48
rog-platform/src/usb_raw.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use rusb::{Device, DeviceHandle};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::error::{PlatformError, Result};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct USBRaw(DeviceHandle<rusb::GlobalContext>);
|
||||
|
||||
impl USBRaw {
|
||||
pub fn new(id_product: u16) -> Result<Self> {
|
||||
for device in rusb::devices()?.iter() {
|
||||
let device_desc = device.device_descriptor()?;
|
||||
if device_desc.vendor_id() == 0x0b05 && device_desc.product_id() == id_product {
|
||||
let handle = Self::get_dev_handle(device)?;
|
||||
return Ok(Self(handle));
|
||||
}
|
||||
}
|
||||
|
||||
Err(PlatformError::MissingFunction(format!(
|
||||
"USBRaw dev {} not found",
|
||||
id_product
|
||||
)))
|
||||
}
|
||||
|
||||
fn get_dev_handle(
|
||||
device: Device<rusb::GlobalContext>,
|
||||
) -> Result<DeviceHandle<rusb::GlobalContext>> {
|
||||
// We don't expect this ID to ever change
|
||||
let mut device = device.open()?;
|
||||
device.reset()?;
|
||||
device.set_auto_detach_kernel_driver(true)?;
|
||||
device.claim_interface(0)?;
|
||||
Ok(device)
|
||||
}
|
||||
|
||||
pub fn write_bytes(&self, message: &[u8]) -> Result<usize> {
|
||||
self.0
|
||||
.write_control(
|
||||
0x21, // request_type
|
||||
0x09, // request
|
||||
0x35e, // value
|
||||
0x00, // index
|
||||
message,
|
||||
Duration::from_millis(200),
|
||||
)
|
||||
.map_err(|e| PlatformError::USB(e))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user