mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Check in work before I wreck it all
This commit is contained in:
127
src/main.rs
127
src/main.rs
@@ -1,111 +1,32 @@
|
|||||||
extern crate rusb;
|
extern crate rusb;
|
||||||
|
mod aura;
|
||||||
|
|
||||||
use rusb::{DeviceHandle, Error};
|
use aura::RogCore;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
static LED_MSG_LEN: usize = 17;
|
|
||||||
static LED_SPEED_BYTES: [u8; 3] = [0xe1, 0xeb, 0xf5];
|
|
||||||
static LED_INIT1: [u8; 2] = [0x5d, 0xb9];
|
|
||||||
static LED_INIT2: &'static str = "]ASUS Tech.Inc."; // 0x5d ASUS Tech.Inc.
|
|
||||||
static LED_INIT3: [u8; 6] = [0x5d, 0x05, 0x20, 0x31, 0x00, 0x08];
|
|
||||||
static LED_INIT4: &'static str = "^ASUS Tech.Inc."; // 0x5e ASUS Tech.Inc.
|
|
||||||
static LED_INIT5: [u8; 6] = [0x5e, 0x05, 0x20, 0x31, 0x00, 0x08];
|
|
||||||
static LED_SET: [u8; 2] = [0x5d, 0xb5];
|
|
||||||
static LED_APPLY: [u8; 2] = [0x5d, 0xb4];
|
|
||||||
static LED_BRIGHT_BYTES: [u8; 6] = [0x5a, 0xba, 0xc5, 0xc4, 0, 0]; // Pos 4 = set brightness
|
|
||||||
|
|
||||||
fn get_device(vendor: u16, product: u16) -> Result<DeviceHandle<rusb::GlobalContext>, Error> {
|
|
||||||
for device in rusb::devices().unwrap().iter() {
|
|
||||||
let device_desc = device.device_descriptor().unwrap();
|
|
||||||
if device_desc.vendor_id() == vendor && device_desc.product_id() == product {
|
|
||||||
return device.open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(Error::NoDevice)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut handle = get_device(0x0B05, 0x1866)?;
|
let mut core = RogCore::new()?;
|
||||||
handle.set_active_configuration(0).unwrap_or(());
|
core.aura_set_brightness(0)?;
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
|
core.aura_set_brightness(3)?;
|
||||||
|
|
||||||
let config = handle.device().config_descriptor(0).unwrap();
|
core.aura_set_colour((0xff, 0x00, 0x00))?;
|
||||||
// Interface with outputs
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
let mut keyboard_iface_num = 0;
|
core.test_builtins(aura::LED_SPEED_BYTES[2])?;
|
||||||
let mut led_iface_num = 0;
|
//core.aura_test()?;
|
||||||
for iface in config.interfaces() {
|
|
||||||
for desc in iface.descriptors() {
|
|
||||||
for endpoint in desc.endpoint_descriptors() {
|
|
||||||
if endpoint.address() == 0x83 {
|
|
||||||
keyboard_iface_num = desc.interface_number();
|
|
||||||
} else if endpoint.address() == 0x81 {
|
|
||||||
led_iface_num = desc.interface_number();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if handle.kernel_driver_active(keyboard_iface_num).unwrap() {
|
// std::thread::sleep(std::time::Duration::from_secs(5));
|
||||||
handle.detach_kernel_driver(keyboard_iface_num).unwrap();
|
// core.aura_set_rainbow(aura::LED_SPEED_BYTES[2])?;
|
||||||
}
|
|
||||||
if handle.kernel_driver_active(led_iface_num).unwrap() {
|
|
||||||
handle.detach_kernel_driver(led_iface_num).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let iface_out = config
|
// // READ KEYBOARD
|
||||||
.interfaces()
|
// let mut buf = [0; 32];
|
||||||
.nth(keyboard_iface_num as usize)
|
// loop {
|
||||||
.unwrap();
|
// match handle.read_interrupt(0x83, &mut buf, Duration::new(0, 5)) {
|
||||||
let iface_led = config.interfaces().nth(led_iface_num as usize).unwrap();
|
// Ok(_) => println!("{:?}", buf),
|
||||||
|
// Err(err) => match err {
|
||||||
handle.claim_interface(iface_out.number()).unwrap();
|
// Error::Timeout => {}
|
||||||
handle.claim_interface(iface_led.number()).unwrap();
|
// _ => return Err(Box::new(err)),
|
||||||
|
// },
|
||||||
// WRITE LED
|
// }
|
||||||
// bmRequestType = 0x21
|
// }
|
||||||
// bRequest = 0x09
|
Ok(())
|
||||||
// wValue = 0x035D
|
|
||||||
// wIndex = 0
|
|
||||||
println!("BEGIN INIT");
|
|
||||||
handle.write_control(0x21, 0x09, 0x035D, 0, &LED_INIT1, Duration::new(0, 5))?;
|
|
||||||
handle.write_control(
|
|
||||||
0x21,
|
|
||||||
0x09,
|
|
||||||
0x035D,
|
|
||||||
0,
|
|
||||||
&LED_INIT2.as_bytes(),
|
|
||||||
Duration::new(0, 5),
|
|
||||||
)?;
|
|
||||||
handle.write_control(0x21, 0x09, 0x035D, 0, &LED_INIT3, Duration::new(0, 5))?;
|
|
||||||
handle.write_control(
|
|
||||||
0x21,
|
|
||||||
0x09,
|
|
||||||
0x035D,
|
|
||||||
0,
|
|
||||||
&LED_INIT4.as_bytes(),
|
|
||||||
Duration::new(0, 5),
|
|
||||||
)?;
|
|
||||||
handle.write_control(0x21, 0x09, 0x035D, 0, &LED_INIT5, Duration::new(0, 5))?;
|
|
||||||
println!("END INIT");
|
|
||||||
|
|
||||||
println!("BEGIN BRIGHT");
|
|
||||||
let mut bright = LED_BRIGHT_BYTES.clone();
|
|
||||||
bright[4] = 1;
|
|
||||||
println!("{:x?}", bright);
|
|
||||||
handle.write_control(0x21, 0x09, 0x035D, 0, &bright, Duration::new(0, 5))?;
|
|
||||||
println!("END BRIGHT");
|
|
||||||
handle.write_control(0x21, 0x09, 0x035D, 0, &LED_SET, Duration::new(0, 5))?;
|
|
||||||
handle.write_control(0x21, 0x09, 0x035D, 0, &LED_APPLY, Duration::new(0, 5))?;
|
|
||||||
println!("END");
|
|
||||||
|
|
||||||
// READ KEYBOARD
|
|
||||||
let mut buf = [0; 32];
|
|
||||||
loop {
|
|
||||||
match handle.read_interrupt(0x83, &mut buf, Duration::new(0, 5)) {
|
|
||||||
Ok(_) => println!("{:?}", buf),
|
|
||||||
Err(err) => match err {
|
|
||||||
Error::Timeout => {}
|
|
||||||
_ => return Err(Box::new(err)),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user