From e938f1f9ec984c175b833ef381f83b62e19d88f1 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Sat, 1 Oct 2022 14:57:25 +1300 Subject: [PATCH] Minor fixes to attr writes --- asusctl/src/main.rs | 14 +++++--------- daemon/src/ctrl_aura/controller.rs | 5 +---- daemon/src/ctrl_platform.rs | 2 +- rog-aura/src/sequencer/effects.rs | 6 +----- rog-platform/src/macros.rs | 1 + rog-platform/src/platform.rs | 19 ++++++++++--------- 6 files changed, 19 insertions(+), 28 deletions(-) diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 4fd9ac82..46adca55 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -31,15 +31,11 @@ fn main() -> Result<(), Box> { let missing_argument_k = gumdrop::Error::missing_argument(Opt::Short('k')); let parsed = match CliStart::parse_args_default(&args) { - Ok(p) => { - p - } - Err(err) if err.to_string() == missing_argument_k.to_string() => { - CliStart { - kbd_bright: Some(LedBrightness::new(None)), - ..Default::default() - } - } + Ok(p) => p, + Err(err) if err.to_string() == missing_argument_k.to_string() => CliStart { + kbd_bright: Some(LedBrightness::new(None)), + ..Default::default() + }, Err(err) => { eprintln!("source {}", err); std::process::exit(2); diff --git a/daemon/src/ctrl_aura/controller.rs b/daemon/src/ctrl_aura/controller.rs index 8152118e..b3fa5056 100644 --- a/daemon/src/ctrl_aura/controller.rs +++ b/daemon/src/ctrl_aura/controller.rs @@ -422,10 +422,7 @@ mod tests { controller.supported_modes.multizone.push(AuraZone::Key2); assert_eq!( - controller - .set_effect(effect) - .unwrap_err() - .to_string(), + controller.set_effect(effect).unwrap_err().to_string(), "No supported Aura keyboard" ); } diff --git a/daemon/src/ctrl_platform.rs b/daemon/src/ctrl_platform.rs index 7c601738..d7ae4aed 100644 --- a/daemon/src/ctrl_platform.rs +++ b/daemon/src/ctrl_platform.rs @@ -78,7 +78,7 @@ impl CtrlPlatform { } fn set_gfx_mode(&self, mode: GpuMode) -> Result<(), RogError> { - self.platform.set_gpu_mux_mode(mode.to_mux())?; + self.platform.set_gpu_mux_mode(mode.to_mux_attr())?; // self.update_initramfs(enable)?; if mode == GpuMode::Discrete { info!("Set system-level graphics mode: Dedicated Nvidia"); diff --git a/rog-aura/src/sequencer/effects.rs b/rog-aura/src/sequencer/effects.rs index a3b83f75..74bfde2a 100644 --- a/rog-aura/src/sequencer/effects.rs +++ b/rog-aura/src/sequencer/effects.rs @@ -142,11 +142,7 @@ impl EffectState for Breathe { *use_colour1 = !*use_colour1; } - let colour = if !*use_colour1 { - colour2 - } else { - colour1 - }; + let colour = if !*use_colour1 { colour2 } else { colour1 }; let r1_scale = colour.0 / speed / 2; let g1_scale = colour.1 / speed / 2; diff --git a/rog-platform/src/macros.rs b/rog-platform/src/macros.rs index 675430c6..386402e9 100644 --- a/rog-platform/src/macros.rs +++ b/rog-platform/src/macros.rs @@ -85,6 +85,7 @@ macro_rules! get_attr_u8 { }; } +/// Most attributes expect `u8` as a char, so `1` should be written as `b'1'`. #[macro_export] macro_rules! set_attr_u8 { ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index a0715c42..32eb1070 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -76,25 +76,26 @@ pub enum GpuMode { } impl GpuMode { - pub fn to_mux(&self) -> u8 { + /// For writing to `gpu_mux_mode` attribute + pub fn to_mux_attr(&self) -> u8 { if *self == Self::Discrete { - return 0; + return b'0'; } - 1 + b'1' } - pub fn to_dgpu(&self) -> u8 { + pub fn to_dgpu_attr(&self) -> u8 { if *self == Self::Integrated { - return 1; + return b'1'; } - 0 + b'0' } - pub fn to_egpu(&self) -> u8 { + pub fn to_egpu_attr(&self) -> u8 { if *self == Self::Egpu { - return 1; + return b'1'; } - 0 + b'0' } pub fn from_mux(num: u8) -> Self {