mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
End up duplicating the CLI structs but without help member
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::cli_options::*;
|
||||
use crate::cli_options;
|
||||
use crate::cli_options::SetAuraBuiltin;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
pub const SINGLE: u8 = 0x00;
|
||||
@@ -14,7 +15,148 @@ pub const PULSE: u8 = 0x0a;
|
||||
pub const COMET: u8 = 0x0b;
|
||||
pub const FLASH: u8 = 0x0c;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||
pub struct Colour(pub u8, pub u8, pub u8);
|
||||
impl From<cli_options::Colour> for Colour {
|
||||
fn from(c: cli_options::Colour) -> Self {
|
||||
Colour(c.0, c.1, c.2)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Deserialize, Serialize)]
|
||||
pub enum Speed {
|
||||
Low = 0xe1,
|
||||
Med = 0xeb,
|
||||
High = 0xf5,
|
||||
}
|
||||
impl From<cli_options::Speed> for Speed {
|
||||
fn from(s: cli_options::Speed) -> Self {
|
||||
match s {
|
||||
cli_options::Speed::Low => Speed::Low,
|
||||
cli_options::Speed::Med => Speed::Med,
|
||||
cli_options::Speed::High => Speed::High,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Default for Speed {
|
||||
fn default() -> Self {
|
||||
Speed::Med
|
||||
}
|
||||
}
|
||||
|
||||
/// Used for Rainbow mode.
|
||||
///
|
||||
/// Enum corresponds to the required integer value
|
||||
#[derive(Copy, Clone, Deserialize, Serialize)]
|
||||
pub enum Direction {
|
||||
Right,
|
||||
Left,
|
||||
Up,
|
||||
Down,
|
||||
}
|
||||
impl From<cli_options::Direction> for Direction {
|
||||
fn from(s: cli_options::Direction) -> Self {
|
||||
match s {
|
||||
cli_options::Direction::Right => Direction::Right,
|
||||
cli_options::Direction::Left => Direction::Left,
|
||||
cli_options::Direction::Up => Direction::Up,
|
||||
cli_options::Direction::Down => Direction::Down,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Default for Direction {
|
||||
fn default() -> Self {
|
||||
Direction::Right
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||
pub struct TwoColourSpeed {
|
||||
pub colour: Colour,
|
||||
pub colour2: Colour,
|
||||
pub speed: Speed,
|
||||
}
|
||||
impl From<cli_options::TwoColourSpeed> for TwoColourSpeed {
|
||||
fn from(mode: cli_options::TwoColourSpeed) -> Self {
|
||||
TwoColourSpeed {
|
||||
colour: mode.colour.into(),
|
||||
colour2: mode.colour2.into(),
|
||||
speed: mode.speed.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||
pub struct SingleSpeed {
|
||||
pub speed: Speed,
|
||||
}
|
||||
impl From<cli_options::SingleSpeed> for SingleSpeed {
|
||||
fn from(mode: cli_options::SingleSpeed) -> Self {
|
||||
SingleSpeed {
|
||||
speed: mode.speed.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||
pub struct SingleColour {
|
||||
pub colour: Colour,
|
||||
}
|
||||
impl From<cli_options::SingleColour> for SingleColour {
|
||||
fn from(mode: cli_options::SingleColour) -> Self {
|
||||
SingleColour {
|
||||
colour: mode.colour.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||
pub struct MultiColour {
|
||||
pub colour1: Colour,
|
||||
pub colour2: Colour,
|
||||
pub colour3: Colour,
|
||||
pub colour4: Colour,
|
||||
}
|
||||
impl From<cli_options::MultiColour> for MultiColour {
|
||||
fn from(mode: cli_options::MultiColour) -> Self {
|
||||
MultiColour {
|
||||
colour1: mode.colour1.into(),
|
||||
colour2: mode.colour2.into(),
|
||||
colour3: mode.colour3.into(),
|
||||
colour4: mode.colour4.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||
pub struct SingleSpeedDirection {
|
||||
pub direction: Direction,
|
||||
pub speed: Speed,
|
||||
}
|
||||
impl From<cli_options::SingleSpeedDirection> for SingleSpeedDirection {
|
||||
fn from(mode: cli_options::SingleSpeedDirection) -> Self {
|
||||
SingleSpeedDirection {
|
||||
direction: mode.direction.into(),
|
||||
speed: mode.speed.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||
pub struct SingleColourSpeed {
|
||||
pub colour: Colour,
|
||||
pub speed: Speed,
|
||||
}
|
||||
impl From<cli_options::SingleColourSpeed> for SingleColourSpeed {
|
||||
fn from(mode: cli_options::SingleColourSpeed) -> Self {
|
||||
SingleColourSpeed {
|
||||
colour: mode.colour.into(),
|
||||
speed: mode.speed.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub enum AuraModes {
|
||||
Stable(SingleColour),
|
||||
Breathe(TwoColourSpeed),
|
||||
@@ -37,56 +179,60 @@ pub enum AuraModes {
|
||||
impl From<SetAuraBuiltin> for AuraModes {
|
||||
fn from(mode: SetAuraBuiltin) -> Self {
|
||||
match mode {
|
||||
SetAuraBuiltin::Stable(x) => AuraModes::Stable(x),
|
||||
SetAuraBuiltin::Breathe(x) => AuraModes::Breathe(x),
|
||||
SetAuraBuiltin::Strobe(x) => AuraModes::Strobe(x),
|
||||
SetAuraBuiltin::Rainbow(x) => AuraModes::Rainbow(x),
|
||||
SetAuraBuiltin::Star(x) => AuraModes::Star(x),
|
||||
SetAuraBuiltin::Rain(x) => AuraModes::Rain(x),
|
||||
SetAuraBuiltin::Highlight(x) => AuraModes::Highlight(x),
|
||||
SetAuraBuiltin::Laser(x) => AuraModes::Laser(x),
|
||||
SetAuraBuiltin::Ripple(x) => AuraModes::Ripple(x),
|
||||
SetAuraBuiltin::Pulse(x) => AuraModes::Pulse(x),
|
||||
SetAuraBuiltin::Comet(x) => AuraModes::Comet(x),
|
||||
SetAuraBuiltin::Flash(x) => AuraModes::Flash(x),
|
||||
SetAuraBuiltin::MultiStatic(x) => AuraModes::MultiStatic(x),
|
||||
SetAuraBuiltin::Stable(x) => AuraModes::Stable(x.into()),
|
||||
SetAuraBuiltin::Breathe(x) => AuraModes::Breathe(x.into()),
|
||||
SetAuraBuiltin::Strobe(x) => AuraModes::Strobe(x.into()),
|
||||
SetAuraBuiltin::Rainbow(x) => AuraModes::Rainbow(x.into()),
|
||||
SetAuraBuiltin::Star(x) => AuraModes::Star(x.into()),
|
||||
SetAuraBuiltin::Rain(x) => AuraModes::Rain(x.into()),
|
||||
SetAuraBuiltin::Highlight(x) => AuraModes::Highlight(x.into()),
|
||||
SetAuraBuiltin::Laser(x) => AuraModes::Laser(x.into()),
|
||||
SetAuraBuiltin::Ripple(x) => AuraModes::Ripple(x.into()),
|
||||
SetAuraBuiltin::Pulse(x) => AuraModes::Pulse(x.into()),
|
||||
SetAuraBuiltin::Comet(x) => AuraModes::Comet(x.into()),
|
||||
SetAuraBuiltin::Flash(x) => AuraModes::Flash(x.into()),
|
||||
SetAuraBuiltin::MultiStatic(x) => AuraModes::MultiStatic(x.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Very specific mode conversion required because numbering isn't linear
|
||||
impl From<AuraModes> for u8 {
|
||||
fn from(mode: AuraModes) -> Self {
|
||||
u8::from(&mode)
|
||||
}
|
||||
}
|
||||
|
||||
/// Very specific mode conversion required because numbering isn't linear
|
||||
impl From<&mut AuraModes> for u8 {
|
||||
fn from(mode: &mut AuraModes) -> Self {
|
||||
u8::from(&*mode)
|
||||
}
|
||||
}
|
||||
|
||||
/// Very specific mode conversion required because numbering isn't linear
|
||||
impl From<&AuraModes> for u8 {
|
||||
fn from(mode: &AuraModes) -> Self {
|
||||
match mode {
|
||||
AuraModes::Stable(_) => 0x00,
|
||||
AuraModes::Breathe(_) => 0x01,
|
||||
AuraModes::Strobe(_) => 0x02,
|
||||
AuraModes::Rainbow(_) => 0x03,
|
||||
AuraModes::Star(_) => 0x04,
|
||||
AuraModes::Rain(_) => 0x05,
|
||||
AuraModes::Highlight(_) => 0x06,
|
||||
AuraModes::Laser(_) => 0x07,
|
||||
AuraModes::Ripple(_) => 0x08,
|
||||
AuraModes::Pulse(_) => 0x0a,
|
||||
AuraModes::Comet(_) => 0x0b,
|
||||
AuraModes::Flash(_) => 0x0c,
|
||||
AuraModes::Stable(_) => SINGLE,
|
||||
AuraModes::Breathe(_) => BREATHING,
|
||||
AuraModes::Strobe(_) => STROBE,
|
||||
AuraModes::Rainbow(_) => RAINBOW,
|
||||
AuraModes::Star(_) => STAR,
|
||||
AuraModes::Rain(_) => RAIN,
|
||||
AuraModes::Highlight(_) => HIGHLIGHT,
|
||||
AuraModes::Laser(_) => LASER,
|
||||
AuraModes::Ripple(_) => RIPPLE,
|
||||
AuraModes::Pulse(_) => PULSE,
|
||||
AuraModes::Comet(_) => COMET,
|
||||
AuraModes::Flash(_) => FLASH,
|
||||
AuraModes::MultiStatic(_) => 0x0d,
|
||||
_ => panic!("Invalid mode"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Exists to convert back from correct bytes
|
||||
impl From<u8> for AuraModes {
|
||||
fn from(byte: u8) -> Self {
|
||||
match byte {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use crate::error::AuraError;
|
||||
use gumdrop::Options;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::fmt::Debug;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug, Options)]
|
||||
#[derive(Options)]
|
||||
pub struct LedBrightness {
|
||||
level: u8,
|
||||
}
|
||||
@@ -31,7 +30,7 @@ impl FromStr for LedBrightness {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Colour(pub u8, pub u8, pub u8);
|
||||
impl Default for Colour {
|
||||
fn default() -> Self {
|
||||
@@ -52,7 +51,7 @@ impl FromStr for Colour {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum Speed {
|
||||
Low = 0xe1,
|
||||
Med = 0xeb,
|
||||
@@ -80,7 +79,7 @@ impl FromStr for Speed {
|
||||
/// Used for Rainbow mode.
|
||||
///
|
||||
/// Enum corresponds to the required integer value
|
||||
#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum Direction {
|
||||
Right,
|
||||
Left,
|
||||
@@ -107,7 +106,7 @@ impl FromStr for Direction {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Options, Deserialize, Serialize)]
|
||||
#[derive(Default, Options, Deserialize, Serialize)]
|
||||
pub struct TwoColourSpeed {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
@@ -119,7 +118,7 @@ pub struct TwoColourSpeed {
|
||||
pub speed: Speed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Options, Deserialize, Serialize)]
|
||||
#[derive(Default, Options, Deserialize, Serialize)]
|
||||
pub struct SingleSpeed {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
@@ -127,7 +126,7 @@ pub struct SingleSpeed {
|
||||
pub speed: Speed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Options, Deserialize, Serialize)]
|
||||
#[derive(Default, Options, Deserialize, Serialize)]
|
||||
pub struct SingleColour {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
@@ -135,7 +134,7 @@ pub struct SingleColour {
|
||||
pub colour: Colour,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Options, Deserialize, Serialize)]
|
||||
#[derive(Default, Options, Deserialize, Serialize)]
|
||||
pub struct MultiColour {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
@@ -149,7 +148,7 @@ pub struct MultiColour {
|
||||
pub colour4: Colour,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Options, Deserialize, Serialize)]
|
||||
#[derive(Default, Options, Deserialize, Serialize)]
|
||||
pub struct SingleSpeedDirection {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
@@ -163,7 +162,7 @@ pub struct SingleSpeedDirection {
|
||||
pub speed: Speed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Options, Deserialize, Serialize)]
|
||||
#[derive(Default, Options, Deserialize, Serialize)]
|
||||
pub struct SingleColourSpeed {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
@@ -173,16 +172,10 @@ pub struct SingleColourSpeed {
|
||||
pub speed: Speed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Options, Clone, Deserialize, Serialize, Default)]
|
||||
pub struct FreeOpts {
|
||||
#[options(free)]
|
||||
free: Vec<String>,
|
||||
}
|
||||
|
||||
/// Byte value for setting the built-in mode.
|
||||
///
|
||||
/// Enum corresponds to the required integer value
|
||||
#[derive(Debug, Clone, Options, Deserialize, Serialize)]
|
||||
#[derive(Options, Deserialize, Serialize)]
|
||||
pub enum SetAuraBuiltin {
|
||||
#[options(help = "set a single static colour")]
|
||||
Stable(SingleColour),
|
||||
|
||||
@@ -149,10 +149,7 @@ impl LaptopBase {
|
||||
0
|
||||
};
|
||||
if let Some(data) = config.get_led_mode_data(self.supported_modes[idx_next]) {
|
||||
aura_command
|
||||
.send(data.to_owned())
|
||||
.await
|
||||
.unwrap_or_else(|_| {});
|
||||
aura_command.send(data.clone()).await.unwrap_or_else(|_| {});
|
||||
}
|
||||
} else {
|
||||
warn!("Tried to step to next LED mode while in non-supported mode");
|
||||
@@ -166,10 +163,7 @@ impl LaptopBase {
|
||||
self.supported_modes.len() - 1
|
||||
};
|
||||
if let Some(data) = config.get_led_mode_data(self.supported_modes[idx_next]) {
|
||||
aura_command
|
||||
.send(data.to_owned())
|
||||
.await
|
||||
.unwrap_or_else(|_| {});
|
||||
aura_command.send(data.clone()).await.unwrap_or_else(|_| {});
|
||||
}
|
||||
} else {
|
||||
warn!("Tried to step to next LED mode while in non-supported mode");
|
||||
|
||||
@@ -161,7 +161,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
warn!("{:?} not supported", mode);
|
||||
warn!("Attempted to set unsupported mode");
|
||||
Err(AuraError::NotSupported)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::io::Write;
|
||||
|
||||
static VERSION: &str = "0.13.1";
|
||||
|
||||
#[derive(Debug, Options)]
|
||||
#[derive(Options)]
|
||||
struct CLIStart {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
@@ -28,13 +28,13 @@ struct CLIStart {
|
||||
command: Option<Command>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Options)]
|
||||
#[derive(Options)]
|
||||
enum Command {
|
||||
#[options(help = "Set the keyboard lighting from built-in modes")]
|
||||
LedMode(LedModeCommand),
|
||||
}
|
||||
|
||||
#[derive(Debug, Options)]
|
||||
#[derive(Options)]
|
||||
struct LedModeCommand {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
|
||||
Reference in New Issue
Block a user