From 128bc3fce1646f7ddd83345e56dcae4cd27dd280 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Sun, 12 Jan 2025 17:36:10 +1300 Subject: [PATCH] Update readme, slash configs --- README.md | 6 +- asusctl/examples/anime-diag-png.rs | 2 +- asusctl/examples/anime-gif.rs | 13 +- asusctl/examples/anime-png.rs | 4 +- asusctl/examples/anime-spinning.rs | 4 +- asusctl/examples/aura-zoned-breathe.rs | 4 +- asusctl/src/anime_cli.rs | 14 +- asusctl/src/aura_cli.rs | 28 +- asusctl/src/cli_opts.rs | 14 +- asusctl/src/fan_curve_cli.rs | 2 +- asusctl/src/main.rs | 61 ++- asusctl/src/scsi_cli.rs | 2 +- asusctl/src/slash_cli.rs | 19 +- asusd-user/src/config.rs | 40 +- asusd-user/src/ctrl_anime.rs | 30 +- asusd-user/src/daemon.rs | 6 +- asusd-user/src/error.rs | 4 +- asusd-user/src/zbus_anime.rs | 6 +- asusd/src/asus_armoury.rs | 16 +- asusd/src/aura_anime/config.rs | 82 ++-- asusd/src/aura_anime/mod.rs | 12 +- asusd/src/aura_anime/trait_impls.rs | 20 +- asusd/src/aura_laptop/config.rs | 144 +++--- asusd/src/aura_laptop/mod.rs | 38 +- asusd/src/aura_laptop/trait_impls.rs | 6 +- asusd/src/aura_manager.rs | 34 +- asusd/src/aura_scsi/config.rs | 34 +- asusd/src/aura_scsi/mod.rs | 2 +- asusd/src/aura_scsi/trait_impls.rs | 4 +- asusd/src/aura_slash/config.rs | 34 +- asusd/src/aura_slash/mod.rs | 16 +- asusd/src/aura_slash/trait_impls.rs | 187 ++++++-- asusd/src/aura_types.rs | 18 +- asusd/src/config.rs | 8 +- asusd/src/ctrl_fancurves.rs | 18 +- asusd/src/ctrl_platform.rs | 32 +- asusd/src/daemon.rs | 4 +- asusd/src/error.rs | 11 +- asusd/src/lib.rs | 14 +- config-traits/src/lib.rs | 2 +- dmi-id/src/lib.rs | 4 +- rog-anime/src/data.rs | 32 +- rog-anime/src/diagonal.rs | 20 +- rog-anime/src/error.rs | 4 +- rog-anime/src/gif.rs | 30 +- rog-anime/src/grid.rs | 6 +- rog-anime/src/image.rs | 46 +- rog-anime/src/sequencer.rs | 71 +-- rog-anime/src/usb.rs | 32 +- rog-anime/tests/ga401.rs | 10 +- rog-anime/tests/ga402q.rs | 20 +- rog-anime/tests/gu604.rs | 14 +- rog-aura/src/aura_detection.rs | 15 +- rog-aura/src/builtin_modes.rs | 100 ++-- rog-aura/src/effects/base.rs | 2 +- rog-aura/src/effects/breathe.rs | 4 +- rog-aura/src/effects/doom.rs | 16 +- rog-aura/src/effects/mod.rs | 28 +- rog-aura/src/effects/static_.rs | 4 +- rog-aura/src/error.rs | 4 +- rog-aura/src/keyboard/advanced.rs | 10 +- rog-aura/src/keyboard/layouts.rs | 226 ++++----- rog-aura/src/keyboard/mod.rs | 2 +- rog-aura/src/keyboard/power.rs | 438 ++++++++++-------- rog-aura/src/lib.rs | 24 +- rog-aura/src/usb.rs | 9 +- rog-control-center/build.rs | 2 +- rog-control-center/src/cli_options.rs | 2 +- rog-control-center/src/config.rs | 8 +- rog-control-center/src/error.rs | 4 +- rog-control-center/src/lib.rs | 2 +- rog-control-center/src/main.rs | 2 +- rog-control-center/src/mocking.rs | 34 +- rog-control-center/src/notify.rs | 22 +- rog-control-center/src/tray.rs | 14 +- rog-control-center/src/types/aura_types.rs | 30 +- rog-control-center/src/types/fan_types.rs | 8 +- rog-control-center/src/ui/mod.rs | 8 +- rog-control-center/src/ui/setup_anime.rs | 4 +- rog-control-center/src/ui/setup_aura.rs | 8 +- rog-control-center/src/ui/setup_fans.rs | 6 +- rog-control-center/src/ui/setup_system.rs | 2 +- rog-control-center/src/zbus_proxies.rs | 15 +- .../translations/en/rog-control-center.po | 2 +- rog-dbus/src/zbus_fan_curves.rs | 2 +- rog-dbus/src/zbus_slash.rs | 34 +- .../examples/ally-gamepad-calibration.rs | 8 +- .../examples/ally-gamepad-mode-changes.rs | 30 +- .../examples/ally-set-qam-secondary.rs | 14 +- rog-platform/src/cpu.rs | 49 +- rog-platform/src/error.rs | 6 +- rog-platform/src/firmware_attributes.rs | 56 +-- rog-platform/src/hid_raw.rs | 8 +- rog-platform/src/keyboard_led.rs | 6 +- rog-platform/src/lib.rs | 4 +- rog-platform/src/platform.rs | 32 +- rog-platform/src/power.rs | 6 +- rog-platform/src/usb_raw.rs | 4 +- rog-profiles/src/error.rs | 5 +- rog-profiles/src/fan_curve_set.rs | 12 +- rog-profiles/src/lib.rs | 32 +- rog-scsi/src/builtin_modes.rs | 41 +- rog-scsi/src/error.rs | 4 +- rog-scsi/src/lib.rs | 8 +- rog-slash/src/data.rs | 18 +- rog-slash/src/error.rs | 4 +- rog-slash/src/usb.rs | 96 ++-- rustfmt.toml | 4 + simulators/src/animatrix/map_ga401.rs | 2 +- simulators/src/animatrix/map_ga402.rs | 2 +- simulators/src/animatrix/map_gu604.rs | 2 +- simulators/src/animatrix/mod.rs | 16 +- simulators/src/simulator.rs | 6 +- 113 files changed, 1545 insertions(+), 1305 deletions(-) diff --git a/README.md b/README.md index 09f0c397..fa909ee4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # `asusctl` for ASUS ROG -[Become a Patron!](https://www.patreon.com/bePatron?u=7602281) - [Asus Linux Website](https://asus-linux.org/) +[![Become a Patron!](https://github.com/codebard/patron-button-and-widgets-by-codebard/blob/master/images/become_a_patron_button.png?raw=true)](https://www.patreon.com/bePatron?u=7602281) [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/V7V5CLU67) - [Asus Linux Website](https://asus-linux.org/) **WARNING:** Many features are developed in tandem with kernel patches. If you see a feature is missing you either need a patched kernel or latest release. @@ -11,7 +11,9 @@ Now includes a GUI, `rog-control-center`. ## Kernel support -**The minimum supported kernel version is 6.10**, which will contain the patches from [here](https://lore.kernel.org/platform-driver-x86/20240404001652.86207-1-luke@ljones.dev/). This is especially required for 2023+ devices and possibly some late 2022 devices. +Due to on-going driver work the minimum suggested kernel version is always **the latest*, as improvements and fixes are continuous. + +Support for some new features is not avilable unless you run a patched kernel with the work I am doing [in this github repo](https://github.com/flukejones/linux/tree/wip/ally-6.13). Use the linked branch, or `wip/ally-6.12`. Everything that is done here is upstreamed eventually (a long process). Z13 devices will need [these](https://lore.kernel.org/linux-input/20240416090402.31057-1-luke@ljones.dev/T/#t) diff --git a/asusctl/examples/anime-diag-png.rs b/asusctl/examples/anime-diag-png.rs index 54bb7ae9..ec78fad9 100644 --- a/asusctl/examples/anime-diag-png.rs +++ b/asusctl/examples/anime-diag-png.rs @@ -23,7 +23,7 @@ fn main() -> Result<(), Box> { Path::new(&args[1]), None, args[2].parse::().unwrap(), - AnimeType::GA401, + AnimeType::GA401 )?; let anime_type = get_anime_type(); diff --git a/asusctl/examples/anime-gif.rs b/asusctl/examples/anime-gif.rs index a205c1ac..1fb63876 100644 --- a/asusctl/examples/anime-gif.rs +++ b/asusctl/examples/anime-gif.rs @@ -21,14 +21,11 @@ fn main() { let brightness = args[2].parse::().unwrap(); let anime_type = get_anime_type(); let mut seq = Sequences::new(anime_type); - seq.insert( - 0, - &ActionLoader::AsusAnimation { - file: path.into(), - time: rog_anime::AnimTime::Infinite, - brightness, - }, - ) + seq.insert(0, &ActionLoader::AsusAnimation { + file: path.into(), + time: rog_anime::AnimTime::Infinite, + brightness + }) .unwrap(); loop { diff --git a/asusctl/examples/anime-png.rs b/asusctl/examples/anime-png.rs index 539fab72..c3d5b02d 100644 --- a/asusctl/examples/anime-png.rs +++ b/asusctl/examples/anime-png.rs @@ -27,10 +27,10 @@ fn main() -> Result<(), Box> { args[3].parse::().unwrap(), Vec2::new( args[4].parse::().unwrap(), - args[5].parse::().unwrap(), + args[5].parse::().unwrap() ), args[6].parse::().unwrap(), - anime_type, + anime_type )?; proxy.write(::try_from(&matrix)?).unwrap(); diff --git a/asusctl/examples/anime-spinning.rs b/asusctl/examples/anime-spinning.rs index fae2de8b..f1ddb1e1 100644 --- a/asusctl/examples/anime-spinning.rs +++ b/asusctl/examples/anime-spinning.rs @@ -30,10 +30,10 @@ fn main() -> Result<(), Box> { args[3].parse::().unwrap(), Vec2::new( args[4].parse::().unwrap(), - args[5].parse::().unwrap(), + args[5].parse::().unwrap() ), args[6].parse::().unwrap(), - anime_type, + anime_type )?; loop { diff --git a/asusctl/examples/aura-zoned-breathe.rs b/asusctl/examples/aura-zoned-breathe.rs index f219ad1d..fab7282f 100644 --- a/asusctl/examples/aura-zoned-breathe.rs +++ b/asusctl/examples/aura-zoned-breathe.rs @@ -36,10 +36,10 @@ fn main() -> Result<(), Box> { Colour { r: 200, g: 110, - b: 0, + b: 0 }, 100, - 10, + 10 )); seq.push(zone); diff --git a/asusctl/src/anime_cli.rs b/asusctl/src/anime_cli.rs index 15dc17e2..8a9c35ca 100644 --- a/asusctl/src/anime_cli.rs +++ b/asusctl/src/anime_cli.rs @@ -40,7 +40,7 @@ pub struct AnimeCommand { #[options(no_short, meta = "", help = "Off with his head!!!")] pub off_with_his_head: Option, #[options(command)] - pub command: Option, + pub command: Option } #[derive(Options)] @@ -54,7 +54,7 @@ pub enum AnimeActions { #[options(help = "display an animated diagonal/pixel-perfect GIF")] PixelGif(AnimeGifDiagonal), #[options(help = "change which builtin animations are shown")] - SetBuiltins(Builtins), + SetBuiltins(Builtins) } #[derive(Options)] @@ -82,7 +82,7 @@ pub struct Builtins { )] pub shutdown: AnimShutdown, #[options(meta = "", help = "set/apply the animations ")] - pub set: Option, + pub set: Option } #[derive(Options)] @@ -100,7 +100,7 @@ pub struct AnimeImage { #[options(meta = "", default = "0.0", help = "the angle in radians")] pub angle: f32, #[options(meta = "", default = "1.0", help = "brightness 0.0-1.0")] - pub bright: f32, + pub bright: f32 } #[derive(Options)] @@ -110,7 +110,7 @@ pub struct AnimeImageDiagonal { #[options(meta = "", help = "full path to the png to display")] pub path: String, #[options(meta = "", default = "1.0", help = "brightness 0.0-1.0")] - pub bright: f32, + pub bright: f32 } #[derive(Options)] @@ -134,7 +134,7 @@ pub struct AnimeGif { default = "1", help = "how many loops to play - 0 is infinite" )] - pub loops: u32, + pub loops: u32 } #[derive(Options)] @@ -150,5 +150,5 @@ pub struct AnimeGifDiagonal { default = "1", help = "how many loops to play - 0 is infinite" )] - pub loops: u32, + pub loops: u32 } diff --git a/asusctl/src/aura_cli.rs b/asusctl/src/aura_cli.rs index 5b44d4f3..b676e175 100644 --- a/asusctl/src/aura_cli.rs +++ b/asusctl/src/aura_cli.rs @@ -17,7 +17,7 @@ pub struct LedPowerCommand1 { #[options(meta = "", help = "Control boot animations ")] pub boot: Option, #[options(meta = "", help = "Control suspend animations ")] - pub sleep: Option, + pub sleep: Option } #[derive(Options, Debug)] @@ -25,7 +25,7 @@ pub struct LedPowerCommand2 { #[options(help = "print help message")] pub help: bool, #[options(command)] - pub command: Option, + pub command: Option } #[derive(Options, Debug)] @@ -42,7 +42,7 @@ pub enum SetAuraZoneEnabled { #[options(help = "")] RearGlow(AuraPowerStates), #[options(help = "")] - Ally(AuraPowerStates), + Ally(AuraPowerStates) } #[derive(Debug, Clone, Options)] @@ -56,12 +56,12 @@ pub struct AuraPowerStates { #[options(help = "defaults to false if option unused")] pub sleep: bool, #[options(help = "defaults to false if option unused")] - pub shutdown: bool, + pub shutdown: bool } #[derive(Options)] pub struct LedBrightness { - level: Option, + level: Option } impl LedBrightness { pub fn new(level: Option) -> Self { @@ -96,7 +96,7 @@ impl ToString for LedBrightness { Some(0x00) => "low", Some(0x01) => "med", Some(0x02) => "high", - _ => "unknown", + _ => "unknown" }; s.to_owned() } @@ -113,7 +113,7 @@ pub struct SingleSpeed { meta = "", help = "set the zone for this effect e.g, 0, 1, one, logo, lightbar-left" )] - pub zone: AuraZone, + pub zone: AuraZone } #[derive(Debug, Clone, Options, Default)] @@ -129,7 +129,7 @@ pub struct SingleSpeedDirection { meta = "", help = "set the zone for this effect e.g, 0, 1, one, logo, lightbar-left" )] - pub zone: AuraZone, + pub zone: AuraZone } #[derive(Debug, Clone, Default, Options)] @@ -143,7 +143,7 @@ pub struct SingleColour { meta = "", help = "set the zone for this effect e.g, 0, 1, one, logo, lightbar-left" )] - pub zone: AuraZone, + pub zone: AuraZone } #[derive(Debug, Clone, Default, Options)] @@ -159,7 +159,7 @@ pub struct SingleColourSpeed { meta = "", help = "set the zone for this effect e.g, 0, 1, one, logo, lightbar-left" )] - pub zone: AuraZone, + pub zone: AuraZone } #[derive(Debug, Clone, Options, Default)] @@ -177,7 +177,7 @@ pub struct TwoColourSpeed { meta = "", help = "set the zone for this effect e.g, 0, 1, one, logo, lightbar-left" )] - pub zone: AuraZone, + pub zone: AuraZone } #[derive(Debug, Clone, Default, Options)] @@ -191,7 +191,7 @@ pub struct MultiZone { #[options(short = "c", meta = "", help = "set the RGB value e.g, ff00ff")] pub colour3: Colour, #[options(short = "d", meta = "", help = "set the RGB value e.g, ff00ff")] - pub colour4: Colour, + pub colour4: Colour } #[derive(Debug, Clone, Default, Options)] @@ -207,7 +207,7 @@ pub struct MultiColourSpeed { #[options(short = "d", meta = "", help = "set the RGB value e.g, ff00ff")] pub colour4: Colour, #[options(no_long, meta = "", help = "set the speed: low, med, high")] - pub speed: Speed, + pub speed: Speed } /// Byte value for setting the built-in mode. @@ -239,7 +239,7 @@ pub enum SetAuraBuiltin { #[options(help = "set a vertical line zooming from left")] Comet(SingleColour), // 11 #[options(help = "set a wide vertical line zooming from left")] - Flash(SingleColour), // 12 + Flash(SingleColour) // 12 } impl Default for SetAuraBuiltin { diff --git a/asusctl/src/cli_opts.rs b/asusctl/src/cli_opts.rs index 2253f184..1558e7f8 100644 --- a/asusctl/src/cli_opts.rs +++ b/asusctl/src/cli_opts.rs @@ -26,7 +26,7 @@ pub struct CliStart { #[options(help = "Toggle one-shot battery charge to 100%")] pub one_shot_chg: bool, #[options(command)] - pub command: Option, + pub command: Option } #[derive(Options)] @@ -55,7 +55,7 @@ pub enum CliCommand { help = "Change platform settings. This is a new interface exposed by the asus-armoury \ driver, some of the settings will be the same as the older platform interface" )] - Armoury(ArmouryCommand), + Armoury(ArmouryCommand) } #[derive(Debug, Clone, Options)] @@ -73,7 +73,7 @@ pub struct ProfileCommand { pub profile_get: bool, #[options(meta = "", help = "set the active profile")] - pub profile_set: Option, + pub profile_set: Option } #[derive(Options)] @@ -85,13 +85,13 @@ pub struct LedModeCommand { #[options(help = "switch to previous aura mode")] pub prev_mode: bool, #[options(command)] - pub command: Option, + pub command: Option } #[derive(Options)] pub struct GraphicsCommand { #[options(help = "print help message")] - pub help: bool, + pub help: bool } #[derive(Options, Debug)] @@ -124,7 +124,7 @@ pub struct PlatformCommand { )] pub panel_overdrive_set: Option, #[options(no_long, short = "o", help = "get panel overdrive")] - pub panel_overdrive_get: bool, + pub panel_overdrive_get: bool } #[derive(Options, Debug)] @@ -132,5 +132,5 @@ pub struct ArmouryCommand { #[options(help = "print help message")] pub help: bool, #[options(free)] - pub free: Vec, + pub free: Vec } diff --git a/asusctl/src/fan_curve_cli.rs b/asusctl/src/fan_curve_cli.rs index 77488726..cbde802e 100644 --- a/asusctl/src/fan_curve_cli.rs +++ b/asusctl/src/fan_curve_cli.rs @@ -45,5 +45,5 @@ pub struct FanCurveCommand { help = "data format = 30c:1%,49c:2%,59c:3%,69c:4%,79c:31%,89c:49%,99c:56%,109c:58%. \ `--mod-profile` required. If '%' is omitted the fan range is 0-255" )] - pub data: Option, + pub data: Option } diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 65f96ed6..a476aeb4 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -89,7 +89,7 @@ fn main() { fn print_error_help( err: &dyn std::error::Error, supported_interfaces: &[String], - supported_properties: &[Properties], + supported_properties: &[Properties] ) { check_service("asusd"); println!("\nError: {}\n", err); @@ -130,7 +130,7 @@ fn check_service(name: &str) -> bool { fn find_iface(iface_name: &str) -> Result, Box> where - T: ProxyImpl<'static> + From>, + T: ProxyImpl<'static> + From> { let conn = zbus::blocking::Connection::system().unwrap(); let f = zbus::blocking::fdo::ObjectManagerProxy::new(&conn, "xyz.ljones.Asusd", "/").unwrap(); @@ -157,7 +157,7 @@ where T::builder(&conn) .path(path.clone())? .destination("xyz.ljones.Asusd")? - .build()?, + .build()? ); } return Ok(ctrl); @@ -170,7 +170,7 @@ fn do_parsed( parsed: &CliStart, supported_interfaces: &[String], supported_properties: &[Properties], - conn: Connection, + conn: Connection ) -> Result<(), Box> { match &parsed.command { Some(CliCommand::Aura(mode)) => handle_led_mode(mode)?, @@ -281,7 +281,7 @@ fn do_parsed( let level = aura.brightness()?; println!("Current keyboard led brightness: {level:?}"); } - Some(level) => aura.set_brightness(rog_aura::LedBrightness::from(level))?, + Some(level) => aura.set_brightness(rog_aura::LedBrightness::from(level))? } } } else { @@ -425,7 +425,7 @@ fn handle_anime(cmd: &AnimeCommand) -> Result<(), Box> { image.angle, Vec2::new(image.x_pos, image.y_pos), image.bright, - anime_type, + anime_type )?; proxy.write(::try_from(&matrix)?)?; @@ -444,7 +444,7 @@ fn handle_anime(cmd: &AnimeCommand) -> Result<(), Box> { Path::new(&image.path), None, image.bright, - anime_type, + anime_type )?; proxy.write(matrix.into_data_buffer(anime_type)?)?; @@ -466,7 +466,7 @@ fn handle_anime(cmd: &AnimeCommand) -> Result<(), Box> { Vec2::new(gif.x_pos, gif.y_pos), AnimTime::Count(1), gif.bright, - anime_type, + anime_type )?; let mut loops = gif.loops as i32; @@ -497,7 +497,7 @@ fn handle_anime(cmd: &AnimeCommand) -> Result<(), Box> { Path::new(&gif.path), AnimTime::Count(1), gif.bright, - anime_type, + anime_type )?; let mut loops = gif.loops as i32; @@ -530,7 +530,7 @@ fn handle_anime(cmd: &AnimeCommand) -> Result<(), Box> { boot: builtins.boot, awake: builtins.awake, sleep: builtins.sleep, - shutdown: builtins.shutdown, + shutdown: builtins.shutdown })?; } } @@ -551,7 +551,12 @@ fn verify_brightness(brightness: f32) { fn handle_slash(cmd: &SlashCommand) -> Result<(), Box> { if (cmd.brightness.is_none() && cmd.interval.is_none() - && cmd.slash_mode.is_none() + && cmd.show_on_boot.is_none() + && cmd.show_on_shutdown.is_none() + && cmd.show_on_sleep.is_none() + && cmd.show_on_battery.is_none() + && cmd.show_battery_warning.is_none() + && cmd.mode.is_none() && !cmd.list && !cmd.enable && !cmd.disable) @@ -577,8 +582,24 @@ fn handle_slash(cmd: &SlashCommand) -> Result<(), Box> { if let Some(interval) = cmd.interval { proxy.set_interval(interval)?; } - if let Some(slash_mode) = cmd.slash_mode { - proxy.set_slash_mode(slash_mode)?; + if let Some(slash_mode) = cmd.mode { + proxy.set_mode(slash_mode)?; + } + if let Some(show) = cmd.show_on_boot { + proxy.set_show_on_boot(show)?; + } + + if let Some(show) = cmd.show_on_shutdown { + proxy.set_show_on_shutdown(show)?; + } + if let Some(show) = cmd.show_on_sleep { + proxy.set_show_on_sleep(show)?; + } + if let Some(show) = cmd.show_on_battery { + proxy.set_show_on_battery(show)?; + } + if let Some(show) = cmd.show_battery_warning { + proxy.set_show_battery_warning(show)?; } } if cmd.list { @@ -772,7 +793,7 @@ fn handle_led_power1(power: &LedPowerCommand1) -> Result<(), Box Result<(), Box> { let mut states = Vec::new(); if power.keyboard { @@ -781,7 +802,7 @@ fn handle_led_power_1_do_1866( boot: power.boot.unwrap_or_default(), awake: power.awake.unwrap_or_default(), sleep: power.sleep.unwrap_or_default(), - shutdown: false, + shutdown: false }); } if power.lightbar { @@ -790,7 +811,7 @@ fn handle_led_power_1_do_1866( boot: power.boot.unwrap_or_default(), awake: power.awake.unwrap_or_default(), sleep: power.sleep.unwrap_or_default(), - shutdown: false, + shutdown: false }); } @@ -852,7 +873,7 @@ fn handle_led_power2(power: &LedPowerCommand2) -> Result<(), Box set(PowerZones::Lightbar, l), aura_cli::SetAuraZoneEnabled::Lid(l) => set(PowerZones::Lid, l), aura_cli::SetAuraZoneEnabled::RearGlow(r) => set(PowerZones::RearGlow, r), - aura_cli::SetAuraZoneEnabled::Ally(r) => set(PowerZones::Ally, r), + aura_cli::SetAuraZoneEnabled::Ally(r) => set(PowerZones::Ally, r) } } @@ -866,7 +887,7 @@ fn handle_led_power2(power: &LedPowerCommand2) -> Result<(), Box Result<(), Box> { if !supported.contains(&Properties::ThrottlePolicy) { println!("Profiles not supported by either this kernel or by the laptop."); @@ -910,7 +931,7 @@ fn handle_throttle_profile( fn handle_fan_curve( conn: &Connection, - cmd: &FanCurveCommand, + cmd: &FanCurveCommand ) -> Result<(), Box> { let Ok(fan_proxy) = FanCurvesProxyBlocking::new(conn).map_err(|e| { println!("Fan-curves not supported by either this kernel or by the laptop: {e:?}"); @@ -989,7 +1010,7 @@ fn handle_fan_curve( fn handle_platform_properties( conn: &Connection, supported: &[Properties], - cmd: &PlatformCommand, + cmd: &PlatformCommand ) -> Result<(), Box> { { if (cmd.gpu_mux_mode_set.is_none() diff --git a/asusctl/src/scsi_cli.rs b/asusctl/src/scsi_cli.rs index ef87d3c1..f2fbf884 100644 --- a/asusctl/src/scsi_cli.rs +++ b/asusctl/src/scsi_cli.rs @@ -31,5 +31,5 @@ pub struct ScsiCommand { pub colours: Vec, #[options(help = "list available animations")] - pub list: bool, + pub list: bool } diff --git a/asusctl/src/slash_cli.rs b/asusctl/src/slash_cli.rs index 4777c19e..349f5ca3 100644 --- a/asusctl/src/slash_cli.rs +++ b/asusctl/src/slash_cli.rs @@ -9,12 +9,27 @@ pub struct SlashCommand { pub enable: bool, #[options(help = "Ddisable the Slash Ledbar")] pub disable: bool, - #[options(meta = "", help = "Set brightness value <0-255>")] + #[options(short = "l", meta = "", help = "Set brightness value <0-255>")] pub brightness: Option, #[options(meta = "", help = "Set interval value <0-5>")] pub interval: Option, #[options(meta = "", help = "Set SlashMode (so 'list' for all options)")] - pub slash_mode: Option, + pub mode: Option, #[options(help = "list available animations")] pub list: bool, + + #[options(short = "B", meta = "", help = "Show the animation on boot")] + pub show_on_boot: Option, + #[options(short = "S", meta = "", help = "Show the animation on shutdown")] + pub show_on_shutdown: Option, + #[options(short = "s", meta = "", help = "Show the animation on sleep")] + pub show_on_sleep: Option, + #[options(short = "b", meta = "", help = "Show the animation on battery")] + pub show_on_battery: Option, + #[options( + short = "w", + meta = "", + help = "Show the low-battery warning animation" + )] + pub show_battery_warning: Option } diff --git a/asusd-user/src/config.rs b/asusd-user/src/config.rs index 36b55478..f68a546d 100644 --- a/asusd-user/src/config.rs +++ b/asusd-user/src/config.rs @@ -21,7 +21,7 @@ fn root_conf_dir() -> PathBuf { #[derive(Debug, Deserialize, Serialize)] pub struct ConfigAnime { pub name: String, - pub anime: Vec, + pub anime: Vec } impl ConfigAnime { @@ -52,8 +52,8 @@ impl Default for ConfigAnime { time: AnimTime::Fade(Fade::new( Duration::from_secs(2), None, - Duration::from_secs(2), - )), + Duration::from_secs(2) + )) }, ActionLoader::AsusAnimation { file: "/usr/share/asusd/anime/asus/rog/Sunset.gif".into(), @@ -61,8 +61,8 @@ impl Default for ConfigAnime { time: AnimTime::Fade(Fade::new( Duration::from_secs(6), None, - Duration::from_secs(3), - )), + Duration::from_secs(3) + )) }, ActionLoader::ImageAnimation { file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(), @@ -73,8 +73,8 @@ impl Default for ConfigAnime { time: AnimTime::Fade(Fade::new( Duration::from_secs(2), Some(Duration::from_secs(2)), - Duration::from_secs(2), - )), + Duration::from_secs(2) + )) }, ActionLoader::Image { file: "/usr/share/asusd/anime/custom/rust.png".into(), @@ -84,9 +84,9 @@ impl Default for ConfigAnime { time: AnimTime::Fade(Fade::new( Duration::from_secs(2), Some(Duration::from_secs(1)), - Duration::from_secs(2), + Duration::from_secs(2) )), - brightness: 0.6, + brightness: 0.6 }, ActionLoader::Pause(Duration::from_secs(1)), ActionLoader::ImageAnimation { @@ -95,9 +95,9 @@ impl Default for ConfigAnime { angle: 0.0, translation: Vec2::new(3.0, 2.0), brightness: 0.5, - time: AnimTime::Count(2), + time: AnimTime::Count(2) }, - ], + ] } } } @@ -121,7 +121,7 @@ impl StdConfigLoad for ConfigAnime {} #[derive(Debug, Deserialize, Serialize)] pub struct ConfigAura { pub name: String, - pub aura: AuraSequences, + pub aura: AuraSequences } impl ConfigAura { @@ -139,14 +139,14 @@ impl Default for ConfigAura { Colour { r: 255, g: 0, - b: 20, + b: 20 }, Colour { r: 20, g: 255, - b: 0, + b: 0 }, - Speed::Low, + Speed::Low )); seq.push(key.clone()); @@ -161,7 +161,7 @@ impl Default for ConfigAura { LedCode::F, Colour { r: 255, g: 0, b: 0 }, Colour { r: 255, g: 0, b: 0 }, - Speed::High, + Speed::High )); seq.push(key); @@ -176,13 +176,13 @@ impl Default for ConfigAura { LedCode::N9, Colour { r: 0, g: 0, b: 255 }, 80, - 40, + 40 )); seq.push(key); Self { name: "aura-default".to_owned(), - aura: seq, + aura: seq } } } @@ -209,14 +209,14 @@ pub struct ConfigBase { /// Name of active anime config file in the user config directory pub active_anime: Option, /// Name of active aura config file in the user config directory - pub active_aura: Option, + pub active_aura: Option } impl StdConfig for ConfigBase { fn new() -> Self { Self { active_anime: Some("anime-default".to_owned()), - active_aura: Some("aura-default".to_owned()), + active_aura: Some("aura-default".to_owned()) } } diff --git a/asusd-user/src/ctrl_anime.rs b/asusd-user/src/ctrl_anime.rs index d77a60d9..b5697027 100644 --- a/asusd-user/src/ctrl_anime.rs +++ b/asusd-user/src/ctrl_anime.rs @@ -25,7 +25,7 @@ pub struct Timer { /// Used only for `TimeType::Timer`, milliseonds to fade the image in for fade_in: u64, /// Used only for `TimeType::Timer`, milliseonds to fade the image out for - fade_out: u64, + fade_out: u64 } impl From for AnimTime { @@ -46,7 +46,7 @@ impl From for AnimTime { } } TimeType::Count => AnimTime::Count(time.count as u32), - TimeType::Infinite => AnimTime::Infinite, + TimeType::Infinite => AnimTime::Infinite } } } @@ -55,7 +55,7 @@ impl From for AnimTime { pub enum TimeType { Timer, Count, - Infinite, + Infinite } /// The inner object exists to allow the zbus proxy to share it with a runner @@ -63,19 +63,19 @@ pub enum TimeType { pub struct CtrlAnimeInner<'a> { sequences: Sequences, client: AnimeProxyBlocking<'a>, - do_early_return: Arc, + do_early_return: Arc } impl CtrlAnimeInner<'static> { pub fn new( sequences: Sequences, client: AnimeProxyBlocking<'static>, - do_early_return: Arc, + do_early_return: Arc ) -> Result { Ok(Self { sequences, client, - do_early_return, + do_early_return }) } @@ -130,7 +130,7 @@ pub struct CtrlAnime<'a> { client: AnimeProxyBlocking<'a>, inner: Arc>>, /// Must be the same Atomic as in CtrlAnimeInner - inner_early_return: Arc, + inner_early_return: Arc } impl CtrlAnime<'static> { @@ -138,13 +138,13 @@ impl CtrlAnime<'static> { config: Arc>, inner: Arc>>, client: AnimeProxyBlocking<'static>, - inner_early_return: Arc, + inner_early_return: Arc ) -> Result { Ok(CtrlAnime { config, client, inner, - inner_early_return, + inner_early_return }) } @@ -174,7 +174,7 @@ impl CtrlAnime<'static> { index: u32, file: &str, time: Timer, - brightness: f32, + brightness: f32 ) -> zbus::fdo::Result { if let Ok(mut config) = self.config.try_lock() { let time: AnimTime = time.into(); @@ -182,7 +182,7 @@ impl CtrlAnime<'static> { let action = ActionLoader::AsusAnimation { file: file.into(), brightness, - time, + time }; // Must make the inner run loop return early @@ -216,7 +216,7 @@ impl CtrlAnime<'static> { angle: f32, xy: (f32, f32), time: Timer, - brightness: f32, + brightness: f32 ) -> zbus::fdo::Result { if let Ok(mut config) = self.config.try_lock() { let time: AnimTime = time.into(); @@ -228,7 +228,7 @@ impl CtrlAnime<'static> { angle, translation, brightness, - time, + time }; // Must make the inner run loop return early @@ -261,7 +261,7 @@ impl CtrlAnime<'static> { angle: f32, xy: (f32, f32), time: Timer, - brightness: f32, + brightness: f32 ) -> zbus::fdo::Result { if let Ok(mut config) = self.config.try_lock() { let file = Path::new(&file); @@ -272,7 +272,7 @@ impl CtrlAnime<'static> { angle, translation: Vec2::new(xy.0, xy.1), brightness, - time, + time }; // Must make the inner run loop return early diff --git a/asusd-user/src/daemon.rs b/asusd-user/src/daemon.rs index 31f7970a..1729c5fb 100644 --- a/asusd-user/src/daemon.rs +++ b/asusd-user/src/daemon.rs @@ -61,16 +61,16 @@ fn main() -> Result<(), Box> { CtrlAnimeInner::new( anime, anime_proxy_blocking.clone(), - early_return.clone(), + early_return.clone() ) - .unwrap(), + .unwrap() )); // Need new client object for dbus control part let anime_control = CtrlAnime::new( anime_config, inner.clone(), anime_proxy_blocking, - early_return, + early_return ) .unwrap(); anime_control.add_to_server(&mut connection).await; diff --git a/asusd-user/src/error.rs b/asusd-user/src/error.rs index e6c0e33e..31977a5a 100644 --- a/asusd-user/src/error.rs +++ b/asusd-user/src/error.rs @@ -8,7 +8,7 @@ pub enum Error { ConfigLoadFail, ConfigLockFail, XdgVars, - Anime(AnimeError), + Anime(AnimeError) } impl fmt::Display for Error { @@ -19,7 +19,7 @@ impl fmt::Display for Error { Error::ConfigLoadFail => write!(f, "Failed to load user config"), Error::ConfigLockFail => write!(f, "Failed to lock user config"), Error::XdgVars => write!(f, "XDG environment vars appear unset"), - Error::Anime(err) => write!(f, "Anime error: {}", err), + Error::Anime(err) => write!(f, "Anime error: {}", err) } } } diff --git a/asusd-user/src/zbus_anime.rs b/asusd-user/src/zbus_anime.rs index 910e038b..e7fae63d 100644 --- a/asusd-user/src/zbus_anime.rs +++ b/asusd-user/src/zbus_anime.rs @@ -32,7 +32,7 @@ trait Daemon { file: &str, time: u32, count: u32, - brightness: f64, + brightness: f64 ) -> zbus::Result; /// InsertImage method @@ -43,7 +43,7 @@ trait Daemon { scale: f64, angle: f64, xy: &(f64, f64), - brightness: f64, + brightness: f64 ) -> zbus::Result; /// InsertImageGif method @@ -56,7 +56,7 @@ trait Daemon { xy: &(f64, f64), time: u32, count: u32, - brightness: f64, + brightness: f64 ) -> zbus::Result; /// InsertPause method diff --git a/asusd/src/asus_armoury.rs b/asusd/src/asus_armoury.rs index fc00879b..f2b0daed 100644 --- a/asusd/src/asus_armoury.rs +++ b/asusd/src/asus_armoury.rs @@ -1,6 +1,6 @@ use log::error; use rog_platform::firmware_attributes::{ - AttrValue, Attribute, FirmwareAttribute, FirmwareAttributes, + AttrValue, Attribute, FirmwareAttribute, FirmwareAttributes }; use serde::{Deserialize, Serialize}; use zbus::zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Type, Value}; @@ -14,7 +14,7 @@ const MOD_NAME: &str = "asus_armoury"; #[derive(Debug, Default, Clone, Deserialize, Serialize, Type, Value, OwnedValue)] pub struct PossibleValues { strings: Vec, - nums: Vec, + nums: Vec } fn dbus_path_for_attr(attr_name: &str) -> OwnedObjectPath { @@ -87,7 +87,7 @@ impl AsusArmouryAttribute { async fn default_value(&self) -> i32 { match self.0.default_value() { AttrValue::Integer(i) => *i, - _ => -1, + _ => -1 } } @@ -95,7 +95,7 @@ impl AsusArmouryAttribute { async fn min_value(&self) -> i32 { match self.0.min_value() { AttrValue::Integer(i) => *i, - _ => -1, + _ => -1 } } @@ -103,7 +103,7 @@ impl AsusArmouryAttribute { async fn max_value(&self) -> i32 { match self.0.max_value() { AttrValue::Integer(i) => *i, - _ => -1, + _ => -1 } } @@ -111,7 +111,7 @@ impl AsusArmouryAttribute { async fn scalar_increment(&self) -> i32 { match self.0.scalar_increment() { AttrValue::Integer(i) => *i, - _ => -1, + _ => -1 } } @@ -119,7 +119,7 @@ impl AsusArmouryAttribute { async fn possible_values(&self) -> Vec { match self.0.possible_values() { AttrValue::EnumInt(i) => i.clone(), - _ => Vec::default(), + _ => Vec::default() } } @@ -129,7 +129,7 @@ impl AsusArmouryAttribute { return Ok(i); } Err(fdo::Error::Failed( - "Could not read current value".to_string(), + "Could not read current value".to_string() )) } diff --git a/asusd/src/aura_anime/config.rs b/asusd/src/aura_anime/config.rs index ca44b63b..28f4cc02 100644 --- a/asusd/src/aura_anime/config.rs +++ b/asusd/src/aura_anime/config.rs @@ -4,7 +4,7 @@ use config_traits::{StdConfig, StdConfigLoad}; use rog_anime::error::AnimeError; use rog_anime::usb::Brightness; use rog_anime::{ - ActionData, ActionLoader, AnimTime, Animations, AnimeType, DeviceState, Fade, Vec2, + ActionData, ActionLoader, AnimTime, Animations, AnimeType, DeviceState, Fade, Vec2 }; use serde::{Deserialize, Serialize}; @@ -15,14 +15,14 @@ pub struct AniMeConfigCached { pub system: Vec, pub boot: Vec, pub wake: Vec, - pub shutdown: Vec, + pub shutdown: Vec } impl AniMeConfigCached { pub fn init_from_config( &mut self, config: &AniMeConfig, - anime_type: AnimeType, + anime_type: AnimeType ) -> Result<(), AnimeError> { let mut sys = Vec::with_capacity(config.system.len()); for ani in &config.system { @@ -68,7 +68,7 @@ pub struct AniMeConfig { pub off_when_suspended: bool, pub off_when_lid_closed: bool, pub brightness_on_battery: Brightness, - pub builtin_anims: Animations, + pub builtin_anims: Animations } impl Default for AniMeConfig { @@ -87,7 +87,7 @@ impl Default for AniMeConfig { off_when_suspended: true, off_when_lid_closed: true, brightness_on_battery: Brightness::Low, - builtin_anims: Animations::default(), + builtin_anims: Animations::default() } } } @@ -118,7 +118,7 @@ impl From<&AniMeConfig> for DeviceState { off_when_unplugged: config.off_when_unplugged, off_when_suspended: config.off_when_suspended, off_when_lid_closed: config.off_when_lid_closed, - brightness_on_battery: config.brightness_on_battery, + brightness_on_battery: config.brightness_on_battery } } } @@ -138,38 +138,44 @@ impl AniMeConfig { // create a default config here AniMeConfig { system: vec![], - boot: vec![ActionLoader::ImageAnimation { - file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(), - scale: 0.9, - angle: 0.65, - translation: Vec2::default(), - brightness: 1.0, - time: AnimTime::Fade(Fade::new( - Duration::from_secs(2), - Some(Duration::from_secs(2)), - Duration::from_secs(2), - )), - }], - wake: vec![ActionLoader::ImageAnimation { - file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(), - scale: 0.9, - angle: 0.65, - translation: Vec2::default(), - brightness: 1.0, - time: AnimTime::Fade(Fade::new( - Duration::from_secs(2), - Some(Duration::from_secs(2)), - Duration::from_secs(2), - )), - }], - shutdown: vec![ActionLoader::ImageAnimation { - file: "/usr/share/asusd/anime/custom/sonic-wait.gif".into(), - scale: 0.9, - angle: 0.0, - translation: Vec2::new(3.0, 2.0), - brightness: 1.0, - time: AnimTime::Infinite, - }], + boot: vec![ + ActionLoader::ImageAnimation { + file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(), + scale: 0.9, + angle: 0.65, + translation: Vec2::default(), + brightness: 1.0, + time: AnimTime::Fade(Fade::new( + Duration::from_secs(2), + Some(Duration::from_secs(2)), + Duration::from_secs(2) + )) + }, + ], + wake: vec![ + ActionLoader::ImageAnimation { + file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(), + scale: 0.9, + angle: 0.65, + translation: Vec2::default(), + brightness: 1.0, + time: AnimTime::Fade(Fade::new( + Duration::from_secs(2), + Some(Duration::from_secs(2)), + Duration::from_secs(2) + )) + }, + ], + shutdown: vec![ + ActionLoader::ImageAnimation { + file: "/usr/share/asusd/anime/custom/sonic-wait.gif".into(), + scale: 0.9, + angle: 0.0, + translation: Vec2::new(3.0, 2.0), + brightness: 1.0, + time: AnimTime::Infinite + }, + ], ..Default::default() } } diff --git a/asusd/src/aura_anime/mod.rs b/asusd/src/aura_anime/mod.rs index 26f6e3c4..66fc920e 100644 --- a/asusd/src/aura_anime/mod.rs +++ b/asusd/src/aura_anime/mod.rs @@ -11,7 +11,7 @@ use config_traits::StdConfig; use log::{error, info, warn}; use rog_anime::usb::{ pkt_flush, pkt_set_brightness, pkt_set_enable_display, pkt_set_enable_powersave_anim, - pkts_for_init, Brightness, + pkts_for_init, Brightness }; use rog_anime::{ActionData, AnimeDataBuffer, AnimePacketType}; use rog_platform::hid_raw::HidRaw; @@ -30,14 +30,14 @@ pub struct AniMe { // set to force thread to exit thread_exit: Arc, // Set to false when the thread exits - thread_running: Arc, + thread_running: Arc } impl AniMe { pub fn new( hid: Option>>, usb: Option>>, - config: Arc>, + config: Arc> ) -> Self { Self { hid, @@ -45,7 +45,7 @@ impl AniMe { config, cache: AniMeConfigCached::default(), thread_exit: Arc::new(AtomicBool::new(false)), - thread_running: Arc::new(AtomicBool::new(false)), + thread_running: Arc::new(AtomicBool::new(false)) } } @@ -106,7 +106,7 @@ impl AniMe { pub async fn set_builtins_enabled( &self, enabled: bool, - bright: Brightness, + bright: Brightness ) -> Result<(), RogError> { self.write_bytes(&pkt_set_enable_powersave_anim(enabled)) .await?; @@ -229,7 +229,7 @@ impl AniMe { } inner .write_bytes(&pkt_set_enable_powersave_anim( - inner.config.lock().await.builtin_anims_enabled, + inner.config.lock().await.builtin_anims_enabled )) .await .map_err(|err| { diff --git a/asusd/src/aura_anime/trait_impls.rs b/asusd/src/aura_anime/trait_impls.rs index cf542559..74c683c2 100644 --- a/asusd/src/aura_anime/trait_impls.rs +++ b/asusd/src/aura_anime/trait_impls.rs @@ -5,7 +5,7 @@ use log::{error, warn}; use logind_zbus::manager::ManagerProxy; use rog_anime::usb::{ pkt_set_brightness, pkt_set_builtin_animations, pkt_set_enable_display, - pkt_set_enable_powersave_anim, Brightness, + pkt_set_enable_powersave_anim, Brightness }; use rog_anime::{Animations, AnimeDataBuffer, DeviceState}; use zbus::object_server::SignalEmitter; @@ -41,7 +41,7 @@ impl AniMeZbus { pub async fn start_tasks( mut self, connection: &Connection, - path: OwnedObjectPath, + path: OwnedObjectPath ) -> Result<(), RogError> { // let task = zbus.clone(); self.reload() @@ -166,10 +166,7 @@ impl AniMeZbus { async fn set_builtin_animations(&self, settings: Animations) { self.0 .write_bytes(&pkt_set_builtin_animations( - settings.boot, - settings.awake, - settings.sleep, - settings.shutdown, + settings.boot, settings.awake, settings.sleep, settings.shutdown )) .await .map_err(|err| { @@ -319,7 +316,7 @@ impl crate::CtrlTask for AniMeZbus { inner .write_bytes(&pkt_set_enable_display( - !(sleeping && config.off_when_suspended), + !(sleeping && config.off_when_suspended) )) .await .map_err(|err| { @@ -330,7 +327,7 @@ impl crate::CtrlTask for AniMeZbus { if config.builtin_anims_enabled { inner .write_bytes(&pkt_set_enable_powersave_anim( - !(sleeping && config.off_when_suspended), + !(sleeping && config.off_when_suspended) )) .await .map_err(|err| { @@ -433,7 +430,7 @@ impl crate::CtrlTask for AniMeZbus { .ok(); } } - }, + } ) .await; @@ -449,10 +446,7 @@ impl crate::Reloadable for AniMeZbus { if config.builtin_anims_enabled { self.0 .write_bytes(&pkt_set_builtin_animations( - anim.boot, - anim.awake, - anim.sleep, - anim.shutdown, + anim.boot, anim.awake, anim.sleep, anim.shutdown )) .await?; } diff --git a/asusd/src/aura_laptop/config.rs b/asusd/src/aura_laptop/config.rs index f2fdf93f..8a554153 100644 --- a/asusd/src/aura_laptop/config.rs +++ b/asusd/src/aura_laptop/config.rs @@ -5,7 +5,7 @@ use log::{debug, info, warn}; use rog_aura::aura_detection::LedSupportData; use rog_aura::keyboard::LaptopAuraPower; use rog_aura::{ - AuraDeviceType, AuraEffect, AuraModeNum, AuraZone, Direction, LedBrightness, Speed, GRADIENT, + AuraDeviceType, AuraEffect, AuraModeNum, AuraZone, Direction, LedBrightness, Speed, GRADIENT }; use serde::{Deserialize, Serialize}; @@ -29,7 +29,7 @@ pub struct AuraConfig { pub multizone_on: bool, pub enabled: LaptopAuraPower, #[serde(skip)] - pub per_key_mode_active: bool, + pub per_key_mode_active: bool } impl StdConfig for AuraConfig { @@ -74,7 +74,7 @@ impl AuraConfig { multizone: None, multizone_on: false, enabled, - per_key_mode_active: false, + per_key_mode_active: false }; for n in &config.support_data.basic_modes { @@ -92,7 +92,7 @@ impl AuraConfig { colour1: *GRADIENT.get(i).unwrap_or(&GRADIENT[0]), colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]), speed: Speed::Med, - direction: Direction::Left, + direction: Direction::Left }); } if let Some(m) = config.multizone.as_mut() { @@ -156,7 +156,7 @@ impl AuraConfig { colour1: *GRADIENT.get(i).unwrap_or(&GRADIENT[0]), colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]), speed: Speed::Med, - direction: Direction::Left, + direction: Direction::Left }); } if default.is_empty() { @@ -232,7 +232,7 @@ impl AuraConfig { mod tests { use rog_aura::keyboard::AuraPowerState; use rog_aura::{ - AuraEffect, AuraModeNum, AuraZone, Colour, Direction, LedBrightness, PowerZones, Speed, + AuraEffect, AuraModeNum, AuraZone, Colour, Direction, LedBrightness, PowerZones, Speed }; use super::AuraConfig; @@ -246,7 +246,7 @@ mod tests { colour1: Colour { r: 0xff, g: 0x00, - b: 0xff, + b: 0xff }, zone: AuraZone::Key1, ..Default::default() @@ -259,7 +259,7 @@ mod tests { colour1: Colour { r: 0x00, g: 0xff, - b: 0xff, + b: 0xff }, zone: AuraZone::Key2, ..Default::default() @@ -270,7 +270,7 @@ mod tests { colour1: Colour { r: 0xff, g: 0xff, - b: 0x00, + b: 0x00 }, zone: AuraZone::Key3, ..Default::default() @@ -281,7 +281,7 @@ mod tests { colour1: Colour { r: 0x00, g: 0xff, - b: 0x00, + b: 0x00 }, zone: AuraZone::Key4, ..Default::default() @@ -294,38 +294,26 @@ mod tests { let res = config.multizone.unwrap(); let sta = res.get(&AuraModeNum::Static).unwrap(); assert_eq!(sta.len(), 4); - assert_eq!( - sta[0].colour1, - Colour { - r: 0xff, - g: 0x00, - b: 0xff - } - ); - assert_eq!( - sta[1].colour1, - Colour { - r: 0x00, - g: 0xff, - b: 0xff - } - ); - assert_eq!( - sta[2].colour1, - Colour { - r: 0xff, - g: 0xff, - b: 0x00 - } - ); - assert_eq!( - sta[3].colour1, - Colour { - r: 0x00, - g: 0xff, - b: 0x00 - } - ); + assert_eq!(sta[0].colour1, Colour { + r: 0xff, + g: 0x00, + b: 0xff + }); + assert_eq!(sta[1].colour1, Colour { + r: 0x00, + g: 0xff, + b: 0xff + }); + assert_eq!(sta[2].colour1, Colour { + r: 0xff, + g: 0xff, + b: 0x00 + }); + assert_eq!(sta[3].colour1, Colour { + r: 0x00, + g: 0xff, + b: 0x00 + }); } #[test] @@ -383,28 +371,22 @@ mod tests { assert_eq!(config.brightness, LedBrightness::Med); assert_eq!(config.builtins.len(), 5); - assert_eq!( - config.builtins.first_entry().unwrap().get(), - &AuraEffect { - mode: AuraModeNum::Static, - zone: AuraZone::None, - colour1: Colour { r: 166, g: 0, b: 0 }, - colour2: Colour { r: 0, g: 0, b: 0 }, - speed: Speed::Med, - direction: Direction::Right - } - ); + assert_eq!(config.builtins.first_entry().unwrap().get(), &AuraEffect { + mode: AuraModeNum::Static, + zone: AuraZone::None, + colour1: Colour { r: 166, g: 0, b: 0 }, + colour2: Colour { r: 0, g: 0, b: 0 }, + speed: Speed::Med, + direction: Direction::Right + }); assert_eq!(config.enabled.states.len(), 1); - assert_eq!( - config.enabled.states[0], - AuraPowerState { - zone: PowerZones::KeyboardAndLightbar, - boot: true, - awake: true, - sleep: true, - shutdown: true - } - ); + assert_eq!(config.enabled.states[0], AuraPowerState { + zone: PowerZones::KeyboardAndLightbar, + boot: true, + awake: true, + sleep: true, + shutdown: true + }); } #[test] @@ -414,27 +396,21 @@ mod tests { assert_eq!(config.brightness, LedBrightness::Med); assert_eq!(config.builtins.len(), 12); - assert_eq!( - config.builtins.first_entry().unwrap().get(), - &AuraEffect { - mode: AuraModeNum::Static, - zone: AuraZone::None, - colour1: Colour { r: 166, g: 0, b: 0 }, - colour2: Colour { r: 0, g: 0, b: 0 }, - speed: Speed::Med, - direction: Direction::Right - } - ); + assert_eq!(config.builtins.first_entry().unwrap().get(), &AuraEffect { + mode: AuraModeNum::Static, + zone: AuraZone::None, + colour1: Colour { r: 166, g: 0, b: 0 }, + colour2: Colour { r: 0, g: 0, b: 0 }, + speed: Speed::Med, + direction: Direction::Right + }); assert_eq!(config.enabled.states.len(), 4); - assert_eq!( - config.enabled.states[0], - AuraPowerState { - zone: PowerZones::Keyboard, - boot: true, - awake: true, - sleep: true, - shutdown: true - } - ); + assert_eq!(config.enabled.states[0], AuraPowerState { + zone: PowerZones::Keyboard, + boot: true, + awake: true, + sleep: true, + shutdown: true + }); } } diff --git a/asusd/src/aura_laptop/mod.rs b/asusd/src/aura_laptop/mod.rs index 060a4f09..601b939d 100644 --- a/asusd/src/aura_laptop/mod.rs +++ b/asusd/src/aura_laptop/mod.rs @@ -19,7 +19,7 @@ pub mod trait_impls; pub struct Aura { pub hid: Option>>, pub backlight: Option>>, - pub config: Arc>, + pub config: Arc> } impl Aura { @@ -91,17 +91,13 @@ impl Aura { pub async fn write_effect_and_apply( &self, dev_type: AuraDeviceType, - mode: &AuraEffect, + mode: &AuraEffect ) -> Result<(), RogError> { if matches!(dev_type, AuraDeviceType::LaptopKeyboardTuf) { if let Some(platform) = &self.backlight { let buf = [ - 1, - mode.mode as u8, - mode.colour1.r, - mode.colour1.g, - mode.colour1.b, - mode.speed as u8, + 1, mode.mode as u8, mode.colour1.r, mode.colour1.g, mode.colour1.b, + mode.speed as u8 ]; platform.lock().await.set_kbd_rgb_mode(&buf)?; } @@ -125,7 +121,7 @@ impl Aura { return Ok(()); } Err(RogError::MissingFunction( - "No LED backlight control available".to_string(), + "No LED backlight control available".to_string() )) } @@ -142,14 +138,24 @@ impl Aura { let hid_raw = hid_raw.lock().await; if let Some(p) = config.enabled.states.first() { if p.zone == PowerZones::Ally { - let msg = [0x5d, 0xd1, 0x09, 0x01, p.new_to_byte() as u8, 0x0, 0x0]; + let msg = [ + 0x5d, + 0xd1, + 0x09, + 0x01, + p.new_to_byte() as u8, + 0x0, + 0x0 + ]; hid_raw.write_bytes(&msg)?; return Ok(()); } } let bytes = config.enabled.to_bytes(config.led_type); - let msg = [0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2], bytes[3]]; + let msg = [ + 0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2], bytes[3] + ]; hid_raw.write_bytes(&msg)?; } Ok(()) @@ -161,7 +167,7 @@ impl Aura { pub async fn write_effect_block( &self, config: &mut AuraConfig, - effect: &AuraLaptopUsbPackets, + effect: &AuraLaptopUsbPackets ) -> Result<(), RogError> { if config.brightness == LedBrightness::Off { config.brightness = LedBrightness::Med; @@ -194,7 +200,9 @@ impl Aura { let r = row[9]; let g = row[10]; let b = row[11]; - tuf.lock().await.set_kbd_rgb_mode(&[0, 0, r, g, b, 0])?; + tuf.lock().await.set_kbd_rgb_mode(&[ + 0, 0, r, g, b, 0 + ])?; } } } @@ -206,7 +214,9 @@ impl Aura { if let Some(hid_raw) = &self.hid { let mut config = self.config.lock().await; if config.ally_fix.is_none() { - let msg = [0x5d, 0xbd, 0x01, 0xff, 0xff, 0xff, 0xff]; + let msg = [ + 0x5d, 0xbd, 0x01, 0xff, 0xff, 0xff, 0xff + ]; hid_raw.lock().await.write_bytes(&msg)?; info!("Reset Ally power settings to base"); config.ally_fix = Some(true); diff --git a/asusd/src/aura_laptop/trait_impls.rs b/asusd/src/aura_laptop/trait_impls.rs index eee5b88f..bcb56ec6 100644 --- a/asusd/src/aura_laptop/trait_impls.rs +++ b/asusd/src/aura_laptop/trait_impls.rs @@ -28,7 +28,7 @@ impl AuraZbus { mut self, connection: &Connection, // _signal_ctx: SignalEmitter<'static>, - path: OwnedObjectPath, + path: OwnedObjectPath ) -> Result<(), RogError> { // let task = zbus.clone(); // let signal_ctx = signal_ctx.clone(); @@ -144,7 +144,7 @@ impl AuraZbus { let mode = config.current_mode; match config.builtins.get(&mode) { Some(effect) => Ok(effect.clone()), - None => Err(ZbErr::Failed("Could not get the current effect".into())), + None => Err(ZbErr::Failed("Could not get the current effect".into())) } } else { Err(ZbErr::Failed("Aura control couldn't lock self".to_string())) @@ -297,7 +297,7 @@ impl CtrlTask for AuraZbus { move |_power_plugged| { // power change async move {} - }, + } ) .await; diff --git a/asusd/src/aura_manager.rs b/asusd/src/aura_manager.rs index ca4f8212..7f7db4dc 100644 --- a/asusd/src/aura_manager.rs +++ b/asusd/src/aura_manager.rs @@ -56,7 +56,7 @@ fn dbus_path_for_dev(parent: &Device) -> Option { if let Some(filename) = filename_partial(parent) { return Some( ObjectPath::from_str_unchecked(&format!("{ASUS_ZBUS_PATH}/{MOD_NAME}/{filename}")) - .into(), + .into() ); } None @@ -91,17 +91,17 @@ fn dev_prop_matches(dev: &Device, prop: &str, value: &str) -> bool { /// required. pub struct AsusDevice { device: DeviceHandle, - dbus_path: OwnedObjectPath, + dbus_path: OwnedObjectPath } pub struct DeviceManager { - _dbus_connection: Connection, + _dbus_connection: Connection } impl DeviceManager { async fn init_hid_devices( connection: &Connection, - device: Device, + device: Device ) -> Result, RogError> { let mut devices = Vec::new(); if let Some(usb_device) = device.parent_with_subsystem_devtype("usb", "usb_device")? { @@ -122,7 +122,7 @@ impl DeviceManager { // SLASH DEVICE if let Ok(dev_type) = DeviceHandle::new_slash_hid( dev.clone(), - usb_id.to_str().unwrap_or_default(), + usb_id.to_str().unwrap_or_default() ) .await { @@ -133,14 +133,14 @@ impl DeviceManager { ctrl.start_tasks(connection, path.clone()).await.unwrap(); devices.push(AsusDevice { device: dev_type, - dbus_path: path, + dbus_path: path }); } } // ANIME MATRIX DEVICE if let Ok(dev_type) = DeviceHandle::maybe_anime_hid( dev.clone(), - usb_id.to_str().unwrap_or_default(), + usb_id.to_str().unwrap_or_default() ) .await { @@ -151,14 +151,14 @@ impl DeviceManager { ctrl.start_tasks(connection, path.clone()).await.unwrap(); devices.push(AsusDevice { device: dev_type, - dbus_path: path, + dbus_path: path }); } } // AURA LAPTOP DEVICE if let Ok(dev_type) = DeviceHandle::maybe_laptop_aura( Some(dev), - usb_id.to_str().unwrap_or_default(), + usb_id.to_str().unwrap_or_default() ) .await { @@ -169,7 +169,7 @@ impl DeviceManager { ctrl.start_tasks(connection, path.clone()).await.unwrap(); devices.push(AsusDevice { device: dev_type, - dbus_path: path, + dbus_path: path }); } } @@ -209,7 +209,7 @@ impl DeviceManager { async fn init_scsi( connection: &Connection, device: &Device, - path: OwnedObjectPath, + path: OwnedObjectPath ) -> Option { // "ID_MODEL_ID" "1932" // "ID_VENDOR_ID" "0b05" @@ -227,7 +227,7 @@ impl DeviceManager { ctrl.start_tasks(connection, path.clone()).await.unwrap(); return Some(AsusDevice { device: dev_type, - dbus_path: path, + dbus_path: path }); } } @@ -305,7 +305,7 @@ impl DeviceManager { ctrl.start_tasks(connection, path.clone()).await.unwrap(); devices.push(AsusDevice { device: dev_type, - dbus_path: path, + dbus_path: path }); } } else { @@ -322,7 +322,7 @@ impl DeviceManager { ctrl.start_tasks(connection, path.clone()).await.unwrap(); devices.push(AsusDevice { device: dev_type, - dbus_path: path, + dbus_path: path }); } } else { @@ -348,7 +348,7 @@ impl DeviceManager { ctrl.start_tasks(connection, path.clone()).await.unwrap(); devices.push(AsusDevice { device: dev_type, - dbus_path: path, + dbus_path: path }); } } @@ -366,7 +366,7 @@ impl DeviceManager { let conn_copy = connection.clone(); let devices = Arc::new(Mutex::new(Self::find_all_devices(&conn_copy).await)); let manager = Self { - _dbus_connection: connection, + _dbus_connection: connection }; // TODO: The /sysfs/ LEDs don't cause events, so they need to be manually @@ -500,7 +500,7 @@ impl DeviceManager { .remove::(&path) .await? } - _ => todo!(), + _ => todo!() }; info!("AuraManager removed: {path:?}, {res}"); } diff --git a/asusd/src/aura_scsi/config.rs b/asusd/src/aura_scsi/config.rs index 5cf77572..9416d2fd 100644 --- a/asusd/src/aura_scsi/config.rs +++ b/asusd/src/aura_scsi/config.rs @@ -14,7 +14,7 @@ pub struct ScsiConfig { pub dev_type: AuraDeviceType, pub enabled: bool, pub current_mode: AuraMode, - pub modes: BTreeMap, + pub modes: BTreeMap } impl ScsiConfig { @@ -38,61 +38,61 @@ impl Default for ScsiConfig { (AuraMode::Off, AuraEffect::default_with_mode(AuraMode::Off)), ( AuraMode::Static, - AuraEffect::default_with_mode(AuraMode::Static), + AuraEffect::default_with_mode(AuraMode::Static) ), ( AuraMode::Breathe, - AuraEffect::default_with_mode(AuraMode::Breathe), + AuraEffect::default_with_mode(AuraMode::Breathe) ), ( AuraMode::Flashing, - AuraEffect::default_with_mode(AuraMode::Flashing), + AuraEffect::default_with_mode(AuraMode::Flashing) ), ( AuraMode::RainbowCycle, - AuraEffect::default_with_mode(AuraMode::RainbowCycle), + AuraEffect::default_with_mode(AuraMode::RainbowCycle) ), ( AuraMode::RainbowWave, - AuraEffect::default_with_mode(AuraMode::RainbowWave), + AuraEffect::default_with_mode(AuraMode::RainbowWave) ), ( AuraMode::RainbowCycleBreathe, - AuraEffect::default_with_mode(AuraMode::RainbowCycleBreathe), + AuraEffect::default_with_mode(AuraMode::RainbowCycleBreathe) ), ( AuraMode::ChaseFade, - AuraEffect::default_with_mode(AuraMode::ChaseFade), + AuraEffect::default_with_mode(AuraMode::ChaseFade) ), ( AuraMode::RainbowCycleChaseFade, - AuraEffect::default_with_mode(AuraMode::RainbowCycleChaseFade), + AuraEffect::default_with_mode(AuraMode::RainbowCycleChaseFade) ), ( AuraMode::Chase, - AuraEffect::default_with_mode(AuraMode::Chase), + AuraEffect::default_with_mode(AuraMode::Chase) ), ( AuraMode::RainbowCycleChase, - AuraEffect::default_with_mode(AuraMode::RainbowCycleChase), + AuraEffect::default_with_mode(AuraMode::RainbowCycleChase) ), ( AuraMode::RainbowCycleWave, - AuraEffect::default_with_mode(AuraMode::RainbowCycleWave), + AuraEffect::default_with_mode(AuraMode::RainbowCycleWave) ), ( AuraMode::RainbowPulseChase, - AuraEffect::default_with_mode(AuraMode::RainbowPulseChase), + AuraEffect::default_with_mode(AuraMode::RainbowPulseChase) ), ( AuraMode::RandomFlicker, - AuraEffect::default_with_mode(AuraMode::RandomFlicker), + AuraEffect::default_with_mode(AuraMode::RandomFlicker) ), ( AuraMode::DoubleFade, - AuraEffect::default_with_mode(AuraMode::DoubleFade), - ), - ]), + AuraEffect::default_with_mode(AuraMode::DoubleFade) + ) + ]) } } } diff --git a/asusd/src/aura_scsi/mod.rs b/asusd/src/aura_scsi/mod.rs index 486d8cfa..73f05a18 100644 --- a/asusd/src/aura_scsi/mod.rs +++ b/asusd/src/aura_scsi/mod.rs @@ -12,7 +12,7 @@ pub mod trait_impls; #[derive(Clone)] pub struct ScsiAura { device: Arc>, - config: Arc>, + config: Arc> } impl ScsiAura { diff --git a/asusd/src/aura_scsi/trait_impls.rs b/asusd/src/aura_scsi/trait_impls.rs index 7345dc28..20fa31de 100644 --- a/asusd/src/aura_scsi/trait_impls.rs +++ b/asusd/src/aura_scsi/trait_impls.rs @@ -22,7 +22,7 @@ impl ScsiZbus { pub async fn start_tasks( self, connection: &Connection, - path: OwnedObjectPath, + path: OwnedObjectPath ) -> Result<(), RogError> { connection .object_server() @@ -87,7 +87,7 @@ impl ScsiZbus { let mode = config.current_mode; match config.modes.get(&mode) { Some(effect) => Ok(effect.clone()), - None => Err(ZbErr::Failed("Could not get the current effect".into())), + None => Err(ZbErr::Failed("Could not get the current effect".into())) } } else { Err(ZbErr::Failed("Aura control couldn't lock self".to_string())) diff --git a/asusd/src/aura_slash/config.rs b/asusd/src/aura_slash/config.rs index b05e664a..8aa02ed5 100644 --- a/asusd/src/aura_slash/config.rs +++ b/asusd/src/aura_slash/config.rs @@ -9,20 +9,30 @@ const CONFIG_FILE: &str = "slash.ron"; pub struct SlashConfig { #[serde(skip)] pub slash_type: SlashType, - pub slash_enabled: bool, - pub slash_brightness: u8, - pub slash_interval: u8, - pub slash_mode: SlashMode, + pub enabled: bool, + pub brightness: u8, + pub display_interval: u8, + pub display_mode: SlashMode, + pub show_on_boot: bool, + pub show_on_shutdown: bool, + pub show_on_sleep: bool, + pub show_on_battery: bool, + pub show_battery_warning: bool } impl Default for SlashConfig { fn default() -> Self { SlashConfig { - slash_enabled: true, - slash_brightness: 255, - slash_interval: 0, - slash_mode: SlashMode::Bounce, + enabled: true, + brightness: 255, + display_interval: 0, + display_mode: SlashMode::Bounce, slash_type: SlashType::Unsupported, + show_on_boot: true, + show_on_shutdown: true, + show_on_sleep: true, + show_on_battery: true, + show_battery_warning: true } } } @@ -45,10 +55,10 @@ impl StdConfigLoad for SlashConfig {} impl From<&SlashConfig> for DeviceState { fn from(config: &SlashConfig) -> Self { DeviceState { - slash_enabled: config.slash_enabled, - slash_brightness: config.slash_brightness, - slash_interval: config.slash_interval, - slash_mode: config.slash_mode, + slash_enabled: config.enabled, + slash_brightness: config.brightness, + slash_interval: config.display_interval, + slash_mode: config.display_mode } } } diff --git a/asusd/src/aura_slash/mod.rs b/asusd/src/aura_slash/mod.rs index 904118aa..8d66e503 100644 --- a/asusd/src/aura_slash/mod.rs +++ b/asusd/src/aura_slash/mod.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use config::SlashConfig; use rog_platform::hid_raw::HidRaw; use rog_platform::usb_raw::USBRaw; -use rog_slash::usb::{pkt_set_mode, pkt_set_options, pkts_for_init}; +use rog_slash::usb::{get_options_packet, pkt_set_mode, pkts_for_init}; use rog_slash::SlashType; use tokio::sync::{Mutex, MutexGuard}; @@ -16,14 +16,14 @@ pub mod trait_impls; pub struct Slash { hid: Option>>, usb: Option>>, - config: Arc>, + config: Arc> } impl Slash { pub fn new( hid: Option>>, usb: Option>>, - config: Arc>, + config: Arc> ) -> Self { Self { hid, usb, config } } @@ -53,15 +53,15 @@ impl Slash { } // Apply config upon initialization - let option_packets = pkt_set_options( + let option_packets = get_options_packet( config.slash_type, - config.slash_enabled, - config.slash_brightness, - config.slash_interval, + config.enabled, + config.brightness, + config.display_interval ); self.write_bytes(&option_packets).await?; - let mode_packets = pkt_set_mode(config.slash_type, config.slash_mode); + let mode_packets = pkt_set_mode(config.slash_type, config.display_mode); // self.node.write_bytes(&mode_packets[0])?; self.write_bytes(&mode_packets[1]).await?; diff --git a/asusd/src/aura_slash/trait_impls.rs b/asusd/src/aura_slash/trait_impls.rs index 92efa129..669993cf 100644 --- a/asusd/src/aura_slash/trait_impls.rs +++ b/asusd/src/aura_slash/trait_impls.rs @@ -1,6 +1,9 @@ use config_traits::StdConfig; use log::{debug, error, warn}; -use rog_slash::usb::{pkt_save, pkt_set_mode, pkt_set_options}; +use rog_slash::usb::{ + get_battery_saver_packet, get_boot_packet, get_low_battery_packet, get_options_packet, + get_shutdown_packet, get_sleep_packet, pkt_save, pkt_set_mode +}; use rog_slash::{DeviceState, SlashMode}; use zbus::zvariant::OwnedObjectPath; use zbus::{interface, Connection}; @@ -20,7 +23,7 @@ impl SlashZbus { pub async fn start_tasks( mut self, connection: &Connection, - path: OwnedObjectPath, + path: OwnedObjectPath ) -> Result<(), RogError> { // let task = zbus.clone(); self.reload() @@ -42,24 +45,24 @@ impl SlashZbus { #[zbus(property)] async fn enabled(&self) -> bool { let lock = self.0.lock_config().await; - lock.slash_enabled + lock.enabled } /// Set enabled true or false #[zbus(property)] async fn set_enabled(&self, enabled: bool) { let mut config = self.0.lock_config().await; - let brightness = if enabled && config.slash_brightness == 0 { + let brightness = if enabled && config.brightness == 0 { 0x88 } else { - config.slash_brightness + config.brightness }; self.0 - .write_bytes(&pkt_set_options( + .write_bytes(&get_options_packet( config.slash_type, enabled, brightness, - config.slash_interval, + config.display_interval )) .await .map_err(|err| { @@ -67,8 +70,8 @@ impl SlashZbus { }) .ok(); - config.slash_enabled = enabled; - config.slash_brightness = brightness; + config.enabled = enabled; + config.brightness = brightness; config.write(); } @@ -76,7 +79,7 @@ impl SlashZbus { #[zbus(property)] async fn brightness(&self) -> u8 { let config = self.0.lock_config().await; - config.slash_brightness + config.brightness } /// Set brightness level @@ -85,11 +88,11 @@ impl SlashZbus { let mut config = self.0.lock_config().await; let enabled = brightness > 0; self.0 - .write_bytes(&pkt_set_options( + .write_bytes(&get_options_packet( config.slash_type, enabled, brightness, - config.slash_interval, + config.display_interval )) .await .map_err(|err| { @@ -97,15 +100,15 @@ impl SlashZbus { }) .ok(); - config.slash_enabled = enabled; - config.slash_brightness = brightness; + config.enabled = enabled; + config.brightness = brightness; config.write(); } #[zbus(property)] async fn interval(&self) -> u8 { let config = self.0.lock_config().await; - config.slash_interval + config.display_interval } /// Set interval between slash animations (0-255) @@ -113,11 +116,8 @@ impl SlashZbus { async fn set_interval(&self, interval: u8) { let mut config = self.0.lock_config().await; self.0 - .write_bytes(&pkt_set_options( - config.slash_type, - config.slash_enabled, - config.slash_brightness, - interval, + .write_bytes(&get_options_packet( + config.slash_type, config.enabled, config.brightness, interval )) .await .map_err(|err| { @@ -125,40 +125,29 @@ impl SlashZbus { }) .ok(); - config.slash_interval = interval; + config.display_interval = interval; config.write(); } #[zbus(property)] - async fn slash_mode(&self) -> u8 { + async fn mode(&self) -> zbus::fdo::Result { let config = self.0.lock_config().await; - config.slash_interval + Ok(config.display_interval) } /// Set interval between slash animations (0-255) #[zbus(property)] - async fn set_slash_mode(&self, slash_mode: SlashMode) { + async fn set_mode(&self, mode: SlashMode) -> zbus::Result<()> { let mut config = self.0.lock_config().await; - let command_packets = pkt_set_mode(config.slash_type, slash_mode); + let command_packets = pkt_set_mode(config.slash_type, mode); // self.node.write_bytes(&command_packets[0])?; - self.0 - .write_bytes(&command_packets[1]) - .await - .map_err(|err| { - warn!("ctrl_slash::set_options {}", err); - }) - .ok(); - self.0 - .write_bytes(&pkt_save(config.slash_type)) - .await - .map_err(|err| { - warn!("ctrl_slash::set_options {}", err); - }) - .ok(); + self.0.write_bytes(&command_packets[1]).await?; + self.0.write_bytes(&pkt_save(config.slash_type)).await?; - config.slash_mode = slash_mode; + config.display_mode = mode; config.write(); + Ok(()) } /// Get the device state as stored by asusd @@ -167,6 +156,91 @@ impl SlashZbus { let config = self.0.lock_config().await; DeviceState::from(&*config) } + + #[zbus(property)] + async fn show_on_boot(&self) -> zbus::fdo::Result { + let config = self.0.lock_config().await; + Ok(config.show_on_boot) + } + + #[zbus(property)] + async fn set_show_on_boot(&self, enable: bool) -> zbus::Result<()> { + let mut config = self.0.lock_config().await; + self.0 + .write_bytes(&get_boot_packet(config.slash_type, enable)) + .await?; + config.show_on_boot = enable; + config.write(); + Ok(()) + } + + #[zbus(property)] + async fn show_on_sleep(&self) -> zbus::fdo::Result { + let config = self.0.lock_config().await; + Ok(config.show_on_sleep) + } + + #[zbus(property)] + async fn set_show_on_sleep(&self, enable: bool) -> zbus::Result<()> { + let mut config = self.0.lock_config().await; + self.0 + .write_bytes(&get_sleep_packet(config.slash_type, enable)) + .await?; + config.show_on_sleep = enable; + config.write(); + Ok(()) + } + + #[zbus(property)] + async fn show_on_shutdown(&self) -> zbus::fdo::Result { + let config = self.0.lock_config().await; + Ok(config.show_on_shutdown) + } + + #[zbus(property)] + async fn set_show_on_shutdown(&self, enable: bool) -> zbus::Result<()> { + let mut config = self.0.lock_config().await; + self.0 + .write_bytes(&get_shutdown_packet(config.slash_type, enable)) + .await?; + config.show_on_shutdown = enable; + config.write(); + Ok(()) + } + + #[zbus(property)] + async fn show_on_battery(&self) -> zbus::fdo::Result { + let config = self.0.lock_config().await; + Ok(config.show_on_battery) + } + + #[zbus(property)] + async fn set_show_on_battery(&self, enable: bool) -> zbus::Result<()> { + let mut config = self.0.lock_config().await; + self.0 + .write_bytes(&get_battery_saver_packet(config.slash_type, enable)) + .await?; + config.show_on_battery = enable; + config.write(); + Ok(()) + } + + #[zbus(property)] + async fn show_battery_warning(&self) -> zbus::fdo::Result { + let config = self.0.lock_config().await; + Ok(config.show_battery_warning) + } + + #[zbus(property)] + async fn set_show_battery_warning(&self, enable: bool) -> zbus::Result<()> { + let mut config = self.0.lock_config().await; + self.0 + .write_bytes(&get_low_battery_packet(config.slash_type, enable)) + .await?; + config.show_battery_warning = enable; + config.write(); + Ok(()) + } } impl Reloadable for SlashZbus { @@ -174,17 +248,40 @@ impl Reloadable for SlashZbus { debug!("reloading slash settings"); let config = self.0.lock_config().await; self.0 - .write_bytes(&pkt_set_options( + .write_bytes(&get_options_packet( config.slash_type, - config.slash_enabled, - config.slash_brightness, - config.slash_interval, + config.enabled, + config.brightness, + config.display_interval )) .await .map_err(|err| { - warn!("ctrl_slash::set_options {}", err); + warn!("set_options {}", err); }) .ok(); + + macro_rules! write_bytes_with_warning { + ($packet_fn:expr, $cfg:ident, $warn_msg:expr) => { + self.0 + .write_bytes(&$packet_fn(config.slash_type, config.$cfg)) + .await + .map_err(|err| { + warn!("{} {}", $warn_msg, err); + }) + .ok(); + }; + } + + write_bytes_with_warning!(get_boot_packet, show_on_boot, "show_on_boot"); + write_bytes_with_warning!(get_sleep_packet, show_on_sleep, "show_on_sleep"); + write_bytes_with_warning!(get_shutdown_packet, show_on_shutdown, "show_on_shutdown"); + write_bytes_with_warning!(get_battery_saver_packet, show_on_battery, "show_on_battery"); + write_bytes_with_warning!( + get_low_battery_packet, + show_battery_warning, + "show_battery_warning" + ); + Ok(()) } } diff --git a/asusd/src/aura_types.rs b/asusd/src/aura_types.rs index edc75e43..ef52507f 100644 --- a/asusd/src/aura_types.rs +++ b/asusd/src/aura_types.rs @@ -31,7 +31,7 @@ pub enum _DeviceHandle { LedClass(KeyboardBacklight), /// TODO MulticolourLed, - None, + None } #[derive(Clone)] @@ -47,14 +47,14 @@ pub enum DeviceHandle { TufLedClass(Arc>), /// TODO MulticolourLed, - None, + None } impl DeviceHandle { /// Try Slash HID. If one exists it is initialsed and returned. pub async fn new_slash_hid( device: Arc>, - prod_id: &str, + prod_id: &str ) -> Result { debug!("Testing for HIDRAW Slash"); let slash_type = SlashType::from_dmi(); @@ -93,7 +93,7 @@ impl DeviceHandle { let slash = Slash::new( None, Some(Arc::new(Mutex::new(usb))), - Arc::new(Mutex::new(config)), + Arc::new(Mutex::new(config)) ); slash.do_initialization().await?; Ok(Self::Slash(slash)) @@ -105,7 +105,7 @@ impl DeviceHandle { /// Try AniMe Matrix HID. If one exists it is initialsed and returned. pub async fn maybe_anime_hid( device: Arc>, - prod_id: &str, + prod_id: &str ) -> Result { debug!("Testing for HIDRAW AniMe"); let anime_type = AnimeType::from_dmi(); @@ -139,13 +139,13 @@ impl DeviceHandle { let mut anime = AniMe::new( None, Some(Arc::new(Mutex::new(usb))), - Arc::new(Mutex::new(config)), + Arc::new(Mutex::new(config)) ); anime.do_initialization().await?; Ok(Self::AniMe(anime)) } else { Err(RogError::NotFound( - "No AnimeMatrix device found".to_string(), + "No AnimeMatrix device found".to_string() )) } } @@ -169,7 +169,7 @@ impl DeviceHandle { pub async fn maybe_laptop_aura( device: Option>>, - prod_id: &str, + prod_id: &str ) -> Result { debug!("Testing for laptop aura"); let aura_type = AuraDeviceType::from(prod_id); @@ -196,7 +196,7 @@ impl DeviceHandle { let aura = Aura { hid: device, backlight, - config: Arc::new(Mutex::new(config)), + config: Arc::new(Mutex::new(config)) }; aura.do_initialization().await?; Ok(Self::Aura(aura)) diff --git a/asusd/src/config.rs b/asusd/src/config.rs index 7ffd710f..c4489e5c 100644 --- a/asusd/src/config.rs +++ b/asusd/src/config.rs @@ -60,7 +60,7 @@ pub struct Config { pub nv_temp_target: Option, /// Temporary state for AC/Batt #[serde(skip)] - pub last_power_plugged: u8, + pub last_power_plugged: u8 } impl Default for Config { @@ -89,7 +89,7 @@ impl Default for Config { ppt_platform_sppt: Default::default(), nv_dynamic_boost: Default::default(), nv_temp_target: Default::default(), - last_power_plugged: Default::default(), + last_power_plugged: Default::default() } } } @@ -137,7 +137,7 @@ pub struct Config507 { pub ppt_apu_sppt: Option, pub ppt_platform_sppt: Option, pub nv_dynamic_boost: Option, - pub nv_temp_target: Option, + pub nv_temp_target: Option } impl From for Config { @@ -167,7 +167,7 @@ impl From for Config { ppt_platform_sppt: c.ppt_platform_sppt, nv_dynamic_boost: c.nv_dynamic_boost, nv_temp_target: c.nv_temp_target, - last_power_plugged: 0, + last_power_plugged: 0 } } } diff --git a/asusd/src/ctrl_fancurves.rs b/asusd/src/ctrl_fancurves.rs index 7b7f6c1d..30ad9226 100644 --- a/asusd/src/ctrl_fancurves.rs +++ b/asusd/src/ctrl_fancurves.rs @@ -23,7 +23,7 @@ pub const FAN_CURVE_ZBUS_PATH: &str = "/xyz/ljones"; pub struct FanCurveConfig { pub profiles: FanCurveProfiles, #[serde(skip)] - pub current: u8, + pub current: u8 } impl StdConfig for FanCurveConfig { @@ -47,7 +47,7 @@ impl StdConfigLoad for FanCurveConfig {} #[derive(Debug, Clone)] pub struct CtrlFanCurveZbus { config: Arc>, - platform: RogPlatform, + platform: RogPlatform } // Non-zbus-derive impl @@ -69,7 +69,7 @@ impl CtrlFanCurveZbus { for this in [ ThrottlePolicy::Balanced, ThrottlePolicy::Performance, - ThrottlePolicy::Quiet, + ThrottlePolicy::Quiet ] { // For each profile we need to switch to it before we // can read the existing values from hardware. The ACPI method used @@ -93,7 +93,7 @@ impl CtrlFanCurveZbus { return Ok(Self { config: Arc::new(Mutex::new(config)), - platform, + platform }); } @@ -108,7 +108,7 @@ impl CtrlFanCurveZbus { async fn set_fan_curves_enabled( &mut self, profile: ThrottlePolicy, - enabled: bool, + enabled: bool ) -> zbus::fdo::Result<()> { self.config .lock() @@ -130,7 +130,7 @@ impl CtrlFanCurveZbus { &mut self, profile: ThrottlePolicy, fan: FanCurvePU, - enabled: bool, + enabled: bool ) -> zbus::fdo::Result<()> { self.config .lock() @@ -149,7 +149,7 @@ impl CtrlFanCurveZbus { /// Get the fan-curve data for the currently active ThrottlePolicy async fn fan_curve_data( &mut self, - profile: ThrottlePolicy, + profile: ThrottlePolicy ) -> zbus::fdo::Result> { let curve = self .config @@ -166,7 +166,7 @@ impl CtrlFanCurveZbus { async fn set_fan_curve( &mut self, profile: ThrottlePolicy, - curve: CurveData, + curve: CurveData ) -> zbus::fdo::Result<()> { self.config .lock() @@ -256,7 +256,7 @@ impl CtrlTask for CtrlFanCurveZbus { .profiles .write_profile_curve_to_platform( profile.into(), - &mut find_fan_curve_node().unwrap(), + &mut find_fan_curve_node().unwrap() ) .map_err(|e| warn!("write_profile_curve_to_platform, {}", e)) .ok(); diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index 4dc23fab..e93273bd 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -86,14 +86,14 @@ pub struct CtrlPlatform { power: AsusPower, platform: RogPlatform, cpu_control: Option, - config: Arc>, + config: Arc> } impl CtrlPlatform { pub fn new( config: Arc>, config_path: &Path, - signal_context: SignalEmitter<'static>, + signal_context: SignalEmitter<'static> ) -> Result { let platform = RogPlatform::new()?; let power = AsusPower::new()?; @@ -112,7 +112,7 @@ impl CtrlPlatform { config, cpu_control: CPUControl::new() .map_err(|e| error!("Couldn't get CPU control sysfs: {e}")) - .ok(), + .ok() }; let mut inotify_self = ret_self.clone(); @@ -131,7 +131,7 @@ impl CtrlPlatform { inotify::WatchMask::MODIFY | inotify::WatchMask::CLOSE_WRITE | inotify::WatchMask::ATTRIB - | inotify::WatchMask::CREATE, + | inotify::WatchMask::CREATE ) .inspect_err(|e| { if e.kind() == std::io::ErrorKind::NotFound { @@ -184,7 +184,7 @@ impl CtrlPlatform { if limit > 0 && std::mem::replace( &mut self.config.lock().await.charge_control_end_threshold, - limit, + limit ) != limit { self.power @@ -266,7 +266,7 @@ impl CtrlPlatform { match throttle { ThrottlePolicy::Balanced => self.config.lock().await.throttle_balanced_epp, ThrottlePolicy::Performance => self.config.lock().await.throttle_performance_epp, - ThrottlePolicy::Quiet => self.config.lock().await.throttle_quiet_epp, + ThrottlePolicy::Quiet => self.config.lock().await.throttle_quiet_epp } } @@ -377,7 +377,7 @@ impl CtrlPlatform { async fn one_shot_full_charge(&self) -> Result<(), FdoErr> { let base_limit = std::mem::replace( &mut self.config.lock().await.charge_control_end_threshold, - 100, + 100 ); if base_limit != 100 { self.power.set_charge_control_end_threshold(100)?; @@ -405,7 +405,7 @@ impl CtrlPlatform { self.config.lock().await.write(); } else { return Err(FdoErr::NotSupported( - "RogPlatform: set_gpu_mux_mode not supported".to_owned(), + "RogPlatform: set_gpu_mux_mode not supported".to_owned() )); } Ok(()) @@ -415,7 +415,7 @@ impl CtrlPlatform { /// If fan-curves are supported will also activate a fan curve for profile. async fn next_throttle_thermal_policy( &mut self, - #[zbus(signal_context)] ctxt: SignalEmitter<'_>, + #[zbus(signal_context)] ctxt: SignalEmitter<'_> ) -> Result<(), FdoErr> { let policy: ThrottlePolicy = platform_get_value!(self, throttle_thermal_policy, "throttle_thermal_policy") @@ -435,7 +435,7 @@ impl CtrlPlatform { Ok(self.throttle_thermal_policy_changed(&ctxt).await?) } else { Err(FdoErr::NotSupported( - "RogPlatform: throttle_thermal_policy not supported".to_owned(), + "RogPlatform: throttle_thermal_policy not supported".to_owned() )) } } @@ -462,7 +462,7 @@ impl CtrlPlatform { }) } else { Err(FdoErr::NotSupported( - "RogPlatform: throttle_thermal_policy not supported".to_owned(), + "RogPlatform: throttle_thermal_policy not supported".to_owned() )) } } @@ -487,7 +487,7 @@ impl CtrlPlatform { #[zbus(property)] async fn set_throttle_policy_on_battery( &mut self, - policy: ThrottlePolicy, + policy: ThrottlePolicy ) -> Result<(), FdoErr> { self.config.lock().await.throttle_policy_on_battery = policy; self.set_throttle_thermal_policy(policy).await?; @@ -747,7 +747,7 @@ impl ReloadAndNotify for CtrlPlatform { async fn reload_and_notify( &mut self, signal_context: &SignalEmitter<'static>, - data: Self::Data, + data: Self::Data ) -> Result<(), RogError> { let mut config = self.config.lock().await; if *config != data { @@ -949,7 +949,7 @@ impl CtrlTask for CtrlPlatform { platform1 .power .set_charge_control_end_threshold( - platform1.config.lock().await.charge_control_end_threshold, + platform1.config.lock().await.charge_control_end_threshold ) .ok(); } @@ -994,7 +994,7 @@ impl CtrlTask for CtrlPlatform { platform2 .power .set_charge_control_end_threshold( - lock.base_charge_control_end_threshold, + lock.base_charge_control_end_threshold ) .map_err(|err| { warn!("CtrlCharge: charge_control_end_threshold {}", err); @@ -1024,7 +1024,7 @@ impl CtrlTask for CtrlPlatform { platform3.restore_charge_limit().await; } } - }, + } ) .await; diff --git a/asusd/src/daemon.rs b/asusd/src/daemon.rs index ff5d658f..55600e54 100644 --- a/asusd/src/daemon.rs +++ b/asusd/src/daemon.rs @@ -27,7 +27,7 @@ async fn main() -> Result<(), Box> { let is_service = match env::var_os("IS_SERVICE") { Some(val) => val == "1", - None => true, + None => true }; if !is_service { @@ -80,7 +80,7 @@ async fn start_daemon() -> Result<(), Box> { match CtrlPlatform::new( config.clone(), &cfg_path, - CtrlPlatform::signal_context(&server)?, + CtrlPlatform::signal_context(&server)? ) { Ok(ctrl) => { let sig_ctx = CtrlPlatform::signal_context(&server)?; diff --git a/asusd/src/error.rs b/asusd/src/error.rs index 601aab95..eacb21f3 100644 --- a/asusd/src/error.rs +++ b/asusd/src/error.rs @@ -37,7 +37,7 @@ pub enum RogError { SystemdUnitAction(String), SystemdUnitWaitTimeout(String), Command(String, std::io::Error), - ParseRon(ron::Error), + ParseRon(ron::Error) } impl fmt::Display for RogError { @@ -87,7 +87,7 @@ impl fmt::Display for RogError { ) } RogError::Command(func, error) => write!(f, "Command exec error: {}: {}", func, error), - RogError::ParseRon(error) => write!(f, "Parse config error: {}", error), + RogError::ParseRon(error) => write!(f, "Parse config error: {}", error) } } } @@ -142,3 +142,10 @@ impl From for zbus::fdo::Error { zbus::fdo::Error::Failed(format!("{}", err)) } } + +impl From for zbus::Error { + #[inline] + fn from(err: RogError) -> Self { + zbus::Error::Failure(format!("{}", err)) + } +} diff --git a/asusd/src/lib.rs b/asusd/src/lib.rs index 8272d617..acb26613 100644 --- a/asusd/src/lib.rs +++ b/asusd/src/lib.rs @@ -149,7 +149,7 @@ pub trait ReloadAndNotify { fn reload_and_notify( &mut self, signal_context: &SignalEmitter<'static>, - data: Self::Data, + data: Self::Data ) -> impl Future> + Send; } @@ -159,7 +159,7 @@ pub trait ZbusRun { fn add_to_server_helper( iface: impl Interface, path: &str, - server: &mut Connection, + server: &mut Connection ) -> impl Future + Send { async move { server @@ -188,7 +188,7 @@ pub trait CtrlTask { /// separate thread. fn create_tasks( &self, - signal: SignalEmitter<'static>, + signal: SignalEmitter<'static> ) -> impl Future> + Send; // /// Create a timed repeating task @@ -212,7 +212,7 @@ pub trait CtrlTask { mut on_prepare_for_sleep: F1, mut on_prepare_for_shutdown: F2, mut on_lid_change: F3, - mut on_external_power_change: F4, + mut on_external_power_change: F4 ) -> impl Future + Send where F1: FnMut(bool) -> Fut1 + Send + 'static, @@ -222,7 +222,7 @@ pub trait CtrlTask { Fut1: Future + Send, Fut2: Future + Send, Fut3: Future + Send, - Fut4: Future + Send, + Fut4: Future + Send { async { let connection = Connection::system() @@ -302,10 +302,10 @@ pub trait GetSupported { pub async fn start_tasks( mut zbus: T, connection: &mut Connection, - signal_ctx: SignalEmitter<'static>, + signal_ctx: SignalEmitter<'static> ) -> Result<(), RogError> where - T: ZbusRun + Reloadable + CtrlTask + Clone, + T: ZbusRun + Reloadable + CtrlTask + Clone { let zbus_clone = zbus.clone(); diff --git a/config-traits/src/lib.rs b/config-traits/src/lib.rs index 7ff7053a..f9b61113 100644 --- a/config-traits/src/lib.rs +++ b/config-traits/src/lib.rs @@ -19,7 +19,7 @@ use serde::Serialize; /// implemented, the rest are intended to be free methods. pub trait StdConfig where - Self: Serialize + DeserializeOwned, + Self: Serialize + DeserializeOwned { /// Taking over the standard `new()` to ensure things can be generic fn new() -> Self; diff --git a/dmi-id/src/lib.rs b/dmi-id/src/lib.rs index faa28813..571782c5 100644 --- a/dmi-id/src/lib.rs +++ b/dmi-id/src/lib.rs @@ -12,7 +12,7 @@ pub struct DMIID { pub bios_vendor: String, pub bios_version: String, pub product_family: String, - pub product_name: String, + pub product_name: String } impl DMIID { @@ -77,7 +77,7 @@ impl DMIID { product_name: device .attribute_value("product_name") .map(|s| s.to_string_lossy().to_string()) - .unwrap_or("Unknown".to_string()), + .unwrap_or("Unknown".to_string()) }); } Err("dmi not found".into()) diff --git a/rog-anime/src/data.rs b/rog-anime/src/data.rs index 48ac3232..7059dc1c 100644 --- a/rog-anime/src/data.rs +++ b/rog-anime/src/data.rs @@ -22,11 +22,17 @@ const BLOCK_END: usize = 634; const PANE_LEN: usize = BLOCK_END - BLOCK_START; /// First packet is for GA401 + GA402 -pub const USB_PREFIX1: [u8; 7] = [0x5e, 0xc0, 0x02, 0x01, 0x00, 0x73, 0x02]; +pub const USB_PREFIX1: [u8; 7] = [ + 0x5e, 0xc0, 0x02, 0x01, 0x00, 0x73, 0x02 +]; /// Second packet is for GA401 + GA402 -pub const USB_PREFIX2: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02]; +pub const USB_PREFIX2: [u8; 7] = [ + 0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02 +]; /// Third packet is for GA402 matrix -pub const USB_PREFIX3: [u8; 7] = [0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02]; +pub const USB_PREFIX3: [u8; 7] = [ + 0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02 +]; #[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))] #[derive(Default, Deserialize, PartialEq, Eq, Clone, Copy, Serialize, Debug)] @@ -34,7 +40,7 @@ pub struct Animations { pub boot: AnimBooting, pub awake: AnimAwake, pub sleep: AnimSleeping, - pub shutdown: AnimShutdown, + pub shutdown: AnimShutdown } // TODO: move this out @@ -48,7 +54,7 @@ pub struct DeviceState { pub off_when_unplugged: bool, pub off_when_suspended: bool, pub off_when_lid_closed: bool, - pub brightness_on_battery: Brightness, + pub brightness_on_battery: Brightness } #[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] @@ -58,7 +64,7 @@ pub enum AnimeType { GA402, GU604, #[default] - Unsupported, + Unsupported } impl FromStr for AnimeType { @@ -69,7 +75,7 @@ impl FromStr for AnimeType { "ga401" | "GA401" => Self::GA401, "ga402" | "GA402" => Self::GA402, "gu604" | "GU604" => Self::GU604, - _ => Self::Unsupported, + _ => Self::Unsupported }) } } @@ -92,7 +98,7 @@ impl AnimeType { pub fn width(&self) -> usize { match self { AnimeType::GU604 => 70, - _ => 74, + _ => 74 } } @@ -101,7 +107,7 @@ impl AnimeType { match self { AnimeType::GA401 => 36, AnimeType::GU604 => 43, - _ => 39, + _ => 39 } } @@ -110,7 +116,7 @@ impl AnimeType { match self { AnimeType::GA401 => PANE_LEN * 2, AnimeType::GU604 => PANE_LEN * 3, - _ => PANE_LEN * 3, + _ => PANE_LEN * 3 } } } @@ -121,7 +127,7 @@ impl AnimeType { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct AnimeDataBuffer { data: Vec, - anime: AnimeType, + anime: AnimeType } impl AnimeDataBuffer { @@ -131,7 +137,7 @@ impl AnimeDataBuffer { AnimeDataBuffer { data: vec![0u8; len], - anime, + anime } } @@ -174,7 +180,7 @@ impl TryFrom for AnimePacketType { let mut buffers = match anime.anime { AnimeType::GA401 => vec![[0; 640]; 2], - AnimeType::GA402 | AnimeType::GU604 | AnimeType::Unsupported => vec![[0; 640]; 3], + AnimeType::GA402 | AnimeType::GU604 | AnimeType::Unsupported => vec![[0; 640]; 3] }; for (idx, chunk) in anime.data.as_slice().chunks(PANE_LEN).enumerate() { diff --git a/rog-anime/src/diagonal.rs b/rog-anime/src/diagonal.rs index a71f9f99..ad1224c5 100644 --- a/rog-anime/src/diagonal.rs +++ b/rog-anime/src/diagonal.rs @@ -20,7 +20,7 @@ impl AnimeDiagonal { Self( anime_type, vec![vec![0; anime_type.width()]; anime_type.height()], - duration, + duration ) } @@ -49,7 +49,7 @@ impl AnimeDiagonal { path: &Path, duration: Option, bright: f32, - anime_type: AnimeType, + anime_type: AnimeType ) -> Result { let data = std::fs::read(path).map_err(|e| { error!("Could not open {path:?}: {e:?}"); @@ -86,7 +86,7 @@ impl AnimeDiagonal { png_pong::PngRaster::Rgba16(ras) => { Self::pixels_from_16bit(ras, &mut matrix, bright, false); } - png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format), + png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format) }; Ok(matrix) @@ -96,9 +96,9 @@ impl AnimeDiagonal { ras: &pix::Raster

, matrix: &mut AnimeDiagonal, bright: f32, - grey: bool, + grey: bool ) where - P: pix::el::Pixel, + P: pix::el::Pixel { let width = ras.width(); for (y, row) in ras.pixels().chunks(width as usize).enumerate() { @@ -121,9 +121,9 @@ impl AnimeDiagonal { ras: &pix::Raster

, matrix: &mut AnimeDiagonal, bright: f32, - grey: bool, + grey: bool ) where - P: pix::el::Pixel, + P: pix::el::Pixel { let width = ras.width(); for (y, row) in ras.pixels().chunks(width as usize).enumerate() { @@ -146,7 +146,7 @@ impl AnimeDiagonal { match anime_type { AnimeType::GA401 => self.to_ga401_packets(), AnimeType::GU604 => self.to_gu604_packets(), - _ => self.to_ga402_packets(), + _ => self.to_ga402_packets() } } @@ -224,7 +224,7 @@ impl AnimeDiagonal { x: usize, y: usize, start_index: &mut usize, - len: usize, + len: usize ) { buf[*start_index..*start_index + len].copy_from_slice(&anime.get_row(x, y, len)); *start_index += len; @@ -307,7 +307,7 @@ impl AnimeDiagonal { x: usize, y: usize, start_index: &mut usize, - len: usize, + len: usize ) { buf[*start_index..*start_index + len].copy_from_slice(&anime.get_row(x, y, len)); *start_index += len; diff --git a/rog-anime/src/error.rs b/rog-anime/src/error.rs index 49f17c86..cd9c256b 100644 --- a/rog-anime/src/error.rs +++ b/rog-anime/src/error.rs @@ -24,7 +24,7 @@ pub enum AnimeError { DataBufferLength, PixelGifWidth(usize), PixelGifHeight(usize), - ParseError(String), + ParseError(String) } impl fmt::Display for AnimeError { @@ -61,7 +61,7 @@ impl fmt::Display for AnimeError { AnimeError::PixelGifHeight(n) => write!( f, "The gif used for pixel-perfect gif is is taller than {n}" - ), + ) } } } diff --git a/rog-anime/src/gif.rs b/rog-anime/src/gif.rs index 60927b3f..786f3ab5 100644 --- a/rog-anime/src/gif.rs +++ b/rog-anime/src/gif.rs @@ -16,7 +16,7 @@ pub struct AnimeFrame { /// the `asusd` daemon over dbus or converted to USB packet with /// `AnimePacketType::from(buffer)` data: AnimeDataBuffer, - delay: Duration, + delay: Duration } impl AnimeFrame { @@ -44,7 +44,7 @@ pub enum AnimTime { /// Run for infinite time Infinite, /// Fade in, play for, fade out - Fade(Fade), + Fade(Fade) } impl Default for AnimTime { @@ -59,7 +59,7 @@ impl Default for AnimTime { pub struct Fade { fade_in: Duration, show_for: Option, - fade_out: Duration, + fade_out: Duration } impl Fade { @@ -67,7 +67,7 @@ impl Fade { Self { fade_in, show_for, - fade_out, + fade_out } } @@ -100,7 +100,7 @@ impl AnimeGif { file_name: &Path, duration: AnimTime, brightness: f32, - anime_type: AnimeType, + anime_type: AnimeType ) -> Result { let mut matrix = AnimeDiagonal::new(anime_type, None); @@ -142,7 +142,7 @@ impl AnimeGif { frames.push(AnimeFrame { data: matrix.into_data_buffer(anime_type)?, - delay: Duration::from_millis(wait as u64), + delay: Duration::from_millis(wait as u64) }); } Ok(Self(frames, duration)) @@ -154,7 +154,7 @@ impl AnimeGif { file_name: &Path, anime_type: AnimeType, duration: AnimTime, - brightness: f32, + brightness: f32 ) -> Result { let image = AnimeDiagonal::from_png(file_name, None, brightness, anime_type)?; @@ -170,7 +170,7 @@ impl AnimeGif { let single = AnimeFrame { data: image.into_data_buffer(anime_type)?, - delay: Duration::from_millis(30), + delay: Duration::from_millis(30) }; let frames = vec![single; frame_count as usize]; @@ -187,7 +187,7 @@ impl AnimeGif { translation: Vec2, duration: AnimTime, brightness: f32, - anime_type: AnimeType, + anime_type: AnimeType ) -> Result { let mut frames = Vec::new(); let mut decoder = gif::DecodeOptions::new(); @@ -211,7 +211,7 @@ impl AnimeGif { brightness, pixels, decoder.width() as u32, - anime_type, + anime_type )?; while let Some(frame) = decoder.read_next_frame()? { @@ -226,7 +226,7 @@ impl AnimeGif { brightness, pixels, width as u32, - anime_type, + anime_type )?; } for (y, row) in frame.buffer.chunks(frame.width as usize * 4).enumerate() { @@ -239,7 +239,7 @@ impl AnimeGif { (x + frame.left as usize) + ((y + frame.top as usize) * width as usize); image.get_mut()[pos] = Pixel { color: ((px[0] as u32 + px[1] as u32 + px[2] as u32) / 3), - alpha: 1.0, + alpha: 1.0 }; } } @@ -247,7 +247,7 @@ impl AnimeGif { frames.push(AnimeFrame { data: ::try_from(&image)?, - delay: Duration::from_millis(wait as u64), + delay: Duration::from_millis(wait as u64) }); } Ok(Self(frames, duration)) @@ -265,7 +265,7 @@ impl AnimeGif { translation: Vec2, duration: AnimTime, brightness: f32, - anime_type: AnimeType, + anime_type: AnimeType ) -> Result { let image = AnimeImage::from_png(file_name, scale, angle, translation, brightness, anime_type)?; @@ -282,7 +282,7 @@ impl AnimeGif { let single = AnimeFrame { data: ::try_from(&image)?, - delay: Duration::from_millis(30), + delay: Duration::from_millis(30) }; let frames = vec![single; frame_count as usize]; diff --git a/rog-anime/src/grid.rs b/rog-anime/src/grid.rs index 064de16f..9d8c36b5 100644 --- a/rog-anime/src/grid.rs +++ b/rog-anime/src/grid.rs @@ -18,7 +18,7 @@ const HEIGHT: usize = 55; #[derive(Debug, Clone)] pub struct AnimeGrid { anime_type: AnimeType, - data: [[u8; WIDTH]; HEIGHT], + data: [[u8; WIDTH]; HEIGHT] } impl AnimeGrid { @@ -26,7 +26,7 @@ impl AnimeGrid { pub fn new(anime_type: AnimeType) -> Self { Self { anime_type, - data: [[0u8; WIDTH]; HEIGHT], + data: [[0u8; WIDTH]; HEIGHT] } } @@ -174,7 +174,7 @@ mod tests { 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, - 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; assert_eq!(matrix.data(), &data_cmp); } diff --git a/rog-anime/src/image.rs b/rog-anime/src/image.rs index a42e945b..c87a9c99 100644 --- a/rog-anime/src/image.rs +++ b/rog-anime/src/image.rs @@ -13,7 +13,7 @@ use crate::AnimeType; #[derive(Copy, Clone, Debug)] pub struct Pixel { pub color: u32, - pub alpha: f32, + pub alpha: f32 } impl Default for Pixel { @@ -21,7 +21,7 @@ impl Default for Pixel { fn default() -> Self { Pixel { color: 0, - alpha: 0.0, + alpha: 0.0 } } } @@ -76,7 +76,7 @@ pub struct AnimeImage { /// The type of the display. The GA401 and GA402 use the same controller and /// therefore same ID, so the identifier must be by laptop model in /// `AnimeType`. - anime_type: AnimeType, + anime_type: AnimeType } impl AnimeImage { @@ -88,7 +88,7 @@ impl AnimeImage { bright: f32, pixels: Vec, width: u32, - anime_type: AnimeType, + anime_type: AnimeType ) -> Result { if !(0.0..=1.0).contains(&bright) { return Err(AnimeError::InvalidBrightness(bright)); @@ -102,7 +102,7 @@ impl AnimeImage { led_pos: Self::generate_image_positioning(anime_type), img_pixels: pixels, width, - anime_type, + anime_type }) } @@ -121,7 +121,7 @@ impl AnimeImage { match anime_type { AnimeType::GA401 => 0.8, AnimeType::GU604 => 0.78, - _ => 0.77, + _ => 0.77 } } @@ -138,7 +138,7 @@ impl AnimeImage { match anime_type { AnimeType::GA401 => 0.3, AnimeType::GU604 => 0.28, - _ => 0.283, + _ => 0.283 } } @@ -237,7 +237,7 @@ impl AnimeImage { AnimeType::GA401 => (33.0 + 0.5) * Self::scale_x(anime_type), AnimeType::GU604 => (38.0 + 0.5) * Self::scale_x(anime_type), - _ => (35.0 + 0.5) * Self::scale_x(anime_type), + _ => (35.0 + 0.5) * Self::scale_x(anime_type) } } @@ -246,7 +246,7 @@ impl AnimeImage { match anime_type { AnimeType::GA401 => 55, AnimeType::GU604 => 62, - _ => 61, + _ => 61 } } @@ -257,7 +257,7 @@ impl AnimeImage { AnimeType::GA401 => (54.0 + 1.0) * Self::scale_y(anime_type), AnimeType::GU604 => 62.0 * Self::scale_y(anime_type), // GA402 may not have dead pixels and require only the physical LED count - _ => 61.0 * Self::scale_y(anime_type), + _ => 61.0 * Self::scale_y(anime_type) } } @@ -267,11 +267,11 @@ impl AnimeImage { AnimeType::GA401 => match y { 0 | 2 | 4 => 33, 1 | 3 => 35, // Some rows are padded - _ => 36 - y / 2, + _ => 36 - y / 2 }, AnimeType::GU604 => AnimeImage::width(anime_type, y), // GA402 does not have padding, equivalent to width - _ => AnimeImage::width(anime_type, y), + _ => AnimeImage::width(anime_type, y) } } @@ -321,7 +321,9 @@ impl AnimeImage { let pos = Vec3::new(led.x(), led.y(), 1.0); let x0 = led_from_px.mul_vec3(pos + Vec3::new(0.0, -0.5, 0.0)); - const GROUP: [f32; 4] = [0.0, 0.5, 1.0, 1.5]; + const GROUP: [f32; 4] = [ + 0.0, 0.5, 1.0, 1.5 + ]; for u in &GROUP { for v in &GROUP { let sample = x0 + *u * du + *v * dv; @@ -397,7 +399,7 @@ impl AnimeImage { let led_from_cm = Mat3::from_scale(Vec2::new( 1.0 / AnimeImage::scale_x(self.anime_type), - 1.0 / AnimeImage::scale_y(self.anime_type), + 1.0 / AnimeImage::scale_y(self.anime_type) )); let transform = @@ -420,7 +422,7 @@ impl AnimeImage { angle: f32, translation: Vec2, bright: f32, - anime_type: AnimeType, + anime_type: AnimeType ) -> Result { let data = std::fs::read(path).map_err(|e| { error!("Could not open {path:?}: {e:?}"); @@ -464,7 +466,7 @@ impl AnimeImage { width = ras.width(); Self::pixels_from_16bit(ras, false) } - png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format), + png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format) }; let mut matrix = AnimeImage::new( @@ -474,7 +476,7 @@ impl AnimeImage { bright, pixels, width, - anime_type, + anime_type )?; matrix.update(); @@ -483,7 +485,7 @@ impl AnimeImage { fn pixels_from_8bit

(ras: &pix::Raster

, grey: bool) -> Vec where - P: pix::el::Pixel, + P: pix::el::Pixel { ras.pixels() .iter() @@ -495,14 +497,14 @@ impl AnimeImage { + (::from(px.two()) / 3) as u32 + (::from(px.three()) / 3) as u32 }, - alpha: ::from(px.alpha()), + alpha: ::from(px.alpha()) }) .collect() } fn pixels_from_16bit

(ras: &pix::Raster

, grey: bool) -> Vec where - P: pix::el::Pixel, + P: pix::el::Pixel { ras.pixels() .iter() @@ -514,7 +516,7 @@ impl AnimeImage { + ((::from(px.two()) / 3) >> 8) as u32 + ((::from(px.three()) / 3) >> 8) as u32 }, - alpha: ::from(px.alpha()), + alpha: ::from(px.alpha()) }) .collect() } @@ -651,7 +653,7 @@ mod tests { Vec2::default(), AnimTime::Infinite, 1.0, - AnimeType::GA402, + AnimeType::GA402 ) .unwrap(); matrix.frames()[0].frame(); diff --git a/rog-anime/src/sequencer.rs b/rog-anime/src/sequencer.rs index 443b8375..cb4bf048 100644 --- a/rog-anime/src/sequencer.rs +++ b/rog-anime/src/sequencer.rs @@ -16,13 +16,13 @@ pub enum ActionLoader { AsusAnimation { file: PathBuf, time: AnimTime, - brightness: f32, + brightness: f32 }, /// Image designed to be pixel perfect using the slanted template AsusImage { file: PathBuf, time: AnimTime, - brightness: f32, + brightness: f32 }, /// Animated gif. If the file is a png a static gif is created using the /// `time` properties @@ -32,7 +32,7 @@ pub enum ActionLoader { angle: f32, translation: Vec2, time: AnimTime, - brightness: f32, + brightness: f32 }, Image { file: PathBuf, @@ -40,10 +40,10 @@ pub enum ActionLoader { angle: f32, translation: Vec2, time: AnimTime, - brightness: f32, + brightness: f32 }, /// A pause to be used between sequences - Pause(Duration), + Pause(Duration) } /// All the possible `AniMe` actions that can be used. The enum is intended to @@ -64,7 +64,7 @@ pub enum ActionData { /// Placeholder TimeDate, /// Placeholder - Matrix, + Matrix } impl ActionData { @@ -73,17 +73,14 @@ impl ActionData { ActionLoader::AsusAnimation { file, time, - brightness, + brightness } => ActionData::Animation(AnimeGif::from_diagonal_gif( - file, - *time, - *brightness, - anime_type, + file, *time, *brightness, anime_type )?), ActionLoader::AsusImage { file, time, - brightness, + brightness } => match time { AnimTime::Infinite => { let image = AnimeDiagonal::from_png(file, None, *brightness, anime_type)?; @@ -91,11 +88,8 @@ impl ActionData { ActionData::Image(Box::new(data)) } _ => ActionData::Animation(AnimeGif::from_diagonal_png( - file, - anime_type, - *time, - *brightness, - )?), + file, anime_type, *time, *brightness + )?) }, ActionLoader::ImageAnimation { file, @@ -103,29 +97,17 @@ impl ActionData { angle, translation, time, - brightness, + brightness } => { if let Some(ext) = file.extension() { if ext.to_string_lossy().to_lowercase() == "png" { return Ok(ActionData::Animation(AnimeGif::from_png( - file, - *scale, - *angle, - *translation, - *time, - *brightness, - anime_type, + file, *scale, *angle, *translation, *time, *brightness, anime_type )?)); } } ActionData::Animation(AnimeGif::from_gif( - file, - *scale, - *angle, - *translation, - *time, - *brightness, - anime_type, + file, *scale, *angle, *translation, *time, *brightness, anime_type )?) } ActionLoader::Image { @@ -134,34 +116,23 @@ impl ActionData { angle, translation, brightness, - time, + time } => { match time { AnimTime::Infinite => { // If no time then create a plain static image let image = AnimeImage::from_png( - file, - *scale, - *angle, - *translation, - *brightness, - anime_type, + file, *scale, *angle, *translation, *brightness, anime_type )?; let data = ::try_from(&image)?; ActionData::Image(Box::new(data)) } _ => ActionData::Animation(AnimeGif::from_png( - file, - *scale, - *angle, - *translation, - *time, - *brightness, - anime_type, - )?), + file, *scale, *angle, *translation, *time, *brightness, anime_type + )?) } } - ActionLoader::Pause(duration) => ActionData::Pause(*duration), + ActionLoader::Pause(duration) => ActionData::Pause(*duration) }; Ok(a) } @@ -200,7 +171,7 @@ impl Sequences { pub fn iter(&self) -> ActionIterator<'_> { ActionIterator { actions: self, - next_idx: 0, + next_idx: 0 } } } @@ -208,7 +179,7 @@ impl Sequences { /// Iteractor helper for iterating over all the actions in `Sequences` pub struct ActionIterator<'a> { actions: &'a Sequences, - next_idx: usize, + next_idx: usize } impl<'a> Iterator for ActionIterator<'a> { diff --git a/rog-anime/src/usb.rs b/rog-anime/src/usb.rs index fcf9fe0d..694c0fa1 100644 --- a/rog-anime/src/usb.rs +++ b/rog-anime/src/usb.rs @@ -35,7 +35,7 @@ pub enum Brightness { Low = 1, #[default] Med = 2, - High = 3, + High = 3 } impl FromStr for Brightness { @@ -47,7 +47,7 @@ impl FromStr for Brightness { "Low" | "low" => Brightness::Low, "Med" | "med" => Brightness::Med, "High" | "high" => Brightness::High, - _ => Brightness::Med, + _ => Brightness::Med }) } } @@ -58,7 +58,7 @@ impl From for Brightness { 0 => Brightness::Off, 1 => Brightness::Low, 3 => Brightness::High, - _ => Brightness::Med, + _ => Brightness::Med } } } @@ -84,7 +84,7 @@ impl From for i32 { pub enum AnimBooting { #[default] GlitchConstruction = 0, - StaticEmergence = 1, + StaticEmergence = 1 } impl FromStr for AnimBooting { @@ -94,7 +94,7 @@ impl FromStr for AnimBooting { match s { "GlitchConstruction" => Ok(Self::GlitchConstruction), "StaticEmergence" => Ok(Self::StaticEmergence), - _ => Err(AnimeError::ParseError(s.to_owned())), + _ => Err(AnimeError::ParseError(s.to_owned())) } } } @@ -104,7 +104,7 @@ impl From for AnimBooting { match value { 0 => Self::GlitchConstruction, 1 => Self::StaticEmergence, - _ => Self::default(), + _ => Self::default() } } } @@ -124,7 +124,7 @@ impl From for i32 { pub enum AnimAwake { #[default] BinaryBannerScroll = 0, - RogLogoGlitch = 1, + RogLogoGlitch = 1 } impl FromStr for AnimAwake { @@ -134,7 +134,7 @@ impl FromStr for AnimAwake { match s { "BinaryBannerScroll" => Ok(Self::BinaryBannerScroll), "RogLogoGlitch" => Ok(Self::RogLogoGlitch), - _ => Err(AnimeError::ParseError(s.to_owned())), + _ => Err(AnimeError::ParseError(s.to_owned())) } } } @@ -144,7 +144,7 @@ impl From for AnimAwake { match value { 0 => Self::BinaryBannerScroll, 1 => Self::RogLogoGlitch, - _ => Self::default(), + _ => Self::default() } } } @@ -164,7 +164,7 @@ impl From for i32 { pub enum AnimSleeping { #[default] BannerSwipe = 0, - Starfield = 1, + Starfield = 1 } impl FromStr for AnimSleeping { @@ -174,7 +174,7 @@ impl FromStr for AnimSleeping { match s { "BannerSwipe" => Ok(Self::BannerSwipe), "Starfield" => Ok(Self::Starfield), - _ => Err(AnimeError::ParseError(s.to_owned())), + _ => Err(AnimeError::ParseError(s.to_owned())) } } } @@ -184,7 +184,7 @@ impl From for AnimSleeping { match value { 0 => Self::BannerSwipe, 1 => Self::Starfield, - _ => Self::default(), + _ => Self::default() } } } @@ -204,7 +204,7 @@ impl From for i32 { pub enum AnimShutdown { #[default] GlitchOut = 0, - SeeYa = 1, + SeeYa = 1 } impl FromStr for AnimShutdown { @@ -214,7 +214,7 @@ impl FromStr for AnimShutdown { match s { "GlitchOut" => Ok(Self::GlitchOut), "SeeYa" => Ok(Self::SeeYa), - _ => Err(AnimeError::ParseError(s.to_owned())), + _ => Err(AnimeError::ParseError(s.to_owned())) } } } @@ -224,7 +224,7 @@ impl From for AnimShutdown { match value { 0 => Self::GlitchOut, 1 => Self::SeeYa, - _ => Self::default(), + _ => Self::default() } } } @@ -326,7 +326,7 @@ pub const fn pkt_set_builtin_animations( boot: AnimBooting, awake: AnimAwake, sleep: AnimSleeping, - shutdown: AnimShutdown, + shutdown: AnimShutdown ) -> [u8; PACKET_SIZE] { let mut pkt = [0; PACKET_SIZE]; pkt[0] = DEV_PAGE; diff --git a/rog-anime/tests/ga401.rs b/rog-anime/tests/ga401.rs index ec1c3729..c61a9532 100644 --- a/rog-anime/tests/ga401.rs +++ b/rog-anime/tests/ga401.rs @@ -52,7 +52,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt1_check = [ 0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -100,7 +100,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let mut matrix = AnimeImage::new( @@ -110,7 +110,7 @@ mod tests { 0.0, vec![Pixel::default(); 1000], 100, - AnimeType::GA401, + AnimeType::GA401 ) .unwrap(); matrix.edge_outline(); @@ -175,7 +175,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt1_check = [ 0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -223,7 +223,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); diff --git a/rog-anime/tests/ga402q.rs b/rog-anime/tests/ga402q.rs index cee27f6d..943f3041 100644 --- a/rog-anime/tests/ga402q.rs +++ b/rog-anime/tests/ga402q.rs @@ -52,7 +52,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt1_check = [ 0x5e, 0xc0, 0x2, 0x74, 0x2, 0x73, 0x2, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, @@ -100,7 +100,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt2_check = [ 0x5e, 0xc0, 0x2, 0xe7, 0x4, 0x73, 0x2, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, @@ -148,7 +148,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let mut matrix = AnimeImage::new( @@ -158,7 +158,7 @@ mod tests { 0.0, vec![Pixel::default(); 1000], 100, - AnimeType::GA402, + AnimeType::GA402 ) .unwrap(); matrix.edge_outline(); @@ -218,7 +218,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt1_check = [ 0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, @@ -266,7 +266,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt2_check = [ 0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, @@ -314,7 +314,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); @@ -378,7 +378,7 @@ mod tests { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt1_check = [ 0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -426,7 +426,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt2_check = [ 0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, @@ -474,7 +474,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); diff --git a/rog-anime/tests/gu604.rs b/rog-anime/tests/gu604.rs index 88f9957d..58baf3d2 100644 --- a/rog-anime/tests/gu604.rs +++ b/rog-anime/tests/gu604.rs @@ -52,7 +52,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt1_check = [ 0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -100,7 +100,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt2_check = [ 0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -148,7 +148,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let mut matrix = AnimeImage::new( @@ -158,7 +158,7 @@ mod tests { 0.0, vec![Pixel::default(); 1000], 100, - AnimeType::GU604, + AnimeType::GU604 ) .unwrap(); matrix.edge_outline(); @@ -218,7 +218,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt1_check = [ 0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -266,7 +266,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let pkt2_check = [ 0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -314,7 +314,7 @@ mod tests { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); diff --git a/rog-aura/src/aura_detection.rs b/rog-aura/src/aura_detection.rs index f0e6733f..6d088691 100644 --- a/rog-aura/src/aura_detection.rs +++ b/rog-aura/src/aura_detection.rs @@ -54,7 +54,7 @@ pub struct LedSupportData { #[serde(default)] pub advanced_type: AdvancedAuraType, /// If empty will default to `Keyboard` power zone - pub power_zones: Vec, + pub power_zones: Vec } impl LedSupportData { @@ -116,7 +116,7 @@ impl LedSupportFile { basic_modes: vec![AuraModeNum::Static], basic_zones: vec![], advanced_type: AdvancedAuraType::None, - power_zones: vec![PowerZones::Keyboard], + power_zones: vec![PowerZones::Keyboard] } } @@ -191,9 +191,16 @@ mod tests { product_id: String::new(), layout_name: "ga401".to_owned(), basic_modes: vec![AuraModeNum::Static], - basic_zones: vec![AuraZone::Key1, AuraZone::Logo, AuraZone::BarLeft], + basic_zones: vec![ + AuraZone::Key1, + AuraZone::Logo, + AuraZone::BarLeft, + ], advanced_type: AdvancedAuraType::Zoned(vec![LedCode::LightbarRight]), - power_zones: vec![PowerZones::Keyboard, PowerZones::RearGlow], + power_zones: vec![ + PowerZones::Keyboard, + PowerZones::RearGlow, + ] }; assert!(ron::to_string(&led).is_ok()); diff --git a/rog-aura/src/builtin_modes.rs b/rog-aura/src/builtin_modes.rs index d371ea40..c7191f44 100644 --- a/rog-aura/src/builtin_modes.rs +++ b/rog-aura/src/builtin_modes.rs @@ -19,7 +19,7 @@ pub enum LedBrightness { Low = 1, #[default] Med = 2, - High = 3, + High = 3 } impl LedBrightness { @@ -28,7 +28,7 @@ impl LedBrightness { Self::Off => Self::Low, Self::Low => Self::Med, Self::Med => Self::High, - Self::High => Self::Off, + Self::High => Self::Off } } @@ -37,7 +37,7 @@ impl LedBrightness { Self::Off => Self::High, Self::Low => Self::Off, Self::Med => Self::Low, - Self::High => Self::Med, + Self::High => Self::Med } } } @@ -48,7 +48,7 @@ impl From for LedBrightness { 0 => LedBrightness::Off, 1 => LedBrightness::Low, 3 => LedBrightness::High, - _ => LedBrightness::Med, + _ => LedBrightness::Med } } } @@ -72,7 +72,7 @@ impl From for LedBrightness { 1 => LedBrightness::Low, 2 => LedBrightness::Med, 3 => LedBrightness::High, - _ => LedBrightness::Med, + _ => LedBrightness::Med } } } @@ -82,7 +82,7 @@ impl From for LedBrightness { pub struct Colour { pub r: u8, pub g: u8, - pub b: u8, + pub b: u8 } impl Default for Colour { @@ -110,14 +110,18 @@ impl From<&[f32; 3]> for Colour { Self { r: (255.0 * c[0]) as u8, g: (255.0 * c[1]) as u8, - b: (255.0 * c[2]) as u8, + b: (255.0 * c[2]) as u8 } } } impl From for [f32; 3] { fn from(c: Colour) -> Self { - [c.r as f32 / 255.0, c.g as f32 / 255.0, c.b as f32 / 255.0] + [ + c.r as f32 / 255.0, + c.g as f32 / 255.0, + c.b as f32 / 255.0 + ] } } @@ -126,14 +130,16 @@ impl From<&[u8; 3]> for Colour { Self { r: c[0], g: c[1], - b: c[2], + b: c[2] } } } impl From for [u8; 3] { fn from(c: Colour) -> Self { - [c.r, c.g, c.b] + [ + c.r, c.g, c.b + ] } } @@ -147,7 +153,7 @@ pub enum Speed { Low = 0xe1, #[default] Med = 0xeb, - High = 0xf5, + High = 0xf5 } impl FromStr for Speed { @@ -159,7 +165,7 @@ impl FromStr for Speed { "low" => Ok(Speed::Low), "med" => Ok(Speed::Med), "high" => Ok(Speed::High), - _ => Err(Error::ParseSpeed), + _ => Err(Error::ParseSpeed) } } } @@ -169,7 +175,7 @@ impl From for Speed { match value { 0 => Self::Low, 2 => Self::High, - _ => Self::Med, + _ => Self::Med } } } @@ -179,7 +185,7 @@ impl From for i32 { match value { Speed::Low => 0, Speed::Med => 1, - Speed::High => 2, + Speed::High => 2 } } } @@ -189,7 +195,7 @@ impl From for u8 { match s { Speed::Low => 0, Speed::Med => 1, - Speed::High => 2, + Speed::High => 2 } } } @@ -207,7 +213,7 @@ pub enum Direction { Right = 0, Left = 1, Up = 2, - Down = 3, + Down = 3 } impl FromStr for Direction { @@ -220,7 +226,7 @@ impl FromStr for Direction { "up" => Ok(Direction::Up), "down" => Ok(Direction::Down), "left" => Ok(Direction::Left), - _ => Err(Error::ParseDirection), + _ => Err(Error::ParseDirection) } } } @@ -231,7 +237,7 @@ impl From for Direction { 1 => Self::Left, 2 => Self::Up, 3 => Self::Down, - _ => Self::Right, + _ => Self::Right } } } @@ -264,7 +270,7 @@ pub enum AuraModeNum { Ripple = 8, Pulse = 10, Comet = 11, - Flash = 12, + Flash = 12 } impl Display for AuraModeNum { @@ -293,7 +299,7 @@ impl From<&AuraModeNum> for &str { AuraModeNum::Ripple => "Ripple", AuraModeNum::Pulse => "Pulse", AuraModeNum::Comet => "Comet", - AuraModeNum::Flash => "Flash", + AuraModeNum::Flash => "Flash" } } } @@ -311,7 +317,7 @@ impl From<&str> for AuraModeNum { "Pulse" => AuraModeNum::Pulse, "Comet" => AuraModeNum::Comet, "Flash" => AuraModeNum::Flash, - _ => AuraModeNum::Static, + _ => AuraModeNum::Static } } } @@ -330,7 +336,7 @@ impl From for AuraModeNum { 10 => AuraModeNum::Pulse, 11 => AuraModeNum::Comet, 12 => AuraModeNum::Flash, - _ => AuraModeNum::Static, + _ => AuraModeNum::Static } } } @@ -377,7 +383,7 @@ pub enum AuraZone { /// The left part of a lightbar (typically on the front of laptop) BarLeft = 6, /// The right part of a lightbar - BarRight = 7, + BarRight = 7 } impl FromStr for AuraZone { @@ -394,7 +400,7 @@ impl FromStr for AuraZone { "5" | "logo" => Ok(AuraZone::Logo), "6" | "lightbar-left" => Ok(AuraZone::BarLeft), "7" | "lightbar-right" => Ok(AuraZone::BarRight), - _ => Err(Error::ParseSpeed), + _ => Err(Error::ParseSpeed) } } } @@ -409,7 +415,7 @@ impl From for AuraZone { 5 => Self::Logo, 6 => Self::BarLeft, 7 => Self::BarRight, - _ => Self::default(), + _ => Self::default() } } } @@ -439,7 +445,7 @@ pub struct AuraEffect { /// One of three speeds for modes that support speed (most that animate) pub speed: Speed, /// Up, down, left, right. Only Rainbow mode seems to use this - pub direction: Direction, + pub direction: Direction } impl AuraEffect { @@ -475,7 +481,7 @@ impl Default for AuraEffect { colour1: Colour { r: 166, g: 0, b: 0 }, colour2: Colour { r: 0, g: 0, b: 0 }, speed: Speed::Med, - direction: Direction::Right, + direction: Direction::Right } } } @@ -535,7 +541,7 @@ impl From<&AuraEffect> for Vec { #[cfg(test)] mod tests { use crate::{ - AuraEffect, AuraModeNum, AuraZone, Colour, Direction, Speed, AURA_LAPTOP_LED_MSG_LEN, + AuraEffect, AuraModeNum, AuraZone, Colour, Direction, Speed, AURA_LAPTOP_LED_MSG_LEN }; #[test] @@ -546,18 +552,18 @@ mod tests { colour1: Colour { r: 0xff, g: 0x11, - b: 0xdd, + b: 0xdd }, colour2: Colour::default(), speed: Speed::Med, - direction: Direction::Right, + direction: Direction::Right }; let ar = <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st); println!("{:02x?}", ar); let check = [ 0x5d, 0xb3, 0x0, 0x0, 0xff, 0x11, 0xdd, 0xeb, 0x0, 0x0, 0xa6, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, + 0x0 ]; assert_eq!(ar, check); } @@ -570,15 +576,15 @@ mod tests { colour1: Colour { r: 0xff, g: 0, - b: 0, + b: 0 }, colour2: Colour { r: 0, g: 0, b: 0 }, speed: Speed::Low, - direction: Direction::Left, + direction: Direction::Left }; let capture = [ 0x5d, 0xb3, 0x01, 0x00, 0xff, 0x00, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, + 0x0, 0x0 ]; assert_eq!( <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9], @@ -589,11 +595,11 @@ mod tests { st.colour1 = Colour { r: 0xff, g: 0xff, - b: 0, + b: 0 }; let capture = [ 0x5d, 0xb3, 0x02, 0x00, 0xff, 0xff, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, + 0x0, 0x0 ]; assert_eq!( <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9], @@ -604,11 +610,11 @@ mod tests { st.colour1 = Colour { r: 0, g: 0xff, - b: 0xff, + b: 0xff }; let capture = [ 0x5d, 0xb3, 0x03, 0x00, 0x00, 0xff, 0xff, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, + 0x0, 0x0 ]; assert_eq!( <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9], @@ -619,11 +625,11 @@ mod tests { st.colour1 = Colour { r: 0xff, g: 0x00, - b: 0xff, + b: 0xff }; let capture = [ 0x5d, 0xb3, 0x04, 0x00, 0xff, 0x00, 0xff, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, + 0x0, 0x0 ]; assert_eq!( <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9], @@ -634,11 +640,11 @@ mod tests { st.colour1 = Colour { r: 0x2c, g: 0xff, - b: 0x00, + b: 0x00 }; let capture = [ 0x5d, 0xb3, 0x05, 0x00, 0x2c, 0xff, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, + 0x0, 0x0 ]; assert_eq!( <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9], @@ -649,11 +655,11 @@ mod tests { st.colour1 = Colour { r: 0xff, g: 0x00, - b: 0x00, + b: 0x00 }; let capture = [ 0x5d, 0xb3, 0x06, 0x00, 0xff, 0x00, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, + 0x0, 0x0 ]; assert_eq!( <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9], @@ -664,11 +670,11 @@ mod tests { st.colour1 = Colour { r: 0xff, g: 0x00, - b: 0xcd, + b: 0xcd }; let capture = [ 0x5d, 0xb3, 0x07, 0x00, 0xff, 0x00, 0xcd, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, + 0x0, 0x0 ]; assert_eq!( <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9], @@ -678,7 +684,7 @@ mod tests { st.mode = AuraModeNum::RainbowWave; let capture = [ 0x5d, 0xb3, 0x07, 0x03, 0xff, 0x00, 0xcd, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, + 0x0, 0x0 ]; assert_eq!( <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9], diff --git a/rog-aura/src/effects/base.rs b/rog-aura/src/effects/base.rs index 9d51025c..4ab25767 100644 --- a/rog-aura/src/effects/base.rs +++ b/rog-aura/src/effects/base.rs @@ -11,7 +11,7 @@ pub struct InputBased { /// - temperature /// - fan speed /// - time - input: Box, + input: Box } impl EffectState for InputBased { diff --git a/rog-aura/src/effects/breathe.rs b/rog-aura/src/effects/breathe.rs index a3c5a345..10ef487d 100644 --- a/rog-aura/src/effects/breathe.rs +++ b/rog-aura/src/effects/breathe.rs @@ -19,7 +19,7 @@ pub struct Breathe { #[serde(skip)] count_flipped: bool, #[serde(skip)] - use_colour1: bool, + use_colour1: bool } impl Breathe { @@ -31,7 +31,7 @@ impl Breathe { speed, colour: colour1, count_flipped: false, - use_colour1: true, + use_colour1: true } } } diff --git a/rog-aura/src/effects/doom.rs b/rog-aura/src/effects/doom.rs index 773a8bb2..5174bd5b 100644 --- a/rog-aura/src/effects/doom.rs +++ b/rog-aura/src/effects/doom.rs @@ -13,7 +13,7 @@ pub struct DoomFlicker { #[serde(skip)] count: u8, #[serde(skip)] - colour: Colour, + colour: Colour } impl DoomFlicker { @@ -24,7 +24,7 @@ impl DoomFlicker { count: 4, max_percentage, min_percentage, - start_colour: colour, + start_colour: colour } } } @@ -53,13 +53,13 @@ impl EffectState for DoomFlicker { let max_light = Colour { r: (start_colour.r as f32 / 100.0 * *max_percentage as f32) as u8, g: (start_colour.g as f32 / 100.0 * *max_percentage as f32) as u8, - b: (start_colour.b as f32 / 100.0 * *max_percentage as f32) as u8, + b: (start_colour.b as f32 / 100.0 * *max_percentage as f32) as u8 }; // min light is a percentage of the set colour let min_light = Colour { r: (start_colour.r as f32 / 100.0 * *min_percentage as f32) as u8, g: (start_colour.g as f32 / 100.0 * *min_percentage as f32) as u8, - b: (start_colour.b as f32 / 100.0 * *min_percentage as f32) as u8, + b: (start_colour.b as f32 / 100.0 * *min_percentage as f32) as u8 }; // Convert the 255 to percentage @@ -96,7 +96,7 @@ pub struct DoomLightFlash { #[serde(skip)] count: u8, #[serde(skip)] - colour: Colour, + colour: Colour } impl DoomLightFlash { @@ -109,7 +109,7 @@ impl DoomLightFlash { min_percentage, start_colour: colour, max_time: 32, - min_time: 7, + min_time: 7 } } } @@ -135,13 +135,13 @@ impl EffectState for DoomLightFlash { let max_light = Colour { r: (start_colour.r as f32 / 100.0 * *max_percentage as f32) as u8, g: (start_colour.g as f32 / 100.0 * *max_percentage as f32) as u8, - b: (start_colour.b as f32 / 100.0 * *max_percentage as f32) as u8, + b: (start_colour.b as f32 / 100.0 * *max_percentage as f32) as u8 }; // min light is a percentage of the set colour let min_light = Colour { r: (start_colour.r as f32 / 100.0 * *min_percentage as f32) as u8, g: (start_colour.g as f32 / 100.0 * *min_percentage as f32) as u8, - b: (start_colour.b as f32 / 100.0 * *min_percentage as f32) as u8, + b: (start_colour.b as f32 / 100.0 * *min_percentage as f32) as u8 }; if *colour == max_light { diff --git a/rog-aura/src/effects/mod.rs b/rog-aura/src/effects/mod.rs index 0fbc7cb9..7863a925 100644 --- a/rog-aura/src/effects/mod.rs +++ b/rog-aura/src/effects/mod.rs @@ -32,7 +32,7 @@ pub const RNDTABLE: [i32; 256] = [ 206, 163, 45, 63, 90, 168, 114, 59, 33, 159, 95, 28, 139, 123, 98, 125, 196, 15, 70, 194, 253, 54, 14, 109, 226, 71, 17, 161, 93, 186, 87, 244, 138, 20, 52, 123, 251, 26, 36, 17, 46, 52, 231, 232, 76, 31, 221, 84, 37, 216, 165, 212, 106, 197, 242, 98, 43, 39, 175, 254, 145, 190, - 84, 118, 222, 187, 136, 120, 163, 236, 249, + 84, 118, 222, 187, 136, 120, 163, 236, 249 ]; pub fn p_random() -> i32 { @@ -67,7 +67,7 @@ pub(crate) trait EffectState { #[derive(Debug, Deserialize, Serialize, Default)] pub struct AdvancedEffects { effects: Vec, - zoned: bool, + zoned: bool } impl AdvancedEffects { @@ -75,7 +75,7 @@ impl AdvancedEffects { pub fn new(zoned: bool) -> Self { Self { effects: Default::default(), - zoned, + zoned } } @@ -186,7 +186,7 @@ pub enum Effect { Static(Static), Breathe(Breathe), DoomFlicker(DoomFlicker), - DoomLightFlash(DoomLightFlash), + DoomLightFlash(DoomLightFlash) } impl Default for Effect { @@ -207,14 +207,12 @@ mod tests { fn single_key_next_state_then_create() { let layout = KeyLayout::default_layout(); let mut seq = AdvancedEffects::new(false); - seq.effects.push(Effect::Static(Static::new( - LedCode::F, - Colour { + seq.effects + .push(Effect::Static(Static::new(LedCode::F, Colour { r: 255, g: 127, - b: 0, - }, - ))); + b: 0 + }))); seq.next_state(&layout); let packets = seq.create_packets(); @@ -234,14 +232,14 @@ mod tests { Colour { r: 255, g: 127, - b: 0, + b: 0 }, Colour { r: 127, g: 0, - b: 255, + b: 255 }, - Speed::Med, + Speed::Med ))); let s = @@ -276,10 +274,10 @@ mod tests { Colour { r: 255, g: 127, - b: 80, + b: 80 }, 100, - 10, + 10 ))); seq.next_state(&layout); diff --git a/rog-aura/src/effects/static_.rs b/rog-aura/src/effects/static_.rs index 0c57646a..7aaa2079 100644 --- a/rog-aura/src/effects/static_.rs +++ b/rog-aura/src/effects/static_.rs @@ -8,14 +8,14 @@ use crate::{effect_state_impl, Colour}; pub struct Static { led: LedCode, /// The starting colour - colour: Colour, + colour: Colour } impl Static { pub fn new(address: LedCode, colour: Colour) -> Self { Self { led: address, - colour, + colour } } } diff --git a/rog-aura/src/error.rs b/rog-aura/src/error.rs index 2e7c86de..10d09c37 100644 --- a/rog-aura/src/error.rs +++ b/rog-aura/src/error.rs @@ -8,7 +8,7 @@ pub enum Error { ParseBrightness, IoPath(String, std::io::Error), Ron(ron::Error), - RonParse(ron::error::SpannedError), + RonParse(ron::error::SpannedError) } impl fmt::Display for Error { @@ -21,7 +21,7 @@ impl fmt::Display for Error { Error::ParseBrightness => write!(f, "Could not parse brightness"), Error::IoPath(path, io) => write!(f, "IO Error: {path}, {io}"), Error::Ron(e) => write!(f, "RON Parse Error: {e}"), - Error::RonParse(e) => write!(f, "RON Parse Error: {e}"), + Error::RonParse(e) => write!(f, "RON Parse Error: {e}") } } } diff --git a/rog-aura/src/keyboard/advanced.rs b/rog-aura/src/keyboard/advanced.rs index 34a91bac..8a910c02 100644 --- a/rog-aura/src/keyboard/advanced.rs +++ b/rog-aura/src/keyboard/advanced.rs @@ -164,7 +164,7 @@ pub enum LedCode { /// To be ignored by effects Spacing, /// To be ignored by effects - Blocking, + Blocking } impl LedCode { @@ -210,7 +210,7 @@ pub struct LedUsbPackets { /// Wether or not this packet collection is zoned. The determines which /// starting bytes are used and what the indexing is for lightbar RGB /// colours - zoned: bool, + zoned: bool } impl Default for LedUsbPackets { @@ -244,7 +244,7 @@ impl LedUsbPackets { } Self { usb_packets: set, - zoned: false, + zoned: false } } @@ -274,7 +274,7 @@ impl LedUsbPackets { } Self { usb_packets: vec![pkt], - zoned: true, + zoned: true } } @@ -633,7 +633,7 @@ impl From<&LedCode> for &str { LedCode::ZonedKbLeft => "Left Zone (zone 1)", LedCode::ZonedKbLeftMid => "Center-left Zone (zone 2)", LedCode::ZonedKbRightMid => "Center-right Zone (zone 3)", - LedCode::ZonedKbRight => "Right Zone (zone 4)", + LedCode::ZonedKbRight => "Right Zone (zone 4)" } } } diff --git a/rog-aura/src/keyboard/layouts.rs b/rog-aura/src/keyboard/layouts.rs index 4a363128..d19ba685 100644 --- a/rog-aura/src/keyboard/layouts.rs +++ b/rog-aura/src/keyboard/layouts.rs @@ -26,12 +26,12 @@ pub enum KeyShape { pad_left: f32, pad_right: f32, pad_top: f32, - pad_bottom: f32, + pad_bottom: f32 }, Blank { width: f32, - height: f32, - }, + height: f32 + } } impl KeyShape { @@ -41,7 +41,7 @@ impl KeyShape { pad_left: f32, pad_right: f32, pad_top: f32, - pad_bottom: f32, + pad_bottom: f32 ) -> Self { Self::Led { width, @@ -49,7 +49,7 @@ impl KeyShape { pad_left, pad_right, pad_top, - pad_bottom, + pad_bottom } } @@ -66,7 +66,7 @@ impl KeyShape { pad_left, pad_right, pad_top, - pad_bottom, + pad_bottom } => { *width *= scale; *height *= scale; @@ -97,7 +97,7 @@ pub struct KeyRow { row: Vec<(LedCode, String)>, /// The final data structure merged key_shapes and rows #[serde(skip)] - built_row: Vec<(LedCode, KeyShape)>, + built_row: Vec<(LedCode, KeyShape)> } impl KeyRow { @@ -106,7 +106,7 @@ impl KeyRow { pad_left, pad_top, row, - built_row: Default::default(), + built_row: Default::default() } } @@ -132,7 +132,7 @@ impl KeyRow { pad_bottom, .. } => height + pad_top + pad_bottom, - KeyShape::Blank { height, .. } => *height, + KeyShape::Blank { height, .. } => *height }; if h < height { @@ -156,7 +156,7 @@ impl KeyRow { pad_right, .. } => w += width + pad_left + pad_right, - KeyShape::Blank { width, .. } => w += width, + KeyShape::Blank { width, .. } => w += width } } w @@ -185,7 +185,7 @@ pub struct KeyLayout { /// Should be copied from the `LaptopLedData` as laptops may have the same /// layout, but different EC features. #[serde(skip)] - advanced_type: AdvancedAuraType, + advanced_type: AdvancedAuraType } impl KeyLayout { @@ -195,7 +195,7 @@ impl KeyLayout { if buf.is_empty() { Err(Error::IoPath( path.to_string_lossy().to_string(), - std::io::ErrorKind::InvalidData.into(), + std::io::ErrorKind::InvalidData.into() )) } else { let mut data = ron::from_str::(&buf)?; @@ -332,121 +332,97 @@ impl KeyLayout { advanced_type: AdvancedAuraType::None, key_shapes: HashMap::from([( "regular".to_owned(), - KeyShape::new_led(1.0, 1.0, 0.1, 0.1, 0.1, 0.1), + KeyShape::new_led(1.0, 1.0, 0.1, 0.1, 0.1, 0.1) )]), key_rows: vec![ - KeyRow::new( - 0.1, - 0.1, - vec![ - (LedCode::Esc, "regular".to_owned()), - (LedCode::F1, "regular".to_owned()), - (LedCode::F2, "regular".to_owned()), - (LedCode::F3, "regular".to_owned()), - (LedCode::F4, "regular".to_owned()), - // not sure which key to put here - (LedCode::F5, "regular".to_owned()), - (LedCode::F6, "regular".to_owned()), - (LedCode::F7, "regular".to_owned()), - (LedCode::F8, "regular".to_owned()), - (LedCode::F9, "regular".to_owned()), - (LedCode::F10, "regular".to_owned()), - (LedCode::F11, "regular".to_owned()), - (LedCode::F12, "regular".to_owned()), - ], - ), - KeyRow::new( - 0.1, - 0.1, - vec![ - (LedCode::Tilde, "regular".to_owned()), - (LedCode::N1, "regular".to_owned()), - (LedCode::N2, "regular".to_owned()), - (LedCode::N3, "regular".to_owned()), - (LedCode::N4, "regular".to_owned()), - (LedCode::N5, "regular".to_owned()), - (LedCode::N6, "regular".to_owned()), - (LedCode::N7, "regular".to_owned()), - (LedCode::N8, "regular".to_owned()), - (LedCode::N9, "regular".to_owned()), - (LedCode::N0, "regular".to_owned()), - (LedCode::Hyphen, "regular".to_owned()), - (LedCode::Equals, "regular".to_owned()), - (LedCode::Backspace, "regular".to_owned()), - ], - ), - KeyRow::new( - 0.1, - 0.1, - vec![ - (LedCode::Tab, "regular".to_owned()), - (LedCode::Q, "regular".to_owned()), - (LedCode::W, "regular".to_owned()), - (LedCode::E, "regular".to_owned()), - (LedCode::R, "regular".to_owned()), - (LedCode::T, "regular".to_owned()), - (LedCode::Y, "regular".to_owned()), - (LedCode::U, "regular".to_owned()), - (LedCode::I, "regular".to_owned()), - (LedCode::O, "regular".to_owned()), - (LedCode::P, "regular".to_owned()), - (LedCode::LBracket, "regular".to_owned()), - (LedCode::RBracket, "regular".to_owned()), - (LedCode::BackSlash, "regular".to_owned()), - ], - ), - KeyRow::new( - 0.1, - 0.1, - vec![ - (LedCode::Caps, "regular".to_owned()), - (LedCode::A, "regular".to_owned()), - (LedCode::S, "regular".to_owned()), - (LedCode::D, "regular".to_owned()), - (LedCode::F, "regular".to_owned()), - (LedCode::G, "regular".to_owned()), - (LedCode::H, "regular".to_owned()), - (LedCode::J, "regular".to_owned()), - (LedCode::K, "regular".to_owned()), - (LedCode::L, "regular".to_owned()), - (LedCode::SemiColon, "regular".to_owned()), - (LedCode::Quote, "regular".to_owned()), - (LedCode::Return, "regular".to_owned()), - ], - ), - KeyRow::new( - 0.1, - 0.1, - vec![ - (LedCode::LShift, "regular".to_owned()), - (LedCode::Z, "regular".to_owned()), - (LedCode::X, "regular".to_owned()), - (LedCode::C, "regular".to_owned()), - (LedCode::V, "regular".to_owned()), - (LedCode::B, "regular".to_owned()), - (LedCode::N, "regular".to_owned()), - (LedCode::M, "regular".to_owned()), - (LedCode::Comma, "regular".to_owned()), - (LedCode::Period, "regular".to_owned()), - (LedCode::FwdSlash, "regular".to_owned()), - (LedCode::Rshift, "regular".to_owned()), - ], - ), - KeyRow::new( - 0.1, - 0.1, - vec![ - (LedCode::LCtrl, "regular".to_owned()), - (LedCode::LFn, "regular".to_owned()), - (LedCode::Meta, "regular".to_owned()), - (LedCode::LAlt, "regular".to_owned()), - (LedCode::Spacebar, "regular".to_owned()), - (LedCode::RAlt, "regular".to_owned()), - (LedCode::PrtSc, "regular".to_owned()), - (LedCode::RCtrl, "regular".to_owned()), - ], - ), - ], + KeyRow::new(0.1, 0.1, vec![ + (LedCode::Esc, "regular".to_owned()), + (LedCode::F1, "regular".to_owned()), + (LedCode::F2, "regular".to_owned()), + (LedCode::F3, "regular".to_owned()), + (LedCode::F4, "regular".to_owned()), + // not sure which key to put here + (LedCode::F5, "regular".to_owned()), + (LedCode::F6, "regular".to_owned()), + (LedCode::F7, "regular".to_owned()), + (LedCode::F8, "regular".to_owned()), + (LedCode::F9, "regular".to_owned()), + (LedCode::F10, "regular".to_owned()), + (LedCode::F11, "regular".to_owned()), + (LedCode::F12, "regular".to_owned()), + ]), + KeyRow::new(0.1, 0.1, vec![ + (LedCode::Tilde, "regular".to_owned()), + (LedCode::N1, "regular".to_owned()), + (LedCode::N2, "regular".to_owned()), + (LedCode::N3, "regular".to_owned()), + (LedCode::N4, "regular".to_owned()), + (LedCode::N5, "regular".to_owned()), + (LedCode::N6, "regular".to_owned()), + (LedCode::N7, "regular".to_owned()), + (LedCode::N8, "regular".to_owned()), + (LedCode::N9, "regular".to_owned()), + (LedCode::N0, "regular".to_owned()), + (LedCode::Hyphen, "regular".to_owned()), + (LedCode::Equals, "regular".to_owned()), + (LedCode::Backspace, "regular".to_owned()), + ]), + KeyRow::new(0.1, 0.1, vec![ + (LedCode::Tab, "regular".to_owned()), + (LedCode::Q, "regular".to_owned()), + (LedCode::W, "regular".to_owned()), + (LedCode::E, "regular".to_owned()), + (LedCode::R, "regular".to_owned()), + (LedCode::T, "regular".to_owned()), + (LedCode::Y, "regular".to_owned()), + (LedCode::U, "regular".to_owned()), + (LedCode::I, "regular".to_owned()), + (LedCode::O, "regular".to_owned()), + (LedCode::P, "regular".to_owned()), + (LedCode::LBracket, "regular".to_owned()), + (LedCode::RBracket, "regular".to_owned()), + (LedCode::BackSlash, "regular".to_owned()), + ]), + KeyRow::new(0.1, 0.1, vec![ + (LedCode::Caps, "regular".to_owned()), + (LedCode::A, "regular".to_owned()), + (LedCode::S, "regular".to_owned()), + (LedCode::D, "regular".to_owned()), + (LedCode::F, "regular".to_owned()), + (LedCode::G, "regular".to_owned()), + (LedCode::H, "regular".to_owned()), + (LedCode::J, "regular".to_owned()), + (LedCode::K, "regular".to_owned()), + (LedCode::L, "regular".to_owned()), + (LedCode::SemiColon, "regular".to_owned()), + (LedCode::Quote, "regular".to_owned()), + (LedCode::Return, "regular".to_owned()), + ]), + KeyRow::new(0.1, 0.1, vec![ + (LedCode::LShift, "regular".to_owned()), + (LedCode::Z, "regular".to_owned()), + (LedCode::X, "regular".to_owned()), + (LedCode::C, "regular".to_owned()), + (LedCode::V, "regular".to_owned()), + (LedCode::B, "regular".to_owned()), + (LedCode::N, "regular".to_owned()), + (LedCode::M, "regular".to_owned()), + (LedCode::Comma, "regular".to_owned()), + (LedCode::Period, "regular".to_owned()), + (LedCode::FwdSlash, "regular".to_owned()), + (LedCode::Rshift, "regular".to_owned()), + ]), + KeyRow::new(0.1, 0.1, vec![ + (LedCode::LCtrl, "regular".to_owned()), + (LedCode::LFn, "regular".to_owned()), + (LedCode::Meta, "regular".to_owned()), + (LedCode::LAlt, "regular".to_owned()), + (LedCode::Spacebar, "regular".to_owned()), + (LedCode::RAlt, "regular".to_owned()), + (LedCode::PrtSc, "regular".to_owned()), + (LedCode::RCtrl, "regular".to_owned()), + ]), + ] } } } diff --git a/rog-aura/src/keyboard/mod.rs b/rog-aura/src/keyboard/mod.rs index 16d2ee61..64ecbe59 100644 --- a/rog-aura/src/keyboard/mod.rs +++ b/rog-aura/src/keyboard/mod.rs @@ -16,5 +16,5 @@ pub enum AdvancedAuraType { #[default] None, Zoned(Vec), - PerKey, + PerKey } diff --git a/rog-aura/src/keyboard/power.rs b/rog-aura/src/keyboard/power.rs index af25a281..32e74b52 100644 --- a/rog-aura/src/keyboard/power.rs +++ b/rog-aura/src/keyboard/power.rs @@ -23,7 +23,7 @@ pub struct AuraPowerState { pub awake: bool, pub sleep: bool, /// Ignored for pre-2021 and Tuf - pub shutdown: bool, + pub shutdown: bool } impl Default for AuraPowerState { @@ -34,7 +34,7 @@ impl Default for AuraPowerState { boot: true, awake: true, sleep: true, - shutdown: true, + shutdown: true } } } @@ -46,13 +46,15 @@ impl AuraPowerState { boot: true, awake: true, sleep: true, - shutdown: true, + shutdown: true } } fn tuf_to_bytes(&self) -> Vec { // &cmd, &boot, &awake, &sleep, &keyboard - vec![1, self.boot as u8, self.awake as u8, self.sleep as u8, 1] + vec![ + 1, self.boot as u8, self.awake as u8, self.sleep as u8, 1, + ] } /// # Bits for older 0x1866 keyboard model @@ -104,41 +106,41 @@ impl AuraPowerState { match self.zone { PowerZones::Logo => { self.boot as u32 - | (self.awake as u32) << 2 - | (self.sleep as u32) << 4 - | (self.shutdown as u32) << 6 + | ((self.awake as u32) << 2) + | ((self.sleep as u32) << 4) + | ((self.shutdown as u32) << 6) } PowerZones::Ally => { (self.boot as u32) - | (self.awake as u32) << 1 - | (self.sleep as u32) << 2 - | (self.shutdown as u32) << 3 + | ((self.awake as u32) << 1) + | ((self.sleep as u32) << 2) + | ((self.shutdown as u32) << 3) } PowerZones::Keyboard => { - (self.boot as u32) << 1 - | (self.awake as u32) << 3 - | (self.sleep as u32) << 5 - | (self.shutdown as u32) << 7 + ((self.boot as u32) << 1) + | ((self.awake as u32) << 3) + | ((self.sleep as u32) << 5) + | ((self.shutdown as u32) << 7) } PowerZones::Lightbar => { - (self.boot as u32) << (7 + 2) - | (self.awake as u32) << (7 + 3) - | (self.sleep as u32) << (7 + 4) - | (self.shutdown as u32) << (7 + 5) + ((self.boot as u32) << (7 + 2)) + | ((self.awake as u32) << (7 + 3)) + | ((self.sleep as u32) << (7 + 4)) + | ((self.shutdown as u32) << (7 + 5)) } PowerZones::Lid => { - (self.boot as u32) << (15 + 1) - | (self.awake as u32) << (15 + 2) - | (self.sleep as u32) << (15 + 3) - | (self.shutdown as u32) << (15 + 4) + ((self.boot as u32) << (15 + 1)) + | ((self.awake as u32) << (15 + 2)) + | ((self.sleep as u32) << (15 + 3)) + | ((self.shutdown as u32) << (15 + 4)) } PowerZones::RearGlow => { - (self.boot as u32) << (23 + 1) - | (self.awake as u32) << (23 + 2) - | (self.sleep as u32) << (23 + 3) - | (self.shutdown as u32) << (23 + 4) + ((self.boot as u32) << (23 + 1)) + | ((self.awake as u32) << (23 + 2)) + | ((self.sleep as u32) << (23 + 3)) + | ((self.shutdown as u32) << (23 + 4)) } - PowerZones::None | PowerZones::KeyboardAndLightbar => 0, + PowerZones::None | PowerZones::KeyboardAndLightbar => 0 } } } @@ -146,7 +148,7 @@ impl AuraPowerState { #[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))] #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct LaptopAuraPower { - pub states: Vec, + pub states: Vec } impl LaptopAuraPower { @@ -204,26 +206,32 @@ impl LaptopAuraPower { // 3. KeyboardAndLightbar if support_data.power_zones.contains(&PowerZones::Lightbar) { Self { - states: vec![AuraPowerState::default_for(PowerZones::KeyboardAndLightbar)], + states: vec![AuraPowerState::default_for(PowerZones::KeyboardAndLightbar)] } } else { Self { - states: vec![AuraPowerState::default_for(PowerZones::Keyboard)], + states: vec![AuraPowerState::default_for(PowerZones::Keyboard)] } } } AuraDeviceType::LaptopKeyboardTuf => Self { - states: vec![AuraPowerState::default_for(PowerZones::Keyboard)], + states: vec![AuraPowerState::default_for(PowerZones::Keyboard)] }, AuraDeviceType::ScsiExtDisk => todo!(), - AuraDeviceType::AnimeOrSlash => todo!(), + AuraDeviceType::AnimeOrSlash => todo!() } } pub fn to_bytes(&self, aura_type: AuraDeviceType) -> Vec { if let Some(stuff) = self.states.first() { if stuff.zone == PowerZones::Ally { - return vec![0x5d, 0xd1, 0x09, 0x01, stuff.new_to_byte() as u8]; + return vec![ + 0x5d, + 0xd1, + 0x09, + 0x01, + stuff.new_to_byte() as u8, + ]; } } match aura_type { @@ -258,7 +266,7 @@ impl LaptopAuraPower { self.new_to_bytes() } AuraDeviceType::ScsiExtDisk => todo!("scsi disk not implemented yet"), - AuraDeviceType::AnimeOrSlash => todo!("anime/slash not implemented yet"), + AuraDeviceType::AnimeOrSlash => todo!("anime/slash not implemented yet") } } } @@ -277,7 +285,7 @@ enum OldAuraPower { Boot = 0xc31209, Sleep = 0x300804, Keyboard = 0x080000, - Lightbar = 0x040500, + Lightbar = 0x040500 } impl BitOr for OldAuraPower { @@ -318,26 +326,30 @@ mod test { #[test] fn check_0x1866_control_bytes() { let power = LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Keyboard, - boot: false, - awake: true, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Keyboard, + boot: false, + awake: true, + sleep: false, + shutdown: false + }, + ] }; let bytes = power.to_bytes(AuraDeviceType::LaptopKeyboardPre2021); println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]); assert_eq!(bytes, [0x08, 0x00, 0x02, 0x00]); let power = LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Lightbar, - boot: false, - awake: true, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Lightbar, + boot: false, + awake: true, + sleep: false, + shutdown: false + }, + ] }; let bytes = power.to_bytes(AuraDeviceType::LaptopKeyboardPre2021); println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]); @@ -357,16 +369,16 @@ mod test { boot: true, awake: true, sleep: true, - shutdown: false, + shutdown: false }, AuraPowerState { zone: PowerZones::Lightbar, boot: true, awake: true, sleep: true, - shutdown: false, + shutdown: false }, - ], + ] }; let bytes = power.to_bytes(AuraDeviceType::LaptopKeyboardPre2021); println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]); @@ -376,184 +388,224 @@ mod test { #[test] fn check_0x19b6_control_bytes_binary_rep() { let boot_logo_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Logo, - boot: true, - awake: false, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Logo, + boot: true, + awake: false, + sleep: false, + shutdown: false + }, + ] }); let boot_keyb_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Keyboard, - boot: true, - awake: false, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Keyboard, + boot: true, + awake: false, + sleep: false, + shutdown: false + }, + ] }); let sleep_logo = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Logo, - boot: false, - awake: false, - sleep: true, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Logo, + boot: false, + awake: false, + sleep: true, + shutdown: false + }, + ] }); let sleep_keyb = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Keyboard, - boot: false, - awake: false, - sleep: true, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Keyboard, + boot: false, + awake: false, + sleep: true, + shutdown: false + }, + ] }); let awake_logo = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Logo, - boot: false, - awake: true, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Logo, + boot: false, + awake: true, + sleep: false, + shutdown: false + }, + ] }); let awake_keyb = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Keyboard, - boot: false, - awake: true, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Keyboard, + boot: false, + awake: true, + sleep: false, + shutdown: false + }, + ] }); let shut_logo_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Logo, - boot: false, - awake: false, - sleep: false, - shutdown: true, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Logo, + boot: false, + awake: false, + sleep: false, + shutdown: true + }, + ] }); let shut_keyb_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Keyboard, - boot: false, - awake: false, - sleep: false, - shutdown: true, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Keyboard, + boot: false, + awake: false, + sleep: false, + shutdown: true + }, + ] }); let boot_bar__ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Lightbar, - boot: true, - awake: false, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Lightbar, + boot: true, + awake: false, + sleep: false, + shutdown: false + }, + ] }); let awake_bar_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Lightbar, - boot: false, - awake: true, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Lightbar, + boot: false, + awake: true, + sleep: false, + shutdown: false + }, + ] }); let sleep_bar_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Lightbar, - boot: false, - awake: false, - sleep: true, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Lightbar, + boot: false, + awake: false, + sleep: true, + shutdown: false + }, + ] }); let shut_bar__ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Lightbar, - boot: false, - awake: false, - sleep: false, - shutdown: true, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Lightbar, + boot: false, + awake: false, + sleep: false, + shutdown: true + }, + ] }); let boot_lid__ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Lid, - boot: true, - awake: false, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Lid, + boot: true, + awake: false, + sleep: false, + shutdown: false + }, + ] }); let awake_lid_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Lid, - boot: false, - awake: true, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Lid, + boot: false, + awake: true, + sleep: false, + shutdown: false + }, + ] }); let sleep_lid_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Lid, - boot: false, - awake: false, - sleep: true, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Lid, + boot: false, + awake: false, + sleep: true, + shutdown: false + }, + ] }); let shut_lid__ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::Lid, - boot: false, - awake: false, - sleep: false, - shutdown: true, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::Lid, + boot: false, + awake: false, + sleep: false, + shutdown: true + }, + ] }); let boot_rear_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::RearGlow, - boot: true, - awake: false, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::RearGlow, + boot: true, + awake: false, + sleep: false, + shutdown: false + }, + ] }); let awake_rear = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::RearGlow, - boot: false, - awake: true, - sleep: false, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::RearGlow, + boot: false, + awake: true, + sleep: false, + shutdown: false + }, + ] }); let sleep_rear = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::RearGlow, - boot: false, - awake: false, - sleep: true, - shutdown: false, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::RearGlow, + boot: false, + awake: false, + sleep: true, + shutdown: false + }, + ] }); let shut_rear_ = to_binary_string_post2021(&LaptopAuraPower { - states: vec![AuraPowerState { - zone: PowerZones::RearGlow, - boot: false, - awake: false, - sleep: false, - shutdown: true, - }], + states: vec![ + AuraPowerState { + zone: PowerZones::RearGlow, + boot: false, + awake: false, + sleep: false, + shutdown: true + }, + ] }); assert_eq!(boot_logo_, "00000001, 00000000, 00000000, 00000000"); @@ -603,7 +655,7 @@ mod test { zone: PowerZones::RearGlow, ..Default::default() }, - ], + ] }); assert_eq!(byte1, "11111111, 00011110, 00001111, 00001111"); } diff --git a/rog-aura/src/lib.rs b/rog-aura/src/lib.rs index bb7e155b..2480e157 100644 --- a/rog-aura/src/lib.rs +++ b/rog-aura/src/lib.rs @@ -29,39 +29,41 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const RED: Colour = Colour { r: 0xff, g: 0x00, - b: 0x00, + b: 0x00 }; pub const GREEN: Colour = Colour { r: 0x00, g: 0xff, - b: 0x00, + b: 0x00 }; pub const BLUE: Colour = Colour { r: 0x00, g: 0x00, - b: 0xff, + b: 0xff }; pub const VIOLET: Colour = Colour { r: 0x9b, g: 0x26, - b: 0xb6, + b: 0xb6 }; pub const TEAL: Colour = Colour { r: 0x00, g: 0x7c, - b: 0x80, + b: 0x80 }; pub const YELLOW: Colour = Colour { r: 0xff, g: 0xef, - b: 0x00, + b: 0x00 }; pub const ORANGE: Colour = Colour { r: 0xff, g: 0xa4, - b: 0x00, + b: 0x00 }; -pub const GRADIENT: [Colour; 7] = [RED, VIOLET, BLUE, TEAL, GREEN, YELLOW, ORANGE]; +pub const GRADIENT: [Colour; 7] = [ + RED, VIOLET, BLUE, TEAL, GREEN, YELLOW, ORANGE +]; #[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -74,7 +76,7 @@ pub enum AuraDeviceType { ScsiExtDisk = 3, Ally = 4, AnimeOrSlash = 5, - Unknown = 255, + Unknown = 255 } impl AuraDeviceType { @@ -108,7 +110,7 @@ impl From<&str> for AuraDeviceType { "1abe" | "1b4c" => Self::Ally, "19b3" | "193b" => Self::AnimeOrSlash, "19b6" => Self::LaptopKeyboard2021, - _ => Self::Unknown, + _ => Self::Unknown } } } @@ -136,5 +138,5 @@ pub enum PowerZones { KeyboardAndLightbar = 5, /// Ally specific for creating correct packet Ally = 6, - None = 255, + None = 255 } diff --git a/rog-aura/src/usb.rs b/rog-aura/src/usb.rs index 470a383b..20592593 100644 --- a/rog-aura/src/usb.rs +++ b/rog-aura/src/usb.rs @@ -1,4 +1,7 @@ // Only these two packets must be 17 bytes -pub const AURA_LAPTOP_LED_APPLY: [u8; 17] = - [0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; -pub const AURA_LAPTOP_LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +pub const AURA_LAPTOP_LED_APPLY: [u8; 17] = [ + 0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +]; +pub const AURA_LAPTOP_LED_SET: [u8; 17] = [ + 0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +]; diff --git a/rog-control-center/build.rs b/rog-control-center/build.rs index a569b106..55fac09e 100644 --- a/rog-control-center/build.rs +++ b/rog-control-center/build.rs @@ -20,7 +20,7 @@ fn main() { CompilerConfiguration::new() // .embed_resources(EmbedResourcesKind::EmbedFiles) .with_include_paths(vec![include]) - .with_style("fluent-dark".into()), + .with_style("fluent-dark".into()) ) .unwrap(); } diff --git a/rog-control-center/src/cli_options.rs b/rog-control-center/src/cli_options.rs index d7bde2d4..f21f13a1 100644 --- a/rog-control-center/src/cli_options.rs +++ b/rog-control-center/src/cli_options.rs @@ -23,5 +23,5 @@ pub struct CliStart { help = "put ROGCC in layout viewing mode - this is helpful for finding existing layouts \ that might match your laptop" )] - pub layout_viewing: bool, + pub layout_viewing: bool } diff --git a/rog-control-center/src/config.rs b/rog-control-center/src/config.rs index ef8207f2..4cf789a2 100644 --- a/rog-control-center/src/config.rs +++ b/rog-control-center/src/config.rs @@ -21,7 +21,7 @@ pub struct Config { pub fullscreen_width: u32, pub fullscreen_height: u32, // This field must be last - pub notifications: EnabledNotifications, + pub notifications: EnabledNotifications } impl Default for Config { @@ -36,7 +36,7 @@ impl Default for Config { fullscreen_height: 1080, notifications: EnabledNotifications::default(), ac_command: String::new(), - bat_command: String::new(), + bat_command: String::new() } } } @@ -77,7 +77,7 @@ pub struct Config461 { pub enable_dgpu_notifications: bool, pub dark_mode: bool, // This field must be last - pub enabled_notifications: EnabledNotifications, + pub enabled_notifications: EnabledNotifications } impl From for Config { @@ -92,7 +92,7 @@ impl From for Config { start_fullscreen: false, fullscreen_width: 1920, fullscreen_height: 1080, - notifications: c.enabled_notifications, + notifications: c.enabled_notifications } } } diff --git a/rog-control-center/src/error.rs b/rog-control-center/src/error.rs index 951d0b0f..a5cfde9e 100644 --- a/rog-control-center/src/error.rs +++ b/rog-control-center/src/error.rs @@ -9,7 +9,7 @@ pub enum Error { ConfigLockFail, XdgVars, Zbus(zbus::Error), - Notification(notify_rust::error::Error), + Notification(notify_rust::error::Error) } impl fmt::Display for Error { @@ -21,7 +21,7 @@ impl fmt::Display for Error { Error::ConfigLockFail => write!(f, "Failed to lock user config"), Error::XdgVars => write!(f, "XDG environment vars appear unset"), Error::Zbus(err) => write!(f, "Error: {}", err), - Error::Notification(err) => write!(f, "Notification Error: {}", err), + Error::Notification(err) => write!(f, "Notification Error: {}", err) } } } diff --git a/rog-control-center/src/lib.rs b/rog-control-center/src/lib.rs index 07b52686..774da4de 100644 --- a/rog-control-center/src/lib.rs +++ b/rog-control-center/src/lib.rs @@ -38,5 +38,5 @@ pub enum Page { System, AuraEffects, AnimeMatrix, - FanCurves, + FanCurves } diff --git a/rog-control-center/src/main.rs b/rog-control-center/src/main.rs index 1e477e4f..32874563 100644 --- a/rog-control-center/src/main.rs +++ b/rog-control-center/src/main.rs @@ -17,7 +17,7 @@ use rog_control_center::slint::ComponentHandle; use rog_control_center::tray::init_tray; use rog_control_center::ui::setup_window; use rog_control_center::zbus_proxies::{ - AppState, ROGCCZbus, ROGCCZbusProxyBlocking, ZBUS_IFACE, ZBUS_PATH, + AppState, ROGCCZbus, ROGCCZbusProxyBlocking, ZBUS_IFACE, ZBUS_PATH }; use rog_control_center::{print_versions, MainWindow}; use tokio::runtime::Runtime; diff --git a/rog-control-center/src/mocking.rs b/rog-control-center/src/mocking.rs index 7c3b40fe..3fbc8419 100644 --- a/rog-control-center/src/mocking.rs +++ b/rog-control-center/src/mocking.rs @@ -5,7 +5,7 @@ use rog_aura::{AuraEffect, AuraModeNum, AuraZone}; use rog_platform::platform::GpuMode; use rog_platform::supported::{ AdvancedAura, AnimeSupportedFunctions, ChargeSupportedFunctions, LedSupportedFunctions, - PlatformProfileFunctions, RogBiosSupportedFunctions, SupportedFunctions, + PlatformProfileFunctions, RogBiosSupportedFunctions, SupportedFunctions }; use rog_profiles::fan_curve_set::{CurveData, FanCurveSet}; use supergfxctl::pci_device::{GfxMode, GfxPower}; @@ -16,7 +16,7 @@ const NOPE: &str = ""; #[derive(Default)] pub struct DaemonProxyBlocking<'a> { - _phantom: &'a str, + _phantom: &'a str } impl<'a> DaemonProxyBlocking<'a> { @@ -35,7 +35,7 @@ impl<'a> DaemonProxyBlocking<'a> { #[derive(Default)] pub struct RogDbusClientBlocking<'a> { - _phantom: &'a str, + _phantom: &'a str } impl<'a> RogDbusClientBlocking<'a> { @@ -125,10 +125,18 @@ impl Profile { pub fn fan_curve_data(&self, _p: rog_profiles::Profile) -> Result { let mut curve = FanCurveSet::default(); - curve.cpu.pwm = [30, 40, 60, 100, 140, 180, 200, 250]; - curve.cpu.temp = [20, 30, 40, 50, 70, 80, 90, 100]; - curve.gpu.pwm = [40, 80, 100, 140, 170, 200, 230, 250]; - curve.gpu.temp = [20, 30, 40, 50, 70, 80, 90, 100]; + curve.cpu.pwm = [ + 30, 40, 60, 100, 140, 180, 200, 250 + ]; + curve.cpu.temp = [ + 20, 30, 40, 50, 70, 80, 90, 100 + ]; + curve.gpu.pwm = [ + 40, 80, 100, 140, 170, 200, 230, 250 + ]; + curve.gpu.temp = [ + 20, 30, 40, 50, 70, 80, 90, 100 + ]; Ok(curve) } @@ -196,7 +204,7 @@ impl Led { AuraDevRog2::AwakeKeyb, AuraDevRog2::SleepLogo, AuraDevRog2::AwakeLogo, - ], + ] }) } @@ -234,11 +242,11 @@ impl Supported { Ok(SupportedFunctions { anime_ctrl: AnimeSupportedFunctions(true), charge_ctrl: ChargeSupportedFunctions { - charge_level_set: true, + charge_level_set: true }, platform_profile: PlatformProfileFunctions { platform_profile: true, - fan_curves: true, + fan_curves: true }, keyboard_led: LedSupportedFunctions { dev_id: AuraDevice::X19b6, @@ -259,7 +267,7 @@ impl Supported { AuraZone::BarRight, AuraZone::Logo, ], - advanced_type: AdvancedAura::PerKey, + advanced_type: AdvancedAura::PerKey }, rog_bios_ctrl: RogBiosSupportedFunctions { post_sound: true, @@ -267,8 +275,8 @@ impl Supported { panel_overdrive: true, dgpu_disable: true, mini_led_mode: true, - egpu_enable: true, - }, + egpu_enable: true + } }) } } diff --git a/rog-control-center/src/notify.rs b/rog-control-center/src/notify.rs index d3aee2ce..bc83bda9 100644 --- a/rog-control-center/src/notify.rs +++ b/rog-control-center/src/notify.rs @@ -32,7 +32,7 @@ const NOTIF_HEADER: &str = "ROG Control"; pub struct EnabledNotifications { pub enabled: bool, pub receive_notify_gfx: bool, - pub receive_notify_gfx_status: bool, + pub receive_notify_gfx_status: bool } impl Default for EnabledNotifications { @@ -40,7 +40,7 @@ impl Default for EnabledNotifications { Self { enabled: true, receive_notify_gfx: true, - receive_notify_gfx_status: true, + receive_notify_gfx_status: true } } } @@ -93,7 +93,7 @@ fn start_dpu_status_mon(config: Arc>) { pub fn start_notifications( config: Arc>, - rt: &Runtime, + rt: &Runtime ) -> Result>> { // Setup the AC/BAT commands that will run on power status change let config_copy = config.clone(); @@ -213,7 +213,7 @@ pub fn start_notifications( supergfxctl::actions::UserActionRequired::Reboot => { do_mux_notification("Graphics mode change requires reboot", &mode) } - _ => do_gfx_action_notif(<&str>::from(action), *action, mode), + _ => do_gfx_action_notif(<&str>::from(action), *action, mode) } .map_err(|e| { error!("zbus signal: do_gfx_action_notif: {e}"); @@ -265,13 +265,13 @@ fn convert_gfx_mode(gfx: GfxMode) -> GpuMode { GfxMode::Vfio => GpuMode::Vfio, GfxMode::AsusEgpu => GpuMode::Egpu, GfxMode::AsusMuxDgpu => GpuMode::Ultimate, - GfxMode::None => GpuMode::Error, + GfxMode::None => GpuMode::Error } } fn base_notification(message: &str, data: &T) -> Notification where - T: Display, + T: Display { let mut notif = Notification::new(); notif @@ -289,7 +289,7 @@ fn do_gpu_status_notif(message: &str, data: &GfxPower) -> Notification { GfxPower::Off => "asus_notif_green", GfxPower::AsusDisabled => "asus_notif_white", GfxPower::AsusMuxDiscreet | GfxPower::Active => "asus_notif_red", - GfxPower::Unknown => "gpu-integrated", + GfxPower::Unknown => "gpu-integrated" }; notif.icon(icon); notif @@ -329,7 +329,9 @@ fn do_gfx_action_notif(message: &str, action: GfxUserAction, mode: GpuMode) -> R handle.wait_for_action(|id| { if id == "gfx-mode-session-action" { let mut cmd = Command::new("qdbus"); - cmd.args(["org.kde.ksmserver", "/KSMServer", "logout", "1", "0", "0"]); + cmd.args([ + "org.kde.ksmserver", "/KSMServer", "logout", "1", "0", "0" + ]); cmd.spawn().ok(); } else if id == "__closed" { // TODO: cancel the switching @@ -371,7 +373,9 @@ fn do_mux_notification(message: &str, m: &GpuMode) -> Result<()> { handle.wait_for_action(|id| { if id == "gfx-mode-session-action" { let mut cmd = Command::new("qdbus"); - cmd.args(["org.kde.ksmserver", "/KSMServer", "logout", "1", "1", "0"]); + cmd.args([ + "org.kde.ksmserver", "/KSMServer", "logout", "1", "1", "0" + ]); cmd.spawn().ok(); } else if id == "__closed" { // TODO: cancel the switching diff --git a/rog-control-center/src/tray.rs b/rog-control-center/src/tray.rs index 6463f9f7..8a3ca014 100644 --- a/rog-control-center/src/tray.rs +++ b/rog-control-center/src/tray.rs @@ -24,7 +24,7 @@ struct Icons { rog_red: Icon, rog_green: Icon, rog_white: Icon, - gpu_integrated: Icon, + gpu_integrated: Icon } static ICONS: OnceLock = OnceLock::new(); @@ -48,14 +48,14 @@ fn read_icon(file: &Path) -> Icon { Icon { width: width as i32, height: height as i32, - data: img.into_raw(), + data: img.into_raw() } } struct AsusTray { current_title: String, current_icon: Icon, - proxy: ROGCCZbusProxyBlocking<'static>, + proxy: ROGCCZbusProxyBlocking<'static> } impl ksni::Tray for AsusTray { @@ -103,7 +103,7 @@ async fn set_tray_icon_and_tip( mode: GfxMode, power: GfxPower, tray: &mut Handle, - supergfx_active: bool, + supergfx_active: bool ) { if let Some(icons) = ICONS.get() { let icon = match power { @@ -163,7 +163,7 @@ pub fn init_tray(_supported_properties: Vec, config: Arc, config: Arc, config: Arc warn!("Couldn't get mode form supergfxd: {e:?}"), + Err(e) => warn!("Couldn't get mode form supergfxd: {e:?}") } info!("Started ROGTray"); diff --git a/rog-control-center/src/types/aura_types.rs b/rog-control-center/src/types/aura_types.rs index f1f28e6c..cece6ea2 100644 --- a/rog-control-center/src/types/aura_types.rs +++ b/rog-control-center/src/types/aura_types.rs @@ -1,6 +1,6 @@ use crate::slint_generatedMainWindow::{ AuraDevType as SlintDeviceType, AuraPowerState as SlintAuraPowerState, - LaptopAuraPower as SlintLaptopAuraPower, + LaptopAuraPower as SlintLaptopAuraPower }; impl From for crate::slint_generatedMainWindow::AuraEffect { @@ -10,20 +10,20 @@ impl From for crate::slint_generatedMainWindow::AuraEffect red: m.colour1.r, green: m.colour1.g, blue: m.colour1.b, - alpha: 255, + alpha: 255 } .into(), colour2: RgbaColor { red: m.colour2.r, green: m.colour2.g, blue: m.colour2.b, - alpha: 255, + alpha: 255 } .into(), direction: m.direction.into(), mode: m.mode.into(), speed: m.speed.into(), - zone: m.zone.into(), + zone: m.zone.into() } } } @@ -36,17 +36,17 @@ impl From for rog_aura::AuraEffect colour1: rog_aura::Colour { r: c1.red, g: c1.green, - b: c1.blue, + b: c1.blue }, colour2: rog_aura::Colour { r: c2.red, g: c2.green, - b: c2.blue, + b: c2.blue }, direction: m.direction.into(), mode: m.mode.into(), speed: m.speed.into(), - zone: m.zone.into(), + zone: m.zone.into() } } } @@ -66,7 +66,7 @@ impl From for SlintPowerZones { PowerZones::RearGlow => SlintPowerZones::RearGlow, PowerZones::KeyboardAndLightbar => SlintPowerZones::KeyboardAndLightbar, PowerZones::Ally => SlintPowerZones::Ally, - PowerZones::None => SlintPowerZones::Keyboard, + PowerZones::None => SlintPowerZones::Keyboard } } } @@ -80,7 +80,7 @@ impl From for PowerZones { SlintPowerZones::Lid => PowerZones::Lid, SlintPowerZones::RearGlow => PowerZones::RearGlow, SlintPowerZones::KeyboardAndLightbar => PowerZones::KeyboardAndLightbar, - SlintPowerZones::Ally => PowerZones::Ally, + SlintPowerZones::Ally => PowerZones::Ally } } } @@ -92,7 +92,7 @@ impl From for AuraPowerState { boot: value.boot, awake: value.awake, sleep: value.sleep, - shutdown: value.shutdown, + shutdown: value.shutdown } } } @@ -106,7 +106,7 @@ impl From for SlintAuraPowerState { sleep: value.sleep, shutdown: value.shutdown, zone, - zone_name_idx: zone as i32, + zone_name_idx: zone as i32 } } } @@ -120,7 +120,7 @@ impl From<&AuraPowerState> for SlintAuraPowerState { sleep: value.sleep, shutdown: value.shutdown, zone, - zone_name_idx: zone as i32, + zone_name_idx: zone as i32 } } } @@ -140,7 +140,7 @@ impl From for SlintLaptopAuraPower { let converted: Vec = value.states.iter().map(SlintAuraPowerState::from).collect(); Self { - states: ModelRc::from(converted.as_slice()), + states: ModelRc::from(converted.as_slice()) } } } @@ -154,7 +154,7 @@ impl From for AuraDeviceType { SlintDeviceType::ScsiExtDisk => Self::ScsiExtDisk, SlintDeviceType::Unknown => Self::Unknown, SlintDeviceType::Ally => Self::Ally, - SlintDeviceType::AnimeOrSlash => Self::AnimeOrSlash, + SlintDeviceType::AnimeOrSlash => Self::AnimeOrSlash } } } @@ -168,7 +168,7 @@ impl From for SlintDeviceType { AuraDeviceType::ScsiExtDisk => SlintDeviceType::ScsiExtDisk, AuraDeviceType::Unknown => SlintDeviceType::Unknown, AuraDeviceType::Ally => SlintDeviceType::Ally, - AuraDeviceType::AnimeOrSlash => SlintDeviceType::AnimeOrSlash, + AuraDeviceType::AnimeOrSlash => SlintDeviceType::AnimeOrSlash } } } diff --git a/rog-control-center/src/types/fan_types.rs b/rog-control-center/src/types/fan_types.rs index 013e263b..2e3224a9 100644 --- a/rog-control-center/src/types/fan_types.rs +++ b/rog-control-center/src/types/fan_types.rs @@ -8,7 +8,7 @@ impl From for ThrottlePolicy { match value { Profile::Balanced => ThrottlePolicy::Balanced, Profile::Performance => ThrottlePolicy::Performance, - Profile::Quiet => ThrottlePolicy::Quiet, + Profile::Quiet => ThrottlePolicy::Quiet } } } @@ -18,7 +18,7 @@ impl From for Profile { match value { ThrottlePolicy::Balanced => Profile::Balanced, ThrottlePolicy::Performance => Profile::Performance, - ThrottlePolicy::Quiet => Profile::Quiet, + ThrottlePolicy::Quiet => Profile::Quiet } } } @@ -28,7 +28,7 @@ impl From for FanCurvePU { match value { FanType::CPU => FanCurvePU::CPU, FanType::Middle => FanCurvePU::MID, - FanType::GPU => FanCurvePU::GPU, + FanType::GPU => FanCurvePU::GPU } } } @@ -38,7 +38,7 @@ impl From for FanType { match value { FanCurvePU::CPU => FanType::CPU, FanCurvePU::GPU => FanType::GPU, - FanCurvePU::MID => FanType::Middle, + FanCurvePU::MID => FanType::Middle } } } diff --git a/rog-control-center/src/ui/mod.rs b/rog-control-center/src/ui/mod.rs index 7b33e3b5..3531aceb 100644 --- a/rog-control-center/src/ui/mod.rs +++ b/rog-control-center/src/ui/mod.rs @@ -67,7 +67,7 @@ pub fn show_toast( success: SharedString, fail: SharedString, handle: Weak, - result: zbus::Result<()>, + result: zbus::Result<()> ) { match result { Ok(_) => { @@ -77,7 +77,7 @@ pub fn show_toast( log::warn!("{fail}: {e}"); handle.unwrap().invoke_show_toast(fail) }) - .ok(), + .ok() }; } @@ -102,9 +102,9 @@ pub fn setup_window(config: Arc>) -> MainWindow { available.contains(&"xyz.ljones.Anime".to_string()), available.contains(&"xyz.ljones.FanCurves".to_string()), true, - true, + true ] - .into(), + .into() ); ui.on_exit_app(move || { diff --git a/rog-control-center/src/ui/setup_anime.rs b/rog-control-center/src/ui/setup_anime.rs index 1dbb43d8..462b2152 100644 --- a/rog-control-center/src/ui/setup_anime.rs +++ b/rog-control-center/src/ui/setup_anime.rs @@ -52,9 +52,9 @@ pub fn setup_anime_page(ui: &MainWindow, _states: Arc>) { boot: boot.into(), awake: awake.into(), sleep: sleep.into(), - shutdown: shutdown.into(), + shutdown: shutdown.into() }) - .await, + .await ); }); }); diff --git a/rog-control-center/src/ui/setup_aura.rs b/rog-control-center/src/ui/setup_aura.rs index 627a015c..b51b4825 100644 --- a/rog-control-center/src/ui/setup_aura.rs +++ b/rog-control-center/src/ui/setup_aura.rs @@ -9,7 +9,7 @@ use slint::{ComponentHandle, Model, RgbaColor, SharedString}; use crate::config::Config; use crate::ui::show_toast; use crate::{ - set_ui_callbacks, set_ui_props_async, AuraPageData, MainWindow, PowerZones as SlintPowerZones, + set_ui_callbacks, set_ui_props_async, AuraPageData, MainWindow, PowerZones as SlintPowerZones }; fn decode_hex(s: &str) -> RgbaColor { @@ -19,7 +19,7 @@ fn decode_hex(s: &str) -> RgbaColor { alpha: 255, red: 0, green: 0, - blue: 0, + blue: 0 }; } let c: Vec = (0..s.len()) @@ -30,7 +30,7 @@ fn decode_hex(s: &str) -> RgbaColor { alpha: 255, red: *c.first().unwrap_or(&255), green: *c.get(1).unwrap_or(&128), - blue: *c.get(2).unwrap_or(&32), + blue: *c.get(2).unwrap_or(&32) } } @@ -198,7 +198,7 @@ pub fn setup_aura_page(ui: &MainWindow, _states: Arc>) { "Aura power settings changed".into(), "Failed to set Aura power settings".into(), handle_copy, - proxy_copy.set_led_power(power).await, + proxy_copy.set_led_power(power).await ); }); }); diff --git a/rog-control-center/src/ui/setup_fans.rs b/rog-control-center/src/ui/setup_fans.rs index 206e8aea..7a470717 100644 --- a/rog-control-center/src/ui/setup_fans.rs +++ b/rog-control-center/src/ui/setup_fans.rs @@ -13,7 +13,7 @@ pub fn update_fan_data( handle: Weak, bal: Vec, perf: Vec, - quiet: Vec, + quiet: Vec ) { handle .upgrade_in_event_loop(move |handle| { @@ -24,7 +24,7 @@ pub fn update_fan_data( .zip(pwm.iter()) .map(|(x, y)| Node { x: *x as f32, - y: *y as f32, + y: *y as f32 }) .collect(); tmp.as_slice().into() @@ -199,6 +199,6 @@ fn fan_data_for(fan: FanType, enabled: bool, data: Vec) -> CurveData { fan: fan.into(), pwm, temp, - enabled, + enabled } } diff --git a/rog-control-center/src/ui/setup_system.rs b/rog-control-center/src/ui/setup_system.rs index 78c3e0f6..19550312 100644 --- a/rog-control-center/src/ui/setup_system.rs +++ b/rog-control-center/src/ui/setup_system.rs @@ -15,7 +15,7 @@ use crate::{set_ui_props_async, AttrMinMax, MainWindow, SystemPageData}; const MINMAX: AttrMinMax = AttrMinMax { min: 0, max: 0, - val: -1.0, + val: -1.0 }; pub fn setup_system_page(ui: &MainWindow, _config: Arc>) { diff --git a/rog-control-center/src/zbus_proxies.rs b/rog-control-center/src/zbus_proxies.rs index a8adcc66..0fcd9af3 100644 --- a/rog-control-center/src/zbus_proxies.rs +++ b/rog-control-center/src/zbus_proxies.rs @@ -14,17 +14,18 @@ pub enum AppState { MainWindowClosed = 2, StartingUp = 3, QuitApp = 4, - LockFailed = 5, + LockFailed = 5 } pub struct ROGCCZbus { - state: Arc>, + state: Arc> } impl ROGCCZbus { + #[allow(clippy::new_without_default)] pub fn new() -> Self { Self { - state: Arc::new(Mutex::new(AppState::StartingUp)), + state: Arc::new(Mutex::new(AppState::StartingUp)) } } @@ -71,7 +72,7 @@ pub trait ROGCCZbus { pub fn find_iface(iface_name: &str) -> Result, Box> where - T: ProxyImpl<'static> + From>, + T: ProxyImpl<'static> + From> { let conn = Connection::system().unwrap(); let f = fdo::ObjectManagerProxy::new(&conn, "xyz.ljones.Asusd", "/").unwrap(); @@ -98,7 +99,7 @@ where T::builder(&conn) .path(path.clone())? .destination("xyz.ljones.Asusd")? - .build()?, + .build()? ); } return Ok(ctrl); @@ -109,7 +110,7 @@ where pub async fn find_iface_async(iface_name: &str) -> Result, Box> where - T: zbus::proxy::ProxyImpl<'static> + From>, + T: zbus::proxy::ProxyImpl<'static> + From> { let conn = zbus::Connection::system().await.unwrap(); let f = zbus::fdo::ObjectManagerProxy::new(&conn, "xyz.ljones.Asusd", "/") @@ -139,7 +140,7 @@ where .path(path.clone())? .destination("xyz.ljones.Asusd")? .build() - .await?, + .await? ); } return Ok(ctrl); diff --git a/rog-control-center/translations/en/rog-control-center.po b/rog-control-center/translations/en/rog-control-center.po index 2260f6c1..54650bd2 100644 --- a/rog-control-center/translations/en/rog-control-center.po +++ b/rog-control-center/translations/en/rog-control-center.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2025-01-01 02:21+0000\n" +"POT-Creation-Date: 2025-01-12 04:36+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/rog-dbus/src/zbus_fan_curves.rs b/rog-dbus/src/zbus_fan_curves.rs index f83e0161..ec517e32 100644 --- a/rog-dbus/src/zbus_fan_curves.rs +++ b/rog-dbus/src/zbus_fan_curves.rs @@ -57,6 +57,6 @@ pub trait FanCurves { &self, profile: ThrottlePolicy, fan: FanCurvePU, - enabled: bool, + enabled: bool ) -> zbus::Result<()>; } diff --git a/rog-dbus/src/zbus_slash.rs b/rog-dbus/src/zbus_slash.rs index 5d925bf3..3c42e6cb 100644 --- a/rog-dbus/src/zbus_slash.rs +++ b/rog-dbus/src/zbus_slash.rs @@ -27,7 +27,37 @@ pub trait Slash { /// Slash modes property #[zbus(property)] - fn slash_mode(&self) -> zbus::Result; + fn mode(&self) -> zbus::Result; #[zbus(property)] - fn set_slash_mode(&self, value: SlashMode) -> zbus::Result<()>; + fn set_mode(&self, value: SlashMode) -> zbus::Result<()>; + + /// ShowBatteryWarning property + #[zbus(property)] + fn show_battery_warning(&self) -> zbus::Result; + #[zbus(property)] + fn set_show_battery_warning(&self, value: bool) -> zbus::Result<()>; + + /// ShowOnBattery property + #[zbus(property)] + fn show_on_battery(&self) -> zbus::Result; + #[zbus(property)] + fn set_show_on_battery(&self, value: bool) -> zbus::Result<()>; + + /// ShowOnBoot property + #[zbus(property)] + fn show_on_boot(&self) -> zbus::Result; + #[zbus(property)] + fn set_show_on_boot(&self, value: bool) -> zbus::Result<()>; + + /// ShowOnShutdown property + #[zbus(property)] + fn show_on_shutdown(&self) -> zbus::Result; + #[zbus(property)] + fn set_show_on_shutdown(&self, value: bool) -> zbus::Result<()>; + + /// ShowOnSleep property + #[zbus(property)] + fn show_on_sleep(&self) -> zbus::Result; + #[zbus(property)] + fn set_show_on_sleep(&self, value: bool) -> zbus::Result<()>; } diff --git a/rog-platform/examples/ally-gamepad-calibration.rs b/rog-platform/examples/ally-gamepad-calibration.rs index b716cdf6..d01fc4a6 100644 --- a/rog-platform/examples/ally-gamepad-calibration.rs +++ b/rog-platform/examples/ally-gamepad-calibration.rs @@ -10,7 +10,7 @@ pub fn main() -> Result<(), Box> { usb_node = Some(node); println!("Looked for keyboard controller 0x{}: Found", id); } - Err(err) => println!("Looked for keyboard controller: {err}"), + Err(err) => println!("Looked for keyboard controller: {err}") } if usb_node.is_none() { @@ -24,7 +24,7 @@ pub fn main() -> Result<(), Box> { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 ]; let x_stable = 2107; @@ -72,7 +72,7 @@ pub fn main() -> Result<(), Box> { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]; node.write_bytes(&packet)?; } @@ -82,7 +82,7 @@ pub fn main() -> Result<(), Box> { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 ]; node.write_bytes(&packet)?; diff --git a/rog-platform/examples/ally-gamepad-mode-changes.rs b/rog-platform/examples/ally-gamepad-mode-changes.rs index f8eb3bc7..8c347681 100644 --- a/rog-platform/examples/ally-gamepad-mode-changes.rs +++ b/rog-platform/examples/ally-gamepad-mode-changes.rs @@ -12,7 +12,7 @@ pub fn main() -> Result<(), Box> { usb_node = Some(node); println!("Looked for keyboard controller 0x{}: Found", id); } - Err(err) => println!("Looked for keyboard controller: {err}"), + Err(err) => println!("Looked for keyboard controller: {err}") } if usb_node.is_none() { @@ -23,19 +23,33 @@ pub fn main() -> Result<(), Box> { // node.write_bytes(&[0x5a, 0xd1, 0x0a, 0x01])?; // TODO: need to CHECK println!("Set mouse mode for 10 seconds"); - node.write_bytes(&[0x5a, 0xd1, 0x01, 0x01, 0x03])?; - node.write_bytes(&[0x5a, 0xd1, 0x0f, 0x20])?; - node.write_bytes(&[0x5a, 0xd1, 0x01, 0x01, 0x00])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x01, 0x01, 0x03 + ])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x0f, 0x20 + ])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x01, 0x01, 0x00 + ])?; sleep(Duration::from_secs(10)); println!("Set wasd mode for 10 seconds"); - node.write_bytes(&[0x5a, 0xd1, 0x01, 0x01, 0x02])?; - node.write_bytes(&[0x5a, 0xd1, 0x0f, 0x20])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x01, 0x01, 0x02 + ])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x0f, 0x20 + ])?; sleep(Duration::from_secs(10)); println!("Set back to gamepad mode"); - node.write_bytes(&[0x5a, 0xd1, 0x01, 0x01, 0x01])?; - node.write_bytes(&[0x5a, 0xd1, 0x0f, 0x20])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x01, 0x01, 0x01 + ])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x0f, 0x20 + ])?; Ok(()) } diff --git a/rog-platform/examples/ally-set-qam-secondary.rs b/rog-platform/examples/ally-set-qam-secondary.rs index 66bb89dd..86cee5f4 100644 --- a/rog-platform/examples/ally-set-qam-secondary.rs +++ b/rog-platform/examples/ally-set-qam-secondary.rs @@ -10,7 +10,7 @@ pub fn main() -> Result<(), Box> { usb_node = Some(node); println!("Looked for keyboard controller 0x{}: Found", id); } - Err(err) => println!("Looked for keyboard controller: {err}"), + Err(err) => println!("Looked for keyboard controller: {err}") } if usb_node.is_none() { @@ -21,9 +21,15 @@ pub fn main() -> Result<(), Box> { // node.write_bytes(&[0x5a, 0xd1, 0x0a, 0x01])?; // TODO: need to CHECK println!("Set mouse mode for 10 seconds"); - node.write_bytes(&[0x5a, 0xd1, 0x01, 0x01, 0x03])?; - node.write_bytes(&[0x5a, 0xd1, 0x0f, 0x20])?; - node.write_bytes(&[0x5a, 0xd1, 0x01, 0x01, 0x00])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x01, 0x01, 0x03 + ])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x0f, 0x20 + ])?; + node.write_bytes(&[ + 0x5a, 0xd1, 0x01, 0x01, 0x00 + ])?; // sleep(Duration::from_secs(10)); // println!("Set wasd mode for 10 seconds"); diff --git a/rog-platform/src/cpu.rs b/rog-platform/src/cpu.rs index 067bf033..49b1adef 100644 --- a/rog-platform/src/cpu.rs +++ b/rog-platform/src/cpu.rs @@ -18,7 +18,7 @@ const ATTR_EPP: &str = "cpufreq/energy_performance_preference"; /// which can drastically alter CPU performance. #[derive(Debug, PartialEq, Eq, PartialOrd, Clone)] pub struct CPUControl { - paths: Vec, + paths: Vec } impl CPUControl { @@ -54,7 +54,7 @@ impl CPUControl { } match device.attribute_value(ATTR_GOVERNOR) { Some(g) => info!("{ATTR_GOVERNOR}: {g:?}"), - None => return Err(PlatformError::CPU(format!("{ATTR_GOVERNOR} not found"))), + None => return Err(PlatformError::CPU(format!("{ATTR_GOVERNOR} not found"))) } match device.attribute_value(ATTR_AVAILABLE_EPP) { Some(g) => info!("{ATTR_AVAILABLE_EPP}: {g:?}"), @@ -66,7 +66,7 @@ impl CPUControl { } match device.attribute_value(ATTR_EPP) { Some(g) => info!("{ATTR_EPP}: {g:?}"), - None => return Err(PlatformError::CPU(format!("{ATTR_EPP} not found"))), + None => return Err(PlatformError::CPU(format!("{ATTR_EPP} not found"))) } supported = true; } @@ -77,7 +77,7 @@ impl CPUControl { } if cpu.paths.is_empty() { return Err(PlatformError::MissingFunction( - "asus-nb-wmi not found".into(), + "asus-nb-wmi not found".into() )); } Ok(cpu) @@ -154,7 +154,7 @@ impl CPUControl { pub enum CPUGovernor { Performance = 0, Powersave = 1, - BadValue = 2, + BadValue = 2 } impl From<&str> for CPUGovernor { @@ -162,7 +162,7 @@ impl From<&str> for CPUGovernor { match s { "performance" => Self::Performance, "powersave" => Self::Powersave, - _ => Self::BadValue, + _ => Self::BadValue } } } @@ -172,7 +172,7 @@ impl From for String { match g { CPUGovernor::Performance => "performance".to_string(), CPUGovernor::Powersave => "powersave".to_string(), - CPUGovernor::BadValue => "bad_value".to_string(), + CPUGovernor::BadValue => "bad_value".to_string() } } } @@ -198,7 +198,7 @@ pub enum CPUEPP { Performance = 1, BalancePerformance = 2, BalancePower = 3, - Power = 4, + Power = 4 } impl From for CPUEPP { @@ -206,7 +206,7 @@ impl From for CPUEPP { match value { ThrottlePolicy::Balanced => CPUEPP::BalancePerformance, ThrottlePolicy::Performance => CPUEPP::Performance, - ThrottlePolicy::Quiet => CPUEPP::Power, + ThrottlePolicy::Quiet => CPUEPP::Power } } } @@ -219,7 +219,7 @@ impl From<&str> for CPUEPP { "balance_performance" => Self::BalancePerformance, "balance_power" => Self::BalancePower, "power" => Self::Power, - _ => Self::Default, + _ => Self::Default } } } @@ -231,7 +231,7 @@ impl From for String { CPUEPP::Performance => "performance".to_string(), CPUEPP::BalancePerformance => "balance_performance".to_string(), CPUEPP::BalancePower => "balance_power".to_string(), - CPUEPP::Power => "power".to_string(), + CPUEPP::Power => "power".to_string() } } } @@ -244,7 +244,7 @@ impl From for CPUEPP { 2 => Self::BalancePerformance, 3 => Self::BalancePower, 4 => Self::Power, - _ => Self::Default, + _ => Self::Default } } } @@ -265,21 +265,18 @@ mod tests { fn check_cpu() { let cpu = CPUControl::new().unwrap(); assert_eq!(cpu.get_governor().unwrap(), CPUGovernor::Powersave); - assert_eq!( - cpu.get_available_governors().unwrap(), - vec![CPUGovernor::Performance, CPUGovernor::Powersave] - ); + assert_eq!(cpu.get_available_governors().unwrap(), vec![ + CPUGovernor::Performance, + CPUGovernor::Powersave + ]); assert_eq!(cpu.get_epp().unwrap(), CPUEPP::BalancePower); - assert_eq!( - cpu.get_available_epp().unwrap(), - vec![ - CPUEPP::Default, - CPUEPP::Performance, - CPUEPP::BalancePerformance, - CPUEPP::BalancePower, - CPUEPP::Power, - ] - ); + assert_eq!(cpu.get_available_epp().unwrap(), vec![ + CPUEPP::Default, + CPUEPP::Performance, + CPUEPP::BalancePerformance, + CPUEPP::BalancePower, + CPUEPP::Power, + ]); } } diff --git a/rog-platform/src/error.rs b/rog-platform/src/error.rs index c24bad42..1e43582b 100644 --- a/rog-platform/src/error.rs +++ b/rog-platform/src/error.rs @@ -22,7 +22,7 @@ pub enum PlatformError { InvalidValue, NoAuraKeyboard, NoAuraNode, - CPU(String), + CPU(String) } impl fmt::Display for PlatformError { @@ -52,7 +52,7 @@ impl fmt::Display for PlatformError { PlatformError::IoPath(path, detail) => write!(f, "{} {}", path, detail), PlatformError::NoAuraKeyboard => write!(f, "No supported Aura keyboard"), PlatformError::NoAuraNode => write!(f, "No Aura keyboard node found"), - PlatformError::CPU(s) => write!(f, "CPU control: {s}"), + PlatformError::CPU(s) => write!(f, "CPU control: {s}") } } } @@ -76,7 +76,7 @@ impl From for FdoErr { log::error!("PlatformError: got: {error}"); match error { PlatformError::NotSupported => FdoErr::NotSupported("".to_owned()), - _ => FdoErr::Failed(format!("Failed with {error}")), + _ => FdoErr::Failed(format!("Failed with {error}")) } } } diff --git a/rog-platform/src/firmware_attributes.rs b/rog-platform/src/firmware_attributes.rs index 6f2cd8ea..3fec9302 100644 --- a/rog-platform/src/firmware_attributes.rs +++ b/rog-platform/src/firmware_attributes.rs @@ -37,7 +37,7 @@ pub enum AttrValue { EnumInt(Vec), EnumStr(Vec), #[default] - None, + None } #[derive(Debug, Default, Clone)] @@ -49,7 +49,7 @@ pub struct Attribute { min_value: AttrValue, max_value: AttrValue, scalar_increment: AttrValue, - base_path: PathBuf, + base_path: PathBuf } impl Attribute { @@ -71,7 +71,7 @@ impl Attribute { Ok(AttrValue::String(val)) } } - Err(e) => Err(e), + Err(e) => Err(e) } } @@ -82,7 +82,7 @@ impl Attribute { let value_str = match new_value { AttrValue::Integer(val) => val.to_string(), AttrValue::String(val) => val, - _ => return Err(PlatformError::InvalidValue), + _ => return Err(PlatformError::InvalidValue) }; let mut file = OpenOptions::new().write(true).open(&path)?; @@ -114,7 +114,7 @@ impl Attribute { /// change, if they do then it is possibly a driver issue - although this is /// subject to `firmware_attributes` class changes in kernel. fn read_base_values( - base_path: &Path, + base_path: &Path ) -> (AttrValue, AttrValue, AttrValue, AttrValue, AttrValue) { let default_value = match read_string(&base_path.join("default_value")) { Ok(val) => { @@ -124,7 +124,7 @@ impl Attribute { AttrValue::String(val) } } - Err(_) => AttrValue::None, + Err(_) => AttrValue::None }; let possible_values = match read_string(&base_path.join("possible_values")) { @@ -137,7 +137,7 @@ impl Attribute { AttrValue::EnumStr(val.split(';').map(|s| s.to_string()).collect()) } } - Err(_) => AttrValue::None, + Err(_) => AttrValue::None }; let min_value = read_i32(&base_path.join("min_value")) @@ -154,17 +154,13 @@ impl Attribute { .unwrap_or_default(); ( - default_value, - possible_values, - min_value, - max_value, - scalar_increment, + default_value, possible_values, min_value, max_value, scalar_increment ) } } pub struct FirmwareAttributes { - attrs: Vec, + attrs: Vec } #[allow(clippy::new_without_default)] @@ -191,7 +187,7 @@ impl FirmwareAttributes { min_value, max_value, scalar_increment, - base_path, + base_path }); } } @@ -226,28 +222,10 @@ macro_rules! define_attribute_getters { } define_attribute_getters!( - apu_mem, - cores_performance, - cores_efficiency, - ppt_pl1_spl, - ppt_pl2_sppt, - ppt_apu_sppt, - ppt_platform_sppt, - ppt_fppt, - nv_dynamic_boost, - nv_temp_target, - dgpu_base_tgp, - dgpu_tgp, - charge_mode, - boot_sound, - mcu_powersave, - panel_od, - panel_hd_mode, - egpu_connected, - egpu_enable, - dgpu_disable, - gpu_mux_mode, - mini_led_mode + apu_mem, cores_performance, cores_efficiency, ppt_pl1_spl, ppt_pl2_sppt, ppt_apu_sppt, + ppt_platform_sppt, ppt_fppt, nv_dynamic_boost, nv_temp_target, dgpu_base_tgp, dgpu_tgp, + charge_mode, boot_sound, mcu_powersave, panel_od, panel_hd_mode, egpu_connected, egpu_enable, + dgpu_disable, gpu_mux_mode, mini_led_mode ); /// CamelCase names of the properties. Intended for use with DBUS @@ -278,7 +256,7 @@ pub enum FirmwareAttribute { GpuMuxMode = 20, MiniLedMode = 21, PendingReboot = 22, - None = 23, + None = 23 } impl From<&str> for FirmwareAttribute { @@ -307,7 +285,7 @@ impl From<&str> for FirmwareAttribute { "gpu_mux_mode" => Self::GpuMuxMode, "mini_led_mode" => Self::MiniLedMode, "pending_reboot" => Self::PendingReboot, - _ => panic!("Invalid firmware attribute: {}", s), + _ => panic!("Invalid firmware attribute: {}", s) } } } @@ -338,7 +316,7 @@ impl From for &str { FirmwareAttribute::GpuMuxMode => "gpu_mux_mode", FirmwareAttribute::MiniLedMode => "mini_led_mode", FirmwareAttribute::PendingReboot => "pending_reboot", - FirmwareAttribute::None => "none", + FirmwareAttribute::None => "none" } } } diff --git a/rog-platform/src/hid_raw.rs b/rog-platform/src/hid_raw.rs index abb349c6..99e89dbd 100644 --- a/rog-platform/src/hid_raw.rs +++ b/rog-platform/src/hid_raw.rs @@ -19,7 +19,7 @@ pub struct HidRaw { prod_id: String, _device_bcd: u32, /// Retaining a handle to the file for the duration of `HidRaw` - file: RefCell, + file: RefCell } impl HidRaw { @@ -66,7 +66,7 @@ impl HidRaw { .unwrap_or_default() .to_string_lossy() .parse() - .unwrap_or_default(), + .unwrap_or_default() }); } } @@ -98,13 +98,13 @@ impl HidRaw { .unwrap_or_default() .to_string_lossy() .parse() - .unwrap_or_default(), + .unwrap_or_default() }); } } } Err(PlatformError::MissingFunction( - "hidraw dev no dev path".to_string(), + "hidraw dev no dev path".to_string() )) } diff --git a/rog-platform/src/keyboard_led.rs b/rog-platform/src/keyboard_led.rs index 183e1db6..e68ddb7b 100644 --- a/rog-platform/src/keyboard_led.rs +++ b/rog-platform/src/keyboard_led.rs @@ -10,7 +10,7 @@ use crate::{attr_u8, has_attr, set_attr_u8_array, to_device}; /// for Aura keyboards #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Clone)] pub struct KeyboardBacklight { - path: PathBuf, + path: PathBuf } impl KeyboardBacklight { @@ -51,12 +51,12 @@ impl KeyboardBacklight { if sys.contains("kbd_backlight") || sys.contains("ally:rgb:gamepad") { info!("Found keyboard LED controls at {:?}", device.sysname()); return Ok(Self { - path: device.syspath().to_owned(), + path: device.syspath().to_owned() }); } } Err(PlatformError::MissingFunction( - "KeyboardLed:new(), asus::kbd_backlight not found".into(), + "KeyboardLed:new(), asus::kbd_backlight not found".into() )) } } diff --git a/rog-platform/src/lib.rs b/rog-platform/src/lib.rs index 79345491..380573b6 100644 --- a/rog-platform/src/lib.rs +++ b/rog-platform/src/lib.rs @@ -111,7 +111,9 @@ pub fn write_attr_string(device: &mut Device, attr: &str, value: &str) -> Result mod tests { #[test] fn check() { - let data = [1, 2, 3, 4, 5]; + let data = [ + 1, 2, 3, 4, 5 + ]; let mut tmp = String::new(); for n in data { tmp.push_str(&n.to_string()); diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index 9f4a9503..8c4887bc 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -20,7 +20,7 @@ use crate::{attr_bool, attr_string, attr_u8, to_device}; #[derive(Debug, PartialEq, Eq, PartialOrd, Clone)] pub struct RogPlatform { path: PathBuf, - pp_path: PathBuf, + pp_path: PathBuf } impl RogPlatform { @@ -127,11 +127,11 @@ impl RogPlatform { info!("Found platform support at {:?}", device.sysname()); return Ok(Self { path: device.syspath().to_owned(), - pp_path: PathBuf::from_str("/sys/firmware/acpi").unwrap(), + pp_path: PathBuf::from_str("/sys/firmware/acpi").unwrap() }); } Err(PlatformError::MissingFunction( - "asus-nb-wmi not found".into(), + "asus-nb-wmi not found".into() )) } } @@ -141,7 +141,7 @@ impl Default for RogPlatform { unsafe { Self { path: PathBuf::from_str("/this_shouldNeVErr_exisid").unwrap_unchecked(), - pp_path: PathBuf::from_str("/this_shouldNeVErr_exisid").unwrap_unchecked(), + pp_path: PathBuf::from_str("/this_shouldNeVErr_exisid").unwrap_unchecked() } } } @@ -159,7 +159,7 @@ pub enum GpuMode { Ultimate = 4, #[default] Error = 254, - NotSupported = 255, + NotSupported = 255 } impl From for GpuMode { @@ -171,7 +171,7 @@ impl From for GpuMode { 3 => GpuMode::Vfio, 4 => GpuMode::Ultimate, 5 => GpuMode::Error, - _ => GpuMode::NotSupported, + _ => GpuMode::NotSupported } } } @@ -238,7 +238,7 @@ impl Display for GpuMode { GpuMode::Vfio => write!(f, "VFIO"), GpuMode::Ultimate => write!(f, "Ultimate"), GpuMode::Error => write!(f, "Error"), - GpuMode::NotSupported => write!(f, "Not Supported"), + GpuMode::NotSupported => write!(f, "Not Supported") } } } @@ -266,7 +266,7 @@ pub enum ThrottlePolicy { #[default] Balanced = 0, Performance = 1, - Quiet = 2, + Quiet = 2 } impl ThrottlePolicy { @@ -274,12 +274,16 @@ impl ThrottlePolicy { match self { Self::Balanced => Self::Performance, Self::Performance => Self::Quiet, - Self::Quiet => Self::Balanced, + Self::Quiet => Self::Balanced } } pub const fn list() -> [Self; 3] { - [Self::Balanced, Self::Performance, Self::Quiet] + [ + Self::Balanced, + Self::Performance, + Self::Quiet + ] } } @@ -308,7 +312,7 @@ impl From for u8 { match p { ThrottlePolicy::Balanced => 0, ThrottlePolicy::Performance => 1, - ThrottlePolicy::Quiet => 2, + ThrottlePolicy::Quiet => 2 } } } @@ -324,7 +328,7 @@ impl From for &str { match profile { ThrottlePolicy::Balanced => "balanced", ThrottlePolicy::Performance => "performance", - ThrottlePolicy::Quiet => "quiet", + ThrottlePolicy::Quiet => "quiet" } } } @@ -337,7 +341,7 @@ impl std::str::FromStr for ThrottlePolicy { "balanced" => Ok(ThrottlePolicy::Balanced), "performance" => Ok(ThrottlePolicy::Performance), "quiet" => Ok(ThrottlePolicy::Quiet), - _ => Err(PlatformError::NotSupported), + _ => Err(PlatformError::NotSupported) } } } @@ -367,5 +371,5 @@ pub enum Properties { PptApuSppt, PptPlatformSppt, NvDynamicBoost, - NvTempTarget, + NvTempTarget } diff --git a/rog-platform/src/power.rs b/rog-platform/src/power.rs index f4f02d0a..01e63786 100644 --- a/rog-platform/src/power.rs +++ b/rog-platform/src/power.rs @@ -16,7 +16,7 @@ use crate::{attr_u8, to_device}; pub struct AsusPower { mains: PathBuf, battery: PathBuf, - usb: Option, + usb: Option } impl AsusPower { @@ -97,12 +97,12 @@ impl AsusPower { return Ok(Self { mains, battery, - usb, + usb }); } Err(PlatformError::MissingFunction( - "Did not find a battery".to_owned(), + "Did not find a battery".to_owned() )) } } diff --git a/rog-platform/src/usb_raw.rs b/rog-platform/src/usb_raw.rs index 33e2ae29..01bd95da 100644 --- a/rog-platform/src/usb_raw.rs +++ b/rog-platform/src/usb_raw.rs @@ -24,7 +24,7 @@ impl USBRaw { } fn get_dev_handle( - device: &Device, + device: &Device ) -> Result> { // We don't expect this ID to ever change let device = device.open()?; @@ -42,7 +42,7 @@ impl USBRaw { 0x35e, // value 0x00, // index message, - Duration::from_millis(200), + Duration::from_millis(200) ) .map_err(PlatformError::USB) } diff --git a/rog-profiles/src/error.rs b/rog-profiles/src/error.rs index d2fe8451..50ba1939 100644 --- a/rog-profiles/src/error.rs +++ b/rog-profiles/src/error.rs @@ -16,8 +16,7 @@ pub enum ProfileError { /// (pwm/temp, prev, next) ParseFanCurvePrevHigher(&'static str, u8, u8), ParseFanCurvePercentOver100(u8), - NotEnoughPoints, - // Zbus(zbus::Error), + NotEnoughPoints // Zbus(zbus::Error), } impl fmt::Display for ProfileError { @@ -61,7 +60,7 @@ impl From for FdoErr { error!("ProfileError: got: {error}"); match error { ProfileError::NotSupported => FdoErr::NotSupported("".to_owned()), - _ => FdoErr::Failed(format!("Failed with {error}")), + _ => FdoErr::Failed(format!("Failed with {error}")) } } } diff --git a/rog-profiles/src/fan_curve_set.rs b/rog-profiles/src/fan_curve_set.rs index 7de8adc1..90f1222d 100644 --- a/rog-profiles/src/fan_curve_set.rs +++ b/rog-profiles/src/fan_curve_set.rs @@ -36,7 +36,7 @@ pub struct CurveData { pub fan: FanCurvePU, pub pwm: [u8; 8], pub temp: [u8; 8], - pub enabled: bool, + pub enabled: bool } impl From<&CurveData> for String { @@ -99,9 +99,7 @@ impl std::str::FromStr for CurveData { if select == 0 { if temp_prev > r { return Err(ProfileError::ParseFanCurvePrevHigher( - "temperature", - temp_prev, - r, + "temperature", temp_prev, r )); } temp_prev = r; @@ -116,9 +114,7 @@ impl std::str::FromStr for CurveData { } if pwm_prev > p { return Err(ProfileError::ParseFanCurvePrevHigher( - "percentage", - pwm_prev, - p, + "percentage", pwm_prev, p )); } pwm_prev = p; @@ -130,7 +126,7 @@ impl std::str::FromStr for CurveData { fan: FanCurvePU::CPU, pwm, temp, - enabled: false, + enabled: false }) } } diff --git a/rog-profiles/src/lib.rs b/rog-profiles/src/lib.rs index f85f5590..77d3defd 100644 --- a/rog-profiles/src/lib.rs +++ b/rog-profiles/src/lib.rs @@ -41,13 +41,17 @@ pub fn find_fan_curve_node() -> Result { pub enum FanCurvePU { CPU = 0, GPU = 1, - MID = 2, + MID = 2 } impl FanCurvePU { fn which_fans(device: &Device) -> Vec { let mut fans = Vec::with_capacity(3); - for fan in [Self::CPU, Self::GPU, Self::MID] { + for fan in [ + Self::CPU, + Self::GPU, + Self::MID + ] { let pwm_num: char = fan.into(); let pwm_enable = format!("pwm{pwm_num}_enable"); debug!("Looking for {pwm_enable}"); @@ -68,7 +72,7 @@ impl From for &str { match pu { FanCurvePU::CPU => "cpu", FanCurvePU::GPU => "gpu", - FanCurvePU::MID => "mid", + FanCurvePU::MID => "mid" } } } @@ -78,7 +82,7 @@ impl From for char { match pu { FanCurvePU::CPU => '1', FanCurvePU::GPU => '2', - FanCurvePU::MID => '3', + FanCurvePU::MID => '3' } } } @@ -91,7 +95,7 @@ impl std::str::FromStr for FanCurvePU { "cpu" => Ok(FanCurvePU::CPU), "gpu" => Ok(FanCurvePU::GPU), "mid" => Ok(FanCurvePU::MID), - _ => Err(ProfileError::ParseProfileName), + _ => Err(ProfileError::ParseProfileName) } } } @@ -108,7 +112,7 @@ impl Default for FanCurvePU { pub struct FanCurveProfiles { pub balanced: Vec, pub performance: Vec, - pub quiet: Vec, + pub quiet: Vec } impl FanCurveProfiles { @@ -122,7 +126,7 @@ impl FanCurveProfiles { pub fn read_from_dev_profile( &mut self, profile: ThrottlePolicy, - device: &Device, + device: &Device ) -> Result<(), ProfileError> { let fans = Self::supported_fans()?; let mut curves = Vec::with_capacity(3); @@ -141,7 +145,7 @@ impl FanCurveProfiles { match profile { ThrottlePolicy::Balanced => self.balanced = curves, ThrottlePolicy::Performance => self.performance = curves, - ThrottlePolicy::Quiet => self.quiet = curves, + ThrottlePolicy::Quiet => self.quiet = curves } Ok(()) } @@ -154,7 +158,7 @@ impl FanCurveProfiles { pub fn set_active_curve_to_defaults( &mut self, profile: ThrottlePolicy, - device: &mut Device, + device: &mut Device ) -> Result<(), ProfileError> { let fans = Self::supported_fans()?; // Do reset for all @@ -172,12 +176,12 @@ impl FanCurveProfiles { pub fn write_profile_curve_to_platform( &mut self, profile: ThrottlePolicy, - device: &mut Device, + device: &mut Device ) -> Result<(), ProfileError> { let fans = match profile { ThrottlePolicy::Balanced => &mut self.balanced, ThrottlePolicy::Performance => &mut self.performance, - ThrottlePolicy::Quiet => &mut self.quiet, + ThrottlePolicy::Quiet => &mut self.quiet }; for fan in fans.iter().filter(|f| !f.enabled) { debug!("write_profile_curve_to_platform: writing profile:{profile}, {fan:?}"); @@ -216,7 +220,7 @@ impl FanCurveProfiles { &mut self, profile: ThrottlePolicy, fan: FanCurvePU, - enabled: bool, + enabled: bool ) { match profile { ThrottlePolicy::Balanced => { @@ -250,7 +254,7 @@ impl FanCurveProfiles { match name { ThrottlePolicy::Balanced => &self.balanced, ThrottlePolicy::Performance => &self.performance, - ThrottlePolicy::Quiet => &self.quiet, + ThrottlePolicy::Quiet => &self.quiet } } @@ -284,7 +288,7 @@ impl FanCurveProfiles { pub fn save_fan_curve( &mut self, curve: CurveData, - profile: ThrottlePolicy, + profile: ThrottlePolicy ) -> Result<(), ProfileError> { match profile { ThrottlePolicy::Balanced => { diff --git a/rog-scsi/src/builtin_modes.rs b/rog-scsi/src/builtin_modes.rs index d0f9645e..5d92f522 100644 --- a/rog-scsi/src/builtin_modes.rs +++ b/rog-scsi/src/builtin_modes.rs @@ -13,7 +13,7 @@ use crate::scsi::{apply_task, dir_task, mode_task, rgb_task, save_task, speed_ta pub struct Colour { pub r: u8, pub g: u8, - pub b: u8, + pub b: u8 } impl Default for Colour { @@ -41,14 +41,16 @@ impl From<&[u8; 3]> for Colour { Self { r: c[0], g: c[1], - b: c[2], + b: c[2] } } } impl From for [u8; 3] { fn from(c: Colour) -> Self { - [c.r, c.b, c.g] + [ + c.r, c.b, c.g + ] } } @@ -61,7 +63,7 @@ impl From for [u8; 3] { pub enum Direction { #[default] Forward = 0, - Reverse = 1, + Reverse = 1 } impl FromStr for Direction { @@ -72,7 +74,7 @@ impl FromStr for Direction { match s.as_str() { "forward" => Ok(Direction::Forward), "reverse" => Ok(Direction::Reverse), - _ => Err(Error::ParseSpeed), + _ => Err(Error::ParseSpeed) } } } @@ -81,7 +83,7 @@ impl From for Direction { fn from(dir: u8) -> Self { match dir { 1 => Direction::Reverse, - _ => Direction::Forward, + _ => Direction::Forward } } } @@ -104,7 +106,7 @@ pub enum Speed { #[default] Med = 2, Fast = 1, - Fastest = 0, + Fastest = 0 } impl FromStr for Speed { @@ -118,7 +120,7 @@ impl FromStr for Speed { "med" => Ok(Speed::Med), "fast" => Ok(Speed::Fast), "fastest" => Ok(Speed::Fastest), - _ => Err(Error::ParseSpeed), + _ => Err(Error::ParseSpeed) } } } @@ -130,7 +132,7 @@ impl From for u8 { Speed::Slow => 3, Speed::Med => 2, Speed::Fast => 1, - Speed::Fastest => 0, + Speed::Fastest => 0 } } } @@ -142,7 +144,7 @@ impl From for Speed { 3 => Self::Slow, 1 => Self::Fast, 0 => Self::Fastest, - _ => Self::Med, + _ => Self::Med } } } @@ -172,7 +174,7 @@ pub enum AuraMode { RainbowCycleWave = 11, RainbowPulseChase = 12, RandomFlicker = 13, - DoubleFade = 14, + DoubleFade = 14 } impl AuraMode { @@ -192,7 +194,7 @@ impl AuraMode { AuraMode::RainbowCycleWave.to_string(), AuraMode::RainbowPulseChase.to_string(), AuraMode::RandomFlicker.to_string(), - AuraMode::DoubleFade.to_string(), + AuraMode::DoubleFade.to_string() ] } } @@ -226,7 +228,7 @@ impl From<&AuraMode> for &str { AuraMode::RainbowCycleWave => "RainbowCycleWave", AuraMode::RainbowPulseChase => "RainbowPulseChase", AuraMode::RandomFlicker => "RandomFlicker", - AuraMode::DoubleFade => "DoubleFade", + AuraMode::DoubleFade => "DoubleFade" } } } @@ -251,7 +253,7 @@ impl FromStr for AuraMode { "RainbowPulseChase" => Ok(Self::RainbowPulseChase), "RandomFlicker" => Ok(Self::RandomFlicker), "DoubleFade" => Ok(Self::DoubleFade), - _ => Err(Error::ParseMode), + _ => Err(Error::ParseMode) } } } @@ -280,7 +282,7 @@ impl From for AuraMode { 12 => Self::RainbowPulseChase, 13 => Self::RandomFlicker, 14 => Self::DoubleFade, - _ => Self::Static, + _ => Self::Static } } } @@ -306,7 +308,7 @@ pub struct AuraEffect { /// Secondary colour in some modes like Breathing or Stars pub colour2: Colour, pub colour3: Colour, - pub colour4: Colour, + pub colour4: Colour } impl AuraEffect { @@ -339,7 +341,7 @@ impl Default for AuraEffect { colour3: Colour { r: 166, g: 0, b: 0 }, colour4: Colour { r: 0, g: 0, b: 0 }, speed: Speed::Med, - direction: Direction::Forward, + direction: Direction::Forward } } } @@ -386,7 +388,10 @@ impl From<&AuraEffect> for Vec { tasks.push(dir_task(effect.direction as u8)); } - tasks.append(&mut vec![apply_task(), save_task()]); + tasks.append(&mut vec![ + apply_task(), + save_task(), + ]); tasks } } diff --git a/rog-scsi/src/error.rs b/rog-scsi/src/error.rs index c80cc889..9a494236 100644 --- a/rog-scsi/src/error.rs +++ b/rog-scsi/src/error.rs @@ -8,7 +8,7 @@ pub enum Error { ParseDirection, IoPath(String, std::io::Error), Ron(ron::Error), - RonParse(ron::error::SpannedError), + RonParse(ron::error::SpannedError) } impl fmt::Display for Error { @@ -21,7 +21,7 @@ impl fmt::Display for Error { Error::ParseMode => write!(f, "Could not parse mode"), Error::IoPath(path, io) => write!(f, "IO Error: {path}, {io}"), Error::Ron(e) => write!(f, "RON Parse Error: {e}"), - Error::RonParse(e) => write!(f, "RON Parse Error: {e}"), + Error::RonParse(e) => write!(f, "RON Parse Error: {e}") } } } diff --git a/rog-scsi/src/lib.rs b/rog-scsi/src/lib.rs index 85765a33..ccdd5ebc 100644 --- a/rog-scsi/src/lib.rs +++ b/rog-scsi/src/lib.rs @@ -13,14 +13,14 @@ pub const PROD_SCSI_ARION: &str = "1932"; pub enum ScsiType { Arion, #[default] - Unsupported, + Unsupported } impl ScsiType { pub const fn prod_id_str(&self) -> &str { match self { ScsiType::Arion => PROD_SCSI_ARION, - ScsiType::Unsupported => "", + ScsiType::Unsupported => "" } } } @@ -29,7 +29,7 @@ impl From<&str> for ScsiType { fn from(s: &str) -> Self { match s.to_lowercase().as_str() { PROD_SCSI_ARION | "0x1932" => Self::Arion, - _ => Self::Unsupported, + _ => Self::Unsupported } } } @@ -38,7 +38,7 @@ impl From for &str { fn from(s: ScsiType) -> Self { match s { ScsiType::Arion => PROD_SCSI_ARION, - ScsiType::Unsupported => "Unsupported", + ScsiType::Unsupported => "Unsupported" } } } diff --git a/rog-slash/src/data.rs b/rog-slash/src/data.rs index 317f5c73..c65a8d37 100644 --- a/rog-slash/src/data.rs +++ b/rog-slash/src/data.rs @@ -16,7 +16,7 @@ pub enum SlashType { GA605, GU605, #[default] - Unsupported, + Unsupported } impl SlashType { @@ -25,7 +25,7 @@ impl SlashType { SlashType::GA403 => PROD_ID1, SlashType::GA605 => PROD_ID2, SlashType::GU605 => PROD_ID1, - SlashType::Unsupported => 0, + SlashType::Unsupported => 0 } } @@ -34,7 +34,7 @@ impl SlashType { SlashType::GA403 => PROD_ID1_STR, SlashType::GA605 => PROD_ID2_STR, SlashType::GU605 => PROD_ID1_STR, - SlashType::Unsupported => "", + SlashType::Unsupported => "" } } @@ -60,7 +60,7 @@ impl FromStr for SlashType { "ga403" | "GA403" => Self::GA403, "ga605" | "GA605" => Self::GA605, "gu605" | "GU605" => Self::GU605, - _ => Self::Unsupported, + _ => Self::Unsupported }) } } @@ -83,7 +83,7 @@ pub enum SlashMode { Ramp = 0x34, GameOver = 0x42, Start = 0x43, - Buzzer = 0x44, + Buzzer = 0x44 } impl FromStr for SlashMode { @@ -106,7 +106,7 @@ impl FromStr for SlashMode { "GameOver" => Ok(SlashMode::GameOver), "Start" => Ok(SlashMode::Start), "Buzzer" => Ok(SlashMode::Buzzer), - _ => Ok(SlashMode::Bounce), + _ => Ok(SlashMode::Bounce) } } } @@ -128,7 +128,7 @@ impl Display for SlashMode { SlashMode::Ramp => String::from("Ramp"), SlashMode::GameOver => String::from("GameOver"), SlashMode::Start => String::from("Start"), - SlashMode::Buzzer => String::from("Buzzer"), + SlashMode::Buzzer => String::from("Buzzer") }; write!(f, "{}", str) } @@ -151,7 +151,7 @@ impl SlashMode { SlashMode::Ramp.to_string(), SlashMode::GameOver.to_string(), SlashMode::Start.to_string(), - SlashMode::Buzzer.to_string(), + SlashMode::Buzzer.to_string() ] } } @@ -162,5 +162,5 @@ pub struct DeviceState { pub slash_enabled: bool, pub slash_brightness: u8, pub slash_interval: u8, - pub slash_mode: SlashMode, + pub slash_mode: SlashMode } diff --git a/rog-slash/src/error.rs b/rog-slash/src/error.rs index af2e0fb6..2be40e6c 100644 --- a/rog-slash/src/error.rs +++ b/rog-slash/src/error.rs @@ -9,7 +9,7 @@ pub enum SlashError { NoDevice, UnsupportedDevice, DataBufferLength, - ParseError(String), + ParseError(String) } impl fmt::Display for SlashError { @@ -24,7 +24,7 @@ impl fmt::Display for SlashError { f, "The data buffer was incorrect length for generating USB packets" ), - SlashError::UnsupportedDevice => write!(f, "Unsupported Slash device found"), + SlashError::UnsupportedDevice => write!(f, "Unsupported Slash device found") } } } diff --git a/rog-slash/src/usb.rs b/rog-slash/src/usb.rs index 5d15bed5..71f11b1b 100644 --- a/rog-slash/src/usb.rs +++ b/rog-slash/src/usb.rs @@ -55,7 +55,7 @@ pub const fn report_id(slash_type: SlashType) -> u8 { SlashType::GA403 => REPORT_ID_193B, SlashType::GA605 => REPORT_ID_19B6, SlashType::GU605 => REPORT_ID_193B, - SlashType::Unsupported => REPORT_ID_19B6, + SlashType::Unsupported => REPORT_ID_19B6 } } @@ -81,7 +81,9 @@ pub fn pkts_for_init(slash_type: SlashType) -> [SlashUsbPacket; 2] { pkt2[4] = 0x08; pkt2[5] = 0xab; - [pkt1, pkt2] + [ + pkt1, pkt2 + ] } #[inline] @@ -126,40 +128,68 @@ pub const fn pkt_set_mode(slash_type: SlashType, mode: SlashMode) -> [SlashUsbPa pkt2[15] = 0x06; pkt2[16] = 0x13; - [pkt1, pkt2] + [ + pkt1, pkt2 + ] } -/// DEVICE SETTINGS -/// Interval: -/// - 1 = 0x5d, 0xd3, 0x3, 0x1, 0x8, 0xab, 0xff, 0x1, 0x1, 0x6, 0x19, 0xff, 0x1 -/// - 5 = 0x5d, 0xd3, 0x3, 0x1, 0x8, 0xab, 0xff, 0x1, 0x1, 0x6, 0x19, 0xff, 0x5 -/// Brightness: 100 -/// - 100 = 0x5d, 0xd3, 0x3, 0x1, 0x8, 0xab, 0xff, 0x1, 0x1, 0x6, 0xff, 0xff -/// - 000 = 0x5d, 0xd3, 0x3, 0x1, 0x8, 0xab, 0xff, 0x1, 0x1, 0x6, 0x00, 0xff -/// - off = 0x5d, 0xd3, 0x3, 0x1, 0x8, 0xab, 0xff, 0x1, 0x0, 0x6, 0xff, 0xff -#[inline] -pub const fn pkt_set_options( +pub const fn get_options_packet( slash_type: SlashType, enabled: bool, brightness: u8, - interval: u8, -) -> SlashUsbPacket { - let status_byte = if enabled { 0x01 } else { 0x00 }; - - let mut pkt = [0; PACKET_SIZE]; - pkt[0] = report_id(slash_type); - pkt[1] = 0xd3; - pkt[2] = 0x03; - pkt[3] = 0x01; - pkt[4] = 0x08; - pkt[5] = 0xab; // Setting byte 1 - pkt[6] = 0xff; // Setting byte 2 - pkt[7] = 0x01; - pkt[8] = status_byte; // Setting enable/disable - pkt[9] = 0x06; - pkt[10] = brightness; - pkt[11] = 0xff; - pkt[12] = interval; - - pkt + interval: u8 +) -> [u8; 13] { + let typ = report_id(slash_type); + let status = enabled as u8; + [ + typ, 0xd3, 0x03, 0x01, 0x08, 0xab, 0xff, 0x01, status, 0x06, brightness, 0xff, interval + ] +} + +pub const fn get_boot_packet(slash_type: SlashType, enabled: bool) -> [u8; 12] { + let typ = report_id(slash_type); + let status = enabled as u8; + [ + typ, 0xd3, 0x03, 0x01, 0x08, 0xa0, 0x04, 0xff, status, 0x01, 0xff, 0x00 + ] +} + +pub const fn get_sleep_packet(slash_type: SlashType, enabled: bool) -> [u8; 12] { + let typ = report_id(slash_type); + let status = (!enabled) as u8; + [ + typ, 0xd3, 0x03, 0x01, 0x08, 0xa1, 0x00, 0xff, status, 0x02, 0xff, 0xff + ] +} + +pub const fn get_low_battery_packet(slash_type: SlashType, enabled: bool) -> [u8; 12] { + let typ = report_id(slash_type); + let status = enabled as u8; + [ + typ, 0xd3, 0x03, 0x01, 0x08, 0xa2, 0x01, 0xff, status, 0x02, 0xff, 0xff + ] +} + +pub const fn get_shutdown_packet(slash_type: SlashType, enabled: bool) -> [u8; 12] { + let typ = report_id(slash_type); + let status = enabled as u8; + [ + typ, 0xd3, 0x03, 0x01, 0x08, 0xa4, 0x05, 0xff, status, 0x01, 0xff, 0x00 + ] +} + +pub const fn get_battery_saver_packet(slash_type: SlashType, enabled: bool) -> [u8; 6] { + let typ = report_id(slash_type); + let status = if enabled { 0x00 } else { 0x80 }; + [ + typ, 0xd8, 0x01, 0x00, 0x01, status + ] +} + +pub const fn get_lid_closed_packet(slash_type: SlashType, enabled: bool) -> [u8; 7] { + let typ = report_id(slash_type); + let status = if enabled { 0x00 } else { 0x80 }; + [ + typ, 0xd8, 0x00, 0x00, 0x02, 0xa5, status + ] } diff --git a/rustfmt.toml b/rustfmt.toml index b22a925c..f1967f7c 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -13,3 +13,7 @@ reorder_modules = true unstable_features = true use_field_init_shorthand = true wrap_comments = true +array_width = 8 +trailing_comma = "Never" +overflow_delimited_expr = true +short_array_element_width_threshold = 20 diff --git a/simulators/src/animatrix/map_ga401.rs b/simulators/src/animatrix/map_ga401.rs index dcbe47ba..944ee97f 100644 --- a/simulators/src/animatrix/map_ga401.rs +++ b/simulators/src/animatrix/map_ga401.rs @@ -65,5 +65,5 @@ pub const GA401: [Row; 63] = [ Row(0xe7, 7 + 155, 11, 23), Row(0xe7, 7 + 166, 10, 24), Row(0xe7, 7 + 176, 10, 24), - Row(0xe7, 7 + 186, 9, 25), + Row(0xe7, 7 + 186, 9, 25) ]; diff --git a/simulators/src/animatrix/map_ga402.rs b/simulators/src/animatrix/map_ga402.rs index f7acc321..1f8c1016 100644 --- a/simulators/src/animatrix/map_ga402.rs +++ b/simulators/src/animatrix/map_ga402.rs @@ -66,5 +66,5 @@ pub const GA402: [Row; 63] = [ Row(0xe7, 7 + 155, 11, 23), Row(0xe7, 7 + 166, 10, 24), Row(0xe7, 7 + 176, 10, 24), - Row(0xe7, 7 + 186, 9, 25), + Row(0xe7, 7 + 186, 9, 25) ]; diff --git a/simulators/src/animatrix/map_gu604.rs b/simulators/src/animatrix/map_gu604.rs index e96b349d..91f04a0f 100644 --- a/simulators/src/animatrix/map_gu604.rs +++ b/simulators/src/animatrix/map_gu604.rs @@ -66,5 +66,5 @@ pub const GU604: [Row; 64] = [ Row(0xe7, 7 + 403, 14, 25), Row(0xe7, 7 + 417, 14, 25), Row(0xe7, 7 + 431, 13, 26), - Row(0xe7, 7 + 444, 13, 26), + Row(0xe7, 7 + 444, 13, 26) ]; diff --git a/simulators/src/animatrix/mod.rs b/simulators/src/animatrix/mod.rs index 22be55d9..ab52bc67 100644 --- a/simulators/src/animatrix/mod.rs +++ b/simulators/src/animatrix/mod.rs @@ -20,7 +20,7 @@ pub struct Row( /// The length to read inclusive pub usize, /// Offset to the right by how many LEDs - pub i32, + pub i32 ); #[derive(Clone, Copy)] @@ -28,12 +28,12 @@ pub struct LedShape { /// Vertical offset from center for the top/bottom points pub vertical: i32, /// Horizontal offset from center for the top/bottom points - pub horizontal: i32, + pub horizontal: i32 } pub struct AniMatrix { rows: Vec, - led_shape: LedShape, + led_shape: LedShape } impl AniMatrix { @@ -41,23 +41,23 @@ impl AniMatrix { let led_shape = match model { AnimeType::GA401 => LedShape { vertical: 2, - horizontal: 5, + horizontal: 5 }, AnimeType::GA402 | AnimeType::Unsupported => LedShape { vertical: 2, - horizontal: 5, + horizontal: 5 }, AnimeType::GU604 => LedShape { vertical: 2, - horizontal: 5, - }, + horizontal: 5 + } }; // Do a hard mapping of each (derived from wireshardk captures) let rows = match model { AnimeType::GA401 => GA401.to_vec(), AnimeType::GA402 | AnimeType::Unsupported => GA402.to_vec(), - AnimeType::GU604 => GU604.to_vec(), + AnimeType::GU604 => GU604.to_vec() }; Self { rows, led_shape } diff --git a/simulators/src/simulator.rs b/simulators/src/simulator.rs index c719ffd9..73bd166e 100644 --- a/simulators/src/simulator.rs +++ b/simulators/src/simulator.rs @@ -17,7 +17,7 @@ use animatrix::*; pub struct VirtAnimeMatrix { device: UHIDDevice, buffer: [u8; 640], - animatrix: AniMatrix, + animatrix: AniMatrix } impl VirtAnimeMatrix { @@ -84,10 +84,10 @@ impl VirtAnimeMatrix { /* 85 bytes */ ] - .to_vec(), + .to_vec() }) .map_err(|err| error!("Could not create virtual device: {:?}", err)) - .expect("Could not create virtual device"), + .expect("Could not create virtual device") } }