Small fixes everywhere

This commit is contained in:
Luke
2020-04-16 11:07:10 +12:00
parent 43373e278b
commit 26a49d518b
4 changed files with 54 additions and 72 deletions

10
Cargo.lock generated
View File

@@ -56,16 +56,18 @@ dependencies = [
[[package]] [[package]]
name = "gumdrop" name = "gumdrop"
version = "0.7.0" version = "0.8.0"
source = "git+https://github.com/murarth/gumdrop.git#61a279eab342381e417b36d06f3f2b67eb21fa3b" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46571f5d540478cf70d2a42dd0d6d8e9f4b9cc7531544b93311e657b86568a0b"
dependencies = [ dependencies = [
"gumdrop_derive", "gumdrop_derive",
] ]
[[package]] [[package]]
name = "gumdrop_derive" name = "gumdrop_derive"
version = "0.7.0" version = "0.8.0"
source = "git+https://github.com/murarth/gumdrop.git#61a279eab342381e417b36d06f3f2b67eb21fa3b" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915ef07c710d84733522461de2a734d4d62a3fd39a4d4f404c2f385ef8618d05"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View File

@@ -6,4 +6,4 @@ edition = "2018"
[dependencies] [dependencies]
rusb = "0.5" rusb = "0.5"
gumdrop = { git = "https://github.com/murarth/gumdrop.git" } gumdrop = "0.8"

View File

@@ -38,25 +38,11 @@ impl Error for AuraError {
} }
} }
#[derive(Debug, PartialEq, Options)] #[derive(Debug, PartialEq)]
pub struct Colour { pub struct Colour(u8, u8, u8);
#[options(help = "print help message")]
help: bool,
#[options(help = "red: eg, 255")]
r: u8,
#[options(help = "green: eg, 123")]
g: u8,
#[options(help = "blue: eg, 166")]
b: u8,
}
impl Default for Colour { impl Default for Colour {
fn default() -> Self { fn default() -> Self {
Colour { Colour(255, 0, 0)
r: 255,
g: 0,
b: 0,
help: false,
}
} }
} }
impl FromStr for Colour { impl FromStr for Colour {
@@ -69,12 +55,7 @@ impl FromStr for Colour {
let r = u8::from_str_radix(&s[0..2], 16).or(Err(AuraError::ParseColour))?; let r = u8::from_str_radix(&s[0..2], 16).or(Err(AuraError::ParseColour))?;
let g = u8::from_str_radix(&s[2..4], 16).or(Err(AuraError::ParseColour))?; let g = u8::from_str_radix(&s[2..4], 16).or(Err(AuraError::ParseColour))?;
let b = u8::from_str_radix(&s[4..6], 16).or(Err(AuraError::ParseColour))?; let b = u8::from_str_radix(&s[4..6], 16).or(Err(AuraError::ParseColour))?;
Ok(Colour { Ok(Colour(r, g, b))
help: false,
r,
g,
b,
})
} }
} }
@@ -137,11 +118,14 @@ impl FromStr for Direction {
pub struct Breathe { pub struct Breathe {
#[options(help = "print help message")] #[options(help = "print help message")]
help: bool, help: bool,
#[options(help = "set the first colour, must be hex string e.g, ff00ff")] #[options(no_long, help = "set the first colour, must be hex string e.g, ff00ff")]
colour1: Colour, colour: Colour,
#[options(help = "set the second colour, must be hex string e.g, ff00ff")] #[options(
no_long,
help = "set the second colour, must be hex string e.g, ff00ff"
)]
colour2: Colour, colour2: Colour,
#[options(help = "set the speed")] #[options(no_long, help = "set the speed: low, med, high")]
speed: Speed, speed: Speed,
} }
@@ -149,7 +133,7 @@ pub struct Breathe {
pub struct SingleSpeed { pub struct SingleSpeed {
#[options(help = "print help message")] #[options(help = "print help message")]
help: bool, help: bool,
#[options(help = "set the speed")] #[options(no_long, help = "set the speed: low, med, high")]
speed: Speed, speed: Speed,
} }
@@ -157,25 +141,27 @@ pub struct SingleSpeed {
pub struct SingleColour { pub struct SingleColour {
#[options(help = "print help message")] #[options(help = "print help message")]
help: bool, help: bool,
#[options(help = "set the colour, must be hex string e.g, ff00ff")] #[options(no_long, help = "set the colour, must be hex string e.g, ff00ff")]
colour: Colour, colour: Colour,
} }
#[derive(Debug, PartialEq, Options)] #[derive(Debug, PartialEq, Options)]
pub struct SingleDirection { pub struct SingleSpeedDirection {
#[options(help = "print help message")] #[options(help = "print help message")]
help: bool, help: bool,
#[options(help = "set the direction: up, down, left, right")] #[options(no_long, help = "set the direction: up, down, left, right")]
direction: Direction, direction: Direction,
#[options(no_long, help = "set the speed: low, med, high")]
speed: Speed,
} }
#[derive(Debug, PartialEq, Options)] #[derive(Debug, PartialEq, Options)]
pub struct SingleColourSpeed { pub struct SingleColourSpeed {
#[options(help = "print help message")] #[options(help = "print help message")]
help: bool, help: bool,
#[options(help = "set the colour, must be hex string e.g, ff00ff")] #[options(no_long, help = "set the colour, must be hex string e.g, ff00ff")]
colour: Colour, colour: Colour,
#[options(help = "set the speed")] #[options(no_long, help = "set the speed: low, med, high")]
speed: Speed, speed: Speed,
} }
@@ -190,8 +176,9 @@ pub enum SetAuraBuiltin {
Breathe(Breathe), Breathe(Breathe),
#[options(help = "cycle through all colours")] #[options(help = "cycle through all colours")]
Cycle(SingleSpeed), Cycle(SingleSpeed),
Rainbow(SingleDirection), #[options(help = "rainbow cycling in one of four directions")]
#[options(help = "random pattern mimicing raindrops")] Rainbow(SingleSpeedDirection),
#[options(help = "random pattern mimicking raindrops")]
Rain(SingleColourSpeed), Rain(SingleColourSpeed),
#[options(help = "random pattern of three preset colours")] #[options(help = "random pattern of three preset colours")]
Random(SingleSpeed), Random(SingleSpeed),
@@ -203,22 +190,17 @@ pub enum SetAuraBuiltin {
Ripple(SingleColourSpeed), Ripple(SingleColourSpeed),
#[options(help = "set a rapid pulse")] #[options(help = "set a rapid pulse")]
Pulse(SingleColour), Pulse(SingleColour),
#[options(help = "set a vertical line racing from left")] #[options(help = "set a vertical line zooming from left")]
LineRace(SingleColour), ThinZoomy(SingleColour),
#[options(help = "set a wide vertical line racing from left")] #[options(help = "set a wide vertical line zooming from left")]
WideLineRace(SingleColour), WideZoomy(SingleColour),
} }
impl Default for SetAuraBuiltin { impl Default for SetAuraBuiltin {
fn default() -> Self { fn default() -> Self {
SetAuraBuiltin::Stable(SingleColour { SetAuraBuiltin::Stable(SingleColour {
help: false, help: false,
colour: Colour { colour: Colour(255, 0, 0),
r: 255,
g: 0,
b: 0,
help: false,
},
}) })
} }
} }
@@ -300,53 +282,50 @@ impl From<SetAuraBuiltin> for ModeMessage {
SetAuraBuiltin::Pulse(_) => { SetAuraBuiltin::Pulse(_) => {
msg[3] = 0x0a; msg[3] = 0x0a;
} }
SetAuraBuiltin::LineRace(_) => { SetAuraBuiltin::ThinZoomy(_) => {
msg[3] = 0x0b; msg[3] = 0x0b;
} }
SetAuraBuiltin::WideLineRace(_) => { SetAuraBuiltin::WideZoomy(_) => {
msg[3] = 0x0c; msg[3] = 0x0c;
} }
_ => {} _ => {}
} }
match mode { match mode {
SetAuraBuiltin::Rainbow(settings) => { SetAuraBuiltin::Rainbow(settings) => {
msg[7] = settings.speed as u8;
msg[8] = settings.direction as u8; msg[8] = settings.direction as u8;
return ModeMessage(msg);
} }
SetAuraBuiltin::Breathe(settings) => { SetAuraBuiltin::Breathe(settings) => {
msg[3] = 0x01; msg[3] = 0x01;
msg[4] = settings.colour1.r; msg[4] = settings.colour.0;
msg[5] = settings.colour1.g; msg[5] = settings.colour.1;
msg[6] = settings.colour1.b; msg[6] = settings.colour.2;
msg[7] = settings.speed as u8; msg[7] = settings.speed as u8;
msg[10] = settings.colour2.r; msg[10] = settings.colour2.0;
msg[11] = settings.colour2.g; msg[11] = settings.colour2.1;
msg[12] = settings.colour2.b; msg[12] = settings.colour2.2;
return ModeMessage(msg);
} }
SetAuraBuiltin::Cycle(settings) | SetAuraBuiltin::Random(settings) => { SetAuraBuiltin::Cycle(settings) | SetAuraBuiltin::Random(settings) => {
msg[7] = settings.speed as u8; msg[7] = settings.speed as u8;
return ModeMessage(msg);
} }
SetAuraBuiltin::Rain(settings) SetAuraBuiltin::Rain(settings)
| SetAuraBuiltin::Highlight(settings) | SetAuraBuiltin::Highlight(settings)
| SetAuraBuiltin::Laser(settings) | SetAuraBuiltin::Laser(settings)
| SetAuraBuiltin::Ripple(settings) => { | SetAuraBuiltin::Ripple(settings) => {
msg[4] = settings.colour.r; msg[4] = settings.colour.0;
msg[5] = settings.colour.g; msg[5] = settings.colour.1;
msg[6] = settings.colour.b; msg[6] = settings.colour.2;
msg[7] = settings.speed as u8; msg[7] = settings.speed as u8;
return ModeMessage(msg);
} }
SetAuraBuiltin::Stable(settings) SetAuraBuiltin::Stable(settings)
| SetAuraBuiltin::Pulse(settings) | SetAuraBuiltin::Pulse(settings)
| SetAuraBuiltin::LineRace(settings) | SetAuraBuiltin::ThinZoomy(settings)
| SetAuraBuiltin::WideLineRace(settings) => { | SetAuraBuiltin::WideZoomy(settings) => {
msg[4] = settings.colour.r; msg[4] = settings.colour.0;
msg[5] = settings.colour.g; msg[5] = settings.colour.1;
msg[6] = settings.colour.b; msg[6] = settings.colour.2;
return ModeMessage(msg);
} }
} }
ModeMessage(msg)
} }
} }

View File

@@ -1,3 +1,4 @@
// TODO: use /sys/class/dmi/id/board_name to detect model
mod aura; mod aura;
mod core; mod core;
@@ -9,7 +10,7 @@ use gumdrop::Options;
struct CLIStart { struct CLIStart {
#[options(help = "print help message")] #[options(help = "print help message")]
help: bool, help: bool,
#[options(help = "<off,low,med,high>")] #[options(help = "<off, low, med, high>")]
bright: Option<LedBrightness>, bright: Option<LedBrightness>,
#[options(command)] #[options(command)]
command: Option<Command>, command: Option<Command>,