Clippy run

This commit is contained in:
Luke D. Jones
2022-09-30 15:10:56 +13:00
parent 8569edf684
commit 600d0ae3d9
39 changed files with 252 additions and 251 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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(())