Code cleanup

This commit is contained in:
Luke
2020-04-15 22:19:22 +12:00
parent 89158cdc98
commit fc7a08ea37
2 changed files with 18 additions and 42 deletions

View File

@@ -11,6 +11,7 @@ pub enum AuraError {
ParseColour,
ParseSpeed,
ParseDirection,
ParseBrightness,
}
impl Debug for AuraError {
@@ -34,6 +35,7 @@ impl Error for AuraError {
AuraError::ParseColour => "could not parse colour",
AuraError::ParseSpeed => "could not parse speed",
AuraError::ParseDirection => "could not parse direction",
AuraError::ParseBrightness => "could not parse brightness",
}
}
}
@@ -43,11 +45,11 @@ pub struct Colour {
#[options(help = "print help message")]
help: bool,
#[options(help = "red: eg, 255")]
red: u8,
r: u8,
#[options(help = "green: eg, 123")]
green: u8,
g: u8,
#[options(help = "blue: eg, 166")]
blue: u8,
b: u8,
}
impl FromStr for Colour {
@@ -62,9 +64,9 @@ impl FromStr for Colour {
let b = u8::from_str_radix(&s[4..6], 16).or(Err(AuraError::ParseColour))?;
Ok(Colour {
help: false,
red: r,
green: g,
blue: b,
r,
g,
b,
})
}
}
@@ -216,20 +218,20 @@ impl From<SetAuraBuiltin> for ModeMessage {
match mode {
SetAuraBuiltin::Stable(settings) => {
msg[3] = 0x00;
msg[4] = settings.red;
msg[5] = settings.green;
msg[6] = settings.blue;
msg[4] = settings.r;
msg[5] = settings.g;
msg[6] = settings.b;
return ModeMessage(msg);
}
SetAuraBuiltin::Breathe(settings) => {
msg[3] = 0x01;
msg[4] = settings.colour1.red;
msg[5] = settings.colour1.green;
msg[6] = settings.colour1.blue;
msg[4] = settings.colour1.r;
msg[5] = settings.colour1.g;
msg[6] = settings.colour1.b;
msg[7] = settings.speed as u8;
msg[10] = settings.colour2.red;
msg[11] = settings.colour2.green;
msg[12] = settings.colour2.blue;
msg[10] = settings.colour2.r;
msg[11] = settings.colour2.g;
msg[12] = settings.colour2.b;
return ModeMessage(msg);
}
_ => {}

View File

@@ -6,33 +6,16 @@ use std::str::FromStr;
use std::time::Duration;
pub const LED_MSG_LEN: usize = 17;
pub static LED_SPEED_BYTES: [u8; 3] = [0xe1, 0xeb, 0xf5]; // maps to 1, 2, 3
static LED_BRIGHT_BYTES: [u8; 5] = [0x5a, 0xba, 0xc5, 0xc4, 0]; // Index 4 = set brightness
static LED_INIT1: [u8; 2] = [0x5d, 0xb9];
static LED_INIT2: &'static str = "]ASUS Tech.Inc."; // ] == 0x5d
static LED_INIT3: [u8; 6] = [0x5d, 0x05, 0x20, 0x31, 0, 0x08];
static LED_INIT4: &'static str = "^ASUS Tech.Inc."; // ^ == 0x5e
static LED_INIT5: [u8; 6] = [0x5e, 0x05, 0x20, 0x31, 0, 0x08];
static LED_BUILTIN: [u8; 13] = [
0x5d, 0xb3, 0x03, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
];
// Only these two packets must be 17 bytes
static LED_APPLY: [u8; 17] = [0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
static LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
// bytes 0,1 set mode
// bytes 3,4,5 set to on,
// byte 6 increments (starts at 0x00, continues 0x10 to 0xA0) 0-10 << 4
// byte 7 resets (stays on 10 until byte6 == 0xA0 then flips to 08 in same packet as 0xA0)
// bytes 8-57 are bitfield for keys
static LED_SPECIAL: [u8; 64] = [
0x5d, 0xbc, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
#[derive(Debug, Options)]
pub struct LedBrightness {
pub level: u8,
@@ -49,7 +32,7 @@ impl FromStr for LedBrightness {
"high" => Ok(LedBrightness { level: 0x03 }),
_ => {
println!("Missing required argument, must be one of:\noff,low,med,high\n");
Err(AuraError::ParseSpeed)
Err(AuraError::ParseBrightness)
}
}
}
@@ -95,15 +78,6 @@ impl RogCore {
handle.set_auto_detach_kernel_driver(true).unwrap();
handle.set_auto_detach_kernel_driver(true).unwrap();
// let iface_out = config
// .interfaces()
// .nth(keys_interface_num as usize)
// .unwrap();
// let iface_led = config.interfaces().nth(led_interface_num as usize).unwrap();
//handle.claim_interface(iface_out.number()).unwrap();
//handle.claim_interface(iface_led.number()).unwrap();
Ok(RogCore {
handle,
initialised: false,