From 4720af2cb8e46551c2083962ae9d6dfb1e0f3088 Mon Sep 17 00:00:00 2001 From: Luke Date: Tue, 2 Feb 2021 14:18:46 +1300 Subject: [PATCH] Migrate to use zbus for all dbus requirements --- CHANGELOG.md | 1 + Cargo.lock | 161 +--- asus-nb-ctrl/Cargo.lock | 1016 -------------------------- asus-nb-ctrl/Cargo.toml | 20 +- asus-nb-ctrl/src/config.rs | 4 +- asus-nb-ctrl/src/laptops.rs | 4 +- asus-nb-ctrl/src/main.rs | 53 +- asus-nb-ctrl/src/supported.rs | 2 +- asus-nb/Cargo.toml | 8 +- asus-nb/examples/animatrix.rs | 10 +- asus-nb/examples/ball.rs | 10 +- asus-nb/examples/comet.rs | 7 +- asus-nb/examples/iterate-keys.rs | 6 +- asus-nb/examples/per-key-effect-2.rs | 8 +- asus-nb/examples/pulser.rs | 6 +- asus-nb/src/anime_dbus.rs | 107 --- asus-nb/src/anime_matrix.rs | 3 + asus-nb/src/aura_modes.rs | 1 - asus-nb/src/core_dbus.rs | 512 ++++--------- asus-nb/src/dbus_anime.rs | 27 - asus-nb/src/dbus_charge.rs | 45 -- asus-nb/src/dbus_gfx.rs | 73 -- asus-nb/src/dbus_ledmode.rs | 67 -- asus-nb/src/dbus_profile.rs | 62 -- asus-nb/src/dbus_rogbios.rs | 86 --- asus-nb/src/dbus_supported.rs | 18 - asus-nb/src/lib.rs | 17 +- asus-nb/src/zbus_anime.rs | 75 ++ asus-nb/src/zbus_charge.rs | 73 ++ asus-nb/src/zbus_gfx.rs | 98 +++ asus-nb/src/zbus_led.rs | 142 ++++ asus-nb/src/zbus_profile.rs | 98 +++ asus-nb/src/zbus_rogbios.rs | 109 +++ asus-nb/src/zbus_supported.rs | 49 ++ asus-notify/Cargo.toml | 5 +- asus-notify/src/main.rs | 53 +- 36 files changed, 902 insertions(+), 2134 deletions(-) delete mode 100644 asus-nb-ctrl/Cargo.lock delete mode 100644 asus-nb/src/anime_dbus.rs delete mode 100644 asus-nb/src/dbus_anime.rs delete mode 100644 asus-nb/src/dbus_charge.rs delete mode 100644 asus-nb/src/dbus_gfx.rs delete mode 100644 asus-nb/src/dbus_ledmode.rs delete mode 100644 asus-nb/src/dbus_profile.rs delete mode 100644 asus-nb/src/dbus_rogbios.rs delete mode 100644 asus-nb/src/dbus_supported.rs create mode 100644 asus-nb/src/zbus_anime.rs create mode 100644 asus-nb/src/zbus_charge.rs create mode 100644 asus-nb/src/zbus_gfx.rs create mode 100644 asus-nb/src/zbus_led.rs create mode 100644 asus-nb/src/zbus_profile.rs create mode 100644 asus-nb/src/zbus_rogbios.rs create mode 100644 asus-nb/src/zbus_supported.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index d8ff2300..5cc78c2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Use same code path as 0x1866 device to configure led support - Remove duplicate code - Set correct speeds for multizone +- Remove dbus crate in favour of zbus. This removes the external dbus lib requirement. # [2.2.2] - 2021-01-31 ### Changed diff --git a/Cargo.lock b/Cargo.lock index 0159fedd..1ecff721 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,11 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "adler32" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" - [[package]] name = "aho-corasick" version = "0.7.15" @@ -31,7 +25,6 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" name = "asus-nb" version = "2.2.1" dependencies = [ - "dbus", "gumdrop", "rog_fan_curve", "serde", @@ -40,6 +33,7 @@ dependencies = [ "tinybmp", "yansi-term", "zbus", + "zbus_macros", "zvariant", ] @@ -58,7 +52,7 @@ dependencies = [ "serde_derive", "serde_json", "sysfs-class", - "toml 0.4.10", + "toml", "udev", "yansi-term", "zbus", @@ -71,11 +65,12 @@ version = "2.0.4" dependencies = [ "asus-nb", "asus-nb-ctrl", - "dbus", "notify-rust", "serde", "serde_derive", "serde_json", + "zbus", + "zvariant", ] [[package]] @@ -208,15 +203,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" -[[package]] -name = "crc32fast" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "crossbeam-utils" version = "0.8.1" @@ -228,16 +214,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "dbus" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cd9e78c210146a1860f897db03412fd5091fd73100778e43ee255cca252cf32" -dependencies = [ - "libc", - "libdbus-sys", -] - [[package]] name = "derivative" version = "2.2.0" @@ -283,9 +259,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.7.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e" dependencies = [ "atty", "humantime", @@ -317,18 +293,6 @@ dependencies = [ "instant", ] -[[package]] -name = "filetime" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall 0.2.4", - "winapi", -] - [[package]] name = "futures" version = "0.3.12" @@ -481,12 +445,9 @@ dependencies = [ [[package]] name = "humantime" -version = "1.3.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "instant" @@ -521,36 +482,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.82" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" - -[[package]] -name = "libdbus-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc12a3bc971424edbbf7edaf6e5740483444db63aa8e23d3751ff12a30f306f0" -dependencies = [ - "pkg-config", -] - -[[package]] -name = "libflate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389de7875e06476365974da3e7ff85d55f1972188ccd9f6020dd7c8156e17914" -dependencies = [ - "adler32", - "crc32fast", - "libflate_lz77", - "rle-decode-fast", -] - -[[package]] -name = "libflate_lz77" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3286f09f7d4926fc486334f28d8d2e6ebe4f7f9994494b6dab27ddfad2c9b11b" +checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff" [[package]] name = "libudev-sys" @@ -564,25 +498,23 @@ dependencies = [ [[package]] name = "libusb1-sys" -version = "0.4.4" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be241693102a24766d0b8526c8988771edac2842630d7e730f8e9fbc014f3703" +checksum = "e22e89d08bbe6816c6c5d446203b859eba35b8fa94bf1b7edb2f6d25d43f023f" dependencies = [ "cc", "libc", - "libflate", "pkg-config", - "tar", "vcpkg", ] [[package]] name = "log" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] [[package]] @@ -762,7 +694,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "toml 0.5.8", + "toml", ] [[package]] @@ -810,12 +742,6 @@ dependencies = [ "unicode-xid 0.2.1", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "0.3.15" @@ -837,15 +763,6 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" -[[package]] -name = "redox_syscall" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570" -dependencies = [ - "bitflags 1.2.1", -] - [[package]] name = "redox_users" version = "0.3.5" @@ -853,7 +770,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" dependencies = [ "getrandom", - "redox_syscall 0.1.57", + "redox_syscall", "rust-argon2", ] @@ -875,12 +792,6 @@ version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" -[[package]] -name = "rle-decode-fast" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac" - [[package]] name = "rog_fan_curve" version = "0.1.7" @@ -892,9 +803,9 @@ dependencies = [ [[package]] name = "rusb" -version = "0.6.5" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f32cd45962594f9f8cd4547b5757132715600e2c8840aa9ccd3d1a9ed6fdc6" +checksum = "c470dc7dc6e4710b6f85e9c4aa4650bc742260b39a36328180578db76fa258c1" dependencies = [ "libc", "libusb1-sys", @@ -1057,17 +968,6 @@ dependencies = [ "numtoa", ] -[[package]] -name = "tar" -version = "0.4.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0313546c01d59e29be4f09687bcb4fb6690cec931cc3607b6aec7a0e417f4cc6" -dependencies = [ - "filetime", - "libc", - "xattr", -] - [[package]] name = "termcolor" version = "1.1.2" @@ -1106,15 +1006,6 @@ dependencies = [ "nom", ] -[[package]] -name = "toml" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" -dependencies = [ - "serde", -] - [[package]] name = "toml" version = "0.5.8" @@ -1126,12 +1017,13 @@ dependencies = [ [[package]] name = "udev" -version = "0.4.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24953d50a3bce0f5f5a9a2766567072dc9af8096f8c40ea81815da651066bc9f" +checksum = "307c2b8c8a320a38365def5bb3ee92d146d405655196230f7a445fe4da6749f6" dependencies = [ "libc", "libudev-sys", + "pkg-config", ] [[package]] @@ -1250,15 +1142,6 @@ dependencies = [ "xml-rs", ] -[[package]] -name = "xattr" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" -dependencies = [ - "libc", -] - [[package]] name = "xml-rs" version = "0.6.1" diff --git a/asus-nb-ctrl/Cargo.lock b/asus-nb-ctrl/Cargo.lock deleted file mode 100644 index 6de19ede..00000000 --- a/asus-nb-ctrl/Cargo.lock +++ /dev/null @@ -1,1016 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "adler32" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" - -[[package]] -name = "aho-corasick" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" -dependencies = [ - "memchr", -] - -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi 0.3.8", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi 0.3.8", -] - -[[package]] -name = "bindgen" -version = "0.53.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb26d6a69a335b8cb0e7c7e9775cd5666611dc50a37177c3f2cedcfc040e8c8" -dependencies = [ - "bitflags", - "cexpr", - "cfg-if", - "clang-sys", - "clap", - "env_logger", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "which", -] - -[[package]] -name = "bit-set" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb" - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "bytes" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" - -[[package]] -name = "cc" -version = "1.0.52" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" - -[[package]] -name = "cexpr" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" -dependencies = [ - "nom", -] - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "clang-sys" -version = "0.29.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe6837df1d5cba2397b835c8530f51723267e16abbf83892e9e5af4f0e5dd10a" -dependencies = [ - "glob", - "libc", - "libloading", -] - -[[package]] -name = "clap" -version = "2.33.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim", - "textwrap", - "unicode-width", - "vec_map", -] - -[[package]] -name = "crc32fast" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "dbus" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f8875bb7afbc20dec12db09e18af3dcbd672b08592d2932950326a6437c616" -dependencies = [ - "futures", - "libc", - "libdbus-sys", -] - -[[package]] -name = "dbus-tokio" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "641f98f32585b8a8cc5d88c6c55a8f6cdf60740baab17c57d59b9b662c73f522" -dependencies = [ - "dbus", - "mio", - "tokio", -] - -[[package]] -name = "enumflags2" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c8d82922337cd23a15f88b70d8e4ef5f11da38dd7cdb55e84dd5de99695da0" -dependencies = [ - "enumflags2_derive", -] - -[[package]] -name = "enumflags2_derive" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "946ee94e3dbf58fdd324f9ce245c7b238d46a66f00e86a020b71996349e46cce" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - -[[package]] -name = "err-derive" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22deed3a8124cff5fa835713fa105621e43bbdc46690c3a6b68328a012d350d4" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "rustversion", - "syn", - "synstructure", -] - -[[package]] -name = "filetime" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f59efc38004c988e4201d11d263b8171f49a2e7ec0bdbb71773433f271504a5e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "winapi 0.3.8", -] - -[[package]] -name = "fnv" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - -[[package]] -name = "futures" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c329ae8753502fb44ae4fc2b622fa2a94652c41e795143765ba0927f92ab780" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a" - -[[package]] -name = "futures-executor" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6" - -[[package]] -name = "futures-macro" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6" - -[[package]] -name = "futures-task" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27" - -[[package]] -name = "futures-util" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-utils", - "proc-macro-hack", - "proc-macro-nested", - "slab", -] - -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - -[[package]] -name = "gumdrop" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46571f5d540478cf70d2a42dd0d6d8e9f4b9cc7531544b93311e657b86568a0b" -dependencies = [ - "gumdrop_derive", -] - -[[package]] -name = "gumdrop_derive" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915ef07c710d84733522461de2a734d4d62a3fd39a4d4f404c2f385ef8618d05" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "hermit-abi" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4" -dependencies = [ - "libc", -] - -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - -[[package]] -name = "intel-pstate" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0e7f68d8a6d149a5b2195ab645923c63ee35928fff58895b3c1d21541afe90c" -dependencies = [ - "err-derive", - "smart-default", -] - -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "lazycell" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" - -[[package]] -name = "libc" -version = "0.2.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005" - -[[package]] -name = "libdbus-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc12a3bc971424edbbf7edaf6e5740483444db63aa8e23d3751ff12a30f306f0" -dependencies = [ - "pkg-config", -] - -[[package]] -name = "libflate" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9135df43b1f5d0e333385cb6e7897ecd1a43d7d11b91ac003f4d2c2d2401fdd" -dependencies = [ - "adler32", - "crc32fast", - "rle-decode-fast", - "take_mut", -] - -[[package]] -name = "libloading" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" -dependencies = [ - "cc", - "winapi 0.3.8", -] - -[[package]] -name = "libusb1-sys" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0318f131edc8211a9a3e40133be6fc93f0b686e14f59c6115eab4e7bd794b34" -dependencies = [ - "cc", - "libc", - "libflate", - "pkg-config", - "tar", - "vcpkg", -] - -[[package]] -name = "log" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "memchr" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" - -[[package]] -name = "mio" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" -dependencies = [ - "cfg-if", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "miow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - -[[package]] -name = "net2" -version = "0.2.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" -dependencies = [ - "cfg-if", - "libc", - "winapi 0.3.8", -] - -[[package]] -name = "nom" -version = "5.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6" -dependencies = [ - "memchr", - "version_check", -] - -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - -[[package]] -name = "pin-project-lite" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkg-config" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" - -[[package]] -name = "proc-macro-error" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "syn-mid", - "version_check", -] - -[[package]] -name = "proc-macro-hack" -version = "0.5.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63" - -[[package]] -name = "proc-macro-nested" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694" - -[[package]] -name = "proc-macro2" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - -[[package]] -name = "quote" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.1.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" - -[[package]] -name = "regex" -version = "1.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", - "thread_local", -] - -[[package]] -name = "regex-syntax" -version = "0.6.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" - -[[package]] -name = "rle-decode-fast" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac" - -[[package]] -name = "rog-daemon" -version = "0.8.0" -dependencies = [ - "dbus", - "dbus-tokio", - "env_logger", - "gumdrop", - "intel-pstate", - "log", - "rusb", - "serde", - "serde_derive", - "thiserror", - "tokio", - "toml", - "uhid-virt", -] - -[[package]] -name = "rusb" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d10caa3e5fc7ad1879a679bf16d3304ea10614b8f2f1a1386be4ec942d44062a" -dependencies = [ - "bit-set", - "libc", - "libusb1-sys", -] - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustversion" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde" -version = "1.0.106" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399" - -[[package]] -name = "serde_derive" -version = "1.0.106" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "shlex" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" - -[[package]] -name = "slab" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" - -[[package]] -name = "smart-default" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - -[[package]] -name = "syn" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "syn-mid" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "synstructure" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", -] - -[[package]] -name = "take_mut" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" - -[[package]] -name = "tar" -version = "0.4.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3196bfbffbba3e57481b6ea32249fbaf590396a52505a2615adbb79d9d826d3" -dependencies = [ - "filetime", - "libc", - "redox_syscall", - "xattr", -] - -[[package]] -name = "termcolor" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "thiserror" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d12a1dae4add0f0d568eebc7bf142f145ba1aa2544cafb195c76f0f409091b60" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f34e0c1caaa462fd840ec6b768946ea1e7842620d94fe29d5b847138f521269" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "tokio" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d9c43f1bb96970e153bcbae39a65e249ccb942bd9d36dbdf086024920417c9c" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "lazy_static", - "mio", - "num_cpus", - "pin-project-lite", - "slab", - "tokio-macros", -] - -[[package]] -name = "tokio-macros" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "toml" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" -dependencies = [ - "serde", -] - -[[package]] -name = "uhid-virt" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057ecb2608f960fd97c220557339335bf7cef77ae77b71fb342d9555e396c00c" -dependencies = [ - "enumflags2", - "libc", - "uhidrs-sys", -] - -[[package]] -name = "uhidrs-sys" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78b2a68a0769dc3b501bcc9127f561220ff54b485b3dd9aa97718fda91dbdaa" -dependencies = [ - "bindgen", -] - -[[package]] -name = "unicode-width" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" - -[[package]] -name = "unicode-xid" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" - -[[package]] -name = "vcpkg" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" - -[[package]] -name = "vec_map" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" - -[[package]] -name = "version_check" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" - -[[package]] -name = "which" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" -dependencies = [ - "libc", -] - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - -[[package]] -name = "winapi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi 0.3.8", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - -[[package]] -name = "xattr" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" -dependencies = [ - "libc", -] diff --git a/asus-nb-ctrl/Cargo.toml b/asus-nb-ctrl/Cargo.toml index 70112542..7521d919 100644 --- a/asus-nb-ctrl/Cargo.toml +++ b/asus-nb-ctrl/Cargo.toml @@ -23,27 +23,27 @@ path = "src/daemon.rs" [dependencies] asus-nb = { path = "../asus-nb" } -rusb = "^0.6.0" -udev = "^0.4.0" +rusb = "^0.7" +udev = "^0.6" # cli and logging -gumdrop = "^0.8.0" -log = "^0.4.8" -env_logger = "^0.7.1" +gumdrop = "^0.8" +log = "^0.4" +env_logger = "^0.8" -zbus = "^1.8.0" -zvariant = "^2.4.0" +zbus = "^1.8" +zvariant = "^2.4" # serialisation serde = "^1.0" serde_derive = "^1.0" serde_json = "^1.0" -toml = "0.4.6" +toml = "^0.5" # Device control sysfs-class = "^0.1.2" # used for backlight control and baord ID -rog_fan_curve = { version = "0.1.5", features = ["serde"] } +rog_fan_curve = { version = "0.1", features = ["serde"] } # cpu power management -intel-pstate = "^0.2.1" +intel-pstate = "^0.2" yansi-term = "^0.1" \ No newline at end of file diff --git a/asus-nb-ctrl/src/config.rs b/asus-nb-ctrl/src/config.rs index dd4ef184..6ac4958c 100644 --- a/asus-nb-ctrl/src/config.rs +++ b/asus-nb-ctrl/src/config.rs @@ -14,15 +14,15 @@ pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf"; #[derive(Deserialize)] struct ConfigV212 { gfx_managed: bool, + bat_charge_limit: u8, active_profile: String, toggle_profiles: Vec, + power_profiles: BTreeMap, // TODO: remove power_profile power_profile: u8, - bat_charge_limit: u8, kbd_led_brightness: u8, kbd_backlight_mode: u8, kbd_backlight_modes: Vec, - power_profiles: BTreeMap, } impl ConfigV212 { diff --git a/asus-nb-ctrl/src/laptops.rs b/asus-nb-ctrl/src/laptops.rs index 3db6c56c..9f7da0eb 100644 --- a/asus-nb-ctrl/src/laptops.rs +++ b/asus-nb-ctrl/src/laptops.rs @@ -31,7 +31,9 @@ impl LaptopBase { pub fn match_laptop() -> Option { for device in rusb::devices().expect("Couldn't get device").iter() { - let device_desc = device.device_descriptor().expect("Couldn't get device descriptor"); + let device_desc = device + .device_descriptor() + .expect("Couldn't get device descriptor"); if device_desc.vendor_id() == 0x0b05 { if LAPTOP_DEVICES.contains(&device_desc.product_id()) { let prod_str = format!("{:x?}", device_desc.product_id()); diff --git a/asus-nb-ctrl/src/main.rs b/asus-nb-ctrl/src/main.rs index bcab3ca4..31380b4e 100644 --- a/asus-nb-ctrl/src/main.rs +++ b/asus-nb-ctrl/src/main.rs @@ -1,5 +1,4 @@ use asus_nb::{ - anime_dbus::AniMeDbusWriter, cli_options::{AniMeActions, AniMeStatusValue, LedBrightness, SetAuraBuiltin}, core_dbus::AuraDbusClient, profile::{ProfileCommand, ProfileEvent}, @@ -143,8 +142,7 @@ fn main() -> Result<(), Box> { println!("Version: {}", daemon::VERSION); } - let dbus_client = AuraDbusClient::new()?; - let anime_dbus_client = AniMeDbusWriter::new()?; + let (dbus, _) = AuraDbusClient::new()?; match parsed.command { Some(CliCommand::LedMode(mode)) => { @@ -159,11 +157,11 @@ fn main() -> Result<(), Box> { println!("Please specify either next or previous") } if mode.next_mode { - dbus_client.next_keyboard_led_mode()?; + dbus.proxies().led().next_led_mode()?; } else if mode.prev_mode { - dbus_client.prev_keyboard_led_mode()?; + dbus.proxies().led().prev_led_mode()?; } else if let Some(command) = mode.command { - dbus_client.write_builtin_mode(&command.into())? + dbus.proxies().led().set_led_mode(&command.into())? } } Some(CliCommand::Profile(cmd)) => { @@ -183,12 +181,14 @@ fn main() -> Result<(), Box> { } } if cmd.next { - dbus_client.next_fan_profile()?; + dbus.proxies().profile().next_fan()?; } else { - dbus_client.write_profile_command(&ProfileEvent::Cli(cmd))? + dbus.proxies() + .profile() + .write_command(&ProfileEvent::Cli(cmd))? } } - Some(CliCommand::Graphics(cmd)) => do_gfx(cmd, &dbus_client)?, + Some(CliCommand::Graphics(cmd)) => do_gfx(cmd, &dbus)?, Some(CliCommand::AniMe(cmd)) => { if (cmd.command.is_none() && cmd.boot.is_none() && cmd.turn.is_none()) || cmd.help { println!("Missing arg or command\n\n{}", cmd.self_usage()); @@ -197,16 +197,16 @@ fn main() -> Result<(), Box> { } } if let Some(anime_turn) = cmd.turn { - anime_dbus_client.turn_on_off(anime_turn.into())? + dbus.proxies().anime().toggle_on(anime_turn.into())? } if let Some(anime_boot) = cmd.boot { - anime_dbus_client.turn_boot_on_off(anime_boot.into())? + dbus.proxies().anime().toggle_boot_on(anime_boot.into())? } if let Some(action) = cmd.command { match action { AniMeActions::Leds(anime_leds) => { let led_brightness = anime_leds.led_brightness(); - anime_dbus_client.set_leds_brightness(led_brightness)?; + dbus.proxies().anime().set_brightness(led_brightness)?; } } } @@ -225,10 +225,10 @@ fn main() -> Result<(), Box> { } if let Some(opt) = cmd.post_sound_set { - dbus_client.set_bios_post_sound(opt)?; + dbus.proxies().rog_bios().set_post_sound(opt)?; } if cmd.post_sound_get { - let res = if dbus_client.get_bios_post_sound()? == 1 { + let res = if dbus.proxies().rog_bios().get_post_sound()? == 1 { true } else { false @@ -236,10 +236,10 @@ fn main() -> Result<(), Box> { println!("Bios POST sound on: {}", res); } if let Some(opt) = cmd.dedicated_gfx_set { - dbus_client.set_bios_dedicated_gfx(opt)?; + dbus.proxies().rog_bios().set_dedicated_gfx(opt)?; } if cmd.dedicated_gfx_get { - let res = if dbus_client.get_bios_dedicated_gfx()? == 1 { + let res = if dbus.proxies().rog_bios().get_dedicated_gfx()? == 1 { true } else { false @@ -264,23 +264,23 @@ fn main() -> Result<(), Box> { if let Some(brightness) = parsed.kbd_bright { match brightness.level() { None => { - let level = dbus_client.get_led_brightness()?; + let level = dbus.proxies().led().get_led_brightness()?; println!("Current keyboard led brightness: {}", level.to_string()); } - Some(level) => dbus_client.write_brightness(level)?, + Some(level) => dbus.proxies().led().set_brightness(level)?, } } if parsed.show_supported { - let dat = dbus_client.get_supported_functions()?; + let dat = dbus.proxies().supported().get_supported_functions()?; println!("Supported laptop functions:\n{}", dat.to_string()); } if let Some(fan_level) = parsed.fan_mode { - dbus_client.write_fan_mode(fan_level.into())?; + dbus.proxies().profile().write_fan_mode(fan_level.into())?; } if let Some(chg_limit) = parsed.chg_limit { - dbus_client.write_charge_limit(chg_limit)?; + dbus.proxies().charge().write_limit(chg_limit)?; } Ok(()) } @@ -293,8 +293,11 @@ fn do_gfx( println!("Updating settings, please wait..."); println!("If this takes longer than 30s, ctrl+c then check `journalctl -b -u asusd`"); - dbus_client.write_gfx_mode(<&str>::from(&mode).into())?; - let res = dbus_client.wait_gfx_changed()?; + dbus_client + .proxies() + .gfx() + .gfx_write_mode(<&str>::from(&mode).into())?; + let res = dbus_client.gfx_wait_changed()?; match res.as_str() { "reboot" => { println!( @@ -331,11 +334,11 @@ fn do_gfx( std::process::exit(-1) } if command.get { - let res = dbus_client.get_gfx_mode()?; + let res = dbus_client.proxies().gfx().gfx_get_mode()?; println!("Current graphics mode: {}", res); } if command.pow { - let res = dbus_client.get_gfx_pwr()?; + let res = dbus_client.proxies().gfx().gfx_get_pwr()?; if res.contains("active") { println!("Current power status: {}", Red.paint(&format!("{}", res))); } else { diff --git a/asus-nb-ctrl/src/supported.rs b/asus-nb-ctrl/src/supported.rs index 9f2b6601..cee559c2 100644 --- a/asus-nb-ctrl/src/supported.rs +++ b/asus-nb-ctrl/src/supported.rs @@ -22,7 +22,7 @@ pub struct SupportedFunctions { rog_bios_ctrl: RogBiosSupportedFunctions, } -#[dbus_interface(name = "org.asuslinux.Daemon")] +#[dbus_interface(name = "org.asuslinux.Supported")] impl SupportedFunctions { fn supported_functions(&self) -> String { serde_json::to_string_pretty(self).unwrap() diff --git a/asus-nb/Cargo.toml b/asus-nb/Cargo.toml index eb4462e3..cc66ac0c 100644 --- a/asus-nb/Cargo.toml +++ b/asus-nb/Cargo.toml @@ -11,14 +11,14 @@ edition = "2018" [dependencies] gumdrop = "^0.8" -dbus = { version = "^0.8" } serde = "^1.0" serde_derive = "^1.0" serde_json = "^1.0" yansi-term = "^0.1" -rog_fan_curve = { version = "0.1", features = ["serde"] } -zbus = "^1.8.0" -zvariant = "^2.4.0" +rog_fan_curve = { version = "^0.1", features = ["serde"] } +zbus = "^1.8" +zbus_macros = "^1.8" +zvariant = "^2.4" [dev-dependencies] tinybmp = "^0.2.3" \ No newline at end of file diff --git a/asus-nb/examples/animatrix.rs b/asus-nb/examples/animatrix.rs index 26f5d651..ccb53400 100644 --- a/asus-nb/examples/animatrix.rs +++ b/asus-nb/examples/animatrix.rs @@ -1,9 +1,11 @@ -use asus_nb::anime_dbus::AniMeDbusWriter; -use asus_nb::anime_matrix::{AniMeMatrix, AniMePacketType, HEIGHT, WIDTH}; +use asus_nb::{ + anime_matrix::{AniMeMatrix, AniMePacketType, HEIGHT, WIDTH}, + core_dbus::AuraDbusClient, +}; use tinybmp::{Bmp, Pixel}; fn main() { - let mut writer = AniMeDbusWriter::new().unwrap(); + let mut writer = AuraDbusClient::new().unwrap(); let bmp = Bmp::from_slice(include_bytes!("non-skewed_r.bmp")).expect("Failed to parse BMP image"); @@ -38,5 +40,5 @@ fn main() { // println!("{:?}", matrix[0].to_vec()); // println!("{:?}", matrix[1].to_vec()); - writer.write_image(&mut matrix).unwrap(); + //writer.set_anime_led_brightness(&mut matrix).unwrap(); } diff --git a/asus-nb/examples/ball.rs b/asus-nb/examples/ball.rs index 88cf8af9..b662dd09 100644 --- a/asus-nb/examples/ball.rs +++ b/asus-nb/examples/ball.rs @@ -54,7 +54,7 @@ impl Ball { } fn main() -> Result<(), Box> { - let mut writer = AuraDbusClient::new()?; + let (dbus, _) = AuraDbusClient::new()?; let mut colours = KeyColourArray::new(); @@ -62,7 +62,7 @@ fn main() -> Result<(), Box> { let mut balls = [Ball::new(2, 1, 12), Ball::new(4, 6, 12)]; - writer.init_effect()?; + dbus.proxies().led().init_effect()?; let rows = layout.get_rows(); loop { @@ -89,10 +89,8 @@ fn main() -> Result<(), Box> { *c.2 = 255; }; } + dbus.proxies().led().set_per_key(&colours)?; - writer.write_colour_block(&colours)?; - - // can change 100 times per second, so need to slow it down - std::thread::sleep(std::time::Duration::from_millis(30)); + std::thread::sleep(std::time::Duration::from_millis(10)); } } diff --git a/asus-nb/examples/comet.rs b/asus-nb/examples/comet.rs index 8fbc4c08..38171022 100644 --- a/asus-nb/examples/comet.rs +++ b/asus-nb/examples/comet.rs @@ -4,11 +4,11 @@ use asus_nb::{ }; fn main() -> Result<(), Box> { - let mut writer = AuraDbusClient::new()?; + let (dbus, _) = AuraDbusClient::new()?; let layout = GX502Layout::default(); - writer.init_effect()?; + dbus.proxies().led().init_effect()?; let rows = layout.get_rows(); let mut column = 0; @@ -25,7 +25,6 @@ fn main() -> Result<(), Box> { column += 1; } - writer.write_colour_block(&key_colours)?; - std::thread::sleep(std::time::Duration::from_millis(30)); + dbus.proxies().led().set_per_key(&key_colours)?; } } diff --git a/asus-nb/examples/iterate-keys.rs b/asus-nb/examples/iterate-keys.rs index 92917986..65fa8b3d 100644 --- a/asus-nb/examples/iterate-keys.rs +++ b/asus-nb/examples/iterate-keys.rs @@ -4,12 +4,12 @@ use asus_nb::{ }; fn main() -> Result<(), Box> { - let mut writer = AuraDbusClient::new()?; + let (dbus, _) = AuraDbusClient::new()?; let mut key_colours = KeyColourArray::new(); let layout = GX502Layout::default(); - writer.init_effect()?; + dbus.proxies().led().init_effect()?; let rows = layout.get_rows(); loop { for (r, row) in rows.iter().enumerate() { @@ -48,7 +48,7 @@ fn main() -> Result<(), Box> { *key_colours.key(Key::S).unwrap().0 = 255; *key_colours.key(Key::D).unwrap().0 = 255; - writer.write_colour_block(&key_colours)?; + dbus.proxies().led().set_per_key(&key_colours)?; std::thread::sleep(std::time::Duration::from_millis(100)); } } diff --git a/asus-nb/examples/per-key-effect-2.rs b/asus-nb/examples/per-key-effect-2.rs index 1c5e2051..b2ce5664 100644 --- a/asus-nb/examples/per-key-effect-2.rs +++ b/asus-nb/examples/per-key-effect-2.rs @@ -4,11 +4,11 @@ use asus_nb::{ }; fn main() -> Result<(), Box> { - let mut writer = AuraDbusClient::new()?; + let (dbus, _) = AuraDbusClient::new()?; let mut key_colours = KeyColourArray::new(); - writer.init_effect()?; + dbus.proxies().led().init_effect()?; loop { let count = 49; for _ in 0..count { @@ -18,7 +18,7 @@ fn main() -> Result<(), Box> { *key_colours.key(Key::N).unwrap().0 += 5; *key_colours.key(Key::U).unwrap().0 += 5; *key_colours.key(Key::X).unwrap().0 += 5; - writer.write_colour_block(&key_colours)?; + dbus.proxies().led().set_per_key(&key_colours)?; } for _ in 0..count { *key_colours.key(Key::ROG).unwrap().0 -= 5; @@ -27,7 +27,7 @@ fn main() -> Result<(), Box> { *key_colours.key(Key::N).unwrap().0 -= 5; *key_colours.key(Key::U).unwrap().0 -= 5; *key_colours.key(Key::X).unwrap().0 -= 5; - writer.write_colour_block(&key_colours)?; + dbus.proxies().led().set_per_key(&key_colours)?; } } } diff --git a/asus-nb/examples/pulser.rs b/asus-nb/examples/pulser.rs index 4353d78d..ff7be201 100644 --- a/asus-nb/examples/pulser.rs +++ b/asus-nb/examples/pulser.rs @@ -4,12 +4,12 @@ use asus_nb::{ }; fn main() -> Result<(), Box> { - let mut writer = AuraDbusClient::new()?; + let (dbus, _) = AuraDbusClient::new()?; let mut key_colours = KeyColourArray::new(); let layout = GX502Layout::default(); - writer.init_effect()?; + dbus.proxies().led().init_effect()?; let rows = layout.get_rows(); let mut fade = 50; @@ -23,7 +23,7 @@ fn main() -> Result<(), Box> { } } - writer.write_colour_block(&key_colours)?; + dbus.proxies().led().set_per_key(&key_colours)?; if flip { if fade > 1 { diff --git a/asus-nb/src/anime_dbus.rs b/asus-nb/src/anime_dbus.rs deleted file mode 100644 index 66eb2975..00000000 --- a/asus-nb/src/anime_dbus.rs +++ /dev/null @@ -1,107 +0,0 @@ -const DBUS_ANIME_PATH: &str = "/org/asuslinux/Anime"; -pub const ANIME_PANE1_PREFIX: [u8; 7] = [0x5e, 0xc0, 0x02, 0x01, 0x00, 0x73, 0x02]; -pub const ANIME_PANE2_PREFIX: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02]; - -use crate::anime_matrix::{AniMeMatrix, AniMePacketType}; -use crate::DBUS_NAME; -use dbus::blocking::{Connection, Proxy}; -use std::error::Error; -use std::{thread, time::Duration}; - -use crate::dbus_anime::OrgAsuslinuxDaemon as OrgAsuslinuxDaemonAniMe; - -/// Interface for the AniMe dot-matrix display -/// -/// The resolution is 34x56 (1904) but only 1,215 LEDs in the top-left are used. -/// The display is available only on select GA401 models. -/// -/// Actual image ratio when displayed is stretched width. -/// -/// Data structure should be nested array of [[u8; 33]; 56] -pub struct AniMeDbusWriter { - connection: Box, - block_time: u64, -} - -impl AniMeDbusWriter { - #[inline] - pub fn new() -> Result> { - let connection = Connection::new_system()?; - Ok(AniMeDbusWriter { - connection: Box::new(connection), - block_time: 25, - }) - } - - // Create D-Bus proxy - fn new_proxy(&self) -> Proxy<&Connection> { - self.connection - .with_proxy(DBUS_NAME, DBUS_ANIME_PATH, Duration::from_millis(200)) - } - - fn thread_sleep(&self) { - thread::sleep(Duration::from_millis(self.block_time)); - } - - pub fn write_image_to_buf(_buf: &mut AniMePacketType, _image_data: &[u8]) { - unimplemented!("Image format is in progress of being worked out") - } - - /// Write an Animatrix image - /// - /// The expected input here is *two* Vectors, 640 bytes in length. - /// The two vectors are each one half of the full image write. - /// - /// After each write a flush is written, it is assumed that this tells the - /// device to go ahead and display the written bytes - /// - /// # Note: The vectors are expected to contain the full sequence of bytes - /// as follows - /// - /// - Write packet 1: 0x5e 0xc0 0x02 0x01 0x00 0x73 0x02 .. - /// - Write packet 2: 0x5e 0xc0 0x02 0x74 0x02 0x73 0x02 .. - /// - /// Where led brightness is 0..255, low to high - #[inline] - pub fn write_image(&self, image: &mut AniMePacketType) -> Result<(), Box> { - let proxy = self.new_proxy(); - - image[0][..7].copy_from_slice(&ANIME_PANE1_PREFIX); - image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX); - - proxy.set_anime(vec![image[0].to_vec(), image[1].to_vec()])?; - self.thread_sleep(); - - Ok(()) - } - - #[inline] - pub fn set_leds_brightness(&self, led_brightness: u8) -> Result<(), Box> { - let mut anime_matrix = AniMeMatrix::new(); - - anime_matrix.fill_with(led_brightness); - self.write_image(&mut AniMePacketType::from(anime_matrix))?; - - Ok(()) - } - - #[inline] - pub fn turn_on_off(&self, status: bool) -> Result<(), Box> { - let proxy = self.new_proxy(); - - proxy.set_on_off(status)?; - self.thread_sleep(); - - Ok(()) - } - - #[inline] - pub fn turn_boot_on_off(&self, status: bool) -> Result<(), Box> { - let proxy = self.new_proxy(); - - proxy.set_boot_on_off(status)?; - self.thread_sleep(); - - Ok(()) - } -} diff --git a/asus-nb/src/anime_matrix.rs b/asus-nb/src/anime_matrix.rs index f2a43ce8..ebc438d1 100644 --- a/asus-nb/src/anime_matrix.rs +++ b/asus-nb/src/anime_matrix.rs @@ -6,6 +6,9 @@ const BLOCK_START: usize = 7; const BLOCK_END: usize = 634; use yansi_term::Colour::RGB; +pub const ANIME_PANE1_PREFIX: [u8; 7] = [0x5e, 0xc0, 0x02, 0x01, 0x00, 0x73, 0x02]; +pub const ANIME_PANE2_PREFIX: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02]; + /// Helper structure for writing images. /// /// See the examples for ways to write an image to `AniMeMatrix` format. diff --git a/asus-nb/src/aura_modes.rs b/asus-nb/src/aura_modes.rs index 6bfb5f9a..f2757439 100644 --- a/asus-nb/src/aura_modes.rs +++ b/asus-nb/src/aura_modes.rs @@ -199,7 +199,6 @@ pub enum AuraModes { MultiBreathe(MultiColourSpeed), LedBrightness(u8), // TODO: use a serializable structure for this (KeyColourArray) - #[serde(skip)] PerKey(Vec>), } diff --git a/asus-nb/src/core_dbus.rs b/asus-nb/src/core_dbus.rs index a81e12ee..c6c22056 100644 --- a/asus-nb/src/core_dbus.rs +++ b/asus-nb/src/core_dbus.rs @@ -1,418 +1,154 @@ use super::*; -use crate::cli_options::LedBrightness; -use crate::fancy::KeyColourArray; -use crate::profile::ProfileEvent; -use dbus::{blocking::Connection, Message}; -use std::error::Error; -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, Mutex, -}; -use std::{thread, time::Duration}; +use std::sync::{Arc, Mutex}; +use zbus::{Connection, Result, SignalReceiver}; -use crate::dbus_charge::{ - OrgAsuslinuxDaemon as OrgAsuslinuxDaemonCharge, OrgAsuslinuxDaemonNotifyCharge, -}; -use crate::dbus_gfx::{ - OrgAsuslinuxDaemon as OrgAsuslinuxDaemonGfx, OrgAsuslinuxDaemonNotifyAction, - OrgAsuslinuxDaemonNotifyGfx, -}; -use crate::dbus_ledmode::{ - OrgAsuslinuxDaemon as OrgAsuslinuxDaemonLed, OrgAsuslinuxDaemonNotifyLed, -}; -use crate::dbus_profile::{ - OrgAsuslinuxDaemon as OrgAsuslinuxDaemonProfile, OrgAsuslinuxDaemonNotifyProfile, -}; -use crate::dbus_rogbios::OrgAsuslinuxDaemon as OrgAsuslinuxDaemonRogBios; -use crate::dbus_supported::OrgAsuslinuxDaemon as OrgAsuslinuxDaemonSupported; +pub struct DbusProxies<'a> { + anime: zbus_anime::AnimeProxy<'a>, + charge: zbus_charge::ChargeProxy<'a>, + gfx: zbus_gfx::GfxProxy<'a>, + led: zbus_led::LedProxy<'a>, + profile: zbus_profile::ProfileProxy<'a>, + rog_bios: zbus_rogbios::RogBiosProxy<'a>, + supported: zbus_supported::SupportProxy<'a>, +} + +impl<'a> DbusProxies<'a> { + #[inline] + pub fn new() -> Result<(Self, Connection)> { + let conn = Connection::new_system()?; + + Ok(( + DbusProxies { + anime: zbus_anime::AnimeProxy::new(&conn)?, + led: zbus_led::LedProxy::new(&conn)?, + charge: zbus_charge::ChargeProxy::new(&conn)?, + gfx: zbus_gfx::GfxProxy::new(&conn)?, + profile: zbus_profile::ProfileProxy::new(&conn)?, + rog_bios: zbus_rogbios::RogBiosProxy::new(&conn)?, + supported: zbus_supported::SupportProxy::new(&conn)?, + }, + conn, + )) + } + + pub fn setup_recv(&'a self, conn: Connection) -> SignalReceiver { + let mut recv = SignalReceiver::new(conn); + //recv.receive_for(&self.proxy_anime); + recv.receive_for(self.led.proxy()); + recv.receive_for(self.charge.proxy()); + recv.receive_for(self.gfx.proxy()); + recv.receive_for(self.profile.proxy()); + recv + } + + pub fn anime(&self) -> &zbus_anime::AnimeProxy<'a> { + &self.anime + } + + pub fn charge(&self) -> &zbus_charge::ChargeProxy<'a> { + &self.charge + } + + pub fn gfx(&self) -> &zbus_gfx::GfxProxy<'a> { + &self.gfx + } + + pub fn led(&self) -> &zbus_led::LedProxy<'a> { + &self.led + } + + pub fn profile(&self) -> &zbus_profile::ProfileProxy<'a> { + &self.profile + } + + pub fn rog_bios(&self) -> &zbus_rogbios::RogBiosProxy<'a> { + &self.rog_bios + } + + pub fn supported(&self) -> &zbus_supported::SupportProxy<'a> { + &self.supported + } +} // Signals separated out -pub struct CtrlSignals { - pub gfx_vendor_signal: Arc>>, - pub gfx_action_signal: Arc>>, - pub profile_signal: Arc>>, - pub ledmode_signal: Arc>>, - pub charge_signal: Arc>>, +pub struct Signals { + pub gfx_vendor: Arc>>, + pub gfx_action: Arc>>, + pub profile: Arc>>, + pub led_mode: Arc>>, + pub charge: Arc>>, } -impl CtrlSignals { +impl Signals { #[inline] - pub fn new(connection: &Connection) -> Result> { - let proxy = connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Gfx", - Duration::from_secs(2), - ); + pub fn new(proxies: &DbusProxies) -> Result { + // + let charge_signal = Arc::new(Mutex::new(None)); + proxies + .charge + .connect_notify_charge(charge_signal.clone())?; - let gfx_vendor_signal = Arc::new(Mutex::new(None)); - let gfx_res1 = gfx_vendor_signal.clone(); - - let _x = proxy.match_signal( - move |sig: OrgAsuslinuxDaemonNotifyGfx, _: &Connection, _: &Message| { - if let Ok(mut lock) = gfx_res1.lock() { - *lock = Some(sig.vendor); - } - true - }, - )?; + // + let ledmode_signal = Arc::new(Mutex::new(None)); + proxies.led.connect_notify_led(ledmode_signal.clone())?; let gfx_action_signal = Arc::new(Mutex::new(None)); - let gfx_res1 = gfx_action_signal.clone(); + proxies + .gfx + .connect_notify_action(gfx_action_signal.clone())?; - let _x = proxy.match_signal( - move |sig: OrgAsuslinuxDaemonNotifyAction, _: &Connection, _: &Message| { - if let Ok(mut lock) = gfx_res1.lock() { - *lock = Some(sig.action); - } - true - }, - )?; - - // - let proxy = connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Profile", - Duration::from_secs(2), - ); + let gfx_vendor_signal = Arc::new(Mutex::new(None)); + proxies.gfx.connect_notify_gfx(gfx_vendor_signal.clone())?; let profile_signal = Arc::new(Mutex::new(None)); - let prof_res1 = profile_signal.clone(); + proxies + .profile + .connect_notify_profile(profile_signal.clone())?; - let _x = proxy.match_signal( - move |sig: OrgAsuslinuxDaemonNotifyProfile, _: &Connection, _: &Message| { - if let Ok(mut lock) = prof_res1.lock() { - *lock = Some(sig.profile); - } - true - }, - )?; - - // - let proxy = connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Led", - Duration::from_secs(2), - ); - - let ledmode_signal = Arc::new(Mutex::new(None)); - let led_res1 = ledmode_signal.clone(); - - let _x = proxy.match_signal( - move |sig: OrgAsuslinuxDaemonNotifyLed, _: &Connection, _: &Message| { - if let Ok(mut lock) = led_res1.lock() { - if let Ok(dat) = serde_json::from_str(&sig.data) { - *lock = Some(dat); - } - } - true - }, - )?; - - // - let proxy = connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Charge", - Duration::from_secs(2), - ); - - let charge_signal = Arc::new(Mutex::new(None)); - let charge_res1 = charge_signal.clone(); - - let _x = proxy.match_signal( - move |sig: OrgAsuslinuxDaemonNotifyCharge, _: &Connection, _: &Message| { - if let Ok(mut lock) = charge_res1.lock() { - *lock = Some(sig.limit); - } - true - }, - )?; - - Ok(CtrlSignals { - gfx_vendor_signal, - gfx_action_signal, - profile_signal, - ledmode_signal, - charge_signal, + Ok(Signals { + gfx_vendor: gfx_vendor_signal, + gfx_action: gfx_action_signal, + profile: profile_signal, + led_mode: ledmode_signal, + charge: charge_signal, }) } } -/// Simplified way to write a effect block -pub struct AuraDbusClient { - connection: Box, - block_time: u64, - stop: Arc, - signals: CtrlSignals, +/// This is the main way to communicate with the DBUS interface +pub struct AuraDbusClient<'a> { + proxies: DbusProxies<'a>, + signals: Signals, } -impl AuraDbusClient { +impl<'a> AuraDbusClient<'a> { #[inline] - pub fn new() -> Result> { - let connection = Connection::new_system()?; + pub fn new() -> Result<(Self, Connection)> { + let (proxies, conn) = DbusProxies::new()?; + let signals = Signals::new(&proxies)?; - let stop = Arc::new(AtomicBool::new(false)); - let match_rule = dbus::message::MatchRule::new_signal(DBUS_IFACE, "NotifyLed"); - let stop1 = stop.clone(); - connection.add_match(match_rule, move |_: (), _, msg| { - if msg.read1::<&str>().is_ok() { - stop1.clone().store(true, Ordering::Relaxed); - } - true - })?; - - let signals = CtrlSignals::new(&connection)?; - - Ok(AuraDbusClient { - connection: Box::new(connection), - block_time: 33333, - stop, - signals, - }) + Ok((AuraDbusClient { proxies, signals }, conn)) } - pub fn wait_gfx_changed(&self) -> Result> { + pub fn proxies(&self) -> &DbusProxies { + &self.proxies + } + + /* + * GFX + */ + pub fn gfx_wait_changed(&self) -> Result { loop { - self.connection.process(Duration::from_millis(1))?; - if let Ok(lock) = self.signals.gfx_action_signal.lock() { - if let Some(stuff) = lock.as_ref() { - return Ok(stuff.to_string()); + if let Ok(res) = self.proxies.gfx.proxy().next_signal() { + if res.is_none() { + if let Ok(lock) = self.signals.gfx_action.lock() { + if let Some(stuff) = lock.as_ref() { + return Ok(stuff.to_string()); + } + } + // return Ok("Failed for unknown reason".to_owned()); } } } } - - /// This method must always be called before the very first write to initialise - /// the keyboard LED EC in the correct mode - #[inline] - pub fn init_effect(&self) -> Result<(), Box> { - let mode = AuraModes::PerKey(vec![vec![]]); - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Led", - Duration::from_secs(2), - ); - proxy.set_led_mode(&serde_json::to_string(&mode)?)?; - Ok(()) - } - - /// Write a single colour block. - /// - /// Intentionally blocks for 10ms after sending to allow the block to - /// be written to the keyboard EC. This should not be async. - #[inline] - pub fn write_colour_block( - &mut self, - key_colour_array: &KeyColourArray, - ) -> Result<(), Box> { - let group = key_colour_array.get(); - let mut vecs = Vec::with_capacity(group.len()); - for v in group { - vecs.push(v.to_vec()); - } - let mode = AuraModes::PerKey(vecs); - - self.write_keyboard_leds(&mode)?; - - thread::sleep(Duration::from_micros(self.block_time)); - self.connection.process(Duration::from_micros(500))?; - - if self.stop.load(Ordering::Relaxed) { - println!("Keyboard backlight was changed, exiting"); - std::process::exit(1) - } - Ok(()) - } - - #[inline] - pub fn write_keyboard_leds(&self, mode: &AuraModes) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Led", - Duration::from_secs(2), - ); - proxy.set_led_mode(&serde_json::to_string(mode)?)?; - Ok(()) - } - - #[inline] - pub fn next_keyboard_led_mode(&self) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Led", - Duration::from_secs(2), - ); - proxy.next_led_mode()?; - Ok(()) - } - - #[inline] - pub fn prev_keyboard_led_mode(&self) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Led", - Duration::from_secs(2), - ); - proxy.prev_led_mode()?; - Ok(()) - } - - #[inline] - pub fn get_gfx_pwr(&self) -> Result> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Gfx", - Duration::from_secs(2), - ); - let x = proxy.power()?; - Ok(x) - } - - #[inline] - pub fn get_gfx_mode(&self) -> Result> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Gfx", - Duration::from_secs(2), - ); - let x = proxy.vendor()?; - Ok(x) - } - - #[inline] - pub fn write_gfx_mode(&self, vendor: String) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Gfx", - Duration::from_secs(30), - ); - proxy.set_vendor(&vendor)?; - Ok(()) - } - - #[inline] - pub fn next_fan_profile(&self) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Profile", - Duration::from_secs(2), - ); - proxy.next_profile()?; - Ok(()) - } - - #[inline] - pub fn write_fan_mode(&self, level: u8) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Profile", - Duration::from_secs(2), - ); - proxy.set_profile(&serde_json::to_string(&ProfileEvent::ChangeMode(level))?)?; - Ok(()) - } - - #[inline] - pub fn write_profile_command( - &self, - cmd: &ProfileEvent, - ) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Profile", - Duration::from_secs(2), - ); - proxy.set_profile(&serde_json::to_string(cmd)?)?; - Ok(()) - } - - #[inline] - pub fn write_charge_limit(&self, level: u8) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Charge", - Duration::from_secs(2), - ); - proxy.set_limit(level)?; - Ok(()) - } - - #[inline] - pub fn write_builtin_mode(&self, mode: &AuraModes) -> Result<(), Box> { - self.write_keyboard_leds(mode) - } - - #[inline] - pub fn get_led_brightness(&self) -> Result> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Led", - Duration::from_secs(2), - ); - match proxy.led_brightness()? { - -1 => Ok(LedBrightness::new(None)), - level => Ok(LedBrightness::new(Some(level as u8))), - } - } - - #[inline] - pub fn write_brightness(&self, level: u8) -> Result<(), Box> { - self.write_keyboard_leds(&AuraModes::LedBrightness(level))?; - Ok(()) - } - - // - #[inline] - pub fn get_bios_dedicated_gfx(&self) -> Result> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/RogBios", - Duration::from_secs(2), - ); - let x = proxy.dedicated_graphic_mode()?; - Ok(x) - } - - #[inline] - pub fn set_bios_dedicated_gfx(&self, on: bool) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/RogBios", - Duration::from_secs(2), - ); - proxy.set_dedicated_graphic_mode(::from(on))?; - Ok(()) - } - - #[inline] - pub fn get_bios_post_sound(&self) -> Result> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/RogBios", - Duration::from_secs(2), - ); - let x = proxy.post_boot_sound()?; - Ok(x) - } - - #[inline] - pub fn set_bios_post_sound(&self, on: bool) -> Result<(), Box> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/RogBios", - Duration::from_secs(2), - ); - proxy.set_post_boot_sound(::from(on))?; - Ok(()) - } - - #[inline] - pub fn get_supported_functions(&self) -> Result> { - let proxy = self.connection.with_proxy( - "org.asuslinux.Daemon", - "/org/asuslinux/Supported", - Duration::from_secs(2), - ); - let x = proxy.supported_functions()?; - Ok(x) - } } diff --git a/asus-nb/src/dbus_anime.rs b/asus-nb/src/dbus_anime.rs deleted file mode 100644 index 75b1993d..00000000 --- a/asus-nb/src/dbus_anime.rs +++ /dev/null @@ -1,27 +0,0 @@ -// This code was autogenerated with `dbus-codegen-rust -s -d org.asuslinux.Daemon -p /org/asuslinux/Anime -m None -f org.asuslinux.Daemon -c blocking`, see https://github.com/diwic/dbus-rs -use dbus; -#[allow(unused_imports)] -use dbus::arg; -use dbus::blocking; - -pub trait OrgAsuslinuxDaemon { - fn set_anime(&self, input: Vec>) -> Result<(), dbus::Error>; - fn set_on_off(&self, status: bool) -> Result<(), dbus::Error>; - fn set_boot_on_off(&self, status: bool) -> Result<(), dbus::Error>; -} - -impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgAsuslinuxDaemon - for blocking::Proxy<'a, C> -{ - fn set_anime(&self, input: Vec>) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "SetAnime", (input,)) - } - - fn set_on_off(&self, status: bool) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "SetOnOff", (status,)) - } - - fn set_boot_on_off(&self, status: bool) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "SetBootOnOff", (status,)) - } -} diff --git a/asus-nb/src/dbus_charge.rs b/asus-nb/src/dbus_charge.rs deleted file mode 100644 index ee275353..00000000 --- a/asus-nb/src/dbus_charge.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This code was autogenerated with `dbus-codegen-rust -s -d org.asuslinux.Daemon -f org.asuslinux.Daemon -c blocking -p /org/asuslinux/Charge -m None`, see https://github.com/diwic/dbus-rs -use dbus; -#[allow(unused_imports)] -use dbus::arg; -use dbus::blocking; - -pub trait OrgAsuslinuxDaemon { - fn set_limit(&self, limit: u8) -> Result<(), dbus::Error>; - fn limit(&self) -> Result; -} - -impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgAsuslinuxDaemon - for blocking::Proxy<'a, C> -{ - fn set_limit(&self, limit: u8) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "SetLimit", (limit,)) - } - - fn limit(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "Limit", ()) - .and_then(|r: (i16,)| Ok(r.0)) - } -} - -#[derive(Debug)] -pub struct OrgAsuslinuxDaemonNotifyCharge { - pub limit: u8, -} - -impl arg::AppendAll for OrgAsuslinuxDaemonNotifyCharge { - fn append(&self, i: &mut arg::IterAppend) { - arg::RefArg::append(&self.limit, i); - } -} - -impl arg::ReadAll for OrgAsuslinuxDaemonNotifyCharge { - fn read(i: &mut arg::Iter) -> Result { - Ok(OrgAsuslinuxDaemonNotifyCharge { limit: i.read()? }) - } -} - -impl dbus::message::SignalArgs for OrgAsuslinuxDaemonNotifyCharge { - const NAME: &'static str = "NotifyCharge"; - const INTERFACE: &'static str = "org.asuslinux.Daemon"; -} diff --git a/asus-nb/src/dbus_gfx.rs b/asus-nb/src/dbus_gfx.rs deleted file mode 100644 index 2d66f971..00000000 --- a/asus-nb/src/dbus_gfx.rs +++ /dev/null @@ -1,73 +0,0 @@ -// This code was autogenerated with `dbus-codegen-rust -s -d org.asuslinux.Daemon -p /org/asuslinux/Gfx -m None -f org.asuslinux.Daemon -c blocking`, see https://github.com/diwic/dbus-rs -use dbus; -#[allow(unused_imports)] -use dbus::arg; -use dbus::blocking; - -pub trait OrgAsuslinuxDaemon { - fn vendor(&self) -> Result; - fn power(&self) -> Result; - fn set_vendor(&self, vendor: &str) -> Result<(), dbus::Error>; -} - -impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgAsuslinuxDaemon - for blocking::Proxy<'a, C> -{ - fn vendor(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "Vendor", ()) - .and_then(|r: (String,)| Ok(r.0)) - } - - fn power(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "Power", ()) - .and_then(|r: (String,)| Ok(r.0)) - } - - fn set_vendor(&self, vendor: &str) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "SetVendor", (vendor,)) - } -} - -#[derive(Debug)] -pub struct OrgAsuslinuxDaemonNotifyGfx { - pub vendor: String, -} - -impl arg::AppendAll for OrgAsuslinuxDaemonNotifyGfx { - fn append(&self, i: &mut arg::IterAppend) { - arg::RefArg::append(&self.vendor, i); - } -} - -impl arg::ReadAll for OrgAsuslinuxDaemonNotifyGfx { - fn read(i: &mut arg::Iter) -> Result { - Ok(OrgAsuslinuxDaemonNotifyGfx { vendor: i.read()? }) - } -} - -impl dbus::message::SignalArgs for OrgAsuslinuxDaemonNotifyGfx { - const NAME: &'static str = "NotifyGfx"; - const INTERFACE: &'static str = "org.asuslinux.Daemon"; -} - -#[derive(Debug)] -pub struct OrgAsuslinuxDaemonNotifyAction { - pub action: String, -} - -impl arg::AppendAll for OrgAsuslinuxDaemonNotifyAction { - fn append(&self, i: &mut arg::IterAppend) { - arg::RefArg::append(&self.action, i); - } -} - -impl arg::ReadAll for OrgAsuslinuxDaemonNotifyAction { - fn read(i: &mut arg::Iter) -> Result { - Ok(OrgAsuslinuxDaemonNotifyAction { action: i.read()? }) - } -} - -impl dbus::message::SignalArgs for OrgAsuslinuxDaemonNotifyAction { - const NAME: &'static str = "NotifyAction"; - const INTERFACE: &'static str = "org.asuslinux.Daemon"; -} diff --git a/asus-nb/src/dbus_ledmode.rs b/asus-nb/src/dbus_ledmode.rs deleted file mode 100644 index 24ca38b5..00000000 --- a/asus-nb/src/dbus_ledmode.rs +++ /dev/null @@ -1,67 +0,0 @@ -// This code was autogenerated with `dbus-codegen-rust -s -d org.asuslinux.Daemon -f org.asuslinux.Daemon -c blocking -p /org/asuslinux/Led -m None`, see https://github.com/diwic/dbus-rs -use dbus; -#[allow(unused_imports)] -use dbus::arg; -use dbus::blocking; - -pub trait OrgAsuslinuxDaemon { - fn set_led_mode(&self, data: &str) -> Result<(), dbus::Error>; - fn next_led_mode(&self) -> Result<(), dbus::Error>; - fn prev_led_mode(&self) -> Result<(), dbus::Error>; - fn led_mode(&self) -> Result; - fn led_modes(&self) -> Result; - fn led_brightness(&self) -> Result; -} - -impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgAsuslinuxDaemon - for blocking::Proxy<'a, C> -{ - fn set_led_mode(&self, data: &str) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "SetLedMode", (data,)) - } - - fn next_led_mode(&self) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "NextLedMode", ()) - } - - fn prev_led_mode(&self) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "PrevLedMode", ()) - } - - fn led_mode(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "LedMode", ()) - .and_then(|r: (String,)| Ok(r.0)) - } - - fn led_modes(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "LedModes", ()) - .and_then(|r: (String,)| Ok(r.0)) - } - - fn led_brightness(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "LedBrightness", ()) - .and_then(|r: (i16,)| Ok(r.0)) - } -} - -#[derive(Debug)] -pub struct OrgAsuslinuxDaemonNotifyLed { - pub data: String, -} - -impl arg::AppendAll for OrgAsuslinuxDaemonNotifyLed { - fn append(&self, i: &mut arg::IterAppend) { - arg::RefArg::append(&self.data, i); - } -} - -impl arg::ReadAll for OrgAsuslinuxDaemonNotifyLed { - fn read(i: &mut arg::Iter) -> Result { - Ok(OrgAsuslinuxDaemonNotifyLed { data: i.read()? }) - } -} - -impl dbus::message::SignalArgs for OrgAsuslinuxDaemonNotifyLed { - const NAME: &'static str = "NotifyLed"; - const INTERFACE: &'static str = "org.asuslinux.Daemon"; -} diff --git a/asus-nb/src/dbus_profile.rs b/asus-nb/src/dbus_profile.rs deleted file mode 100644 index dd3ca0e6..00000000 --- a/asus-nb/src/dbus_profile.rs +++ /dev/null @@ -1,62 +0,0 @@ -// This code was autogenerated with `dbus-codegen-rust -s -d org.asuslinux.Daemon -p /org/asuslinux/Profile -m None -f org.asuslinux.Daemon -c blocking`, see https://github.com/diwic/dbus-rs -use dbus; -#[allow(unused_imports)] -use dbus::arg; -use dbus::blocking; - -pub trait OrgAsuslinuxDaemon { - fn set_profile(&self, profile: &str) -> Result<(), dbus::Error>; - fn next_profile(&self) -> Result<(), dbus::Error>; - fn active_profile_name(&self) -> Result; - fn profile(&self) -> Result; - fn profiles(&self) -> Result; -} - -impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgAsuslinuxDaemon - for blocking::Proxy<'a, C> -{ - fn set_profile(&self, profile: &str) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "SetProfile", (profile,)) - } - - fn next_profile(&self) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "NextProfile", ()) - } - - fn active_profile_name(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "ActiveProfileName", ()) - .and_then(|r: (String,)| Ok(r.0)) - } - - fn profile(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "Profile", ()) - .and_then(|r: (String,)| Ok(r.0)) - } - - fn profiles(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "Profiles", ()) - .and_then(|r: (String,)| Ok(r.0)) - } -} - -#[derive(Debug)] -pub struct OrgAsuslinuxDaemonNotifyProfile { - pub profile: String, -} - -impl arg::AppendAll for OrgAsuslinuxDaemonNotifyProfile { - fn append(&self, i: &mut arg::IterAppend) { - arg::RefArg::append(&self.profile, i); - } -} - -impl arg::ReadAll for OrgAsuslinuxDaemonNotifyProfile { - fn read(i: &mut arg::Iter) -> Result { - Ok(OrgAsuslinuxDaemonNotifyProfile { profile: i.read()? }) - } -} - -impl dbus::message::SignalArgs for OrgAsuslinuxDaemonNotifyProfile { - const NAME: &'static str = "NotifyProfile"; - const INTERFACE: &'static str = "org.asuslinux.Daemon"; -} diff --git a/asus-nb/src/dbus_rogbios.rs b/asus-nb/src/dbus_rogbios.rs deleted file mode 100644 index 83e9e3e1..00000000 --- a/asus-nb/src/dbus_rogbios.rs +++ /dev/null @@ -1,86 +0,0 @@ -// This code was autogenerated with `dbus-codegen-rust -s -d org.asuslinux.Daemon -f org.asuslinux.Daemon -c blocking -p /org/asuslinux/RogBios -m None -o asus-nb/src/dbus_rogbios.rs`, see https://github.com/diwic/dbus-rs -use dbus; -#[allow(unused_imports)] -use dbus::arg; -use dbus::blocking; - -pub trait OrgAsuslinuxDaemon { - fn set_dedicated_graphic_mode(&self, dedicated: bool) -> Result<(), dbus::Error>; - fn dedicated_graphic_mode(&self) -> Result; - fn set_post_boot_sound(&self, on: bool) -> Result<(), dbus::Error>; - fn post_boot_sound(&self) -> Result; -} - -impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgAsuslinuxDaemon - for blocking::Proxy<'a, C> -{ - fn set_dedicated_graphic_mode(&self, dedicated: bool) -> Result<(), dbus::Error> { - self.method_call( - "org.asuslinux.Daemon", - "SetDedicatedGraphicMode", - (dedicated,), - ) - } - - fn dedicated_graphic_mode(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "DedicatedGraphicMode", ()) - .and_then(|r: (i16,)| Ok(r.0)) - } - - fn set_post_boot_sound(&self, on: bool) -> Result<(), dbus::Error> { - self.method_call("org.asuslinux.Daemon", "SetPostBootSound", (on,)) - } - - fn post_boot_sound(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "PostBootSound", ()) - .and_then(|r: (i16,)| Ok(r.0)) - } -} - -#[derive(Debug)] -pub struct OrgAsuslinuxDaemonNotifyDedicatedGraphicMode { - pub dedicated: bool, -} - -impl arg::AppendAll for OrgAsuslinuxDaemonNotifyDedicatedGraphicMode { - fn append(&self, i: &mut arg::IterAppend) { - arg::RefArg::append(&self.dedicated, i); - } -} - -impl arg::ReadAll for OrgAsuslinuxDaemonNotifyDedicatedGraphicMode { - fn read(i: &mut arg::Iter) -> Result { - Ok(OrgAsuslinuxDaemonNotifyDedicatedGraphicMode { - dedicated: i.read()?, - }) - } -} - -impl dbus::message::SignalArgs for OrgAsuslinuxDaemonNotifyDedicatedGraphicMode { - const NAME: &'static str = "NotifyDedicatedGraphicMode"; - const INTERFACE: &'static str = "org.asuslinux.Daemon"; -} - -#[derive(Debug)] -pub struct OrgAsuslinuxDaemonNotifyPostBootSound { - pub dedicated: bool, -} - -impl arg::AppendAll for OrgAsuslinuxDaemonNotifyPostBootSound { - fn append(&self, i: &mut arg::IterAppend) { - arg::RefArg::append(&self.dedicated, i); - } -} - -impl arg::ReadAll for OrgAsuslinuxDaemonNotifyPostBootSound { - fn read(i: &mut arg::Iter) -> Result { - Ok(OrgAsuslinuxDaemonNotifyPostBootSound { - dedicated: i.read()?, - }) - } -} - -impl dbus::message::SignalArgs for OrgAsuslinuxDaemonNotifyPostBootSound { - const NAME: &'static str = "NotifyPostBootSound"; - const INTERFACE: &'static str = "org.asuslinux.Daemon"; -} diff --git a/asus-nb/src/dbus_supported.rs b/asus-nb/src/dbus_supported.rs deleted file mode 100644 index 9a4a5ebf..00000000 --- a/asus-nb/src/dbus_supported.rs +++ /dev/null @@ -1,18 +0,0 @@ -// This code was autogenerated with `dbus-codegen-rust -s -d org.asuslinux.Daemon -f org.asuslinux.Daemon -c blocking -p /org/asuslinux/Supported -m None -o asus-nb/src/dbus_supported.rs`, see https://github.com/diwic/dbus-rs -use dbus; -#[allow(unused_imports)] -use dbus::arg; -use dbus::blocking; - -pub trait OrgAsuslinuxDaemon { - fn supported_functions(&self) -> Result; -} - -impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgAsuslinuxDaemon - for blocking::Proxy<'a, C> -{ - fn supported_functions(&self) -> Result { - self.method_call("org.asuslinux.Daemon", "SupportedFunctions", ()) - .and_then(|r: (String,)| Ok(r.0)) - } -} diff --git a/asus-nb/src/lib.rs b/asus-nb/src/lib.rs index 6f31b8da..b48c6755 100644 --- a/asus-nb/src/lib.rs +++ b/asus-nb/src/lib.rs @@ -17,21 +17,18 @@ pub mod fancy; /// The main dbus group for system controls, e.g, fan control, keyboard LED's pub mod core_dbus; -/// Specific dbus for writing to the AniMe Matrix display (if supported) -pub mod anime_dbus; - /// Helper functions for the AniMe display pub mod anime_matrix; pub mod error; -pub mod dbus_anime; -pub mod dbus_charge; -pub mod dbus_gfx; -pub mod dbus_ledmode; -pub mod dbus_profile; -pub mod dbus_rogbios; -pub mod dbus_supported; +pub mod zbus_anime; +pub mod zbus_charge; +pub mod zbus_gfx; +pub mod zbus_led; +pub mod zbus_profile; +pub mod zbus_rogbios; +pub mod zbus_supported; // static LED_INIT1: [u8; 2] = [0x5d, 0xb9]; // static LED_INIT2: &str = "]ASUS Tech.Inc."; // ] == 0x5d diff --git a/asus-nb/src/zbus_anime.rs b/asus-nb/src/zbus_anime.rs new file mode 100644 index 00000000..e68893ee --- /dev/null +++ b/asus-nb/src/zbus_anime.rs @@ -0,0 +1,75 @@ +//! # DBus interface proxy for: `org.asuslinux.Daemon` +//! +//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data. +//! Source: `Interface '/org/asuslinux/Anime' from service 'org.asuslinux.Daemon' on system bus`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! +//! This DBus object implements +//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html), +//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used: +//! +//! * [`zbus::fdo::IntrospectableProxy`] +//! * [`zbus::fdo::PeerProxy`] +//! * [`zbus::fdo::PropertiesProxy`] +//! +//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. + +use zbus::{dbus_proxy, Connection, Result}; + +use crate::anime_matrix::{AniMeMatrix, AniMePacketType, ANIME_PANE1_PREFIX, ANIME_PANE2_PREFIX}; + +#[dbus_proxy( + interface = "org.asuslinux.Daemon", + default_path = "/org/asuslinux/Anime" +)] +trait Daemon { + /// SetAnime method + fn set_anime(&self, input: &[&[u8]]) -> zbus::Result<()>; + + /// SetBootOnOff method + fn set_boot_on_off(&self, status: bool) -> zbus::Result<()>; + + /// SetOnOff method + fn set_on_off(&self, status: bool) -> zbus::Result<()>; +} + +pub struct AnimeProxy<'a>(DaemonProxy<'a>); + +impl<'a> AnimeProxy<'a> { + #[inline] + pub fn new(conn: &Connection) -> Result { + Ok(AnimeProxy(DaemonProxy::new(&conn)?)) + } + + pub fn proxy(&self) -> &DaemonProxy<'a> { + &self.0 + } + + #[inline] + pub fn set_brightness(&self, led_brightness: u8) -> Result<()> { + let mut anime_matrix = AniMeMatrix::new(); + + anime_matrix.fill_with(led_brightness); + + let mut image = AniMePacketType::from(anime_matrix); + image[0][..7].copy_from_slice(&ANIME_PANE1_PREFIX); + image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX); + + self.0.set_anime(&[&image[0], &image[1]]) + } + + #[inline] + pub fn toggle_boot_on(&self, on: bool) -> Result<()> { + self.0.set_boot_on_off(on) + } + + #[inline] + pub fn toggle_on(&self, on: bool) -> Result<()> { + self.0.set_on_off(on) + } +} diff --git a/asus-nb/src/zbus_charge.rs b/asus-nb/src/zbus_charge.rs new file mode 100644 index 00000000..5237d3a8 --- /dev/null +++ b/asus-nb/src/zbus_charge.rs @@ -0,0 +1,73 @@ +//! # DBus interface proxy for: `org.asuslinux.Daemon` +//! +//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data. +//! Source: `Interface '/org/asuslinux/Charge' from service 'org.asuslinux.Daemon' on system bus`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! +//! This DBus object implements +//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html), +//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used: +//! +//! * [`zbus::fdo::PropertiesProxy`] +//! * [`zbus::fdo::PeerProxy`] +//! * [`zbus::fdo::IntrospectableProxy`] +//! +//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. + +use std::sync::{Arc, Mutex}; + +use zbus::{dbus_proxy, Connection, Result}; + +#[dbus_proxy( + interface = "org.asuslinux.Daemon", + default_path = "/org/asuslinux/Charge" +)] +trait Daemon { + /// Limit method + fn limit(&self) -> zbus::Result; + + /// SetLimit method + fn set_limit(&self, limit: u8) -> zbus::Result<()>; + + /// NotifyCharge signal + #[dbus_proxy(signal)] + fn notify_charge(&self, limit: u8) -> zbus::Result<()>; +} + +pub struct ChargeProxy<'a>(DaemonProxy<'a>); + +impl<'a> ChargeProxy<'a> { + #[inline] + pub fn new(conn: &Connection) -> Result { + Ok(ChargeProxy(DaemonProxy::new(&conn)?)) + } + + pub fn proxy(&self) -> &DaemonProxy<'a> { + &self.0 + } + + #[inline] + pub fn write_limit(&self, level: u8) -> Result<()> { + self.0.set_limit(level) + } + + #[inline] + pub fn get_limit(&self) -> Result { + self.0.limit() + } + + #[inline] + pub fn connect_notify_charge(&self, charge: Arc>>) -> zbus::fdo::Result<()> { + self.0.connect_notify_charge(move |data| { + if let Ok(mut lock) = charge.lock() { + *lock = Some(data); + } + Ok(()) + }) + } +} diff --git a/asus-nb/src/zbus_gfx.rs b/asus-nb/src/zbus_gfx.rs new file mode 100644 index 00000000..c62e0020 --- /dev/null +++ b/asus-nb/src/zbus_gfx.rs @@ -0,0 +1,98 @@ +//! # DBus interface proxy for: `org.asuslinux.Gfx` +//! +//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data. +//! Source: `Interface '/org/asuslinux/Gfx' from service 'org.asuslinux.Daemon' on system bus`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! +//! This DBus object implements +//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html), +//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used: +//! +//! * [`zbus::fdo::PropertiesProxy`] +//! * [`zbus::fdo::IntrospectableProxy`] +//! * [`zbus::fdo::PeerProxy`] +//! +//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. + +use std::sync::{Arc, Mutex}; + +use zbus::{dbus_proxy, Connection, Result}; + +#[dbus_proxy( + interface = "org.asuslinux.Daemon", + default_path = "/org/asuslinux/Gfx" +)] +trait Daemon { + /// Power method + fn power(&self) -> zbus::Result; + + /// SetVendor method + fn set_vendor(&self, vendor: &str) -> zbus::Result<()>; + + /// Vendor method + fn vendor(&self) -> zbus::Result; + + /// NotifyAction signal + #[dbus_proxy(signal)] + fn notify_action(&self, action: &str) -> zbus::Result<()>; + + /// NotifyGfx signal + #[dbus_proxy(signal)] + fn notify_gfx(&self, vendor: &str) -> zbus::Result<()>; +} + +pub struct GfxProxy<'a>(DaemonProxy<'a>); + +impl<'a> GfxProxy<'a> { + #[inline] + pub fn new(conn: &Connection) -> Result { + Ok(GfxProxy(DaemonProxy::new(&conn)?)) + } + + pub fn proxy(&self) -> &DaemonProxy<'a> { + &self.0 + } + + #[inline] + pub fn gfx_get_pwr(&self) -> Result { + self.0.power() + } + + #[inline] + pub fn gfx_get_mode(&self) -> Result { + self.0.vendor() + } + + #[inline] + pub fn gfx_write_mode(&self, vendor: &str) -> Result<()> { + self.0.set_vendor(vendor) + } + + #[inline] + pub fn connect_notify_action( + &self, + action: Arc>>, + ) -> zbus::fdo::Result<()> { + self.0.connect_notify_action(move |data| { + if let Ok(mut lock) = action.lock() { + *lock = Some(data.to_owned()); + } + Ok(()) + }) + } + + #[inline] + pub fn connect_notify_gfx(&self, vendor: Arc>>) -> zbus::fdo::Result<()> { + self.0.connect_notify_gfx(move |data| { + if let Ok(mut lock) = vendor.lock() { + *lock = Some(data.to_owned()); + } + Ok(()) + }) + } +} diff --git a/asus-nb/src/zbus_led.rs b/asus-nb/src/zbus_led.rs new file mode 100644 index 00000000..cc2e6dd5 --- /dev/null +++ b/asus-nb/src/zbus_led.rs @@ -0,0 +1,142 @@ +//! # DBus interface proxy for: `org.asuslinux.Daemon` +//! +//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data. +//! Source: `Interface '/org/asuslinux/Led' from service 'org.asuslinux.Daemon' on system bus`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! +//! This DBus object implements +//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html), +//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used: +//! +//! * [`zbus::fdo::PeerProxy`] +//! * [`zbus::fdo::IntrospectableProxy`] +//! * [`zbus::fdo::PropertiesProxy`] +//! +//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. + +use std::sync::{Arc, Mutex}; + +use zbus::{dbus_proxy, Connection, Result}; + +use crate::{aura_modes::AuraModes, cli_options::LedBrightness, fancy::KeyColourArray}; + +const BLOCKING_TIME: u64 = 40; // 100ms = 10 FPS, max 50ms = 20 FPS, 40ms = 25 FPS + +#[dbus_proxy( + interface = "org.asuslinux.Daemon", + default_path = "/org/asuslinux/Led" +)] +trait Daemon { + /// LedBrightness method + fn led_brightness(&self) -> zbus::Result; + + /// LedMode method + fn led_mode(&self) -> zbus::Result; + + /// LedModes method + fn led_modes(&self) -> zbus::Result; + + /// NextLedMode method + fn next_led_mode(&self) -> zbus::Result<()>; + + /// PrevLedMode method + fn prev_led_mode(&self) -> zbus::Result<()>; + + /// SetLedMode method + fn set_led_mode(&self, data: &str) -> zbus::Result<()>; + + /// NotifyLed signal + #[dbus_proxy(signal)] + fn notify_led(&self, data: &str) -> zbus::Result<()>; +} + +pub struct LedProxy<'a>(DaemonProxy<'a>); + +impl<'a> LedProxy<'a> { + #[inline] + pub fn new(conn: &Connection) -> Result { + Ok(LedProxy(DaemonProxy::new(&conn)?)) + } + + pub fn proxy(&self) -> &DaemonProxy<'a> { + &self.0 + } + + #[inline] + pub fn get_led_brightness(&self) -> Result { + match self.0.led_brightness()? { + -1 => Ok(LedBrightness::new(None)), + level => Ok(LedBrightness::new(Some(level as u8))), + } + } + + #[inline] + pub fn set_brightness(&self, level: u8) -> Result<()> { + self.set_led_mode(&AuraModes::LedBrightness(level))?; + Ok(()) + } + + #[inline] + pub fn next_led_mode(&self) -> Result<()> { + self.0.next_led_mode() + } + + #[inline] + pub fn prev_led_mode(&self) -> Result<()> { + self.0.prev_led_mode() + } + + #[inline] + pub fn set_led_mode(&self, mode: &AuraModes) -> Result<()> { + self.0.set_led_mode(&serde_json::to_string(mode).unwrap()) + } + + /// Write a single colour block. + /// + /// Intentionally blocks for 10ms after sending to allow the block to + /// be written to the keyboard EC. This should not be async. + #[inline] + pub fn set_per_key(&self, key_colour_array: &KeyColourArray) -> Result<()> { + let group = key_colour_array.get(); + let mut vecs = Vec::with_capacity(group.len()); + for v in group { + vecs.push(v.to_vec()); + } + let mode = AuraModes::PerKey(vecs); + + self.set_led_mode(&mode)?; + + std::thread::sleep(std::time::Duration::from_millis(BLOCKING_TIME)); + + // if self.stop.load(Ordering::Relaxed) { + // println!("Keyboard backlight was changed, exiting"); + // std::process::exit(1) + // } + Ok(()) + } + + /// This method must always be called before the very first write to initialise + /// the keyboard LED EC in the correct mode + #[inline] + pub fn init_effect(&self) -> Result<()> { + let mode = AuraModes::PerKey(vec![vec![]]); + self.0.set_led_mode(&serde_json::to_string(&mode).unwrap()) + } + + #[inline] + pub fn connect_notify_led(&self, led: Arc>>) -> zbus::fdo::Result<()> { + self.0.connect_notify_led(move |data| { + if let Ok(mut lock) = led.lock() { + if let Ok(dat) = serde_json::from_str(&data) { + *lock = Some(dat); + } + } + Ok(()) + }) + } +} diff --git a/asus-nb/src/zbus_profile.rs b/asus-nb/src/zbus_profile.rs new file mode 100644 index 00000000..a4187a8d --- /dev/null +++ b/asus-nb/src/zbus_profile.rs @@ -0,0 +1,98 @@ +//! # DBus interface proxy for: `org.asuslinux.Daemon` +//! +//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data. +//! Source: `Interface '/org/asuslinux/Profile' from service 'org.asuslinux.Daemon' on system bus`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! +//! This DBus object implements +//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html), +//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used: +//! +//! * [`zbus::fdo::IntrospectableProxy`] +//! * [`zbus::fdo::PeerProxy`] +//! * [`zbus::fdo::PropertiesProxy`] +//! +//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. + +use std::sync::{Arc, Mutex}; + +use zbus::{dbus_proxy, Connection, Result}; + +use crate::profile::ProfileEvent; + +#[dbus_proxy( + interface = "org.asuslinux.Daemon", + default_path = "/org/asuslinux/Profile" +)] +trait Daemon { + /// ActiveProfileName method + fn active_profile_name(&self) -> zbus::Result; + + /// NextProfile method + fn next_profile(&self) -> zbus::Result<()>; + + /// Profile method + fn profile(&self) -> zbus::Result; + + /// Profiles method + fn profiles(&self) -> zbus::Result; + + /// SetProfile method + fn set_profile(&self, profile: &str) -> zbus::Result<()>; + + /// NotifyProfile signal + #[dbus_proxy(signal)] + fn notify_profile(&self, profile: &str) -> zbus::Result<()>; +} + +pub struct ProfileProxy<'a>(DaemonProxy<'a>); + +impl<'a> ProfileProxy<'a> { + #[inline] + pub fn new(conn: &Connection) -> Result { + Ok(ProfileProxy(DaemonProxy::new(&conn)?)) + } + + pub fn proxy(&self) -> &DaemonProxy<'a> { + &self.0 + } + + #[inline] + pub fn active_profile_name(&self) -> Result { + self.0.active_profile_name() + } + + #[inline] + pub fn next_fan(&self) -> Result<()> { + self.0.next_profile() + } + + #[inline] + pub fn write_fan_mode(&self, level: u8) -> Result<()> { + self.0 + .set_profile(&serde_json::to_string(&ProfileEvent::ChangeMode(level)).unwrap()) + } + + #[inline] + pub fn write_command(&self, cmd: &ProfileEvent) -> Result<()> { + self.0.set_profile(&serde_json::to_string(cmd).unwrap()) + } + + #[inline] + pub fn connect_notify_profile( + &self, + charge: Arc>>, + ) -> zbus::fdo::Result<()> { + self.0.connect_notify_profile(move |data| { + if let Ok(mut lock) = charge.lock() { + *lock = Some(data.to_owned()); + } + Ok(()) + }) + } +} diff --git a/asus-nb/src/zbus_rogbios.rs b/asus-nb/src/zbus_rogbios.rs new file mode 100644 index 00000000..065c3495 --- /dev/null +++ b/asus-nb/src/zbus_rogbios.rs @@ -0,0 +1,109 @@ +//! # DBus interface proxy for: `org.asuslinux.Daemon` +//! +//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data. +//! Source: `Interface '/org/asuslinux/RogBios' from service 'org.asuslinux.Daemon' on system bus`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! +//! This DBus object implements +//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html), +//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used: +//! +//! * [`zbus::fdo::PropertiesProxy`] +//! * [`zbus::fdo::PeerProxy`] +//! * [`zbus::fdo::IntrospectableProxy`] +//! +//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. + +use std::sync::{Arc, Mutex}; + +use zbus::{dbus_proxy, Connection, Result}; + +#[dbus_proxy( + interface = "org.asuslinux.Daemon", + default_path = "/org/asuslinux/RogBios" +)] +trait Daemon { + /// DedicatedGraphicMode method + fn dedicated_graphic_mode(&self) -> zbus::Result; + + /// PostBootSound method + fn post_boot_sound(&self) -> zbus::Result; + + /// SetDedicatedGraphicMode method + fn set_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()>; + + /// SetPostBootSound method + fn set_post_boot_sound(&self, on: bool) -> zbus::Result<()>; + + /// NotifyDedicatedGraphicMode signal + #[dbus_proxy(signal)] + fn notify_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()>; + + /// NotifyPostBootSound signal + #[dbus_proxy(signal)] + fn notify_post_boot_sound(&self, dedicated: bool) -> zbus::Result<()>; +} + +pub struct RogBiosProxy<'a>(DaemonProxy<'a>); + +impl<'a> RogBiosProxy<'a> { + #[inline] + pub fn new(conn: &Connection) -> Result { + Ok(RogBiosProxy(DaemonProxy::new(&conn)?)) + } + + pub fn proxy(&self) -> &DaemonProxy<'a> { + &self.0 + } + + #[inline] + pub fn get_dedicated_gfx(&self) -> Result { + self.0.dedicated_graphic_mode() + } + + #[inline] + pub fn set_dedicated_gfx(&self, on: bool) -> Result<()> { + self.0.set_dedicated_graphic_mode(on) + } + + #[inline] + pub fn get_post_sound(&self) -> Result { + self.0.post_boot_sound() + } + + #[inline] + pub fn set_post_sound(&self, on: bool) -> Result<()> { + self.0.set_post_boot_sound(on) + } + + #[inline] + pub fn connect_notify_dedicated_graphic_mode( + &self, + dedicated: Arc>>, + ) -> zbus::fdo::Result<()> { + self.0.connect_notify_dedicated_graphic_mode(move |data| { + if let Ok(mut lock) = dedicated.lock() { + *lock = Some(data); + } + Ok(()) + }) + } + + #[inline] + pub fn connect_notify_post_boot_sound( + &self, + sound: Arc>>, + ) -> zbus::fdo::Result<()> { + self.0.connect_notify_post_boot_sound(move |data| { + if let Ok(mut lock) = sound.lock() { + *lock = Some(data); + } + Ok(()) + }) + } +} diff --git a/asus-nb/src/zbus_supported.rs b/asus-nb/src/zbus_supported.rs new file mode 100644 index 00000000..4e8cd49b --- /dev/null +++ b/asus-nb/src/zbus_supported.rs @@ -0,0 +1,49 @@ +//! # DBus interface proxy for: `org.asuslinux.Daemon` +//! +//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data. +//! Source: `Interface '/org/asuslinux/Supported' from service 'org.asuslinux.Daemon' on system bus`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! +//! This DBus object implements +//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html), +//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used: +//! +//! * [`zbus::fdo::PeerProxy`] +//! * [`zbus::fdo::PropertiesProxy`] +//! * [`zbus::fdo::IntrospectableProxy`] +//! +//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. + +use zbus::{dbus_proxy, Connection, Result}; + +#[dbus_proxy( + interface = "org.asuslinux.Daemon", + default_path = "/org/asuslinux/Supported" +)] +trait Daemon { + /// SupportedFunctions method + fn supported_functions(&self) -> zbus::Result; +} + +pub struct SupportProxy<'a>(DaemonProxy<'a>); + +impl<'a> SupportProxy<'a> { + #[inline] + pub fn new(conn: &Connection) -> Result { + Ok(SupportProxy(DaemonProxy::new(&conn)?)) + } + + pub fn proxy(&self) -> &DaemonProxy<'a> { + &self.0 + } + + #[inline] + pub fn get_supported_functions(&self) -> Result { + self.0.supported_functions() + } +} diff --git a/asus-notify/Cargo.toml b/asus-notify/Cargo.toml index f715cdc8..9bf7e869 100644 --- a/asus-notify/Cargo.toml +++ b/asus-notify/Cargo.toml @@ -11,11 +11,12 @@ edition = "2018" serde = "^1.0" serde_derive = "^1.0" serde_json = "^1.0" -dbus = { version = "^0.8" } asus-nb = { path = "../asus-nb" } asus-nb-ctrl = { path = "../asus-nb-ctrl" } +zbus = "^1.8" +zvariant = "^2.4" [dependencies.notify-rust] -version = "^4.0.0" +version = "^4.0" default-features = false features = ["z"] \ No newline at end of file diff --git a/asus-notify/src/main.rs b/asus-notify/src/main.rs index 32b91bbd..bd713c00 100644 --- a/asus-notify/src/main.rs +++ b/asus-notify/src/main.rs @@ -1,6 +1,5 @@ -use asus_nb::core_dbus::CtrlSignals; -use daemon::config::{Config, Profile}; -use dbus::blocking::Connection; +use asus_nb::core_dbus::{DbusProxies, Signals}; +use daemon::config::Profile; use notify_rust::{Hint, Notification, NotificationHandle}; use std::error::Error; use std::time::Duration; @@ -8,22 +7,23 @@ use std::time::Duration; fn main() -> Result<(), Box> { println!("Version {}", env!("CARGO_PKG_VERSION")); - let mut cfg = Config::read_new()?; - let mut last_profile = String::new(); + // let mut cfg = Config::read_new()?; + // let mut last_profile = String::new(); - let connection = Connection::new_system()?; - let signals = CtrlSignals::new(&connection)?; + let (proxies, conn) = DbusProxies::new()?; + let signals = Signals::new(&proxies)?; let mut last_profile_notif: Option = None; let mut last_led_notif: Option = None; let mut last_gfx_notif: Option = None; let mut last_chrg_notif: Option = None; + let recv = proxies.setup_recv(conn); loop { std::thread::sleep(Duration::from_millis(100)); - connection.process(std::time::Duration::from_millis(200))?; + recv.next_signal().unwrap(); - if let Ok(mut lock) = signals.gfx_vendor_signal.lock() { + if let Ok(mut lock) = signals.gfx_vendor.lock() { if let Some(vendor) = lock.take() { if let Some(notif) = last_gfx_notif.take() { notif.close(); @@ -33,17 +33,32 @@ fn main() -> Result<(), Box> { } } - if let Ok(mut lock) = signals.charge_signal.lock() { + if let Ok(mut lock) = signals.charge.lock() { if let Some(limit) = lock.take() { if let Some(notif) = last_chrg_notif.take() { notif.close(); } let x = do_notif(&format!("Battery charge limit changed to {}", limit))?; - last_led_notif = Some(x); + last_chrg_notif = Some(x); } } - if let Ok(mut lock) = signals.ledmode_signal.lock() { + if let Ok(mut lock) = signals.profile.lock() { + if let Some(profile) = lock.take() { + if let Some(notif) = last_profile_notif.take() { + notif.close(); + } + if let Ok(profile) = serde_json::from_str(&profile) { + let profile: Profile = profile; + if let Ok(name) = proxies.profile().active_profile_name() { + let x = do_thermal_notif(&profile, &name)?; + last_profile_notif = Some(x); + } + } + } + } + + if let Ok(mut lock) = signals.led_mode.lock() { if let Some(ledmode) = lock.take() { if let Some(notif) = last_led_notif.take() { notif.close(); @@ -55,20 +70,6 @@ fn main() -> Result<(), Box> { last_led_notif = Some(x); } } - - // We need to do the config read because of a limitation preventing - // easy dbus notification from the profile controller - cfg.read(); - if last_profile != cfg.active_profile { - if let Some(notif) = last_profile_notif.take() { - notif.close(); - } - if let Some(profile) = cfg.power_profiles.get(&cfg.active_profile) { - let x = do_thermal_notif(&profile, &cfg.active_profile)?; - last_profile_notif = Some(x); - last_profile = cfg.active_profile.clone(); - } - } } }