Better structure

This commit is contained in:
Luke
2020-04-15 22:10:13 +12:00
parent 732295f8b7
commit 89158cdc98
5 changed files with 137 additions and 112 deletions

View File

@@ -1,5 +1,8 @@
use crate::aura::AuraError;
use crate::aura::ModeMessage;
use gumdrop::Options;
use rusb::{DeviceHandle, Error};
use std::str::FromStr;
use std::time::Duration;
pub const LED_MSG_LEN: usize = 17;
@@ -30,6 +33,27 @@ static LED_SPECIAL: [u8; 64] = [
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,
}
impl FromStr for LedBrightness {
type Err = AuraError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.to_lowercase();
match s.as_str() {
"off" => Ok(LedBrightness { level: 0x00 }),
"low" => Ok(LedBrightness { level: 0x01 }),
"med" => Ok(LedBrightness { level: 0x02 }),
"high" => Ok(LedBrightness { level: 0x03 }),
_ => {
println!("Missing required argument, must be one of:\noff,low,med,high\n");
Err(AuraError::ParseSpeed)
}
}
}
}
/// ROG device controller
///