mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Clippy run
This commit is contained in:
@@ -9,7 +9,9 @@ stages:
|
||||
|
||||
test:
|
||||
script:
|
||||
- cargo check #+nightly check --features "clippy"
|
||||
- rustup component add clippy
|
||||
- cargo check
|
||||
- cargo clippy
|
||||
- cargo test
|
||||
|
||||
build:
|
||||
|
||||
34
Cargo.lock
generated
34
Cargo.lock
generated
@@ -86,7 +86,7 @@ dependencies = [
|
||||
"rog_profiles",
|
||||
"serde_json",
|
||||
"smol",
|
||||
"zbus 3.1.0",
|
||||
"zbus 3.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -584,7 +584,7 @@ dependencies = [
|
||||
"sysfs-class",
|
||||
"tokio",
|
||||
"toml",
|
||||
"zbus 3.1.0",
|
||||
"zbus 3.2.0",
|
||||
"zvariant",
|
||||
]
|
||||
|
||||
@@ -601,7 +601,7 @@ dependencies = [
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"smol",
|
||||
"zbus 3.1.0",
|
||||
"zbus 3.2.0",
|
||||
"zvariant",
|
||||
"zvariant_derive",
|
||||
]
|
||||
@@ -1394,7 +1394,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c2bd5667a34b046e66f21ac2c016b1f4b41318423f9282b4e04f755ad947817"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"zbus 3.1.0",
|
||||
"zbus 3.2.0",
|
||||
"zvariant",
|
||||
]
|
||||
|
||||
@@ -2032,7 +2032,7 @@ dependencies = [
|
||||
"smol",
|
||||
"tempfile",
|
||||
"toml",
|
||||
"zbus 3.1.0",
|
||||
"zbus 3.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2047,7 +2047,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"sysfs-class",
|
||||
"zbus 3.1.0",
|
||||
"zbus 3.2.0",
|
||||
"zvariant",
|
||||
]
|
||||
|
||||
@@ -2070,8 +2070,8 @@ dependencies = [
|
||||
"rog_aura",
|
||||
"rog_platform",
|
||||
"rog_profiles",
|
||||
"zbus 3.1.0",
|
||||
"zbus_macros 2.3.2",
|
||||
"zbus 3.2.0",
|
||||
"zbus_macros 3.2.0",
|
||||
"zvariant",
|
||||
]
|
||||
|
||||
@@ -3148,9 +3148,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zbus"
|
||||
version = "3.1.0"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d37e0d34b881934b987b72a91fdc1daba9ebc90c1f91b7944c680991c4443fc6"
|
||||
checksum = "be2db10dd0354816a3615c72deff837f983d5c8ad9a0312727d0f89a5a9e9145"
|
||||
dependencies = [
|
||||
"async-broadcast",
|
||||
"async-channel",
|
||||
@@ -3180,7 +3180,7 @@ dependencies = [
|
||||
"tracing",
|
||||
"uds_windows",
|
||||
"winapi",
|
||||
"zbus_macros 3.1.0",
|
||||
"zbus_macros 3.2.0",
|
||||
"zbus_names",
|
||||
"zvariant",
|
||||
]
|
||||
@@ -3200,9 +3200,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zbus_macros"
|
||||
version = "3.1.0"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba7905f7c665ea41828bd69112902daa131191a85131fef0f60f7cc3bc2fbec4"
|
||||
checksum = "7d03f1a5fb482cc0d97f3d3de9fe2e942f436a635a5fb6c12c9f03f21eb03075"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -3224,9 +3224,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zvariant"
|
||||
version = "3.6.0"
|
||||
version = "3.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bd68e4e6432ef19df47d7e90e2e72b5e7e3d778e0ae3baddf12b951265cc758"
|
||||
checksum = "a7b1e052202eb9cc010ad11f556edc81508e1dd08e215188c236c81cd169d83d"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"enumflags2",
|
||||
@@ -3238,9 +3238,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zvariant_derive"
|
||||
version = "3.6.0"
|
||||
version = "3.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08e977eaa3af652f63d479ce50d924254ad76722a6289ec1a1eac3231ca30430"
|
||||
checksum = "63331f3cf9f98b3bfbc1410ef55ec07f966beea5c0c8797c7003511c0642a2aa"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
|
||||
@@ -11,8 +11,8 @@ concat-idents = "1.1.3"
|
||||
dirs = "^4.0"
|
||||
smol = "^1.2"
|
||||
|
||||
zbus = "^3.1.0"
|
||||
zbus_macros = "^2.0"
|
||||
zbus = "^3.2"
|
||||
zbus_macros = "^3.2"
|
||||
zvariant = "^3.2"
|
||||
zvariant_derive = "^3.2"
|
||||
logind-zbus = { version = "^3.0" } #, default-features = false, features = ["non_blocking"] }
|
||||
|
||||
5
Makefile
5
Makefile
@@ -114,5 +114,10 @@ ifeq ($(VENDORED),1)
|
||||
tar pxf vendor_asusctl_$(VERSION).tar.xz
|
||||
endif
|
||||
cargo build $(ARGS)
|
||||
strip -s ./target/release/$(BIN_C)
|
||||
strip -s ./target/release/$(BIN_D)
|
||||
strip -s ./target/release/$(BIN_U)
|
||||
strip -s ./target/release/$(BIN_N)
|
||||
strip -s ./target/release/$(BIN_ROG)
|
||||
|
||||
.PHONY: all clean distclean install uninstall update build
|
||||
|
||||
@@ -54,7 +54,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
p.for_each(|e| {
|
||||
if let Ok(out) = e.args() {
|
||||
if let Ok(ref mut lock) = x.try_lock() {
|
||||
notify!(do_post_sound_notif, lock, &out.on());
|
||||
notify!(do_post_sound_notif, lock, out.on());
|
||||
}
|
||||
}
|
||||
future::ready(())
|
||||
|
||||
@@ -29,23 +29,22 @@ mod profiles_cli;
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<String> = args().skip(1).collect();
|
||||
|
||||
let parsed: CliStart;
|
||||
let missing_argument_k = gumdrop::Error::missing_argument(Opt::Short('k'));
|
||||
match CliStart::parse_args_default(&args) {
|
||||
let parsed = match CliStart::parse_args_default(&args) {
|
||||
Ok(p) => {
|
||||
parsed = p;
|
||||
p
|
||||
}
|
||||
Err(err) if err.to_string() == missing_argument_k.to_string() => {
|
||||
parsed = CliStart {
|
||||
CliStart {
|
||||
kbd_bright: Some(LedBrightness::new(None)),
|
||||
..Default::default()
|
||||
};
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("source {}", err);
|
||||
std::process::exit(2);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let (dbus, _) = RogDbusClientBlocking::new()
|
||||
.map_err(|e| {
|
||||
@@ -376,7 +375,7 @@ fn handle_anime(
|
||||
}
|
||||
|
||||
fn verify_brightness(brightness: f32) {
|
||||
if brightness < 0.0 || brightness > 1.0 {
|
||||
if !(0.0..=1.0).contains(&brightness) {
|
||||
println!(
|
||||
"Image and global brightness must be between 0.0 and 1.0 (inclusive), was {}",
|
||||
brightness
|
||||
@@ -474,7 +473,7 @@ fn handle_led_power1(
|
||||
}
|
||||
|
||||
println!("These options are for keyboards of product ID 0x1866 or TUF only");
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_led_power_1_do_1866(
|
||||
|
||||
@@ -86,7 +86,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.map_err(|e| {
|
||||
println!("{BOARD_NAME}, {e}");
|
||||
})
|
||||
.unwrap_or(KeyLayout::ga401_layout());
|
||||
.unwrap_or_else(|_| KeyLayout::ga401_layout());
|
||||
|
||||
executor
|
||||
.spawn(async move {
|
||||
|
||||
@@ -30,7 +30,7 @@ pub trait ConfigLoadSave<T: DeserializeOwned + serde::Serialize> {
|
||||
if !path.exists() {
|
||||
create_dir(path.clone())?;
|
||||
}
|
||||
let name = self.name().clone();
|
||||
let name = self.name();
|
||||
path.push(name + ".cfg");
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
@@ -230,7 +230,7 @@ impl Default for UserAuraConfig {
|
||||
80,
|
||||
40,
|
||||
));
|
||||
seq.push(key.clone());
|
||||
seq.push(key);
|
||||
|
||||
Self {
|
||||
name: "default".to_string(),
|
||||
|
||||
@@ -130,7 +130,7 @@ impl CtrlAnime {
|
||||
.ok();
|
||||
false // Don't exit yet
|
||||
})
|
||||
.map(|r| Ok(r))
|
||||
.map(Ok)
|
||||
.unwrap_or_else(|| {
|
||||
warn!("rog_anime::run_animation:callback failed");
|
||||
Err(AnimeError::NoFrames)
|
||||
|
||||
@@ -123,14 +123,14 @@ impl CtrlAnimeZbus {
|
||||
#[dbus_interface(property)]
|
||||
async fn awake_enabled(&self) -> bool {
|
||||
let lock = self.0.lock().await;
|
||||
return lock.config.awake_enabled;
|
||||
lock.config.awake_enabled
|
||||
}
|
||||
|
||||
/// Get the status of if factory system-status animations are enabled
|
||||
#[dbus_interface(property)]
|
||||
async fn boot_enabled(&self) -> bool {
|
||||
let lock = self.0.lock().await;
|
||||
return lock.config.boot_anim_enabled;
|
||||
lock.config.boot_anim_enabled
|
||||
}
|
||||
|
||||
/// Notify listeners of the status of AniMe LED power and factory system-status animations
|
||||
@@ -152,10 +152,10 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
||||
|start: bool, lock: MutexGuard<CtrlAnime>, inner: Arc<Mutex<CtrlAnime>>| {
|
||||
if start {
|
||||
info!("CtrlAnimeTask running sleep animation");
|
||||
CtrlAnime::run_thread(inner.clone(), lock.cache.shutdown.clone(), true);
|
||||
CtrlAnime::run_thread(inner, lock.cache.shutdown.clone(), true);
|
||||
} else {
|
||||
info!("CtrlAnimeTask running wake animation");
|
||||
CtrlAnime::run_thread(inner.clone(), lock.cache.wake.clone(), true);
|
||||
CtrlAnime::run_thread(inner, lock.cache.wake.clone(), true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -27,11 +27,11 @@ impl AuraPowerConfig {
|
||||
match control {
|
||||
AuraPowerConfig::AuraDevTuf(_) => [0, 0, 0],
|
||||
AuraPowerConfig::AuraDev1866(c) => {
|
||||
let c: Vec<AuraDev1866> = c.iter().map(|v| *v).collect();
|
||||
let c: Vec<AuraDev1866> = c.iter().copied().collect();
|
||||
AuraDev1866::to_bytes(&c)
|
||||
}
|
||||
AuraPowerConfig::AuraDev19b6(c) => {
|
||||
let c: Vec<AuraDev19b6> = c.iter().map(|v| *v).collect();
|
||||
let c: Vec<AuraDev19b6> = c.iter().copied().collect();
|
||||
AuraDev19b6::to_bytes(&c)
|
||||
}
|
||||
}
|
||||
@@ -95,19 +95,19 @@ impl From<&AuraPowerConfig> for AuraPowerDev {
|
||||
fn from(config: &AuraPowerConfig) -> Self {
|
||||
match config {
|
||||
AuraPowerConfig::AuraDevTuf(d) => AuraPowerDev {
|
||||
tuf: d.iter().map(|o| *o).collect(),
|
||||
tuf: d.iter().copied().collect(),
|
||||
x1866: vec![],
|
||||
x19b6: vec![],
|
||||
},
|
||||
AuraPowerConfig::AuraDev1866(d) => AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: d.iter().map(|o| *o).collect(),
|
||||
x1866: d.iter().copied().collect(),
|
||||
x19b6: vec![],
|
||||
},
|
||||
AuraPowerConfig::AuraDev19b6(d) => AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: vec![],
|
||||
x19b6: d.iter().map(|o| *o).collect(),
|
||||
x19b6: d.iter().copied().collect(),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ impl Default for AuraConfig {
|
||||
fn default() -> Self {
|
||||
let mut prod_id = AuraDevice::Unknown;
|
||||
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
||||
if let Ok(_) = HidRaw::new(prod) {
|
||||
if HidRaw::new(prod).is_ok() {
|
||||
prod_id = AuraDevice::from(*prod);
|
||||
break;
|
||||
}
|
||||
@@ -335,26 +335,34 @@ mod tests {
|
||||
fn set_multizone_4key_config() {
|
||||
let mut config = AuraConfig::default();
|
||||
|
||||
let mut effect = AuraEffect::default();
|
||||
effect.colour1 = Colour(0xff, 0x00, 0xff);
|
||||
effect.zone = AuraZone::Key1;
|
||||
let effect = AuraEffect {
|
||||
colour1: Colour(0xff, 0x00, 0xff),
|
||||
zone: AuraZone::Key1,
|
||||
..Default::default()
|
||||
};
|
||||
config.set_builtin(effect);
|
||||
|
||||
assert!(config.multizone.is_some());
|
||||
|
||||
let mut effect = AuraEffect::default();
|
||||
effect.colour1 = Colour(0x00, 0xff, 0xff);
|
||||
effect.zone = AuraZone::Key2;
|
||||
let effect = AuraEffect {
|
||||
colour1: Colour(0x00, 0xff, 0xff),
|
||||
zone: AuraZone::Key2,
|
||||
..Default::default()
|
||||
};
|
||||
config.set_builtin(effect);
|
||||
|
||||
let mut effect = AuraEffect::default();
|
||||
effect.colour1 = Colour(0xff, 0xff, 0x00);
|
||||
effect.zone = AuraZone::Key3;
|
||||
let effect = AuraEffect {
|
||||
colour1: Colour(0xff, 0xff, 0x00),
|
||||
zone: AuraZone::Key3,
|
||||
..Default::default()
|
||||
};
|
||||
config.set_builtin(effect);
|
||||
|
||||
let mut effect = AuraEffect::default();
|
||||
effect.colour1 = Colour(0x00, 0xff, 0x00);
|
||||
effect.zone = AuraZone::Key4;
|
||||
let effect = AuraEffect {
|
||||
colour1: Colour(0x00, 0xff, 0x00),
|
||||
zone: AuraZone::Key4,
|
||||
..Default::default()
|
||||
};
|
||||
let effect_clone = effect.clone();
|
||||
config.set_builtin(effect);
|
||||
// This should replace existing
|
||||
@@ -373,25 +381,33 @@ mod tests {
|
||||
fn set_multizone_multimode_config() {
|
||||
let mut config = AuraConfig::default();
|
||||
|
||||
let mut effect = AuraEffect::default();
|
||||
effect.zone = AuraZone::Key1;
|
||||
let effect = AuraEffect {
|
||||
zone: AuraZone::Key1,
|
||||
..Default::default()
|
||||
};
|
||||
config.set_builtin(effect);
|
||||
|
||||
assert!(config.multizone.is_some());
|
||||
|
||||
let mut effect = AuraEffect::default();
|
||||
effect.zone = AuraZone::Key2;
|
||||
effect.mode = AuraModeNum::Breathe;
|
||||
let effect = AuraEffect {
|
||||
zone: AuraZone::Key2,
|
||||
mode: AuraModeNum::Breathe,
|
||||
..Default::default()
|
||||
};
|
||||
config.set_builtin(effect);
|
||||
|
||||
let mut effect = AuraEffect::default();
|
||||
effect.zone = AuraZone::Key3;
|
||||
effect.mode = AuraModeNum::Comet;
|
||||
let effect = AuraEffect {
|
||||
zone: AuraZone::Key3,
|
||||
mode: AuraModeNum::Comet,
|
||||
..Default::default()
|
||||
};
|
||||
config.set_builtin(effect);
|
||||
|
||||
let mut effect = AuraEffect::default();
|
||||
effect.zone = AuraZone::Key4;
|
||||
effect.mode = AuraModeNum::Pulse;
|
||||
let effect = AuraEffect {
|
||||
zone: AuraZone::Key4,
|
||||
mode: AuraModeNum::Pulse,
|
||||
..Default::default()
|
||||
};
|
||||
config.set_builtin(effect);
|
||||
|
||||
let res = config.multizone.unwrap();
|
||||
|
||||
@@ -27,7 +27,7 @@ impl GetSupported for CtrlKbdLed {
|
||||
|
||||
let mut prod_id = AuraDevice::Unknown;
|
||||
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
||||
if let Ok(_) = HidRaw::new(prod) {
|
||||
if HidRaw::new(prod).is_ok() {
|
||||
prod_id = AuraDevice::from(*prod);
|
||||
break;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ impl GetSupported for CtrlKbdLed {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd)]
|
||||
pub enum LEDNode {
|
||||
KbdLed(KeyboardLed),
|
||||
Rog(HidRaw),
|
||||
@@ -121,13 +121,13 @@ impl CtrlKbdLed {
|
||||
pub(super) fn get_brightness(&self) -> Result<u8, RogError> {
|
||||
self.kd_brightness
|
||||
.get_brightness()
|
||||
.map_err(|e| RogError::Platform(e))
|
||||
.map_err(RogError::Platform)
|
||||
}
|
||||
|
||||
pub(super) fn set_brightness(&self, brightness: LedBrightness) -> Result<(), RogError> {
|
||||
self.kd_brightness
|
||||
.set_brightness(brightness as u8)
|
||||
.map_err(|e| RogError::Platform(e))
|
||||
.map_err(RogError::Platform)
|
||||
}
|
||||
|
||||
pub fn next_brightness(&mut self) -> Result<(), RogError> {
|
||||
@@ -176,10 +176,9 @@ impl CtrlKbdLed {
|
||||
/// On success the aura config file is read to refresh cached values, then the effect is
|
||||
/// stored and config written to disk.
|
||||
pub(crate) fn set_effect(&mut self, effect: AuraEffect) -> Result<(), RogError> {
|
||||
if !self.supported_modes.standard.contains(&effect.mode) {
|
||||
return Err(RogError::AuraEffectNotSupported);
|
||||
} else if effect.zone != AuraZone::None
|
||||
&& !self.supported_modes.multizone.contains(&effect.zone)
|
||||
if !self.supported_modes.standard.contains(&effect.mode)
|
||||
|| effect.zone != AuraZone::None
|
||||
&& !self.supported_modes.multizone.contains(&effect.zone)
|
||||
{
|
||||
return Err(RogError::AuraEffectNotSupported);
|
||||
}
|
||||
@@ -387,9 +386,11 @@ mod tests {
|
||||
config,
|
||||
};
|
||||
|
||||
let mut effect = AuraEffect::default();
|
||||
effect.colour1 = Colour(0xff, 0x00, 0xff);
|
||||
effect.zone = AuraZone::None;
|
||||
let mut effect = AuraEffect {
|
||||
colour1: Colour(0xff, 0x00, 0xff),
|
||||
zone: AuraZone::None,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// This error comes from write_bytes because we don't have a keyboard node stored
|
||||
assert_eq!(
|
||||
@@ -422,7 +423,7 @@ mod tests {
|
||||
controller.supported_modes.multizone.push(AuraZone::Key2);
|
||||
assert_eq!(
|
||||
controller
|
||||
.set_effect(effect.clone())
|
||||
.set_effect(effect)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"No supported Aura keyboard"
|
||||
|
||||
@@ -26,7 +26,7 @@ impl CtrlKbdLedZbus {
|
||||
lock.config.read();
|
||||
lock.config.brightness = (bright as u32).into();
|
||||
lock.config.write();
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,19 +192,19 @@ impl CtrlKbdLedZbus {
|
||||
// #[dbus_interface(property)]
|
||||
async fn leds_enabled(&self) -> AuraPowerDev {
|
||||
let ctrl = self.0.lock().await;
|
||||
return AuraPowerDev::from(&ctrl.config.enabled);
|
||||
AuraPowerDev::from(&ctrl.config.enabled)
|
||||
}
|
||||
|
||||
/// Return the current mode data
|
||||
async fn led_mode(&self) -> AuraModeNum {
|
||||
let ctrl = self.0.lock().await;
|
||||
return ctrl.config.current_mode;
|
||||
ctrl.config.current_mode
|
||||
}
|
||||
|
||||
/// Return a list of available modes
|
||||
async fn led_modes(&self) -> BTreeMap<AuraModeNum, AuraEffect> {
|
||||
let ctrl = self.0.lock().await;
|
||||
return ctrl.config.builtins.clone();
|
||||
ctrl.config.builtins.clone()
|
||||
}
|
||||
|
||||
async fn per_key_raw(&self, data: PerKeyRaw) -> zbus::fdo::Result<()> {
|
||||
|
||||
@@ -202,21 +202,16 @@ impl CtrlPlatform {
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
overdrive: bool,
|
||||
) {
|
||||
if self
|
||||
.platform
|
||||
.set_panel_od(overdrive)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_panel_overdrive {}", err);
|
||||
err
|
||||
})
|
||||
.is_ok()
|
||||
{
|
||||
if let Some(mut lock) = self.config.try_lock() {
|
||||
lock.panel_od = overdrive;
|
||||
lock.write();
|
||||
match self.platform.set_panel_od(overdrive) {
|
||||
Ok(_) => {
|
||||
if let Some(mut lock) = self.config.try_lock() {
|
||||
lock.panel_od = overdrive;
|
||||
lock.write();
|
||||
}
|
||||
Self::notify_panel_od(&ctxt, overdrive).await.ok();
|
||||
}
|
||||
Self::notify_panel_od(&ctxt, overdrive).await.ok();
|
||||
}
|
||||
Err(err) => warn!("CtrlRogBios: set_panel_overdrive {}", err),
|
||||
};
|
||||
}
|
||||
|
||||
/// Get the `panel_od` value from platform. Updates the stored value in internal config also.
|
||||
@@ -245,17 +240,12 @@ impl CtrlPlatform {
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
disable: bool,
|
||||
) {
|
||||
if self
|
||||
.platform
|
||||
.set_dgpu_disable(disable)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_dgpu_disable {}", err);
|
||||
err
|
||||
})
|
||||
.is_ok()
|
||||
{
|
||||
Self::notify_dgpu_disable(&ctxt, disable).await.ok();
|
||||
}
|
||||
match self.platform.set_dgpu_disable(disable) {
|
||||
Ok(_) => {
|
||||
Self::notify_dgpu_disable(&ctxt, disable).await.ok();
|
||||
}
|
||||
Err(err) => warn!("CtrlRogBios: set_dgpu_disable {}", err),
|
||||
};
|
||||
}
|
||||
|
||||
fn dgpu_disable(&self) -> bool {
|
||||
@@ -280,17 +270,12 @@ impl CtrlPlatform {
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
enable: bool,
|
||||
) {
|
||||
if self
|
||||
.platform
|
||||
.set_egpu_enable(enable)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_egpu_enable {}", err);
|
||||
err
|
||||
})
|
||||
.is_ok()
|
||||
{
|
||||
Self::notify_egpu_enable(&ctxt, enable).await.ok();
|
||||
}
|
||||
match self.platform.set_egpu_enable(enable) {
|
||||
Ok(_) => {
|
||||
Self::notify_egpu_enable(&ctxt, enable).await.ok();
|
||||
}
|
||||
Err(err) => warn!("CtrlRogBios: set_egpu_enable {}", err),
|
||||
};
|
||||
}
|
||||
|
||||
fn egpu_enable(&self) -> bool {
|
||||
|
||||
@@ -87,7 +87,7 @@ impl ProfileZbus {
|
||||
if let Some(curves) = &ctrl.config.fan_curves {
|
||||
return Ok(curves.get_enabled_curve_profiles().to_vec());
|
||||
}
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
Err(Error::Failed(UNSUPPORTED_MSG.to_string()))
|
||||
}
|
||||
|
||||
/// Set a profile fan curve enabled status. Will also activate a fan curve if in the
|
||||
@@ -99,7 +99,7 @@ impl ProfileZbus {
|
||||
) -> zbus::fdo::Result<()> {
|
||||
let mut ctrl = self.0.lock().await;
|
||||
ctrl.config.read();
|
||||
return if let Some(curves) = &mut ctrl.config.fan_curves {
|
||||
if let Some(curves) = &mut ctrl.config.fan_curves {
|
||||
curves.set_profile_curve_enabled(profile, enabled);
|
||||
|
||||
ctrl.write_profile_curve_to_platform()
|
||||
@@ -110,7 +110,7 @@ impl ProfileZbus {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::Failed(UNSUPPORTED_MSG.to_string()))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the fan-curve data for the currently active Profile
|
||||
@@ -121,7 +121,7 @@ impl ProfileZbus {
|
||||
let curve = curves.get_fan_curves_for(profile);
|
||||
return Ok(curve.clone());
|
||||
}
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
Err(Error::Failed(UNSUPPORTED_MSG.to_string()))
|
||||
}
|
||||
|
||||
/// Set the fan curve for the specified profile.
|
||||
|
||||
@@ -151,7 +151,7 @@ where
|
||||
.unwrap_or_else(|err| warn!("Controller error: {}", err));
|
||||
zbus.add_to_server(connection).await;
|
||||
|
||||
task.create_tasks(CtrlKbdLedZbus::signal_context(&connection)?)
|
||||
task.create_tasks(CtrlKbdLedZbus::signal_context(connection)?)
|
||||
.await
|
||||
.ok();
|
||||
Ok(())
|
||||
|
||||
@@ -29,7 +29,7 @@ const USB_PREFIX2: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02];
|
||||
const USB_PREFIX3: [u8; 7] = [0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02];
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, PartialEq, Copy, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||
pub struct AnimePowerStates {
|
||||
pub brightness: u8,
|
||||
pub enabled: bool,
|
||||
|
||||
@@ -131,14 +131,14 @@ impl AnimeDiagonal {
|
||||
#[inline]
|
||||
pub fn into_data_buffer(&self, anime_type: AnimeType) -> Result<AnimeDataBuffer> {
|
||||
match anime_type {
|
||||
AnimeType::GA401 => self.into_ga401_packets(),
|
||||
AnimeType::GA402 => self.into_ga402_packets(),
|
||||
AnimeType::GA401 => self.to_ga401_packets(),
|
||||
AnimeType::GA402 => self.to_ga402_packets(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Do conversion from the nested Vec in AnimeMatrix to the two required
|
||||
/// packets suitable for sending over USB
|
||||
fn into_ga401_packets(&self) -> Result<AnimeDataBuffer> {
|
||||
fn to_ga401_packets(&self) -> Result<AnimeDataBuffer> {
|
||||
let mut buf = vec![0u8; AnimeType::GA401.data_length()];
|
||||
|
||||
buf[1..=32].copy_from_slice(&self.get_row(0, 3, 32));
|
||||
@@ -200,12 +200,12 @@ impl AnimeDiagonal {
|
||||
AnimeDataBuffer::from_vec(crate::AnimeType::GA401, buf)
|
||||
}
|
||||
|
||||
fn into_ga402_packets(&self) -> Result<AnimeDataBuffer> {
|
||||
fn to_ga402_packets(&self) -> Result<AnimeDataBuffer> {
|
||||
let mut buf = vec![0u8; AnimeType::GA402.data_length()];
|
||||
let mut start_index: usize = 0;
|
||||
|
||||
fn copy_slice(
|
||||
buf: &mut Vec<u8>,
|
||||
buf: &mut [u8],
|
||||
anime: &AnimeDiagonal,
|
||||
x: usize,
|
||||
y: usize,
|
||||
|
||||
@@ -88,7 +88,7 @@ impl AnimeImage {
|
||||
width: u32,
|
||||
anime_type: AnimeType,
|
||||
) -> Result<Self> {
|
||||
if bright < 0.0 || bright > 1.0 {
|
||||
if !(0.0..=1.0).contains(&bright) {
|
||||
return Err(AnimeError::InvalidBrightness(bright));
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ pub fn get_anime_type() -> Result<AnimeType, AnimeError> {
|
||||
let dmi = sysfs_class::DmiId::default();
|
||||
let board_name = dmi.board_name()?;
|
||||
|
||||
if board_name.contains("GA401I") {
|
||||
return Ok(AnimeType::GA401);
|
||||
} else if board_name.contains("GA401Q") {
|
||||
if board_name.contains("GA401I") || board_name.contains("GA401Q") {
|
||||
return Ok(AnimeType::GA401);
|
||||
} else if board_name.contains("GA402R") {
|
||||
return Ok(AnimeType::GA402);
|
||||
|
||||
@@ -12,7 +12,7 @@ use zvariant::Type;
|
||||
use crate::{error::Error, LED_MSG_LEN};
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub enum LedBrightness {
|
||||
Off,
|
||||
Low,
|
||||
@@ -33,7 +33,7 @@ impl From<u32> for LedBrightness {
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Copy, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Copy, Deserialize, Serialize)]
|
||||
pub struct Colour(pub u8, pub u8, pub u8);
|
||||
|
||||
impl Default for Colour {
|
||||
@@ -85,7 +85,7 @@ impl From<Colour> for [u8; 3] {
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub enum Speed {
|
||||
Low = 0xe1,
|
||||
Med = 0xeb,
|
||||
@@ -123,7 +123,7 @@ impl From<Speed> for u8 {
|
||||
///
|
||||
/// Enum corresponds to the required integer value
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub enum Direction {
|
||||
Right,
|
||||
Left,
|
||||
@@ -251,7 +251,7 @@ impl From<u8> for AuraModeNum {
|
||||
|
||||
/// Base effects have no zoning, while multizone is 1-4
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub enum AuraZone {
|
||||
/// Used if keyboard has no zones, or if setting all
|
||||
#[default]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Copy, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
|
||||
pub enum Key {
|
||||
VolUp,
|
||||
VolDown,
|
||||
@@ -235,51 +235,44 @@ impl KeyShape {
|
||||
/// A blank is used to space keys out in GUI's and can be used or ignored
|
||||
/// depednign on the per-key effect
|
||||
pub const fn is_blank(&self) -> bool {
|
||||
match self {
|
||||
matches!(
|
||||
self,
|
||||
Self::NormalBlank
|
||||
| Self::FuncBlank
|
||||
| Self::ArrowBlank
|
||||
| Self::ArrowSplitBlank
|
||||
| Self::ArrowRegularBlank => true,
|
||||
_ => false,
|
||||
}
|
||||
| Self::FuncBlank
|
||||
| Self::ArrowBlank
|
||||
| Self::ArrowSplitBlank
|
||||
| Self::ArrowRegularBlank
|
||||
)
|
||||
}
|
||||
|
||||
/// A spacer is used to space keys out in GUI's, but ignored in per-key effects
|
||||
pub const fn is_spacer(&self) -> bool {
|
||||
match self {
|
||||
matches!(
|
||||
self,
|
||||
Self::FuncSpacer
|
||||
| Self::NormalSpacer
|
||||
| Self::ArrowSpacer
|
||||
| Self::ArrowSplitSpacer
|
||||
| Self::ArrowRegularSpacer => true,
|
||||
_ => false,
|
||||
}
|
||||
| Self::NormalSpacer
|
||||
| Self::ArrowSpacer
|
||||
| Self::ArrowSplitSpacer
|
||||
| Self::ArrowRegularSpacer
|
||||
)
|
||||
}
|
||||
|
||||
/// All keys with a postfix of some number
|
||||
pub const fn is_group(&self) -> bool {
|
||||
match self {
|
||||
Self::LShift3 | Self::RShift3 => true,
|
||||
Self::Return3 | Self::Space5 | Self::Backspace3 => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
self,
|
||||
Self::LShift3 | Self::RShift3 | Self::Return3 | Self::Space5 | Self::Backspace3
|
||||
)
|
||||
}
|
||||
|
||||
/// Mostly intended as a helper for signalling when to draw a
|
||||
/// split/compact arrow cluster
|
||||
pub const fn is_arrow_cluster(&self) -> bool {
|
||||
match self {
|
||||
Self::Arrow | Self::ArrowBlank | Self::ArrowSpacer => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Self::Arrow | Self::ArrowBlank | Self::ArrowSpacer)
|
||||
}
|
||||
|
||||
pub const fn is_arrow_splits(&self) -> bool {
|
||||
match self {
|
||||
Self::ArrowSplit | Self::ArrowSplitBlank | Self::ArrowSplitSpacer => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Self::Arrow | Self::ArrowBlank | Self::ArrowSpacer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ impl KeyLayout {
|
||||
let mut buf = String::new();
|
||||
let read_len = file.read_to_string(&mut buf)?;
|
||||
if read_len == 0 {
|
||||
return Err(Error::Io(std::io::ErrorKind::InvalidData.into()));
|
||||
Err(Error::Io(std::io::ErrorKind::InvalidData.into()))
|
||||
} else {
|
||||
return Ok(toml::from_str::<Self>(&buf)?);
|
||||
Ok(toml::from_str::<Self>(&buf)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,16 +138,15 @@ impl EffectState for Breathe {
|
||||
|
||||
let speed = 4 - <u8>::from(*speed);
|
||||
|
||||
let colour: &mut Colour;
|
||||
if *colour_actual == Colour(0, 0, 0) {
|
||||
*use_colour1 = !*use_colour1;
|
||||
}
|
||||
|
||||
if !*use_colour1 {
|
||||
colour = colour2;
|
||||
let colour = if !*use_colour1 {
|
||||
colour2
|
||||
} else {
|
||||
colour = colour1;
|
||||
}
|
||||
colour1
|
||||
};
|
||||
|
||||
let r1_scale = colour.0 / speed / 2;
|
||||
let g1_scale = colour.1 / speed / 2;
|
||||
|
||||
@@ -21,7 +21,7 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Clone, Debug, PartialEq, PartialOrd, Serialize, Deserialize, Default)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Serialize, Deserialize, Default)]
|
||||
pub enum AuraDevice {
|
||||
Tuf,
|
||||
X1854,
|
||||
@@ -127,7 +127,7 @@ impl BitOr<AuraDev1866> for AuraDev1866 {
|
||||
type Output = u32;
|
||||
|
||||
fn bitor(self, rhs: AuraDev1866) -> Self::Output {
|
||||
return self as u32 | rhs as u32;
|
||||
self as u32 | rhs as u32
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ impl BitAnd<AuraDev1866> for AuraDev1866 {
|
||||
type Output = u32;
|
||||
|
||||
fn bitand(self, rhs: AuraDev1866) -> Self::Output {
|
||||
return self as u32 & rhs as u32;
|
||||
self as u32 & rhs as u32
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,14 +178,14 @@ pub enum AuraDev19b6 {
|
||||
SleepKeyb = 1 << 5,
|
||||
ShutdownLogo = 1 << 6,
|
||||
ShutdownKeyb = 1 << 7,
|
||||
BootBar = 1 << 7 + 2,
|
||||
AwakeBar = 1 << 7 + 3,
|
||||
SleepBar = 1 << 7 + 4,
|
||||
ShutdownBar = 1 << 7 + 5,
|
||||
BootLid = 1 << 15 + 1,
|
||||
AwakeLid = 1 << 15 + 2,
|
||||
SleepLid = 1 << 15 + 3,
|
||||
ShutdownLid = 1 << 15 + 4,
|
||||
BootBar = 1 << (7 + 2),
|
||||
AwakeBar = 1 << (7 + 3),
|
||||
SleepBar = 1 << (7 + 4),
|
||||
ShutdownBar = 1 << (7 + 5),
|
||||
BootLid = 1 << (15 + 1),
|
||||
AwakeLid = 1 << (15 + 2),
|
||||
SleepLid = 1 << (15 + 3),
|
||||
ShutdownLid = 1 << (15 + 4),
|
||||
}
|
||||
|
||||
impl From<AuraDev19b6> for u32 {
|
||||
@@ -216,7 +216,7 @@ impl BitOr<AuraDev19b6> for AuraDev19b6 {
|
||||
type Output = u16;
|
||||
|
||||
fn bitor(self, rhs: AuraDev19b6) -> Self::Output {
|
||||
return self as u16 | rhs as u16;
|
||||
self as u16 | rhs as u16
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ impl BitAnd<AuraDev19b6> for AuraDev19b6 {
|
||||
type Output = u16;
|
||||
|
||||
fn bitand(self, rhs: AuraDev19b6) -> Self::Output {
|
||||
return self as u16 & rhs as u16;
|
||||
self as u16 & rhs as u16
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ pub fn print_versions() {
|
||||
pub const SHOWING_GUI: u8 = 1;
|
||||
pub const SHOW_GUI: u8 = 2;
|
||||
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub enum Page {
|
||||
System,
|
||||
AuraEffects,
|
||||
|
||||
@@ -72,7 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.map_err(|e| {
|
||||
println!("{BOARD_NAME}, {e}");
|
||||
})
|
||||
.unwrap_or(KeyLayout::ga401_layout());
|
||||
.unwrap_or_else(|_| KeyLayout::ga401_layout());
|
||||
|
||||
// Cheap method to alert to notifications rather than spinning a thread for each
|
||||
// This is quite different when done in a retained mode app
|
||||
|
||||
@@ -114,7 +114,7 @@ pub fn start_notifications(
|
||||
})
|
||||
.detach();
|
||||
|
||||
let bios_notified1 = bios_notified.clone();
|
||||
let bios_notified1 = bios_notified;
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
@@ -181,9 +181,9 @@ pub fn start_notifications(
|
||||
.detach();
|
||||
|
||||
// LED notif
|
||||
let last_notif = last_notification.clone();
|
||||
let last_notif = last_notification;
|
||||
let aura_notif = aura_notified.clone();
|
||||
let notifs_enabled1 = notifs_enabled.clone();
|
||||
let notifs_enabled1 = notifs_enabled;
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
|
||||
@@ -262,6 +262,7 @@ pub struct PageDataStates {
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
impl PageDataStates {
|
||||
pub fn new(
|
||||
keyboard_layout: KeyLayout,
|
||||
|
||||
@@ -73,10 +73,10 @@ fn aura_power1(
|
||||
if ui.toggle_value(&mut keyboard, "Keyboard").changed() {
|
||||
changed = true;
|
||||
}
|
||||
if !supported.keyboard_led.multizone_led_mode.is_empty() {
|
||||
if ui.toggle_value(&mut lightbar, "Lightbar").changed() {
|
||||
changed = true;
|
||||
}
|
||||
if !supported.keyboard_led.multizone_led_mode.is_empty()
|
||||
&& ui.toggle_value(&mut lightbar, "Lightbar").changed()
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
|
||||
@@ -54,40 +54,38 @@ pub fn rog_bios_group(
|
||||
.ok();
|
||||
}
|
||||
|
||||
if supported.rog_bios_ctrl.post_sound {
|
||||
if ui
|
||||
if supported.rog_bios_ctrl.post_sound
|
||||
&& ui
|
||||
.add(egui::Checkbox::new(
|
||||
&mut states.bios.post_sound,
|
||||
"POST sound",
|
||||
))
|
||||
.changed()
|
||||
{
|
||||
dbus.proxies()
|
||||
.rog_bios()
|
||||
.set_post_boot_sound(states.bios.post_sound)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
{
|
||||
dbus.proxies()
|
||||
.rog_bios()
|
||||
.set_post_boot_sound(states.bios.post_sound)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
if supported.rog_bios_ctrl.post_sound {
|
||||
if ui
|
||||
if supported.rog_bios_ctrl.post_sound
|
||||
&& ui
|
||||
.add(egui::Checkbox::new(
|
||||
&mut states.bios.panel_overdrive,
|
||||
"Panel overdrive",
|
||||
))
|
||||
.changed()
|
||||
{
|
||||
dbus.proxies()
|
||||
.rog_bios()
|
||||
.set_panel_od(states.bios.panel_overdrive)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
{
|
||||
dbus.proxies()
|
||||
.rog_bios()
|
||||
.set_panel_od(states.bios.panel_overdrive)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
if supported.rog_bios_ctrl.gpu_mux {
|
||||
|
||||
@@ -4,7 +4,7 @@ use log::{info, warn};
|
||||
|
||||
use crate::error::{PlatformError, Result};
|
||||
|
||||
#[derive(Debug, PartialEq, PartialOrd, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)]
|
||||
pub struct HidRaw(PathBuf);
|
||||
|
||||
impl HidRaw {
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
has_attr, set_attr_u8_array, to_device,
|
||||
};
|
||||
|
||||
#[derive(Debug, Default, PartialEq, PartialOrd, Clone)]
|
||||
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Clone)]
|
||||
pub struct KeyboardLed {
|
||||
path: PathBuf,
|
||||
}
|
||||
@@ -32,10 +32,12 @@ impl KeyboardLed {
|
||||
PlatformError::Udev("match_subsystem failed".into(), err)
|
||||
})?;
|
||||
|
||||
for device in enumerator.scan_devices().map_err(|err| {
|
||||
if let Some(device) = (enumerator.scan_devices().map_err(|err| {
|
||||
warn!("{}", err);
|
||||
PlatformError::Udev("scan_devices failed".into(), err)
|
||||
})? {
|
||||
})?)
|
||||
.next()
|
||||
{
|
||||
info!("Found keyboard LED controls at {:?}", device.sysname());
|
||||
return Ok(Self {
|
||||
path: device.syspath().to_owned(),
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn write_attr_bool(device: &mut Device, attr: &str, value: bool) -> Result<(
|
||||
pub fn read_attr_u8(device: &Device, attr_name: &str) -> Result<u8> {
|
||||
if let Some(value) = device.attribute_value(attr_name) {
|
||||
let tmp = value.to_string_lossy();
|
||||
return Ok(tmp.parse::<u8>().map_err(|_| PlatformError::ParseNum)?);
|
||||
return tmp.parse::<u8>().map_err(|_| PlatformError::ParseNum);
|
||||
}
|
||||
Err(PlatformError::AttrNotFound(attr_name.to_string()))
|
||||
}
|
||||
@@ -67,7 +67,7 @@ pub fn read_attr_u8_array(device: &Device, attr_name: &str) -> Result<Vec<u8>> {
|
||||
let tmp = value.to_string_lossy();
|
||||
let tmp = tmp
|
||||
.split(' ')
|
||||
.map(|v| u8::from_str_radix(v, 10).unwrap_or(0))
|
||||
.map(|v| v.parse::<u8>().unwrap_or(0))
|
||||
.collect();
|
||||
return Ok(tmp);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ mod tests {
|
||||
|
||||
let tmp: Vec<u8> = tmp
|
||||
.split(' ')
|
||||
.map(|v| u8::from_str_radix(v, 10).unwrap_or(0))
|
||||
.map(|v| v.parse::<u8>().unwrap_or(0))
|
||||
.collect();
|
||||
assert_eq!(tmp, &[1, 2, 3, 4, 5]);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ macro_rules! has_attr {
|
||||
$(#[$doc_comment])*
|
||||
pub fn fn_name(&self) -> bool {
|
||||
match to_device(&self.$item) {
|
||||
Ok(p) => crate::has_attr(&p, $attr_name),
|
||||
Ok(p) => $crate::has_attr(&p, $attr_name),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ macro_rules! get_attr_bool {
|
||||
concat_idents::concat_idents!(fn_name = get_, $attr_name {
|
||||
$(#[$doc_comment])*
|
||||
pub fn fn_name(&self) -> Result<bool> {
|
||||
crate::read_attr_bool(&to_device(&self.$item)?, $attr_name)
|
||||
$crate::read_attr_bool(&to_device(&self.$item)?, $attr_name)
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -57,7 +57,7 @@ macro_rules! set_attr_bool {
|
||||
concat_idents::concat_idents!(fn_name = set_, $attr_name {
|
||||
$(#[$doc_comment])*
|
||||
pub fn fn_name(&self, value: bool) -> Result<()> {
|
||||
crate::write_attr_bool(&mut to_device(&self.$item)?, $attr_name, value)
|
||||
$crate::write_attr_bool(&mut to_device(&self.$item)?, $attr_name, value)
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -66,10 +66,10 @@ macro_rules! set_attr_bool {
|
||||
#[macro_export]
|
||||
macro_rules! attr_bool {
|
||||
($attr_name:literal, $item:ident) => {
|
||||
crate::has_attr!($attr_name $item);
|
||||
crate::get_attr_bool!( $attr_name $item);
|
||||
crate::set_attr_bool!($attr_name $item);
|
||||
crate::watch_attr!($attr_name $item);
|
||||
$crate::has_attr!($attr_name $item);
|
||||
$crate::get_attr_bool!( $attr_name $item);
|
||||
$crate::set_attr_bool!($attr_name $item);
|
||||
$crate::watch_attr!($attr_name $item);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ macro_rules! get_attr_u8 {
|
||||
concat_idents::concat_idents!(fn_name = get_, $attr_name {
|
||||
$(#[$doc_comment])*
|
||||
pub fn fn_name(&self) -> Result<u8> {
|
||||
crate::read_attr_u8(&to_device(&self.$item)?, $attr_name)
|
||||
$crate::read_attr_u8(&to_device(&self.$item)?, $attr_name)
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -91,7 +91,7 @@ macro_rules! set_attr_u8 {
|
||||
concat_idents::concat_idents!(fn_name = set_, $attr_name {
|
||||
$(#[$doc_comment])*
|
||||
pub fn fn_name(&self, value: u8) -> Result<()> {
|
||||
crate::write_attr_u8(&mut to_device(&self.$item)?, $attr_name, value)
|
||||
$crate::write_attr_u8(&mut to_device(&self.$item)?, $attr_name, value)
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -100,10 +100,10 @@ macro_rules! set_attr_u8 {
|
||||
#[macro_export]
|
||||
macro_rules! attr_u8 {
|
||||
($attr_name:literal, $item:ident) => {
|
||||
crate::has_attr!($attr_name $item);
|
||||
crate::get_attr_u8!($attr_name $item);
|
||||
crate::set_attr_u8!($attr_name $item);
|
||||
crate::watch_attr!($attr_name $item);
|
||||
$crate::has_attr!($attr_name $item);
|
||||
$crate::get_attr_u8!($attr_name $item);
|
||||
$crate::set_attr_u8!($attr_name $item);
|
||||
$crate::watch_attr!($attr_name $item);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ macro_rules! get_attr_u8_array {
|
||||
concat_idents::concat_idents!(fn_name = get_, $attr_name {
|
||||
$(#[$doc_comment])*
|
||||
pub fn fn_name(&self) -> Result<Vec<u8>> {
|
||||
crate::read_attr_u8_array(&to_device(&self.$item)?, $attr_name)
|
||||
$crate::read_attr_u8_array(&to_device(&self.$item)?, $attr_name)
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -125,7 +125,7 @@ macro_rules! set_attr_u8_array {
|
||||
concat_idents::concat_idents!(fn_name = set_, $attr_name {
|
||||
$(#[$doc_comment])*
|
||||
pub fn fn_name(&self, values: &[u8]) -> Result<()> {
|
||||
crate::write_attr_u8_array(&mut to_device(&self.$item)?, $attr_name, values)
|
||||
$crate::write_attr_u8_array(&mut to_device(&self.$item)?, $attr_name, values)
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -134,9 +134,9 @@ macro_rules! set_attr_u8_array {
|
||||
#[macro_export]
|
||||
macro_rules! attr_u8_array {
|
||||
($attr_name:literal, $item:ident) => {
|
||||
crate::has_attr!($attr_name $item);
|
||||
crate::get_attr_u8_array!($attr_name $item);
|
||||
crate::set_attr_u8_array!($attr_name $item);
|
||||
crate::watch_attr!($attr_name $item);
|
||||
$crate::has_attr!($attr_name $item);
|
||||
$crate::get_attr_u8_array!($attr_name $item);
|
||||
$crate::set_attr_u8_array!($attr_name $item);
|
||||
$crate::watch_attr!($attr_name $item);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::{
|
||||
/// - gpu_mux
|
||||
/// - keyboard_mode, set keyboard RGB mode and speed
|
||||
/// - keyboard_state, set keyboard power states
|
||||
#[derive(Debug, PartialEq, PartialOrd, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)]
|
||||
pub struct AsusPlatform {
|
||||
path: PathBuf,
|
||||
pp_path: PathBuf,
|
||||
@@ -38,10 +38,12 @@ impl AsusPlatform {
|
||||
PlatformError::Udev("match_subsystem failed".into(), err)
|
||||
})?;
|
||||
|
||||
for device in enumerator.scan_devices().map_err(|err| {
|
||||
if let Some(device) = (enumerator.scan_devices().map_err(|err| {
|
||||
warn!("{}", err);
|
||||
PlatformError::Udev("scan_devices failed".into(), err)
|
||||
})? {
|
||||
})?)
|
||||
.next()
|
||||
{
|
||||
info!("Found platform support at {:?}", device.sysname());
|
||||
return Ok(Self {
|
||||
path: device.syspath().to_owned(),
|
||||
@@ -63,7 +65,7 @@ impl AsusPlatform {
|
||||
attr_u8!("platform_profile", pp_path);
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Type, Debug, PartialEq, Clone, Copy)]
|
||||
#[derive(Serialize, Deserialize, Type, Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum GpuMode {
|
||||
Discrete,
|
||||
Optimus,
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::{
|
||||
/// - gpu_mux
|
||||
/// - keyboard_mode, set keyboard RGB mode and speed
|
||||
/// - keyboard_state, set keyboard power states
|
||||
#[derive(Debug, PartialEq, PartialOrd, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)]
|
||||
pub struct AsusPower {
|
||||
mains: PathBuf,
|
||||
battery: PathBuf,
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::time::Duration;
|
||||
|
||||
use crate::error::{PlatformError, Result};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct USBRaw(DeviceHandle<rusb::GlobalContext>);
|
||||
|
||||
impl USBRaw {
|
||||
@@ -43,6 +43,6 @@ impl USBRaw {
|
||||
message,
|
||||
Duration::from_millis(200),
|
||||
)
|
||||
.map_err(|e| PlatformError::USB(e))
|
||||
.map_err(PlatformError::USB)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ impl std::str::FromStr for Profile {
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone, Copy)]
|
||||
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum FanCurvePU {
|
||||
CPU,
|
||||
GPU,
|
||||
|
||||
Reference in New Issue
Block a user