diff --git a/rog-aura/src/layouts/mod.rs b/rog-aura/src/layouts/mod.rs index 893fad82..687931cf 100644 --- a/rog-aura/src/layouts/mod.rs +++ b/rog-aura/src/layouts/mod.rs @@ -1,3 +1,6 @@ +//! A series of pre-defined layouts. These were mostly used to generate an editable +//! config. + /// Hardcoded layout. Was used to generate a toml default pub mod g513; /// Hardcoded layout. Was used to generate a toml default diff --git a/rog-aura/src/per_key_rgb.rs b/rog-aura/src/per_key_rgb.rs index 28ac01ac..2dd3ca6d 100644 --- a/rog-aura/src/per_key_rgb.rs +++ b/rog-aura/src/per_key_rgb.rs @@ -47,7 +47,7 @@ impl KeyColourArray { #[inline] pub fn set(&mut self, key: Key, r: u8, g: u8, b: u8) { - if let Some(c) = self.rgb(key) { + if let Some(c) = self.rgb_for_key(key) { c[0] = r; c[1] = g; c[2] = b; @@ -56,7 +56,7 @@ impl KeyColourArray { /// Indexes in to `KeyColourArray` at the correct row and column /// to set a series of three bytes to the chosen R,G,B values - pub fn rgb(&mut self, key: Key) -> Option<&mut [u8]> { + pub fn rgb_for_key(&mut self, key: Key) -> Option<&mut [u8]> { // Tuples are indexes in to array let (row, col) = match key { Key::VolDown => (0, 15), @@ -223,171 +223,3 @@ impl KeyColourArray { pub trait KeyLayout { fn get_rows(&self) -> &Vec<[Key; 17]>; } - -#[allow(clippy::upper_case_acronyms)] -pub struct GX502Layout(Vec<[Key; 17]>); - -impl KeyLayout for GX502Layout { - fn get_rows(&self) -> &Vec<[Key; 17]> { - &self.0 - } -} - -impl Default for GX502Layout { - fn default() -> Self { - GX502Layout(vec![ - [ - Key::NormalSpacer, - Key::FuncSpacer, - Key::VolDown, - Key::VolUp, - Key::MicMute, - Key::Rog, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - ], - [ - Key::Esc, - Key::NormalBlank, - Key::F1, - Key::F2, - Key::F3, - Key::F4, - Key::NormalBlank, // not sure which key to put here - Key::F5, - Key::F6, - Key::F7, - Key::F8, - Key::NormalBlank, - Key::F9, - Key::F10, - Key::F11, - Key::F12, - Key::Del, - ], - [ - Key::Tilde, - Key::N1, - Key::N2, - Key::N3, - Key::N4, - Key::N5, - Key::N6, - Key::N7, - Key::N8, - Key::N9, - Key::N0, - Key::Hyphen, - Key::Equals, - Key::BkSpc3_1, - Key::BkSpc3_2, - Key::BkSpc3_3, - Key::Home, - ], - [ - Key::Tab, - Key::Q, - Key::W, - Key::E, - Key::R, - Key::T, - Key::Y, - Key::U, - Key::I, - Key::O, - Key::P, - Key::LBracket, - Key::RBracket, - Key::BackSlash, - Key::BackSlash, - Key::BackSlash, - Key::PgUp, - ], - [ - Key::Caps, - Key::A, - Key::S, - Key::D, - Key::F, - Key::G, - Key::H, - Key::J, - Key::K, - Key::L, - Key::SemiColon, - Key::Quote, - Key::Quote, - Key::Return3_1, - Key::Return3_2, - Key::Return3_3, - Key::PgDn, - ], - [ - Key::LShift, - Key::LShift, - Key::Z, - Key::X, - Key::C, - Key::V, - Key::B, - Key::N, - Key::M, - Key::Comma, - Key::Period, - Key::FwdSlash, - Key::FwdSlash, - Key::Rshift3_1, - Key::Rshift3_2, - Key::Rshift3_3, - Key::End, - ], - [ - Key::LCtrl, - Key::LFn, - Key::Meta, - Key::LAlt, - Key::Space5_1, - Key::Space5_2, - Key::Space5_3, - Key::Space5_4, - Key::Space5_5, - Key::RAlt, - Key::PrtSc, - Key::RCtrl, - Key::RCtrl, - Key::Left, - Key::Up, - Key::Right, - Key::RFn, - ], - [ - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::NormalBlank, - Key::Left, - Key::Down, - Key::Right, - Key::NormalBlank, - ], - ]) - } -} diff --git a/rog-platform/src/power.rs b/rog-platform/src/power.rs index c15dbfd4..4b131aea 100644 --- a/rog-platform/src/power.rs +++ b/rog-platform/src/power.rs @@ -23,9 +23,14 @@ pub struct AsusPower { } impl AsusPower { + /// When checking for battery this will look in order: + /// - if attr `manufacturer` contains `asus` + /// - if attr `charge_control_end_threshold` exists and `energy_full_design` >= 50 watt + /// - if syspath end conatins `BAT` + /// - if attr `type` is `battery` (last resort) pub fn new() -> Result { let mut mains = PathBuf::new(); - let mut battery = PathBuf::new(); + let mut battery = None; let mut usb = None; let mut enumerator = udev::Enumerator::new().map_err(|err| { @@ -48,13 +53,45 @@ impl AsusPower { mains = device.syspath().to_path_buf(); } Some("Battery") => { - // This check required due to an instance where another "not" - // battery can be found - if let Some(m) = device.attribute_value("manufacturer") { - // Should always be ASUSTeK, but match on a lowercase part to be sure - if m.to_string_lossy().to_lowercase().contains("asus") { - info!("Found battery power at {:?}", device.sysname()); - battery = device.syspath().to_path_buf(); + // Priortised list of checks + if battery.is_none() { + // This check required due to an instance where another "not" + // battery can be found + if let Some(m) = device.attribute_value("manufacturer") { + // Should always be ASUSTeK, but match on a lowercase part to be sure + if m.to_string_lossy().to_lowercase().contains("asus") { + info!( + "Found battery power at {:?}, matched manufacturer", + device.sysname() + ); + battery = Some(device.syspath().to_path_buf()); + } + } else if device + .attribute_value("charge_control_end_threshold") + .is_some() + { + if let Some(m) = device.attribute_value("energy_full_design") { + if let Ok(num) = m.to_string_lossy().parse::() { + if num >= 50_000_000 { + info!("Found battery power at {:?}, matched charge_control_end_threshold and energy_full_design", device.sysname()); + battery = Some(device.syspath().to_path_buf()); + } + } + } + } else if device.sysname().to_string_lossy().contains("BAT") { + info!( + "Found battery power at {:?}, sysfs path ended with BAT", + device.sysname() + ); + battery = Some(device.syspath().to_path_buf()); + } else if let Some(m) = device.attribute_value("type") { + if m.to_string_lossy().to_lowercase().contains("battery") { + info!( + "Last resort: Found battery power at {:?}", + device.sysname() + ); + battery = Some(device.syspath().to_path_buf()); + } } } } @@ -67,11 +104,17 @@ impl AsusPower { } } - Ok(Self { - mains, - battery, - usb, - }) + if let Some(battery) = battery { + return Ok(Self { + mains, + battery, + usb, + }); + } + + Err(PlatformError::MissingFunction( + "Did not find a battery".to_owned(), + )) } attr_u8!("charge_control_end_threshold", battery);