From 7b17a13ce7c461880df6da99f7048318c5f655b9 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Tue, 27 Jun 2023 21:16:13 +1200 Subject: [PATCH] ridiculous refactor to allow enums to be dbus strings for better TS generation --- .gitignore | 2 +- CHANGELOG.md | 1 + Cargo.lock | 223 +++++++++++------- Cargo.toml | 1 + Makefile | 16 +- asusctl/examples/aura-zoned-breathe.rs | 6 +- asusd-user/src/config.rs | 25 +- asusd-user/src/ctrl_anime.rs | 14 +- asusd/src/ctrl_aura/config.rs | 60 ++++- asusd/src/ctrl_aura/controller.rs | 14 +- asusd/src/ctrl_aura/trait_impls.rs | 58 +++-- bindings/dbus-xml/org-asuslinux-anime-4.xml | 105 +++++++++ bindings/dbus-xml/org-asuslinux-aura-4.xml | 146 ++++++++++++ .../dbus-xml/org-asuslinux-platform-4.xml | 107 +++++++++ bindings/dbus-xml/org-asuslinux-power-4.xml | 60 +++++ bindings/dbus-xml/org-asuslinux-profile-4.xml | 120 ++++++++++ .../dbus-xml/org-asuslinux-supported-4.xml | 48 ++++ bindings/ts/anime.ts | 53 +++++ bindings/ts/aura.ts | 219 +++++++++++++++++ bindings/ts/platform.ts | 57 +++++ bindings/ts/profiles.ts | 35 +++ rog-anime/Cargo.toml | 1 + rog-anime/src/data.rs | 10 +- rog-anime/src/lib.rs | 24 ++ rog-anime/src/usb.rs | 16 +- rog-aura/Cargo.toml | 1 + rog-aura/src/advanced.rs | 3 + rog-aura/src/builtin_modes.rs | 130 ++++++---- rog-aura/src/effects/breathe.rs | 27 ++- rog-aura/src/effects/doom.rs | 46 ++-- rog-aura/src/effects/mod.rs | 30 ++- rog-aura/src/layouts.rs | 1 + rog-aura/src/lib.rs | 42 +++- rog-aura/src/usb.rs | 22 +- rog-control-center/Cargo.toml | 2 +- rog-control-center/src/mocking.rs | 13 +- rog-control-center/src/pages/aura_page.rs | 22 +- rog-platform/Cargo.toml | 1 + rog-platform/src/platform.rs | 2 + rog-platform/src/supported.rs | 8 + rog-profiles/Cargo.toml | 1 + rog-profiles/src/fan_curve_set.rs | 3 + rog-profiles/src/lib.rs | 8 +- 43 files changed, 1516 insertions(+), 267 deletions(-) create mode 100644 bindings/dbus-xml/org-asuslinux-anime-4.xml create mode 100644 bindings/dbus-xml/org-asuslinux-aura-4.xml create mode 100644 bindings/dbus-xml/org-asuslinux-platform-4.xml create mode 100644 bindings/dbus-xml/org-asuslinux-power-4.xml create mode 100644 bindings/dbus-xml/org-asuslinux-profile-4.xml create mode 100644 bindings/dbus-xml/org-asuslinux-supported-4.xml create mode 100644 bindings/ts/anime.ts create mode 100644 bindings/ts/aura.ts create mode 100644 bindings/ts/platform.ts create mode 100644 bindings/ts/profiles.ts diff --git a/.gitignore b/.gitignore index 39daca04..a4b21632 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ vendor_* .vscode-ctags .vscode .~lock.* -*.ods# \ No newline at end of file +*.ods# diff --git a/CHANGELOG.md b/CHANGELOG.md index d02f131c..85aeba8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update GL503 led config ### BREAKING - All Anime related DBUS methods/notifs are changed +- All dbus interfaces that handled an enum have now been forced to use the enum as String type, not uint or similar, this unfortunately breaks a heap of stuff but has the benefit of allowing asusctl to use crates to generate a typescript (or other) binding to the types being used by zbus for the proxies. The implication here is that there will be an eventual tighter integration with the gnome extension and maybe KDE also. ## [v4.6.2] - Fix rog-control-center not reopening if `startup_in_background` is set diff --git a/Cargo.lock b/Cargo.lock index 4968446c..656c096e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,6 +137,21 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.71" @@ -169,9 +184,9 @@ checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] name = "arrayvec" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8868f09ff8cea88b079da74ae569d9b8c62a23c68c746240b704ee6f7525c89c" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "asusctl" @@ -350,7 +365,7 @@ checksum = "0e97ce7de6cf12de5d7226c73f5ba9811622f4db3a5b91b55c53e987e5f91cba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -367,7 +382,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -549,7 +564,7 @@ checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -641,9 +656,9 @@ dependencies = [ [[package]] name = "cfg-expr" -version = "0.15.2" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e70d3ad08698a0568b0562f22710fe6bfc1f4a61a367c77d0398c562eadd453a" +checksum = "215c0072ecc28f92eeb0eea38ba63ddfcb65c2828c46311d646f1a3ff5f9841c" dependencies = [ "smallvec", "target-lexicon", @@ -670,6 +685,20 @@ dependencies = [ "libc", ] +[[package]] +name = "chrono" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "winapi", +] + [[package]] name = "clang-sys" version = "1.6.1" @@ -709,12 +738,12 @@ dependencies = [ [[package]] name = "concat-idents" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fe0e1d9f7de897d18e590a7496b5facbe87813f746cf4b8db596ba77e07e832" +checksum = "f76990911f2267d837d9d0ad060aa63aaad170af40904b29461734c339030d4d" dependencies = [ "quote", - "syn 1.0.109", + "syn 2.0.22", ] [[package]] @@ -770,21 +799,20 @@ dependencies = [ [[package]] name = "core-graphics-types" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" +checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" dependencies = [ "bitflags", "core-foundation", - "foreign-types", "libc", ] [[package]] name = "cpufeatures" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" +checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" dependencies = [ "libc", ] @@ -1027,7 +1055,7 @@ checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -1222,7 +1250,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -1436,7 +1464,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb1a9325847aa46f1e96ffea37611b9d51fc4827e67f79e7de502a297560a67b" dependencies = [ "anyhow", - "heck 0.4.1", + "heck", "proc-macro-crate", "proc-macro-error", "proc-macro2", @@ -1474,9 +1502,9 @@ dependencies = [ [[package]] name = "glutin" -version = "0.30.8" +version = "0.30.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f9b771a65f0a1e3ddb6aa16f867d87dc73c922411c255e6c4ab7f6d45c7327" +checksum = "23b0385782048be65f0a9dd046c469d6a758a53fe1aa63a8111dea394d2ffa2f" dependencies = [ "bitflags", "cfg_aliases", @@ -1628,15 +1656,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.4.1" @@ -1679,6 +1698,29 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows 0.48.0", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.4.0" @@ -1855,9 +1897,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.146" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libloading" @@ -2449,9 +2491,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.60" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406" +checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" dependencies = [ "unicode-ident", ] @@ -2602,6 +2644,7 @@ dependencies = [ "serde", "serde_derive", "sysfs-class", + "typeshare", "zbus", ] @@ -2615,6 +2658,7 @@ dependencies = [ "serde", "serde_derive", "sysfs-class", + "typeshare", "zbus", ] @@ -2643,6 +2687,7 @@ dependencies = [ "serde", "serde_derive", "sysfs-class", + "typeshare", "udev 0.7.0", "zbus", ] @@ -2654,6 +2699,7 @@ dependencies = [ "cargo-husky", "serde", "serde_derive", + "typeshare", "udev 0.7.0", "zbus", ] @@ -2806,14 +2852,14 @@ checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] name = "serde_json" -version = "1.0.96" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" dependencies = [ "itoa", "ryu", @@ -2828,14 +2874,14 @@ checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] name = "serde_spanned" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93107647184f6027e3b7dcb2e11034cf95ffa1e3a682c67951963ac69c1c007d" +checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" dependencies = [ "serde", ] @@ -2980,31 +3026,10 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" -[[package]] -name = "strum" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7ac893c7d471c8a21f31cfe213ec4f6d9afeed25537c772e08ef3f005f8729e" -dependencies = [ - "strum_macros", -] - -[[package]] -name = "strum_macros" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "339f799d8b549e3744c7ac7feb216383e4005d94bdb22561b3ab8f3b808ae9fb" -dependencies = [ - "heck 0.3.3", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "supergfxctl" version = "5.1.1" -source = "git+https://gitlab.com/asus-linux/supergfxctl.git#d94887aff842336db50bf78ba8ef53440a7b19a8" +source = "git+https://gitlab.com/asus-linux/supergfxctl.git#fcba63b1a29284fc76da65e60751a33b81380259" dependencies = [ "log", "logind-zbus", @@ -3014,8 +3039,6 @@ dependencies = [ "tokio", "udev 0.6.3", "zbus", - "zvariant", - "zvariant_derive", ] [[package]] @@ -3031,9 +3054,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.18" +version = "2.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" dependencies = [ "proc-macro2", "quote", @@ -3051,12 +3074,12 @@ dependencies = [ [[package]] name = "system-deps" -version = "6.1.0" +version = "6.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5fa6fb9ee296c0dc2df41a656ca7948546d061958115ddb0bcaae43ad0d17d2" +checksum = "30c2de8a4d8f4b823d634affc9cd2a74ec98c53a756f317e529a48046cbf71f3" dependencies = [ "cfg-expr", - "heck 0.4.1", + "heck", "pkg-config", "toml 0.7.3", "version-compare", @@ -3074,18 +3097,17 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.7" +version = "0.12.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5" +checksum = "1b1c7f239eb94671427157bd93b3694320f3668d4e1eff08c7285366fd777fac" [[package]] name = "tauri-winrt-notification" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58de036c4d2e20717024de2a3c4bf56c301f07b21bc8ef9b57189fce06f1f3b" +checksum = "37d70573554e7630c2ca3677ea78d5ae6b030aedee5f9bf33c15d644904fa698" dependencies = [ "quick-xml", - "strum", "windows 0.39.0", ] @@ -3129,7 +3151,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -3221,7 +3243,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -3247,9 +3269,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a76a9312f5ba4c2dec6b9161fdf25d87ad8a09256ccea5a556fef03c706a10f" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" dependencies = [ "serde", ] @@ -3281,13 +3303,13 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.18", + "syn 2.0.22", ] [[package]] @@ -3301,9 +3323,9 @@ dependencies = [ [[package]] name = "ttf-parser" -version = "0.19.0" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44dcf002ae3b32cd25400d6df128c5babec3927cd1eb7ce813cfff20eb6c3746" +checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33" [[package]] name = "typenum" @@ -3311,6 +3333,28 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +[[package]] +name = "typeshare" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f44d1a2f454cb35fbe05b218c410792697e76bd868f48d3a418f2cd1a7d527d6" +dependencies = [ + "chrono", + "serde", + "serde_json", + "typeshare-annotation", +] + +[[package]] +name = "typeshare-annotation" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc670d0e358428857cc3b4bf504c691e572fccaec9542ff09212d3f13d74b7a9" +dependencies = [ + "quote", + "syn 1.0.109", +] + [[package]] name = "udev" version = "0.6.3" @@ -3384,12 +3428,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "url" version = "2.4.0" @@ -3705,6 +3743,15 @@ dependencies = [ "windows-targets 0.42.2", ] +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.0", +] + [[package]] name = "windows-implement" version = "0.44.0" diff --git a/Cargo.toml b/Cargo.toml index b13486b8..42a924f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ serde_derive = "^1.0" serde_json = "^1.0" toml = "^0.5.10" ron = "*" +typeshare = "1.0.0" log = "^0.4" env_logger = "^0.10.0" diff --git a/Makefile b/Makefile index 7932b7e6..520324f3 100644 --- a/Makefile +++ b/Makefile @@ -115,6 +115,20 @@ vendor: tar pcfJ vendor_asusctl_$(VERSION).tar.xz vendor rm -rf vendor +bindings: + typeshare ./rog-anime/src/ --lang=typescript --output-file=bindings/ts/anime.ts + typeshare ./rog-aura/src/ --lang=typescript --output-file=bindings/ts/aura.ts + typeshare ./rog-profiles/src/ --lang=typescript --output-file=bindings/ts/profiles.ts + typeshare ./rog-platform/src/ --lang=typescript --output-file=bindings/ts/platform.ts + +introspect: + dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Aura org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-aura-4.xml + dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Anime org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-anime-4.xml + dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Platform org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-platform-4.xml + dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Power org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-power-4.xml + dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Profile org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-profile-4.xml + dbus-send --system --type=method_call --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Supported org.freedesktop.DBus.Introspectable.Introspect > bindings/dbus-xml/org-asuslinux-supported-4.xml + build: ifeq ($(VENDORED),1) @echo "version = $(VERSION)" @@ -129,4 +143,4 @@ ifneq ($(STRIP_BINARIES),0) endif -.PHONY: all clean distclean install uninstall update build +.PHONY: all clean distclean install uninstall update build bindings diff --git a/asusctl/examples/aura-zoned-breathe.rs b/asusctl/examples/aura-zoned-breathe.rs index bbeb8aef..1fc7b306 100644 --- a/asusctl/examples/aura-zoned-breathe.rs +++ b/asusctl/examples/aura-zoned-breathe.rs @@ -32,7 +32,11 @@ fn main() -> Result<(), Box> { let zone = Effect::DoomFlicker(rog_aura::effects::DoomFlicker::new( LedCode::SingleZone, - Colour(200, 110, 0), + Colour { + r: 200, + g: 110, + b: 0, + }, 100, 10, )); diff --git a/asusd-user/src/config.rs b/asusd-user/src/config.rs index 785bfbf1..62c8c118 100644 --- a/asusd-user/src/config.rs +++ b/asusd-user/src/config.rs @@ -136,8 +136,16 @@ impl Default for ConfigAura { let mut seq = AuraSequences::new(false); let mut key = Effect::Breathe(Breathe::new( LedCode::W, - Colour(255, 0, 20), - Colour(20, 255, 0), + Colour { + r: 255, + g: 0, + b: 20, + }, + Colour { + r: 20, + g: 255, + b: 0, + }, Speed::Low, )); @@ -151,20 +159,25 @@ impl Default for ConfigAura { let key = Effect::Breathe(Breathe::new( LedCode::F, - Colour(255, 0, 0), - Colour(255, 0, 0), + Colour { r: 255, g: 0, b: 0 }, + Colour { r: 255, g: 0, b: 0 }, Speed::High, )); seq.push(key); - let mut key = Effect::Static(Static::new(LedCode::RCtrl, Colour(0, 0, 255))); + let mut key = Effect::Static(Static::new(LedCode::RCtrl, Colour { r: 0, g: 0, b: 255 })); seq.push(key.clone()); key.set_led(LedCode::LCtrl); seq.push(key.clone()); key.set_led(LedCode::Esc); seq.push(key); - let key = Effect::DoomFlicker(DoomFlicker::new(LedCode::N9, Colour(0, 0, 255), 80, 40)); + let key = Effect::DoomFlicker(DoomFlicker::new( + LedCode::N9, + Colour { r: 0, g: 0, b: 255 }, + 80, + 40, + )); seq.push(key); Self { diff --git a/asusd-user/src/ctrl_anime.rs b/asusd-user/src/ctrl_anime.rs index a87898d2..6cdb006a 100644 --- a/asusd-user/src/ctrl_anime.rs +++ b/asusd-user/src/ctrl_anime.rs @@ -22,22 +22,18 @@ pub struct Timer { /// animation loop count count: u64, /// Used only for `TimeType::Timer`, milliseonds to fade the image in for - fade_in: Option, + fade_in: u64, /// Used only for `TimeType::Timer`, milliseonds to fade the image out for - fade_out: Option, + fade_out: u64, } impl From for AnimTime { fn from(time: Timer) -> Self { match time.type_of { TimeType::Timer => { - if time.fade_in.is_some() || time.fade_out.is_some() { - let fade_in = time - .fade_in - .map_or(Duration::from_secs(0), Duration::from_millis); - let fade_out = time - .fade_out - .map_or(Duration::from_secs(0), Duration::from_millis); + if time.fade_in != 0 && time.fade_out != 0 { + let fade_in = Duration::from_millis(time.fade_in); + let fade_out = Duration::from_millis(time.fade_out); let show_for = if time.count != 0 { Some(Duration::from_millis(time.count)) } else { diff --git a/asusd/src/ctrl_aura/config.rs b/asusd/src/ctrl_aura/config.rs index 566c9e39..0d1ddddf 100644 --- a/asusd/src/ctrl_aura/config.rs +++ b/asusd/src/ctrl_aura/config.rs @@ -267,7 +267,11 @@ mod tests { let mut config = AuraConfig::create_default(AuraDevice::X19b6, &LaptopLedData::default()); let effect = AuraEffect { - colour1: Colour(0xff, 0x00, 0xff), + colour1: Colour { + r: 0xff, + g: 0x00, + b: 0xff, + }, zone: AuraZone::Key1, ..Default::default() }; @@ -276,21 +280,33 @@ mod tests { assert!(config.multizone.is_some()); let effect = AuraEffect { - colour1: Colour(0x00, 0xff, 0xff), + colour1: Colour { + r: 0x00, + g: 0xff, + b: 0xff, + }, zone: AuraZone::Key2, ..Default::default() }; config.set_builtin(effect); let effect = AuraEffect { - colour1: Colour(0xff, 0xff, 0x00), + colour1: Colour { + r: 0xff, + g: 0xff, + b: 0x00, + }, zone: AuraZone::Key3, ..Default::default() }; config.set_builtin(effect); let effect = AuraEffect { - colour1: Colour(0x00, 0xff, 0x00), + colour1: Colour { + r: 0x00, + g: 0xff, + b: 0x00, + }, zone: AuraZone::Key4, ..Default::default() }; @@ -302,10 +318,38 @@ 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(0xff, 0x00, 0xff)); - assert_eq!(sta[1].colour1, Colour(0x00, 0xff, 0xff)); - assert_eq!(sta[2].colour1, Colour(0xff, 0xff, 0x00)); - assert_eq!(sta[3].colour1, Colour(0x00, 0xff, 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] diff --git a/asusd/src/ctrl_aura/controller.rs b/asusd/src/ctrl_aura/controller.rs index 041b8e61..13aacfb7 100644 --- a/asusd/src/ctrl_aura/controller.rs +++ b/asusd/src/ctrl_aura/controller.rs @@ -49,7 +49,7 @@ impl GetSupported for CtrlKbdLed { } } -#[derive(Debug, PartialEq, Eq, PartialOrd)] +#[derive(Debug, PartialEq, Eq)] pub enum LEDNode { KbdLed(KeyboardLed), Rog(HidRaw), @@ -317,9 +317,9 @@ impl CtrlKbdLed { let buf = [ 1, mode.mode as u8, - mode.colour1.0, - mode.colour1.1, - mode.colour1.2, + mode.colour1.r, + mode.colour1.g, + mode.colour1.b, mode.speed as u8, ]; platform.set_kbd_rgb_mode(&buf)?; @@ -435,7 +435,11 @@ mod tests { }; let mut effect = AuraEffect { - colour1: Colour(0xff, 0x00, 0xff), + colour1: Colour { + r: 0xff, + g: 0x00, + b: 0xff, + }, zone: AuraZone::None, ..Default::default() }; diff --git a/asusd/src/ctrl_aura/trait_impls.rs b/asusd/src/ctrl_aura/trait_impls.rs index fedde20a..5db6659a 100644 --- a/asusd/src/ctrl_aura/trait_impls.rs +++ b/asusd/src/ctrl_aura/trait_impls.rs @@ -55,33 +55,44 @@ impl CtrlKbdLedZbus { /// /// ```text /// pub struct AuraPowerDev { - /// pub x1866: Vec, - /// pub x19b6: Vec, + /// tuf: Vec, + /// x1866: Vec, + /// x19b6: Vec, /// } - /// pub enum AuraDev1866 { - /// Awake, - /// Keyboard, - /// Lightbar, + /// pub enum AuraDevTuf { /// Boot, + /// Awake, /// Sleep, + /// Keyboard, /// } - /// enum AuraDev19b6 { - /// BootLogo, - /// BootKeyb, - /// AwakeLogo, - /// AwakeKeyb, - /// SleepLogo, - /// SleepKeyb, - /// ShutdownLogo, - /// ShutdownKeyb, - /// AwakeBar, - /// BootBar, - /// SleepBar, - /// ShutdownBar, - /// BootRearBar, - /// AwakeRearBar, - /// SleepRearBar, - /// ShutdownRearBar, + /// pub enum AuraDevRog1 { + /// Awake = 0x000002, + /// Keyboard = 0x080000, + /// Lightbar = 0x040500, + /// Boot = 0xc31209, + /// Sleep = 0x300804, + /// } + /// pub enum AuraDevRog2 { + /// BootLogo = 1, + /// BootKeyb = 1 << 1, + /// AwakeLogo = 1 << 2, + /// AwakeKeyb = 1 << 3, + /// SleepLogo = 1 << 4, + /// SleepKeyb = 1 << 5, + /// ShutdownLogo = 1 << 6, + /// ShutdownKeyb = 1 << 7, + /// BootBar = 1 << (7 + 2), + /// AwakeBar = 1 << (7 + 3), + /// SleepBar = 1 << (7 + 4), + /// ShutdownBar = 1 << (7 + 5), + /// BootLid = 1 << (15 + 1), + /// AwakeLid = 1 << (15 + 2), + /// SleepLid = 1 << (15 + 3), + /// ShutdownLid = 1 << (15 + 4), + /// BootRearGlow = 1 << (23 + 1), + /// AwakeRearGlow = 1 << (23 + 2), + /// SleepRearGlow = 1 << (23 + 3), + /// ShutdownRearGlow = 1 << (23 + 4), /// } /// ``` async fn set_leds_power( @@ -260,7 +271,6 @@ impl CtrlTask for CtrlKbdLedZbus { .map_err(|e| error!("CtrlKbdLedTask: {e}")) .ok(); } else if start { - info!("CtrlKbdLedTask saving last brightness"); Self::update_config(&mut lock) .map_err(|e| error!("CtrlKbdLedTask: {e}")) .ok(); diff --git a/bindings/dbus-xml/org-asuslinux-anime-4.xml b/bindings/dbus-xml/org-asuslinux-anime-4.xml new file mode 100644 index 00000000..1c4d1dfa --- /dev/null +++ b/bindings/dbus-xml/org-asuslinux-anime-4.xml @@ -0,0 +1,105 @@ +method return time=1687857321.236676 sender=:1.373 -> destination=:1.434 serial=2259 reply_serial=2 + string " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" diff --git a/bindings/dbus-xml/org-asuslinux-aura-4.xml b/bindings/dbus-xml/org-asuslinux-aura-4.xml new file mode 100644 index 00000000..95405fe8 --- /dev/null +++ b/bindings/dbus-xml/org-asuslinux-aura-4.xml @@ -0,0 +1,146 @@ +method return time=1687857321.234264 sender=:1.373 -> destination=:1.433 serial=2258 reply_serial=2 + string " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" diff --git a/bindings/dbus-xml/org-asuslinux-platform-4.xml b/bindings/dbus-xml/org-asuslinux-platform-4.xml new file mode 100644 index 00000000..1bb7ebb1 --- /dev/null +++ b/bindings/dbus-xml/org-asuslinux-platform-4.xml @@ -0,0 +1,107 @@ +method return time=1687857321.238947 sender=:1.373 -> destination=:1.435 serial=2260 reply_serial=2 + string " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" diff --git a/bindings/dbus-xml/org-asuslinux-power-4.xml b/bindings/dbus-xml/org-asuslinux-power-4.xml new file mode 100644 index 00000000..61ff702b --- /dev/null +++ b/bindings/dbus-xml/org-asuslinux-power-4.xml @@ -0,0 +1,60 @@ +method return time=1687857321.240891 sender=:1.373 -> destination=:1.436 serial=2261 reply_serial=2 + string " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" diff --git a/bindings/dbus-xml/org-asuslinux-profile-4.xml b/bindings/dbus-xml/org-asuslinux-profile-4.xml new file mode 100644 index 00000000..d13d9cc8 --- /dev/null +++ b/bindings/dbus-xml/org-asuslinux-profile-4.xml @@ -0,0 +1,120 @@ +method return time=1687857321.242598 sender=:1.373 -> destination=:1.437 serial=2262 reply_serial=2 + string " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" diff --git a/bindings/dbus-xml/org-asuslinux-supported-4.xml b/bindings/dbus-xml/org-asuslinux-supported-4.xml new file mode 100644 index 00000000..eb025705 --- /dev/null +++ b/bindings/dbus-xml/org-asuslinux-supported-4.xml @@ -0,0 +1,48 @@ +method return time=1687857321.244505 sender=:1.373 -> destination=:1.438 serial=2263 reply_serial=2 + string " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" diff --git a/bindings/ts/anime.ts b/bindings/ts/anime.ts new file mode 100644 index 00000000..0b3493c3 --- /dev/null +++ b/bindings/ts/anime.ts @@ -0,0 +1,53 @@ +/* + Generated by typeshare 1.6.0 +*/ + +export enum AnimBooting { + GlitchConstruction = "GlitchConstruction", + StaticEmergence = "StaticEmergence", +} + +export enum AnimAwake { + BinaryBannerScroll = "BinaryBannerScroll", + RogLogoGlitch = "RogLogoGlitch", +} + +export enum AnimSleeping { + BannerSwipe = "BannerSwipe", + Starfield = "Starfield", +} + +export enum AnimShutdown { + GlitchOut = "GlitchOut", + SeeYa = "SeeYa", +} + +export interface Animations { + boot: AnimBooting; + awake: AnimAwake; + sleep: AnimSleeping; + shutdown: AnimShutdown; +} + +/** Base LED brightness of the display */ +export enum Brightness { + Off = "Off", + Low = "Low", + Med = "Med", + High = "High", +} + +export interface DeviceState { + display_enabled: boolean; + display_brightness: Brightness; + builtin_anims_enabled: boolean; + builtin_anims: Animations; +} + +export enum AnimeType { + GA401 = "GA401", + GA402 = "GA402", + GU604 = "GU604", + Unknown = "Unknown", +} + diff --git a/bindings/ts/aura.ts b/bindings/ts/aura.ts new file mode 100644 index 00000000..1a7309fe --- /dev/null +++ b/bindings/ts/aura.ts @@ -0,0 +1,219 @@ +/* + Generated by typeshare 1.6.0 +*/ + +/** Represents the per-key raw USB packets */ +export type UsbPackets = number[][]; + +/** + * A `UsbPackets` contains all data to change the full set of keyboard + * key colours individually. + * + * Each row of the internal array is a full HID packet that can be sent + * to the keyboard EC. One row controls one group of keys, these keys are not + * necessarily all on the same row of the keyboard, with some splitting between + * two rows. + */ +export interface LedUsbPackets { + /** The packet data used to send data to the USB keyboard */ + usb_packets: UsbPackets; + /** + * 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: boolean; +} + +export interface Colour { + r: number; + g: number; + b: number; +} + +/** Enum of modes that convert to the actual number required by a USB HID packet */ +export enum AuraModeNum { + Static = "Static", + Breathe = "Breathe", + Strobe = "Strobe", + Rainbow = "Rainbow", + Star = "Star", + Rain = "Rain", + Highlight = "Highlight", + Laser = "Laser", + Ripple = "Ripple", + Pulse = "Pulse", + Comet = "Comet", + Flash = "Flash", +} + +/** Base effects have no zoning, while multizone is 1-4 */ +export enum AuraZone { + /** Used if keyboard has no zones, or if setting all */ + None = "None", + /** Leftmost zone */ + Key1 = "Key1", + /** Zone after leftmost */ + Key2 = "Key2", + /** Zone second from right */ + Key3 = "Key3", + /** Rightmost zone */ + Key4 = "Key4", + /** Logo on the lid (or elsewhere?) */ + Logo = "Logo", + /** The left part of a lightbar (typically on the front of laptop) */ + BarLeft = "BarLeft", + /** The right part of a lightbar */ + BarRight = "BarRight", +} + +export enum Speed { + Low = "Low", + Med = "Med", + High = "High", +} + +/** + * Used for Rainbow mode. + * + * Enum corresponds to the required integer value + */ +export enum Direction { + Right = "Right", + Left = "Left", + Up = "Up", + Down = "Down", +} + +/** + * Default factory modes structure. This easily converts to an USB HID packet + * with: + * ```rust + * // let bytes: [u8; LED_MSG_LEN] = mode.into(); + * ``` + */ +export interface AuraEffect { + /** The effect type */ + mode: AuraModeNum; + /** `AuraZone::None` for no zone or zoneless keyboards */ + zone: AuraZone; + /** Primary colour for all modes */ + colour1: Colour; + /** Secondary colour in some modes like Breathing or Stars */ + colour2: Colour; + /** One of three speeds for modes that support speed (most that animate) */ + speed: Speed; + /** Up, down, left, right. Only Rainbow mode seems to use this */ + direction: Direction; +} + +export enum AuraDevTuf { + Boot = "Boot", + Awake = "Awake", + Sleep = "Sleep", + Keyboard = "Keyboard", +} + +/** + * # Bits for older 0x1866, 0x1869, 0x1854 keyboard models + * + * Keybord and Lightbar require Awake, Boot and Sleep apply to both + * Keybord and Lightbar regardless of if either are enabled (or Awake is + * enabled) + * + * | Byte 1 | Byte 2 | Byte 3 | Byte 4 | function | hex + * | + * |------------|------------|------------|------------|-----------|-------------| + * | 0000, 0000 | 0000, 0000 | 0000, 0010 | 0000, 0000 | Awake | + * 00,00,02,00 | | 0000, 1000 | 0000, 0000 | 0000, 0000 | 0000, 0000 | Keyboard + * | 08,00,00,00 | | 0000, 0100 | 0000, 0101 | 0000, 0000 | 0000, 0000 | + * Lightbar | 04,05,00,00 | | 1100, 0011 | 0001, 0010 | 0000, 1001 | 0000, + * 0000 | Boot/Sht | c3,12,09,00 | | 0011, 0000 | 0000, 1000 | 0000, 0100 | + * 0000, 0000 | Sleep | 30,08,04,00 | | 1111, 1111 | 0001, 1111 | 0000, + * 1111 | 0000, 0000 | all on | | | 0000, 0000 | 0000, 0000 | + * 0000, 0000 | 0000, 0010 | Rear Glow | 00,00,00,02 | + */ +export enum AuraDevRog1 { + Awake = "Awake", + Keyboard = "Keyboard", + Lightbar = "Lightbar", + Boot = "Boot", + Sleep = "Sleep", +} + +/** + * # Bits for newer 0x18c6, 0x19B6, 0x1a30, keyboard models + * + * byte 4 in the USB packet is for keyboard + logo power states + * default is on, `ff` + * Keyboard and logo use the full range of bits (almost) + * + * | n1 | n2 | hex | action | bit | + * |------|------|-----|-----------------------|-------| + * | 0000 | 0000 | 00 | all off | | + * | 0000 | 0001 | 01 | logo boot | bit 1 | + * | 0000 | 0010 | 02 | keyboard boot | bit 2 | + * | 0000 | 0100 | 04 | logo awake | bit 3 | + * | 0000 | 1000 | 08 | keyboard awake | bit 4 | + * | 0001 | 0000 | 10 | logo sleep off | bit 5 | + * | 0010 | 0000 | 20 | keyboard sleep | bit 6 | + * | 0100 | 0000 | 40 | logo shutdown off | bit 7 | + * | 1000 | 0000 | 80 | keyboard shutdown off | bit 8 | + * + * byte 5 = lightbar + * + * | 1 | 2 | hex | action | bit | + * |------|------|-----|----------------------|-------| + * | 0000 | 0010 | 02 | lightbar off boot | bit 2 | + * | 0000 | 0100 | 04 | lightbar on | bit 3 | + * | 0000 | 1000 | 08 | lightbar off sleep | bit 4 | + * | 0001 | 0000 | 10 | lightbar shtdn off | bit 5 | + */ +export enum AuraDevRog2 { + BootLogo = "BootLogo", + BootKeyb = "BootKeyb", + AwakeLogo = "AwakeLogo", + AwakeKeyb = "AwakeKeyb", + SleepLogo = "SleepLogo", + SleepKeyb = "SleepKeyb", + ShutdownLogo = "ShutdownLogo", + ShutdownKeyb = "ShutdownKeyb", + BootBar = "BootBar", + AwakeBar = "AwakeBar", + SleepBar = "SleepBar", + ShutdownBar = "ShutdownBar", + BootLid = "BootLid", + AwakeLid = "AwakeLid", + SleepLid = "SleepLid", + ShutdownLid = "ShutdownLid", + BootRearGlow = "BootRearGlow", + AwakeRearGlow = "AwakeRearGlow", + SleepRearGlow = "SleepRearGlow", + ShutdownRearGlow = "ShutdownRearGlow", +} + +/** This struct is intended as a helper to pass args to generic dbus interface */ +export interface AuraPowerDev { + tuf: AuraDevTuf[]; + x1866: AuraDevRog1[]; + x19b6: AuraDevRog2[]; +} + +export enum LedBrightness { + Off = "Off", + Low = "Low", + Med = "Med", + High = "High", +} + +export enum AuraDevice { + Tuf = "Tuf", + X1854 = "X1854", + X1869 = "X1869", + X1866 = "X1866", + X18c6 = "X18c6", + X19b6 = "X19b6", + X1a30 = "X1a30", + Unknown = "Unknown", +} + diff --git a/bindings/ts/platform.ts b/bindings/ts/platform.ts new file mode 100644 index 00000000..ed0ee5f2 --- /dev/null +++ b/bindings/ts/platform.ts @@ -0,0 +1,57 @@ +/* + Generated by typeshare 1.6.0 +*/ + +export type AnimeSupportedFunctions = boolean; + +export interface ChargeSupportedFunctions { + charge_level_set: boolean; +} + +export interface PlatformProfileFunctions { + platform_profile: boolean; + fan_curves: boolean; +} + +export enum AdvancedAura { + None = "None", + Zoned = "Zoned", + PerKey = "PerKey", +} + +export interface LedSupportedFunctions { + dev_id: AuraDevice; + brightness: boolean; + basic_modes: AuraModeNum[]; + basic_zones: AuraZone[]; + advanced_type: AdvancedAura; +} + +export interface RogBiosSupportedFunctions { + post_sound: boolean; + gpu_mux: boolean; + panel_overdrive: boolean; + dgpu_disable: boolean; + egpu_enable: boolean; + mini_led_mode: boolean; +} + +export interface SupportedFunctions { + anime_ctrl: AnimeSupportedFunctions; + charge_ctrl: ChargeSupportedFunctions; + platform_profile: PlatformProfileFunctions; + keyboard_led: LedSupportedFunctions; + rog_bios_ctrl: RogBiosSupportedFunctions; +} + +export enum GpuMode { + Discrete = "Discrete", + Optimus = "Optimus", + Integrated = "Integrated", + Egpu = "Egpu", + Vfio = "Vfio", + Ultimate = "Ultimate", + Error = "Error", + NotSupported = "NotSupported", +} + diff --git a/bindings/ts/profiles.ts b/bindings/ts/profiles.ts new file mode 100644 index 00000000..0d7439f0 --- /dev/null +++ b/bindings/ts/profiles.ts @@ -0,0 +1,35 @@ +/* + Generated by typeshare 1.6.0 +*/ + +export enum FanCurvePU { + CPU = "CPU", + GPU = "GPU", +} + +export interface CurveData { + fan: FanCurvePU; + pwm: [number, number, number, number, number, number, number, number]; + temp: [number, number, number, number, number, number, number, number]; +} + +/** A `FanCurveSet` contains both CPU and GPU fan curve data */ +export interface FanCurveSet { + enabled: boolean; + cpu: CurveData; + gpu: CurveData; +} + +/** Main purpose of `FanCurves` is to enable restoring state on system boot */ +export interface FanCurveProfiles { + balanced: FanCurveSet; + performance: FanCurveSet; + quiet: FanCurveSet; +} + +export enum Profile { + Balanced = "Balanced", + Performance = "Performance", + Quiet = "Quiet", +} + diff --git a/rog-anime/Cargo.toml b/rog-anime/Cargo.toml index 7456e3d3..19779993 100644 --- a/rog-anime/Cargo.toml +++ b/rog-anime/Cargo.toml @@ -31,6 +31,7 @@ serde.workspace = true serde_derive.workspace = true glam.workspace = true +typeshare.workspace = true zbus = { workspace = true, optional = true } diff --git a/rog-anime/src/data.rs b/rog-anime/src/data.rs index 2c33bb15..2529db07 100644 --- a/rog-anime/src/data.rs +++ b/rog-anime/src/data.rs @@ -5,6 +5,7 @@ use std::time::{Duration, Instant}; use log::info; use serde_derive::{Deserialize, Serialize}; +use typeshare::typeshare; #[cfg(feature = "dbus")] use zbus::zvariant::Type; @@ -27,7 +28,9 @@ 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]; +#[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] +#[typeshare] #[derive(Default, Deserialize, PartialEq, Eq, Clone, Copy, Serialize, Debug)] pub struct Animations { pub boot: AnimBooting, @@ -36,7 +39,9 @@ pub struct Animations { pub shutdown: AnimShutdown, } +#[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] +#[typeshare] #[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)] pub struct DeviceState { pub display_enabled: bool, @@ -45,8 +50,9 @@ pub struct DeviceState { pub builtin_anims: Animations, } -#[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum AnimeType { GA401, GA402, diff --git a/rog-anime/src/lib.rs b/rog-anime/src/lib.rs index 63629291..0abd01dc 100644 --- a/rog-anime/src/lib.rs +++ b/rog-anime/src/lib.rs @@ -33,3 +33,27 @@ pub mod error; pub mod usb; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); + +// #[cfg(feature = "typescript")] +// #[cfg(test)] +// mod tests { +// use crate::usb::{AnimShutdown, Brightness, AnimSleeping, AnimAwake, +// AnimBooting}; use crate::{AnimeType, Animations, DeviceState}; +// use ts_rs::SingleFileExporter; +// #[test] +// fn test_singlefile() { +// let out = SingleFileExporter::new(false) +// .and::() +// .and::() +// .and::() +// .and::() +// .and::() +// .and::() +// .and::() +// .and::() +// .finish() +// .unwrap(); +// println!("{out}"); +// assert_eq!(out, ""); +// } +// } diff --git a/rog-anime/src/usb.rs b/rog-anime/src/usb.rs index 86e356b0..462ccf4e 100644 --- a/rog-anime/src/usb.rs +++ b/rog-anime/src/usb.rs @@ -11,6 +11,7 @@ use std::str::FromStr; use serde_derive::{Deserialize, Serialize}; +use typeshare::typeshare; #[cfg(feature = "dbus")] use zbus::zvariant::Type; @@ -22,7 +23,8 @@ const DEV_PAGE: u8 = 0x5e; pub const VENDOR_ID: u16 = 0x0b05; pub const PROD_ID: u16 = 0x193b; -#[cfg_attr(feature = "dbus", derive(Type))] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[typeshare] #[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)] /// Base LED brightness of the display pub enum Brightness { @@ -58,7 +60,8 @@ impl From for Brightness { } } -#[cfg_attr(feature = "dbus", derive(Type))] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[typeshare] #[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)] pub enum AnimBooting { #[default] @@ -78,7 +81,8 @@ impl FromStr for AnimBooting { } } -#[cfg_attr(feature = "dbus", derive(Type))] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[typeshare] #[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)] pub enum AnimAwake { #[default] @@ -98,7 +102,8 @@ impl FromStr for AnimAwake { } } -#[cfg_attr(feature = "dbus", derive(Type))] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[typeshare] #[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)] pub enum AnimSleeping { #[default] @@ -118,7 +123,8 @@ impl FromStr for AnimSleeping { } } -#[cfg_attr(feature = "dbus", derive(Type))] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[typeshare] #[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)] pub enum AnimShutdown { #[default] diff --git a/rog-aura/Cargo.toml b/rog-aura/Cargo.toml index e495c9a3..233c6829 100644 --- a/rog-aura/Cargo.toml +++ b/rog-aura/Cargo.toml @@ -23,6 +23,7 @@ zbus = { workspace = true, optional = true } # cli and logging log.workspace = true +typeshare.workspace = true # Device control sysfs-class.workspace = true # used for backlight control and baord ID diff --git a/rog-aura/src/advanced.rs b/rog-aura/src/advanced.rs index 95be63fe..a546c200 100644 --- a/rog-aura/src/advanced.rs +++ b/rog-aura/src/advanced.rs @@ -1,5 +1,6 @@ use log::warn; use serde::{Deserialize, Serialize}; +use typeshare::typeshare; #[cfg(feature = "dbus")] use zbus::zvariant::Type; @@ -190,6 +191,7 @@ impl LedCode { } /// Represents the per-key raw USB packets +#[typeshare] pub type UsbPackets = Vec>; /// A `UsbPackets` contains all data to change the full set of keyboard @@ -199,6 +201,7 @@ pub type UsbPackets = Vec>; /// to the keyboard EC. One row controls one group of keys, these keys are not /// necessarily all on the same row of the keyboard, with some splitting between /// two rows. +#[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] #[derive(Debug, Clone, Deserialize, Serialize)] pub struct LedUsbPackets { diff --git a/rog-aura/src/builtin_modes.rs b/rog-aura/src/builtin_modes.rs index 47f8467e..37cdd18d 100644 --- a/rog-aura/src/builtin_modes.rs +++ b/rog-aura/src/builtin_modes.rs @@ -8,13 +8,15 @@ use std::fmt::Display; use std::str::FromStr; use serde_derive::{Deserialize, Serialize}; +use typeshare::typeshare; #[cfg(feature = "dbus")] use zbus::zvariant::Type; use crate::error::Error; use crate::LED_MSG_LEN; -#[cfg_attr(feature = "dbus", derive(Type))] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] #[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum LedBrightness { Off, @@ -34,13 +36,18 @@ impl From for LedBrightness { } } +#[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Copy, Deserialize, Serialize)] -pub struct Colour(pub u8, pub u8, pub u8); +#[derive(Debug, Clone, PartialEq, Eq, Copy, Deserialize, Serialize)] +pub struct Colour { + pub r: u8, + pub g: u8, + pub b: u8, +} impl Default for Colour { fn default() -> Self { - Colour(166, 0, 0) + Colour { r: 166, g: 0, b: 0 } } } @@ -54,39 +61,44 @@ impl FromStr for Colour { let r = u8::from_str_radix(&s[0..2], 16).or(Err(Error::ParseColour))?; let g = u8::from_str_radix(&s[2..4], 16).or(Err(Error::ParseColour))?; let b = u8::from_str_radix(&s[4..6], 16).or(Err(Error::ParseColour))?; - Ok(Colour(r, g, b)) + Ok(Colour { r, g, b }) } } impl From<&[f32; 3]> for Colour { fn from(c: &[f32; 3]) -> Self { - Self( - (255.0 * c[0]) as u8, - (255.0 * c[1]) as u8, - (255.0 * c[2]) as u8, - ) + Self { + r: (255.0 * c[0]) as u8, + g: (255.0 * c[1]) as u8, + b: (255.0 * c[2]) as u8, + } } } impl From for [f32; 3] { fn from(c: Colour) -> Self { - [c.0 as f32 / 255.0, c.1 as f32 / 255.0, c.2 as f32 / 255.0] + [c.r as f32 / 255.0, c.g as f32 / 255.0, c.b as f32 / 255.0] } } impl From<&[u8; 3]> for Colour { fn from(c: &[u8; 3]) -> Self { - Self(c[0], c[1], c[2]) + Self { + r: c[0], + g: c[1], + b: c[2], + } } } impl From for [u8; 3] { fn from(c: Colour) -> Self { - [c.0, c.1, c.2] + [c.r, c.g, c.b] } } -#[cfg_attr(feature = "dbus", derive(Type))] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] #[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum Speed { Low = 0xe1, @@ -124,7 +136,8 @@ impl From for u8 { /// Used for Rainbow mode. /// /// Enum corresponds to the required integer value -#[cfg_attr(feature = "dbus", derive(Type))] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] #[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum Direction { Right, @@ -153,9 +166,10 @@ impl FromStr for Direction { } /// Enum of modes that convert to the actual number required by a USB HID packet -#[cfg_attr(feature = "dbus", derive(Type))] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] #[derive( - Debug, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Deserialize, Serialize, + Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Deserialize, Serialize, )] pub enum AuraModeNum { #[default] @@ -242,7 +256,8 @@ impl From for AuraModeNum { } /// Base effects have no zoning, while multizone is 1-4 -#[cfg_attr(feature = "dbus", derive(Type))] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum AuraZone { /// Used if keyboard has no zones, or if setting all @@ -288,6 +303,7 @@ impl FromStr for AuraZone { /// ```rust /// // let bytes: [u8; LED_MSG_LEN] = mode.into(); /// ``` +#[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] #[derive(Debug, Clone, Deserialize, Serialize)] pub struct AuraEffect { @@ -335,8 +351,8 @@ impl Default for AuraEffect { Self { mode: AuraModeNum::Static, zone: AuraZone::None, - colour1: Colour(166, 0, 0), - colour2: Colour(0, 0, 0), + colour1: Colour { r: 166, g: 0, b: 0 }, + colour2: Colour { r: 0, g: 0, b: 0 }, speed: Speed::Med, direction: Direction::Right, } @@ -408,14 +424,14 @@ impl From<&AuraEffect> for [u8; LED_MSG_LEN] { msg[1] = 0xb3; msg[2] = aura.zone as u8; msg[3] = aura.mode as u8; - msg[4] = aura.colour1.0; - msg[5] = aura.colour1.1; - msg[6] = aura.colour1.2; + msg[4] = aura.colour1.r; + msg[5] = aura.colour1.g; + msg[6] = aura.colour1.b; msg[7] = aura.speed as u8; msg[8] = aura.direction as u8; - msg[10] = aura.colour2.0; - msg[11] = aura.colour2.1; - msg[12] = aura.colour2.2; + msg[10] = aura.colour2.r; + msg[11] = aura.colour2.g; + msg[12] = aura.colour2.b; msg } } @@ -427,14 +443,14 @@ impl From<&AuraEffect> for Vec { msg[1] = 0xb3; msg[2] = aura.zone as u8; msg[3] = aura.mode as u8; - msg[4] = aura.colour1.0; - msg[5] = aura.colour1.1; - msg[6] = aura.colour1.2; + msg[4] = aura.colour1.r; + msg[5] = aura.colour1.g; + msg[6] = aura.colour1.b; msg[7] = aura.speed as u8; msg[8] = aura.direction as u8; - msg[10] = aura.colour2.0; - msg[11] = aura.colour2.1; - msg[12] = aura.colour2.2; + msg[10] = aura.colour2.r; + msg[11] = aura.colour2.g; + msg[12] = aura.colour2.b; msg } } @@ -448,7 +464,11 @@ mod tests { let st = AuraEffect { mode: AuraModeNum::Static, zone: AuraZone::None, - colour1: Colour(0xff, 0x11, 0xdd), + colour1: Colour { + r: 0xff, + g: 0x11, + b: 0xdd, + }, colour2: Colour::default(), speed: Speed::Med, direction: Direction::Right, @@ -468,8 +488,12 @@ mod tests { let mut st = AuraEffect { mode: AuraModeNum::Static, zone: AuraZone::Key1, - colour1: Colour(0xff, 0, 0), - colour2: Colour(0, 0, 0), + colour1: Colour { + r: 0xff, + g: 0, + b: 0, + }, + colour2: Colour { r: 0, g: 0, b: 0 }, speed: Speed::Low, direction: Direction::Left, }; @@ -480,7 +504,11 @@ mod tests { assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]); st.zone = AuraZone::Key2; - st.colour1 = Colour(0xff, 0xff, 0); + st.colour1 = Colour { + r: 0xff, + g: 0xff, + b: 0, + }; let capture = [ 0x5d, 0xb3, 0x02, 0x00, 0xff, 0xff, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -488,7 +516,11 @@ mod tests { assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]); st.zone = AuraZone::Key3; - st.colour1 = Colour(0, 0xff, 0xff); + st.colour1 = Colour { + r: 0, + g: 0xff, + b: 0xff, + }; let capture = [ 0x5d, 0xb3, 0x03, 0x00, 0x00, 0xff, 0xff, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -496,7 +528,11 @@ mod tests { assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]); st.zone = AuraZone::Key4; - st.colour1 = Colour(0xff, 0x00, 0xff); + st.colour1 = Colour { + r: 0xff, + g: 0x00, + b: 0xff, + }; let capture = [ 0x5d, 0xb3, 0x04, 0x00, 0xff, 0x00, 0xff, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -504,7 +540,11 @@ mod tests { assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]); st.zone = AuraZone::Logo; - st.colour1 = Colour(0x2c, 0xff, 0x00); + st.colour1 = Colour { + r: 0x2c, + g: 0xff, + b: 0x00, + }; let capture = [ 0x5d, 0xb3, 0x05, 0x00, 0x2c, 0xff, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -512,7 +552,11 @@ mod tests { assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]); st.zone = AuraZone::BarLeft; - st.colour1 = Colour(0xff, 0x00, 0x00); + st.colour1 = Colour { + r: 0xff, + g: 0x00, + b: 0x00, + }; let capture = [ 0x5d, 0xb3, 0x06, 0x00, 0xff, 0x00, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -520,7 +564,11 @@ mod tests { assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]); st.zone = AuraZone::BarRight; - st.colour1 = Colour(0xff, 0x00, 0xcd); + st.colour1 = Colour { + r: 0xff, + g: 0x00, + b: 0xcd, + }; let capture = [ 0x5d, 0xb3, 0x07, 0x00, 0xff, 0x00, 0xcd, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, diff --git a/rog-aura/src/effects/breathe.rs b/rog-aura/src/effects/breathe.rs index e2f00fca..b9fc481e 100644 --- a/rog-aura/src/effects/breathe.rs +++ b/rog-aura/src/effects/breathe.rs @@ -53,30 +53,33 @@ impl EffectState for Breathe { let speed = 4 - ::from(*speed); - if *colour_actual == Colour(0, 0, 0) { + if *colour_actual == (Colour { r: 0, g: 0, b: 0 }) { *use_colour1 = !*use_colour1; } let colour = if !*use_colour1 { colour2 } else { colour1 }; - let r1_scale = colour.0 / speed / 2; - let g1_scale = colour.1 / speed / 2; - let b1_scale = colour.2 / speed / 2; + let r1_scale = colour.r / speed / 2; + let g1_scale = colour.g / speed / 2; + let b1_scale = colour.b / speed / 2; - if *colour_actual == Colour(0, 0, 0) { + if *colour_actual == (Colour { r: 0, g: 0, b: 0 }) { *flipped = true; - } else if colour_actual >= colour { + } else if colour_actual.r >= colour.r + && colour_actual.g >= colour.g + && colour_actual.b >= colour.b + { *flipped = false; } if !*flipped { - colour_actual.0 = colour_actual.0.saturating_sub(r1_scale); - colour_actual.1 = colour_actual.1.saturating_sub(g1_scale); - colour_actual.2 = colour_actual.2.saturating_sub(b1_scale); + colour_actual.r = colour_actual.r.saturating_sub(r1_scale); + colour_actual.g = colour_actual.g.saturating_sub(g1_scale); + colour_actual.b = colour_actual.b.saturating_sub(b1_scale); } else { - colour_actual.0 = colour_actual.0.saturating_add(r1_scale); - colour_actual.1 = colour_actual.1.saturating_add(g1_scale); - colour_actual.2 = colour_actual.2.saturating_add(b1_scale); + colour_actual.r = colour_actual.r.saturating_add(r1_scale); + colour_actual.g = colour_actual.g.saturating_add(g1_scale); + colour_actual.b = colour_actual.b.saturating_add(b1_scale); } } } diff --git a/rog-aura/src/effects/doom.rs b/rog-aura/src/effects/doom.rs index e1b613e4..28492e0a 100644 --- a/rog-aura/src/effects/doom.rs +++ b/rog-aura/src/effects/doom.rs @@ -51,17 +51,17 @@ impl EffectState for DoomFlicker { } // TODO: make a "percentage" method on Colour. - let max_light = Colour( - (start_colour.0 as f32 / 100.0 * *max_percentage as f32) as u8, - (start_colour.1 as f32 / 100.0 * *max_percentage as f32) as u8, - (start_colour.2 as f32 / 100.0 * *max_percentage as f32) as u8, - ); + 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, + }; // min light is a percentage of the set colour - let min_light = Colour( - (start_colour.0 as f32 / 100.0 * *min_percentage as f32) as u8, - (start_colour.1 as f32 / 100.0 * *min_percentage as f32) as u8, - (start_colour.2 as f32 / 100.0 * *min_percentage as f32) as u8, - ); + 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, + }; // Convert the 255 to percentage let amount = (p_random() & 7) as f32 * 8.0; @@ -76,9 +76,9 @@ impl EffectState for DoomFlicker { *colour = (max - max_amount) as u8; } }; - set_colour(&mut colour.0, max_light.0 as f32, min_light.0 as f32); - set_colour(&mut colour.1, max_light.1 as f32, min_light.1 as f32); - set_colour(&mut colour.2, max_light.2 as f32, min_light.2 as f32); + set_colour(&mut colour.r, max_light.r as f32, min_light.r as f32); + set_colour(&mut colour.g, max_light.g as f32, min_light.g as f32); + set_colour(&mut colour.b, max_light.b as f32, min_light.b as f32); self.count = 4; } @@ -133,17 +133,17 @@ impl EffectState for DoomLightFlash { } // TODO: make a "percentage" method on Colour. - let max_light = Colour( - (start_colour.0 as f32 / 100.0 * *max_percentage as f32) as u8, - (start_colour.1 as f32 / 100.0 * *max_percentage as f32) as u8, - (start_colour.2 as f32 / 100.0 * *max_percentage as f32) as u8, - ); + 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, + }; // min light is a percentage of the set colour - let min_light = Colour( - (start_colour.0 as f32 / 100.0 * *min_percentage as f32) as u8, - (start_colour.1 as f32 / 100.0 * *min_percentage as f32) as u8, - (start_colour.2 as f32 / 100.0 * *min_percentage as f32) as u8, - ); + 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, + }; if *colour == max_light { *colour = min_light; diff --git a/rog-aura/src/effects/mod.rs b/rog-aura/src/effects/mod.rs index 88a53b3a..6e567c67 100644 --- a/rog-aura/src/effects/mod.rs +++ b/rog-aura/src/effects/mod.rs @@ -118,7 +118,7 @@ impl AdvancedEffects { for effect in &self.effects { let c = effect.colour(); - usb_packets.set(effect.led(), c.0, c.1, c.2); + usb_packets.set(effect.led(), c.r, c.g, c.b); } usb_packets.into() } @@ -209,8 +209,14 @@ 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(255, 127, 0)))); + seq.effects.push(Effect::Static(Static::new( + LedCode::F, + Colour { + r: 255, + g: 127, + b: 0, + }, + ))); seq.next_state(&layout); let packets = seq.create_packets(); @@ -227,8 +233,16 @@ mod tests { let mut seq = AdvancedEffects::new(false); seq.effects.push(Effect::Breathe(Breathe::new( LedCode::F, - Colour(255, 127, 0), - Colour(127, 0, 255), + Colour { + r: 255, + g: 127, + b: 0, + }, + Colour { + r: 127, + g: 0, + b: 255, + }, Speed::Med, ))); @@ -261,7 +275,11 @@ mod tests { let mut seq = AdvancedEffects::new(false); seq.effects.push(Effect::DoomFlicker(DoomFlicker::new( LedCode::F, - Colour(255, 127, 80), + Colour { + r: 255, + g: 127, + b: 80, + }, 100, 10, ))); diff --git a/rog-aura/src/layouts.rs b/rog-aura/src/layouts.rs index d7900eba..6e67e2ac 100644 --- a/rog-aura/src/layouts.rs +++ b/rog-aura/src/layouts.rs @@ -522,6 +522,7 @@ mod tests { let mut data_path = PathBuf::from(DATA_DIR); data_path.push("data"); data_path.push("aura_support.ron"); + dbg!(&data_path); let mut buf = std::fs::read_to_string(&data_path).unwrap(); let data: LedSupportFile = ron::from_str(&buf).unwrap(); diff --git a/rog-aura/src/lib.rs b/rog-aura/src/lib.rs index 232662cd..078d2790 100644 --- a/rog-aura/src/lib.rs +++ b/rog-aura/src/lib.rs @@ -21,13 +21,41 @@ pub mod usb; pub const LED_MSG_LEN: usize = 17; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); -pub const RED: Colour = Colour(0xff, 0x00, 0x00); -pub const GREEN: Colour = Colour(0x00, 0xff, 0x00); -pub const BLUE: Colour = Colour(0x00, 0x00, 0xff); -pub const VIOLET: Colour = Colour(0x9b, 0x26, 0xb6); -pub const TEAL: Colour = Colour(0x00, 0x7c, 0x80); -pub const YELLOW: Colour = Colour(0xff, 0xef, 0x00); -pub const ORANGE: Colour = Colour(0xff, 0xa4, 0x00); +pub const RED: Colour = Colour { + r: 0xff, + g: 0x00, + b: 0x00, +}; +pub const GREEN: Colour = Colour { + r: 0x00, + g: 0xff, + b: 0x00, +}; +pub const BLUE: Colour = Colour { + r: 0x00, + g: 0x00, + b: 0xff, +}; +pub const VIOLET: Colour = Colour { + r: 0x9b, + g: 0x26, + b: 0xb6, +}; +pub const TEAL: Colour = Colour { + r: 0x00, + g: 0x7c, + b: 0x80, +}; +pub const YELLOW: Colour = Colour { + r: 0xff, + g: 0xef, + b: 0x00, +}; +pub const ORANGE: Colour = Colour { + r: 0xff, + g: 0xa4, + b: 0x00, +}; pub const GRADIENT: [Colour; 7] = [RED, VIOLET, BLUE, TEAL, GREEN, YELLOW, ORANGE]; #[derive(Debug, Clone, PartialEq, Eq, Default, serde::Deserialize, serde::Serialize)] diff --git a/rog-aura/src/usb.rs b/rog-aura/src/usb.rs index 4abfc516..4641a264 100644 --- a/rog-aura/src/usb.rs +++ b/rog-aura/src/usb.rs @@ -2,6 +2,7 @@ use std::fmt::Debug; use std::ops::{BitAnd, BitOr}; use serde::{Deserialize, Serialize}; +use typeshare::typeshare; #[cfg(feature = "dbus")] use zbus::zvariant::Type; @@ -22,8 +23,9 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] { ] } -#[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Serialize, Deserialize, Default)] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] pub enum AuraDevice { Tuf, X1854, @@ -82,6 +84,7 @@ impl Debug for AuraDevice { } /// This struct is intended as a helper to pass args to generic dbus interface +#[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] #[derive(Clone, Default, Debug, Serialize, Deserialize)] pub struct AuraPowerDev { @@ -90,8 +93,9 @@ pub struct AuraPowerDev { pub x19b6: Vec, } -#[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[repr(u32)] pub enum AuraDevTuf { Boot, @@ -123,8 +127,9 @@ impl AuraDevTuf { /// 0000, 0000 | Sleep | 30,08,04,00 | | 1111, 1111 | 0001, 1111 | 0000, /// 1111 | 0000, 0000 | all on | | | 0000, 0000 | 0000, 0000 | /// 0000, 0000 | 0000, 0010 | Rear Glow | 00,00,00,02 | -#[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[repr(u32)] pub enum AuraDevRog1 { Awake = 0x000002, @@ -201,8 +206,9 @@ impl BitAnd for AuraDevRog1 { /// | 0000 | 0100 | 04 | lightbar on | bit 3 | /// | 0000 | 1000 | 08 | lightbar off sleep | bit 4 | /// | 0001 | 0000 | 10 | lightbar shtdn off | bit 5 | -#[cfg_attr(feature = "dbus", derive(Type))] -#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[repr(u32)] pub enum AuraDevRog2 { BootLogo = 1, diff --git a/rog-control-center/Cargo.toml b/rog-control-center/Cargo.toml index c4778c0f..af91e38a 100644 --- a/rog-control-center/Cargo.toml +++ b/rog-control-center/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [features] #default = ["mocking"] -mocking = [] +#mocking = [] [dependencies] egui = { git = "https://github.com/emilk/egui", rev = "b8e798777de519de3a1878798097ab2ab0bd4def"} diff --git a/rog-control-center/src/mocking.rs b/rog-control-center/src/mocking.rs index d99cfe16..e6a6a962 100644 --- a/rog-control-center/src/mocking.rs +++ b/rog-control-center/src/mocking.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use rog_aura::usb::{AuraDev19b6, AuraDevice, AuraPowerDev}; +use rog_aura::usb::{AuraDevRog2, AuraDevice, AuraPowerDev}; use rog_aura::{AuraEffect, AuraModeNum, AuraZone}; use rog_platform::platform::GpuMode; use rog_platform::supported::{ @@ -192,10 +192,10 @@ impl Led { tuf: vec![], x1866: vec![], x19b6: vec![ - AuraDev19b6::BootKeyb, - AuraDev19b6::AwakeKeyb, - AuraDev19b6::SleepLogo, - AuraDev19b6::AwakeLogo, + AuraDevRog2::BootKeyb, + AuraDevRog2::AwakeKeyb, + AuraDevRog2::SleepLogo, + AuraDevRog2::AwakeLogo, ], }) } @@ -241,7 +241,7 @@ impl Supported { fan_curves: true, }, keyboard_led: LedSupportedFunctions { - dev_id: AuraDevice::X19B6, + dev_id: AuraDevice::X19b6, brightness: true, basic_modes: vec![ AuraModeNum::Rain, @@ -266,6 +266,7 @@ impl Supported { gpu_mux: true, panel_overdrive: true, dgpu_disable: true, + mini_led_mode: true, egpu_enable: true, }, }) diff --git a/rog-control-center/src/pages/aura_page.rs b/rog-control-center/src/pages/aura_page.rs index b99dc0c6..1732aa24 100644 --- a/rog-control-center/src/pages/aura_page.rs +++ b/rog-control-center/src/pages/aura_page.rs @@ -22,7 +22,7 @@ impl RogApp { let green = oscillator2.load(Ordering::SeqCst) as u32; let blue = oscillator3.load(Ordering::SeqCst) as u32; states.aura.nudge_wave(red as u8, green as u8, blue as u8); - // let osc = c.0 * 255 / osc; + // let osc = c.r * 255 / osc; let c1 = states .aura .modes @@ -37,25 +37,25 @@ impl RogApp { .unwrap_or(&AuraEffect::default()) .colour2; - let mut colour = Color32::from_rgb(c1.0, c1.1, c1.2); + let mut colour = Color32::from_rgb(c1.r, c1.g, c1.b); if states.aura.current_mode == AuraModeNum::Pulse { colour = Color32::from_rgb( - (red * c1.0 as u32 / 100) as u8, - (red * c1.1 as u32 / 100) as u8, - (red * c1.2 as u32 / 100) as u8, + (red * c1.r as u32 / 100) as u8, + (red * c1.g as u32 / 100) as u8, + (red * c1.b as u32 / 100) as u8, ); } else if states.aura.current_mode == AuraModeNum::Breathe { if self.oscillator_toggle.load(Ordering::SeqCst) { colour = Color32::from_rgb( - (red * c2.0 as u32 / 100) as u8, - (red * c2.1 as u32 / 100) as u8, - (red * c2.2 as u32 / 100) as u8, + (red * c2.r as u32 / 100) as u8, + (red * c2.g as u32 / 100) as u8, + (red * c2.b as u32 / 100) as u8, ); } else { colour = Color32::from_rgb( - (red * c1.0 as u32 / 100) as u8, - (red * c1.1 as u32 / 100) as u8, - (red * c1.2 as u32 / 100) as u8, + (red * c1.r as u32 / 100) as u8, + (red * c1.g as u32 / 100) as u8, + (red * c1.b as u32 / 100) as u8, ); } } else if states.aura.current_mode == AuraModeNum::Strobe { diff --git a/rog-platform/Cargo.toml b/rog-platform/Cargo.toml index b412a887..23ca7566 100644 --- a/rog-platform/Cargo.toml +++ b/rog-platform/Cargo.toml @@ -14,6 +14,7 @@ sysfs-class.workspace = true concat-idents.workspace = true udev.workspace = true inotify.workspace = true +typeshare.workspace = true rusb.workspace = true diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index 3ec27d31..170a1f34 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -4,6 +4,7 @@ use std::str::FromStr; use log::{info, warn}; use serde::{Deserialize, Serialize}; +use typeshare::typeshare; use zbus::zvariant::Type; use crate::error::{PlatformError, Result}; @@ -72,6 +73,7 @@ impl AsusPlatform { } } +#[typeshare] #[derive(Serialize, Deserialize, Default, Type, Debug, PartialEq, Eq, Clone, Copy)] pub enum GpuMode { Discrete, diff --git a/rog-platform/src/supported.rs b/rog-platform/src/supported.rs index 77f8a402..25a0ad98 100644 --- a/rog-platform/src/supported.rs +++ b/rog-platform/src/supported.rs @@ -3,8 +3,10 @@ use std::fmt; use rog_aura::usb::AuraDevice; use rog_aura::{AdvancedAuraType, AuraModeNum, AuraZone}; use serde_derive::{Deserialize, Serialize}; +use typeshare::typeshare; use zbus::zvariant::Type; +#[typeshare] #[derive(Serialize, Deserialize, Type, Debug, Default, Clone)] pub struct SupportedFunctions { pub anime_ctrl: AnimeSupportedFunctions, @@ -14,20 +16,24 @@ pub struct SupportedFunctions { pub rog_bios_ctrl: RogBiosSupportedFunctions, } +#[typeshare] #[derive(Serialize, Deserialize, Type, Debug, Default, Clone)] pub struct AnimeSupportedFunctions(pub bool); +#[typeshare] #[derive(Serialize, Deserialize, Type, Debug, Default, Clone)] pub struct ChargeSupportedFunctions { pub charge_level_set: bool, } +#[typeshare] #[derive(Serialize, Deserialize, Type, Debug, Default, Clone)] pub struct PlatformProfileFunctions { pub platform_profile: bool, pub fan_curves: bool, } +#[typeshare] #[derive(Serialize, Deserialize, Default, Type, Debug, Clone)] pub enum AdvancedAura { #[default] @@ -46,6 +52,7 @@ impl From for AdvancedAura { } } +#[typeshare] #[derive(Serialize, Deserialize, Type, Debug, Default, Clone)] pub struct LedSupportedFunctions { pub dev_id: AuraDevice, @@ -55,6 +62,7 @@ pub struct LedSupportedFunctions { pub advanced_type: AdvancedAura, } +#[typeshare] #[derive(Serialize, Deserialize, Type, Debug, Default, Clone)] pub struct RogBiosSupportedFunctions { pub post_sound: bool, diff --git a/rog-profiles/Cargo.toml b/rog-profiles/Cargo.toml index 0023850a..76a07e24 100644 --- a/rog-profiles/Cargo.toml +++ b/rog-profiles/Cargo.toml @@ -13,6 +13,7 @@ dbus = ["zbus"] udev.workspace = true serde.workspace = true serde_derive.workspace = true +typeshare.workspace = true zbus = { workspace = true, optional = true } diff --git a/rog-profiles/src/fan_curve_set.rs b/rog-profiles/src/fan_curve_set.rs index 8db6b651..b6069824 100644 --- a/rog-profiles/src/fan_curve_set.rs +++ b/rog-profiles/src/fan_curve_set.rs @@ -1,4 +1,5 @@ use serde_derive::{Deserialize, Serialize}; +use typeshare::typeshare; use udev::Device; #[cfg(feature = "dbus")] use zbus::zvariant::Type; @@ -26,6 +27,7 @@ pub(crate) fn temp_str(fan: char, index: usize) -> String { buf } +#[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] #[derive(Deserialize, Serialize, Default, Debug, Clone)] pub struct CurveData { @@ -195,6 +197,7 @@ impl CurveData { } /// A `FanCurveSet` contains both CPU and GPU fan curve data +#[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] #[derive(Deserialize, Serialize, Debug, Clone)] pub struct FanCurveSet { diff --git a/rog-profiles/src/lib.rs b/rog-profiles/src/lib.rs index df663c14..c23ccca7 100644 --- a/rog-profiles/src/lib.rs +++ b/rog-profiles/src/lib.rs @@ -9,6 +9,7 @@ use std::path::Path; use error::ProfileError; use fan_curve_set::{CurveData, FanCurveSet}; use serde_derive::{Deserialize, Serialize}; +use typeshare::typeshare; use udev::Device; #[cfg(feature = "dbus")] use zbus::zvariant::Type; @@ -35,7 +36,8 @@ pub fn find_fan_curve_node() -> Result, ProfileError> { Err(ProfileError::NotSupported) } -#[cfg_attr(feature = "dbus", derive(Type))] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] #[derive(Deserialize, Serialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] pub enum Profile { Balanced, @@ -127,7 +129,8 @@ impl Display for Profile { } } -#[cfg_attr(feature = "dbus", derive(Type))] +#[typeshare] +#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))] #[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone, Copy)] pub enum FanCurvePU { CPU, @@ -162,6 +165,7 @@ impl Default for FanCurvePU { } /// Main purpose of `FanCurves` is to enable restoring state on system boot +#[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] #[derive(Deserialize, Serialize, Debug, Default)] pub struct FanCurveProfiles {