Minor fixes to attr writes

This commit is contained in:
Luke D. Jones
2022-10-01 14:57:25 +13:00
parent 600d0ae3d9
commit e938f1f9ec
6 changed files with 19 additions and 28 deletions

View File

@@ -31,15 +31,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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 {
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);

View File

@@ -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"
);
}

View File

@@ -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");

View File

@@ -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;

View File

@@ -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) => {

View File

@@ -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 {