mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Compare commits
378 Commits
6.0.3
...
remove_sup
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9c5315bda | ||
|
|
b521a9ffc1 | ||
|
|
5e48923db1 | ||
|
|
392436808d | ||
|
|
3d9a08d7e0 | ||
|
|
ff103f98af | ||
|
|
d05182ae64 | ||
|
|
a4957a6eeb | ||
|
|
dda750cf33 | ||
|
|
0b5e04393a | ||
|
|
c9c9a022a4 | ||
|
|
aa063c20fd | ||
|
|
8551908452 | ||
|
|
5ecb174b8f | ||
|
|
fa266bff5b | ||
|
|
f53f1f360f | ||
|
|
da19216b78 | ||
|
|
46efd4190f | ||
|
|
ed3022e25e | ||
|
|
7c10d6c6d9 | ||
|
|
af5f3a5c71 | ||
|
|
7d5ec5f2c7 | ||
|
|
1c8acf6de3 | ||
|
|
7b644e7ad6 | ||
|
|
0f02fe868c | ||
|
|
abd3100e30 | ||
|
|
6f651c2b85 | ||
|
|
93ec5d1bce | ||
|
|
5aea7f51c0 | ||
|
|
d03d8ce67f | ||
|
|
ae3693e0d9 | ||
|
|
c8b9248eda | ||
|
|
22098794fe | ||
|
|
10d49f4fc8 | ||
|
|
5aba2854b0 | ||
|
|
ea32ad6e0a | ||
|
|
ee0e612c04 | ||
|
|
e565ce748a | ||
|
|
7024941663 | ||
|
|
817a0165b5 | ||
|
|
efcd038f40 | ||
|
|
375d99b8fc | ||
|
|
3a206eb76f | ||
|
|
4449838282 | ||
|
|
58d740f77a | ||
|
|
f0488d9750 | ||
|
|
f1b9ae6f71 | ||
|
|
db5de3b854 | ||
|
|
7a3d39b8f1 | ||
|
|
7a5d6325c0 | ||
|
|
574b954866 | ||
|
|
a811f20f65 | ||
|
|
0c9c263be6 | ||
|
|
6571c04bfe | ||
|
|
e48acbb8a2 | ||
|
|
f33496ef68 | ||
|
|
cd3176b565 | ||
|
|
7595613d7e | ||
|
|
b8d0245e7a | ||
|
|
54bd2ec800 | ||
|
|
b6c8566565 | ||
|
|
052c096014 | ||
|
|
81cbe3c522 | ||
|
|
09f7492bec | ||
|
|
6adfb2cf48 | ||
|
|
a2a56792a8 | ||
|
|
317daf4ed1 | ||
|
|
eb0d9514b5 | ||
|
|
d324b1bce5 | ||
|
|
d1c7385146 | ||
|
|
48a4935fc7 | ||
|
|
7e917b91a5 | ||
|
|
45f8b8ffb0 | ||
|
|
031a36242b | ||
|
|
8ad26ad136 | ||
|
|
907d4694f3 | ||
|
|
1dcc4ff502 | ||
|
|
cf232047b0 | ||
|
|
ff99ec9a39 | ||
|
|
8a19374a41 | ||
|
|
4cec1f49b4 | ||
|
|
01aae200f3 | ||
|
|
4c6db9f0a9 | ||
|
|
7207d3287a | ||
|
|
1b2d8d83fc | ||
|
|
6d8db91583 | ||
|
|
20c3628476 | ||
|
|
4edecfce1c | ||
|
|
34699a7021 | ||
|
|
ef311689ec | ||
|
|
8ee0281b4f | ||
|
|
d8504b5430 | ||
|
|
5c4d833fbd | ||
|
|
698999e828 | ||
|
|
0eae9e55c6 | ||
|
|
07171888a1 | ||
|
|
9321fde6af | ||
|
|
f90d0a6673 | ||
|
|
bbd03c128d | ||
|
|
132a2f3665 | ||
|
|
180566e5f1 | ||
|
|
c9e76f3273 | ||
|
|
2997ae83ff | ||
|
|
151d681e16 | ||
|
|
90b3f43a36 | ||
|
|
a345b09ce1 | ||
|
|
f26b0d8de5 | ||
|
|
9366b0ec04 | ||
|
|
415712143b | ||
|
|
60fce30a06 | ||
|
|
d8f06230fa | ||
|
|
834464a527 | ||
|
|
4faa96298a | ||
|
|
78c574b761 | ||
|
|
9785eafd53 | ||
|
|
51cad9ea7e | ||
|
|
319373faea | ||
|
|
f6aa3e3d01 | ||
|
|
d11fc20bab | ||
|
|
b0e1b21e4b | ||
|
|
1c1daaa6d2 | ||
|
|
c3b5de843f | ||
|
|
09dcfb4065 | ||
|
|
b2e7211bbe | ||
|
|
1ab1adf937 | ||
|
|
a21bf779b0 | ||
|
|
0dba22529c | ||
|
|
180d63620b | ||
|
|
daea1f538c | ||
|
|
f5e2484797 | ||
|
|
7105ae40c6 | ||
|
|
33f9900ef9 | ||
|
|
1aa1c62e40 | ||
|
|
3a18ef4c7b | ||
|
|
9dcce77302 | ||
|
|
995df9b51b | ||
|
|
84c8babdb7 | ||
|
|
1014f97b6f | ||
|
|
3c023be57d | ||
|
|
eff20c84d6 | ||
|
|
f8984eb7e9 | ||
|
|
2ffd2a1e1f | ||
|
|
341bd081f8 | ||
|
|
52af4203a1 | ||
|
|
e5a6088392 | ||
|
|
6ee5dfb352 | ||
|
|
3f8336fc5e | ||
|
|
8fc7e8f3a7 | ||
|
|
098b1f2668 | ||
|
|
20df3ad2f2 | ||
|
|
7aaadad6da | ||
|
|
be60c1ba02 | ||
|
|
698a8e8677 | ||
|
|
ce6420eeac | ||
|
|
f5f5e4f720 | ||
|
|
c08503826b | ||
|
|
685345d656 | ||
|
|
59aab24a4a | ||
|
|
c3f0e61ebc | ||
|
|
c143536cd0 | ||
|
|
2a168e93d3 | ||
|
|
c3570a23f1 | ||
|
|
9db6cb5545 | ||
|
|
836575c0a8 | ||
|
|
61f2216c25 | ||
|
|
7f5b3ef376 | ||
|
|
257471a36c | ||
|
|
568f3e848f | ||
|
|
0c9b58755f | ||
|
|
1b47fb7873 | ||
|
|
df93209839 | ||
|
|
11ee7827e9 | ||
|
|
c337de5139 | ||
|
|
d55c2befed | ||
|
|
4cd9918e1a | ||
|
|
3a900f23fe | ||
|
|
aee465aced | ||
|
|
192e5ccaa3 | ||
|
|
f164583792 | ||
|
|
b4d657b866 | ||
|
|
f7bf7aeef9 | ||
|
|
2cd4c4850f | ||
|
|
805ccfe451 | ||
|
|
5655f63dff | ||
|
|
a2795e4d78 | ||
|
|
0684c16bf5 | ||
|
|
a08ca3af98 | ||
|
|
efa379e778 | ||
|
|
5cbf0816fe | ||
|
|
2951d3926c | ||
|
|
eb19d59d52 | ||
|
|
3e4d594b05 | ||
|
|
ae8ce83583 | ||
|
|
5c3348a9f5 | ||
|
|
f299ffeb6e | ||
|
|
21c468cf02 | ||
|
|
7f12f62ad5 | ||
|
|
5fb0e26331 | ||
|
|
4dd29952c8 | ||
|
|
2c006699f2 | ||
|
|
0bdf0474c9 | ||
|
|
66196ceb17 | ||
|
|
b2726f3a67 | ||
|
|
663f87d5e2 | ||
|
|
377bb4d6ad | ||
|
|
98e60db2da | ||
|
|
11ac46df11 | ||
|
|
05bec93644 | ||
|
|
c77e7cf1ce | ||
|
|
d30f7dc2ea | ||
|
|
759606fca3 | ||
|
|
25ed8bdeed | ||
|
|
de61a15b7a | ||
|
|
16700e55f4 | ||
|
|
5833a011ce | ||
|
|
62577ee0e4 | ||
|
|
dac35996b1 | ||
|
|
5c2bcad7c6 | ||
|
|
a206591e97 | ||
|
|
81f6c18a24 | ||
|
|
bcc3d42789 | ||
|
|
36c34cb3dd | ||
|
|
9b82b875f1 | ||
|
|
bddccc696f | ||
|
|
51e9f10087 | ||
|
|
911ff8690e | ||
|
|
25823dc6b7 | ||
|
|
cba8e1a473 | ||
|
|
fb98827a1a | ||
|
|
b9296862df | ||
|
|
450205f9a9 | ||
|
|
82431ee25b | ||
|
|
f11aea02a8 | ||
|
|
2d6d669c22 | ||
|
|
f9cebf9221 | ||
|
|
a00808313e | ||
|
|
3426591d32 | ||
|
|
ef3b6636f5 | ||
|
|
ee9e0a1e31 | ||
|
|
9e84997cbf | ||
|
|
2b22f82b72 | ||
|
|
7a1b45071d | ||
|
|
ad63c429cb | ||
|
|
a790d9a499 | ||
|
|
be51a1ab77 | ||
|
|
d9a88e7cc3 | ||
|
|
d785e17f95 | ||
|
|
efe64119c6 | ||
|
|
128bc3fce1 | ||
|
|
2123f369ad | ||
|
|
2b7a2a5be3 | ||
|
|
1d9e89ef3d | ||
|
|
4011b3ebd4 | ||
|
|
f7456f0144 | ||
|
|
2ed2d82e03 | ||
|
|
d40f4733e2 | ||
|
|
98dc155e41 | ||
|
|
fd3384decc | ||
|
|
a1a9c7077a | ||
|
|
62aa1fe04f | ||
|
|
a7b98c67ee | ||
|
|
e7bbd99178 | ||
|
|
e2d3f99d91 | ||
|
|
1cad5afc0d | ||
|
|
fd31ac458d | ||
|
|
6292b3361d | ||
|
|
ab7a4bbad3 | ||
|
|
0f2d89858e | ||
|
|
19ffcf3376 | ||
|
|
72c0b24ead | ||
|
|
0ddfe76c31 | ||
|
|
c05c8ba648 | ||
|
|
ccdc576319 | ||
|
|
39b16ffc91 | ||
|
|
72ff1ab3ab | ||
|
|
e7c4619ee9 | ||
|
|
71fcb382ea | ||
|
|
e5b2e3ef11 | ||
|
|
dfd39522a8 | ||
|
|
2759c28196 | ||
|
|
207e199016 | ||
|
|
5f8cbdb94b | ||
|
|
0853c16d5e | ||
|
|
0be04726ca | ||
|
|
a672a86cc4 | ||
|
|
c7ff3b44dc | ||
|
|
f0ebda9ecd | ||
|
|
b984176cd0 | ||
|
|
599b1cc9ad | ||
|
|
d93df8752e | ||
|
|
8a9564bbfa | ||
|
|
5455e345b2 | ||
|
|
520101fea1 | ||
|
|
e866b4eeb1 | ||
|
|
c5c46738ee | ||
|
|
27ed95bd3e | ||
|
|
ea9ca79a8f | ||
|
|
4a97f173be | ||
|
|
8f35220c5f | ||
|
|
c3880d055d | ||
|
|
b661f67084 | ||
|
|
abd2ca8601 | ||
|
|
0905ed8ad4 | ||
|
|
c1268d4aad | ||
|
|
5ed47abc32 | ||
|
|
718bb8b86f | ||
|
|
5ab9642b79 | ||
|
|
14acab9a9c | ||
|
|
c5c5a9ac67 | ||
|
|
b84bc61f3d | ||
|
|
b4e38e0814 | ||
|
|
e4dd485dd4 | ||
|
|
ab1d75e5ec | ||
|
|
e4c5df6cca | ||
|
|
9ee7ee26a2 | ||
|
|
e8ebdacb91 | ||
|
|
b97921fea2 | ||
|
|
a3423195a6 | ||
|
|
f55edfbae0 | ||
|
|
3e065b6715 | ||
|
|
f14d1ad61e | ||
|
|
85d4e9cabd | ||
|
|
e47a9cffd7 | ||
|
|
ca93dc7215 | ||
|
|
93a646773c | ||
|
|
1cba693469 | ||
|
|
166149b351 | ||
|
|
1b11b6d8fb | ||
|
|
02568299df | ||
|
|
acdc93596c | ||
|
|
22e26adfb6 | ||
|
|
4730e645ba | ||
|
|
d203fab70d | ||
|
|
792fae3ed7 | ||
|
|
e443ab00c9 | ||
|
|
aee54f5756 | ||
|
|
00904e9603 | ||
|
|
b1212585e2 | ||
|
|
faca084cff | ||
|
|
89dc0b3501 | ||
|
|
ea988279a8 | ||
|
|
219bd559b6 | ||
|
|
ad1ef9b8a2 | ||
|
|
59795c605c | ||
|
|
a36ac2b6d3 | ||
|
|
a20837f252 | ||
|
|
1353fe3fdb | ||
|
|
770bd12a5c | ||
|
|
af2f5592f0 | ||
|
|
9686c41ac4 | ||
|
|
fbdb0514d2 | ||
|
|
1f5650d26b | ||
|
|
14db97c476 | ||
|
|
66a501ecf6 | ||
|
|
6b129763d4 | ||
|
|
a0368d4345 | ||
|
|
f2f090a88f | ||
|
|
6c7e1a6467 | ||
|
|
92ca7bc70d | ||
|
|
dd1e6b845b | ||
|
|
882fa9bed8 | ||
|
|
9c7dfb4030 | ||
|
|
f855908c82 | ||
|
|
293a087b8a | ||
|
|
fd72a04bb8 | ||
|
|
f131a3fa70 | ||
|
|
ccf8d8df91 | ||
|
|
b970d364f7 | ||
|
|
1da68ea69d | ||
|
|
e62e7e8eca | ||
|
|
1b1d10c461 | ||
|
|
14ea0f6d83 | ||
|
|
5107a6c39c | ||
|
|
2c77ec9e24 | ||
|
|
817a66bdf1 | ||
|
|
664a3d5533 | ||
|
|
37bc5e45b9 | ||
|
|
7122fbaca8 |
53
.cargo-husky/hooks/post-commit
Executable file
53
.cargo-husky/hooks/post-commit
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
ROOT_DIR=$(git rev-parse --show-toplevel)
|
||||||
|
AURA_DATA="${ROOT_DIR}/rog-aura/data/aura_support.ron"
|
||||||
|
SPEC_FILE="${ROOT_DIR}/distro-packaging/asusctl.spec"
|
||||||
|
TRANSLATION="${ROOT_DIR}/rog-control-center/translations/en/rog-control-center.po"
|
||||||
|
VERSION=$(grep -Pm1 'version = "(\d+.\d+.\d+.*)"' "${ROOT_DIR}/Cargo.toml" | cut -d'"' -f2)
|
||||||
|
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
echo "Error: Could not extract version from Cargo.toml"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ ! -f "$SPEC_FILE" ]; then
|
||||||
|
echo "Error: Spec file not found at ${SPEC_FILE}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update spec file
|
||||||
|
sed -i "s/^%define version.*/%define version ${VERSION}/" "$SPEC_FILE"
|
||||||
|
if git diff --quiet "$SPEC_FILE"; then
|
||||||
|
echo "No changes to spec file"
|
||||||
|
else
|
||||||
|
git add "$SPEC_FILE"
|
||||||
|
git commit --no-verify -m "chore: update spec file version to ${VERSION}"
|
||||||
|
echo "Updated spec file version to ${VERSION}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update translations only if UI files changed
|
||||||
|
if git diff-tree -r HEAD@{1} HEAD --name-only | grep -q "^rog-control-center/ui/"; then
|
||||||
|
echo 'find -name \*.slint | xargs slint-tr-extractor -o ${TRANSLATION}'
|
||||||
|
find -name \*.slint | xargs slint-tr-extractor -o $TRANSLATION
|
||||||
|
if git diff --quiet "$TRANSLATION"; then
|
||||||
|
echo "No changes to translation file"
|
||||||
|
else
|
||||||
|
git add "$TRANSLATION"
|
||||||
|
git commit --no-verify -m "chore: update translations"
|
||||||
|
echo "Updated ${TRANSLATION}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "No changes in rog-control-center/ui/, skipping translation update"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update aura data
|
||||||
|
cargo test --package rog_aura --lib -- aura_detection::tests::check_data_file_parse --exact
|
||||||
|
cargo test --package rog_aura --lib -- aura_detection::tests::find_data_file_groups --exact
|
||||||
|
if git diff --quiet "$AURA_DATA"; then
|
||||||
|
echo "No changes to aura data file"
|
||||||
|
else
|
||||||
|
git add "$AURA_DATA"
|
||||||
|
git commit --no-verify -m "chore: update aura data"
|
||||||
|
echo "Updated $AURA_DATA"
|
||||||
|
fi
|
||||||
@@ -1,18 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo 'find -name \*.slint | xargs slint-tr-extractor -o rog-control-center/translations/en/rog-control-center.po'
|
echo '+cargo fmt --all -- --check'
|
||||||
find -name \*.slint | xargs slint-tr-extractor -o rog-control-center/translations/en/rog-control-center.po
|
cargo fmt --all -- --check
|
||||||
|
git add -u
|
||||||
echo '+cargo +nightly fmt --all -- --check'
|
|
||||||
cargo +nightly fmt --all -- --check
|
|
||||||
|
|
||||||
echo '+cargo clippy --all -- -D warnings'
|
|
||||||
cargo clippy --all -- -D warnings
|
|
||||||
|
|
||||||
echo '+cargo test --all'
|
|
||||||
cargo test --all
|
|
||||||
|
|
||||||
echo '+cargo cranky'
|
|
||||||
cargo cranky
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo '+cargo +nightly fmt --all -- --check'
|
echo '+cargo fmt --all -- --check'
|
||||||
cargo +nightly fmt --all -- --check
|
cargo fmt --all -- --check
|
||||||
echo '+cargo clippy --all -- -D warnings'
|
echo '+cargo clippy --all -- -D warnings'
|
||||||
cargo clippy --all -- -D warnings
|
cargo clippy --all -- -D warnings
|
||||||
echo '+cargo cranky'
|
echo '+cargo cranky'
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,6 +9,7 @@ vendor_*
|
|||||||
.vscode
|
.vscode
|
||||||
.~lock.*
|
.~lock.*
|
||||||
*.ods#
|
*.ods#
|
||||||
|
*.patch
|
||||||
|
|
||||||
# gnome extension
|
# gnome extension
|
||||||
node-modules
|
node-modules
|
||||||
|
|||||||
@@ -1,23 +1,27 @@
|
|||||||
image: rust:latest
|
image: rust:latest
|
||||||
|
|
||||||
|
# Use shallow clone to reduce checkout size
|
||||||
|
variables:
|
||||||
|
GIT_DEPTH: "1"
|
||||||
|
# Put cargo home and target under project dir so we can clean them easily
|
||||||
|
CARGO_HOME: "$CI_PROJECT_DIR/.cargo"
|
||||||
|
CARGO_TARGET_DIR: "$CI_PROJECT_DIR/ci-target"
|
||||||
|
GIT_SUBMODULE_STRATEGY: normal
|
||||||
|
|
||||||
|
# Cache only cargo registries/git metadata to speed dependency fetches.
|
||||||
|
# Avoid caching compiled `target` artifacts which are large and easily fill disk.
|
||||||
.rust_cache: &rust_cache
|
.rust_cache: &rust_cache
|
||||||
cache:
|
cache:
|
||||||
# key: $CI_COMMIT_REF_SLUG
|
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
|
||||||
paths:
|
paths:
|
||||||
# Don't include `incremental` to save space
|
- .cargo/registry
|
||||||
# Debug
|
- .cargo/git
|
||||||
- target/debug/build/
|
|
||||||
- target/debug/deps/
|
|
||||||
- target/debug/.fingerprint/
|
|
||||||
- target/debug/.cargo-lock
|
|
||||||
# Release
|
|
||||||
- target/release/build/
|
|
||||||
- target/release/deps/
|
|
||||||
- target/release/.fingerprint/
|
|
||||||
- target/release/.cargo-lock
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- apt-get update -qq && apt-get install -y -qq libinput-dev libseat-dev libudev-dev libgtk-3-dev grep llvm clang libclang-dev libsdl2-dev libsdl2-gfx-dev
|
- df -h
|
||||||
|
- echo "Cleaning stale targets to free space if present"
|
||||||
|
- rm -rf "$CI_PROJECT_DIR/target" "$CI_PROJECT_DIR/ci-target" || true
|
||||||
|
- apt-get update -qq && apt-get install -y -qq libudev-dev libgtk-3-dev grep llvm clang libclang-dev libsdl2-dev libsdl2-gfx-dev
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- format
|
- format
|
||||||
@@ -31,20 +35,24 @@ format:
|
|||||||
- tags
|
- tags
|
||||||
<<: *rust_cache
|
<<: *rust_cache
|
||||||
script:
|
script:
|
||||||
- echo "nightly" > rust-toolchain
|
- rustup component add rustfmt || true
|
||||||
- rustup component add rustfmt
|
|
||||||
- cargo fmt --check
|
- cargo fmt --check
|
||||||
|
after_script:
|
||||||
|
- du -sh "$CI_PROJECT_DIR/ci-target" || true
|
||||||
|
- rm -rf "$CI_PROJECT_DIR/ci-target" || true
|
||||||
|
|
||||||
check:
|
check:
|
||||||
except:
|
except:
|
||||||
- tags
|
- tags
|
||||||
<<: *rust_cache
|
<<: *rust_cache
|
||||||
script:
|
script:
|
||||||
- rustup component add clippy
|
- rustup component add clippy || true
|
||||||
- cargo check
|
- cargo check --locked --workspace
|
||||||
# deny currently catches too much
|
# deny currently catches too much
|
||||||
#- cargo install cargo-deny && cargo deny
|
#- cargo install cargo-deny && cargo deny
|
||||||
- cargo install cargo-cranky && cargo cranky
|
- cargo install cargo-cranky && cargo cranky
|
||||||
|
after_script:
|
||||||
|
- rm -rf "$CI_PROJECT_DIR/ci-target" || true
|
||||||
|
|
||||||
test:
|
test:
|
||||||
except:
|
except:
|
||||||
@@ -52,7 +60,9 @@ test:
|
|||||||
<<: *rust_cache
|
<<: *rust_cache
|
||||||
script:
|
script:
|
||||||
- mkdir -p .git/hooks > /dev/null
|
- mkdir -p .git/hooks > /dev/null
|
||||||
- cargo test --all
|
- cargo test --locked --all
|
||||||
|
after_script:
|
||||||
|
- rm -rf "$CI_PROJECT_DIR/ci-target" || true
|
||||||
|
|
||||||
release:
|
release:
|
||||||
only:
|
only:
|
||||||
@@ -60,11 +70,15 @@ release:
|
|||||||
<<: *rust_cache
|
<<: *rust_cache
|
||||||
script:
|
script:
|
||||||
- cargo install cargo-vendor-filterer
|
- cargo install cargo-vendor-filterer
|
||||||
- make && make vendor
|
- cargo fetch
|
||||||
|
- make FROZEN=1 && make vendor
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- vendor_asusctl*.tar.xz
|
- vendor_asusctl*.tar.xz
|
||||||
- cargo-config
|
- cargo-config
|
||||||
|
expire_in: 1 week
|
||||||
|
after_script:
|
||||||
|
- rm -rf vendor vendor_asusctl*.tar.xz "$CI_PROJECT_DIR/ci-target" || true
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
@@ -72,14 +86,14 @@ pages:
|
|||||||
- tags
|
- tags
|
||||||
<<: *rust_cache
|
<<: *rust_cache
|
||||||
script:
|
script:
|
||||||
- cargo doc --document-private-items --no-deps --workspace
|
- cargo doc --locked --document-private-items --no-deps --workspace
|
||||||
- rm -rf public
|
- rm -rf public
|
||||||
- mkdir public
|
- mkdir public
|
||||||
- cp -R target/doc/* public
|
- cp -R ci-target/doc/* public
|
||||||
- cp extra/index.html public
|
- cp extra/index.html public
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
expire_in: 1 week
|
||||||
variables:
|
after_script:
|
||||||
GIT_SUBMODULE_STRATEGY: normal
|
- rm -rf "$CI_PROJECT_DIR/ci-target" || true
|
||||||
|
|||||||
316
CHANGELOG.md
316
CHANGELOG.md
@@ -1,12 +1,318 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Added support for TUF keyboard powerstate control
|
||||||
|
- Improved AniMe Matrix support thanks to @Seom1177 !
|
||||||
|
- Fixed a bug with one-shot battery change, thanks @bitr8 !
|
||||||
|
|
||||||
|
|
||||||
|
## [6.2.0]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Added aura support for FX607V: thanks @jomp16
|
||||||
|
- Added testing support for G835LW
|
||||||
|
- Added support for GU605C models slash lighting: thanks @Otters
|
||||||
|
- Restore fedora: thanks @ali205412
|
||||||
|
- Add support to G614F models slash lighting
|
||||||
|
|
||||||
|
## [6.1.22]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Allow configuration of nv_tgp
|
||||||
|
- Treat dGPU attributes as power profiles
|
||||||
|
- Add EXPERTBOOK DMI match to ensure the service is loaded
|
||||||
|
- Support G815L thanks to @solost !
|
||||||
|
|
||||||
|
## [6.1.21]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Kill Fedora: screw your cursed cargo bullshit
|
||||||
|
- Restore CI building
|
||||||
|
|
||||||
|
## [6.1.20]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Addded support for G635L: thanks @luca_pisl !
|
||||||
|
- Suppress verbose output in applications too, not just daemon
|
||||||
|
|
||||||
|
## [6.1.18]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Add aura support for G614FR (ROG Strix G16 2025)
|
||||||
|
- all notifications now respects the timeout
|
||||||
|
- improve udev daemon-starting rule
|
||||||
|
- reduce log noise
|
||||||
|
|
||||||
|
## [v6.1.17]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix Makefile
|
||||||
|
- Share a single HID device
|
||||||
|
|
||||||
|
## [v6.1.16]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Expose more properties via rog-control-center
|
||||||
|
- Add support for a few more models
|
||||||
|
|
||||||
|
## [v6.1.15]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Reflect the current asus-armoury status on AC plug connection status change
|
||||||
|
|
||||||
|
## [v6.1.14]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix formatting
|
||||||
|
- Attempt to fix tests
|
||||||
|
|
||||||
|
## [v6.1.13]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix a problem in reloading the service (@evertvorster)
|
||||||
|
- Add Azerbaijani language (@rashadgasimli)
|
||||||
|
- Add Ubuntu installation instructions
|
||||||
|
|
||||||
|
## [v6.1.12]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix an unbounded event loop caused by other processes causing a "modify" event on the screen backlight brightness.
|
||||||
|
|
||||||
|
## [v6.1.11]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix anime flickering issue when using custom anims (@I-Al-Istannen)
|
||||||
|
- Include pt_BR translations file (@PabloKiryu)
|
||||||
|
|
||||||
|
## Added
|
||||||
|
- Support for the screenpad brightness on some Laptops. This includes syncing to the primary screen brightness, and a gamma adjustment to set brightness scaling.
|
||||||
|
- Add asusctl CLI options
|
||||||
|
- Add UI options
|
||||||
|
- Add a fake gamma correction (`asusctl backlight --sync-screenpad-brightness`, 1.5 for example sets screenpad low brightness lower than primary, and scales upwards)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- asusd: single line fix for profile switching
|
||||||
|
|
||||||
|
## [v6.1.9]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- ROGCC: better handling of platform profiles
|
||||||
|
|
||||||
|
## [v6.1.8]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Testing CI for opensuse RPM build
|
||||||
|
- ROGCC: Fixes to showing the PPT enablement toggle
|
||||||
|
- ROGCC: Fixes to how PPT and NV sliders work and enable/disable
|
||||||
|
- RGOCC: Fix quiet fan-curves availability
|
||||||
|
|
||||||
|
## [v6.1.7]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix Slash display enable
|
||||||
|
|
||||||
|
## [v6.1.6]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Disable skia bindings for UI again. It causes failures in build pipelines and requires extra dependencies.
|
||||||
|
|
||||||
|
## [v6.1.5]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Update dependencies
|
||||||
|
- Fix fan-curve proxy type signatures
|
||||||
|
|
||||||
|
## [v6.1.4]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix git doing me a dirty
|
||||||
|
|
||||||
|
## [v6.1.3]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Many small bugfixes such as for platform profile switching
|
||||||
|
|
||||||
|
## [v6.1.2]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Try a slightly different tact to fix charge control slider
|
||||||
|
|
||||||
|
## [v6.1.1]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix aura data matching
|
||||||
|
- Fix charge control slider
|
||||||
|
|
||||||
|
## [v6.1.0]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Update deps
|
||||||
|
- Add support for G513RC RGB modes
|
||||||
|
- Many UI fixes
|
||||||
|
- Fixes to PPT settings in UI
|
||||||
|
|
||||||
|
## [v6.1.0-rc7]
|
||||||
|
|
||||||
|
- Refactor PPT handling more:
|
||||||
|
1. Per profile, per-ac/dc
|
||||||
|
2. Do not apply unless group is enabled
|
||||||
|
3. Better reset/disable handling
|
||||||
|
4. Selecting a profile defaults PPT to off/disabled
|
||||||
|
- Bugfix: prevent an AniMe thread async deadlock
|
||||||
|
|
||||||
|
## [v6.1.0-rc6]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Two small fixes, one for `low-power` profile name, and one for base gpu tdp
|
||||||
|
- Move to using platform_profile api only (no throttle_thermal_policy)
|
||||||
|
|
||||||
|
## [v6.1.0-rc5]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Per-AC/DC, per-profile tunings enabled (Battery vs AC power + platform profile)
|
||||||
|
- Add ability to restore PPT defaults
|
||||||
|
- Add PPT help dialogue to UI
|
||||||
|
- Bug fix: correctly set charge limit from UI
|
||||||
|
|
||||||
|
## [v6.1.0-rc4]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Bug fix: UI was setting incorrect value for FPPT
|
||||||
|
- Bug fix: Re-add callbacks for the throttle and epp settings in UI
|
||||||
|
- Bug fix: Fix UI settigns for AniMe Matrix display
|
||||||
|
- Bug fix: better handle missing tray (for example gnome)
|
||||||
|
- Strip out all outdated and unsafe tuning stuff
|
||||||
|
- Allow each performance profile to have different PPT settings
|
||||||
|
|
||||||
|
## [v6.1.0-rc3]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Bug fixes
|
||||||
|
- Partial support for per-profile CPU tunings (WIP)
|
||||||
|
|
||||||
|
## [v6.1.0-rc2]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- asus-armoury driver support. WIP, will be adjusted/changed further
|
||||||
|
- More "Slash" display controls
|
||||||
|
|
||||||
|
## [v6.1.0-rc1]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- ROG Arion external driver LED support
|
||||||
|
- Add GA605W LED layout
|
||||||
|
- Add GA605 + GU605 Slash support
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fix attribute writes. At some point the kernel API seems to have changed.
|
||||||
|
- Extremely large refactor of Aura device handling. Should enable easy add of different kinds now.
|
||||||
|
- Rename CLI args for aura related properties. This will likely change further as more devices are added
|
||||||
|
|
||||||
|
## [v6.0.12]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Add Ally X aura config
|
||||||
|
- Fixes to Ally led power configs
|
||||||
|
- Fix CLI led modes
|
||||||
|
- Add FX517Z to aura_support
|
||||||
|
- Add G614JJ Aura support
|
||||||
|
- Add G614JZ (2023 Strix G16) Aura support
|
||||||
|
|
||||||
|
## [v6.0.11]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Renamed `Strobe` effect to `RainbowCycle` to prevent confusion over what it is
|
||||||
|
- Ranamed `Rainbow` effect to `RainbowWave`
|
||||||
|
- Cleaned up serde crate deps
|
||||||
|
- Fixed AniMe on GA402XZ
|
||||||
|
- Update some of the G713 device aura features
|
||||||
|
- Update some of the G513 device aura features
|
||||||
|
|
||||||
|
## [v6.0.10]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Add the GA401I model to aura_support.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Aura support return a default aura definition instead of nothing
|
||||||
|
- Minor updates in aura controller to ensure configs are updated if the support file changes
|
||||||
|
- Don't panic if -ENODEV on fan_curve enable
|
||||||
|
- Adjust the G513Q support to match what is on the asus website.
|
||||||
|
- Adjust init sequence of anime to prevent accidental use of Slash as Anime
|
||||||
|
- Enable notifs and tray icon without supergfx
|
||||||
|
|
||||||
|
## [v6.0.9]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add G513RS to laptop DB.
|
||||||
|
- Add G512LI to laptop DB.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Rename and recreate the default Anime config if cache setup fails
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Nuke the issue of GUI taking 100% of a CPU core
|
||||||
|
|
||||||
|
## [v6.0.8]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Add G512L laptop DB entry
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Add more tests to verify things
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
- asusctl incorrectly assumes fan-curves unsupported. Now fixed.
|
||||||
|
- try to fix ROGCC using CPU time.
|
||||||
|
|
||||||
|
## [v6.0.7]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Add a config option to set if throttle policy is changed on ac/bat change (UI only)
|
||||||
|
- Allow X11 GUI. This is *not* supported. Please see readme.
|
||||||
|
- Fixes to some GUI widget layouts and sizing
|
||||||
|
- Do a backup HID raw write fro brightness if the read-back value does not match. This is a temporary solve for some G14 and G16 until the kernel patch is ready.
|
||||||
|
- Reimplement the older 0x1866 MCU keyboard control power bits plus UI control for it. If you had a keyboard affected by Lightbar issues and it is older than a couple of years this should help. If not, please file a bug.
|
||||||
|
|
||||||
|
## [v6.0.6]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Add GX650R laptop to aura DB
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Further tweaks to aura init
|
||||||
|
- More logging
|
||||||
|
- Fix TUF laptop led power
|
||||||
|
- Sanitize the dbus path for aura devices (remove `.` chars)
|
||||||
|
- Even more error handling (gracefully)
|
||||||
|
- Better checking for dbus interfaces
|
||||||
|
- Remove dbus `supported_interfaces`
|
||||||
|
- dbus ObjectManager is now at root `/`
|
||||||
|
|
||||||
|
## [v6.0.5]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Better more robust error handling in ROGCC
|
||||||
|
- Try to better handle pre-2021 laptops with lightbar
|
||||||
|
- Add more logging to try and trace the charge_control_end_threshold issue
|
||||||
|
- Make `kbd_brightness` optional to work around issues on some laptops that seem to lack it. Likely this will all need a refactor *again* if work proceeds in kernel for better RGB support.
|
||||||
|
|
||||||
|
## [v6.0.4]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Remove some `todo()` in rogcc
|
||||||
|
- Add missing `#[zbus(property)]` derive to Slash dbus properties
|
||||||
|
- Match G533Q laptop explicitly to the 0x8166 PID
|
||||||
|
|
||||||
## [v6.0.3]
|
## [v6.0.3]
|
||||||
|
|
||||||
### NOTE
|
### NOTE
|
||||||
|
|||||||
5449
Cargo.lock
generated
5449
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
91
Cargo.toml
91
Cargo.toml
@@ -1,32 +1,6 @@
|
|||||||
[workspace]
|
|
||||||
members = [
|
|
||||||
"asusctl",
|
|
||||||
"asusd",
|
|
||||||
"asusd-user",
|
|
||||||
"config-traits",
|
|
||||||
"cpuctl",
|
|
||||||
"dmi-id",
|
|
||||||
"rog-platform",
|
|
||||||
"rog-dbus",
|
|
||||||
"rog-anime",
|
|
||||||
"rog-aura",
|
|
||||||
"rog-profiles",
|
|
||||||
"rog-control-center",
|
|
||||||
"rog-slash",
|
|
||||||
"simulators",
|
|
||||||
]
|
|
||||||
default-members = [
|
|
||||||
"asusctl",
|
|
||||||
"asusd",
|
|
||||||
"asusd-user",
|
|
||||||
"cpuctl",
|
|
||||||
"rog-control-center",
|
|
||||||
]
|
|
||||||
resolver = "2"
|
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "6.0.3"
|
version = "6.2.0"
|
||||||
rust-version = "1.77"
|
rust-version = "1.82"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Luke <luke@ljones.dev>"]
|
authors = ["Luke <luke@ljones.dev>"]
|
||||||
@@ -35,25 +9,46 @@ homepage = "https://gitlab.com/asus-linux/asusctl"
|
|||||||
description = "Laptop feature control for ASUS ROG laptops and others"
|
description = "Laptop feature control for ASUS ROG laptops and others"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
|
members = [
|
||||||
|
"asusctl",
|
||||||
|
"asusd",
|
||||||
|
"asusd-user",
|
||||||
|
"config-traits",
|
||||||
|
"dmi-id",
|
||||||
|
"rog-platform",
|
||||||
|
"rog-dbus",
|
||||||
|
"rog-anime",
|
||||||
|
"rog-aura",
|
||||||
|
"rog-profiles",
|
||||||
|
"rog-control-center",
|
||||||
|
"rog-slash",
|
||||||
|
"simulators",
|
||||||
|
"rog-scsi",
|
||||||
|
]
|
||||||
|
|
||||||
|
default-members = ["asusctl", "asusd", "asusd-user", "rog-control-center"]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
tokio = { version = "^1.36.0", default-features = false, features = [
|
tokio = { version = "^1.39.0", default-features = false, features = [
|
||||||
"macros",
|
"macros",
|
||||||
"sync",
|
"sync",
|
||||||
"time",
|
"time",
|
||||||
"rt-multi-thread",
|
"rt",
|
||||||
|
"rt-multi-thread",
|
||||||
] }
|
] }
|
||||||
concat-idents = "^1.1"
|
concat-idents = "^1.1"
|
||||||
dirs = "^4.0"
|
dirs = "^4.0"
|
||||||
smol = "^1.3"
|
smol = "^2.0"
|
||||||
mio = "0.8.11"
|
mio = "0.8.11"
|
||||||
|
|
||||||
zbus = "4.1"
|
futures-util = "0.3.31"
|
||||||
logind-zbus = { version = "4.0.2" } #, default-features = false, features = ["non_blocking"] }
|
zbus = "5.13.1"
|
||||||
|
logind-zbus = { version = "5.2.0" } #, default-features = false, features = ["non_blocking"] }
|
||||||
|
|
||||||
serde = "^1.0"
|
serde = { version = "^1.0", features = ["serde_derive"] }
|
||||||
serde_derive = "^1.0"
|
|
||||||
ron = "*"
|
ron = "*"
|
||||||
typeshare = "1.0.0"
|
|
||||||
|
|
||||||
log = "^0.4"
|
log = "^0.4"
|
||||||
env_logger = "^0.10.0"
|
env_logger = "^0.10.0"
|
||||||
@@ -62,18 +57,18 @@ glam = { version = "^0.22", features = ["serde"] }
|
|||||||
gumdrop = "^0.8"
|
gumdrop = "^0.8"
|
||||||
udev = { version = "^0.8", features = ["mio"] }
|
udev = { version = "^0.8", features = ["mio"] }
|
||||||
rusb = "^0.9"
|
rusb = "^0.9"
|
||||||
inotify = "^0.10.0"
|
inotify = "^0.10"
|
||||||
|
|
||||||
png_pong = "^0.8"
|
png_pong = "^0.8"
|
||||||
pix = "^0.13"
|
pix = "^0.13"
|
||||||
tinybmp = "^0.4.0"
|
tinybmp = "^0.4"
|
||||||
gif = "^0.12.0"
|
gif = "^0.12"
|
||||||
|
|
||||||
versions = "6.2"
|
versions = "6.2"
|
||||||
|
|
||||||
notify-rust = { git = "https://github.com/flukejones/notify-rust.git", rev = "54176413b81189a3e4edbdc20a0b4f7e2e35c063", default-features = false, features = [
|
notify-rust = { version = "4.11.5", features = ["z", "async"] }
|
||||||
"z",
|
|
||||||
] }
|
sg = { git = "https://github.com/flukejones/sg-rs.git" }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
# thin = 57s, asusd = 9.0M
|
# thin = 57s, asusd = 9.0M
|
||||||
@@ -82,15 +77,15 @@ lto = "fat"
|
|||||||
debug = false
|
debug = false
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
codegen-units = 1
|
# codegen-units = 1
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = 1
|
opt-level = 1
|
||||||
codegen-units = 16
|
# codegen-units = 1
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
[profile.dev.package."*"]
|
||||||
opt-level = 1
|
opt-level = 1
|
||||||
codegen-units = 16
|
# codegen-units = 1
|
||||||
|
|
||||||
[profile.bench]
|
[profile.bench]
|
||||||
debug = false
|
debug = false
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ The LED controller (e.g, aura) enables setting many of the factory modes availab
|
|||||||
|
|
||||||
#### Supported laptops
|
#### Supported laptops
|
||||||
|
|
||||||
There are over 60 supported laptops as of 01-01-2023. Please see [the rog-aura crate readme for further details](/rog-aura/README.md).
|
There are over 80 supported laptops as of 01-01-2023. Please see [the rog-aura crate readme for further details](/rog-aura/README.md).
|
||||||
|
|
||||||
### Charge control
|
### Charge control
|
||||||
|
|
||||||
@@ -420,13 +420,13 @@ To switch to next/previous Aura modes you will need to bind both the aura keys (
|
|||||||
**Next**
|
**Next**
|
||||||
|
|
||||||
```
|
```
|
||||||
asusctl led-mode -n
|
asusctl aura -n
|
||||||
```
|
```
|
||||||
|
|
||||||
**Previous**
|
**Previous**
|
||||||
|
|
||||||
```
|
```
|
||||||
asusctl led-mode -p
|
asusctl aura -p
|
||||||
```
|
```
|
||||||
|
|
||||||
To switch Fan/Thermal profiles you need to bind the Fn+F5 key to `asusctl profile -n`.
|
To switch Fan/Thermal profiles you need to bind the Fn+F5 key to `asusctl profile -n`.
|
||||||
|
|||||||
85
Makefile
85
Makefile
@@ -1,4 +1,4 @@
|
|||||||
VERSION := $(shell /usr/bin/grep -Pm1 'version = "(\d.\d.\d)"' Cargo.toml | cut -d'"' -f2)
|
VERSION := $(shell /usr/bin/grep -Pm1 'version = "(\d+.\d+.\d+.*)"' Cargo.toml | cut -d'"' -f2)
|
||||||
|
|
||||||
INSTALL = install
|
INSTALL = install
|
||||||
INSTALL_PROGRAM = ${INSTALL} -D -m 0755
|
INSTALL_PROGRAM = ${INSTALL} -D -m 0755
|
||||||
@@ -17,6 +17,8 @@ BIN_D := asusd
|
|||||||
BIN_U := asusd-user
|
BIN_U := asusd-user
|
||||||
LEDCFG := aura_support.ron
|
LEDCFG := aura_support.ron
|
||||||
|
|
||||||
|
DESTDIR_REALPATH = $(shell realpath $(DESTDIR))
|
||||||
|
|
||||||
SRC := Cargo.toml Cargo.lock Makefile $(shell find -type f -wholename '**/src/*.rs')
|
SRC := Cargo.toml Cargo.lock Makefile $(shell find -type f -wholename '**/src/*.rs')
|
||||||
|
|
||||||
STRIP_BINARIES ?= 0
|
STRIP_BINARIES ?= 0
|
||||||
@@ -30,6 +32,20 @@ else
|
|||||||
TARGET = debug
|
TARGET = debug
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
X11 ?= 0
|
||||||
|
ifeq ($(X11),1)
|
||||||
|
ARGS += --features "rog-control-center/x11"
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Always use the versions in Cargo.lock by default
|
||||||
|
ARGS += --locked
|
||||||
|
|
||||||
|
# Allow optionally freezing the build to avoid any network access and enforce Cargo.lock strictly
|
||||||
|
FROZEN ?= 0
|
||||||
|
ifeq ($(FROZEN),1)
|
||||||
|
ARGS += --frozen
|
||||||
|
endif
|
||||||
|
|
||||||
VENDORED ?= 0
|
VENDORED ?= 0
|
||||||
ifeq ($(VENDORED),1)
|
ifeq ($(VENDORED),1)
|
||||||
ARGS += --frozen
|
ARGS += --frozen
|
||||||
@@ -43,24 +59,38 @@ clean:
|
|||||||
distclean:
|
distclean:
|
||||||
rm -rf .cargo vendor vendor.tar.xz
|
rm -rf .cargo vendor vendor.tar.xz
|
||||||
|
|
||||||
install-program:
|
target/$(TARGET)/$(BIN_D): $(SRC)
|
||||||
$(INSTALL_PROGRAM) "./target/$(TARGET)/$(BIN_ROG)" "$(DESTDIR)$(bindir)/$(BIN_ROG)"
|
$(MAKE) build
|
||||||
|
|
||||||
$(INSTALL_PROGRAM) "./target/$(TARGET)/$(BIN_C)" "$(DESTDIR)$(bindir)/$(BIN_C)"
|
target/$(TARGET)/$(BIN_C): $(SRC)
|
||||||
|
$(MAKE) build
|
||||||
|
|
||||||
|
target/$(TARGET)/$(BIN_U): $(SRC)
|
||||||
|
$(MAKE) build
|
||||||
|
|
||||||
|
target/$(TARGET)/$(BIN_ROG): $(SRC)
|
||||||
|
$(MAKE) build
|
||||||
|
|
||||||
|
install-asusd: target/$(TARGET)/$(BIN_D)
|
||||||
$(INSTALL_PROGRAM) "./target/$(TARGET)/$(BIN_D)" "$(DESTDIR)$(bindir)/$(BIN_D)"
|
$(INSTALL_PROGRAM) "./target/$(TARGET)/$(BIN_D)" "$(DESTDIR)$(bindir)/$(BIN_D)"
|
||||||
|
|
||||||
|
install-asusctl: target/$(TARGET)/$(BIN_C)
|
||||||
|
$(INSTALL_PROGRAM) "./target/$(TARGET)/$(BIN_C)" "$(DESTDIR)$(bindir)/$(BIN_C)"
|
||||||
|
|
||||||
|
install-asusd_user: target/$(TARGET)/$(BIN_U)
|
||||||
$(INSTALL_PROGRAM) "./target/$(TARGET)/$(BIN_U)" "$(DESTDIR)$(bindir)/$(BIN_U)"
|
$(INSTALL_PROGRAM) "./target/$(TARGET)/$(BIN_U)" "$(DESTDIR)$(bindir)/$(BIN_U)"
|
||||||
|
|
||||||
install-data:
|
install-rog_gui: target/$(TARGET)/$(BIN_ROG)
|
||||||
|
$(INSTALL_PROGRAM) "./target/$(TARGET)/$(BIN_ROG)" "$(DESTDIR)$(bindir)/$(BIN_ROG)"
|
||||||
|
|
||||||
|
.PHONY: install-asusd install-asusctl install-asusd_user install-rog_gui
|
||||||
|
|
||||||
|
install-program: install-asusd install-asusctl install-asusd_user install-rog_gui
|
||||||
|
|
||||||
|
install-data-rog_gui:
|
||||||
$(INSTALL_DATA) "./rog-control-center/data/$(BIN_ROG).desktop" "$(DESTDIR)$(datarootdir)/applications/$(BIN_ROG).desktop"
|
$(INSTALL_DATA) "./rog-control-center/data/$(BIN_ROG).desktop" "$(DESTDIR)$(datarootdir)/applications/$(BIN_ROG).desktop"
|
||||||
$(INSTALL_DATA) "./rog-control-center/data/$(BIN_ROG).png" "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/$(BIN_ROG).png"
|
$(INSTALL_DATA) "./rog-control-center/data/$(BIN_ROG).png" "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/$(BIN_ROG).png"
|
||||||
cd rog-aura/data/layouts && find . -type f -name "*.ron" -exec $(INSTALL_DATA) "{}" "$(DESTDIR)$(datarootdir)/rog-gui/layouts/{}" \;
|
cd rog-aura/data/layouts && find . -type f -name "*.ron" -exec $(INSTALL_DATA) "{}" "$(DESTDIR_REALPATH)$(datarootdir)/rog-gui/layouts/{}" \;
|
||||||
|
|
||||||
$(INSTALL_DATA) "./data/$(BIN_D).rules" "$(DESTDIR)$(libdir)/udev/rules.d/99-$(BIN_D).rules"
|
|
||||||
$(INSTALL_DATA) "./rog-aura/data/$(LEDCFG)" "$(DESTDIR)$(datarootdir)/asusd/$(LEDCFG)"
|
|
||||||
$(INSTALL_DATA) "./data/$(BIN_D).conf" "$(DESTDIR)$(datarootdir)/dbus-1/system.d/$(BIN_D).conf"
|
|
||||||
|
|
||||||
$(INSTALL_DATA) "./data/$(BIN_D).service" "$(DESTDIR)$(libdir)/systemd/system/$(BIN_D).service"
|
|
||||||
$(INSTALL_DATA) "./data/$(BIN_U).service" "$(DESTDIR)$(libdir)/systemd/user/$(BIN_U).service"
|
|
||||||
|
|
||||||
$(INSTALL_DATA) "./data/icons/asus_notif_yellow.png" "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/asus_notif_yellow.png"
|
$(INSTALL_DATA) "./data/icons/asus_notif_yellow.png" "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/asus_notif_yellow.png"
|
||||||
$(INSTALL_DATA) "./data/icons/asus_notif_green.png" "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/asus_notif_green.png"
|
$(INSTALL_DATA) "./data/icons/asus_notif_green.png" "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/asus_notif_green.png"
|
||||||
@@ -76,9 +106,24 @@ install-data:
|
|||||||
$(INSTALL_DATA) "./data/icons/scalable/gpu-vfio.svg" "$(DESTDIR)$(datarootdir)/icons/hicolor/scalable/status/gpu-vfio.svg"
|
$(INSTALL_DATA) "./data/icons/scalable/gpu-vfio.svg" "$(DESTDIR)$(datarootdir)/icons/hicolor/scalable/status/gpu-vfio.svg"
|
||||||
$(INSTALL_DATA) "./data/icons/scalable/notification-reboot.svg" "$(DESTDIR)$(datarootdir)/icons/hicolor/scalable/status/notification-reboot.svg"
|
$(INSTALL_DATA) "./data/icons/scalable/notification-reboot.svg" "$(DESTDIR)$(datarootdir)/icons/hicolor/scalable/status/notification-reboot.svg"
|
||||||
|
|
||||||
cd rog-anime/data && find "./anime" -type f -exec $(INSTALL_DATA) "{}" "$(DESTDIR)$(datarootdir)/asusd/{}" \;
|
install-data-asusd:
|
||||||
|
$(INSTALL_DATA) "./data/$(BIN_D).rules" "$(DESTDIR)$(libdir)/udev/rules.d/99-$(BIN_D).rules"
|
||||||
|
$(INSTALL_DATA) "./rog-aura/data/$(LEDCFG)" "$(DESTDIR)$(datarootdir)/asusd/$(LEDCFG)"
|
||||||
|
$(INSTALL_DATA) "./data/$(BIN_D).conf" "$(DESTDIR)$(datarootdir)/dbus-1/system.d/$(BIN_D).conf"
|
||||||
|
|
||||||
|
$(INSTALL_DATA) "./data/$(BIN_D).service" "$(DESTDIR)$(libdir)/systemd/system/$(BIN_D).service"
|
||||||
|
|
||||||
|
cd rog-anime/data && find "./anime" -type f -exec $(INSTALL_DATA) "{}" "$(DESTDIR_REALPATH)$(datarootdir)/asusd/{}" \;
|
||||||
|
|
||||||
|
install-data-asusd_user:
|
||||||
|
$(INSTALL_DATA) "./data/$(BIN_U).service" "$(DESTDIR)$(libdir)/systemd/user/$(BIN_U).service"
|
||||||
|
|
||||||
|
.PHONY: install-data-asusd install-data-asusd_user
|
||||||
|
|
||||||
|
install-data: install-data-asusd install-data-asusd_user install-data-rog_gui
|
||||||
|
|
||||||
install: install-program install-data
|
install: install-program install-data
|
||||||
|
$(INSTALL_DATA) "./LICENSE" "$(DESTDIR)$(datarootdir)/asusctl/LICENSE"
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f "$(DESTDIR)$(bindir)/$(BIN_ROG)"
|
rm -f "$(DESTDIR)$(bindir)/$(BIN_ROG)"
|
||||||
@@ -113,16 +158,12 @@ vendor:
|
|||||||
mv .cargo/config ./cargo-config
|
mv .cargo/config ./cargo-config
|
||||||
rm -rf .cargo
|
rm -rf .cargo
|
||||||
rm -rf vendor
|
rm -rf vendor
|
||||||
cargo vendor-filterer --platform x86_64-unknown-linux-gnu vendor
|
# Ensure cargo-vendor-filterer is installed (CI installs it already)
|
||||||
|
command -v cargo-vendor-filterer >/dev/null 2>&1 || cargo install --locked cargo-vendor-filterer
|
||||||
|
cargo vendor-filterer --all-features --platform x86_64-unknown-linux-gnu vendor
|
||||||
tar pcfJ vendor_asusctl_$(VERSION).tar.xz vendor
|
tar pcfJ vendor_asusctl_$(VERSION).tar.xz vendor
|
||||||
rm -rf vendor
|
rm -rf vendor
|
||||||
|
|
||||||
bindings:
|
|
||||||
typeshare ./rog-anime/src/ --lang=typescript --output-file=bindings/ts/anime.ts
|
|
||||||
typeshare ./rog-aura/src/ --lang=typescript --output-file=bindings/ts/aura.ts
|
|
||||||
typeshare ./rog-profiles/src/ --lang=typescript --output-file=bindings/ts/profiles.ts
|
|
||||||
typeshare ./rog-platform/src/ --lang=typescript --output-file=bindings/ts/platform.ts
|
|
||||||
|
|
||||||
translate:
|
translate:
|
||||||
find -name \*.slint | xargs slint-tr-extractor -o rog-control-center/translations/en/rog-control-center.po
|
find -name \*.slint | xargs slint-tr-extractor -o rog-control-center/translations/en/rog-control-center.po
|
||||||
|
|
||||||
@@ -133,7 +174,7 @@ ifeq ($(VENDORED),1)
|
|||||||
tar pxf vendor_asusctl_$(VERSION).tar.xz
|
tar pxf vendor_asusctl_$(VERSION).tar.xz
|
||||||
endif
|
endif
|
||||||
cargo build $(ARGS)
|
cargo build $(ARGS)
|
||||||
ifneq ($(STRIP_BINARIES),0)
|
ifeq ($(STRIP_BINARIES),1)
|
||||||
strip -s ./target/$(TARGET)/$(BIN_C)
|
strip -s ./target/$(TARGET)/$(BIN_C)
|
||||||
strip -s ./target/$(TARGET)/$(BIN_D)
|
strip -s ./target/$(TARGET)/$(BIN_D)
|
||||||
strip -s ./target/$(TARGET)/$(BIN_U)
|
strip -s ./target/$(TARGET)/$(BIN_U)
|
||||||
|
|||||||
77
README.md
77
README.md
@@ -1,6 +1,6 @@
|
|||||||
# `asusctl` for ASUS ROG
|
# `asusctl` for ASUS ROG
|
||||||
|
|
||||||
[Become a Patron!](https://www.patreon.com/bePatron?u=7602281) - [Asus Linux Website](https://asus-linux.org/)
|
[](https://www.patreon.com/bePatron?u=7602281) [](https://ko-fi.com/V7V5CLU67) - [Asus Linux Website](https://asus-linux.org/)
|
||||||
|
|
||||||
**WARNING:** Many features are developed in tandem with kernel patches. If you see a feature is missing you either need a patched kernel or latest release.
|
**WARNING:** Many features are developed in tandem with kernel patches. If you see a feature is missing you either need a patched kernel or latest release.
|
||||||
|
|
||||||
@@ -11,10 +11,16 @@ Now includes a GUI, `rog-control-center`.
|
|||||||
|
|
||||||
## Kernel support
|
## Kernel support
|
||||||
|
|
||||||
**The minimum supported kernel version is 6.10**, which will contain the patches from [here](https://lore.kernel.org/platform-driver-x86/20240404001652.86207-1-luke@ljones.dev/). This is especially required for 2023+ devices and possibly some lat 2022 devices.
|
Due to on-going driver work the minimum suggested kernel version is always **the latest*, as improvements and fixes are continuous.
|
||||||
|
|
||||||
|
Support for some new features is not avilable unless you run a patched kernel with the work I am doing [in this github repo](https://github.com/flukejones/linux/tree/wip/ally-6.13). Use the linked branch, or `wip/ally-6.12`. Everything that is done here is upstreamed eventually (a long process).
|
||||||
|
|
||||||
Z13 devices will need [these](https://lore.kernel.org/linux-input/20240416090402.31057-1-luke@ljones.dev/T/#t)
|
Z13 devices will need [these](https://lore.kernel.org/linux-input/20240416090402.31057-1-luke@ljones.dev/T/#t)
|
||||||
|
|
||||||
|
## X11 support
|
||||||
|
|
||||||
|
X11 is not supported at all, as in I will not help you with X11 issues if there are any due to limited time and it being unmaintained itself. You can however build `rog-control-center` with it enabled `cargo build --features "rog-control-center/x11"`.
|
||||||
|
|
||||||
## Goals
|
## Goals
|
||||||
|
|
||||||
The main goal of this work is to provide a safe and easy to use abstraction over various laptop features via DBUS, and to provide some helpful defaults and other behaviour such as toggling throttle/profile on AC/battery change.
|
The main goal of this work is to provide a safe and easy to use abstraction over various laptop features via DBUS, and to provide some helpful defaults and other behaviour such as toggling throttle/profile on AC/battery change.
|
||||||
@@ -33,20 +39,20 @@ See the [rog-aura readme](./rog-aura/README.md) for more details.
|
|||||||
|
|
||||||
## Discord
|
## Discord
|
||||||
|
|
||||||
[](https://discord.gg/z8y99XqPb7)
|
[](https://discord.gg/B8GftRW2Hd)
|
||||||
|
|
||||||
## SUPPORTED LAPTOPS
|
## SUPPORTED LAPTOPS
|
||||||
|
|
||||||
Most ASUS gaming laptops that have a USB keyboard. If `lsusb` shows something similar
|
Most ASUS gaming laptops that have a USB keyboard. If `lsusb` shows something similar
|
||||||
to this:
|
to this:
|
||||||
|
|
||||||
```
|
```plain
|
||||||
Bus 001 Device 002: ID 0b05:1866 ASUSTek Computer, Inc. N-KEY Device
|
Bus 001 Device 002: ID 0b05:1866 ASUSTek Computer, Inc. N-KEY Device
|
||||||
```
|
```
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
```
|
```plain
|
||||||
Bus 003 Device 002: ID 0b05:19b6 ASUSTek Computer, Inc. [unknown]
|
Bus 003 Device 002: ID 0b05:19b6 ASUSTek Computer, Inc. [unknown]
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -68,33 +74,56 @@ The list is a bit outdated as many features have been enabled in the Linux kerne
|
|||||||
- [x] Toggle bios setting for boot/POST sound
|
- [x] Toggle bios setting for boot/POST sound
|
||||||
- [x] Toggle GPU MUX (g-sync, or called MUX on 2022+ laptops)
|
- [x] Toggle GPU MUX (g-sync, or called MUX on 2022+ laptops)
|
||||||
|
|
||||||
# GUI
|
## GUI
|
||||||
|
|
||||||
A gui is now in the repo - ROG Control Center. At this time it is still a WIP, but it has almost all features in place already.
|
A gui is now in the repo - ROG Control Center. At this time it is still a WIP, but it has almost all features in place already.
|
||||||
|
|
||||||
# BUILDING
|
**NOTE**: Xorg is not supported.
|
||||||
|
|
||||||
Rust and cargo are required, they can be installed from [rustup.rs](https://rustup.rs/) or from the distro repos if newer than 1.75.
|
## BUILDING
|
||||||
|
|
||||||
|
Rust and cargo are required, they can be installed from [rustup.rs](https://rustup.rs/).
|
||||||
|
|
||||||
|
Distro packaging should work with the stable toolchain. If your distro does not provide a recent Rust toolchain, install rustup and use the stable toolchain.
|
||||||
|
|
||||||
**fedora:**
|
**fedora:**
|
||||||
|
|
||||||
dnf install cmake clang-devel libinput-devel libseat-devel libgbm-devel libxkbcommon-devel systemd-devel \
|
```sh
|
||||||
libdrm-devel expat-devel pcre2-devel libzstd-devel libappindicator-gtk3
|
dnf install cmake clang-devel libxkbcommon-devel systemd-devel expat-devel pcre2-devel libzstd-devel gtk3-devel
|
||||||
make
|
make
|
||||||
sudo make install
|
sudo make install
|
||||||
|
```
|
||||||
|
|
||||||
**openSUSE:**
|
**openSUSE:**
|
||||||
|
|
||||||
Works with KDE Plasma (without GTK packages)
|
Works with KDE Plasma (without GTK packages)
|
||||||
|
|
||||||
zypper in -t pattern devel_basis
|
```sh
|
||||||
zypper in rustup make cmake libinput-devel libseat-devel libgbm-devel systemd-devel clang-devel llvm-devel gdk-pixbuf-devel cairo-devel pango-devel freetype-devel libexpat-devel libayatana-indicator3-7
|
zypper in -t pattern devel_basis
|
||||||
make
|
zypper in rustup make cmake clang-devel libxkbcommon-devel systemd-devel expat-devel pcre2-devel libzstd-devel gtk3-devel
|
||||||
sudo make install
|
make
|
||||||
|
sudo make install
|
||||||
|
```
|
||||||
|
|
||||||
|
**Debian(unsuported):**
|
||||||
|
|
||||||
|
officially unsuported,but you can still try and test it by yourself(some features may not be available).
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo apt install libclang-dev libudev-dev libfontconfig-dev build-essential cmake libxkbcommon-dev
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
```
|
||||||
|
|
||||||
**Ubuntu, Popos (unsuported):**
|
**Ubuntu, Popos (unsuported):**
|
||||||
|
|
||||||
instructions removed as outdated
|
```sh
|
||||||
|
sudo apt install make cargo gcc pkg-config openssl libasound2-dev cmake build-essential python3 libfreetype6-dev libexpat1-dev libxcb-composite0-dev libssl-dev libx11-dev libfontconfig1-dev curl libclang-dev libudev-dev checkinstall libseat-dev libinput-dev libxkbcommon-dev libgbm-dev
|
||||||
|
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
```
|
||||||
|
|
||||||
## Installing
|
## Installing
|
||||||
|
|
||||||
@@ -112,15 +141,15 @@ You may also need to activate the service for debian install. If running Pop!\_O
|
|||||||
|
|
||||||
If you are upgrading from a previous installed version, you will need to restart the service or reboot.
|
If you are upgrading from a previous installed version, you will need to restart the service or reboot.
|
||||||
|
|
||||||
```
|
```sh
|
||||||
$ systemctl daemon-reload && systemctl restart asusd
|
systemctl daemon-reload && systemctl restart asusd
|
||||||
```
|
```
|
||||||
|
|
||||||
## Uninstalling
|
## Uninstalling
|
||||||
|
|
||||||
Run `sudo make uninstall` in the source repo, and remove `/etc/asusd/`.
|
Run `sudo make uninstall` in the source repo, and remove `/etc/asusd/`.
|
||||||
|
|
||||||
# Contributing
|
## Contributing
|
||||||
|
|
||||||
See `CONTRIBUTING.md`. Additionally, also do `cargo clean` and `cargo test` on first checkout to ensure the commit hooks are used (via `cargo-husky`).
|
See `CONTRIBUTING.md`. Additionally, also do `cargo clean` and `cargo test` on first checkout to ensure the commit hooks are used (via `cargo-husky`).
|
||||||
|
|
||||||
@@ -128,17 +157,17 @@ Generation of the bindings with `make bindings` requires `typeshare` to be insta
|
|||||||
|
|
||||||
Dbus introsepction XML requires with `make introspection` requires `anime_sim` to be running before starting `asusd`.
|
Dbus introsepction XML requires with `make introspection` requires `anime_sim` to be running before starting `asusd`.
|
||||||
|
|
||||||
# OTHER
|
## OTHER
|
||||||
|
|
||||||
## AniMe Matrix simulator
|
### AniMe Matrix simulator
|
||||||
|
|
||||||
A simulator using SDL2 can be built using `cargo build --package rog_simulators` and run with `./target/debug/anime_sim`. Once started `asusd` will need restarting to pick it up. If running this sim on a laptop _with_ the display, the simulated display will be used instead of the physical display.
|
A simulator using SDL2 can be built using `cargo build --package rog_simulators` and run with `./target/debug/anime_sim`. Once started `asusd` will need restarting to pick it up. If running this sim on a laptop _with_ the display, the simulated display will be used instead of the physical display.
|
||||||
|
|
||||||
## Supporting more laptops
|
### Supporting more laptops
|
||||||
|
|
||||||
Please file a support request.
|
Please file a support request.
|
||||||
|
|
||||||
# License & Trademarks
|
## License & Trademarks
|
||||||
|
|
||||||
Mozilla Public License 2 (MPL-2.0)
|
Mozilla Public License 2 (MPL-2.0)
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,17 @@ edition.workspace = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rog_anime = { path = "../rog-anime" }
|
rog_anime = { path = "../rog-anime" }
|
||||||
|
rog_scsi = { path = "../rog-scsi" }
|
||||||
rog_slash = { path = "../rog-slash" }
|
rog_slash = { path = "../rog-slash" }
|
||||||
rog_aura = { path = "../rog-aura" }
|
rog_aura = { path = "../rog-aura" }
|
||||||
rog_dbus = { path = "../rog-dbus" }
|
rog_dbus = { path = "../rog-dbus" }
|
||||||
rog_profiles = { path = "../rog-profiles" }
|
rog_profiles = { path = "../rog-profiles" }
|
||||||
rog_platform = { path = "../rog-platform" }
|
rog_platform = { path = "../rog-platform" }
|
||||||
asusd = { path = "../asusd" }
|
|
||||||
dmi_id = { path = "../dmi-id" }
|
dmi_id = { path = "../dmi-id" }
|
||||||
|
|
||||||
|
log.workspace = true
|
||||||
|
env_logger.workspace = true
|
||||||
|
|
||||||
ron.workspace = true
|
ron.workspace = true
|
||||||
gumdrop.workspace = true
|
gumdrop.workspace = true
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
@@ -25,4 +28,14 @@ zbus.workspace = true
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rog_dbus = { path = "../rog-dbus" }
|
rog_dbus = { path = "../rog-dbus" }
|
||||||
|
|
||||||
cargo-husky.workspace = true
|
[package.metadata.deb]
|
||||||
|
license-file = ["../LICENSE", "4"]
|
||||||
|
extended-description = """\
|
||||||
|
An utility for Linux to control many aspects of various ASUS laptops
|
||||||
|
but can also be used with non-asus laptops with reduced features."""
|
||||||
|
depends = "$auto"
|
||||||
|
section = "utility"
|
||||||
|
priority = "optional"
|
||||||
|
assets = [
|
||||||
|
["target/release/asusctl", "usr/bin/", "755"],
|
||||||
|
]
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
AnimeType::GA401,
|
AnimeType::GA401,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let anime_type = get_anime_type()?;
|
let anime_type = get_anime_type();
|
||||||
|
|
||||||
proxy.write(matrix.into_data_buffer(anime_type)?).unwrap();
|
proxy.write(matrix.into_data_buffer(anime_type)?).unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let anime_type = get_anime_type().unwrap();
|
let anime_type = get_anime_type();
|
||||||
proxy
|
proxy
|
||||||
.write(matrix.into_data_buffer(anime_type).unwrap())
|
.write(matrix.into_data_buffer(anime_type).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ fn main() {
|
|||||||
|
|
||||||
let path = Path::new(&args[1]);
|
let path = Path::new(&args[1]);
|
||||||
let brightness = args[2].parse::<f32>().unwrap();
|
let brightness = args[2].parse::<f32>().unwrap();
|
||||||
let anime_type = get_anime_type().unwrap();
|
let anime_type = get_anime_type();
|
||||||
let mut seq = Sequences::new(anime_type);
|
let mut seq = Sequences::new(anime_type);
|
||||||
seq.insert(
|
seq.insert(
|
||||||
0,
|
0,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ fn main() {
|
|||||||
let conn = Connection::system().unwrap();
|
let conn = Connection::system().unwrap();
|
||||||
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
|
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
|
||||||
|
|
||||||
let anime_type = get_anime_type().unwrap();
|
let anime_type = get_anime_type();
|
||||||
let mut matrix = AnimeGrid::new(anime_type);
|
let mut matrix = AnimeGrid::new(anime_type);
|
||||||
let tmp = matrix.get_mut();
|
let tmp = matrix.get_mut();
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use zbus::blocking::Connection;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let conn = Connection::system().unwrap();
|
let conn = Connection::system().unwrap();
|
||||||
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
|
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
|
||||||
let anime_type = get_anime_type().unwrap();
|
let anime_type = get_anime_type();
|
||||||
let mut matrix = AnimeDataBuffer::new(anime_type);
|
let mut matrix = AnimeDataBuffer::new(anime_type);
|
||||||
matrix.data_mut()[1] = 100; // start = 1
|
matrix.data_mut()[1] = 100; // start = 1
|
||||||
for n in matrix.data_mut()[2..32].iter_mut() {
|
for n in matrix.data_mut()[2..32].iter_mut() {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let anime_type = get_anime_type()?;
|
let anime_type = get_anime_type();
|
||||||
let matrix = AnimeImage::from_png(
|
let matrix = AnimeImage::from_png(
|
||||||
Path::new(&args[1]),
|
Path::new(&args[1]),
|
||||||
args[2].parse::<f32>().unwrap(),
|
args[2].parse::<f32>().unwrap(),
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let anime_type = get_anime_type()?;
|
let anime_type = get_anime_type();
|
||||||
let mut matrix = AnimeImage::from_png(
|
let mut matrix = AnimeImage::from_png(
|
||||||
Path::new(&args[1]),
|
Path::new(&args[1]),
|
||||||
args[2].parse::<f32>().unwrap(),
|
args[2].parse::<f32>().unwrap(),
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ pub enum SetAuraZoneEnabled {
|
|||||||
Lid(AuraPowerStates),
|
Lid(AuraPowerStates),
|
||||||
#[options(help = "")]
|
#[options(help = "")]
|
||||||
RearGlow(AuraPowerStates),
|
RearGlow(AuraPowerStates),
|
||||||
|
#[options(help = "")]
|
||||||
|
Ally(AuraPowerStates),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Options)]
|
#[derive(Debug, Clone, Options)]
|
||||||
@@ -179,6 +181,7 @@ pub struct TwoColourSpeed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Options)]
|
#[derive(Debug, Clone, Default, Options)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct MultiZone {
|
pub struct MultiZone {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
help: bool,
|
help: bool,
|
||||||
@@ -193,6 +196,7 @@ pub struct MultiZone {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Options)]
|
#[derive(Debug, Clone, Default, Options)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct MultiColourSpeed {
|
pub struct MultiColourSpeed {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
help: bool,
|
help: bool,
|
||||||
@@ -219,9 +223,9 @@ pub enum SetAuraBuiltin {
|
|||||||
#[options(help = "pulse between one or two colours")]
|
#[options(help = "pulse between one or two colours")]
|
||||||
Breathe(TwoColourSpeed), // 1
|
Breathe(TwoColourSpeed), // 1
|
||||||
#[options(help = "strobe through all colours")]
|
#[options(help = "strobe through all colours")]
|
||||||
Strobe(SingleSpeed), // 2
|
RainbowCycle(SingleSpeed), // 2
|
||||||
#[options(help = "rainbow cycling in one of four directions")]
|
#[options(help = "rainbow cycling in one of four directions")]
|
||||||
Rainbow(SingleSpeedDirection), // 3
|
RainbowWave(SingleSpeedDirection), // 3
|
||||||
#[options(help = "rain pattern mimicking raindrops")]
|
#[options(help = "rain pattern mimicking raindrops")]
|
||||||
Stars(TwoColourSpeed), // 4
|
Stars(TwoColourSpeed), // 4
|
||||||
#[options(help = "rain pattern of three preset colours")]
|
#[options(help = "rain pattern of three preset colours")]
|
||||||
@@ -312,14 +316,14 @@ impl From<&SetAuraBuiltin> for AuraEffect {
|
|||||||
data.mode = AuraModeNum::Breathe;
|
data.mode = AuraModeNum::Breathe;
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
SetAuraBuiltin::Strobe(x) => {
|
SetAuraBuiltin::RainbowCycle(x) => {
|
||||||
let mut data: AuraEffect = x.into();
|
let mut data: AuraEffect = x.into();
|
||||||
data.mode = AuraModeNum::Strobe;
|
data.mode = AuraModeNum::RainbowCycle;
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
SetAuraBuiltin::Rainbow(x) => {
|
SetAuraBuiltin::RainbowWave(x) => {
|
||||||
let mut data: AuraEffect = x.into();
|
let mut data: AuraEffect = x.into();
|
||||||
data.mode = AuraModeNum::Rainbow;
|
data.mode = AuraModeNum::RainbowWave;
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
SetAuraBuiltin::Stars(x) => {
|
SetAuraBuiltin::Stars(x) => {
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use gumdrop::Options;
|
use gumdrop::Options;
|
||||||
use rog_platform::platform::ThrottlePolicy;
|
use rog_platform::platform::PlatformProfile;
|
||||||
|
|
||||||
use crate::anime_cli::AnimeCommand;
|
use crate::anime_cli::AnimeCommand;
|
||||||
use crate::aura_cli::{LedBrightness, LedPowerCommand1, LedPowerCommand2, SetAuraBuiltin};
|
use crate::aura_cli::{LedBrightness, LedPowerCommand1, LedPowerCommand2, SetAuraBuiltin};
|
||||||
use crate::fan_curve_cli::FanCurveCommand;
|
use crate::fan_curve_cli::FanCurveCommand;
|
||||||
|
use crate::scsi_cli::ScsiCommand;
|
||||||
use crate::slash_cli::SlashCommand;
|
use crate::slash_cli::SlashCommand;
|
||||||
|
|
||||||
#[derive(Default, Options)]
|
#[derive(Default, Options)]
|
||||||
@@ -22,6 +23,8 @@ pub struct CliStart {
|
|||||||
pub prev_kbd_bright: bool,
|
pub prev_kbd_bright: bool,
|
||||||
#[options(meta = "", help = "Set your battery charge limit <20-100>")]
|
#[options(meta = "", help = "Set your battery charge limit <20-100>")]
|
||||||
pub chg_limit: Option<u8>,
|
pub chg_limit: Option<u8>,
|
||||||
|
#[options(help = "Toggle one-shot battery charge to 100%")]
|
||||||
|
pub one_shot_chg: bool,
|
||||||
#[options(command)]
|
#[options(command)]
|
||||||
pub command: Option<CliCommand>,
|
pub command: Option<CliCommand>,
|
||||||
}
|
}
|
||||||
@@ -29,11 +32,11 @@ pub struct CliStart {
|
|||||||
#[derive(Options)]
|
#[derive(Options)]
|
||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
#[options(help = "Set the keyboard lighting from built-in modes")]
|
#[options(help = "Set the keyboard lighting from built-in modes")]
|
||||||
LedMode(LedModeCommand),
|
Aura(LedModeCommand),
|
||||||
#[options(help = "Set the LED power states")]
|
#[options(help = "Set the LED power states")]
|
||||||
LedPow1(LedPowerCommand1),
|
AuraPowerOld(LedPowerCommand1),
|
||||||
#[options(help = "Set the LED power states")]
|
#[options(help = "Set the LED power states")]
|
||||||
LedPow2(LedPowerCommand2),
|
AuraPower(LedPowerCommand2),
|
||||||
#[options(help = "Set or select platform_profile")]
|
#[options(help = "Set or select platform_profile")]
|
||||||
Profile(ProfileCommand),
|
Profile(ProfileCommand),
|
||||||
#[options(help = "Set, select, or modify fan curves if supported")]
|
#[options(help = "Set, select, or modify fan curves if supported")]
|
||||||
@@ -44,8 +47,15 @@ pub enum CliCommand {
|
|||||||
Anime(AnimeCommand),
|
Anime(AnimeCommand),
|
||||||
#[options(name = "slash", help = "Manage Slash Ledbar")]
|
#[options(name = "slash", help = "Manage Slash Ledbar")]
|
||||||
Slash(SlashCommand),
|
Slash(SlashCommand),
|
||||||
#[options(help = "Change bios settings")]
|
#[options(name = "scsi", help = "Manage SCSI external drive")]
|
||||||
Bios(BiosCommand),
|
Scsi(ScsiCommand),
|
||||||
|
#[options(
|
||||||
|
help = "Change platform settings. This is a new interface exposed by the asus-armoury \
|
||||||
|
driver, some of the settings will be the same as the older platform interface"
|
||||||
|
)]
|
||||||
|
Armoury(ArmouryCommand),
|
||||||
|
#[options(name = "backlight", help = "Set screen backlight levels")]
|
||||||
|
Backlight(BacklightCommand),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Options)]
|
#[derive(Debug, Clone, Options)]
|
||||||
@@ -63,7 +73,17 @@ pub struct ProfileCommand {
|
|||||||
pub profile_get: bool,
|
pub profile_get: bool,
|
||||||
|
|
||||||
#[options(meta = "", help = "set the active profile")]
|
#[options(meta = "", help = "set the active profile")]
|
||||||
pub profile_set: Option<ThrottlePolicy>,
|
pub profile_set: Option<PlatformProfile>,
|
||||||
|
|
||||||
|
#[options(short = "a", meta = "", help = "set the profile to use on AC power")]
|
||||||
|
pub profile_set_ac: Option<PlatformProfile>,
|
||||||
|
|
||||||
|
#[options(
|
||||||
|
short = "b",
|
||||||
|
meta = "",
|
||||||
|
help = "set the profile to use on battery power"
|
||||||
|
)]
|
||||||
|
pub profile_set_bat: Option<PlatformProfile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Options)]
|
#[derive(Options)]
|
||||||
@@ -85,34 +105,30 @@ pub struct GraphicsCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Options, Debug)]
|
#[derive(Options, Debug)]
|
||||||
pub struct BiosCommand {
|
pub struct ArmouryCommand {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
pub help: bool,
|
pub help: bool,
|
||||||
#[options(
|
#[options(
|
||||||
meta = "",
|
free,
|
||||||
short = "S",
|
help = "append each value name followed by the value to set. `-1` sets to default"
|
||||||
no_long,
|
|
||||||
help = "set bios POST sound: asusctl -S <true/false>"
|
|
||||||
)]
|
)]
|
||||||
pub post_sound_set: Option<bool>,
|
pub free: Vec<String>,
|
||||||
#[options(no_long, short = "s", help = "read bios POST sound")]
|
}
|
||||||
pub post_sound_get: bool,
|
|
||||||
#[options(
|
#[derive(Options)]
|
||||||
meta = "",
|
pub struct BacklightCommand {
|
||||||
short = "D",
|
#[options(help = "print help message")]
|
||||||
no_long,
|
pub help: bool,
|
||||||
help = "Switch GPU MUX mode: 0 = Discrete, 1 = Optimus, reboot required"
|
#[options(meta = "", help = "Set screen brightness <0-100>")]
|
||||||
)]
|
pub screenpad_brightness: Option<i32>,
|
||||||
pub gpu_mux_mode_set: Option<u8>,
|
#[options(
|
||||||
#[options(no_long, short = "d", help = "get GPU mode")]
|
meta = "",
|
||||||
pub gpu_mux_mode_get: bool,
|
help = "Set screenpad gamma brightness 0.5 - 2.2, 1.0 == linear"
|
||||||
#[options(
|
)]
|
||||||
meta = "",
|
pub screenpad_gamma: Option<f32>,
|
||||||
short = "O",
|
#[options(
|
||||||
no_long,
|
meta = "",
|
||||||
help = "Set device panel overdrive <true/false>"
|
help = "Set screenpad brightness to sync with primary display"
|
||||||
)]
|
)]
|
||||||
pub panel_overdrive_set: Option<bool>,
|
pub sync_screenpad_brightness: Option<bool>,
|
||||||
#[options(no_long, short = "o", help = "get panel overdrive")]
|
|
||||||
pub panel_overdrive_get: bool,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use gumdrop::Options;
|
use gumdrop::Options;
|
||||||
use rog_platform::platform::ThrottlePolicy;
|
use rog_platform::platform::PlatformProfile;
|
||||||
use rog_profiles::fan_curve_set::CurveData;
|
use rog_profiles::fan_curve_set::CurveData;
|
||||||
use rog_profiles::FanCurvePU;
|
use rog_profiles::FanCurvePU;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ pub struct FanCurveCommand {
|
|||||||
meta = "",
|
meta = "",
|
||||||
help = "profile to modify fan-curve for. Shows data if no options provided"
|
help = "profile to modify fan-curve for. Shows data if no options provided"
|
||||||
)]
|
)]
|
||||||
pub mod_profile: Option<ThrottlePolicy>,
|
pub mod_profile: Option<PlatformProfile>,
|
||||||
|
|
||||||
#[options(
|
#[options(
|
||||||
meta = "",
|
meta = "",
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
35
asusctl/src/scsi_cli.rs
Normal file
35
asusctl/src/scsi_cli.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
use gumdrop::Options;
|
||||||
|
use rog_scsi::{AuraMode, Colour, Direction, Speed};
|
||||||
|
|
||||||
|
#[derive(Options)]
|
||||||
|
pub struct ScsiCommand {
|
||||||
|
#[options(help = "print help message")]
|
||||||
|
pub help: bool,
|
||||||
|
|
||||||
|
#[options(help = "Enable the SCSI drive LEDs")]
|
||||||
|
pub enable: Option<bool>,
|
||||||
|
|
||||||
|
#[options(meta = "", help = "Set LED mode (so 'list' for all options)")]
|
||||||
|
pub mode: Option<AuraMode>,
|
||||||
|
|
||||||
|
#[options(
|
||||||
|
meta = "",
|
||||||
|
help = "Set LED mode speed <slowest, slow, med, fast, fastest> (does not apply to all)"
|
||||||
|
)]
|
||||||
|
pub speed: Option<Speed>,
|
||||||
|
|
||||||
|
#[options(
|
||||||
|
meta = "",
|
||||||
|
help = "Set LED mode direction <forward, reverse> (does not apply to all)"
|
||||||
|
)]
|
||||||
|
pub direction: Option<Direction>,
|
||||||
|
|
||||||
|
#[options(
|
||||||
|
meta = "",
|
||||||
|
help = "Set LED colours <hex>, specify up to 4 with repeated arg"
|
||||||
|
)]
|
||||||
|
pub colours: Vec<Colour>,
|
||||||
|
|
||||||
|
#[options(help = "list available animations")]
|
||||||
|
pub list: bool,
|
||||||
|
}
|
||||||
@@ -7,14 +7,31 @@ pub struct SlashCommand {
|
|||||||
pub help: bool,
|
pub help: bool,
|
||||||
#[options(help = "Enable the Slash Ledbar")]
|
#[options(help = "Enable the Slash Ledbar")]
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
#[options(help = "Ddisable the Slash Ledbar")]
|
#[options(help = "Disable the Slash Ledbar")]
|
||||||
pub disable: bool,
|
pub disable: bool,
|
||||||
#[options(meta = "", help = "Set brightness value <0-255>")]
|
#[options(short = "l", meta = "", help = "Set brightness value <0-255>")]
|
||||||
pub brightness: Option<u8>,
|
pub brightness: Option<u8>,
|
||||||
#[options(meta = "", help = "Set interval value <0-255>")]
|
#[options(meta = "", help = "Set interval value <0-5>")]
|
||||||
pub interval: Option<u8>,
|
pub interval: Option<u8>,
|
||||||
#[options(help = "Set SlashMode (so 'list' for all options)")]
|
#[options(meta = "", help = "Set SlashMode (so 'list' for all options)")]
|
||||||
pub slash_mode: Option<SlashMode>,
|
pub mode: Option<SlashMode>,
|
||||||
#[options(help = "list available animations")]
|
#[options(help = "list available animations")]
|
||||||
pub list: bool,
|
pub list: bool,
|
||||||
|
|
||||||
|
#[options(short = "B", meta = "", help = "Show the animation on boot")]
|
||||||
|
pub show_on_boot: Option<bool>,
|
||||||
|
#[options(short = "S", meta = "", help = "Show the animation on shutdown")]
|
||||||
|
pub show_on_shutdown: Option<bool>,
|
||||||
|
#[options(short = "s", meta = "", help = "Show the animation on sleep")]
|
||||||
|
pub show_on_sleep: Option<bool>,
|
||||||
|
#[options(short = "b", meta = "", help = "Show the animation on battery")]
|
||||||
|
pub show_on_battery: Option<bool>,
|
||||||
|
// #[options(short = "L", meta = "", help = "Show the animation on lid closed")]
|
||||||
|
// pub show_on_lid_closed: Option<bool>,
|
||||||
|
#[options(
|
||||||
|
short = "w",
|
||||||
|
meta = "",
|
||||||
|
help = "Show the low-battery warning animation"
|
||||||
|
)]
|
||||||
|
pub show_battery_warning: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,16 @@ edition.workspace = true
|
|||||||
name = "asusd-user"
|
name = "asusd-user"
|
||||||
path = "src/daemon.rs"
|
path = "src/daemon.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
local_data = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dirs.workspace = true
|
dirs.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
|
|
||||||
# serialisation
|
# serialisation
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
|
||||||
ron.workspace = true
|
ron.workspace = true
|
||||||
|
|
||||||
rog_anime = { path = "../rog-anime" }
|
rog_anime = { path = "../rog-anime" }
|
||||||
@@ -30,8 +33,15 @@ config-traits = { path = "../config-traits" }
|
|||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[package.metadata.deb]
|
||||||
cargo-husky.workspace = true
|
license-file = ["../LICENSE", "4"]
|
||||||
|
extended-description = """\
|
||||||
[package.metadata.cargo-machete]
|
An user utility for Linux to control fancy things on various ASUS laptops
|
||||||
ignored = ["serde"]
|
like keyboard effects or anime matrix animation cycles."""
|
||||||
|
depends = "$auto"
|
||||||
|
section = "utility"
|
||||||
|
priority = "optional"
|
||||||
|
assets = [
|
||||||
|
["target/release/asusd-user", "usr/bin/", "755"],
|
||||||
|
["../asusd_user-fakeinstall/usr/lib/systemd/user/*", "usr/lib/systemd/user/", "644"],
|
||||||
|
]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use rog_anime::{ActionLoader, AnimTime, AnimeType, Fade, Sequences as AnimeSeque
|
|||||||
use rog_aura::effects::{AdvancedEffects as AuraSequences, Breathe, DoomFlicker, Effect, Static};
|
use rog_aura::effects::{AdvancedEffects as AuraSequences, Breathe, DoomFlicker, Effect, Static};
|
||||||
use rog_aura::keyboard::LedCode;
|
use rog_aura::keyboard::LedCode;
|
||||||
use rog_aura::{Colour, Speed};
|
use rog_aura::{Colour, Speed};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use rog_anime::error::AnimeError;
|
|||||||
use rog_anime::{ActionData, ActionLoader, AnimTime, Fade, Sequences, Vec2};
|
use rog_anime::{ActionData, ActionLoader, AnimTime, Fade, Sequences, Vec2};
|
||||||
use rog_dbus::zbus_anime::AnimeProxyBlocking;
|
use rog_dbus::zbus_anime::AnimeProxyBlocking;
|
||||||
use ron::ser::PrettyConfig;
|
use ron::ser::PrettyConfig;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use zbus::interface;
|
use zbus::interface;
|
||||||
use zbus::zvariant::{ObjectPath, Type};
|
use zbus::zvariant::{ObjectPath, Type};
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ pub struct CtrlAnimeInner<'a> {
|
|||||||
do_early_return: Arc<AtomicBool>,
|
do_early_return: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CtrlAnimeInner<'static> {
|
impl CtrlAnimeInner<'static> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
sequences: Sequences,
|
sequences: Sequences,
|
||||||
client: AnimeProxyBlocking<'static>,
|
client: AnimeProxyBlocking<'static>,
|
||||||
@@ -81,7 +81,7 @@ impl<'a> CtrlAnimeInner<'static> {
|
|||||||
|
|
||||||
/// To be called on each main loop iteration to pump out commands to the
|
/// To be called on each main loop iteration to pump out commands to the
|
||||||
/// anime
|
/// anime
|
||||||
pub fn run(&'a self) -> Result<(), Error> {
|
pub fn run(&self) -> Result<(), Error> {
|
||||||
if self.do_early_return.load(Ordering::SeqCst) {
|
if self.do_early_return.load(Ordering::SeqCst) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -151,10 +151,7 @@ impl CtrlAnime<'static> {
|
|||||||
pub async fn add_to_server(self, server: &mut zbus::Connection) {
|
pub async fn add_to_server(self, server: &mut zbus::Connection) {
|
||||||
server
|
server
|
||||||
.object_server()
|
.object_server()
|
||||||
.at(
|
.at(&ObjectPath::from_str_unchecked("/xyz/ljones/Anime"), self)
|
||||||
&ObjectPath::from_str_unchecked("/org/asuslinux/Anime"),
|
|
||||||
self,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
println!("CtrlAnime: add_to_server {}", err);
|
println!("CtrlAnime: add_to_server {}", err);
|
||||||
@@ -170,7 +167,7 @@ impl CtrlAnime<'static> {
|
|||||||
// - Do actions
|
// - Do actions
|
||||||
// - Write config if required
|
// - Write config if required
|
||||||
// - Unset inner_early_return
|
// - Unset inner_early_return
|
||||||
#[interface(name = "org.asuslinux.Daemon")]
|
#[interface(name = "xyz.ljones.Asusd")]
|
||||||
impl CtrlAnime<'static> {
|
impl CtrlAnime<'static> {
|
||||||
pub fn insert_asus_gif(
|
pub fn insert_asus_gif(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ use rog_aura::aura_detection::LedSupportData;
|
|||||||
use rog_aura::keyboard::KeyLayout;
|
use rog_aura::keyboard::KeyLayout;
|
||||||
use rog_dbus::zbus_anime::AnimeProxyBlocking;
|
use rog_dbus::zbus_anime::AnimeProxyBlocking;
|
||||||
use rog_dbus::zbus_aura::AuraProxyBlocking;
|
use rog_dbus::zbus_aura::AuraProxyBlocking;
|
||||||
use rog_dbus::zbus_platform::PlatformProxyBlocking;
|
use rog_dbus::{list_iface_blocking, DBUS_NAME};
|
||||||
use rog_dbus::DBUS_NAME;
|
|
||||||
use smol::Executor;
|
use smol::Executor;
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
||||||
@@ -36,20 +35,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
println!("rog-platform v{}", rog_platform::VERSION);
|
println!("rog-platform v{}", rog_platform::VERSION);
|
||||||
|
|
||||||
let conn = zbus::blocking::Connection::system().unwrap();
|
let conn = zbus::blocking::Connection::system().unwrap();
|
||||||
let platform_proxy = PlatformProxyBlocking::new(&conn).unwrap();
|
|
||||||
|
|
||||||
let supported = platform_proxy
|
let supported = list_iface_blocking()?;
|
||||||
.supported_interfaces()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.contains(&"Anime".to_string());
|
|
||||||
let config = ConfigBase::new().load();
|
let config = ConfigBase::new().load();
|
||||||
let executor = Executor::new();
|
let executor = Executor::new();
|
||||||
|
|
||||||
let early_return = Arc::new(AtomicBool::new(false));
|
let early_return = Arc::new(AtomicBool::new(false));
|
||||||
// Set up the anime data and run loop/thread
|
// Set up the anime data and run loop/thread
|
||||||
if supported {
|
if supported.contains(&"xyz.ljones.Anime".to_string()) {
|
||||||
if let Some(cfg) = config.active_anime {
|
if let Some(cfg) = config.active_anime {
|
||||||
let anime_type = get_anime_type()?;
|
let anime_type = get_anime_type();
|
||||||
let anime_config = ConfigAnime::new().set_name(cfg).load();
|
let anime_config = ConfigAnime::new().set_name(cfg).load();
|
||||||
let anime = anime_config.create(anime_type)?;
|
let anime = anime_config.create(anime_type)?;
|
||||||
let anime_config = Arc::new(Mutex::new(anime_config));
|
let anime_config = Arc::new(Mutex::new(anime_config));
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
//! # `DBus` interface proxy for: `org.asuslinux.Daemon`
|
//! # `DBus` interface proxy for: `xyz.ljones.Asusd`
|
||||||
//!
|
//!
|
||||||
//! This code was generated by `zbus-xmlgen` `1.0.0` from `DBus` introspection
|
//! This code was generated by `zbus-xmlgen` `1.0.0` from `DBus` introspection
|
||||||
//! data. Source: `Interface '/org/asuslinux/Anime' from service
|
//! data. Source: `Interface '/xyz/ljones/Anime' from service
|
||||||
//! 'org.asuslinux.Daemon' on session bus`.
|
//! 'xyz.ljones.Asusd' on session bus`.
|
||||||
//!
|
//!
|
||||||
//! You may prefer to adapt it, instead of using it verbatim.
|
//! You may prefer to adapt it, instead of using it verbatim.
|
||||||
//!
|
//!
|
||||||
@@ -23,10 +23,7 @@
|
|||||||
|
|
||||||
use zbus::proxy;
|
use zbus::proxy;
|
||||||
|
|
||||||
#[proxy(
|
#[proxy(interface = "xyz.ljones.Asusd", default_path = "/xyz/ljones/Anime")]
|
||||||
interface = "org.asuslinux.Daemon",
|
|
||||||
default_path = "/org/asuslinux/Anime"
|
|
||||||
)]
|
|
||||||
trait Daemon {
|
trait Daemon {
|
||||||
/// InsertAsusGif method
|
/// InsertAsusGif method
|
||||||
fn insert_asus_gif(
|
fn insert_asus_gif(
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ config-traits = { path = "../config-traits" }
|
|||||||
rog_anime = { path = "../rog-anime", features = ["dbus"] }
|
rog_anime = { path = "../rog-anime", features = ["dbus"] }
|
||||||
rog_slash = { path = "../rog-slash", features = ["dbus"] }
|
rog_slash = { path = "../rog-slash", features = ["dbus"] }
|
||||||
rog_aura = { path = "../rog-aura", features = ["dbus"] }
|
rog_aura = { path = "../rog-aura", features = ["dbus"] }
|
||||||
|
rog_scsi = { path = "../rog-scsi", features = ["dbus"] }
|
||||||
rog_platform = { path = "../rog-platform" }
|
rog_platform = { path = "../rog-platform" }
|
||||||
rog_profiles = { path = "../rog-profiles" }
|
rog_profiles = { path = "../rog-profiles" }
|
||||||
dmi_id = { path = "../dmi-id" }
|
dmi_id = { path = "../dmi-id" }
|
||||||
@@ -33,17 +34,29 @@ tokio.workspace = true
|
|||||||
log.workspace = true
|
log.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
|
|
||||||
|
futures-util.workspace = true
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
logind-zbus.workspace = true
|
logind-zbus.workspace = true
|
||||||
|
|
||||||
# serialisation
|
# serialisation
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
|
||||||
|
|
||||||
concat-idents.workspace = true
|
concat-idents.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
cargo-husky.workspace = true
|
cargo-husky.workspace = true
|
||||||
|
|
||||||
[package.metadata.cargo-machete]
|
[package.metadata.deb]
|
||||||
ignored = ["serde"]
|
license-file = ["../LICENSE", "4"]
|
||||||
|
extended-description = """\
|
||||||
|
The dbus server for asusctl and rog-control-center applications."""
|
||||||
|
depends = "$auto"
|
||||||
|
section = "utility"
|
||||||
|
priority = "optional"
|
||||||
|
assets = [
|
||||||
|
["target/release/asusd", "usr/bin/", "755"],
|
||||||
|
["../asusd-fakeinstall/usr/lib/systemd/system/*", "usr/lib/systemd/system/", "644"],
|
||||||
|
["../asusd-fakeinstall/usr/lib/udev/rules.d/*", "usr/lib/udev/rules.d/", "644"],
|
||||||
|
["../asusd-fakeinstall/usr/share/asusd/*", "usr/share/share/asusd/", "644"],
|
||||||
|
["../asusd-fakeinstall/usr/share/dbus-1/system.d/*", "usr/share/dbus-1/system.d/", "644"],
|
||||||
|
]
|
||||||
|
|||||||
564
asusd/src/asus_armoury.rs
Normal file
564
asusd/src/asus_armoury.rs
Normal file
@@ -0,0 +1,564 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use config_traits::StdConfig;
|
||||||
|
use log::{debug, error, info, warn};
|
||||||
|
use rog_platform::asus_armoury::{AttrValue, Attribute, FirmwareAttribute, FirmwareAttributes};
|
||||||
|
use rog_platform::platform::{PlatformProfile, RogPlatform};
|
||||||
|
use rog_platform::power::AsusPower;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
use zbus::object_server::SignalEmitter;
|
||||||
|
use zbus::zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Type, Value};
|
||||||
|
use zbus::{fdo, interface, Connection};
|
||||||
|
|
||||||
|
use crate::config::Config;
|
||||||
|
use crate::error::RogError;
|
||||||
|
use crate::{Reloadable, ASUS_ZBUS_PATH};
|
||||||
|
|
||||||
|
const MOD_NAME: &str = "asus_armoury";
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone, Deserialize, Serialize, Type, Value, OwnedValue)]
|
||||||
|
pub struct PossibleValues {
|
||||||
|
strings: Vec<String>,
|
||||||
|
nums: Vec<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dbus_path_for_attr(attr_name: &str) -> OwnedObjectPath {
|
||||||
|
ObjectPath::from_str_unchecked(&format!("{ASUS_ZBUS_PATH}/{MOD_NAME}/{attr_name}")).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct AsusArmouryAttribute {
|
||||||
|
attr: Attribute,
|
||||||
|
config: Arc<Mutex<Config>>,
|
||||||
|
/// platform control required here for access to PPD or Throttle profile
|
||||||
|
platform: RogPlatform,
|
||||||
|
power: AsusPower,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsusArmouryAttribute {
|
||||||
|
pub fn new(
|
||||||
|
attr: Attribute,
|
||||||
|
platform: RogPlatform,
|
||||||
|
power: AsusPower,
|
||||||
|
config: Arc<Mutex<Config>>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
attr,
|
||||||
|
config,
|
||||||
|
platform,
|
||||||
|
power,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn attribute_name(&self) -> String {
|
||||||
|
String::from(self.attr.name())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolve_i32_value(refreshed: Option<i32>, cached: &AttrValue) -> i32 {
|
||||||
|
refreshed
|
||||||
|
.or(match cached {
|
||||||
|
AttrValue::Integer(i) => Some(*i),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.unwrap_or(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn emit_limits(&self, connection: &Connection) -> Result<(), RogError> {
|
||||||
|
let path = dbus_path_for_attr(self.attr.name());
|
||||||
|
let signal = SignalEmitter::new(connection, path)?;
|
||||||
|
self.min_value_changed(&signal).await?;
|
||||||
|
self.max_value_changed(&signal).await?;
|
||||||
|
self.scalar_increment_changed(&signal).await?;
|
||||||
|
self.current_value_changed(&signal).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn move_to_zbus(self, connection: &Connection) -> Result<(), RogError> {
|
||||||
|
let path = dbus_path_for_attr(self.attr.name());
|
||||||
|
connection
|
||||||
|
.object_server()
|
||||||
|
.at(path.clone(), self)
|
||||||
|
.await
|
||||||
|
.map_err(|e| error!("Couldn't add server at path: {path}, {e:?}"))
|
||||||
|
.ok();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn watch_and_notify(
|
||||||
|
&mut self,
|
||||||
|
signal_ctxt: SignalEmitter<'static>,
|
||||||
|
) -> Result<(), RogError> {
|
||||||
|
use futures_util::StreamExt;
|
||||||
|
|
||||||
|
let name = self.name();
|
||||||
|
macro_rules! watch_value_notify {
|
||||||
|
($attr_str:expr, $fn_prop_changed:ident) => {
|
||||||
|
match self.attr.get_watcher($attr_str) {
|
||||||
|
Ok(watch) => {
|
||||||
|
let name = <&str>::from(name);
|
||||||
|
let ctrl = self.clone();
|
||||||
|
let sig = signal_ctxt.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let mut buffer = [0; 32];
|
||||||
|
if let Ok(stream) = watch.into_event_stream(&mut buffer) {
|
||||||
|
stream
|
||||||
|
.for_each(|_| async {
|
||||||
|
debug!("{} changed", name);
|
||||||
|
ctrl.$fn_prop_changed(&sig).await.ok();
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"inotify event stream failed for {} ({}). You can ignore this \
|
||||||
|
if unsupported",
|
||||||
|
name, $attr_str
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Err(e) => info!(
|
||||||
|
"inotify watch failed: {}. You can ignore this if your device does not \
|
||||||
|
support the feature",
|
||||||
|
e
|
||||||
|
),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// "current_value", "default_value", "min_value", "max_value"
|
||||||
|
watch_value_notify!("current_value", current_value_changed);
|
||||||
|
watch_value_notify!("default_value", default_value_changed);
|
||||||
|
watch_value_notify!("min_value", min_value_changed);
|
||||||
|
watch_value_notify!("max_value", max_value_changed);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
pub struct ArmouryAttributeRegistry {
|
||||||
|
attrs: Vec<AsusArmouryAttribute>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ArmouryAttributeRegistry {
|
||||||
|
pub fn push(&mut self, attr: AsusArmouryAttribute) {
|
||||||
|
self.attrs.push(attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn emit_limits(&self, connection: &Connection) -> Result<(), RogError> {
|
||||||
|
let mut last_err: Option<RogError> = None;
|
||||||
|
for attr in &self.attrs {
|
||||||
|
if let Err(e) = attr.emit_limits(connection).await {
|
||||||
|
error!(
|
||||||
|
"Failed to emit updated limits for attribute '{}': {e:?}",
|
||||||
|
attr.attribute_name()
|
||||||
|
);
|
||||||
|
last_err = Some(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(err) = last_err {
|
||||||
|
Err(err)
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl crate::Reloadable for AsusArmouryAttribute {
|
||||||
|
async fn reload(&mut self) -> Result<(), RogError> {
|
||||||
|
info!("Reloading {}", self.attr.name());
|
||||||
|
let name: FirmwareAttribute = self.attr.name().into();
|
||||||
|
|
||||||
|
// Treat dGPU attributes the same as PPT attributes for power-profile
|
||||||
|
// behaviour so they follow AC/DC tuning groups.
|
||||||
|
if name.is_ppt() || name.is_dgpu() {
|
||||||
|
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||||
|
let power_plugged = self
|
||||||
|
.power
|
||||||
|
.get_online()
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Could not get power status: {e:?}");
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
== 1;
|
||||||
|
|
||||||
|
let apply_value = {
|
||||||
|
let config = self.config.lock().await;
|
||||||
|
config
|
||||||
|
.select_tunings_ref(power_plugged, profile)
|
||||||
|
.and_then(|tuning| {
|
||||||
|
if tuning.enabled {
|
||||||
|
tuning.group.get(&self.name()).copied()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(tune) = apply_value {
|
||||||
|
self.attr
|
||||||
|
.set_current_value(&AttrValue::Integer(tune))
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Could not set {} value: {e:?}", self.attr.name());
|
||||||
|
self.attr.base_path_exists();
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
info!(
|
||||||
|
"Restored PPT armoury setting {} to {:?}",
|
||||||
|
self.attr.name(),
|
||||||
|
tune
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
info!("Ignored restoring PPT armoury setting {} as tuning group is disabled or no saved value", self.attr.name());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Handle non-PPT attributes (boolean and other settings)
|
||||||
|
if let Some(saved_value) = self.config.lock().await.armoury_settings.get(&name) {
|
||||||
|
self.attr
|
||||||
|
.set_current_value(&AttrValue::Integer(*saved_value))
|
||||||
|
.map_err(|e| {
|
||||||
|
error!(
|
||||||
|
"Error restoring armoury setting {}: {e:?}",
|
||||||
|
self.attr.name()
|
||||||
|
);
|
||||||
|
self.attr.base_path_exists();
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
info!(
|
||||||
|
"Restored armoury setting {} to {:?}",
|
||||||
|
self.attr.name(),
|
||||||
|
saved_value
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"No saved armoury setting for {}: skipping restore",
|
||||||
|
self.attr.name()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If return is `-1` on a property then there is avilable value for that
|
||||||
|
/// property
|
||||||
|
#[interface(name = "xyz.ljones.AsusArmoury")]
|
||||||
|
impl AsusArmouryAttribute {
|
||||||
|
#[zbus(property)]
|
||||||
|
fn name(&self) -> FirmwareAttribute {
|
||||||
|
self.attr.name().into()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn available_attrs(&self) -> Vec<String> {
|
||||||
|
let mut attrs = Vec::new();
|
||||||
|
if !matches!(self.attr.default_value(), AttrValue::None) {
|
||||||
|
attrs.push("default_value".to_string());
|
||||||
|
}
|
||||||
|
if !matches!(self.attr.min_value(), AttrValue::None) {
|
||||||
|
attrs.push("min_value".to_string());
|
||||||
|
}
|
||||||
|
if !matches!(self.attr.max_value(), AttrValue::None) {
|
||||||
|
attrs.push("max_value".to_string());
|
||||||
|
}
|
||||||
|
if !matches!(self.attr.scalar_increment(), AttrValue::None) {
|
||||||
|
attrs.push("scalar_increment".to_string());
|
||||||
|
}
|
||||||
|
if !matches!(self.attr.possible_values(), AttrValue::None) {
|
||||||
|
attrs.push("possible_values".to_string());
|
||||||
|
}
|
||||||
|
// TODO: Don't unwrap, use error
|
||||||
|
if let Ok(value) = self.attr.current_value().map_err(|e| {
|
||||||
|
error!("Failed to read: {e:?}");
|
||||||
|
e
|
||||||
|
}) {
|
||||||
|
if !matches!(value, AttrValue::None) {
|
||||||
|
attrs.push("current_value".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attrs
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If return is `-1` then there is no default value
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn default_value(&self) -> i32 {
|
||||||
|
match self.attr.default_value() {
|
||||||
|
AttrValue::Integer(i) => *i,
|
||||||
|
_ => -1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn restore_default(&self) -> fdo::Result<()> {
|
||||||
|
self.attr.restore_default()?;
|
||||||
|
if self.name().is_ppt() || self.name().is_dgpu() {
|
||||||
|
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||||
|
let power_plugged = self
|
||||||
|
.power
|
||||||
|
.get_online()
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Could not get power status: {e:?}");
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let mut config = self.config.lock().await;
|
||||||
|
let tuning = config.select_tunings(power_plugged == 1, profile);
|
||||||
|
if let Some(tune) = tuning.group.get_mut(&self.name()) {
|
||||||
|
if let AttrValue::Integer(i) = self.attr.default_value() {
|
||||||
|
*tune = *i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tuning.enabled {
|
||||||
|
self.attr
|
||||||
|
.set_current_value(self.attr.default_value())
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Could not set value: {e:?}");
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn min_value(&self) -> i32 {
|
||||||
|
Self::resolve_i32_value(self.attr.refresh_min_value(), self.attr.min_value())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn max_value(&self) -> i32 {
|
||||||
|
Self::resolve_i32_value(self.attr.refresh_max_value(), self.attr.max_value())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn scalar_increment(&self) -> i32 {
|
||||||
|
Self::resolve_i32_value(
|
||||||
|
self.attr.refresh_scalar_increment(),
|
||||||
|
self.attr.scalar_increment(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn possible_values(&self) -> Vec<i32> {
|
||||||
|
match self.attr.possible_values() {
|
||||||
|
AttrValue::EnumInt(i) => i.clone(),
|
||||||
|
_ => Vec::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn current_value(&self) -> fdo::Result<i32> {
|
||||||
|
if self.name().is_ppt() || self.name().is_dgpu() {
|
||||||
|
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||||
|
let power_plugged = self
|
||||||
|
.power
|
||||||
|
.get_online()
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Could not get power status: {e:?}");
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
== 1;
|
||||||
|
let config = self.config.lock().await;
|
||||||
|
if let Some(tuning) = config.select_tunings_ref(power_plugged, profile) {
|
||||||
|
if let Some(tune) = tuning.group.get(&self.name()) {
|
||||||
|
return Ok(*tune);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let AttrValue::Integer(i) = self.attr.default_value() {
|
||||||
|
return Ok(*i);
|
||||||
|
}
|
||||||
|
return Err(fdo::Error::Failed(
|
||||||
|
"Could not read current value".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(AttrValue::Integer(i)) = self.attr.current_value() {
|
||||||
|
return Ok(i);
|
||||||
|
}
|
||||||
|
Err(fdo::Error::Failed(
|
||||||
|
"Could not read current value".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_current_value(&mut self, value: i32) -> fdo::Result<()> {
|
||||||
|
if self.name().is_ppt() || self.name().is_dgpu() {
|
||||||
|
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||||
|
let power_plugged = self
|
||||||
|
.power
|
||||||
|
.get_online()
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Could not get power status: {e:?}");
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let mut config = self.config.lock().await;
|
||||||
|
let tuning = config.select_tunings(power_plugged == 1, profile);
|
||||||
|
|
||||||
|
if let Some(tune) = tuning.group.get_mut(&self.name()) {
|
||||||
|
*tune = value;
|
||||||
|
} else {
|
||||||
|
tuning.group.insert(self.name(), value);
|
||||||
|
debug!("Store tuning config for {} = {:?}", self.attr.name(), value);
|
||||||
|
}
|
||||||
|
if tuning.enabled {
|
||||||
|
self.attr
|
||||||
|
.set_current_value(&AttrValue::Integer(value))
|
||||||
|
.map_err(|e| {
|
||||||
|
error!(
|
||||||
|
"Could not set value to PPT property {}: {e:?}",
|
||||||
|
self.attr.name()
|
||||||
|
);
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
} else {
|
||||||
|
warn!(
|
||||||
|
"Tuning group is disabled: skipping setting value to PPT property {}",
|
||||||
|
self.attr.name()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.attr
|
||||||
|
.set_current_value(&AttrValue::Integer(value))
|
||||||
|
.map_err(|e| {
|
||||||
|
error!(
|
||||||
|
"Could not set value {value} to attribute {}: {e:?}",
|
||||||
|
self.attr.name()
|
||||||
|
);
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let mut settings = self.config.lock().await;
|
||||||
|
settings
|
||||||
|
.armoury_settings
|
||||||
|
.entry(self.name())
|
||||||
|
.and_modify(|setting| {
|
||||||
|
debug!("Set config for {} = {value}", self.attr.name());
|
||||||
|
*setting = value;
|
||||||
|
})
|
||||||
|
.or_insert_with(|| {
|
||||||
|
debug!("Adding config for {} = {value}", self.attr.name());
|
||||||
|
value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// write config after setting value
|
||||||
|
self.config.lock().await.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start_attributes_zbus(
|
||||||
|
conn: &Connection,
|
||||||
|
platform: RogPlatform,
|
||||||
|
power: AsusPower,
|
||||||
|
attributes: FirmwareAttributes,
|
||||||
|
config: Arc<Mutex<Config>>,
|
||||||
|
) -> Result<ArmouryAttributeRegistry, RogError> {
|
||||||
|
let mut registry = ArmouryAttributeRegistry::default();
|
||||||
|
for attr in attributes.attributes() {
|
||||||
|
let mut attr = AsusArmouryAttribute::new(
|
||||||
|
attr.clone(),
|
||||||
|
platform.clone(),
|
||||||
|
power.clone(),
|
||||||
|
config.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let registry_attr = attr.clone();
|
||||||
|
|
||||||
|
if let Err(e) = attr.reload().await {
|
||||||
|
error!(
|
||||||
|
"Skipping attribute '{}' due to reload error: {e:?}",
|
||||||
|
attr.attr.name()
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let attr_name = attr.attribute_name();
|
||||||
|
|
||||||
|
let path = dbus_path_for_attr(attr_name.as_str());
|
||||||
|
match zbus::object_server::SignalEmitter::new(conn, path) {
|
||||||
|
Ok(sig) => {
|
||||||
|
if let Err(e) = attr.watch_and_notify(sig).await {
|
||||||
|
error!("Failed to start watcher for '{}': {e:?}", attr.attr.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!(
|
||||||
|
"Failed to create SignalEmitter for '{}': {e:?}",
|
||||||
|
attr.attr.name()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = attr.move_to_zbus(conn).await {
|
||||||
|
error!("Failed to register attribute '{attr_name}' on zbus: {e:?}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
registry.push(registry_attr);
|
||||||
|
}
|
||||||
|
Ok(registry)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_config_or_default(
|
||||||
|
attrs: &FirmwareAttributes,
|
||||||
|
config: &mut Config,
|
||||||
|
power_plugged: bool,
|
||||||
|
profile: PlatformProfile,
|
||||||
|
) {
|
||||||
|
for attr in attrs.attributes().iter() {
|
||||||
|
let name: FirmwareAttribute = attr.name().into();
|
||||||
|
if name.is_ppt() || name.is_dgpu() {
|
||||||
|
let tuning = config.select_tunings(power_plugged, profile);
|
||||||
|
if !tuning.enabled {
|
||||||
|
debug!("Tuning group is not enabled, skipping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(tune) = tuning.group.get(&name) {
|
||||||
|
attr.set_current_value(&AttrValue::Integer(*tune))
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Failed to set {}: {e}", <&str>::from(name));
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
} else {
|
||||||
|
let default = attr.default_value();
|
||||||
|
attr.set_current_value(default)
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Failed to set {}: {e}", <&str>::from(name));
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
if let AttrValue::Integer(i) = default {
|
||||||
|
tuning.group.insert(name, *i);
|
||||||
|
info!(
|
||||||
|
"Set default tuning config for {} = {:?}",
|
||||||
|
<&str>::from(name),
|
||||||
|
i
|
||||||
|
);
|
||||||
|
// config.write();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Handle non-PPT attributes (boolean and other settings)
|
||||||
|
if let Some(saved_value) = config.armoury_settings.get(&name) {
|
||||||
|
attr.set_current_value(&AttrValue::Integer(*saved_value))
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Failed to set {}: {e}", <&str>::from(name));
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
info!(
|
||||||
|
"Restored armoury setting for {} = {:?}",
|
||||||
|
<&str>::from(name),
|
||||||
|
saved_value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,81 +1,27 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use config_traits::{StdConfig, StdConfigLoad2};
|
use config_traits::{StdConfig, StdConfigLoad};
|
||||||
use rog_anime::error::AnimeError;
|
use rog_anime::error::AnimeError;
|
||||||
use rog_anime::usb::Brightness;
|
use rog_anime::usb::Brightness;
|
||||||
use rog_anime::{
|
use rog_anime::{
|
||||||
ActionData, ActionLoader, AnimTime, Animations, AnimeType, DeviceState, Fade, Vec2,
|
ActionData, ActionLoader, AnimTime, Animations, AnimeType, DeviceState, Fade, Vec2,
|
||||||
};
|
};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
const CONFIG_FILE: &str = "anime.ron";
|
const CONFIG_FILE: &str = "anime.ron";
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
|
||||||
pub struct AnimeConfigV460 {
|
pub struct AniMeConfigCached {
|
||||||
pub system: Vec<ActionLoader>,
|
|
||||||
pub boot: Vec<ActionLoader>,
|
|
||||||
pub wake: Vec<ActionLoader>,
|
|
||||||
pub sleep: Vec<ActionLoader>,
|
|
||||||
pub shutdown: Vec<ActionLoader>,
|
|
||||||
pub brightness: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<AnimeConfigV460> for AnimeConfig {
|
|
||||||
fn from(c: AnimeConfigV460) -> AnimeConfig {
|
|
||||||
AnimeConfig {
|
|
||||||
system: c.system,
|
|
||||||
boot: c.boot,
|
|
||||||
wake: c.wake,
|
|
||||||
shutdown: c.shutdown,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
|
||||||
pub struct AnimeConfigV472 {
|
|
||||||
pub model_override: Option<AnimeType>,
|
|
||||||
pub system: Vec<ActionLoader>,
|
|
||||||
pub boot: Vec<ActionLoader>,
|
|
||||||
pub wake: Vec<ActionLoader>,
|
|
||||||
pub sleep: Vec<ActionLoader>,
|
|
||||||
pub shutdown: Vec<ActionLoader>,
|
|
||||||
pub brightness: f32,
|
|
||||||
pub display_enabled: bool,
|
|
||||||
pub display_brightness: Brightness,
|
|
||||||
pub builtin_anims_enabled: bool,
|
|
||||||
pub builtin_anims: Animations,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<AnimeConfigV472> for AnimeConfig {
|
|
||||||
fn from(c: AnimeConfigV472) -> AnimeConfig {
|
|
||||||
AnimeConfig {
|
|
||||||
system: c.system,
|
|
||||||
boot: c.boot,
|
|
||||||
wake: c.wake,
|
|
||||||
shutdown: c.shutdown,
|
|
||||||
model_override: c.model_override,
|
|
||||||
display_enabled: c.display_enabled,
|
|
||||||
display_brightness: c.display_brightness,
|
|
||||||
builtin_anims_enabled: c.builtin_anims_enabled,
|
|
||||||
builtin_anims: c.builtin_anims,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Default)]
|
|
||||||
pub struct AnimeConfigCached {
|
|
||||||
pub system: Vec<ActionData>,
|
pub system: Vec<ActionData>,
|
||||||
pub boot: Vec<ActionData>,
|
pub boot: Vec<ActionData>,
|
||||||
pub wake: Vec<ActionData>,
|
pub wake: Vec<ActionData>,
|
||||||
pub shutdown: Vec<ActionData>,
|
pub shutdown: Vec<ActionData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnimeConfigCached {
|
impl AniMeConfigCached {
|
||||||
pub fn init_from_config(
|
pub fn init_from_config(
|
||||||
&mut self,
|
&mut self,
|
||||||
config: &AnimeConfig,
|
config: &AniMeConfig,
|
||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<(), AnimeError> {
|
) -> Result<(), AnimeError> {
|
||||||
let mut sys = Vec::with_capacity(config.system.len());
|
let mut sys = Vec::with_capacity(config.system.len());
|
||||||
@@ -107,8 +53,9 @@ impl AnimeConfigCached {
|
|||||||
|
|
||||||
/// Config for base system actions for the anime display
|
/// Config for base system actions for the anime display
|
||||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct AnimeConfig {
|
pub struct AniMeConfig {
|
||||||
pub model_override: Option<AnimeType>,
|
#[serde(skip)]
|
||||||
|
pub anime_type: AnimeType,
|
||||||
pub system: Vec<ActionLoader>,
|
pub system: Vec<ActionLoader>,
|
||||||
pub boot: Vec<ActionLoader>,
|
pub boot: Vec<ActionLoader>,
|
||||||
pub wake: Vec<ActionLoader>,
|
pub wake: Vec<ActionLoader>,
|
||||||
@@ -124,10 +71,10 @@ pub struct AnimeConfig {
|
|||||||
pub builtin_anims: Animations,
|
pub builtin_anims: Animations,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AnimeConfig {
|
impl Default for AniMeConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
AnimeConfig {
|
AniMeConfig {
|
||||||
model_override: None,
|
anime_type: AnimeType::GA402,
|
||||||
system: Vec::new(),
|
system: Vec::new(),
|
||||||
boot: Vec::new(),
|
boot: Vec::new(),
|
||||||
wake: Vec::new(),
|
wake: Vec::new(),
|
||||||
@@ -145,7 +92,7 @@ impl Default for AnimeConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdConfig for AnimeConfig {
|
impl StdConfig for AniMeConfig {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self::create_default()
|
Self::create_default()
|
||||||
}
|
}
|
||||||
@@ -159,10 +106,10 @@ impl StdConfig for AnimeConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdConfigLoad2<AnimeConfigV460, AnimeConfigV472> for AnimeConfig {}
|
impl StdConfigLoad for AniMeConfig {}
|
||||||
|
|
||||||
impl From<&AnimeConfig> for DeviceState {
|
impl From<&AniMeConfig> for DeviceState {
|
||||||
fn from(config: &AnimeConfig) -> Self {
|
fn from(config: &AniMeConfig) -> Self {
|
||||||
DeviceState {
|
DeviceState {
|
||||||
display_enabled: config.display_enabled,
|
display_enabled: config.display_enabled,
|
||||||
display_brightness: config.display_brightness,
|
display_brightness: config.display_brightness,
|
||||||
@@ -176,7 +123,7 @@ impl From<&AnimeConfig> for DeviceState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnimeConfig {
|
impl AniMeConfig {
|
||||||
// fn clamp_config_brightness(mut config: &mut AnimeConfig) {
|
// fn clamp_config_brightness(mut config: &mut AnimeConfig) {
|
||||||
// if config.brightness < 0.0 || config.brightness > 1.0 {
|
// if config.brightness < 0.0 || config.brightness > 1.0 {
|
||||||
// warn!(
|
// warn!(
|
||||||
@@ -189,40 +136,46 @@ impl AnimeConfig {
|
|||||||
|
|
||||||
fn create_default() -> Self {
|
fn create_default() -> Self {
|
||||||
// create a default config here
|
// create a default config here
|
||||||
AnimeConfig {
|
AniMeConfig {
|
||||||
system: vec![],
|
system: vec![],
|
||||||
boot: vec![ActionLoader::ImageAnimation {
|
boot: vec![
|
||||||
file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(),
|
ActionLoader::ImageAnimation {
|
||||||
scale: 0.9,
|
file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(),
|
||||||
angle: 0.65,
|
scale: 0.9,
|
||||||
translation: Vec2::default(),
|
angle: 0.65,
|
||||||
brightness: 1.0,
|
translation: Vec2::default(),
|
||||||
time: AnimTime::Fade(Fade::new(
|
brightness: 1.0,
|
||||||
Duration::from_secs(2),
|
time: AnimTime::Fade(Fade::new(
|
||||||
Some(Duration::from_secs(2)),
|
Duration::from_secs(2),
|
||||||
Duration::from_secs(2),
|
Some(Duration::from_secs(2)),
|
||||||
)),
|
Duration::from_secs(2),
|
||||||
}],
|
)),
|
||||||
wake: vec![ActionLoader::ImageAnimation {
|
},
|
||||||
file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(),
|
],
|
||||||
scale: 0.9,
|
wake: vec![
|
||||||
angle: 0.65,
|
ActionLoader::ImageAnimation {
|
||||||
translation: Vec2::default(),
|
file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(),
|
||||||
brightness: 1.0,
|
scale: 0.9,
|
||||||
time: AnimTime::Fade(Fade::new(
|
angle: 0.65,
|
||||||
Duration::from_secs(2),
|
translation: Vec2::default(),
|
||||||
Some(Duration::from_secs(2)),
|
brightness: 1.0,
|
||||||
Duration::from_secs(2),
|
time: AnimTime::Fade(Fade::new(
|
||||||
)),
|
Duration::from_secs(2),
|
||||||
}],
|
Some(Duration::from_secs(2)),
|
||||||
shutdown: vec![ActionLoader::ImageAnimation {
|
Duration::from_secs(2),
|
||||||
file: "/usr/share/asusd/anime/custom/sonic-wait.gif".into(),
|
)),
|
||||||
scale: 0.9,
|
},
|
||||||
angle: 0.0,
|
],
|
||||||
translation: Vec2::new(3.0, 2.0),
|
shutdown: vec![
|
||||||
brightness: 1.0,
|
ActionLoader::ImageAnimation {
|
||||||
time: AnimTime::Infinite,
|
file: "/usr/share/asusd/anime/custom/sonic-wait.gif".into(),
|
||||||
}],
|
scale: 0.9,
|
||||||
|
angle: 0.0,
|
||||||
|
translation: Vec2::new(3.0, 2.0),
|
||||||
|
brightness: 1.0,
|
||||||
|
time: AnimTime::Infinite,
|
||||||
|
},
|
||||||
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
248
asusd/src/aura_anime/mod.rs
Normal file
248
asusd/src/aura_anime/mod.rs
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
pub mod config;
|
||||||
|
/// Implements `CtrlTask`, Reloadable, `ZbusRun`
|
||||||
|
pub mod trait_impls;
|
||||||
|
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::thread::sleep;
|
||||||
|
|
||||||
|
use config_traits::StdConfig;
|
||||||
|
use log::{debug, error, info, warn};
|
||||||
|
use rog_anime::usb::{
|
||||||
|
pkt_flush, pkt_set_brightness, pkt_set_enable_display, pkt_set_enable_powersave_anim,
|
||||||
|
pkts_for_init, Brightness,
|
||||||
|
};
|
||||||
|
use rog_anime::{ActionData, AnimeDataBuffer, AnimePacketType};
|
||||||
|
use rog_platform::hid_raw::HidRaw;
|
||||||
|
use rog_platform::usb_raw::USBRaw;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
|
use self::config::{AniMeConfig, AniMeConfigCached};
|
||||||
|
use crate::error::RogError;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct AniMe {
|
||||||
|
hid: Option<Arc<Mutex<HidRaw>>>,
|
||||||
|
usb: Option<Arc<Mutex<USBRaw>>>,
|
||||||
|
config: Arc<Mutex<AniMeConfig>>,
|
||||||
|
cache: AniMeConfigCached,
|
||||||
|
// set to force thread to exit
|
||||||
|
thread_exit: Arc<AtomicBool>,
|
||||||
|
// Set to false when the thread exits
|
||||||
|
thread_running: Arc<AtomicBool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AniMe {
|
||||||
|
pub fn new(
|
||||||
|
hid: Option<Arc<Mutex<HidRaw>>>,
|
||||||
|
usb: Option<Arc<Mutex<USBRaw>>>,
|
||||||
|
config: Arc<Mutex<AniMeConfig>>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
hid,
|
||||||
|
usb,
|
||||||
|
config,
|
||||||
|
cache: AniMeConfigCached::default(),
|
||||||
|
thread_exit: Arc::new(AtomicBool::new(false)),
|
||||||
|
thread_running: Arc::new(AtomicBool::new(false)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Will fail if something is already holding the config lock
|
||||||
|
async fn do_init_cache(&mut self) {
|
||||||
|
if let Ok(mut config) = self.config.try_lock() {
|
||||||
|
if let Err(e) = self.cache.init_from_config(&config, config.anime_type) {
|
||||||
|
error!(
|
||||||
|
"Trying to cache the Anime Config failed, will reset to default config: {e:?}"
|
||||||
|
);
|
||||||
|
config.rename_file_old();
|
||||||
|
*config = AniMeConfig::new();
|
||||||
|
config.write();
|
||||||
|
} else {
|
||||||
|
debug!("Initialised AniMe cache");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error!("AniMe Matrix could not init cache")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialise the device if required.
|
||||||
|
pub async fn do_initialization(&mut self) -> Result<(), RogError> {
|
||||||
|
self.do_init_cache().await;
|
||||||
|
let pkts = pkts_for_init();
|
||||||
|
self.write_bytes(&pkts[0]).await?;
|
||||||
|
self.write_bytes(&pkts[1]).await?;
|
||||||
|
debug!("Succesfully initialised AniMe matrix display");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
||||||
|
if let Some(hid) = &self.hid {
|
||||||
|
hid.lock().await.write_bytes(message)?;
|
||||||
|
} else if let Some(usb) = &self.usb {
|
||||||
|
usb.lock().await.write_bytes(message)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write only a data packet. This will modify the leds brightness using the
|
||||||
|
/// global brightness set in config.
|
||||||
|
async fn write_data_buffer(&self, mut buffer: AnimeDataBuffer) -> Result<(), RogError> {
|
||||||
|
for led in buffer.data_mut().iter_mut() {
|
||||||
|
let mut bright = *led as f32;
|
||||||
|
if bright > 254.0 {
|
||||||
|
bright = 254.0;
|
||||||
|
}
|
||||||
|
*led = bright as u8;
|
||||||
|
}
|
||||||
|
let data = AnimePacketType::try_from(buffer)?;
|
||||||
|
for row in &data {
|
||||||
|
self.write_bytes(row).await?;
|
||||||
|
}
|
||||||
|
self.write_bytes(&pkt_flush()).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_builtins_enabled(
|
||||||
|
&self,
|
||||||
|
enabled: bool,
|
||||||
|
bright: Brightness,
|
||||||
|
) -> Result<(), RogError> {
|
||||||
|
self.write_bytes(&pkt_set_enable_powersave_anim(enabled))
|
||||||
|
.await?;
|
||||||
|
self.write_bytes(&pkt_set_enable_display(enabled)).await?;
|
||||||
|
self.write_bytes(&pkt_set_brightness(bright)).await?;
|
||||||
|
self.write_bytes(&pkt_set_enable_powersave_anim(enabled))
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start an action thread. This is classed as a singleton and there should
|
||||||
|
/// be only one running - so the thread uses atomics to signal run/exit.
|
||||||
|
///
|
||||||
|
/// Because this also writes to the usb device, other write tries (display
|
||||||
|
/// only) *must* get the mutex lock and set the `thread_exit` atomic.
|
||||||
|
async fn run_thread(&self, actions: Vec<ActionData>, mut once: bool) {
|
||||||
|
if actions.is_empty() {
|
||||||
|
warn!("AniMe system actions was empty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.write_bytes(&pkt_set_enable_powersave_anim(false))
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("rog_anime::run_animation:callback {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
let thread_exit = self.thread_exit.clone();
|
||||||
|
let thread_running = self.thread_running.clone();
|
||||||
|
let anime_type = self.config.lock().await.anime_type;
|
||||||
|
let inner = self.clone();
|
||||||
|
|
||||||
|
// Loop rules:
|
||||||
|
// - Lock the mutex **only when required**. That is, the lock must be held for
|
||||||
|
// the shortest duration possible.
|
||||||
|
// - An AtomicBool used for thread exit should be checked in every loop,
|
||||||
|
// including nested
|
||||||
|
|
||||||
|
// The only reason for this outer thread is to prevent blocking while waiting
|
||||||
|
// for the next spawned thread to exit
|
||||||
|
// TODO: turn this in to async task (maybe? COuld still risk blocking main
|
||||||
|
// thread)
|
||||||
|
tokio::spawn(async move {
|
||||||
|
info!("AniMe new system thread started");
|
||||||
|
// First two loops are to ensure we *do* aquire a lock on the mutex
|
||||||
|
// The reason the loop is required is because the USB writes can block
|
||||||
|
// for up to 10ms. We can't fail to get the atomics.
|
||||||
|
while thread_running.load(Ordering::SeqCst) {
|
||||||
|
// Make any running loop exit first
|
||||||
|
thread_exit.store(true, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("AniMe no previous system thread running (now)");
|
||||||
|
thread_exit.store(false, Ordering::SeqCst);
|
||||||
|
thread_running.store(true, Ordering::SeqCst);
|
||||||
|
'main: loop {
|
||||||
|
for action in &actions {
|
||||||
|
if thread_exit.load(Ordering::SeqCst) {
|
||||||
|
break 'main;
|
||||||
|
}
|
||||||
|
match action {
|
||||||
|
ActionData::Animation(frames) => {
|
||||||
|
// TODO: sort all this out
|
||||||
|
rog_anime::run_animation(frames, &|frame| {
|
||||||
|
if thread_exit.load(Ordering::Acquire) {
|
||||||
|
info!("rog-anime: animation sub-loop was asked to exit");
|
||||||
|
return Ok(true); // Do safe exit
|
||||||
|
}
|
||||||
|
let inner = inner.clone();
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
inner
|
||||||
|
.write_data_buffer(frame)
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("rog_anime::run_animation:callback {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
});
|
||||||
|
Ok(false) // Don't exit yet
|
||||||
|
});
|
||||||
|
if thread_exit.load(Ordering::Acquire) {
|
||||||
|
info!("rog-anime: sub-loop exited and main loop exiting now");
|
||||||
|
break 'main;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ActionData::Image(image) => {
|
||||||
|
once = false;
|
||||||
|
inner
|
||||||
|
.write_data_buffer(image.as_ref().clone())
|
||||||
|
.await
|
||||||
|
.map_err(|e| error!("{}", e))
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
ActionData::Pause(duration) => sleep(*duration),
|
||||||
|
ActionData::AudioEq
|
||||||
|
| ActionData::SystemInfo
|
||||||
|
| ActionData::TimeDate
|
||||||
|
| ActionData::Matrix => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if thread_exit.load(Ordering::SeqCst) {
|
||||||
|
break 'main;
|
||||||
|
}
|
||||||
|
if once || actions.is_empty() {
|
||||||
|
break 'main;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Clear the display on exit
|
||||||
|
if let Ok(data) =
|
||||||
|
AnimeDataBuffer::from_vec(anime_type, vec![0u8; anime_type.data_length()])
|
||||||
|
.map_err(|e| error!("{}", e))
|
||||||
|
{
|
||||||
|
inner
|
||||||
|
.write_data_buffer(data)
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("rog_anime::run_animation:callback {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
// A write can block for many milliseconds so lets not hold the config lock for
|
||||||
|
// the same period
|
||||||
|
let enabled = inner.config.lock().await.builtin_anims_enabled;
|
||||||
|
inner
|
||||||
|
.write_bytes(&pkt_set_enable_powersave_anim(enabled))
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("rog_anime::run_animation:callback {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
// Loop ended, set the atmonics
|
||||||
|
thread_running.store(false, Ordering::SeqCst);
|
||||||
|
info!("AniMe system thread exited");
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map(|err| info!("AniMe system thread: {:?}", err))
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,22 @@
|
|||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use config_traits::StdConfig;
|
use config_traits::StdConfig;
|
||||||
use log::warn;
|
use log::{debug, error, warn};
|
||||||
use logind_zbus::manager::ManagerProxy;
|
use logind_zbus::manager::ManagerProxy;
|
||||||
use rog_anime::usb::{
|
use rog_anime::usb::{
|
||||||
pkt_set_brightness, pkt_set_builtin_animations, pkt_set_enable_display,
|
pkt_set_brightness, pkt_set_builtin_animations, pkt_set_enable_display,
|
||||||
pkt_set_enable_powersave_anim, Brightness,
|
pkt_set_enable_powersave_anim, Brightness,
|
||||||
};
|
};
|
||||||
use rog_anime::{Animations, AnimeDataBuffer, DeviceState};
|
use rog_anime::{Animations, AnimeDataBuffer, DeviceState};
|
||||||
use zbus::export::futures_util::lock::Mutex;
|
use zbus::object_server::SignalEmitter;
|
||||||
use zbus::{interface, CacheProperties, Connection, SignalContext};
|
use zbus::proxy::CacheProperties;
|
||||||
|
use zbus::zvariant::OwnedObjectPath;
|
||||||
|
use zbus::{interface, Connection};
|
||||||
|
|
||||||
use super::config::AnimeConfig;
|
use super::config::AniMeConfig;
|
||||||
use super::CtrlAnime;
|
use super::AniMe;
|
||||||
use crate::error::RogError;
|
use crate::error::RogError;
|
||||||
|
use crate::Reloadable;
|
||||||
pub const ANIME_ZBUS_NAME: &str = "Anime";
|
|
||||||
pub const ANIME_ZBUS_PATH: &str = "/org/asuslinux";
|
|
||||||
|
|
||||||
async fn get_logind_manager<'a>() -> ManagerProxy<'a> {
|
async fn get_logind_manager<'a>() -> ManagerProxy<'a> {
|
||||||
let connection = Connection::system()
|
let connection = Connection::system()
|
||||||
@@ -32,104 +31,121 @@ async fn get_logind_manager<'a>() -> ManagerProxy<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CtrlAnimeZbus(pub Arc<Mutex<CtrlAnime>>);
|
pub struct AniMeZbus(AniMe);
|
||||||
|
|
||||||
/// The struct with the main dbus methods requires this trait
|
impl AniMeZbus {
|
||||||
impl crate::ZbusRun for CtrlAnimeZbus {
|
pub fn new(anime: AniMe) -> Self {
|
||||||
async fn add_to_server(self, server: &mut Connection) {
|
Self(anime)
|
||||||
Self::add_to_server_helper(self, ANIME_ZBUS_PATH, server).await;
|
}
|
||||||
|
|
||||||
|
pub async fn start_tasks(
|
||||||
|
mut self,
|
||||||
|
connection: &Connection,
|
||||||
|
path: OwnedObjectPath,
|
||||||
|
) -> Result<(), RogError> {
|
||||||
|
// let task = zbus.clone();
|
||||||
|
self.reload()
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|err| warn!("Controller error: {}", err));
|
||||||
|
connection
|
||||||
|
.object_server()
|
||||||
|
.at(path.clone(), self)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Couldn't add server at path: {path}, {e:?}");
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
debug!("start_tasks was successful");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// None of these calls can be guarnateed to succeed unless we loop until okay
|
// None of these calls can be guarnateed to succeed unless we loop until okay
|
||||||
// If the try_lock *does* succeed then any other thread trying to lock will not
|
// If the try_lock *does* succeed then any other thread trying to lock will not
|
||||||
// grab it until we finish.
|
// grab it until we finish.
|
||||||
#[interface(name = "org.asuslinux.Anime")]
|
#[interface(name = "xyz.ljones.Anime")]
|
||||||
impl CtrlAnimeZbus {
|
impl AniMeZbus {
|
||||||
/// Writes a data stream of length. Will force system thread to exit until
|
/// Writes a data stream of length. Will force system thread to exit until
|
||||||
/// it is restarted
|
/// it is restarted
|
||||||
async fn write(&self, input: AnimeDataBuffer) -> zbus::fdo::Result<()> {
|
async fn write(&self, input: AnimeDataBuffer) -> zbus::fdo::Result<()> {
|
||||||
self.0
|
let bright = self.0.config.lock().await.display_brightness;
|
||||||
.lock()
|
if self.0.config.lock().await.builtin_anims_enabled {
|
||||||
.await
|
// This clears the display, causing flickers if done indiscriminately on every
|
||||||
.thread_exit
|
// write. Therefore, we guard it behind a config check.
|
||||||
.store(true, Ordering::SeqCst);
|
self.0.set_builtins_enabled(false, bright).await?;
|
||||||
self.0
|
}
|
||||||
.lock()
|
self.0.thread_exit.store(true, Ordering::SeqCst);
|
||||||
.await
|
self.0.write_data_buffer(input).await.map_err(|err| {
|
||||||
.write_data_buffer(input)
|
warn!("ctrl_anime::run_animation:callback {}", err);
|
||||||
.map_err(|err| {
|
err
|
||||||
warn!("ctrl_anime::run_animation:callback {}", err);
|
})?;
|
||||||
err
|
|
||||||
})?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set base brightness level
|
/// Set base brightness level
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn brightness(&self) -> Brightness {
|
async fn brightness(&self) -> Brightness {
|
||||||
self.0.lock().await.config.display_brightness
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
|
return config.display_brightness;
|
||||||
|
}
|
||||||
|
Brightness::Off
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set base brightness level
|
/// Set base brightness level
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn set_brightness(&self, brightness: Brightness) {
|
async fn set_brightness(&self, brightness: Brightness) {
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_brightness(brightness))
|
.write_bytes(&pkt_set_brightness(brightness))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("ctrl_anime::set_brightness {}", err);
|
warn!("ctrl_anime::set_brightness {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_display(brightness != Brightness::Off))
|
.write_bytes(&pkt_set_enable_display(brightness != Brightness::Off))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("ctrl_anime::set_brightness {}", err);
|
warn!("ctrl_anime::set_brightness {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
self.0.lock().await.config.display_enabled = brightness != Brightness::Off;
|
let mut config = self.0.config.lock().await;
|
||||||
self.0.lock().await.config.display_brightness = brightness;
|
config.display_enabled = brightness != Brightness::Off;
|
||||||
self.0.lock().await.config.write();
|
config.display_brightness = brightness;
|
||||||
|
config.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn builtins_enabled(&self) -> bool {
|
async fn builtins_enabled(&self) -> bool {
|
||||||
let lock = self.0.lock().await;
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
lock.config.builtin_anims_enabled
|
return config.builtin_anims_enabled;
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable the builtin animations or not. This is quivalent to "Powersave
|
/// Enable the builtin animations or not. This is quivalent to "Powersave
|
||||||
/// animations" in Armory crate
|
/// animations" in Armory crate
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn set_builtins_enabled(&self, enabled: bool) {
|
async fn set_builtins_enabled(&self, enabled: bool) {
|
||||||
let brightness = self.0.lock().await.config.display_brightness;
|
let mut config = self.0.config.lock().await;
|
||||||
|
let brightness = config.display_brightness;
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.set_builtins_enabled(enabled, brightness)
|
.set_builtins_enabled(enabled, brightness)
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("ctrl_anime::set_builtins_enabled {}", err);
|
warn!("ctrl_anime::set_builtins_enabled {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
if !enabled {
|
if !enabled {
|
||||||
let anime_type = self.0.lock().await.anime_type;
|
let anime_type = config.anime_type;
|
||||||
let data = vec![255u8; anime_type.data_length()];
|
let data = vec![255u8; anime_type.data_length()];
|
||||||
if let Ok(tmp) = AnimeDataBuffer::from_vec(anime_type, data).map_err(|err| {
|
if let Ok(tmp) = AnimeDataBuffer::from_vec(anime_type, data).map_err(|err| {
|
||||||
warn!("ctrl_anime::set_builtins_enabled {}", err);
|
warn!("ctrl_anime::set_builtins_enabled {}", err);
|
||||||
}) {
|
}) {
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(tmp.data())
|
.write_bytes(tmp.data())
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("ctrl_anime::set_builtins_enabled {}", err);
|
warn!("ctrl_anime::set_builtins_enabled {}", err);
|
||||||
})
|
})
|
||||||
@@ -137,77 +153,75 @@ impl CtrlAnimeZbus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.0.lock().await.config.builtin_anims_enabled = enabled;
|
config.builtin_anims_enabled = enabled;
|
||||||
self.0.lock().await.config.write();
|
config.write();
|
||||||
if enabled {
|
if enabled {
|
||||||
self.0
|
self.0.thread_exit.store(true, Ordering::Release);
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.thread_exit
|
|
||||||
.store(true, Ordering::Release);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn builtin_animations(&self) -> Animations {
|
async fn builtin_animations(&self) -> Animations {
|
||||||
self.0.lock().await.config.builtin_anims
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
|
return config.builtin_anims;
|
||||||
|
}
|
||||||
|
Animations::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set which builtin animation is used for each stage
|
/// Set which builtin animation is used for each stage
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn set_builtin_animations(&self, settings: Animations) {
|
async fn set_builtin_animations(&self, settings: Animations) {
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_builtin_animations(
|
.write_bytes(&pkt_set_builtin_animations(
|
||||||
settings.boot,
|
settings.boot, settings.awake, settings.sleep, settings.shutdown,
|
||||||
settings.awake,
|
|
||||||
settings.sleep,
|
|
||||||
settings.shutdown,
|
|
||||||
))
|
))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("ctrl_anime::run_animation:callback {}", err);
|
warn!("ctrl_anime::run_animation:callback {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_powersave_anim(true))
|
.write_bytes(&pkt_set_enable_powersave_anim(true))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("ctrl_anime::run_animation:callback {}", err);
|
warn!("ctrl_anime::run_animation:callback {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
self.0.lock().await.config.display_enabled = true;
|
let mut config = self.0.config.lock().await;
|
||||||
self.0.lock().await.config.builtin_anims = settings;
|
config.display_enabled = true;
|
||||||
self.0.lock().await.config.write();
|
config.builtin_anims = settings;
|
||||||
|
config.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn enable_display(&self) -> bool {
|
async fn enable_display(&self) -> bool {
|
||||||
self.0.lock().await.config.display_enabled
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
|
return config.display_enabled;
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set whether the AniMe is enabled at all
|
/// Set whether the AniMe is enabled at all
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn set_enable_display(&self, enabled: bool) {
|
async fn set_enable_display(&self, enabled: bool) {
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_display(enabled))
|
.write_bytes(&pkt_set_enable_display(enabled))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("ctrl_anime::run_animation:callback {}", err);
|
warn!("ctrl_anime::run_animation:callback {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
self.0.lock().await.config.display_enabled = enabled;
|
let mut config = self.0.config.lock().await;
|
||||||
self.0.lock().await.config.write();
|
config.display_enabled = enabled;
|
||||||
|
config.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn off_when_unplugged(&self) -> bool {
|
async fn off_when_unplugged(&self) -> bool {
|
||||||
self.0.lock().await.config.off_when_unplugged
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
|
return config.off_when_unplugged;
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set if to turn the AniMe Matrix off when external power is unplugged
|
/// Set if to turn the AniMe Matrix off when external power is unplugged
|
||||||
@@ -217,34 +231,40 @@ impl CtrlAnimeZbus {
|
|||||||
let pow = manager.on_external_power().await.unwrap_or_default();
|
let pow = manager.on_external_power().await.unwrap_or_default();
|
||||||
|
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_display(!pow && !enabled))
|
.write_bytes(&pkt_set_enable_display(!pow && !enabled))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("create_sys_event_tasks::off_when_lid_closed {}", err);
|
warn!("create_sys_event_tasks::off_when_lid_closed {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
self.0.lock().await.config.off_when_unplugged = enabled;
|
let mut config = self.0.config.lock().await;
|
||||||
self.0.lock().await.config.write();
|
config.off_when_unplugged = enabled;
|
||||||
|
config.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn off_when_suspended(&self) -> bool {
|
async fn off_when_suspended(&self) -> bool {
|
||||||
self.0.lock().await.config.off_when_suspended
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
|
return config.off_when_suspended;
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set if to turn the AniMe Matrix off when the laptop is suspended
|
/// Set if to turn the AniMe Matrix off when the laptop is suspended
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn set_off_when_suspended(&self, enabled: bool) {
|
async fn set_off_when_suspended(&self, enabled: bool) {
|
||||||
self.0.lock().await.config.off_when_suspended = enabled;
|
let mut config = self.0.config.lock().await;
|
||||||
self.0.lock().await.config.write();
|
config.off_when_suspended = enabled;
|
||||||
|
config.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn off_when_lid_closed(&self) -> bool {
|
async fn off_when_lid_closed(&self) -> bool {
|
||||||
self.0.lock().await.config.off_when_lid_closed
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
|
return config.off_when_lid_closed;
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set if to turn the AniMe Matrix off when the lid is closed
|
/// Set if to turn the AniMe Matrix off when the lid is closed
|
||||||
@@ -254,50 +274,40 @@ impl CtrlAnimeZbus {
|
|||||||
let lid = manager.lid_closed().await.unwrap_or_default();
|
let lid = manager.lid_closed().await.unwrap_or_default();
|
||||||
|
|
||||||
self.0
|
self.0
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_display(lid && !enabled))
|
.write_bytes(&pkt_set_enable_display(lid && !enabled))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("create_sys_event_tasks::off_when_lid_closed {}", err);
|
warn!("create_sys_event_tasks::off_when_lid_closed {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
self.0.lock().await.config.off_when_lid_closed = enabled;
|
let mut config = self.0.config.lock().await;
|
||||||
self.0.lock().await.config.write();
|
config.off_when_lid_closed = enabled;
|
||||||
|
config.write();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The main loop is the base system set action if the user isn't running
|
/// The main loop is the base system set action if the user isn't running
|
||||||
/// the user daemon
|
/// the user daemon
|
||||||
async fn run_main_loop(&self, start: bool) {
|
async fn run_main_loop(&self, start: bool) {
|
||||||
if start {
|
if start {
|
||||||
self.0
|
self.0.thread_exit.store(true, Ordering::SeqCst);
|
||||||
.lock()
|
self.0.run_thread(self.0.cache.system.clone(), false).await;
|
||||||
.await
|
|
||||||
.thread_exit
|
|
||||||
.store(true, Ordering::SeqCst);
|
|
||||||
CtrlAnime::run_thread(
|
|
||||||
self.0.clone(),
|
|
||||||
self.0.lock().await.cache.system.clone(),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the device state as stored by asusd
|
/// Get the device state as stored by asusd
|
||||||
// #[zbus(property)]
|
// #[zbus(property)]
|
||||||
async fn device_state(&self) -> DeviceState {
|
async fn device_state(&self) -> DeviceState {
|
||||||
DeviceState::from(&self.0.lock().await.config)
|
DeviceState::from(&*self.0.config.lock().await)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::CtrlTask for CtrlAnimeZbus {
|
impl crate::CtrlTask for AniMeZbus {
|
||||||
fn zbus_path() -> &'static str {
|
fn zbus_path() -> &'static str {
|
||||||
ANIME_ZBUS_PATH
|
"ANIME_ZBUS_PATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_tasks(&self, _: SignalContext<'static>) -> Result<(), RogError> {
|
async fn create_tasks(&self, _: SignalEmitter<'static>) -> Result<(), RogError> {
|
||||||
let inner1 = self.0.clone();
|
let inner1 = self.0.clone();
|
||||||
let inner2 = self.0.clone();
|
let inner2 = self.0.clone();
|
||||||
let inner3 = self.0.clone();
|
let inner3 = self.0.clone();
|
||||||
@@ -307,21 +317,15 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
|||||||
// on_sleep
|
// on_sleep
|
||||||
let inner = inner1.clone();
|
let inner = inner1.clone();
|
||||||
async move {
|
async move {
|
||||||
let config = inner.lock().await.config.clone();
|
let config = inner.config.lock().await.clone();
|
||||||
if config.display_enabled {
|
if config.display_enabled {
|
||||||
inner
|
inner.thread_exit.store(true, Ordering::Release); // ensure clean slate
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.thread_exit
|
|
||||||
.store(true, Ordering::Release); // ensure clean slate
|
|
||||||
|
|
||||||
inner
|
inner
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_display(
|
.write_bytes(&pkt_set_enable_display(
|
||||||
!(sleeping && config.off_when_suspended),
|
!(sleeping && config.off_when_suspended),
|
||||||
))
|
))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("create_sys_event_tasks::off_when_suspended {}", err);
|
warn!("create_sys_event_tasks::off_when_suspended {}", err);
|
||||||
})
|
})
|
||||||
@@ -329,12 +333,10 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
|||||||
|
|
||||||
if config.builtin_anims_enabled {
|
if config.builtin_anims_enabled {
|
||||||
inner
|
inner
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_powersave_anim(
|
.write_bytes(&pkt_set_enable_powersave_anim(
|
||||||
!(sleeping && config.off_when_suspended),
|
!(sleeping && config.off_when_suspended),
|
||||||
))
|
))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("create_sys_event_tasks::off_when_suspended {}", err);
|
warn!("create_sys_event_tasks::off_when_suspended {}", err);
|
||||||
})
|
})
|
||||||
@@ -342,18 +344,11 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
|||||||
} else if !sleeping && !config.builtin_anims_enabled {
|
} else if !sleeping && !config.builtin_anims_enabled {
|
||||||
// Run custom wake animation
|
// Run custom wake animation
|
||||||
inner
|
inner
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_powersave_anim(false))
|
.write_bytes(&pkt_set_enable_powersave_anim(false))
|
||||||
|
.await
|
||||||
.ok(); // ensure builtins are disabled
|
.ok(); // ensure builtins are disabled
|
||||||
|
|
||||||
CtrlAnime::run_thread(
|
inner.run_thread(inner.cache.wake.clone(), true).await;
|
||||||
inner.clone(),
|
|
||||||
inner.lock().await.cache.wake.clone(),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -362,26 +357,16 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
|||||||
// on_shutdown
|
// on_shutdown
|
||||||
let inner = inner2.clone();
|
let inner = inner2.clone();
|
||||||
async move {
|
async move {
|
||||||
let AnimeConfig {
|
let AniMeConfig {
|
||||||
display_enabled,
|
display_enabled,
|
||||||
builtin_anims_enabled,
|
builtin_anims_enabled,
|
||||||
..
|
..
|
||||||
} = inner.lock().await.config;
|
} = *inner.config.lock().await;
|
||||||
if display_enabled && !builtin_anims_enabled {
|
if display_enabled && !builtin_anims_enabled {
|
||||||
if shutting_down {
|
if shutting_down {
|
||||||
CtrlAnime::run_thread(
|
inner.run_thread(inner.cache.shutdown.clone(), true).await;
|
||||||
inner.clone(),
|
|
||||||
inner.lock().await.cache.shutdown.clone(),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
} else {
|
} else {
|
||||||
CtrlAnime::run_thread(
|
inner.run_thread(inner.cache.boot.clone(), true).await;
|
||||||
inner.clone(),
|
|
||||||
inner.lock().await.cache.boot.clone(),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -390,28 +375,24 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
|||||||
let inner = inner3.clone();
|
let inner = inner3.clone();
|
||||||
// on lid change
|
// on lid change
|
||||||
async move {
|
async move {
|
||||||
let AnimeConfig {
|
let AniMeConfig {
|
||||||
off_when_lid_closed,
|
off_when_lid_closed,
|
||||||
builtin_anims_enabled,
|
builtin_anims_enabled,
|
||||||
..
|
..
|
||||||
} = inner.lock().await.config;
|
} = *inner.config.lock().await;
|
||||||
if off_when_lid_closed {
|
if off_when_lid_closed {
|
||||||
if builtin_anims_enabled {
|
if builtin_anims_enabled {
|
||||||
inner
|
inner
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_powersave_anim(!lid_closed))
|
.write_bytes(&pkt_set_enable_powersave_anim(!lid_closed))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("create_sys_event_tasks::off_when_suspended {}", err);
|
warn!("create_sys_event_tasks::off_when_suspended {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
inner
|
inner
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_display(!lid_closed))
|
.write_bytes(&pkt_set_enable_display(!lid_closed))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("create_sys_event_tasks::off_when_lid_closed {}", err);
|
warn!("create_sys_event_tasks::off_when_lid_closed {}", err);
|
||||||
})
|
})
|
||||||
@@ -423,39 +404,33 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
|||||||
let inner = inner4.clone();
|
let inner = inner4.clone();
|
||||||
// on power change
|
// on power change
|
||||||
async move {
|
async move {
|
||||||
let AnimeConfig {
|
let AniMeConfig {
|
||||||
off_when_unplugged,
|
off_when_unplugged,
|
||||||
builtin_anims_enabled,
|
builtin_anims_enabled,
|
||||||
brightness_on_battery,
|
brightness_on_battery,
|
||||||
..
|
..
|
||||||
} = inner.lock().await.config;
|
} = *inner.config.lock().await;
|
||||||
if off_when_unplugged {
|
if off_when_unplugged {
|
||||||
if builtin_anims_enabled {
|
if builtin_anims_enabled {
|
||||||
inner
|
inner
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_powersave_anim(power_plugged))
|
.write_bytes(&pkt_set_enable_powersave_anim(power_plugged))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("create_sys_event_tasks::off_when_suspended {}", err);
|
warn!("create_sys_event_tasks::off_when_suspended {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
inner
|
inner
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_enable_display(power_plugged))
|
.write_bytes(&pkt_set_enable_display(power_plugged))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("create_sys_event_tasks::off_when_unplugged {}", err);
|
warn!("create_sys_event_tasks::off_when_unplugged {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
} else {
|
} else {
|
||||||
inner
|
inner
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.node
|
|
||||||
.write_bytes(&pkt_set_brightness(brightness_on_battery))
|
.write_bytes(&pkt_set_brightness(brightness_on_battery))
|
||||||
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!("create_sys_event_tasks::off_when_unplugged {}", err);
|
warn!("create_sys_event_tasks::off_when_unplugged {}", err);
|
||||||
})
|
})
|
||||||
@@ -470,52 +445,62 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::Reloadable for CtrlAnimeZbus {
|
impl crate::Reloadable for AniMeZbus {
|
||||||
async fn reload(&mut self) -> Result<(), RogError> {
|
async fn reload(&mut self) -> Result<(), RogError> {
|
||||||
if let Some(lock) = self.0.try_lock() {
|
let AniMeConfig {
|
||||||
let anim = &lock.config.builtin_anims;
|
builtin_anims_enabled,
|
||||||
// Set builtins
|
builtin_anims,
|
||||||
if lock.config.builtin_anims_enabled {
|
display_enabled,
|
||||||
lock.node.write_bytes(&pkt_set_builtin_animations(
|
display_brightness,
|
||||||
anim.boot,
|
off_when_lid_closed,
|
||||||
anim.awake,
|
off_when_unplugged,
|
||||||
anim.sleep,
|
..
|
||||||
anim.shutdown,
|
} = *self.0.config.lock().await;
|
||||||
))?;
|
|
||||||
}
|
|
||||||
// Builtins enabled or na?
|
|
||||||
lock.node.set_builtins_enabled(
|
|
||||||
lock.config.builtin_anims_enabled,
|
|
||||||
lock.config.display_brightness,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let manager = get_logind_manager().await;
|
// Set builtins
|
||||||
let lid_closed = manager.lid_closed().await.unwrap_or_default();
|
if builtin_anims_enabled {
|
||||||
let power_plugged = manager.on_external_power().await.unwrap_or_default();
|
self.0
|
||||||
|
.write_bytes(&pkt_set_builtin_animations(
|
||||||
|
builtin_anims.boot,
|
||||||
|
builtin_anims.awake,
|
||||||
|
builtin_anims.sleep,
|
||||||
|
builtin_anims.shutdown,
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
// Builtins enabled or na?
|
||||||
|
self.0
|
||||||
|
.set_builtins_enabled(builtin_anims_enabled, display_brightness)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let turn_off = (lid_closed && lock.config.off_when_lid_closed)
|
let manager = get_logind_manager().await;
|
||||||
|| (!power_plugged && lock.config.off_when_unplugged);
|
let lid_closed = manager.lid_closed().await.unwrap_or_default();
|
||||||
lock.node
|
let power_plugged = manager.on_external_power().await.unwrap_or_default();
|
||||||
.write_bytes(&pkt_set_enable_display(!turn_off))
|
|
||||||
.map_err(|err| {
|
let turn_off =
|
||||||
warn!("create_sys_event_tasks::reload {}", err);
|
(lid_closed && off_when_lid_closed) || (!power_plugged && off_when_unplugged);
|
||||||
})
|
self.0
|
||||||
|
.write_bytes(&pkt_set_enable_display(!turn_off))
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("create_sys_event_tasks::reload {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
if turn_off || !display_enabled {
|
||||||
|
self.0.write_bytes(&pkt_set_enable_display(false)).await?;
|
||||||
|
// early return so we don't run animation thread
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
if !builtin_anims_enabled && !self.0.cache.boot.is_empty() {
|
||||||
|
self.0
|
||||||
|
.write_bytes(&pkt_set_enable_powersave_anim(false))
|
||||||
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
if turn_off || !lock.config.display_enabled {
|
let action = self.0.cache.boot.clone();
|
||||||
lock.node.write_bytes(&pkt_set_enable_display(false))?;
|
self.0.run_thread(action, true).await;
|
||||||
// early return so we don't run animation thread
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
if !lock.config.builtin_anims_enabled && !lock.cache.boot.is_empty() {
|
|
||||||
lock.node
|
|
||||||
.write_bytes(&pkt_set_enable_powersave_anim(false))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
let action = lock.cache.boot.clone();
|
|
||||||
CtrlAnime::run_thread(self.0.clone(), action, true).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -7,12 +7,20 @@ use rog_aura::keyboard::LaptopAuraPower;
|
|||||||
use rog_aura::{
|
use rog_aura::{
|
||||||
AuraDeviceType, AuraEffect, AuraModeNum, AuraZone, Direction, LedBrightness, Speed, GRADIENT,
|
AuraDeviceType, AuraEffect, AuraModeNum, AuraZone, Direction, LedBrightness, Speed, GRADIENT,
|
||||||
};
|
};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::error::RogError;
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Default, Debug, Clone)]
|
#[derive(Deserialize, Serialize, Default, Debug, Clone)]
|
||||||
// #[serde(default)]
|
// #[serde(default)]
|
||||||
pub struct AuraConfig {
|
pub struct AuraConfig {
|
||||||
|
#[serde(skip)]
|
||||||
|
pub led_type: AuraDeviceType,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub support_data: LedSupportData,
|
||||||
pub config_name: String,
|
pub config_name: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub ally_fix: Option<bool>,
|
||||||
pub brightness: LedBrightness,
|
pub brightness: LedBrightness,
|
||||||
pub current_mode: AuraModeNum,
|
pub current_mode: AuraModeNum,
|
||||||
pub builtins: BTreeMap<AuraModeNum, AuraEffect>,
|
pub builtins: BTreeMap<AuraModeNum, AuraEffect>,
|
||||||
@@ -20,6 +28,8 @@ pub struct AuraConfig {
|
|||||||
pub multizone: Option<BTreeMap<AuraModeNum, Vec<AuraEffect>>>,
|
pub multizone: Option<BTreeMap<AuraModeNum, Vec<AuraEffect>>>,
|
||||||
pub multizone_on: bool,
|
pub multizone_on: bool,
|
||||||
pub enabled: LaptopAuraPower,
|
pub enabled: LaptopAuraPower,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub per_key_mode_active: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdConfig for AuraConfig {
|
impl StdConfig for AuraConfig {
|
||||||
@@ -54,24 +64,29 @@ impl AuraConfig {
|
|||||||
let support_data = LedSupportData::get_data(prod_id);
|
let support_data = LedSupportData::get_data(prod_id);
|
||||||
let enabled = LaptopAuraPower::new(device_type, &support_data);
|
let enabled = LaptopAuraPower::new(device_type, &support_data);
|
||||||
let mut config = AuraConfig {
|
let mut config = AuraConfig {
|
||||||
|
led_type: device_type,
|
||||||
|
support_data,
|
||||||
config_name: format!("aura_{prod_id}.ron"),
|
config_name: format!("aura_{prod_id}.ron"),
|
||||||
|
ally_fix: None,
|
||||||
brightness: LedBrightness::Med,
|
brightness: LedBrightness::Med,
|
||||||
current_mode: AuraModeNum::Static,
|
current_mode: AuraModeNum::Static,
|
||||||
builtins: BTreeMap::new(),
|
builtins: BTreeMap::new(),
|
||||||
multizone: None,
|
multizone: None,
|
||||||
multizone_on: false,
|
multizone_on: false,
|
||||||
enabled,
|
enabled,
|
||||||
|
per_key_mode_active: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
for n in &support_data.basic_modes {
|
for n in &config.support_data.basic_modes {
|
||||||
debug!("creating default for {n}");
|
debug!("creating default for {n}");
|
||||||
config
|
config
|
||||||
.builtins
|
.builtins
|
||||||
.insert(*n, AuraEffect::default_with_mode(*n));
|
.insert(*n, AuraEffect::default_with_mode(*n));
|
||||||
|
}
|
||||||
if !support_data.basic_zones.is_empty() {
|
if !config.support_data.basic_zones.is_empty() {
|
||||||
|
for n in &config.support_data.basic_modes {
|
||||||
let mut default = vec![];
|
let mut default = vec![];
|
||||||
for (i, tmp) in support_data.basic_zones.iter().enumerate() {
|
for (i, tmp) in config.support_data.basic_zones.iter().enumerate() {
|
||||||
default.push(AuraEffect {
|
default.push(AuraEffect {
|
||||||
mode: *n,
|
mode: *n,
|
||||||
zone: *tmp,
|
zone: *tmp,
|
||||||
@@ -104,14 +119,14 @@ impl AuraConfig {
|
|||||||
self.multizone_on = false;
|
self.multizone_on = false;
|
||||||
} else {
|
} else {
|
||||||
if let Some(multi) = self.multizone.as_mut() {
|
if let Some(multi) = self.multizone.as_mut() {
|
||||||
if let Some(fx) = multi.get_mut(effect.mode()) {
|
if let Some(fx_vec) = multi.get_mut(effect.mode()) {
|
||||||
for fx in fx.iter_mut() {
|
for fx in fx_vec.iter_mut() {
|
||||||
if fx.zone == effect.zone {
|
if fx.zone == effect.zone {
|
||||||
*fx = effect;
|
*fx = effect;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fx.push(effect);
|
fx_vec.push(effect);
|
||||||
} else {
|
} else {
|
||||||
multi.insert(*effect.mode(), vec![effect]);
|
multi.insert(*effect.mode(), vec![effect]);
|
||||||
}
|
}
|
||||||
@@ -130,16 +145,116 @@ impl AuraConfig {
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a default for the `current_mode` if multizone and no config
|
||||||
|
/// exists.
|
||||||
|
pub fn create_multizone_default(&mut self) -> Result<(), RogError> {
|
||||||
|
let mut default = vec![];
|
||||||
|
for (i, tmp) in self.support_data.basic_zones.iter().enumerate() {
|
||||||
|
default.push(AuraEffect {
|
||||||
|
mode: self.current_mode,
|
||||||
|
zone: *tmp,
|
||||||
|
colour1: *GRADIENT.get(i).unwrap_or(&GRADIENT[0]),
|
||||||
|
colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]),
|
||||||
|
speed: Speed::Med,
|
||||||
|
direction: Direction::Left,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if default.is_empty() {
|
||||||
|
return Err(RogError::AuraEffectNotSupported);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(multizones) = self.multizone.as_mut() {
|
||||||
|
multizones.insert(self.current_mode, default);
|
||||||
|
} else {
|
||||||
|
let mut tmp = BTreeMap::new();
|
||||||
|
tmp.insert(self.current_mode, default);
|
||||||
|
self.multizone = Some(tmp);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reload the config from disk then verify and update it if required.
|
||||||
|
/// Always rewrites the file to disk.
|
||||||
|
pub fn load_and_update_config(prod_id: &str) -> AuraConfig {
|
||||||
|
// New loads data from the DB also
|
||||||
|
let mut config_init = AuraConfig::new(prod_id);
|
||||||
|
// config_init.set_filename(prod_id);
|
||||||
|
let mut config_loaded = config_init.clone().load();
|
||||||
|
// update the initialised data with what we loaded from disk
|
||||||
|
for mode_init in &mut config_init.builtins {
|
||||||
|
// update init values from loaded values if they exist
|
||||||
|
if let Some(loaded) = config_loaded.builtins.get(mode_init.0) {
|
||||||
|
*mode_init.1 = loaded.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Then replace just incase the initialised data contains new modes added
|
||||||
|
config_loaded.builtins = config_init.builtins;
|
||||||
|
config_loaded.support_data = config_init.support_data;
|
||||||
|
config_loaded.led_type = config_init.led_type;
|
||||||
|
config_loaded.ally_fix = config_init.ally_fix;
|
||||||
|
|
||||||
|
for enabled_init in &mut config_init.enabled.states {
|
||||||
|
for enabled in &mut config_loaded.enabled.states {
|
||||||
|
if enabled.zone == enabled_init.zone {
|
||||||
|
*enabled_init = *enabled;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config_loaded.enabled = config_init.enabled;
|
||||||
|
|
||||||
|
if let (Some(mut multizone_init), Some(multizone_loaded)) =
|
||||||
|
(config_init.multizone, config_loaded.multizone.as_mut())
|
||||||
|
{
|
||||||
|
for mode in multizone_init.iter_mut() {
|
||||||
|
// update init values from loaded values if they exist
|
||||||
|
if let Some(loaded) = multizone_loaded.get(mode.0) {
|
||||||
|
let mut new_set = Vec::new();
|
||||||
|
let data = LedSupportData::get_data(prod_id);
|
||||||
|
// only reuse a zone mode if the mode is supported
|
||||||
|
for mode in loaded {
|
||||||
|
if data.basic_modes.contains(&mode.mode) {
|
||||||
|
new_set.push(mode.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*mode.1 = new_set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*multizone_loaded = multizone_init;
|
||||||
|
}
|
||||||
|
|
||||||
|
config_loaded.write();
|
||||||
|
config_loaded
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour};
|
use std::sync::{Mutex, MutexGuard, OnceLock};
|
||||||
|
|
||||||
|
use rog_aura::keyboard::AuraPowerState;
|
||||||
|
use rog_aura::{
|
||||||
|
AuraEffect, AuraModeNum, AuraZone, Colour, Direction, LedBrightness, PowerZones, Speed,
|
||||||
|
};
|
||||||
|
|
||||||
use super::AuraConfig;
|
use super::AuraConfig;
|
||||||
|
|
||||||
|
// Global mutex to serialize tests that rely on process-wide environment
|
||||||
|
// variables
|
||||||
|
static TEST_MUTEX: OnceLock<Mutex<()>> = OnceLock::new();
|
||||||
|
|
||||||
|
fn test_lock() -> MutexGuard<'static, ()> {
|
||||||
|
TEST_MUTEX
|
||||||
|
.get_or_init(|| Mutex::new(()))
|
||||||
|
.lock()
|
||||||
|
.expect("TEST_MUTEX poisoned")
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn set_multizone_4key_config() {
|
fn set_multizone_4key_config() {
|
||||||
|
let _guard = test_lock();
|
||||||
|
std::env::set_var("BOARD_NAME", "");
|
||||||
let mut config = AuraConfig::new("19b6");
|
let mut config = AuraConfig::new("19b6");
|
||||||
|
|
||||||
let effect = AuraEffect {
|
let effect = AuraEffect {
|
||||||
@@ -230,6 +345,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn set_multizone_multimode_config() {
|
fn set_multizone_multimode_config() {
|
||||||
|
let _guard = test_lock();
|
||||||
|
std::env::set_var("BOARD_NAME", "");
|
||||||
let mut config = AuraConfig::new("19b6");
|
let mut config = AuraConfig::new("19b6");
|
||||||
|
|
||||||
let effect = AuraEffect {
|
let effect = AuraEffect {
|
||||||
@@ -274,4 +391,68 @@ mod tests {
|
|||||||
let sta = res.get(&AuraModeNum::Pulse).unwrap();
|
let sta = res.get(&AuraModeNum::Pulse).unwrap();
|
||||||
assert_eq!(sta.len(), 1);
|
assert_eq!(sta.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn verify_0x1866_g531i() {
|
||||||
|
let _guard = test_lock();
|
||||||
|
std::env::set_var("BOARD_NAME", "G513I");
|
||||||
|
let mut config = AuraConfig::new("1866");
|
||||||
|
|
||||||
|
assert_eq!(config.brightness, LedBrightness::Med);
|
||||||
|
assert_eq!(config.builtins.len(), 5);
|
||||||
|
assert_eq!(
|
||||||
|
config.builtins.first_entry().unwrap().get(),
|
||||||
|
&AuraEffect {
|
||||||
|
mode: AuraModeNum::Static,
|
||||||
|
zone: AuraZone::None,
|
||||||
|
colour1: Colour { r: 166, g: 0, b: 0 },
|
||||||
|
colour2: Colour { r: 0, g: 0, b: 0 },
|
||||||
|
speed: Speed::Med,
|
||||||
|
direction: Direction::Right
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(config.enabled.states.len(), 1);
|
||||||
|
assert_eq!(
|
||||||
|
config.enabled.states[0],
|
||||||
|
AuraPowerState {
|
||||||
|
zone: PowerZones::KeyboardAndLightbar,
|
||||||
|
boot: true,
|
||||||
|
awake: true,
|
||||||
|
sleep: true,
|
||||||
|
shutdown: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn verify_0x19b6_g634j() {
|
||||||
|
let _guard = test_lock();
|
||||||
|
std::env::set_var("BOARD_NAME", "G634J");
|
||||||
|
let mut config = AuraConfig::new("19b6");
|
||||||
|
|
||||||
|
assert_eq!(config.brightness, LedBrightness::Med);
|
||||||
|
assert_eq!(config.builtins.len(), 12);
|
||||||
|
assert_eq!(
|
||||||
|
config.builtins.first_entry().unwrap().get(),
|
||||||
|
&AuraEffect {
|
||||||
|
mode: AuraModeNum::Static,
|
||||||
|
zone: AuraZone::None,
|
||||||
|
colour1: Colour { r: 166, g: 0, b: 0 },
|
||||||
|
colour2: Colour { r: 0, g: 0, b: 0 },
|
||||||
|
speed: Speed::Med,
|
||||||
|
direction: Direction::Right
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(config.enabled.states.len(), 4);
|
||||||
|
assert_eq!(
|
||||||
|
config.enabled.states[0],
|
||||||
|
AuraPowerState {
|
||||||
|
zone: PowerZones::Keyboard,
|
||||||
|
boot: true,
|
||||||
|
awake: true,
|
||||||
|
sleep: true,
|
||||||
|
shutdown: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
229
asusd/src/aura_laptop/mod.rs
Normal file
229
asusd/src/aura_laptop/mod.rs
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use config::AuraConfig;
|
||||||
|
use config_traits::StdConfig;
|
||||||
|
use log::info;
|
||||||
|
use rog_aura::keyboard::{AuraLaptopUsbPackets, LedUsbPackets};
|
||||||
|
use rog_aura::usb::{AURA_LAPTOP_LED_APPLY, AURA_LAPTOP_LED_SET};
|
||||||
|
use rog_aura::{AuraDeviceType, AuraEffect, LedBrightness, PowerZones, AURA_LAPTOP_LED_MSG_LEN};
|
||||||
|
use rog_platform::hid_raw::HidRaw;
|
||||||
|
use rog_platform::keyboard_led::KeyboardBacklight;
|
||||||
|
use tokio::sync::{Mutex, MutexGuard};
|
||||||
|
|
||||||
|
use crate::error::RogError;
|
||||||
|
|
||||||
|
pub mod config;
|
||||||
|
pub mod trait_impls;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Aura {
|
||||||
|
pub hid: Option<Arc<Mutex<HidRaw>>>,
|
||||||
|
pub backlight: Option<Arc<Mutex<KeyboardBacklight>>>,
|
||||||
|
pub config: Arc<Mutex<AuraConfig>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Aura {
|
||||||
|
/// Initialise the device if required.
|
||||||
|
pub async fn do_initialization(&self) -> Result<(), RogError> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn lock_config(&self) -> MutexGuard<'_, AuraConfig> {
|
||||||
|
self.config.lock().await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Will lock the internal config and update. If anything else has locked
|
||||||
|
/// this in scope then a deadlock can occur.
|
||||||
|
pub async fn update_config(&self) -> Result<(), RogError> {
|
||||||
|
let mut config = self.config.lock().await;
|
||||||
|
let bright = if let Some(bl) = self.backlight.as_ref() {
|
||||||
|
bl.lock().await.get_brightness().unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
config.brightness.into()
|
||||||
|
};
|
||||||
|
config.read();
|
||||||
|
config.brightness = bright.into();
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn write_current_config_mode(&self, config: &mut AuraConfig) -> Result<(), RogError> {
|
||||||
|
if config.multizone_on {
|
||||||
|
let mode = config.current_mode;
|
||||||
|
let mut create = false;
|
||||||
|
// There is no multizone config for this mode so create one here
|
||||||
|
// using the colours of rainbow if it exists, or first available
|
||||||
|
// mode, or random
|
||||||
|
if config.multizone.is_none() {
|
||||||
|
create = true;
|
||||||
|
} else if let Some(multizones) = config.multizone.as_ref() {
|
||||||
|
if !multizones.contains_key(&mode) {
|
||||||
|
create = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if create {
|
||||||
|
info!("No user-set config for zone founding, attempting a default");
|
||||||
|
config.create_multizone_default()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(multizones) = config.multizone.as_mut() {
|
||||||
|
if let Some(set) = multizones.get(&mode) {
|
||||||
|
for mode in set.clone() {
|
||||||
|
self.write_effect_and_apply(config.led_type, &mode).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let mode = config.current_mode;
|
||||||
|
if let Some(effect) = config.builtins.get(&mode).cloned() {
|
||||||
|
self.write_effect_and_apply(config.led_type, &effect)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write the AuraEffect to the device. Will lock `backlight` or `hid`.
|
||||||
|
///
|
||||||
|
/// If per-key or software-mode is active it must be marked as disabled in
|
||||||
|
/// config.
|
||||||
|
pub async fn write_effect_and_apply(
|
||||||
|
&self,
|
||||||
|
dev_type: AuraDeviceType,
|
||||||
|
mode: &AuraEffect,
|
||||||
|
) -> Result<(), RogError> {
|
||||||
|
if matches!(dev_type, AuraDeviceType::LaptopKeyboardTuf) {
|
||||||
|
if let Some(platform) = &self.backlight {
|
||||||
|
let buf = [
|
||||||
|
1, mode.mode as u8, mode.colour1.r, mode.colour1.g, mode.colour1.b,
|
||||||
|
mode.speed as u8,
|
||||||
|
];
|
||||||
|
platform.lock().await.set_kbd_rgb_mode(&buf)?;
|
||||||
|
}
|
||||||
|
} else if let Some(hid_raw) = &self.hid {
|
||||||
|
let bytes: [u8; AURA_LAPTOP_LED_MSG_LEN] = mode.into();
|
||||||
|
let hid_raw = hid_raw.lock().await;
|
||||||
|
hid_raw.write_bytes(&bytes)?;
|
||||||
|
hid_raw.write_bytes(&AURA_LAPTOP_LED_SET)?;
|
||||||
|
// Changes won't persist unless apply is set
|
||||||
|
hid_raw.write_bytes(&AURA_LAPTOP_LED_APPLY)?;
|
||||||
|
} else {
|
||||||
|
return Err(RogError::NoAuraKeyboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_brightness(&self, value: u8) -> Result<(), RogError> {
|
||||||
|
if let Some(backlight) = &self.backlight {
|
||||||
|
backlight.lock().await.set_brightness(value)?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
Err(RogError::MissingFunction(
|
||||||
|
"No LED backlight control available".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set combination state for boot animation/sleep animation/all leds/keys
|
||||||
|
/// leds/side leds LED active
|
||||||
|
pub async fn set_power_states(&self, config: &AuraConfig) -> Result<(), RogError> {
|
||||||
|
if matches!(config.led_type, rog_aura::AuraDeviceType::LaptopKeyboardTuf) {
|
||||||
|
if let Some(backlight) = &self.backlight {
|
||||||
|
// TODO: tuf bool array
|
||||||
|
let buf = config.enabled.to_bytes(config.led_type);
|
||||||
|
backlight.lock().await.set_kbd_rgb_state(&buf)?;
|
||||||
|
}
|
||||||
|
} else if let Some(hid_raw) = &self.hid {
|
||||||
|
let hid_raw = hid_raw.lock().await;
|
||||||
|
if let Some(p) = config.enabled.states.first() {
|
||||||
|
if p.zone == PowerZones::Ally {
|
||||||
|
let msg = [
|
||||||
|
0x5d,
|
||||||
|
0xd1,
|
||||||
|
0x09,
|
||||||
|
0x01,
|
||||||
|
p.new_to_byte() as u8,
|
||||||
|
0x0,
|
||||||
|
0x0,
|
||||||
|
];
|
||||||
|
hid_raw.write_bytes(&msg)?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let bytes = config.enabled.to_bytes(config.led_type);
|
||||||
|
let msg = [
|
||||||
|
0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2], bytes[3],
|
||||||
|
];
|
||||||
|
hid_raw.write_bytes(&msg)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write an effect block. This is for per-key, but can be repurposed to
|
||||||
|
/// write the raw factory mode packets - when doing this it is expected that
|
||||||
|
/// only the first `Vec` (`effect[0]`) is valid.
|
||||||
|
pub async fn write_effect_block(
|
||||||
|
&self,
|
||||||
|
config: &mut AuraConfig,
|
||||||
|
effect: &AuraLaptopUsbPackets,
|
||||||
|
) -> Result<(), RogError> {
|
||||||
|
if config.brightness == LedBrightness::Off {
|
||||||
|
config.brightness = LedBrightness::Med;
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
|
||||||
|
let pkt_type = effect[0][1];
|
||||||
|
const PER_KEY_TYPE: u8 = 0xbc;
|
||||||
|
|
||||||
|
if let Some(hid_raw) = &self.hid {
|
||||||
|
let hid_raw = hid_raw.lock().await;
|
||||||
|
if pkt_type != PER_KEY_TYPE {
|
||||||
|
config.per_key_mode_active = false;
|
||||||
|
hid_raw.write_bytes(&effect[0])?;
|
||||||
|
hid_raw.write_bytes(&AURA_LAPTOP_LED_SET)?;
|
||||||
|
// hid_raw.write_bytes(&LED_APPLY)?;
|
||||||
|
} else {
|
||||||
|
if !config.per_key_mode_active {
|
||||||
|
let init = LedUsbPackets::get_init_msg();
|
||||||
|
hid_raw.write_bytes(&init)?;
|
||||||
|
config.per_key_mode_active = true;
|
||||||
|
}
|
||||||
|
for row in effect.iter() {
|
||||||
|
hid_raw.write_bytes(row)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if matches!(config.led_type, rog_aura::AuraDeviceType::LaptopKeyboardTuf) {
|
||||||
|
if let Some(tuf) = &self.backlight {
|
||||||
|
for row in effect.iter() {
|
||||||
|
let r = row[9];
|
||||||
|
let g = row[10];
|
||||||
|
let b = row[11];
|
||||||
|
tuf.lock().await.set_kbd_rgb_mode(&[
|
||||||
|
0, 0, r, g, b, 0,
|
||||||
|
])?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn fix_ally_power(&mut self) -> Result<(), RogError> {
|
||||||
|
if self.config.lock().await.led_type == AuraDeviceType::Ally {
|
||||||
|
if let Some(hid_raw) = &self.hid {
|
||||||
|
let mut config = self.config.lock().await;
|
||||||
|
if config.ally_fix.is_none() {
|
||||||
|
let msg = [
|
||||||
|
0x5d, 0xbd, 0x01, 0xff, 0xff, 0xff, 0xff,
|
||||||
|
];
|
||||||
|
hid_raw.lock().await.write_bytes(&msg)?;
|
||||||
|
info!("Reset Ally power settings to base");
|
||||||
|
config.ally_fix = Some(true);
|
||||||
|
}
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
349
asusd/src/aura_laptop/trait_impls.rs
Normal file
349
asusd/src/aura_laptop/trait_impls.rs
Normal file
@@ -0,0 +1,349 @@
|
|||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use config_traits::StdConfig;
|
||||||
|
use log::{debug, error, info, warn};
|
||||||
|
use rog_aura::keyboard::{AuraLaptopUsbPackets, LaptopAuraPower};
|
||||||
|
use rog_aura::{AuraDeviceType, AuraEffect, AuraModeNum, AuraZone, LedBrightness, PowerZones};
|
||||||
|
use zbus::fdo::Error as ZbErr;
|
||||||
|
use zbus::object_server::SignalEmitter;
|
||||||
|
use zbus::zvariant::OwnedObjectPath;
|
||||||
|
use zbus::{interface, Connection};
|
||||||
|
|
||||||
|
use super::Aura;
|
||||||
|
use crate::error::RogError;
|
||||||
|
use crate::{CtrlTask, Reloadable};
|
||||||
|
|
||||||
|
pub const AURA_ZBUS_NAME: &str = "Aura";
|
||||||
|
pub const AURA_ZBUS_PATH: &str = "/xyz/ljones";
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct AuraZbus(Aura);
|
||||||
|
|
||||||
|
impl AuraZbus {
|
||||||
|
pub fn new(aura: Aura) -> Self {
|
||||||
|
Self(aura)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start_tasks(
|
||||||
|
mut self,
|
||||||
|
connection: &Connection,
|
||||||
|
// _signal_ctx: SignalEmitter<'static>,
|
||||||
|
path: OwnedObjectPath,
|
||||||
|
) -> Result<(), RogError> {
|
||||||
|
// let task = zbus.clone();
|
||||||
|
// let signal_ctx = signal_ctx.clone();
|
||||||
|
self.reload()
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|err| warn!("Controller error: {}", err));
|
||||||
|
connection
|
||||||
|
.object_server()
|
||||||
|
.at(path.clone(), self)
|
||||||
|
.await
|
||||||
|
.map_err(|e| error!("Couldn't add server at path: {path}, {e:?}"))
|
||||||
|
.ok();
|
||||||
|
// TODO: skip this until we keep handles to tasks so they can be killed
|
||||||
|
// task.create_tasks(signal_ctx).await
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The main interface for changing, reading, or notfying
|
||||||
|
///
|
||||||
|
/// LED commands are split between Brightness, Modes, Per-Key
|
||||||
|
#[interface(name = "xyz.ljones.Aura")]
|
||||||
|
impl AuraZbus {
|
||||||
|
/// Return the device type for this Aura keyboard
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn device_type(&self) -> AuraDeviceType {
|
||||||
|
self.0.config.lock().await.led_type
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the current LED brightness
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn brightness(&self) -> Result<LedBrightness, ZbErr> {
|
||||||
|
if let Some(bl) = self.0.backlight.as_ref() {
|
||||||
|
return Ok(bl.lock().await.get_brightness().map(|n| n.into())?);
|
||||||
|
}
|
||||||
|
Err(ZbErr::Failed("No sysfs brightness control".to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the keyboard brightness level (0-3)
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_brightness(&mut self, brightness: LedBrightness) -> Result<(), ZbErr> {
|
||||||
|
if let Some(bl) = self.0.backlight.as_ref() {
|
||||||
|
let res = bl.lock().await.set_brightness(brightness.into());
|
||||||
|
if res.is_ok() {
|
||||||
|
let mut config = self.0.config.lock().await;
|
||||||
|
config.brightness = brightness;
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
return Ok(res?);
|
||||||
|
}
|
||||||
|
Err(ZbErr::Failed("No sysfs brightness control".to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Total levels of brightness available
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn supported_brightness(&self) -> Vec<LedBrightness> {
|
||||||
|
vec![
|
||||||
|
LedBrightness::Off,
|
||||||
|
LedBrightness::Low,
|
||||||
|
LedBrightness::Med,
|
||||||
|
LedBrightness::High,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The total available modes
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn supported_basic_modes(&self) -> Result<Vec<AuraModeNum>, ZbErr> {
|
||||||
|
let config = self.0.config.lock().await;
|
||||||
|
Ok(config.builtins.keys().cloned().collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn supported_basic_zones(&self) -> Result<Vec<AuraZone>, ZbErr> {
|
||||||
|
let config = self.0.config.lock().await;
|
||||||
|
Ok(config.support_data.basic_zones.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn supported_power_zones(&self) -> Result<Vec<PowerZones>, ZbErr> {
|
||||||
|
let config = self.0.config.lock().await;
|
||||||
|
Ok(config.support_data.power_zones.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The current mode data
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn led_mode(&self) -> Result<AuraModeNum, ZbErr> {
|
||||||
|
// entirely possible to deadlock here, so use try instead of lock()
|
||||||
|
// let ctrl = self.0.lock().await;
|
||||||
|
// Ok(config.current_mode)
|
||||||
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
|
Ok(config.current_mode)
|
||||||
|
} else {
|
||||||
|
Err(ZbErr::Failed("Aura control couldn't lock self".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set an Aura effect if the effect mode or zone is supported.
|
||||||
|
///
|
||||||
|
/// On success the aura config file is read to refresh cached values, then
|
||||||
|
/// the effect is stored and config written to disk.
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_led_mode(&mut self, num: AuraModeNum) -> Result<(), ZbErr> {
|
||||||
|
let mut config = self.0.config.lock().await;
|
||||||
|
config.current_mode = num;
|
||||||
|
self.0.write_current_config_mode(&mut config).await?;
|
||||||
|
if config.brightness == LedBrightness::Off {
|
||||||
|
config.brightness = LedBrightness::Med;
|
||||||
|
}
|
||||||
|
self.0.set_brightness(config.brightness.into()).await?;
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The current mode data
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn led_mode_data(&self) -> Result<AuraEffect, ZbErr> {
|
||||||
|
// entirely possible to deadlock here, so use try instead of lock()
|
||||||
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
|
let mode = config.current_mode;
|
||||||
|
match config.builtins.get(&mode) {
|
||||||
|
Some(effect) => Ok(effect.clone()),
|
||||||
|
None => Err(ZbErr::Failed("Could not get the current effect".into())),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(ZbErr::Failed("Aura control couldn't lock self".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set an Aura effect if the effect mode or zone is supported.
|
||||||
|
///
|
||||||
|
/// On success the aura config file is read to refresh cached values, then
|
||||||
|
/// the effect is stored and config written to disk.
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_led_mode_data(&mut self, effect: AuraEffect) -> Result<(), ZbErr> {
|
||||||
|
let mut config = self.0.config.lock().await;
|
||||||
|
if !config.support_data.basic_modes.contains(&effect.mode)
|
||||||
|
|| effect.zone != AuraZone::None
|
||||||
|
&& !config.support_data.basic_zones.contains(&effect.zone)
|
||||||
|
{
|
||||||
|
return Err(ZbErr::NotSupported(format!(
|
||||||
|
"The Aura effect is not supported: {effect:?}"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.0
|
||||||
|
.write_effect_and_apply(config.led_type, &effect)
|
||||||
|
.await?;
|
||||||
|
if config.brightness == LedBrightness::Off {
|
||||||
|
config.brightness = LedBrightness::Med;
|
||||||
|
}
|
||||||
|
self.0.set_brightness(config.brightness.into()).await?;
|
||||||
|
config.set_builtin(effect);
|
||||||
|
config.write();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the data set for every mode available
|
||||||
|
async fn all_mode_data(&self) -> BTreeMap<AuraModeNum, AuraEffect> {
|
||||||
|
let config = self.0.config.lock().await;
|
||||||
|
config.builtins.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
// As property doesn't work for AuraPowerDev (complexity of serialization?)
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn led_power(&self) -> LaptopAuraPower {
|
||||||
|
let config = self.0.config.lock().await;
|
||||||
|
config.enabled.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set a variety of states, input is array of enum.
|
||||||
|
/// `enabled` sets if the sent array should be disabled or enabled
|
||||||
|
///
|
||||||
|
/// For Modern ROG devices the "enabled" flag is ignored.
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_led_power(&mut self, options: LaptopAuraPower) -> Result<(), ZbErr> {
|
||||||
|
let mut config = self.0.config.lock().await;
|
||||||
|
for opt in options.states {
|
||||||
|
let zone = opt.zone;
|
||||||
|
for config in config.enabled.states.iter_mut() {
|
||||||
|
if config.zone == zone {
|
||||||
|
*config = opt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.write();
|
||||||
|
Ok(self.0.set_power_states(&config).await.map_err(|e| {
|
||||||
|
warn!("{}", e);
|
||||||
|
e
|
||||||
|
})?)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// On machine that have some form of either per-key keyboard or per-zone
|
||||||
|
/// this can be used to write custom effects over dbus. The input is a
|
||||||
|
/// nested `Vec<Vec<8>>` where `Vec<u8>` is a raw USB packet
|
||||||
|
async fn direct_addressing_raw(&self, data: AuraLaptopUsbPackets) -> Result<(), ZbErr> {
|
||||||
|
let mut config = self.0.config.lock().await;
|
||||||
|
self.0.write_effect_block(&mut config, &data).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CtrlTask for AuraZbus {
|
||||||
|
fn zbus_path() -> &'static str {
|
||||||
|
"/xyz/ljones"
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn create_tasks(&self, _: SignalEmitter<'static>) -> Result<(), RogError> {
|
||||||
|
let inner1 = self.0.clone();
|
||||||
|
let inner3 = self.0.clone();
|
||||||
|
self.create_sys_event_tasks(
|
||||||
|
move |sleeping| {
|
||||||
|
let inner1 = inner1.clone();
|
||||||
|
// unwrap as we want to bomb out of the task
|
||||||
|
async move {
|
||||||
|
if !sleeping {
|
||||||
|
info!("CtrlKbdLedTask reloading brightness and modes");
|
||||||
|
if let Some(backlight) = &inner1.backlight {
|
||||||
|
backlight
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.set_brightness(inner1.config.lock().await.brightness.into())
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("CtrlKbdLedTask: {e}");
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
let mut config = inner1.config.lock().await;
|
||||||
|
inner1
|
||||||
|
.write_current_config_mode(&mut config)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("CtrlKbdLedTask: {e}");
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
} else if sleeping {
|
||||||
|
inner1
|
||||||
|
.update_config()
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("CtrlKbdLedTask: {e}");
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
move |_shutting_down| {
|
||||||
|
let inner3 = inner3.clone();
|
||||||
|
async move {
|
||||||
|
info!("CtrlKbdLedTask reloading brightness and modes");
|
||||||
|
if let Some(backlight) = &inner3.backlight {
|
||||||
|
// unwrap as we want to bomb out of the task
|
||||||
|
backlight
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.set_brightness(inner3.config.lock().await.brightness.into())
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("CtrlKbdLedTask: {e}");
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
move |_lid_closed| {
|
||||||
|
// on lid change
|
||||||
|
async move {}
|
||||||
|
},
|
||||||
|
move |_power_plugged| {
|
||||||
|
// power change
|
||||||
|
async move {}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
// let ctrl2 = self.0.clone();
|
||||||
|
// let ctrl = self.0.lock().await;
|
||||||
|
// if ctrl.led_node.has_brightness_control() {
|
||||||
|
// let watch = ctrl.led_node.monitor_brightness()?;
|
||||||
|
// tokio::spawn(async move {
|
||||||
|
// let mut buffer = [0; 32];
|
||||||
|
// watch
|
||||||
|
// .into_event_stream(&mut buffer)
|
||||||
|
// .unwrap()
|
||||||
|
// .for_each(|_| async {
|
||||||
|
// if let Some(lock) = ctrl2.try_lock() {
|
||||||
|
// load_save(true, lock).unwrap(); // unwrap as we want
|
||||||
|
// // to
|
||||||
|
// // bomb out of the
|
||||||
|
// // task
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .await;
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reloadable for AuraZbus {
|
||||||
|
async fn reload(&mut self) -> Result<(), RogError> {
|
||||||
|
self.0.fix_ally_power().await?;
|
||||||
|
debug!("reloading keyboard mode");
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
self.0.write_current_config_mode(&mut config).await?;
|
||||||
|
debug!("reloading power states");
|
||||||
|
self.0
|
||||||
|
.set_power_states(&config)
|
||||||
|
.await
|
||||||
|
.map_err(|err| warn!("{err}"))
|
||||||
|
.ok();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
592
asusd/src/aura_manager.rs
Normal file
592
asusd/src/aura_manager.rs
Normal file
@@ -0,0 +1,592 @@
|
|||||||
|
// Plan:
|
||||||
|
// - Manager has udev monitor on USB looking for ROG devices
|
||||||
|
// - If a device is found, add it to watch
|
||||||
|
// - Add it to Zbus server
|
||||||
|
// - If udev sees device removed then remove the zbus path
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use dmi_id::DMIID;
|
||||||
|
use futures_lite::future::block_on;
|
||||||
|
use log::{debug, error, info, warn};
|
||||||
|
use mio::{Events, Interest, Poll, Token};
|
||||||
|
use rog_platform::error::PlatformError;
|
||||||
|
use rog_platform::hid_raw::HidRaw;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
use udev::{Device, MonitorBuilder};
|
||||||
|
use zbus::zvariant::{ObjectPath, OwnedObjectPath};
|
||||||
|
use zbus::Connection;
|
||||||
|
|
||||||
|
use crate::aura_anime::trait_impls::AniMeZbus;
|
||||||
|
use crate::aura_laptop::trait_impls::AuraZbus;
|
||||||
|
use crate::aura_scsi::trait_impls::ScsiZbus;
|
||||||
|
use crate::aura_slash::trait_impls::SlashZbus;
|
||||||
|
use crate::aura_types::DeviceHandle;
|
||||||
|
use crate::error::RogError;
|
||||||
|
use crate::ASUS_ZBUS_PATH;
|
||||||
|
|
||||||
|
const MOD_NAME: &str = "aura";
|
||||||
|
|
||||||
|
/// Returns only the Device details concatenated in a form usable for
|
||||||
|
/// adding/appending to a filename
|
||||||
|
pub fn filename_partial(parent: &Device) -> Option<OwnedObjectPath> {
|
||||||
|
if let Some(id_product) = parent.attribute_value("idProduct") {
|
||||||
|
let id_product = id_product.to_string_lossy();
|
||||||
|
let mut path = if let Some(devnum) = parent.attribute_value("devnum") {
|
||||||
|
let devnum = devnum.to_string_lossy();
|
||||||
|
if let Some(devpath) = parent.attribute_value("devpath") {
|
||||||
|
let devpath = devpath.to_string_lossy();
|
||||||
|
format!("{id_product}_{devnum}_{devpath}")
|
||||||
|
} else {
|
||||||
|
format!("{id_product}_{devnum}")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
format!("{id_product}")
|
||||||
|
};
|
||||||
|
if path.contains('.') {
|
||||||
|
warn!("dbus path for {id_product} contains `.`, removing");
|
||||||
|
path.replace('.', "").clone_into(&mut path);
|
||||||
|
}
|
||||||
|
return Some(ObjectPath::from_str_unchecked(&path).into());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dbus_path_for_dev(parent: &Device) -> Option<OwnedObjectPath> {
|
||||||
|
if let Some(filename) = filename_partial(parent) {
|
||||||
|
return Some(
|
||||||
|
ObjectPath::from_str_unchecked(&format!("{ASUS_ZBUS_PATH}/{MOD_NAME}/{filename}"))
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dbus_path_for_tuf() -> OwnedObjectPath {
|
||||||
|
ObjectPath::from_str_unchecked(&format!("{ASUS_ZBUS_PATH}/{MOD_NAME}/tuf")).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dbus_path_for_slash() -> OwnedObjectPath {
|
||||||
|
ObjectPath::from_str_unchecked(&format!("{ASUS_ZBUS_PATH}/{MOD_NAME}/slash")).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dbus_path_for_anime() -> OwnedObjectPath {
|
||||||
|
ObjectPath::from_str_unchecked(&format!("{ASUS_ZBUS_PATH}/{MOD_NAME}/anime")).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dbus_path_for_scsi(prod_id: &str) -> OwnedObjectPath {
|
||||||
|
ObjectPath::from_str_unchecked(&format!("{ASUS_ZBUS_PATH}/{MOD_NAME}/{prod_id}_scsi")).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dev_prop_matches(dev: &Device, prop: &str, value: &str) -> bool {
|
||||||
|
if let Some(p) = dev.property_value(prop) {
|
||||||
|
return p == value;
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A device.
|
||||||
|
///
|
||||||
|
/// Each controller within should track its dbus path so it can be removed if
|
||||||
|
/// required.
|
||||||
|
pub struct AsusDevice {
|
||||||
|
device: DeviceHandle,
|
||||||
|
dbus_path: OwnedObjectPath,
|
||||||
|
hid_key: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DeviceManager {
|
||||||
|
_dbus_connection: Connection,
|
||||||
|
_hid_handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DeviceManager {
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
|
async fn get_or_create_hid_handle(
|
||||||
|
handles: &Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
||||||
|
endpoint: &Device,
|
||||||
|
) -> Result<(Arc<Mutex<HidRaw>>, String), RogError> {
|
||||||
|
let dev_node = endpoint
|
||||||
|
.devnode()
|
||||||
|
.ok_or_else(|| RogError::MissingFunction("hidraw devnode missing".to_string()))?;
|
||||||
|
let key = dev_node.to_string_lossy().to_string();
|
||||||
|
|
||||||
|
if let Some(existing) = handles.lock().await.get(&key).cloned() {
|
||||||
|
return Ok((existing, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
let hidraw = HidRaw::from_device(endpoint.clone())?;
|
||||||
|
let handle = Arc::new(Mutex::new(hidraw));
|
||||||
|
handles.lock().await.insert(key.clone(), handle.clone());
|
||||||
|
Ok((handle, key))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn init_hid_devices(
|
||||||
|
connection: &Connection,
|
||||||
|
device: Device,
|
||||||
|
handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
||||||
|
) -> Result<Vec<AsusDevice>, RogError> {
|
||||||
|
let mut devices = Vec::new();
|
||||||
|
if let Some(usb_device) = device.parent_with_subsystem_devtype("usb", "usb_device")? {
|
||||||
|
if let Some(usb_id) = usb_device.attribute_value("idProduct") {
|
||||||
|
if let Some(vendor_id) = usb_device.attribute_value("idVendor") {
|
||||||
|
if vendor_id != "0b05" {
|
||||||
|
debug!("Not ASUS vendor ID: {}", vendor_id.to_string_lossy());
|
||||||
|
return Ok(devices);
|
||||||
|
}
|
||||||
|
// Almost all devices are identified by the productId.
|
||||||
|
// So let's see what we have and:
|
||||||
|
// 1. Generate an interface path
|
||||||
|
// 2. Create the device
|
||||||
|
// Use the top-level endpoint, not the parent
|
||||||
|
if let Ok((dev, hid_key)) =
|
||||||
|
Self::get_or_create_hid_handle(&handles, &device).await
|
||||||
|
{
|
||||||
|
debug!("Testing device {usb_id:?}");
|
||||||
|
// SLASH DEVICE
|
||||||
|
if let Ok(dev_type) = DeviceHandle::new_slash_hid(
|
||||||
|
dev.clone(),
|
||||||
|
usb_id.to_str().unwrap_or_default(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
if let DeviceHandle::Slash(slash) = dev_type.clone() {
|
||||||
|
let path =
|
||||||
|
dbus_path_for_dev(&usb_device).unwrap_or(dbus_path_for_slash());
|
||||||
|
let ctrl = SlashZbus::new(slash);
|
||||||
|
ctrl.start_tasks(connection, path.clone()).await.unwrap();
|
||||||
|
devices.push(AsusDevice {
|
||||||
|
device: dev_type,
|
||||||
|
dbus_path: path,
|
||||||
|
hid_key: Some(hid_key.clone()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ANIME MATRIX DEVICE
|
||||||
|
if let Ok(dev_type) = DeviceHandle::maybe_anime_hid(
|
||||||
|
dev.clone(),
|
||||||
|
usb_id.to_str().unwrap_or_default(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
if let DeviceHandle::AniMe(anime) = dev_type.clone() {
|
||||||
|
let path =
|
||||||
|
dbus_path_for_dev(&usb_device).unwrap_or(dbus_path_for_anime());
|
||||||
|
let ctrl = AniMeZbus::new(anime);
|
||||||
|
ctrl.start_tasks(connection, path.clone()).await.unwrap();
|
||||||
|
devices.push(AsusDevice {
|
||||||
|
device: dev_type,
|
||||||
|
dbus_path: path,
|
||||||
|
hid_key: Some(hid_key.clone()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// AURA LAPTOP DEVICE
|
||||||
|
if let Ok(dev_type) = DeviceHandle::maybe_laptop_aura(
|
||||||
|
Some(dev),
|
||||||
|
usb_id.to_str().unwrap_or_default(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
if let DeviceHandle::Aura(aura) = dev_type.clone() {
|
||||||
|
let path =
|
||||||
|
dbus_path_for_dev(&usb_device).unwrap_or(dbus_path_for_tuf());
|
||||||
|
let ctrl = AuraZbus::new(aura);
|
||||||
|
ctrl.start_tasks(connection, path.clone()).await.unwrap();
|
||||||
|
devices.push(AsusDevice {
|
||||||
|
device: dev_type,
|
||||||
|
dbus_path: path,
|
||||||
|
hid_key: Some(hid_key),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn!("Failed to initialise shared hid handle for {usb_id:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(devices)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// To be called on daemon startup
|
||||||
|
async fn init_all_hid(
|
||||||
|
connection: &Connection,
|
||||||
|
handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
||||||
|
) -> Result<Vec<AsusDevice>, RogError> {
|
||||||
|
// track and ensure we use only one hidraw per prod_id
|
||||||
|
// let mut interfaces = HashSet::new();
|
||||||
|
let mut devices: Vec<AsusDevice> = Vec::new();
|
||||||
|
|
||||||
|
let mut enumerator = udev::Enumerator::new().map_err(|err| {
|
||||||
|
warn!("{}", err);
|
||||||
|
PlatformError::Udev("enumerator failed".into(), err)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
enumerator.match_subsystem("hidraw").map_err(|err| {
|
||||||
|
warn!("{}", err);
|
||||||
|
PlatformError::Udev("match_subsystem failed".into(), err)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
for device in enumerator
|
||||||
|
.scan_devices()
|
||||||
|
.map_err(|e| PlatformError::IoPath("enumerator".to_owned(), e))?
|
||||||
|
{
|
||||||
|
devices.append(&mut Self::init_hid_devices(connection, device, handles.clone()).await?);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(devices)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn init_scsi(
|
||||||
|
connection: &Connection,
|
||||||
|
device: &Device,
|
||||||
|
path: OwnedObjectPath,
|
||||||
|
) -> Option<AsusDevice> {
|
||||||
|
// "ID_MODEL_ID" "1932"
|
||||||
|
// "ID_VENDOR_ID" "0b05"
|
||||||
|
if dev_prop_matches(device, "ID_VENDOR_ID", "0b05") {
|
||||||
|
if let Some(dev_node) = device.devnode() {
|
||||||
|
let prod_id = device
|
||||||
|
.property_value("ID_MODEL_ID")
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string_lossy();
|
||||||
|
if let Ok(dev_type) =
|
||||||
|
DeviceHandle::maybe_scsi(dev_node.as_os_str().to_str().unwrap(), &prod_id).await
|
||||||
|
{
|
||||||
|
if let DeviceHandle::Scsi(scsi) = dev_type.clone() {
|
||||||
|
let ctrl = ScsiZbus::new(scsi);
|
||||||
|
ctrl.start_tasks(connection, path.clone()).await.unwrap();
|
||||||
|
return Some(AsusDevice {
|
||||||
|
device: dev_type,
|
||||||
|
dbus_path: path,
|
||||||
|
hid_key: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn init_all_scsi(connection: &Connection) -> Result<Vec<AsusDevice>, RogError> {
|
||||||
|
// track and ensure we use only one hidraw per prod_id
|
||||||
|
// let mut interfaces = HashSet::new();
|
||||||
|
let mut devices: Vec<AsusDevice> = Vec::new();
|
||||||
|
|
||||||
|
let mut enumerator = udev::Enumerator::new().map_err(|err| {
|
||||||
|
warn!("{}", err);
|
||||||
|
PlatformError::Udev("enumerator failed".into(), err)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
enumerator.match_subsystem("block").map_err(|err| {
|
||||||
|
warn!("{}", err);
|
||||||
|
PlatformError::Udev("match_subsystem failed".into(), err)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let mut found = Vec::new();
|
||||||
|
for device in enumerator
|
||||||
|
.scan_devices()
|
||||||
|
.map_err(|e| PlatformError::IoPath("enumerator".to_owned(), e))?
|
||||||
|
{
|
||||||
|
if let Some(serial) = device.property_value("ID_SERIAL_SHORT") {
|
||||||
|
let serial = serial.to_string_lossy().to_string();
|
||||||
|
let path = dbus_path_for_scsi(&serial);
|
||||||
|
if found.contains(&path) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(dev) = Self::init_scsi(connection, &device, path.clone()).await {
|
||||||
|
devices.push(dev);
|
||||||
|
found.push(path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debug!("No serial for SCSI device: {:?}", device.devpath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(devices)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn find_all_devices(
|
||||||
|
connection: &Connection,
|
||||||
|
handles: Arc<Mutex<HashMap<String, Arc<Mutex<HidRaw>>>>>,
|
||||||
|
) -> Vec<AsusDevice> {
|
||||||
|
let mut devices: Vec<AsusDevice> = Vec::new();
|
||||||
|
// HID first, always
|
||||||
|
if let Ok(devs) = &mut Self::init_all_hid(connection, handles.clone()).await {
|
||||||
|
devices.append(devs);
|
||||||
|
}
|
||||||
|
// USB after, need to check if HID picked something up and if so, skip it
|
||||||
|
let mut do_anime = true;
|
||||||
|
let mut do_slash = true;
|
||||||
|
let mut do_kb_backlight = true;
|
||||||
|
for dev in devices.iter() {
|
||||||
|
if matches!(dev.device, DeviceHandle::Slash(_)) {
|
||||||
|
do_slash = false;
|
||||||
|
}
|
||||||
|
if matches!(dev.device, DeviceHandle::AniMe(_)) {
|
||||||
|
do_anime = false;
|
||||||
|
}
|
||||||
|
if matches!(dev.device, DeviceHandle::Aura(_) | DeviceHandle::OldAura(_)) {
|
||||||
|
do_kb_backlight = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if do_slash {
|
||||||
|
if let Ok(dev_type) = DeviceHandle::new_slash_usb().await {
|
||||||
|
if let DeviceHandle::Slash(slash) = dev_type.clone() {
|
||||||
|
let path = dbus_path_for_slash();
|
||||||
|
let ctrl = SlashZbus::new(slash);
|
||||||
|
ctrl.start_tasks(connection, path.clone()).await.unwrap();
|
||||||
|
devices.push(AsusDevice {
|
||||||
|
device: dev_type,
|
||||||
|
dbus_path: path,
|
||||||
|
hid_key: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
info!("Tested device was not Slash");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if do_anime {
|
||||||
|
if let Ok(dev_type) = DeviceHandle::maybe_anime_usb().await {
|
||||||
|
// TODO: this is copy/pasted
|
||||||
|
if let DeviceHandle::AniMe(anime) = dev_type.clone() {
|
||||||
|
let path = dbus_path_for_anime();
|
||||||
|
let ctrl = AniMeZbus::new(anime);
|
||||||
|
if ctrl
|
||||||
|
.start_tasks(connection, path.clone())
|
||||||
|
.await
|
||||||
|
.map_err(|e| error!("Failed to start tasks: {e:?}, not adding this device"))
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
devices.push(AsusDevice {
|
||||||
|
device: dev_type,
|
||||||
|
dbus_path: path,
|
||||||
|
hid_key: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
info!("Tested device was not AniMe Matrix");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if do_kb_backlight {
|
||||||
|
// TUF AURA LAPTOP DEVICE
|
||||||
|
// product_name = ASUS TUF Gaming F15 FX507ZE_FX507ZE
|
||||||
|
// product_family = ASUS TUF Gaming F15
|
||||||
|
let product_name = DMIID::new().unwrap_or_default().product_name;
|
||||||
|
let product_family = DMIID::new().unwrap_or_default().product_family;
|
||||||
|
info!(
|
||||||
|
"No USB keyboard aura, system is {product_name}, try using sysfs backlight control"
|
||||||
|
);
|
||||||
|
if product_name.contains("TUF") || product_family.contains("TUF") {
|
||||||
|
info!("TUF laptop, try using sysfs backlight control");
|
||||||
|
if let Ok(dev_type) = DeviceHandle::maybe_laptop_aura(None, "tuf").await {
|
||||||
|
if let DeviceHandle::Aura(aura) = dev_type.clone() {
|
||||||
|
let path = dbus_path_for_tuf();
|
||||||
|
let ctrl = AuraZbus::new(aura);
|
||||||
|
ctrl.start_tasks(connection, path.clone()).await.unwrap();
|
||||||
|
devices.push(AsusDevice {
|
||||||
|
device: dev_type,
|
||||||
|
dbus_path: path,
|
||||||
|
hid_key: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(devs) = &mut Self::init_all_scsi(connection).await {
|
||||||
|
devices.append(devs);
|
||||||
|
}
|
||||||
|
|
||||||
|
devices
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn new(connection: Connection) -> Result<Self, RogError> {
|
||||||
|
let conn_copy = connection.clone();
|
||||||
|
let hid_handles = Arc::new(Mutex::new(HashMap::new()));
|
||||||
|
let devices = Self::find_all_devices(&conn_copy, hid_handles.clone()).await;
|
||||||
|
info!("Found {} valid devices on startup", devices.len());
|
||||||
|
let devices = Arc::new(Mutex::new(devices));
|
||||||
|
let manager = Self {
|
||||||
|
_dbus_connection: connection,
|
||||||
|
_hid_handles: hid_handles.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: The /sysfs/ LEDs don't cause events, so they need to be manually
|
||||||
|
// checked for and added
|
||||||
|
|
||||||
|
let hid_handles_thread = hid_handles.clone();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
let mut monitor = MonitorBuilder::new()?.listen()?;
|
||||||
|
let mut poll = Poll::new()?;
|
||||||
|
let mut events = Events::with_capacity(1024);
|
||||||
|
poll.registry()
|
||||||
|
.register(&mut monitor, Token(0), Interest::READABLE)?;
|
||||||
|
|
||||||
|
let rt = tokio::runtime::Runtime::new().expect("Unable to create Runtime");
|
||||||
|
let _enter = rt.enter();
|
||||||
|
loop {
|
||||||
|
if poll.poll(&mut events, None).is_err() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for event in monitor.iter() {
|
||||||
|
let action = event
|
||||||
|
.action()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
let subsys = if let Some(subsys) = event.subsystem() {
|
||||||
|
subsys.to_string_lossy().to_string()
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
let devices = devices.clone();
|
||||||
|
let conn_copy = conn_copy.clone();
|
||||||
|
let hid_handles = hid_handles_thread.clone();
|
||||||
|
block_on(async move {
|
||||||
|
// SCSCI devs
|
||||||
|
if subsys == "block" {
|
||||||
|
if action == "remove" {
|
||||||
|
if let Some(serial) =
|
||||||
|
event.device().property_value("ID_SERIAL_SHORT")
|
||||||
|
{
|
||||||
|
let serial = serial.to_string_lossy().to_string();
|
||||||
|
let path = dbus_path_for_scsi(&serial);
|
||||||
|
|
||||||
|
let index = if let Some(index) = devices
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.iter()
|
||||||
|
.position(|dev| dev.dbus_path == path)
|
||||||
|
{
|
||||||
|
index
|
||||||
|
} else {
|
||||||
|
if dev_prop_matches(&event.device(), "ID_VENDOR_ID", "0b05")
|
||||||
|
{
|
||||||
|
warn!("No device for dbus path: {path:?}");
|
||||||
|
}
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
info!("removing: {path:?}");
|
||||||
|
let dev = devices.lock().await.remove(index);
|
||||||
|
let path = path.clone();
|
||||||
|
if let DeviceHandle::Scsi(_) = dev.device {
|
||||||
|
conn_copy
|
||||||
|
.object_server()
|
||||||
|
.remove::<ScsiZbus, _>(&path)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if action == "add" {
|
||||||
|
let evdev = event.device();
|
||||||
|
if let Some(serial) = evdev.property_value("ID_SERIAL_SHORT") {
|
||||||
|
let serial = serial.to_string_lossy().to_string();
|
||||||
|
let path = dbus_path_for_scsi(&serial);
|
||||||
|
if let Some(new_devs) =
|
||||||
|
Self::init_scsi(&conn_copy, &evdev, path).await
|
||||||
|
{
|
||||||
|
devices.lock().await.append(&mut vec![new_devs]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if subsys == "hidraw" {
|
||||||
|
if let Some(parent) =
|
||||||
|
event.parent_with_subsystem_devtype("usb", "usb_device")?
|
||||||
|
{
|
||||||
|
if action == "remove" {
|
||||||
|
if let Some(path) = dbus_path_for_dev(&parent) {
|
||||||
|
// Find the indexs of devices matching the path
|
||||||
|
let removals: Vec<usize> = devices
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(i, dev)| {
|
||||||
|
if dev.dbus_path == path {
|
||||||
|
Some(i)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
if removals.is_empty() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
info!("removing: {path:?}");
|
||||||
|
// Iter in reverse so as to not screw up indexing
|
||||||
|
for index in removals.iter().rev() {
|
||||||
|
let dev = devices.lock().await.remove(*index);
|
||||||
|
let hid_key = dev.hid_key.clone();
|
||||||
|
let path = path.clone();
|
||||||
|
let res = match dev.device {
|
||||||
|
DeviceHandle::Aura(_) => {
|
||||||
|
conn_copy
|
||||||
|
.object_server()
|
||||||
|
.remove::<AuraZbus, _>(&path)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
DeviceHandle::Slash(_) => {
|
||||||
|
conn_copy
|
||||||
|
.object_server()
|
||||||
|
.remove::<SlashZbus, _>(&path)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
DeviceHandle::AniMe(_) => {
|
||||||
|
conn_copy
|
||||||
|
.object_server()
|
||||||
|
.remove::<AniMeZbus, _>(&path)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
DeviceHandle::Scsi(_) => {
|
||||||
|
conn_copy
|
||||||
|
.object_server()
|
||||||
|
.remove::<ScsiZbus, _>(&path)
|
||||||
|
.await?
|
||||||
|
}
|
||||||
|
_ => todo!(),
|
||||||
|
};
|
||||||
|
info!("AuraManager removed: {path:?}, {res}");
|
||||||
|
if let Some(key) = hid_key {
|
||||||
|
hid_handles.lock().await.remove(&key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if action == "add" {
|
||||||
|
let evdev = event.device();
|
||||||
|
if let Ok(mut new_devs) = Self::init_hid_devices(
|
||||||
|
&conn_copy,
|
||||||
|
evdev,
|
||||||
|
hid_handles.clone(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|e| error!("Couldn't add new device: {e:?}"))
|
||||||
|
{
|
||||||
|
devices.lock().await.append(&mut new_devs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok::<(), RogError>(())
|
||||||
|
})
|
||||||
|
.map_err(|e| error!("{e:?}"))
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Required for return type on spawn
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
Ok::<(), RogError>(())
|
||||||
|
});
|
||||||
|
Ok(manager)
|
||||||
|
}
|
||||||
|
}
|
||||||
114
asusd/src/aura_scsi/config.rs
Normal file
114
asusd/src/aura_scsi/config.rs
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use config_traits::{StdConfig, StdConfigLoad};
|
||||||
|
use rog_aura::AuraDeviceType;
|
||||||
|
use rog_scsi::{AuraEffect, AuraMode};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
const CONFIG_FILE: &str = "scsi.ron";
|
||||||
|
|
||||||
|
/// Config for base system actions for the anime display
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
pub struct ScsiConfig {
|
||||||
|
#[serde(skip)]
|
||||||
|
pub dev_type: AuraDeviceType,
|
||||||
|
pub enabled: bool,
|
||||||
|
pub current_mode: AuraMode,
|
||||||
|
pub modes: BTreeMap<AuraMode, AuraEffect>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScsiConfig {
|
||||||
|
pub fn get_effect(&mut self, mode: AuraMode) -> Option<&AuraEffect> {
|
||||||
|
self.modes.get(&mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save_effect(&mut self, effect: AuraEffect) {
|
||||||
|
self.current_mode = effect.mode;
|
||||||
|
self.modes.insert(*effect.mode(), effect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ScsiConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
ScsiConfig {
|
||||||
|
enabled: true,
|
||||||
|
current_mode: AuraMode::Static,
|
||||||
|
dev_type: AuraDeviceType::ScsiExtDisk,
|
||||||
|
modes: BTreeMap::from([
|
||||||
|
(AuraMode::Off, AuraEffect::default_with_mode(AuraMode::Off)),
|
||||||
|
(
|
||||||
|
AuraMode::Static,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::Static),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::Breathe,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::Breathe),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::Flashing,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::Flashing),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::RainbowCycle,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::RainbowCycle),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::RainbowWave,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::RainbowWave),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::RainbowCycleBreathe,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::RainbowCycleBreathe),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::ChaseFade,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::ChaseFade),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::RainbowCycleChaseFade,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::RainbowCycleChaseFade),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::Chase,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::Chase),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::RainbowCycleChase,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::RainbowCycleChase),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::RainbowCycleWave,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::RainbowCycleWave),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::RainbowPulseChase,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::RainbowPulseChase),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::RandomFlicker,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::RandomFlicker),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AuraMode::DoubleFade,
|
||||||
|
AuraEffect::default_with_mode(AuraMode::DoubleFade),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StdConfig for ScsiConfig {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn file_name(&self) -> String {
|
||||||
|
CONFIG_FILE.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn config_dir() -> std::path::PathBuf {
|
||||||
|
std::path::PathBuf::from(crate::CONFIG_PATH_BASE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StdConfigLoad for ScsiConfig {}
|
||||||
45
asusd/src/aura_scsi/mod.rs
Normal file
45
asusd/src/aura_scsi/mod.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use config::ScsiConfig;
|
||||||
|
use rog_scsi::{AuraEffect, Device, Task};
|
||||||
|
use tokio::sync::{Mutex, MutexGuard};
|
||||||
|
|
||||||
|
use crate::error::RogError;
|
||||||
|
|
||||||
|
pub mod config;
|
||||||
|
pub mod trait_impls;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ScsiAura {
|
||||||
|
device: Arc<Mutex<Device>>,
|
||||||
|
config: Arc<Mutex<ScsiConfig>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScsiAura {
|
||||||
|
pub fn new(device: Arc<Mutex<Device>>, config: Arc<Mutex<ScsiConfig>>) -> Self {
|
||||||
|
Self { device, config }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn lock_config(&self) -> MutexGuard<'_, ScsiConfig> {
|
||||||
|
self.config.lock().await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn write_effect(&self, effect: &AuraEffect) -> Result<(), RogError> {
|
||||||
|
let tasks: Vec<Task> = effect.into();
|
||||||
|
for task in &tasks {
|
||||||
|
self.device.lock().await.perform(task).ok();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialise the device if required. Locks the internal config so be wary
|
||||||
|
/// of deadlocks.
|
||||||
|
pub async fn do_initialization(&self) -> Result<(), RogError> {
|
||||||
|
let config = self.config.lock().await;
|
||||||
|
let mode = config.current_mode;
|
||||||
|
if let Some(effect) = config.modes.get(&mode) {
|
||||||
|
self.write_effect(effect).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
116
asusd/src/aura_scsi/trait_impls.rs
Normal file
116
asusd/src/aura_scsi/trait_impls.rs
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use config_traits::StdConfig;
|
||||||
|
use log::error;
|
||||||
|
use rog_aura::AuraDeviceType;
|
||||||
|
use rog_scsi::{AuraEffect, AuraMode};
|
||||||
|
use zbus::fdo::Error as ZbErr;
|
||||||
|
use zbus::zvariant::OwnedObjectPath;
|
||||||
|
use zbus::{interface, Connection};
|
||||||
|
|
||||||
|
use super::ScsiAura;
|
||||||
|
use crate::error::RogError;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ScsiZbus(ScsiAura);
|
||||||
|
|
||||||
|
impl ScsiZbus {
|
||||||
|
pub fn new(scsi: ScsiAura) -> Self {
|
||||||
|
Self(scsi)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start_tasks(
|
||||||
|
self,
|
||||||
|
connection: &Connection,
|
||||||
|
path: OwnedObjectPath,
|
||||||
|
) -> Result<(), RogError> {
|
||||||
|
connection
|
||||||
|
.object_server()
|
||||||
|
.at(path.clone(), self)
|
||||||
|
.await
|
||||||
|
.map_err(|e| error!("Couldn't add server at path: {path}, {e:?}"))
|
||||||
|
.ok();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[interface(name = "xyz.ljones.ScsiAura")]
|
||||||
|
impl ScsiZbus {
|
||||||
|
/// Return the device type for this Aura keyboard
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn device_type(&self) -> AuraDeviceType {
|
||||||
|
self.0.config.lock().await.dev_type
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get enabled or not
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn enabled(&self) -> bool {
|
||||||
|
let lock = self.0.lock_config().await;
|
||||||
|
lock.enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set enabled true or false
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_enabled(&self, enabled: bool) {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
config.enabled = enabled;
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn led_mode(&self) -> u8 {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
config.current_mode as u8
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_led_mode(&self, mode: AuraMode) -> Result<(), zbus::Error> {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
if let Some(effect) = config.get_effect(mode) {
|
||||||
|
self.0
|
||||||
|
.write_effect(effect)
|
||||||
|
.await
|
||||||
|
.map_err(|e| zbus::Error::Failure(format!("{e:?}")))?;
|
||||||
|
} else {
|
||||||
|
return Err(zbus::Error::Failure("Mode data does not exist".to_string()));
|
||||||
|
}
|
||||||
|
config.current_mode = mode;
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The current mode data
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn led_mode_data(&self) -> Result<AuraEffect, ZbErr> {
|
||||||
|
// entirely possible to deadlock here, so use try instead of lock()
|
||||||
|
if let Ok(config) = self.0.config.try_lock() {
|
||||||
|
let mode = config.current_mode;
|
||||||
|
match config.modes.get(&mode) {
|
||||||
|
Some(effect) => Ok(effect.clone()),
|
||||||
|
None => Err(ZbErr::Failed("Could not get the current effect".into())),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(ZbErr::Failed("Aura control couldn't lock self".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set an Aura effect if the effect mode or zone is supported.
|
||||||
|
///
|
||||||
|
/// On success the aura config file is read to refresh cached values, then
|
||||||
|
/// the effect is stored and config written to disk.
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_led_mode_data(&mut self, effect: AuraEffect) -> Result<(), ZbErr> {
|
||||||
|
self.0.write_effect(&effect).await?;
|
||||||
|
|
||||||
|
let mut config = self.0.config.lock().await;
|
||||||
|
config.save_effect(effect);
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the data set for every mode available
|
||||||
|
async fn all_mode_data(&self) -> BTreeMap<AuraMode, AuraEffect> {
|
||||||
|
let config = self.0.config.lock().await;
|
||||||
|
config.modes.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
66
asusd/src/aura_slash/config.rs
Normal file
66
asusd/src/aura_slash/config.rs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
use config_traits::{StdConfig, StdConfigLoad};
|
||||||
|
use rog_slash::{DeviceState, SlashMode, SlashType};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
const CONFIG_FILE: &str = "slash.ron";
|
||||||
|
|
||||||
|
/// Config for base system actions for the anime display
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
pub struct SlashConfig {
|
||||||
|
#[serde(skip)]
|
||||||
|
pub slash_type: SlashType,
|
||||||
|
pub enabled: bool,
|
||||||
|
pub brightness: u8,
|
||||||
|
pub display_interval: u8,
|
||||||
|
pub display_mode: SlashMode,
|
||||||
|
pub show_on_boot: bool,
|
||||||
|
pub show_on_shutdown: bool,
|
||||||
|
pub show_on_sleep: bool,
|
||||||
|
pub show_on_battery: bool,
|
||||||
|
pub show_battery_warning: bool,
|
||||||
|
pub show_on_lid_closed: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for SlashConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
SlashConfig {
|
||||||
|
enabled: true,
|
||||||
|
brightness: 255,
|
||||||
|
display_interval: 0,
|
||||||
|
display_mode: SlashMode::Bounce,
|
||||||
|
slash_type: SlashType::Unsupported,
|
||||||
|
show_on_boot: true,
|
||||||
|
show_on_shutdown: true,
|
||||||
|
show_on_sleep: true,
|
||||||
|
show_on_battery: true,
|
||||||
|
show_battery_warning: true,
|
||||||
|
show_on_lid_closed: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl StdConfig for SlashConfig {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn file_name(&self) -> String {
|
||||||
|
CONFIG_FILE.to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn config_dir() -> std::path::PathBuf {
|
||||||
|
std::path::PathBuf::from(crate::CONFIG_PATH_BASE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StdConfigLoad for SlashConfig {}
|
||||||
|
|
||||||
|
impl From<&SlashConfig> for DeviceState {
|
||||||
|
fn from(config: &SlashConfig) -> Self {
|
||||||
|
DeviceState {
|
||||||
|
slash_enabled: config.enabled,
|
||||||
|
slash_brightness: config.brightness,
|
||||||
|
slash_interval: config.display_interval,
|
||||||
|
slash_mode: config.display_mode,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
69
asusd/src/aura_slash/mod.rs
Normal file
69
asusd/src/aura_slash/mod.rs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use config::SlashConfig;
|
||||||
|
use rog_platform::hid_raw::HidRaw;
|
||||||
|
use rog_platform::usb_raw::USBRaw;
|
||||||
|
use rog_slash::usb::{slash_pkt_enable, slash_pkt_init, slash_pkt_options, slash_pkt_set_mode};
|
||||||
|
use tokio::sync::{Mutex, MutexGuard};
|
||||||
|
|
||||||
|
use crate::error::RogError;
|
||||||
|
|
||||||
|
pub mod config;
|
||||||
|
pub mod trait_impls;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Slash {
|
||||||
|
hid: Option<Arc<Mutex<HidRaw>>>,
|
||||||
|
usb: Option<Arc<Mutex<USBRaw>>>,
|
||||||
|
config: Arc<Mutex<SlashConfig>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Slash {
|
||||||
|
pub fn new(
|
||||||
|
hid: Option<Arc<Mutex<HidRaw>>>,
|
||||||
|
usb: Option<Arc<Mutex<USBRaw>>>,
|
||||||
|
config: Arc<Mutex<SlashConfig>>,
|
||||||
|
) -> Self {
|
||||||
|
Self { hid, usb, config }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn lock_config(&self) -> MutexGuard<'_, SlashConfig> {
|
||||||
|
self.config.lock().await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
||||||
|
if let Some(hid) = &self.hid {
|
||||||
|
hid.lock().await.write_bytes(message)?;
|
||||||
|
} else if let Some(usb) = &self.usb {
|
||||||
|
usb.lock().await.write_bytes(message)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialise the device if required. Locks the internal config so be wary
|
||||||
|
/// of deadlocks.
|
||||||
|
pub async fn do_initialization(&self) -> Result<(), RogError> {
|
||||||
|
// Don't try to initialise these models as the asus drivers already did
|
||||||
|
let config = self.config.lock().await;
|
||||||
|
for pkt in &slash_pkt_init(config.slash_type) {
|
||||||
|
self.write_bytes(pkt).await?;
|
||||||
|
}
|
||||||
|
self.write_bytes(&slash_pkt_enable(config.slash_type, config.enabled))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// Apply config upon initialization
|
||||||
|
let option_packets = slash_pkt_options(
|
||||||
|
config.slash_type,
|
||||||
|
config.enabled,
|
||||||
|
config.brightness,
|
||||||
|
config.display_interval,
|
||||||
|
);
|
||||||
|
self.write_bytes(&option_packets).await?;
|
||||||
|
|
||||||
|
let mode_packets = slash_pkt_set_mode(config.slash_type, config.display_mode);
|
||||||
|
// self.node.write_bytes(&mode_packets[0])?;
|
||||||
|
self.write_bytes(&mode_packets[1]).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
317
asusd/src/aura_slash/trait_impls.rs
Normal file
317
asusd/src/aura_slash/trait_impls.rs
Normal file
@@ -0,0 +1,317 @@
|
|||||||
|
use config_traits::StdConfig;
|
||||||
|
use log::{debug, error, warn};
|
||||||
|
use rog_slash::usb::{
|
||||||
|
slash_pkt_battery_saver, slash_pkt_boot, slash_pkt_enable, slash_pkt_lid_closed,
|
||||||
|
slash_pkt_low_battery, slash_pkt_options, slash_pkt_save, slash_pkt_set_mode,
|
||||||
|
slash_pkt_shutdown, slash_pkt_sleep,
|
||||||
|
};
|
||||||
|
use rog_slash::{DeviceState, SlashMode};
|
||||||
|
use zbus::zvariant::OwnedObjectPath;
|
||||||
|
use zbus::{interface, Connection};
|
||||||
|
|
||||||
|
use super::Slash;
|
||||||
|
use crate::error::RogError;
|
||||||
|
use crate::Reloadable;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct SlashZbus(Slash);
|
||||||
|
|
||||||
|
impl SlashZbus {
|
||||||
|
pub fn new(slash: Slash) -> Self {
|
||||||
|
Self(slash)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start_tasks(
|
||||||
|
mut self,
|
||||||
|
connection: &Connection,
|
||||||
|
path: OwnedObjectPath,
|
||||||
|
) -> Result<(), RogError> {
|
||||||
|
// let task = zbus.clone();
|
||||||
|
self.reload()
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|err| warn!("Controller error: {}", err));
|
||||||
|
connection
|
||||||
|
.object_server()
|
||||||
|
.at(path.clone(), self)
|
||||||
|
.await
|
||||||
|
.map_err(|e| error!("Couldn't add server at path: {path}, {e:?}"))
|
||||||
|
.ok();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[interface(name = "xyz.ljones.Slash")]
|
||||||
|
impl SlashZbus {
|
||||||
|
/// Get enabled or not
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn enabled(&self) -> bool {
|
||||||
|
let lock = self.0.lock_config().await;
|
||||||
|
lock.enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set enabled true or false
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_enabled(&self, enabled: bool) {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
let brightness = if enabled && config.brightness == 0 {
|
||||||
|
0x88
|
||||||
|
} else {
|
||||||
|
config.brightness
|
||||||
|
};
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_enable(config.slash_type, enabled))
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("ctrl_slash::enable {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_options(
|
||||||
|
config.slash_type,
|
||||||
|
enabled,
|
||||||
|
brightness,
|
||||||
|
config.display_interval,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("ctrl_slash::set_options {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
config.enabled = enabled;
|
||||||
|
config.brightness = brightness;
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get brightness level
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn brightness(&self) -> u8 {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
config.brightness
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set brightness level
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_brightness(&self, brightness: u8) {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
let enabled = brightness > 0;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_options(
|
||||||
|
config.slash_type,
|
||||||
|
enabled,
|
||||||
|
brightness,
|
||||||
|
config.display_interval,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("ctrl_slash::set_options {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
config.enabled = enabled;
|
||||||
|
config.brightness = brightness;
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn interval(&self) -> u8 {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
config.display_interval
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set interval between slash animations (0-255)
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_interval(&self, interval: u8) {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_options(
|
||||||
|
config.slash_type, config.enabled, config.brightness, interval,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("ctrl_slash::set_options {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
config.display_interval = interval;
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn mode(&self) -> zbus::fdo::Result<u8> {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
Ok(config.display_interval)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set interval between slash animations (0-255)
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_mode(&self, mode: SlashMode) -> zbus::Result<()> {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
|
||||||
|
let command_packets = slash_pkt_set_mode(config.slash_type, mode);
|
||||||
|
// self.node.write_bytes(&command_packets[0])?;
|
||||||
|
self.0.write_bytes(&command_packets[1]).await?;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_save(config.slash_type))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
config.display_mode = mode;
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the device state as stored by asusd
|
||||||
|
// #[zbus(property)]
|
||||||
|
async fn device_state(&self) -> DeviceState {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
DeviceState::from(&*config)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn show_on_boot(&self) -> zbus::fdo::Result<bool> {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
Ok(config.show_on_boot)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_show_on_boot(&self, enable: bool) -> zbus::Result<()> {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_boot(config.slash_type, enable))
|
||||||
|
.await?;
|
||||||
|
config.show_on_boot = enable;
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn show_on_sleep(&self) -> zbus::fdo::Result<bool> {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
Ok(config.show_on_sleep)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_show_on_sleep(&self, enable: bool) -> zbus::Result<()> {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_sleep(config.slash_type, enable))
|
||||||
|
.await?;
|
||||||
|
config.show_on_sleep = enable;
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn show_on_shutdown(&self) -> zbus::fdo::Result<bool> {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
Ok(config.show_on_shutdown)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_show_on_shutdown(&self, enable: bool) -> zbus::Result<()> {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_shutdown(config.slash_type, enable))
|
||||||
|
.await?;
|
||||||
|
config.show_on_shutdown = enable;
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn show_on_battery(&self) -> zbus::fdo::Result<bool> {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
Ok(config.show_on_battery)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_show_on_battery(&self, enable: bool) -> zbus::Result<()> {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_battery_saver(config.slash_type, enable))
|
||||||
|
.await?;
|
||||||
|
config.show_on_battery = enable;
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn show_battery_warning(&self) -> zbus::fdo::Result<bool> {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
Ok(config.show_battery_warning)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_show_battery_warning(&self, enable: bool) -> zbus::Result<()> {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_low_battery(config.slash_type, enable))
|
||||||
|
.await?;
|
||||||
|
config.show_battery_warning = enable;
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn show_on_lid_closed(&self) -> zbus::fdo::Result<bool> {
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
Ok(config.show_on_lid_closed)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_show_on_lid_closed(&self, enable: bool) -> zbus::Result<()> {
|
||||||
|
let mut config = self.0.lock_config().await;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_lid_closed(config.slash_type, enable))
|
||||||
|
.await?;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_save(config.slash_type))
|
||||||
|
.await?;
|
||||||
|
config.show_on_lid_closed = enable;
|
||||||
|
config.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reloadable for SlashZbus {
|
||||||
|
async fn reload(&mut self) -> Result<(), RogError> {
|
||||||
|
debug!("reloading slash settings");
|
||||||
|
let config = self.0.lock_config().await;
|
||||||
|
self.0
|
||||||
|
.write_bytes(&slash_pkt_options(
|
||||||
|
config.slash_type,
|
||||||
|
config.enabled,
|
||||||
|
config.brightness,
|
||||||
|
config.display_interval,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("set_options {}", err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
macro_rules! write_bytes_with_warning {
|
||||||
|
($packet_fn:expr, $cfg:ident, $warn_msg:expr) => {
|
||||||
|
self.0
|
||||||
|
.write_bytes(&$packet_fn(config.slash_type, config.$cfg))
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("{} {}", $warn_msg, err);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
write_bytes_with_warning!(slash_pkt_boot, show_on_boot, "show_on_boot");
|
||||||
|
write_bytes_with_warning!(slash_pkt_sleep, show_on_sleep, "show_on_sleep");
|
||||||
|
write_bytes_with_warning!(slash_pkt_shutdown, show_on_shutdown, "show_on_shutdown");
|
||||||
|
write_bytes_with_warning!(slash_pkt_battery_saver, show_on_battery, "show_on_battery");
|
||||||
|
write_bytes_with_warning!(
|
||||||
|
slash_pkt_low_battery,
|
||||||
|
show_battery_warning,
|
||||||
|
"show_battery_warning"
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
209
asusd/src/aura_types.rs
Normal file
209
asusd/src/aura_types.rs
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use config_traits::{StdConfig, StdConfigLoad};
|
||||||
|
use log::{debug, error, info};
|
||||||
|
use rog_anime::error::AnimeError;
|
||||||
|
use rog_anime::usb::get_anime_type;
|
||||||
|
use rog_anime::AnimeType;
|
||||||
|
use rog_aura::AuraDeviceType;
|
||||||
|
use rog_platform::hid_raw::HidRaw;
|
||||||
|
use rog_platform::keyboard_led::KeyboardBacklight;
|
||||||
|
use rog_platform::usb_raw::USBRaw;
|
||||||
|
use rog_scsi::{open_device, ScsiType};
|
||||||
|
use rog_slash::error::SlashError;
|
||||||
|
use rog_slash::SlashType;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
|
use crate::aura_anime::config::AniMeConfig;
|
||||||
|
use crate::aura_anime::AniMe;
|
||||||
|
use crate::aura_laptop::config::AuraConfig;
|
||||||
|
use crate::aura_laptop::Aura;
|
||||||
|
use crate::aura_scsi::config::ScsiConfig;
|
||||||
|
use crate::aura_scsi::ScsiAura;
|
||||||
|
use crate::aura_slash::config::SlashConfig;
|
||||||
|
use crate::aura_slash::Slash;
|
||||||
|
use crate::error::RogError;
|
||||||
|
|
||||||
|
pub enum _DeviceHandle {
|
||||||
|
/// The AniMe devices require USBRaw as they are not HID devices
|
||||||
|
Usb(USBRaw),
|
||||||
|
HidRaw(HidRaw),
|
||||||
|
LedClass(KeyboardBacklight),
|
||||||
|
/// TODO
|
||||||
|
MulticolourLed,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum DeviceHandle {
|
||||||
|
Aura(Aura),
|
||||||
|
Slash(Slash),
|
||||||
|
/// The AniMe devices require USBRaw as they are not HID devices
|
||||||
|
AniMe(AniMe),
|
||||||
|
Scsi(ScsiAura),
|
||||||
|
Ally(Arc<Mutex<HidRaw>>),
|
||||||
|
OldAura(Arc<Mutex<HidRaw>>),
|
||||||
|
/// TUF laptops have an aditional set of attributes added to the LED /sysfs/
|
||||||
|
TufLedClass(Arc<Mutex<HidRaw>>),
|
||||||
|
/// TODO
|
||||||
|
MulticolourLed,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DeviceHandle {
|
||||||
|
/// Try Slash HID. If one exists it is initialsed and returned.
|
||||||
|
pub async fn new_slash_hid(
|
||||||
|
device: Arc<Mutex<HidRaw>>,
|
||||||
|
prod_id: &str,
|
||||||
|
) -> Result<Self, RogError> {
|
||||||
|
debug!("Testing for HIDRAW Slash");
|
||||||
|
let slash_type = SlashType::from_dmi();
|
||||||
|
if matches!(slash_type, SlashType::Unsupported)
|
||||||
|
|| slash_type
|
||||||
|
.prod_id_str()
|
||||||
|
.to_lowercase()
|
||||||
|
.trim_start_matches("0x")
|
||||||
|
!= prod_id
|
||||||
|
{
|
||||||
|
log::info!("Unknown or invalid slash: {prod_id:?}, skipping");
|
||||||
|
return Err(RogError::NotFound("No slash device".to_string()));
|
||||||
|
}
|
||||||
|
info!("Found slash type {slash_type:?}: {prod_id}");
|
||||||
|
|
||||||
|
let mut config = SlashConfig::new().load();
|
||||||
|
config.slash_type = slash_type;
|
||||||
|
let slash = Slash::new(Some(device), None, Arc::new(Mutex::new(config)));
|
||||||
|
slash.do_initialization().await?;
|
||||||
|
Ok(Self::Slash(slash))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Try Slash USB. If one exists it is initialsed and returned.
|
||||||
|
pub async fn new_slash_usb() -> Result<Self, RogError> {
|
||||||
|
debug!("Testing for USB Slash");
|
||||||
|
let slash_type = SlashType::from_dmi();
|
||||||
|
if matches!(slash_type, SlashType::Unsupported) {
|
||||||
|
return Err(RogError::Slash(SlashError::NoDevice));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(usb) = USBRaw::new(slash_type.prod_id()) {
|
||||||
|
info!("Found Slash USB {slash_type:?}");
|
||||||
|
|
||||||
|
let mut config = SlashConfig::new().load();
|
||||||
|
config.slash_type = slash_type;
|
||||||
|
let slash = Slash::new(
|
||||||
|
None,
|
||||||
|
Some(Arc::new(Mutex::new(usb))),
|
||||||
|
Arc::new(Mutex::new(config)),
|
||||||
|
);
|
||||||
|
slash.do_initialization().await?;
|
||||||
|
Ok(Self::Slash(slash))
|
||||||
|
} else {
|
||||||
|
Err(RogError::NotFound("No slash device found".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Try AniMe Matrix HID. If one exists it is initialsed and returned.
|
||||||
|
pub async fn maybe_anime_hid(
|
||||||
|
_device: Arc<Mutex<HidRaw>>,
|
||||||
|
_prod_id: &str,
|
||||||
|
) -> Result<Self, RogError> {
|
||||||
|
// TODO: can't use HIDRAW for anime at the moment
|
||||||
|
Err(RogError::NotFound(
|
||||||
|
"Can't use anime over hidraw yet. Skip.".to_string(),
|
||||||
|
))
|
||||||
|
|
||||||
|
// debug!("Testing for HIDRAW AniMe");
|
||||||
|
// let anime_type = AnimeType::from_dmi();
|
||||||
|
// dbg!(prod_id);
|
||||||
|
// if matches!(anime_type, AnimeType::Unsupported) || prod_id != "193b"
|
||||||
|
// { log::info!("Unknown or invalid AniMe: {prod_id:?},
|
||||||
|
// skipping"); return Err(RogError::NotFound("No
|
||||||
|
// anime-matrix device".to_string())); }
|
||||||
|
// info!("Found AniMe Matrix HIDRAW {anime_type:?}: {prod_id}");
|
||||||
|
|
||||||
|
// let mut config = AniMeConfig::new().load();
|
||||||
|
// config.anime_type = anime_type;
|
||||||
|
// let mut anime = AniMe::new(Some(device), None,
|
||||||
|
// Arc::new(Mutex::new(config))); anime.do_initialization().
|
||||||
|
// await?; Ok(Self::AniMe(anime))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn maybe_anime_usb() -> Result<Self, RogError> {
|
||||||
|
debug!("Testing for USB AniMe");
|
||||||
|
let anime_type = get_anime_type();
|
||||||
|
if matches!(anime_type, AnimeType::Unsupported) {
|
||||||
|
info!("No Anime Matrix capable laptop found");
|
||||||
|
return Err(RogError::Anime(AnimeError::NoDevice));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(usb) = USBRaw::new(0x193b) {
|
||||||
|
info!("Found AniMe Matrix USB {anime_type:?}");
|
||||||
|
|
||||||
|
let mut config = AniMeConfig::new().load();
|
||||||
|
config.anime_type = anime_type;
|
||||||
|
let mut anime = AniMe::new(
|
||||||
|
None,
|
||||||
|
Some(Arc::new(Mutex::new(usb))),
|
||||||
|
Arc::new(Mutex::new(config)),
|
||||||
|
);
|
||||||
|
anime.do_initialization().await?;
|
||||||
|
Ok(Self::AniMe(anime))
|
||||||
|
} else {
|
||||||
|
Err(RogError::NotFound(
|
||||||
|
"No AnimeMatrix device found".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn maybe_scsi(dev_node: &str, prod_id: &str) -> Result<Self, RogError> {
|
||||||
|
debug!("Testing for SCSI");
|
||||||
|
let prod_id = ScsiType::from(prod_id);
|
||||||
|
if prod_id == ScsiType::Unsupported {
|
||||||
|
log::info!("Unknown or invalid SCSI: {prod_id:?}, skipping");
|
||||||
|
return Err(RogError::NotFound("No SCSI device".to_string()));
|
||||||
|
}
|
||||||
|
info!("Found SCSI device {prod_id:?} on {dev_node}");
|
||||||
|
|
||||||
|
let mut config = ScsiConfig::new().load();
|
||||||
|
config.dev_type = AuraDeviceType::ScsiExtDisk;
|
||||||
|
let dev = Arc::new(Mutex::new(open_device(dev_node)?));
|
||||||
|
let scsi = ScsiAura::new(dev, Arc::new(Mutex::new(config)));
|
||||||
|
scsi.do_initialization().await?;
|
||||||
|
Ok(Self::Scsi(scsi))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn maybe_laptop_aura(
|
||||||
|
device: Option<Arc<Mutex<HidRaw>>>,
|
||||||
|
prod_id: &str,
|
||||||
|
) -> Result<Self, RogError> {
|
||||||
|
debug!("Testing for laptop aura");
|
||||||
|
let aura_type = AuraDeviceType::from(prod_id);
|
||||||
|
if !matches!(
|
||||||
|
aura_type,
|
||||||
|
AuraDeviceType::LaptopKeyboard2021
|
||||||
|
| AuraDeviceType::LaptopKeyboardPre2021
|
||||||
|
| AuraDeviceType::LaptopKeyboardTuf
|
||||||
|
) {
|
||||||
|
log::info!("Unknown or invalid laptop aura: {prod_id:?}, skipping");
|
||||||
|
return Err(RogError::NotFound("No laptop aura device".to_string()));
|
||||||
|
}
|
||||||
|
info!("Found laptop aura type {prod_id:?}");
|
||||||
|
|
||||||
|
let backlight = KeyboardBacklight::new()
|
||||||
|
.map_err(|e| error!("Keyboard backlight error: {e:?}"))
|
||||||
|
.map_or(None, |k| {
|
||||||
|
info!("Found sysfs backlight control");
|
||||||
|
Some(Arc::new(Mutex::new(k)))
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut config = AuraConfig::load_and_update_config(prod_id);
|
||||||
|
config.led_type = aura_type;
|
||||||
|
let aura = Aura {
|
||||||
|
hid: device,
|
||||||
|
backlight,
|
||||||
|
config: Arc::new(Mutex::new(config)),
|
||||||
|
};
|
||||||
|
aura.do_initialization().await?;
|
||||||
|
Ok(Self::Aura(aura))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,85 +1,119 @@
|
|||||||
use config_traits::{StdConfig, StdConfigLoad3};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use config_traits::{StdConfig, StdConfigLoad2};
|
||||||
|
use rog_platform::asus_armoury::FirmwareAttribute;
|
||||||
use rog_platform::cpu::CPUEPP;
|
use rog_platform::cpu::CPUEPP;
|
||||||
use rog_platform::platform::ThrottlePolicy;
|
use rog_platform::platform::PlatformProfile;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
const CONFIG_FILE: &str = "asusd.ron";
|
const CONFIG_FILE: &str = "asusd.ron";
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, PartialEq, PartialOrd)]
|
/// Default value for base_charge_control_end_threshold when not present in config.
|
||||||
|
/// Returns 0 so restore_charge_limit() skips restoration for upgraded configs.
|
||||||
|
fn default_base_charge_limit() -> u8 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Clone, Deserialize, Serialize, PartialEq)]
|
||||||
|
pub struct Tuning {
|
||||||
|
pub enabled: bool,
|
||||||
|
pub group: HashMap<FirmwareAttribute, i32>,
|
||||||
|
}
|
||||||
|
type Tunings = HashMap<PlatformProfile, Tuning>;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, PartialEq)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// Save charge limit for restoring on boot/resume
|
// The current charge limit applied
|
||||||
pub charge_control_end_threshold: u8,
|
pub charge_control_end_threshold: u8,
|
||||||
pub panel_od: bool,
|
/// Save charge limit for restoring after one-shot full charge
|
||||||
pub boot_sound: bool,
|
#[serde(default = "default_base_charge_limit")]
|
||||||
pub mini_led_mode: bool,
|
pub base_charge_control_end_threshold: u8,
|
||||||
pub disable_nvidia_powerd_on_battery: bool,
|
pub disable_nvidia_powerd_on_battery: bool,
|
||||||
/// An optional command/script to run when power is changed to AC
|
/// An optional command/script to run when power is changed to AC
|
||||||
pub ac_command: String,
|
pub ac_command: String,
|
||||||
/// An optional command/script to run when power is changed to battery
|
/// An optional command/script to run when power is changed to battery
|
||||||
pub bat_command: String,
|
pub bat_command: String,
|
||||||
/// Set true if energy_performance_preference should be set if the
|
/// Set true if energy_performance_preference should be set if the
|
||||||
/// throttle/platform profile is changed
|
/// platform profile is changed
|
||||||
pub throttle_policy_linked_epp: bool,
|
pub platform_profile_linked_epp: bool,
|
||||||
/// Which throttle/profile to use on battery power
|
/// Which platform profile to use on battery power
|
||||||
pub throttle_policy_on_battery: ThrottlePolicy,
|
pub platform_profile_on_battery: PlatformProfile,
|
||||||
/// Which throttle/profile to use on AC power
|
/// Should the throttle policy be set on bat/ac change?
|
||||||
pub throttle_policy_on_ac: ThrottlePolicy,
|
pub change_platform_profile_on_battery: bool,
|
||||||
/// The energy_performance_preference for this throttle/platform profile
|
/// Which platform profile to use on AC power
|
||||||
pub throttle_quiet_epp: CPUEPP,
|
pub platform_profile_on_ac: PlatformProfile,
|
||||||
/// The energy_performance_preference for this throttle/platform profile
|
/// Should the platform profile be set on bat/ac change?
|
||||||
pub throttle_balanced_epp: CPUEPP,
|
pub change_platform_profile_on_ac: bool,
|
||||||
/// The energy_performance_preference for this throttle/platform profile
|
/// The energy_performance_preference for this platform profile
|
||||||
pub throttle_performance_epp: CPUEPP,
|
pub profile_quiet_epp: CPUEPP,
|
||||||
/// Defaults to `None` if not supported
|
/// The energy_performance_preference for this platform profile
|
||||||
|
pub profile_balanced_epp: CPUEPP,
|
||||||
|
/// The energy_performance_preference for this platform profile
|
||||||
|
pub profile_custom_epp: CPUEPP,
|
||||||
|
/// The energy_performance_preference for this platform profile
|
||||||
|
pub profile_performance_epp: CPUEPP,
|
||||||
|
pub ac_profile_tunings: Tunings,
|
||||||
|
pub dc_profile_tunings: Tunings,
|
||||||
|
pub armoury_settings: HashMap<FirmwareAttribute, i32>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
pub ppt_pl1_spl: Option<u8>,
|
pub screenpad_gamma: Option<f32>,
|
||||||
/// Defaults to `None` if not supported
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
pub ppt_pl2_sppt: Option<u8>,
|
pub screenpad_sync_primary: Option<bool>,
|
||||||
/// Defaults to `None` if not supported
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
||||||
pub ppt_fppt: Option<u8>,
|
|
||||||
/// Defaults to `None` if not supported
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
||||||
pub ppt_apu_sppt: Option<u8>,
|
|
||||||
/// Defaults to `None` if not supported
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
||||||
pub ppt_platform_sppt: Option<u8>,
|
|
||||||
/// Defaults to `None` if not supported
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
||||||
pub nv_dynamic_boost: Option<u8>,
|
|
||||||
/// Defaults to `None` if not supported
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
||||||
pub nv_temp_target: Option<u8>,
|
|
||||||
/// Temporary state for AC/Batt
|
/// Temporary state for AC/Batt
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub last_power_plugged: u8,
|
pub last_power_plugged: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn select_tunings(&mut self, power_plugged: bool, profile: PlatformProfile) -> &mut Tuning {
|
||||||
|
let config = if power_plugged {
|
||||||
|
&mut self.ac_profile_tunings
|
||||||
|
} else {
|
||||||
|
&mut self.dc_profile_tunings
|
||||||
|
};
|
||||||
|
config.entry(profile).or_insert_with(Tuning::default)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn select_tunings_ref(
|
||||||
|
&self,
|
||||||
|
power_plugged: bool,
|
||||||
|
profile: PlatformProfile,
|
||||||
|
) -> Option<&Tuning> {
|
||||||
|
let config = if power_plugged {
|
||||||
|
&self.ac_profile_tunings
|
||||||
|
} else {
|
||||||
|
&self.dc_profile_tunings
|
||||||
|
};
|
||||||
|
config.get(&profile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
charge_control_end_threshold: 100,
|
charge_control_end_threshold: 100,
|
||||||
panel_od: false,
|
// NOTE: This is intentionally 100 (not 0 like the serde default).
|
||||||
boot_sound: false,
|
// New installs get 100 (no limit). Upgraded configs missing this
|
||||||
mini_led_mode: false,
|
// field get 0 via serde, which skips restore_charge_limit().
|
||||||
|
base_charge_control_end_threshold: 100,
|
||||||
disable_nvidia_powerd_on_battery: true,
|
disable_nvidia_powerd_on_battery: true,
|
||||||
ac_command: Default::default(),
|
ac_command: Default::default(),
|
||||||
bat_command: Default::default(),
|
bat_command: Default::default(),
|
||||||
throttle_policy_linked_epp: true,
|
platform_profile_linked_epp: true,
|
||||||
throttle_policy_on_battery: ThrottlePolicy::Quiet,
|
platform_profile_on_battery: PlatformProfile::Quiet,
|
||||||
throttle_policy_on_ac: ThrottlePolicy::Performance,
|
change_platform_profile_on_battery: true,
|
||||||
throttle_quiet_epp: CPUEPP::Power,
|
platform_profile_on_ac: PlatformProfile::Performance,
|
||||||
throttle_balanced_epp: CPUEPP::BalancePower,
|
change_platform_profile_on_ac: true,
|
||||||
throttle_performance_epp: CPUEPP::Performance,
|
profile_quiet_epp: CPUEPP::Power,
|
||||||
ppt_pl1_spl: Default::default(),
|
profile_balanced_epp: CPUEPP::BalancePower,
|
||||||
ppt_pl2_sppt: Default::default(),
|
profile_performance_epp: CPUEPP::Performance,
|
||||||
ppt_fppt: Default::default(),
|
profile_custom_epp: CPUEPP::Performance,
|
||||||
ppt_apu_sppt: Default::default(),
|
ac_profile_tunings: HashMap::default(),
|
||||||
ppt_platform_sppt: Default::default(),
|
dc_profile_tunings: HashMap::default(),
|
||||||
nv_dynamic_boost: Default::default(),
|
armoury_settings: HashMap::default(),
|
||||||
nv_temp_target: Default::default(),
|
|
||||||
last_power_plugged: Default::default(),
|
last_power_plugged: Default::default(),
|
||||||
|
screenpad_gamma: Default::default(),
|
||||||
|
screenpad_sync_primary: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,8 +123,8 @@ impl StdConfig for Config {
|
|||||||
Config {
|
Config {
|
||||||
charge_control_end_threshold: 100,
|
charge_control_end_threshold: 100,
|
||||||
disable_nvidia_powerd_on_battery: true,
|
disable_nvidia_powerd_on_battery: true,
|
||||||
throttle_policy_on_battery: ThrottlePolicy::Quiet,
|
platform_profile_on_battery: PlatformProfile::Quiet,
|
||||||
throttle_policy_on_ac: ThrottlePolicy::Performance,
|
platform_profile_on_ac: PlatformProfile::Performance,
|
||||||
ac_command: String::new(),
|
ac_command: String::new(),
|
||||||
bat_command: String::new(),
|
bat_command: String::new(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -106,130 +140,128 @@ impl StdConfig for Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdConfigLoad3<Config472, Config506, Config507> for Config {}
|
impl StdConfigLoad2<Config611, Config601> for Config {}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct Config507 {
|
pub struct Config611 {
|
||||||
/// Save charge limit for restoring on boot
|
|
||||||
pub charge_control_end_threshold: u8,
|
pub charge_control_end_threshold: u8,
|
||||||
pub panel_od: bool,
|
|
||||||
pub mini_led_mode: bool,
|
|
||||||
pub disable_nvidia_powerd_on_battery: bool,
|
|
||||||
pub ac_command: String,
|
|
||||||
pub bat_command: String,
|
|
||||||
pub platform_policy_linked_epp: bool,
|
|
||||||
pub platform_policy_on_battery: ThrottlePolicy,
|
|
||||||
pub platform_policy_on_ac: ThrottlePolicy,
|
|
||||||
//
|
|
||||||
pub ppt_pl1_spl: Option<u8>,
|
|
||||||
pub ppt_pl2_sppt: Option<u8>,
|
|
||||||
pub ppt_fppt: Option<u8>,
|
|
||||||
pub ppt_apu_sppt: Option<u8>,
|
|
||||||
pub ppt_platform_sppt: Option<u8>,
|
|
||||||
pub nv_dynamic_boost: Option<u8>,
|
|
||||||
pub nv_temp_target: Option<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Config507> for Config {
|
|
||||||
fn from(c: Config507) -> Self {
|
|
||||||
Self {
|
|
||||||
charge_control_end_threshold: c.charge_control_end_threshold,
|
|
||||||
panel_od: c.panel_od,
|
|
||||||
boot_sound: false,
|
|
||||||
disable_nvidia_powerd_on_battery: c.disable_nvidia_powerd_on_battery,
|
|
||||||
ac_command: c.ac_command,
|
|
||||||
bat_command: c.bat_command,
|
|
||||||
mini_led_mode: c.mini_led_mode,
|
|
||||||
throttle_policy_linked_epp: true,
|
|
||||||
throttle_policy_on_battery: c.platform_policy_on_battery,
|
|
||||||
throttle_policy_on_ac: c.platform_policy_on_ac,
|
|
||||||
throttle_quiet_epp: CPUEPP::Power,
|
|
||||||
throttle_balanced_epp: CPUEPP::BalancePower,
|
|
||||||
throttle_performance_epp: CPUEPP::Performance,
|
|
||||||
ppt_pl1_spl: c.ppt_pl1_spl,
|
|
||||||
ppt_pl2_sppt: c.ppt_pl2_sppt,
|
|
||||||
ppt_fppt: c.ppt_fppt,
|
|
||||||
ppt_apu_sppt: c.ppt_apu_sppt,
|
|
||||||
ppt_platform_sppt: c.ppt_platform_sppt,
|
|
||||||
nv_dynamic_boost: c.nv_dynamic_boost,
|
|
||||||
nv_temp_target: c.nv_temp_target,
|
|
||||||
last_power_plugged: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
|
||||||
pub struct Config506 {
|
|
||||||
/// Save charge limit for restoring on boot
|
|
||||||
pub charge_control_end_threshold: u8,
|
|
||||||
pub panel_od: bool,
|
|
||||||
pub mini_led_mode: bool,
|
|
||||||
pub disable_nvidia_powerd_on_battery: bool,
|
|
||||||
pub ac_command: String,
|
|
||||||
pub bat_command: String,
|
|
||||||
/// Restored on boot as well as when power is plugged
|
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub platform_policy_to_restore: ThrottlePolicy,
|
pub base_charge_control_end_threshold: u8,
|
||||||
pub platform_policy_on_battery: ThrottlePolicy,
|
pub disable_nvidia_powerd_on_battery: bool,
|
||||||
pub platform_policy_on_ac: ThrottlePolicy,
|
pub ac_command: String,
|
||||||
//
|
pub bat_command: String,
|
||||||
pub ppt_pl1_spl: Option<u8>,
|
pub platform_profile_linked_epp: bool,
|
||||||
pub ppt_pl2_sppt: Option<u8>,
|
pub platform_profile_on_battery: PlatformProfile,
|
||||||
pub ppt_fppt: Option<u8>,
|
pub change_platform_profile_on_battery: bool,
|
||||||
pub ppt_apu_sppt: Option<u8>,
|
pub platform_profile_on_ac: PlatformProfile,
|
||||||
pub ppt_platform_sppt: Option<u8>,
|
pub change_platform_profile_on_ac: bool,
|
||||||
pub nv_dynamic_boost: Option<u8>,
|
pub profile_quiet_epp: CPUEPP,
|
||||||
pub nv_temp_target: Option<u8>,
|
pub profile_balanced_epp: CPUEPP,
|
||||||
|
pub profile_custom_epp: CPUEPP,
|
||||||
|
pub profile_performance_epp: CPUEPP,
|
||||||
|
pub ac_profile_tunings: Tunings,
|
||||||
|
pub dc_profile_tunings: Tunings,
|
||||||
|
pub armoury_settings: HashMap<FirmwareAttribute, i32>,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub last_power_plugged: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Config506> for Config {
|
impl From<Config611> for Config {
|
||||||
fn from(c: Config506) -> Self {
|
fn from(c: Config611) -> Self {
|
||||||
Self {
|
let mut config = Self {
|
||||||
|
// Restore the base charge limit
|
||||||
charge_control_end_threshold: c.charge_control_end_threshold,
|
charge_control_end_threshold: c.charge_control_end_threshold,
|
||||||
panel_od: c.panel_od,
|
base_charge_control_end_threshold: c.charge_control_end_threshold,
|
||||||
boot_sound: false,
|
|
||||||
disable_nvidia_powerd_on_battery: c.disable_nvidia_powerd_on_battery,
|
disable_nvidia_powerd_on_battery: c.disable_nvidia_powerd_on_battery,
|
||||||
ac_command: c.ac_command,
|
ac_command: c.ac_command,
|
||||||
bat_command: c.bat_command,
|
bat_command: c.bat_command,
|
||||||
mini_led_mode: c.mini_led_mode,
|
platform_profile_linked_epp: c.platform_profile_linked_epp,
|
||||||
throttle_policy_linked_epp: true,
|
platform_profile_on_battery: c.platform_profile_on_battery,
|
||||||
throttle_policy_on_battery: c.platform_policy_on_battery,
|
change_platform_profile_on_battery: c.change_platform_profile_on_battery,
|
||||||
throttle_policy_on_ac: c.platform_policy_on_ac,
|
platform_profile_on_ac: c.platform_profile_on_ac,
|
||||||
throttle_quiet_epp: CPUEPP::Power,
|
change_platform_profile_on_ac: c.change_platform_profile_on_ac,
|
||||||
throttle_balanced_epp: CPUEPP::BalancePower,
|
profile_quiet_epp: c.profile_quiet_epp,
|
||||||
throttle_performance_epp: CPUEPP::Performance,
|
profile_balanced_epp: c.profile_balanced_epp,
|
||||||
ppt_pl1_spl: c.ppt_pl1_spl,
|
profile_performance_epp: c.profile_performance_epp,
|
||||||
ppt_pl2_sppt: c.ppt_pl2_sppt,
|
profile_custom_epp: c.profile_performance_epp,
|
||||||
ppt_fppt: c.ppt_fppt,
|
last_power_plugged: c.last_power_plugged,
|
||||||
ppt_apu_sppt: c.ppt_apu_sppt,
|
ac_profile_tunings: HashMap::default(),
|
||||||
ppt_platform_sppt: c.ppt_platform_sppt,
|
dc_profile_tunings: HashMap::default(),
|
||||||
nv_dynamic_boost: c.nv_dynamic_boost,
|
armoury_settings: HashMap::default(),
|
||||||
nv_temp_target: c.nv_temp_target,
|
screenpad_gamma: None,
|
||||||
last_power_plugged: 0,
|
screenpad_sync_primary: Default::default(),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
config.ac_profile_tunings = c.ac_profile_tunings;
|
||||||
|
config.dc_profile_tunings = c.dc_profile_tunings;
|
||||||
|
config.armoury_settings = c.armoury_settings;
|
||||||
|
config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct Config472 {
|
pub struct Config601 {
|
||||||
/// Save charge limit for restoring on boot
|
pub charge_control_end_threshold: u8,
|
||||||
pub bat_charge_limit: u8,
|
#[serde(skip)]
|
||||||
|
pub base_charge_control_end_threshold: u8,
|
||||||
pub panel_od: bool,
|
pub panel_od: bool,
|
||||||
|
pub boot_sound: bool,
|
||||||
pub mini_led_mode: bool,
|
pub mini_led_mode: bool,
|
||||||
pub disable_nvidia_powerd_on_battery: bool,
|
pub disable_nvidia_powerd_on_battery: bool,
|
||||||
pub ac_command: String,
|
pub ac_command: String,
|
||||||
pub bat_command: String,
|
pub bat_command: String,
|
||||||
|
pub platform_profile_linked_epp: bool,
|
||||||
|
pub platform_profile_on_battery: PlatformProfile,
|
||||||
|
pub change_platform_profile_on_battery: bool,
|
||||||
|
pub platform_profile_on_ac: PlatformProfile,
|
||||||
|
pub change_platform_profile_on_ac: bool,
|
||||||
|
pub profile_quiet_epp: CPUEPP,
|
||||||
|
pub profile_balanced_epp: CPUEPP,
|
||||||
|
pub profile_performance_epp: CPUEPP,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub ppt_pl1_spl: Option<u8>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub ppt_pl2_sppt: Option<u8>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub ppt_pl3_fppt: Option<u8>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub ppt_fppt: Option<u8>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub ppt_apu_sppt: Option<u8>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub ppt_platform_sppt: Option<u8>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub nv_dynamic_boost: Option<u8>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub nv_temp_target: Option<u8>,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub last_power_plugged: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Config472> for Config {
|
impl From<Config601> for Config {
|
||||||
fn from(c: Config472) -> Self {
|
fn from(c: Config601) -> Self {
|
||||||
Self {
|
Self {
|
||||||
charge_control_end_threshold: c.bat_charge_limit,
|
// Restore the base charge limit
|
||||||
panel_od: c.panel_od,
|
charge_control_end_threshold: c.charge_control_end_threshold,
|
||||||
disable_nvidia_powerd_on_battery: true,
|
base_charge_control_end_threshold: c.charge_control_end_threshold,
|
||||||
|
disable_nvidia_powerd_on_battery: c.disable_nvidia_powerd_on_battery,
|
||||||
ac_command: c.ac_command,
|
ac_command: c.ac_command,
|
||||||
bat_command: c.bat_command,
|
bat_command: c.bat_command,
|
||||||
..Default::default()
|
platform_profile_linked_epp: c.platform_profile_linked_epp,
|
||||||
|
platform_profile_on_battery: c.platform_profile_on_battery,
|
||||||
|
change_platform_profile_on_battery: c.change_platform_profile_on_battery,
|
||||||
|
platform_profile_on_ac: c.platform_profile_on_ac,
|
||||||
|
change_platform_profile_on_ac: c.change_platform_profile_on_ac,
|
||||||
|
profile_quiet_epp: c.profile_quiet_epp,
|
||||||
|
profile_balanced_epp: c.profile_balanced_epp,
|
||||||
|
profile_performance_epp: c.profile_performance_epp,
|
||||||
|
profile_custom_epp: c.profile_performance_epp,
|
||||||
|
last_power_plugged: c.last_power_plugged,
|
||||||
|
ac_profile_tunings: HashMap::default(),
|
||||||
|
dc_profile_tunings: HashMap::default(),
|
||||||
|
armoury_settings: HashMap::default(),
|
||||||
|
screenpad_gamma: None,
|
||||||
|
screenpad_sync_primary: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,292 +0,0 @@
|
|||||||
pub mod config;
|
|
||||||
/// Implements `CtrlTask`, Reloadable, `ZbusRun`
|
|
||||||
pub mod trait_impls;
|
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
use std::sync::Arc;
|
|
||||||
use std::thread::sleep;
|
|
||||||
|
|
||||||
use ::zbus::export::futures_util::lock::Mutex;
|
|
||||||
use config_traits::{StdConfig, StdConfigLoad2};
|
|
||||||
use log::{error, info, warn};
|
|
||||||
use rog_anime::error::AnimeError;
|
|
||||||
use rog_anime::usb::{
|
|
||||||
get_anime_type, pkt_flush, pkt_set_brightness, pkt_set_enable_display,
|
|
||||||
pkt_set_enable_powersave_anim, pkts_for_init, Brightness,
|
|
||||||
};
|
|
||||||
use rog_anime::{ActionData, AnimeDataBuffer, AnimePacketType, AnimeType};
|
|
||||||
use rog_platform::hid_raw::HidRaw;
|
|
||||||
use rog_platform::usb_raw::USBRaw;
|
|
||||||
|
|
||||||
use self::config::{AnimeConfig, AnimeConfigCached};
|
|
||||||
use crate::error::RogError;
|
|
||||||
|
|
||||||
enum Node {
|
|
||||||
Usb(USBRaw),
|
|
||||||
Hid(HidRaw),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Node {
|
|
||||||
pub fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
|
||||||
// TODO: map and pass on errors
|
|
||||||
match self {
|
|
||||||
Node::Usb(u) => {
|
|
||||||
u.write_bytes(message).ok();
|
|
||||||
}
|
|
||||||
Node::Hid(h) => {
|
|
||||||
h.write_bytes(message).ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_builtins_enabled(&self, enabled: bool, bright: Brightness) -> Result<(), RogError> {
|
|
||||||
self.write_bytes(&pkt_set_enable_powersave_anim(enabled))?;
|
|
||||||
self.write_bytes(&pkt_set_enable_display(enabled))?;
|
|
||||||
self.write_bytes(&pkt_set_brightness(bright))?;
|
|
||||||
self.write_bytes(&pkt_set_enable_powersave_anim(enabled))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CtrlAnime {
|
|
||||||
// node: HidRaw,
|
|
||||||
node: Node,
|
|
||||||
anime_type: AnimeType,
|
|
||||||
cache: AnimeConfigCached,
|
|
||||||
config: AnimeConfig,
|
|
||||||
// set to force thread to exit
|
|
||||||
thread_exit: Arc<AtomicBool>,
|
|
||||||
// Set to false when the thread exits
|
|
||||||
thread_running: Arc<AtomicBool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CtrlAnime {
|
|
||||||
#[inline]
|
|
||||||
pub fn new() -> Result<CtrlAnime, RogError> {
|
|
||||||
let usb = USBRaw::new(0x193b).ok();
|
|
||||||
let hid = HidRaw::new("193b").ok();
|
|
||||||
let node = if usb.is_some() {
|
|
||||||
info!("Anime using the USB interface");
|
|
||||||
unsafe { Node::Usb(usb.unwrap_unchecked()) }
|
|
||||||
} else if hid.is_some() {
|
|
||||||
info!("Anime using the HID interface");
|
|
||||||
unsafe { Node::Hid(hid.unwrap_unchecked()) }
|
|
||||||
} else {
|
|
||||||
return Err(RogError::Anime(AnimeError::NoDevice));
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: something better to set wakeups disabled
|
|
||||||
// if matches!(node, Node::Usb(_)) {
|
|
||||||
// if let Ok(mut enumerator) = udev::Enumerator::new() {
|
|
||||||
// enumerator.match_subsystem("usb").ok();
|
|
||||||
// enumerator.match_attribute("idProduct", "193b").ok();
|
|
||||||
|
|
||||||
// if let Ok(mut enumer) = enumerator.scan_devices() {
|
|
||||||
// if let Some(mut dev) = enumer.next() {
|
|
||||||
// dev.set_attribute_value("power/wakeup", "disabled").ok();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
let config = AnimeConfig::new().load();
|
|
||||||
let mut anime_type = get_anime_type()?;
|
|
||||||
if let AnimeType::Unknown = anime_type {
|
|
||||||
if let Some(model) = config.model_override {
|
|
||||||
warn!("Overriding the Animatrix type as {model:?}");
|
|
||||||
anime_type = model;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("Device has an AniMe Matrix display: {anime_type:?}");
|
|
||||||
let mut cache = AnimeConfigCached::default();
|
|
||||||
cache.init_from_config(&config, anime_type)?;
|
|
||||||
|
|
||||||
let ctrl = CtrlAnime {
|
|
||||||
node,
|
|
||||||
anime_type,
|
|
||||||
cache,
|
|
||||||
config,
|
|
||||||
thread_exit: Arc::new(AtomicBool::new(false)),
|
|
||||||
thread_running: Arc::new(AtomicBool::new(false)),
|
|
||||||
};
|
|
||||||
ctrl.do_initialization()?;
|
|
||||||
|
|
||||||
Ok(ctrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
// let device = CtrlAnime::get_device(0x0b05, 0x193b)?;
|
|
||||||
|
|
||||||
/// Start an action thread. This is classed as a singleton and there should
|
|
||||||
/// be only one running - so the thread uses atomics to signal run/exit.
|
|
||||||
///
|
|
||||||
/// Because this also writes to the usb device, other write tries (display
|
|
||||||
/// only) *must* get the mutex lock and set the `thread_exit` atomic.
|
|
||||||
async fn run_thread(inner: Arc<Mutex<CtrlAnime>>, actions: Vec<ActionData>, mut once: bool) {
|
|
||||||
if actions.is_empty() {
|
|
||||||
warn!("AniMe system actions was empty");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(lock) = inner.try_lock() {
|
|
||||||
lock.node
|
|
||||||
.write_bytes(&pkt_set_enable_powersave_anim(false))
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!("rog_anime::run_animation:callback {}", err);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop rules:
|
|
||||||
// - Lock the mutex **only when required**. That is, the lock must be held for
|
|
||||||
// the shortest duration possible.
|
|
||||||
// - An AtomicBool used for thread exit should be checked in every loop,
|
|
||||||
// including nested
|
|
||||||
|
|
||||||
// The only reason for this outer thread is to prevent blocking while waiting
|
|
||||||
// for the next spawned thread to exit
|
|
||||||
// TODO: turn this in to async task (maybe? COuld still risk blocking main
|
|
||||||
// thread)
|
|
||||||
std::thread::Builder::new()
|
|
||||||
.name("AniMe system thread start".into())
|
|
||||||
.spawn(move || {
|
|
||||||
info!("AniMe new system thread started");
|
|
||||||
// Getting copies of these Atomics is done *in* the thread to ensure
|
|
||||||
// we don't block other threads/main
|
|
||||||
let thread_exit;
|
|
||||||
let thread_running;
|
|
||||||
let anime_type;
|
|
||||||
loop {
|
|
||||||
if let Some(lock) = inner.try_lock() {
|
|
||||||
thread_exit = lock.thread_exit.clone();
|
|
||||||
thread_running = lock.thread_running.clone();
|
|
||||||
anime_type = lock.anime_type;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// First two loops are to ensure we *do* aquire a lock on the mutex
|
|
||||||
// The reason the loop is required is because the USB writes can block
|
|
||||||
// for up to 10ms. We can't fail to get the atomics.
|
|
||||||
while thread_running.load(Ordering::SeqCst) {
|
|
||||||
// Make any running loop exit first
|
|
||||||
thread_exit.store(true, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("AniMe no previous system thread running (now)");
|
|
||||||
thread_exit.store(false, Ordering::SeqCst);
|
|
||||||
thread_running.store(true, Ordering::SeqCst);
|
|
||||||
'main: loop {
|
|
||||||
for action in &actions {
|
|
||||||
if thread_exit.load(Ordering::SeqCst) {
|
|
||||||
break 'main;
|
|
||||||
}
|
|
||||||
match action {
|
|
||||||
ActionData::Animation(frames) => {
|
|
||||||
rog_anime::run_animation(frames, &|frame| {
|
|
||||||
if thread_exit.load(Ordering::Acquire) {
|
|
||||||
info!("rog-anime: animation sub-loop was asked to exit");
|
|
||||||
return Ok(true); // Do safe exit
|
|
||||||
}
|
|
||||||
inner
|
|
||||||
.try_lock()
|
|
||||||
.map(|lock| {
|
|
||||||
lock.write_data_buffer(frame)
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!(
|
|
||||||
"rog_anime::run_animation:callback {}",
|
|
||||||
err
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
false // Don't exit yet
|
|
||||||
})
|
|
||||||
.map_or_else(
|
|
||||||
|| {
|
|
||||||
warn!("rog_anime::run_animation:callback failed");
|
|
||||||
Err(AnimeError::NoFrames)
|
|
||||||
},
|
|
||||||
Ok,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
if thread_exit.load(Ordering::Acquire) {
|
|
||||||
info!("rog-anime: sub-loop exited and main loop exiting now");
|
|
||||||
break 'main;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ActionData::Image(image) => {
|
|
||||||
once = false;
|
|
||||||
if let Some(lock) = inner.try_lock() {
|
|
||||||
lock.write_data_buffer(image.as_ref().clone())
|
|
||||||
.map_err(|e| error!("{}", e))
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ActionData::Pause(duration) => sleep(*duration),
|
|
||||||
ActionData::AudioEq
|
|
||||||
| ActionData::SystemInfo
|
|
||||||
| ActionData::TimeDate
|
|
||||||
| ActionData::Matrix => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if thread_exit.load(Ordering::SeqCst) {
|
|
||||||
break 'main;
|
|
||||||
}
|
|
||||||
if once || actions.is_empty() {
|
|
||||||
break 'main;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Clear the display on exit
|
|
||||||
if let Some(lock) = inner.try_lock() {
|
|
||||||
if let Ok(data) =
|
|
||||||
AnimeDataBuffer::from_vec(anime_type, vec![0u8; anime_type.data_length()])
|
|
||||||
.map_err(|e| error!("{}", e))
|
|
||||||
{
|
|
||||||
lock.write_data_buffer(data)
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!("rog_anime::run_animation:callback {}", err);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
lock.node
|
|
||||||
.write_bytes(&pkt_set_enable_powersave_anim(
|
|
||||||
lock.config.builtin_anims_enabled,
|
|
||||||
))
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!("rog_anime::run_animation:callback {}", err);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
// Loop ended, set the atmonics
|
|
||||||
thread_running.store(false, Ordering::SeqCst);
|
|
||||||
info!("AniMe system thread exited");
|
|
||||||
})
|
|
||||||
.map(|err| info!("AniMe system thread: {:?}", err))
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write only a data packet. This will modify the leds brightness using the
|
|
||||||
/// global brightness set in config.
|
|
||||||
fn write_data_buffer(&self, mut buffer: AnimeDataBuffer) -> Result<(), RogError> {
|
|
||||||
for led in buffer.data_mut().iter_mut() {
|
|
||||||
let mut bright = *led as f32;
|
|
||||||
if bright > 254.0 {
|
|
||||||
bright = 254.0;
|
|
||||||
}
|
|
||||||
*led = bright as u8;
|
|
||||||
}
|
|
||||||
let data = AnimePacketType::try_from(buffer)?;
|
|
||||||
for row in &data {
|
|
||||||
self.node.write_bytes(row)?;
|
|
||||||
}
|
|
||||||
self.node.write_bytes(&pkt_flush())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn do_initialization(&self) -> Result<(), RogError> {
|
|
||||||
let pkts = pkts_for_init();
|
|
||||||
self.node.write_bytes(&pkts[0])?;
|
|
||||||
self.node.write_bytes(&pkts[1])?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,467 +0,0 @@
|
|||||||
use std::collections::{BTreeMap, HashSet};
|
|
||||||
|
|
||||||
use config_traits::{StdConfig, StdConfigLoad};
|
|
||||||
use dmi_id::DMIID;
|
|
||||||
use inotify::Inotify;
|
|
||||||
use log::{debug, info, warn};
|
|
||||||
use rog_aura::aura_detection::LedSupportData;
|
|
||||||
use rog_aura::keyboard::{LedUsbPackets, UsbPackets};
|
|
||||||
use rog_aura::usb::{LED_APPLY, LED_SET};
|
|
||||||
use rog_aura::{
|
|
||||||
AuraDeviceType, AuraEffect, Direction, LedBrightness, Speed, GRADIENT, LED_MSG_LEN,
|
|
||||||
};
|
|
||||||
use rog_platform::hid_raw::HidRaw;
|
|
||||||
use rog_platform::keyboard_led::KeyboardLed;
|
|
||||||
use zbus::zvariant::OwnedObjectPath;
|
|
||||||
|
|
||||||
use super::config::AuraConfig;
|
|
||||||
use crate::ctrl_aura::manager::{dbus_path_for_dev, dbus_path_for_tuf};
|
|
||||||
use crate::error::RogError;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum LEDNode {
|
|
||||||
/// Brightness and/or TUF RGB controls
|
|
||||||
KbdLed(KeyboardLed),
|
|
||||||
/// Raw HID handle
|
|
||||||
Rog(KeyboardLed, HidRaw),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LEDNode {
|
|
||||||
// TODO: move various methods upwards to this
|
|
||||||
pub fn set_brightness(&self, value: u8) -> Result<(), RogError> {
|
|
||||||
match self {
|
|
||||||
LEDNode::KbdLed(k) => k.set_brightness(value)?,
|
|
||||||
LEDNode::Rog(k, _) => k.set_brightness(value)?,
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_brightness(&self) -> Result<u8, RogError> {
|
|
||||||
Ok(match self {
|
|
||||||
LEDNode::KbdLed(k) => k.get_brightness()?,
|
|
||||||
LEDNode::Rog(k, _) => k.get_brightness()?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn monitor_brightness(&self) -> Result<Inotify, RogError> {
|
|
||||||
Ok(match self {
|
|
||||||
LEDNode::KbdLed(k) => k.monitor_brightness()?,
|
|
||||||
LEDNode::Rog(k, _) => k.monitor_brightness()?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Individual controller for one Aura device
|
|
||||||
pub struct CtrlKbdLed {
|
|
||||||
pub led_type: AuraDeviceType,
|
|
||||||
pub led_node: LEDNode,
|
|
||||||
pub supported_data: LedSupportData, // TODO: is storing this really required?
|
|
||||||
pub per_key_mode_active: bool,
|
|
||||||
pub config: AuraConfig,
|
|
||||||
pub dbus_path: OwnedObjectPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CtrlKbdLed {
|
|
||||||
pub fn find_all() -> Result<Vec<Self>, RogError> {
|
|
||||||
info!("Searching for all Aura devices");
|
|
||||||
let mut devices = Vec::new();
|
|
||||||
let mut found = HashSet::new(); // track and ensure we use only one hidraw per prod_id
|
|
||||||
|
|
||||||
let mut enumerator = udev::Enumerator::new().map_err(|err| {
|
|
||||||
warn!("{}", err);
|
|
||||||
err
|
|
||||||
})?;
|
|
||||||
|
|
||||||
enumerator.match_subsystem("hidraw").map_err(|err| {
|
|
||||||
warn!("{}", err);
|
|
||||||
err
|
|
||||||
})?;
|
|
||||||
|
|
||||||
for end_point in enumerator.scan_devices()? {
|
|
||||||
// usb_device gives us a product and vendor ID
|
|
||||||
if let Some(usb_device) =
|
|
||||||
end_point.parent_with_subsystem_devtype("usb", "usb_device")?
|
|
||||||
{
|
|
||||||
// The asus_wmi driver latches MCU that controls the USB endpoints
|
|
||||||
if let Some(parent) = end_point.parent() {
|
|
||||||
if let Some(driver) = parent.driver() {
|
|
||||||
// There is a tree of devices added so filter by driver
|
|
||||||
if driver != "asus" {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Device is something like 002, while its parent is the MCU
|
|
||||||
// Think of it like the device is an endpoint of the USB device attached
|
|
||||||
let mut prod_id = String::new();
|
|
||||||
if let Some(usb_id) = usb_device.attribute_value("idProduct") {
|
|
||||||
prod_id = usb_id.to_string_lossy().to_string();
|
|
||||||
let aura_dev = AuraDeviceType::from(prod_id.as_str());
|
|
||||||
if aura_dev == AuraDeviceType::Unknown || found.contains(&aura_dev) {
|
|
||||||
log::debug!("Unknown or invalid device: {usb_id:?}, skipping");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
found.insert(aura_dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
let dev_node = if let Some(dev_node) = usb_device.devnode() {
|
|
||||||
dev_node
|
|
||||||
} else {
|
|
||||||
debug!("Device has no devnode, skipping");
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
info!("AuraControl found device at: {:?}", dev_node);
|
|
||||||
let dbus_path = dbus_path_for_dev(&usb_device).unwrap_or_default();
|
|
||||||
let dev = HidRaw::from_device(end_point)?;
|
|
||||||
let mut dev = Self::from_hidraw(dev, dbus_path)?;
|
|
||||||
dev.config = Self::init_config(&prod_id);
|
|
||||||
devices.push(dev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for a TUF laptop LED. Assume there is only ever one.
|
|
||||||
if let Ok(kbd_backlight) = KeyboardLed::new() {
|
|
||||||
if kbd_backlight.has_kbd_rgb_mode() {
|
|
||||||
// Extra sure double-check that this isn't a laptop with crap
|
|
||||||
// ACPI with borked return on the TUF rgb methods
|
|
||||||
let dmi = DMIID::new().unwrap_or_default();
|
|
||||||
info!("Found a TUF with product family: {}", dmi.product_family);
|
|
||||||
info!("and board name: {}", dmi.board_name);
|
|
||||||
|
|
||||||
if dmi.product_family.contains("TUF") {
|
|
||||||
info!("AuraControl found a TUF laptop keyboard");
|
|
||||||
let ctrl = CtrlKbdLed {
|
|
||||||
led_type: AuraDeviceType::LaptopTuf,
|
|
||||||
led_node: LEDNode::KbdLed(kbd_backlight),
|
|
||||||
supported_data: LedSupportData::get_data("tuf"),
|
|
||||||
per_key_mode_active: false,
|
|
||||||
config: Self::init_config("tuf"),
|
|
||||||
dbus_path: dbus_path_for_tuf(),
|
|
||||||
};
|
|
||||||
devices.push(ctrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("Found {} Aura devices", devices.len());
|
|
||||||
|
|
||||||
Ok(devices)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The generated data from this function has a default config. This config
|
|
||||||
/// should be overwritten. The reason for the default config is because
|
|
||||||
/// of async issues between this and udev/hidraw
|
|
||||||
pub fn from_hidraw(device: HidRaw, dbus_path: OwnedObjectPath) -> Result<Self, RogError> {
|
|
||||||
let rgb_led = KeyboardLed::new()?;
|
|
||||||
let prod_id = AuraDeviceType::from(device.prod_id());
|
|
||||||
if prod_id == AuraDeviceType::Unknown {
|
|
||||||
log::error!("{} is AuraDevice::Unknown", device.prod_id());
|
|
||||||
return Err(RogError::NoAuraNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// New loads data from the DB also
|
|
||||||
// let config = Self::init_config(prod_id, data);
|
|
||||||
|
|
||||||
let data = LedSupportData::get_data(device.prod_id());
|
|
||||||
let ctrl = CtrlKbdLed {
|
|
||||||
led_type: prod_id,
|
|
||||||
led_node: LEDNode::Rog(rgb_led, device),
|
|
||||||
supported_data: data.clone(),
|
|
||||||
per_key_mode_active: false,
|
|
||||||
config: AuraConfig::default(),
|
|
||||||
dbus_path,
|
|
||||||
};
|
|
||||||
Ok(ctrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_config(prod_id: &str) -> AuraConfig {
|
|
||||||
// New loads data from the DB also
|
|
||||||
let mut config_init = AuraConfig::new(prod_id);
|
|
||||||
// config_init.set_filename(prod_id);
|
|
||||||
let mut config_loaded = config_init.clone().load();
|
|
||||||
// update the initialised data with what we loaded from disk
|
|
||||||
for mode in &mut config_init.builtins {
|
|
||||||
// update init values from loaded values if they exist
|
|
||||||
if let Some(loaded) = config_loaded.builtins.get(mode.0) {
|
|
||||||
*mode.1 = loaded.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Then replace just incase the initialised data contains new modes added
|
|
||||||
config_loaded.builtins = config_init.builtins;
|
|
||||||
|
|
||||||
if let (Some(mut multizone_init), Some(multizone_loaded)) =
|
|
||||||
(config_init.multizone, config_loaded.multizone.as_mut())
|
|
||||||
{
|
|
||||||
for mode in multizone_init.iter_mut() {
|
|
||||||
// update init values from loaded values if they exist
|
|
||||||
if let Some(loaded) = multizone_loaded.get(mode.0) {
|
|
||||||
let mut new_set = Vec::new();
|
|
||||||
let data = LedSupportData::get_data(prod_id);
|
|
||||||
// only reuse a zone mode if the mode is supported
|
|
||||||
for mode in loaded {
|
|
||||||
if data.basic_modes.contains(&mode.mode) {
|
|
||||||
new_set.push(mode.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*mode.1 = new_set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*multizone_loaded = multizone_init;
|
|
||||||
}
|
|
||||||
|
|
||||||
config_loaded
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set combination state for boot animation/sleep animation/all leds/keys
|
|
||||||
/// leds/side leds LED active
|
|
||||||
pub(super) fn set_power_states(&mut self) -> Result<(), RogError> {
|
|
||||||
if let LEDNode::KbdLed(_platform) = &mut self.led_node {
|
|
||||||
// TODO: tuf bool array
|
|
||||||
// if let Some(pwr) =
|
|
||||||
// AuraPowerConfig::to_tuf_bool_array(&self.config.enabled) {
|
|
||||||
// let buf = [1, pwr[1] as u8, pwr[2] as u8, pwr[3] as u8,
|
|
||||||
// pwr[4] as u8]; platform.set_kbd_rgb_state(&buf)?;
|
|
||||||
// }
|
|
||||||
} else if let LEDNode::Rog(_, hid_raw) = &self.led_node {
|
|
||||||
let bytes = self.config.enabled.to_bytes(self.led_type);
|
|
||||||
let message = [0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2], bytes[3]];
|
|
||||||
|
|
||||||
hid_raw.write_bytes(&message)?;
|
|
||||||
hid_raw.write_bytes(&LED_SET)?;
|
|
||||||
// Changes won't persist unless apply is set
|
|
||||||
hid_raw.write_bytes(&LED_APPLY)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write an effect block. This is for per-key, but can be repurposed to
|
|
||||||
/// write the raw factory mode packets - when doing this it is expected that
|
|
||||||
/// only the first `Vec` (`effect[0]`) is valid.
|
|
||||||
pub fn write_effect_block(&mut self, effect: &UsbPackets) -> Result<(), RogError> {
|
|
||||||
if self.config.brightness == LedBrightness::Off {
|
|
||||||
self.config.brightness = LedBrightness::Med;
|
|
||||||
self.config.write();
|
|
||||||
}
|
|
||||||
|
|
||||||
let pkt_type = effect[0][1];
|
|
||||||
const PER_KEY_TYPE: u8 = 0xbc;
|
|
||||||
|
|
||||||
if pkt_type != PER_KEY_TYPE {
|
|
||||||
self.per_key_mode_active = false;
|
|
||||||
if let LEDNode::Rog(_, hid_raw) = &self.led_node {
|
|
||||||
hid_raw.write_bytes(&effect[0])?;
|
|
||||||
hid_raw.write_bytes(&LED_SET)?;
|
|
||||||
// hid_raw.write_bytes(&LED_APPLY)?;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if !self.per_key_mode_active {
|
|
||||||
if let LEDNode::Rog(_, hid_raw) = &self.led_node {
|
|
||||||
let init = LedUsbPackets::get_init_msg();
|
|
||||||
hid_raw.write_bytes(&init)?;
|
|
||||||
}
|
|
||||||
self.per_key_mode_active = true;
|
|
||||||
}
|
|
||||||
if let LEDNode::Rog(_, hid_raw) = &self.led_node {
|
|
||||||
for row in effect.iter() {
|
|
||||||
hid_raw.write_bytes(row)?;
|
|
||||||
}
|
|
||||||
} else if let LEDNode::KbdLed(tuf) = &self.led_node {
|
|
||||||
for row in effect.iter() {
|
|
||||||
let r = row[9];
|
|
||||||
let g = row[10];
|
|
||||||
let b = row[11];
|
|
||||||
tuf.set_kbd_rgb_mode(&[0, 0, r, g, b, 0])?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_mode(&mut self, mode: &AuraEffect) -> Result<(), RogError> {
|
|
||||||
if let LEDNode::KbdLed(platform) = &self.led_node {
|
|
||||||
let buf = [
|
|
||||||
1,
|
|
||||||
mode.mode as u8,
|
|
||||||
mode.colour1.r,
|
|
||||||
mode.colour1.g,
|
|
||||||
mode.colour1.b,
|
|
||||||
mode.speed as u8,
|
|
||||||
];
|
|
||||||
platform.set_kbd_rgb_mode(&buf)?;
|
|
||||||
} else if let LEDNode::Rog(_, hid_raw) = &self.led_node {
|
|
||||||
let bytes: [u8; LED_MSG_LEN] = mode.into();
|
|
||||||
hid_raw.write_bytes(&bytes)?;
|
|
||||||
hid_raw.write_bytes(&LED_SET)?;
|
|
||||||
// Changes won't persist unless apply is set
|
|
||||||
hid_raw.write_bytes(&LED_APPLY)?;
|
|
||||||
} else {
|
|
||||||
return Err(RogError::NoAuraKeyboard);
|
|
||||||
}
|
|
||||||
self.per_key_mode_active = false;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn write_current_config_mode(&mut self) -> Result<(), RogError> {
|
|
||||||
if self.config.multizone_on {
|
|
||||||
let mode = self.config.current_mode;
|
|
||||||
let mut create = false;
|
|
||||||
// There is no multizone config for this mode so create one here
|
|
||||||
// using the colours of rainbow if it exists, or first available
|
|
||||||
// mode, or random
|
|
||||||
if self.config.multizone.is_none() {
|
|
||||||
create = true;
|
|
||||||
} else if let Some(multizones) = self.config.multizone.as_ref() {
|
|
||||||
if !multizones.contains_key(&mode) {
|
|
||||||
create = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if create {
|
|
||||||
info!("No user-set config for zone founding, attempting a default");
|
|
||||||
self.create_multizone_default()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(multizones) = self.config.multizone.as_mut() {
|
|
||||||
if let Some(set) = multizones.get(&mode) {
|
|
||||||
for mode in set.clone() {
|
|
||||||
self.write_mode(&mode)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let mode = self.config.current_mode;
|
|
||||||
if let Some(effect) = self.config.builtins.get(&mode).cloned() {
|
|
||||||
self.write_mode(&effect)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a default for the `current_mode` if multizone and no config
|
|
||||||
/// exists.
|
|
||||||
fn create_multizone_default(&mut self) -> Result<(), RogError> {
|
|
||||||
let mut default = vec![];
|
|
||||||
for (i, tmp) in self.supported_data.basic_zones.iter().enumerate() {
|
|
||||||
default.push(AuraEffect {
|
|
||||||
mode: self.config.current_mode,
|
|
||||||
zone: *tmp,
|
|
||||||
colour1: *GRADIENT.get(i).unwrap_or(&GRADIENT[0]),
|
|
||||||
colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]),
|
|
||||||
speed: Speed::Med,
|
|
||||||
direction: Direction::Left,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if default.is_empty() {
|
|
||||||
return Err(RogError::AuraEffectNotSupported);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(multizones) = self.config.multizone.as_mut() {
|
|
||||||
multizones.insert(self.config.current_mode, default);
|
|
||||||
} else {
|
|
||||||
let mut tmp = BTreeMap::new();
|
|
||||||
tmp.insert(self.config.current_mode, default);
|
|
||||||
self.config.multizone = Some(tmp);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use rog_aura::aura_detection::LedSupportData;
|
|
||||||
use rog_aura::{AuraDeviceType, AuraModeNum, AuraZone, PowerZones};
|
|
||||||
use rog_platform::hid_raw::HidRaw;
|
|
||||||
use rog_platform::keyboard_led::KeyboardLed;
|
|
||||||
use zbus::zvariant::OwnedObjectPath;
|
|
||||||
|
|
||||||
use super::CtrlKbdLed;
|
|
||||||
use crate::ctrl_aura::config::AuraConfig;
|
|
||||||
use crate::ctrl_aura::controller::LEDNode;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[ignore = "Unable to run in CI as the HIDRAW device is required"]
|
|
||||||
fn create_multizone_if_no_config() {
|
|
||||||
// Checking to ensure set_mode errors when unsupported modes are tried
|
|
||||||
let config = AuraConfig::new("19b6");
|
|
||||||
let supported_basic_modes = LedSupportData {
|
|
||||||
device_name: String::new(),
|
|
||||||
product_id: String::new(),
|
|
||||||
layout_name: "ga401".to_owned(),
|
|
||||||
basic_modes: vec![AuraModeNum::Static],
|
|
||||||
basic_zones: vec![],
|
|
||||||
advanced_type: rog_aura::keyboard::AdvancedAuraType::None,
|
|
||||||
power_zones: vec![PowerZones::Keyboard, PowerZones::RearGlow],
|
|
||||||
};
|
|
||||||
let mut controller = CtrlKbdLed {
|
|
||||||
led_type: AuraDeviceType::LaptopPost2021,
|
|
||||||
led_node: LEDNode::Rog(KeyboardLed::default(), HidRaw::new("19b6").unwrap()),
|
|
||||||
supported_data: supported_basic_modes,
|
|
||||||
per_key_mode_active: false,
|
|
||||||
config,
|
|
||||||
dbus_path: OwnedObjectPath::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
assert!(controller.config.multizone.is_none());
|
|
||||||
assert!(controller.create_multizone_default().is_err());
|
|
||||||
assert!(controller.config.multizone.is_none());
|
|
||||||
|
|
||||||
controller.supported_data.basic_zones.push(AuraZone::Key1);
|
|
||||||
controller.supported_data.basic_zones.push(AuraZone::Key2);
|
|
||||||
assert!(controller.create_multizone_default().is_ok());
|
|
||||||
assert!(controller.config.multizone.is_some());
|
|
||||||
|
|
||||||
let m = controller.config.multizone.unwrap();
|
|
||||||
assert!(m.contains_key(&AuraModeNum::Static));
|
|
||||||
let e = m.get(&AuraModeNum::Static).unwrap();
|
|
||||||
assert_eq!(e.len(), 2);
|
|
||||||
assert_eq!(e[0].zone, AuraZone::Key1);
|
|
||||||
assert_eq!(e[1].zone, AuraZone::Key2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[ignore = "Unable to run in CI as the HIDRAW device is required"]
|
|
||||||
// TODO: use sim device
|
|
||||||
fn next_mode_create_multizone_if_no_config() {
|
|
||||||
// Checking to ensure set_mode errors when unsupported modes are tried
|
|
||||||
let config = AuraConfig::new("19b6");
|
|
||||||
let supported_basic_modes = LedSupportData {
|
|
||||||
device_name: String::new(),
|
|
||||||
product_id: String::new(),
|
|
||||||
layout_name: "ga401".to_owned(),
|
|
||||||
basic_modes: vec![AuraModeNum::Static],
|
|
||||||
basic_zones: vec![AuraZone::Key1, AuraZone::Key2],
|
|
||||||
advanced_type: rog_aura::keyboard::AdvancedAuraType::None,
|
|
||||||
power_zones: vec![PowerZones::Keyboard, PowerZones::RearGlow],
|
|
||||||
};
|
|
||||||
let mut controller = CtrlKbdLed {
|
|
||||||
led_type: AuraDeviceType::LaptopPost2021,
|
|
||||||
led_node: LEDNode::Rog(KeyboardLed::default(), HidRaw::new("19b6").unwrap()),
|
|
||||||
supported_data: supported_basic_modes,
|
|
||||||
per_key_mode_active: false,
|
|
||||||
config,
|
|
||||||
dbus_path: OwnedObjectPath::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
assert!(controller.config.multizone.is_none());
|
|
||||||
controller.config.multizone_on = true;
|
|
||||||
// This is called in toggle_mode. It will error here because we have no
|
|
||||||
// keyboard node in tests.
|
|
||||||
assert_eq!(
|
|
||||||
controller
|
|
||||||
.write_current_config_mode()
|
|
||||||
.unwrap_err()
|
|
||||||
.to_string(),
|
|
||||||
"No supported Aura keyboard"
|
|
||||||
);
|
|
||||||
assert!(controller.config.multizone.is_some());
|
|
||||||
|
|
||||||
let m = controller.config.multizone.unwrap();
|
|
||||||
assert!(m.contains_key(&AuraModeNum::Static));
|
|
||||||
let e = m.get(&AuraModeNum::Static).unwrap();
|
|
||||||
assert_eq!(e.len(), 2);
|
|
||||||
assert_eq!(e[0].zone, AuraZone::Key1);
|
|
||||||
assert_eq!(e[1].zone, AuraZone::Key2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
// Plan:
|
|
||||||
// - Manager has udev monitor on USB looking for ROG devices
|
|
||||||
// - If a device is found, add it to watch
|
|
||||||
// - Add it to Zbus server
|
|
||||||
// - If udev sees device removed then remove the zbus path
|
|
||||||
|
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use log::{debug, error, info, warn};
|
|
||||||
use mio::{Events, Interest, Poll, Token};
|
|
||||||
use rog_aura::AuraDeviceType;
|
|
||||||
use rog_platform::hid_raw::HidRaw;
|
|
||||||
use tokio::task::spawn_blocking;
|
|
||||||
use udev::{Device, MonitorBuilder};
|
|
||||||
use zbus::object_server::SignalContext;
|
|
||||||
use zbus::zvariant::{ObjectPath, OwnedObjectPath};
|
|
||||||
use zbus::Connection;
|
|
||||||
|
|
||||||
use crate::ctrl_aura::controller::CtrlKbdLed;
|
|
||||||
use crate::ctrl_aura::trait_impls::{CtrlAuraZbus, AURA_ZBUS_PATH};
|
|
||||||
use crate::error::RogError;
|
|
||||||
use crate::{CtrlTask, Reloadable};
|
|
||||||
|
|
||||||
pub struct AuraManager {
|
|
||||||
_connection: Connection,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AuraManager {
|
|
||||||
pub async fn new(connection: Connection) -> Result<Self, RogError> {
|
|
||||||
let conn_copy = connection.clone();
|
|
||||||
let mut interfaces = HashSet::new();
|
|
||||||
|
|
||||||
// Do the initial keyboard detection:
|
|
||||||
let all = CtrlKbdLed::find_all()?;
|
|
||||||
for ctrl in all {
|
|
||||||
let path = ctrl.dbus_path.clone();
|
|
||||||
interfaces.insert(path.clone()); // ensure we record the initial stuff
|
|
||||||
let sig_ctx = CtrlAuraZbus::signal_context(&connection)?;
|
|
||||||
let sig_ctx2 = sig_ctx.clone();
|
|
||||||
let zbus = CtrlAuraZbus::new(ctrl, sig_ctx);
|
|
||||||
start_tasks(zbus, connection.clone(), sig_ctx2, path).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let manager = Self {
|
|
||||||
_connection: connection,
|
|
||||||
};
|
|
||||||
|
|
||||||
// detect all plugged in aura devices (eventually)
|
|
||||||
// only USB devices are detected for here
|
|
||||||
spawn_blocking(move || {
|
|
||||||
let mut monitor = MonitorBuilder::new()?.match_subsystem("hidraw")?.listen()?;
|
|
||||||
let mut poll = Poll::new()?;
|
|
||||||
let mut events = Events::with_capacity(1024);
|
|
||||||
poll.registry()
|
|
||||||
.register(&mut monitor, Token(0), Interest::READABLE)?;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if poll.poll(&mut events, None).is_err() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for event in monitor.iter() {
|
|
||||||
let parent = if let Some(parent) =
|
|
||||||
event.parent_with_subsystem_devtype("usb", "usb_device")?
|
|
||||||
{
|
|
||||||
parent
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let action = if let Some(action) = event.action() {
|
|
||||||
action
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let id_product = if let Some(id_product) = parent.attribute_value("idProduct") {
|
|
||||||
id_product.to_string_lossy()
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let path = if let Some(path) = dbus_path_for_dev(&parent) {
|
|
||||||
path
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let aura_device = AuraDeviceType::from(&*id_product);
|
|
||||||
if aura_device == AuraDeviceType::Unknown {
|
|
||||||
warn!("idProduct:{id_product:?} is unknown, not using");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if action == "remove" {
|
|
||||||
if interfaces.remove(&path) {
|
|
||||||
info!("AuraManager removing: {path:?}");
|
|
||||||
let conn_copy = conn_copy.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
let res = conn_copy
|
|
||||||
.object_server()
|
|
||||||
.remove::<CtrlAuraZbus, _>(&path)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("Failed to remove {path:?}, {e:?}");
|
|
||||||
e
|
|
||||||
})?;
|
|
||||||
info!("AuraManager removed: {path:?}, {res}");
|
|
||||||
Ok::<(), RogError>(())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if action == "add" {
|
|
||||||
if interfaces.contains(&path) {
|
|
||||||
debug!("Already a ctrl at {path:?}");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Need to check the driver is asus to prevent using hid_generic
|
|
||||||
if let Some(p2) = event.parent() {
|
|
||||||
if let Some(driver) = p2.driver() {
|
|
||||||
// There is a tree of devices added so filter by driver
|
|
||||||
if driver != "asus" {
|
|
||||||
debug!("{id_product:?} driver was not asus, skipping");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(dev_node) = event.devnode() {
|
|
||||||
if let Ok(raw) = HidRaw::from_device(event.device())
|
|
||||||
.map_err(|e| error!("device path error: {e:?}"))
|
|
||||||
{
|
|
||||||
if let Ok(mut ctrl) = CtrlKbdLed::from_hidraw(raw, path.clone()) {
|
|
||||||
ctrl.config = CtrlKbdLed::init_config(&id_product);
|
|
||||||
interfaces.insert(path.clone());
|
|
||||||
info!("AuraManager starting device at: {dev_node:?}, {path:?}");
|
|
||||||
let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?;
|
|
||||||
let zbus = CtrlAuraZbus::new(ctrl, sig_ctx);
|
|
||||||
let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?;
|
|
||||||
let conn_copy = conn_copy.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
start_tasks(zbus, conn_copy.clone(), sig_ctx, path).await
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Required for return type on spawn
|
|
||||||
#[allow(unreachable_code)]
|
|
||||||
Ok::<(), RogError>(())
|
|
||||||
});
|
|
||||||
Ok(manager)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn dbus_path_for_dev(parent: &Device) -> Option<OwnedObjectPath> {
|
|
||||||
if let Some(filename) = super::filename_partial(parent) {
|
|
||||||
return Some(
|
|
||||||
ObjectPath::from_str_unchecked(&format!("{AURA_ZBUS_PATH}/{filename}")).into(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn dbus_path_for_tuf() -> OwnedObjectPath {
|
|
||||||
ObjectPath::from_str_unchecked(&format!("{AURA_ZBUS_PATH}/tuf")).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn start_tasks(
|
|
||||||
mut zbus: CtrlAuraZbus,
|
|
||||||
connection: Connection,
|
|
||||||
_signal_ctx: SignalContext<'static>,
|
|
||||||
path: OwnedObjectPath,
|
|
||||||
) -> Result<(), RogError> {
|
|
||||||
// let task = zbus.clone();
|
|
||||||
// let signal_ctx = signal_ctx.clone();
|
|
||||||
zbus.reload()
|
|
||||||
.await
|
|
||||||
.unwrap_or_else(|err| warn!("Controller error: {}", err));
|
|
||||||
connection.object_server().at(path, zbus).await.unwrap();
|
|
||||||
// TODO: skip this until we keep handles to tasks so they can be killed
|
|
||||||
// task.create_tasks(signal_ctx).await
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
use udev::Device;
|
|
||||||
use zbus::zvariant::{ObjectPath, OwnedObjectPath};
|
|
||||||
|
|
||||||
pub mod config;
|
|
||||||
pub mod controller;
|
|
||||||
pub mod manager;
|
|
||||||
/// Implements `CtrlTask`, `Reloadable`, `ZbusRun`
|
|
||||||
pub mod trait_impls;
|
|
||||||
|
|
||||||
/// Returns only the Device details concatenated in a form usable for
|
|
||||||
/// adding/appending to a filename
|
|
||||||
pub(super) fn filename_partial(parent: &Device) -> Option<OwnedObjectPath> {
|
|
||||||
if let Some(id_product) = parent.attribute_value("idProduct") {
|
|
||||||
let id_product = id_product.to_string_lossy();
|
|
||||||
let path = if let Some(devnum) = parent.attribute_value("devnum") {
|
|
||||||
let devnum = devnum.to_string_lossy();
|
|
||||||
if let Some(devpath) = parent.attribute_value("devpath") {
|
|
||||||
let devpath = devpath.to_string_lossy();
|
|
||||||
format!("{id_product}_{devnum}_{devpath}")
|
|
||||||
} else {
|
|
||||||
format!("{id_product}_{devnum}")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
format!("{id_product}")
|
|
||||||
};
|
|
||||||
return Some(ObjectPath::from_str_unchecked(&path).into());
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
@@ -1,295 +0,0 @@
|
|||||||
use std::collections::BTreeMap;
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use config_traits::StdConfig;
|
|
||||||
use log::{debug, error, info, warn};
|
|
||||||
use rog_aura::keyboard::{LaptopAuraPower, UsbPackets};
|
|
||||||
use rog_aura::{AuraDeviceType, AuraEffect, AuraModeNum, AuraZone, LedBrightness, PowerZones};
|
|
||||||
use zbus::export::futures_util::lock::{Mutex, MutexGuard};
|
|
||||||
use zbus::export::futures_util::StreamExt;
|
|
||||||
use zbus::fdo::Error as ZbErr;
|
|
||||||
use zbus::{interface, SignalContext};
|
|
||||||
|
|
||||||
use super::controller::CtrlKbdLed;
|
|
||||||
use crate::error::RogError;
|
|
||||||
use crate::CtrlTask;
|
|
||||||
|
|
||||||
pub const AURA_ZBUS_NAME: &str = "Aura";
|
|
||||||
pub const AURA_ZBUS_PATH: &str = "/org/asuslinux";
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct CtrlAuraZbus(Arc<Mutex<CtrlKbdLed>>, SignalContext<'static>);
|
|
||||||
|
|
||||||
impl CtrlAuraZbus {
|
|
||||||
pub fn new(controller: CtrlKbdLed, signal: SignalContext<'static>) -> Self {
|
|
||||||
Self(Arc::new(Mutex::new(controller)), signal)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_config(lock: &mut CtrlKbdLed) -> Result<(), RogError> {
|
|
||||||
let bright = lock.led_node.get_brightness()?;
|
|
||||||
lock.config.read();
|
|
||||||
lock.config.brightness = bright.into();
|
|
||||||
lock.config.write();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The main interface for changing, reading, or notfying
|
|
||||||
///
|
|
||||||
/// LED commands are split between Brightness, Modes, Per-Key
|
|
||||||
#[interface(name = "org.asuslinux.Aura")]
|
|
||||||
impl CtrlAuraZbus {
|
|
||||||
/// Return the device type for this Aura keyboard
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn device_type(&self) -> AuraDeviceType {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
ctrl.led_type
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the current LED brightness
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn brightness(&self) -> Result<LedBrightness, ZbErr> {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
Ok(ctrl.led_node.get_brightness().map(|n| n.into())?)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the keyboard brightness level (0-3)
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn set_brightness(&mut self, brightness: LedBrightness) -> Result<(), ZbErr> {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
Ok(ctrl.led_node.set_brightness(brightness.into())?)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Total levels of brightness available
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn supported_brightness(&self) -> Vec<LedBrightness> {
|
|
||||||
vec![
|
|
||||||
LedBrightness::Off,
|
|
||||||
LedBrightness::Low,
|
|
||||||
LedBrightness::Med,
|
|
||||||
LedBrightness::High,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The total available modes
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn supported_basic_modes(&self) -> Result<Vec<AuraModeNum>, ZbErr> {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
Ok(ctrl.config.builtins.keys().cloned().collect())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn supported_basic_zones(&self) -> Result<Vec<AuraZone>, ZbErr> {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
Ok(ctrl.supported_data.basic_zones.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn supported_power_zones(&self) -> Result<Vec<PowerZones>, ZbErr> {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
Ok(ctrl.supported_data.power_zones.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The current mode data
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn led_mode(&self) -> Result<AuraModeNum, ZbErr> {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
Ok(ctrl.config.current_mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set an Aura effect if the effect mode or zone is supported.
|
|
||||||
///
|
|
||||||
/// On success the aura config file is read to refresh cached values, then
|
|
||||||
/// the effect is stored and config written to disk.
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn set_led_mode(&mut self, num: AuraModeNum) -> Result<(), ZbErr> {
|
|
||||||
let mut ctrl = self.0.lock().await;
|
|
||||||
ctrl.config.current_mode = num;
|
|
||||||
ctrl.write_current_config_mode()?;
|
|
||||||
if ctrl.config.brightness == LedBrightness::Off {
|
|
||||||
ctrl.config.brightness = LedBrightness::Med;
|
|
||||||
}
|
|
||||||
ctrl.led_node
|
|
||||||
.set_brightness(ctrl.config.brightness.into())?;
|
|
||||||
ctrl.config.write();
|
|
||||||
|
|
||||||
self.led_mode_data_invalidate(&self.1).await.ok();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The current mode data
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn led_mode_data(&self) -> Result<AuraEffect, ZbErr> {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
let mode = ctrl.config.current_mode;
|
|
||||||
match ctrl.config.builtins.get(&mode) {
|
|
||||||
Some(effect) => Ok(effect.clone()),
|
|
||||||
None => Err(ZbErr::Failed("Could not get the current effect".into())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set an Aura effect if the effect mode or zone is supported.
|
|
||||||
///
|
|
||||||
/// On success the aura config file is read to refresh cached values, then
|
|
||||||
/// the effect is stored and config written to disk.
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn set_led_mode_data(&mut self, effect: AuraEffect) -> Result<(), ZbErr> {
|
|
||||||
let mut ctrl = self.0.lock().await;
|
|
||||||
if !ctrl.supported_data.basic_modes.contains(&effect.mode)
|
|
||||||
|| effect.zone != AuraZone::None
|
|
||||||
&& !ctrl.supported_data.basic_zones.contains(&effect.zone)
|
|
||||||
{
|
|
||||||
return Err(ZbErr::NotSupported(format!(
|
|
||||||
"The Aura effect is not supported: {effect:?}"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ctrl.write_mode(&effect)?;
|
|
||||||
if ctrl.config.brightness == LedBrightness::Off {
|
|
||||||
ctrl.config.brightness = LedBrightness::Med;
|
|
||||||
}
|
|
||||||
ctrl.led_node
|
|
||||||
.set_brightness(ctrl.config.brightness.into())?;
|
|
||||||
ctrl.config.set_builtin(effect);
|
|
||||||
ctrl.config.write();
|
|
||||||
|
|
||||||
self.led_mode_invalidate(&self.1).await.ok();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the data set for every mode available
|
|
||||||
async fn all_mode_data(&self) -> BTreeMap<AuraModeNum, AuraEffect> {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
ctrl.config.builtins.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
// As property doesn't work for AuraPowerDev (complexity of serialization?)
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn led_power(&self) -> LaptopAuraPower {
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
ctrl.config.enabled.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set a variety of states, input is array of enum.
|
|
||||||
/// `enabled` sets if the sent array should be disabled or enabled
|
|
||||||
///
|
|
||||||
/// For Modern ROG devices the "enabled" flag is ignored.
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn set_led_power(&mut self, options: LaptopAuraPower) -> Result<(), ZbErr> {
|
|
||||||
let mut ctrl = self.0.lock().await;
|
|
||||||
for opt in options.states {
|
|
||||||
let zone = opt.zone;
|
|
||||||
for config in ctrl.config.enabled.states.iter_mut() {
|
|
||||||
if config.zone == zone {
|
|
||||||
*config = opt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ctrl.config.write();
|
|
||||||
Ok(ctrl.set_power_states().map_err(|e| {
|
|
||||||
warn!("{}", e);
|
|
||||||
e
|
|
||||||
})?)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// On machine that have some form of either per-key keyboard or per-zone
|
|
||||||
/// this can be used to write custom effects over dbus. The input is a
|
|
||||||
/// nested `Vec<Vec<8>>` where `Vec<u8>` is a raw USB packet
|
|
||||||
async fn direct_addressing_raw(&self, data: UsbPackets) -> Result<(), ZbErr> {
|
|
||||||
let mut ctrl = self.0.lock().await;
|
|
||||||
ctrl.write_effect_block(&data)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CtrlTask for CtrlAuraZbus {
|
|
||||||
fn zbus_path() -> &'static str {
|
|
||||||
"/org/asuslinux"
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn create_tasks(&self, _: SignalContext<'static>) -> Result<(), RogError> {
|
|
||||||
let load_save =
|
|
||||||
|start: bool, mut lock: MutexGuard<'_, CtrlKbdLed>| -> Result<(), RogError> {
|
|
||||||
// If waking up
|
|
||||||
if !start {
|
|
||||||
info!("CtrlKbdLedTask reloading brightness and modes");
|
|
||||||
lock.led_node
|
|
||||||
.set_brightness(lock.config.brightness.into())
|
|
||||||
.map_err(|e| {
|
|
||||||
error!("CtrlKbdLedTask: {e}");
|
|
||||||
e
|
|
||||||
})?;
|
|
||||||
lock.write_current_config_mode().map_err(|e| {
|
|
||||||
error!("CtrlKbdLedTask: {e}");
|
|
||||||
e
|
|
||||||
})?;
|
|
||||||
} else if start {
|
|
||||||
Self::update_config(&mut lock).map_err(|e| {
|
|
||||||
error!("CtrlKbdLedTask: {e}");
|
|
||||||
e
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
};
|
|
||||||
|
|
||||||
let inner1 = self.0.clone();
|
|
||||||
let inner3 = self.0.clone();
|
|
||||||
self.create_sys_event_tasks(
|
|
||||||
move |sleeping| {
|
|
||||||
let inner1 = inner1.clone();
|
|
||||||
async move {
|
|
||||||
let lock = inner1.lock().await;
|
|
||||||
load_save(sleeping, lock).unwrap(); // unwrap as we want to
|
|
||||||
// bomb out of the task
|
|
||||||
}
|
|
||||||
},
|
|
||||||
move |_shutting_down| {
|
|
||||||
let inner3 = inner3.clone();
|
|
||||||
async move {
|
|
||||||
let lock = inner3.lock().await;
|
|
||||||
load_save(false, lock).unwrap(); // unwrap as we want to
|
|
||||||
// bomb out of the task
|
|
||||||
}
|
|
||||||
},
|
|
||||||
move |_lid_closed| {
|
|
||||||
// on lid change
|
|
||||||
async move {}
|
|
||||||
},
|
|
||||||
move |_power_plugged| {
|
|
||||||
// power change
|
|
||||||
async move {}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let ctrl2 = self.0.clone();
|
|
||||||
let ctrl = self.0.lock().await;
|
|
||||||
let watch = ctrl.led_node.monitor_brightness()?;
|
|
||||||
tokio::spawn(async move {
|
|
||||||
let mut buffer = [0; 32];
|
|
||||||
watch
|
|
||||||
.into_event_stream(&mut buffer)
|
|
||||||
.unwrap()
|
|
||||||
.for_each(|_| async {
|
|
||||||
if let Some(lock) = ctrl2.try_lock() {
|
|
||||||
load_save(true, lock).unwrap(); // unwrap as we want to
|
|
||||||
// bomb out of the task
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl crate::Reloadable for CtrlAuraZbus {
|
|
||||||
async fn reload(&mut self) -> Result<(), RogError> {
|
|
||||||
let mut ctrl = self.0.lock().await;
|
|
||||||
debug!("reloading keyboard mode");
|
|
||||||
ctrl.write_current_config_mode()?;
|
|
||||||
debug!("reloading power states");
|
|
||||||
ctrl.set_power_states().map_err(|err| warn!("{err}")).ok();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
348
asusd/src/ctrl_backlight.rs
Normal file
348
asusd/src/ctrl_backlight.rs
Normal file
@@ -0,0 +1,348 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use config_traits::StdConfig;
|
||||||
|
use log::{info, warn};
|
||||||
|
use rog_platform::backlight::{Backlight, BacklightType};
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
use zbus::fdo::Error as FdoErr;
|
||||||
|
use zbus::object_server::SignalEmitter;
|
||||||
|
use zbus::{interface, Connection};
|
||||||
|
|
||||||
|
use crate::config::Config;
|
||||||
|
use crate::error::RogError;
|
||||||
|
use crate::ASUS_ZBUS_PATH;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct CtrlBacklight {
|
||||||
|
backlights: Vec<Backlight>,
|
||||||
|
config: Arc<Mutex<Config>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CtrlBacklight {
|
||||||
|
pub fn new(config: Arc<Mutex<Config>>) -> Result<Self, RogError> {
|
||||||
|
let mut backlights = Vec::new();
|
||||||
|
|
||||||
|
if let Ok(primary) = Backlight::new(BacklightType::Primary) {
|
||||||
|
info!("Found primary display backlight");
|
||||||
|
backlights.push(primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(screenpad) = Backlight::new(BacklightType::Screenpad) {
|
||||||
|
info!("Found screenpad backlight");
|
||||||
|
backlights.push(screenpad);
|
||||||
|
}
|
||||||
|
|
||||||
|
if backlights.is_empty() {
|
||||||
|
return Err(RogError::MissingFunction("No backlights found".into()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Self { backlights, config })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_backlight(&self, device_type: &BacklightType) -> Option<&Backlight> {
|
||||||
|
self.backlights
|
||||||
|
.iter()
|
||||||
|
.find(|b| b.device_type() == device_type)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn set_brightness_with_sync(
|
||||||
|
&self,
|
||||||
|
device_type: &BacklightType,
|
||||||
|
level: i32,
|
||||||
|
) -> Result<(), FdoErr> {
|
||||||
|
let sync = self
|
||||||
|
.config
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.screenpad_sync_primary
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
// If sync is enabled and we're setting screenpad brightness, set primary first
|
||||||
|
if sync && *device_type == BacklightType::Screenpad {
|
||||||
|
if let Some(primary) = self.get_backlight(&BacklightType::Primary) {
|
||||||
|
if let Ok(primary_max) = primary.get_max_brightness() {
|
||||||
|
let primary_scaled = level * primary_max / 100;
|
||||||
|
let _ = primary.set_brightness(primary_scaled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(backlight) = self.get_backlight(device_type) {
|
||||||
|
let max = backlight.get_max_brightness().map_err(|e| {
|
||||||
|
warn!("Failed to get max brightness: {}", e);
|
||||||
|
FdoErr::Failed(format!("Failed to get max brightness: {}", e))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let gamma = self.config.lock().await.screenpad_gamma.unwrap_or(1.0);
|
||||||
|
let scaled = if *device_type == BacklightType::Screenpad {
|
||||||
|
// Apply non-linear scaling with the configurable gamma value only for Screenpad
|
||||||
|
let normalized_level = level as f32 / 100.0;
|
||||||
|
let gamma_corrected = normalized_level.powf(gamma);
|
||||||
|
(gamma_corrected * max as f32) as i32
|
||||||
|
} else {
|
||||||
|
// Linear scaling for other devices
|
||||||
|
level * max / 100
|
||||||
|
};
|
||||||
|
|
||||||
|
backlight.set_brightness(scaled).map_err(|e| {
|
||||||
|
warn!("Failed to set brightness: {}", e);
|
||||||
|
FdoErr::Failed(format!("Failed to set brightness: {}", e))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// If sync is enabled and we're setting primary brightness, set screenpad
|
||||||
|
// afterward
|
||||||
|
if sync && *device_type == BacklightType::Primary {
|
||||||
|
for other in self
|
||||||
|
.backlights
|
||||||
|
.iter()
|
||||||
|
.filter(|b| b.device_type() != device_type)
|
||||||
|
{
|
||||||
|
if let Ok(other_max) = other.get_max_brightness() {
|
||||||
|
let other_scaled = if other.device_type() == &BacklightType::Screenpad {
|
||||||
|
// Apply gamma only to Screenpad
|
||||||
|
let normalized_level = level as f32 / 100.0;
|
||||||
|
let gamma_corrected = normalized_level.powf(gamma);
|
||||||
|
(gamma_corrected * other_max as f32) as i32
|
||||||
|
} else {
|
||||||
|
// Linear scaling for other devices
|
||||||
|
level * other_max / 100
|
||||||
|
};
|
||||||
|
let _ = other.set_brightness(other_scaled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(FdoErr::NotSupported(format!(
|
||||||
|
"Backlight {:?} not found",
|
||||||
|
device_type
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_brightness_percent(&self, device_type: &BacklightType) -> Result<i32, FdoErr> {
|
||||||
|
if let Some(backlight) = self.get_backlight(device_type) {
|
||||||
|
let brightness = backlight.get_brightness().map_err(|e| {
|
||||||
|
warn!("Failed to get brightness: {}", e);
|
||||||
|
FdoErr::Failed(format!("Failed to get brightness: {}", e))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let max = backlight.get_max_brightness().map_err(|e| {
|
||||||
|
warn!("Failed to get max brightness: {}", e);
|
||||||
|
FdoErr::Failed(format!("Failed to get max brightness: {}", e))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if *device_type == BacklightType::Screenpad {
|
||||||
|
let gamma = self.config.lock().await.screenpad_gamma.unwrap_or(1.0);
|
||||||
|
let normalized = brightness as f32 / max as f32;
|
||||||
|
let corrected = normalized.powf(1.0 / gamma);
|
||||||
|
Ok((corrected * 100.0).round() as i32)
|
||||||
|
} else {
|
||||||
|
Ok(brightness * 100 / max)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(FdoErr::NotSupported(format!(
|
||||||
|
"Backlight {:?} not found",
|
||||||
|
device_type
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start_watch_primary(&self) -> Result<(), RogError> {
|
||||||
|
if self.get_backlight(&BacklightType::Screenpad).is_none() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(sync) = self.config.lock().await.screenpad_sync_primary {
|
||||||
|
if !sync {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(backlight) = self.get_backlight(&BacklightType::Primary) {
|
||||||
|
let watch = backlight.monitor_brightness()?;
|
||||||
|
|
||||||
|
let backlights = self.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let mut last_level = 0;
|
||||||
|
let mut buffer = [0; 32];
|
||||||
|
use futures_lite::StreamExt;
|
||||||
|
if let Ok(mut stream) = watch.into_event_stream(&mut buffer) {
|
||||||
|
loop {
|
||||||
|
let _ = stream.next().await;
|
||||||
|
|
||||||
|
let sync = backlights.config.lock().await.screenpad_sync_primary;
|
||||||
|
if let Some(sync) = sync {
|
||||||
|
if !sync {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if backlights
|
||||||
|
.config
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.screenpad_sync_primary
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let level = backlights
|
||||||
|
.get_brightness_percent(&BacklightType::Primary)
|
||||||
|
.await
|
||||||
|
.unwrap_or(60);
|
||||||
|
if last_level != level {
|
||||||
|
last_level = level;
|
||||||
|
backlights
|
||||||
|
.set_brightness_with_sync(&BacklightType::Screenpad, level)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// other processes cause "MODIFY" event and make this spin 100%, so sleep
|
||||||
|
tokio::time::sleep(Duration::from_millis(300)).await;
|
||||||
|
}
|
||||||
|
// watch
|
||||||
|
// .into_event_stream(&mut buffer)
|
||||||
|
// .unwrap()
|
||||||
|
// .for_each(|_| async {})
|
||||||
|
// .await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[interface(name = "xyz.ljones.Backlight")]
|
||||||
|
impl CtrlBacklight {
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn screenpad_sync_with_primary(&self) -> bool {
|
||||||
|
self.config
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.screenpad_sync_primary
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_screenpad_sync_with_primary(&self, sync: bool) -> Result<(), zbus::Error> {
|
||||||
|
self.config.lock().await.screenpad_sync_primary = Some(sync);
|
||||||
|
self.config.lock().await.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn screenpad_gamma(&self) -> String {
|
||||||
|
(self.config.lock().await.screenpad_gamma.unwrap_or(1.0)).to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_screenpad_gamma(&self, value: &str) -> Result<(), zbus::Error> {
|
||||||
|
let gamma: f32 = value
|
||||||
|
.parse()
|
||||||
|
.map_err(|_| FdoErr::Failed("Invalid gamma value, must be a valid number".into()))?;
|
||||||
|
|
||||||
|
if gamma < 0.1 {
|
||||||
|
return Err(FdoErr::Failed("Gamma value must be greater than 0".into()).into());
|
||||||
|
}
|
||||||
|
if gamma > 2.0 {
|
||||||
|
return Err(FdoErr::Failed("Gamma value must be 2.0 or less".into()).into());
|
||||||
|
}
|
||||||
|
self.config.lock().await.screenpad_gamma = Some(gamma);
|
||||||
|
self.config.lock().await.write();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn primary_brightness(&self) -> Result<i32, FdoErr> {
|
||||||
|
self.get_brightness_percent(&BacklightType::Primary).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_primary_brightness(
|
||||||
|
&self,
|
||||||
|
#[zbus(signal_context)] ctxt: SignalEmitter<'_>,
|
||||||
|
level: i32,
|
||||||
|
) -> Result<(), zbus::Error> {
|
||||||
|
if level > 100 {
|
||||||
|
return Err(FdoErr::Failed("Brightness level must be 0-100".into()).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
self.set_brightness_with_sync(&BacklightType::Primary, level)
|
||||||
|
.await?;
|
||||||
|
self.primary_brightness_changed(&ctxt).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn screenpad_brightness(&self) -> Result<i32, FdoErr> {
|
||||||
|
self.get_brightness_percent(&BacklightType::Screenpad).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_screenpad_brightness(
|
||||||
|
&self,
|
||||||
|
// #[zbus(signal_context)] ctxt: SignalEmitter<'_>,
|
||||||
|
level: i32,
|
||||||
|
) -> Result<(), zbus::Error> {
|
||||||
|
if level > 100 {
|
||||||
|
return Err(FdoErr::Failed("Brightness level must be 0-100".into()).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
self.set_brightness_with_sync(&BacklightType::Screenpad, level)
|
||||||
|
.await?;
|
||||||
|
// self.screenpad_brightness_changed(&ctxt).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn screenpad_power(&self) -> Result<bool, FdoErr> {
|
||||||
|
if let Some(backlight) = self.get_backlight(&BacklightType::Screenpad) {
|
||||||
|
let power = backlight.get_bl_power().map_err(|e| {
|
||||||
|
warn!("Failed to get backlight power: {}", e);
|
||||||
|
FdoErr::Failed(format!("Failed to get backlight power: {}", e))
|
||||||
|
})?;
|
||||||
|
Ok(power == 0)
|
||||||
|
} else {
|
||||||
|
Err(FdoErr::NotSupported("Screenpad backlight not found".into()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[zbus(property)]
|
||||||
|
async fn set_screenpad_power(
|
||||||
|
&self,
|
||||||
|
#[zbus(signal_context)] ctxt: SignalEmitter<'_>,
|
||||||
|
power: bool,
|
||||||
|
) -> Result<(), zbus::Error> {
|
||||||
|
if let Some(backlight) = self.get_backlight(&BacklightType::Screenpad) {
|
||||||
|
backlight
|
||||||
|
.set_bl_power(if power { 0 } else { 1 })
|
||||||
|
.map_err(|e| {
|
||||||
|
warn!("Failed to set backlight power: {}", e);
|
||||||
|
FdoErr::Failed(format!("Failed to set backlight power: {}", e))
|
||||||
|
})?;
|
||||||
|
self.screenpad_power_changed(&ctxt).await?;
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(FdoErr::NotSupported("Screenpad backlight not found".into()).into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl crate::ZbusRun for CtrlBacklight {
|
||||||
|
async fn add_to_server(self, server: &mut Connection) {
|
||||||
|
Self::add_to_server_helper(self, ASUS_ZBUS_PATH, server).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl crate::Reloadable for CtrlBacklight {
|
||||||
|
async fn reload(&mut self) -> Result<(), RogError> {
|
||||||
|
info!("Reloading backlight settings");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,25 +4,26 @@ use std::sync::Arc;
|
|||||||
use config_traits::{StdConfig, StdConfigLoad};
|
use config_traits::{StdConfig, StdConfigLoad};
|
||||||
use futures_lite::StreamExt;
|
use futures_lite::StreamExt;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use rog_platform::platform::{RogPlatform, ThrottlePolicy};
|
use rog_platform::platform::{PlatformProfile, RogPlatform};
|
||||||
use rog_profiles::error::ProfileError;
|
use rog_profiles::error::ProfileError;
|
||||||
use rog_profiles::fan_curve_set::CurveData;
|
use rog_profiles::fan_curve_set::CurveData;
|
||||||
use rog_profiles::{find_fan_curve_node, FanCurvePU, FanCurveProfiles};
|
use rog_profiles::{find_fan_curve_node, FanCurvePU, FanCurveProfiles};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use zbus::{interface, Connection, SignalContext};
|
use zbus::object_server::SignalEmitter;
|
||||||
|
use zbus::{interface, Connection};
|
||||||
|
|
||||||
use crate::error::RogError;
|
use crate::error::RogError;
|
||||||
use crate::{CtrlTask, CONFIG_PATH_BASE};
|
use crate::{CtrlTask, CONFIG_PATH_BASE};
|
||||||
|
|
||||||
pub const FAN_CURVE_ZBUS_NAME: &str = "FanCurves";
|
pub const FAN_CURVE_ZBUS_NAME: &str = "FanCurves";
|
||||||
pub const FAN_CURVE_ZBUS_PATH: &str = "/org/asuslinux";
|
pub const FAN_CURVE_ZBUS_PATH: &str = "/xyz/ljones";
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, Default)]
|
#[derive(Deserialize, Serialize, Debug, Default)]
|
||||||
pub struct FanCurveConfig {
|
pub struct FanCurveConfig {
|
||||||
pub profiles: FanCurveProfiles,
|
pub profiles: FanCurveProfiles,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub current: u8,
|
pub current: PlatformProfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdConfig for FanCurveConfig {
|
impl StdConfig for FanCurveConfig {
|
||||||
@@ -53,7 +54,7 @@ pub struct CtrlFanCurveZbus {
|
|||||||
impl CtrlFanCurveZbus {
|
impl CtrlFanCurveZbus {
|
||||||
pub fn new() -> Result<Self, RogError> {
|
pub fn new() -> Result<Self, RogError> {
|
||||||
let platform = RogPlatform::new()?;
|
let platform = RogPlatform::new()?;
|
||||||
if platform.has_throttle_thermal_policy() {
|
if platform.has_platform_profile() {
|
||||||
info!("Device has profile control available");
|
info!("Device has profile control available");
|
||||||
find_fan_curve_node()?;
|
find_fan_curve_node()?;
|
||||||
info!("Device has fan curves available");
|
info!("Device has fan curves available");
|
||||||
@@ -64,16 +65,13 @@ impl CtrlFanCurveZbus {
|
|||||||
if config.profiles.balanced.is_empty() || !config.file_path().exists() {
|
if config.profiles.balanced.is_empty() || !config.file_path().exists() {
|
||||||
info!("Fetching default fan curves");
|
info!("Fetching default fan curves");
|
||||||
|
|
||||||
let current = platform.get_throttle_thermal_policy()?;
|
let current = platform.get_platform_profile()?;
|
||||||
for this in [
|
let profiles = platform.get_platform_profile_choices()?;
|
||||||
ThrottlePolicy::Balanced,
|
for this in profiles {
|
||||||
ThrottlePolicy::Performance,
|
|
||||||
ThrottlePolicy::Quiet,
|
|
||||||
] {
|
|
||||||
// For each profile we need to switch to it before we
|
// For each profile we need to switch to it before we
|
||||||
// can read the existing values from hardware. The ACPI method used
|
// can read the existing values from hardware. The ACPI method used
|
||||||
// for this is what limits us.
|
// for this is what limits us.
|
||||||
platform.set_throttle_thermal_policy(this.into())?;
|
platform.set_platform_profile(this.into())?;
|
||||||
let mut dev = find_fan_curve_node()?;
|
let mut dev = find_fan_curve_node()?;
|
||||||
fan_curves.set_active_curve_to_defaults(this, &mut dev)?;
|
fan_curves.set_active_curve_to_defaults(this, &mut dev)?;
|
||||||
|
|
||||||
@@ -82,7 +80,7 @@ impl CtrlFanCurveZbus {
|
|||||||
info!("{}", String::from(curve));
|
info!("{}", String::from(curve));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
platform.set_throttle_thermal_policy(current)?;
|
platform.set_platform_profile(current.as_str())?;
|
||||||
config.profiles = fan_curves;
|
config.profiles = fan_curves;
|
||||||
config.write();
|
config.write();
|
||||||
} else {
|
} else {
|
||||||
@@ -100,13 +98,13 @@ impl CtrlFanCurveZbus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[interface(name = "org.asuslinux.FanCurves")]
|
#[interface(name = "xyz.ljones.FanCurves")]
|
||||||
impl CtrlFanCurveZbus {
|
impl CtrlFanCurveZbus {
|
||||||
/// Set all fan curves for a profile to enabled status. Will also activate a
|
/// Set all fan curves for a profile to enabled status. Will also activate a
|
||||||
/// fan curve if in the same profile mode
|
/// fan curve if in the same profile mode
|
||||||
async fn set_fan_curves_enabled(
|
async fn set_fan_curves_enabled(
|
||||||
&mut self,
|
&mut self,
|
||||||
profile: ThrottlePolicy,
|
profile: PlatformProfile,
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> zbus::fdo::Result<()> {
|
||||||
self.config
|
self.config
|
||||||
@@ -127,7 +125,7 @@ impl CtrlFanCurveZbus {
|
|||||||
/// activate a fan curve if in the same profile mode
|
/// activate a fan curve if in the same profile mode
|
||||||
async fn set_profile_fan_curve_enabled(
|
async fn set_profile_fan_curve_enabled(
|
||||||
&mut self,
|
&mut self,
|
||||||
profile: ThrottlePolicy,
|
profile: PlatformProfile,
|
||||||
fan: FanCurvePU,
|
fan: FanCurvePU,
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> zbus::fdo::Result<()> {
|
||||||
@@ -148,7 +146,7 @@ impl CtrlFanCurveZbus {
|
|||||||
/// Get the fan-curve data for the currently active ThrottlePolicy
|
/// Get the fan-curve data for the currently active ThrottlePolicy
|
||||||
async fn fan_curve_data(
|
async fn fan_curve_data(
|
||||||
&mut self,
|
&mut self,
|
||||||
profile: ThrottlePolicy,
|
profile: PlatformProfile,
|
||||||
) -> zbus::fdo::Result<Vec<CurveData>> {
|
) -> zbus::fdo::Result<Vec<CurveData>> {
|
||||||
let curve = self
|
let curve = self
|
||||||
.config
|
.config
|
||||||
@@ -164,7 +162,7 @@ impl CtrlFanCurveZbus {
|
|||||||
/// Will also activate the fan curve if the user is in the same mode.
|
/// Will also activate the fan curve if the user is in the same mode.
|
||||||
async fn set_fan_curve(
|
async fn set_fan_curve(
|
||||||
&mut self,
|
&mut self,
|
||||||
profile: ThrottlePolicy,
|
profile: PlatformProfile,
|
||||||
curve: CurveData,
|
curve: CurveData,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> zbus::fdo::Result<()> {
|
||||||
self.config
|
self.config
|
||||||
@@ -172,7 +170,7 @@ impl CtrlFanCurveZbus {
|
|||||||
.await
|
.await
|
||||||
.profiles
|
.profiles
|
||||||
.save_fan_curve(curve, profile)?;
|
.save_fan_curve(curve, profile)?;
|
||||||
let active: ThrottlePolicy = self.platform.get_throttle_thermal_policy()?.into();
|
let active: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||||
if active == profile {
|
if active == profile {
|
||||||
self.config
|
self.config
|
||||||
.lock()
|
.lock()
|
||||||
@@ -189,15 +187,15 @@ impl CtrlFanCurveZbus {
|
|||||||
///
|
///
|
||||||
/// Each platform_profile has a different default and the default can be
|
/// Each platform_profile has a different default and the default can be
|
||||||
/// read only for the currently active profile.
|
/// read only for the currently active profile.
|
||||||
async fn set_curves_to_defaults(&mut self, profile: ThrottlePolicy) -> zbus::fdo::Result<()> {
|
async fn set_curves_to_defaults(&mut self, profile: PlatformProfile) -> zbus::fdo::Result<()> {
|
||||||
let active = self.platform.get_throttle_thermal_policy()?;
|
let active = self.platform.get_platform_profile()?;
|
||||||
self.platform.set_throttle_thermal_policy(profile.into())?;
|
self.platform.set_platform_profile(profile.into())?;
|
||||||
self.config
|
self.config
|
||||||
.lock()
|
.lock()
|
||||||
.await
|
.await
|
||||||
.profiles
|
.profiles
|
||||||
.set_active_curve_to_defaults(profile, &mut find_fan_curve_node()?)?;
|
.set_active_curve_to_defaults(profile, &mut find_fan_curve_node()?)?;
|
||||||
self.platform.set_throttle_thermal_policy(active)?;
|
self.platform.set_platform_profile(active.as_str())?;
|
||||||
self.config.lock().await.write();
|
self.config.lock().await.write();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -207,16 +205,16 @@ impl CtrlFanCurveZbus {
|
|||||||
///
|
///
|
||||||
/// Each platform_profile has a different default and the defualt can be
|
/// Each platform_profile has a different default and the defualt can be
|
||||||
/// read only for the currently active profile.
|
/// read only for the currently active profile.
|
||||||
async fn reset_profile_curves(&self, profile: ThrottlePolicy) -> zbus::fdo::Result<()> {
|
async fn reset_profile_curves(&self, profile: PlatformProfile) -> zbus::fdo::Result<()> {
|
||||||
let active = self.platform.get_throttle_thermal_policy()?;
|
let active = self.platform.get_platform_profile()?;
|
||||||
|
|
||||||
self.platform.set_throttle_thermal_policy(profile.into())?;
|
self.platform.set_platform_profile(profile.into())?;
|
||||||
self.config
|
self.config
|
||||||
.lock()
|
.lock()
|
||||||
.await
|
.await
|
||||||
.profiles
|
.profiles
|
||||||
.set_active_curve_to_defaults(active.into(), &mut find_fan_curve_node()?)?;
|
.set_active_curve_to_defaults(active.as_str().into(), &mut find_fan_curve_node()?)?;
|
||||||
self.platform.set_throttle_thermal_policy(active)?;
|
self.platform.set_platform_profile(active.as_str())?;
|
||||||
|
|
||||||
self.config.lock().await.write();
|
self.config.lock().await.write();
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -234,27 +232,32 @@ impl CtrlTask for CtrlFanCurveZbus {
|
|||||||
FAN_CURVE_ZBUS_PATH
|
FAN_CURVE_ZBUS_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_tasks(&self, _signal_ctxt: SignalContext<'static>) -> Result<(), RogError> {
|
async fn create_tasks(&self, _signal_ctxt: SignalEmitter<'static>) -> Result<(), RogError> {
|
||||||
let watch_throttle_thermal_policy = self.platform.monitor_throttle_thermal_policy()?;
|
let watch_platform_profile = self.platform.monitor_platform_profile()?;
|
||||||
let platform = self.platform.clone();
|
let platform = self.platform.clone();
|
||||||
let config = self.config.clone();
|
let config = self.config.clone();
|
||||||
let fan_curves = self.config.clone();
|
let fan_curves = self.config.clone();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut buffer = [0; 32];
|
let mut buffer = [0; 32];
|
||||||
if let Ok(mut stream) = watch_throttle_thermal_policy.into_event_stream(&mut buffer) {
|
if let Ok(mut stream) = watch_platform_profile.into_event_stream(&mut buffer) {
|
||||||
while (stream.next().await).is_some() {
|
while (stream.next().await).is_some() {
|
||||||
debug!("watch_throttle_thermal_policy changed");
|
debug!("watch_platform_profile changed");
|
||||||
if let Ok(profile) = platform.get_throttle_thermal_policy().map_err(|e| {
|
if let Ok(profile) =
|
||||||
error!("get_throttle_thermal_policy error: {e}");
|
platform
|
||||||
}) {
|
.get_platform_profile()
|
||||||
|
.map(|p| p.into())
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("get_platform_profile error: {e}");
|
||||||
|
})
|
||||||
|
{
|
||||||
if profile != config.lock().await.current {
|
if profile != config.lock().await.current {
|
||||||
fan_curves
|
fan_curves
|
||||||
.lock()
|
.lock()
|
||||||
.await
|
.await
|
||||||
.profiles
|
.profiles
|
||||||
.write_profile_curve_to_platform(
|
.write_profile_curve_to_platform(
|
||||||
profile.into(),
|
profile,
|
||||||
&mut find_fan_curve_node().unwrap(),
|
&mut find_fan_curve_node().unwrap(),
|
||||||
)
|
)
|
||||||
.map_err(|e| warn!("write_profile_curve_to_platform, {}", e))
|
.map_err(|e| warn!("write_profile_curve_to_platform, {}", e))
|
||||||
@@ -273,7 +276,7 @@ impl CtrlTask for CtrlFanCurveZbus {
|
|||||||
impl crate::Reloadable for CtrlFanCurveZbus {
|
impl crate::Reloadable for CtrlFanCurveZbus {
|
||||||
/// Fetch the active profile and use that to set all related components up
|
/// Fetch the active profile and use that to set all related components up
|
||||||
async fn reload(&mut self) -> Result<(), RogError> {
|
async fn reload(&mut self) -> Result<(), RogError> {
|
||||||
let active = self.platform.get_throttle_thermal_policy()?.into();
|
let active = self.platform.get_platform_profile()?.into();
|
||||||
let mut config = self.config.lock().await;
|
let mut config = self.config.lock().await;
|
||||||
if let Ok(mut device) = find_fan_curve_node() {
|
if let Ok(mut device) = find_fan_curve_node() {
|
||||||
config
|
config
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,51 +0,0 @@
|
|||||||
use config_traits::{StdConfig, StdConfigLoad};
|
|
||||||
use rog_slash::{DeviceState, SlashMode};
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
const CONFIG_FILE: &str = "slash.ron";
|
|
||||||
|
|
||||||
/// Config for base system actions for the anime display
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
|
||||||
pub struct SlashConfig {
|
|
||||||
pub slash_enabled: bool,
|
|
||||||
pub slash_brightness: u8,
|
|
||||||
pub slash_interval: u8,
|
|
||||||
pub slash_mode: SlashMode,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for SlashConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
SlashConfig {
|
|
||||||
slash_enabled: true,
|
|
||||||
slash_brightness: 255,
|
|
||||||
slash_interval: 0,
|
|
||||||
slash_mode: SlashMode::Bounce,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl StdConfig for SlashConfig {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn file_name(&self) -> String {
|
|
||||||
CONFIG_FILE.to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn config_dir() -> std::path::PathBuf {
|
|
||||||
std::path::PathBuf::from(crate::CONFIG_PATH_BASE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StdConfigLoad for SlashConfig {}
|
|
||||||
|
|
||||||
impl From<&SlashConfig> for DeviceState {
|
|
||||||
fn from(config: &SlashConfig) -> Self {
|
|
||||||
DeviceState {
|
|
||||||
slash_enabled: config.slash_enabled,
|
|
||||||
slash_brightness: config.slash_brightness,
|
|
||||||
slash_interval: config.slash_interval,
|
|
||||||
slash_mode: config.slash_mode,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
pub mod config;
|
|
||||||
pub mod trait_impls;
|
|
||||||
|
|
||||||
use config_traits::{StdConfig, StdConfigLoad};
|
|
||||||
use rog_platform::hid_raw::HidRaw;
|
|
||||||
use rog_platform::usb_raw::USBRaw;
|
|
||||||
use rog_slash::error::SlashError;
|
|
||||||
use rog_slash::usb::{get_slash_type, pkt_set_mode, pkt_set_options, pkts_for_init};
|
|
||||||
use rog_slash::{SlashMode, SlashType};
|
|
||||||
|
|
||||||
use crate::ctrl_slash::config::SlashConfig;
|
|
||||||
use crate::error::RogError;
|
|
||||||
|
|
||||||
enum Node {
|
|
||||||
Usb(USBRaw),
|
|
||||||
Hid(HidRaw),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Node {
|
|
||||||
pub fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
|
||||||
// TODO: map and pass on errors
|
|
||||||
match self {
|
|
||||||
Node::Usb(u) => {
|
|
||||||
u.write_bytes(message).ok();
|
|
||||||
}
|
|
||||||
Node::Hid(h) => {
|
|
||||||
h.write_bytes(message).ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CtrlSlash {
|
|
||||||
node: Node,
|
|
||||||
config: SlashConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CtrlSlash {
|
|
||||||
#[inline]
|
|
||||||
pub fn new() -> Result<CtrlSlash, RogError> {
|
|
||||||
let slash_type = get_slash_type()?;
|
|
||||||
if matches!(slash_type, SlashType::Unknown | SlashType::Unsupported) {
|
|
||||||
return Err(RogError::Slash(SlashError::NoDevice));
|
|
||||||
}
|
|
||||||
|
|
||||||
let usb = USBRaw::new(rog_slash::usb::PROD_ID).ok();
|
|
||||||
let hid = HidRaw::new(rog_slash::usb::PROD_ID_STR).ok();
|
|
||||||
let node = if usb.is_some() {
|
|
||||||
unsafe { Node::Usb(usb.unwrap_unchecked()) }
|
|
||||||
} else if hid.is_some() {
|
|
||||||
unsafe { Node::Hid(hid.unwrap_unchecked()) }
|
|
||||||
} else {
|
|
||||||
return Err(RogError::NotSupported);
|
|
||||||
};
|
|
||||||
|
|
||||||
let ctrl = CtrlSlash {
|
|
||||||
node,
|
|
||||||
config: SlashConfig::new().load(),
|
|
||||||
};
|
|
||||||
ctrl.do_initialization()?;
|
|
||||||
|
|
||||||
Ok(ctrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn do_initialization(&self) -> Result<(), RogError> {
|
|
||||||
let init_packets = pkts_for_init();
|
|
||||||
self.node.write_bytes(&init_packets[0])?;
|
|
||||||
self.node.write_bytes(&init_packets[1])?;
|
|
||||||
|
|
||||||
// Apply config upon initialization
|
|
||||||
let option_packets = pkt_set_options(
|
|
||||||
self.config.slash_enabled,
|
|
||||||
self.config.slash_brightness,
|
|
||||||
self.config.slash_interval,
|
|
||||||
);
|
|
||||||
self.node.write_bytes(&option_packets)?;
|
|
||||||
|
|
||||||
let mode_packets = pkt_set_mode(self.config.slash_mode);
|
|
||||||
self.node.write_bytes(&mode_packets[0])?;
|
|
||||||
self.node.write_bytes(&mode_packets[1])?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_options(&self, enabled: bool, brightness: u8, interval: u8) -> Result<(), RogError> {
|
|
||||||
let command_packets = pkt_set_options(enabled, brightness, interval);
|
|
||||||
self.node.write_bytes(&command_packets)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_slash_mode(&self, slash_mode: SlashMode) -> Result<(), RogError> {
|
|
||||||
let command_packets = pkt_set_mode(slash_mode);
|
|
||||||
self.node.write_bytes(&command_packets[0])?;
|
|
||||||
self.node.write_bytes(&command_packets[1])?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use config_traits::StdConfig;
|
|
||||||
use log::warn;
|
|
||||||
use rog_slash::usb::{pkt_set_mode, pkt_set_options};
|
|
||||||
use rog_slash::{DeviceState, SlashMode};
|
|
||||||
use zbus::export::futures_util::lock::Mutex;
|
|
||||||
use zbus::{interface, Connection, SignalContext};
|
|
||||||
|
|
||||||
use crate::ctrl_slash::CtrlSlash;
|
|
||||||
use crate::error::RogError;
|
|
||||||
|
|
||||||
pub const SLASH_ZBUS_NAME: &str = "Slash";
|
|
||||||
pub const SLASH_ZBUS_PATH: &str = "/org/asuslinux";
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct CtrlSlashZbus(pub Arc<Mutex<CtrlSlash>>);
|
|
||||||
|
|
||||||
/// The struct with the main dbus methods requires this trait
|
|
||||||
impl crate::ZbusRun for CtrlSlashZbus {
|
|
||||||
async fn add_to_server(self, server: &mut Connection) {
|
|
||||||
Self::add_to_server_helper(self, SLASH_ZBUS_PATH, server).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[interface(name = "org.asuslinux.Slash")]
|
|
||||||
impl CtrlSlashZbus {
|
|
||||||
/// Get enabled or not
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn enabled(&self) -> bool {
|
|
||||||
let lock = self.0.lock().await;
|
|
||||||
lock.config.slash_enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set enabled true or false
|
|
||||||
async fn set_enabled(&self, enabled: bool) {
|
|
||||||
let mut lock = self.0.lock().await;
|
|
||||||
let brightness = if enabled && lock.config.slash_brightness == 0 {
|
|
||||||
0x88
|
|
||||||
} else {
|
|
||||||
lock.config.slash_brightness
|
|
||||||
};
|
|
||||||
lock.node
|
|
||||||
.write_bytes(&pkt_set_options(
|
|
||||||
enabled,
|
|
||||||
brightness,
|
|
||||||
lock.config.slash_interval,
|
|
||||||
))
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!("ctrl_slash::set_options {}", err);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
lock.config.slash_enabled = enabled;
|
|
||||||
lock.config.slash_brightness = brightness;
|
|
||||||
lock.config.write();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get brightness level
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn brightness(&self) -> u8 {
|
|
||||||
let lock = self.0.lock().await;
|
|
||||||
lock.config.slash_brightness
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set brightness level
|
|
||||||
async fn set_brightness(&self, brightness: u8) {
|
|
||||||
let mut lock = self.0.lock().await;
|
|
||||||
let enabled = brightness > 0;
|
|
||||||
lock.node
|
|
||||||
.write_bytes(&pkt_set_options(
|
|
||||||
enabled,
|
|
||||||
brightness,
|
|
||||||
lock.config.slash_interval,
|
|
||||||
))
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!("ctrl_slash::set_options {}", err);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
lock.config.slash_enabled = enabled;
|
|
||||||
lock.config.slash_brightness = brightness;
|
|
||||||
lock.config.write();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn interval(&self) -> u8 {
|
|
||||||
let lock = self.0.lock().await;
|
|
||||||
lock.config.slash_interval
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set interval between slash animations (0-255)
|
|
||||||
async fn set_interval(&self, interval: u8) {
|
|
||||||
let mut lock = self.0.lock().await;
|
|
||||||
lock.node
|
|
||||||
.write_bytes(&pkt_set_options(
|
|
||||||
lock.config.slash_enabled,
|
|
||||||
lock.config.slash_brightness,
|
|
||||||
interval,
|
|
||||||
))
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!("ctrl_slash::set_options {}", err);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
lock.config.slash_interval = interval;
|
|
||||||
lock.config.write();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[zbus(property)]
|
|
||||||
async fn slash_mode(&self) -> u8 {
|
|
||||||
let lock = self.0.lock().await;
|
|
||||||
lock.config.slash_interval
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set interval between slash animations (0-255)
|
|
||||||
async fn set_slash_mode(&self, slash_mode: SlashMode) {
|
|
||||||
let mut lock = self.0.lock().await;
|
|
||||||
|
|
||||||
let command_packets = pkt_set_mode(slash_mode);
|
|
||||||
|
|
||||||
lock.node
|
|
||||||
.write_bytes(&command_packets[0])
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!("ctrl_slash::set_options {}", err);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
lock.node
|
|
||||||
.write_bytes(&command_packets[1])
|
|
||||||
.map_err(|err| {
|
|
||||||
warn!("ctrl_slash::set_options {}", err);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
lock.config.slash_mode = slash_mode;
|
|
||||||
lock.config.write();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the device state as stored by asusd
|
|
||||||
// #[zbus(property)]
|
|
||||||
async fn device_state(&self) -> DeviceState {
|
|
||||||
let lock = self.0.lock().await;
|
|
||||||
DeviceState::from(&lock.config)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl crate::CtrlTask for CtrlSlashZbus {
|
|
||||||
fn zbus_path() -> &'static str {
|
|
||||||
SLASH_ZBUS_PATH
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn create_tasks(&self, _: SignalContext<'static>) -> Result<(), RogError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl crate::Reloadable for CtrlSlashZbus {
|
|
||||||
async fn reload(&mut self) -> Result<(), RogError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,34 +2,38 @@ use std::env;
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ::zbus::export::futures_util::lock::Mutex;
|
|
||||||
use ::zbus::Connection;
|
use ::zbus::Connection;
|
||||||
|
use asusd::asus_armoury::{start_attributes_zbus, ArmouryAttributeRegistry};
|
||||||
|
use asusd::aura_manager::DeviceManager;
|
||||||
use asusd::config::Config;
|
use asusd::config::Config;
|
||||||
use asusd::ctrl_anime::trait_impls::CtrlAnimeZbus;
|
use asusd::ctrl_backlight::CtrlBacklight;
|
||||||
use asusd::ctrl_anime::CtrlAnime;
|
|
||||||
use asusd::ctrl_aura::manager::AuraManager;
|
|
||||||
use asusd::ctrl_fancurves::CtrlFanCurveZbus;
|
use asusd::ctrl_fancurves::CtrlFanCurveZbus;
|
||||||
use asusd::ctrl_platform::CtrlPlatform;
|
use asusd::ctrl_platform::CtrlPlatform;
|
||||||
use asusd::ctrl_slash::trait_impls::CtrlSlashZbus;
|
use asusd::{print_board_info, start_tasks, CtrlTask, ZbusRun, DBUS_NAME};
|
||||||
use asusd::ctrl_slash::CtrlSlash;
|
use config_traits::{StdConfig, StdConfigLoad2};
|
||||||
use asusd::{print_board_info, start_tasks, CtrlTask, DBUS_NAME};
|
|
||||||
use config_traits::{StdConfig, StdConfigLoad3};
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
|
use rog_platform::asus_armoury::FirmwareAttributes;
|
||||||
|
use rog_platform::platform::RogPlatform;
|
||||||
|
use rog_platform::power::AsusPower;
|
||||||
|
use tokio::sync::Mutex;
|
||||||
use zbus::fdo::ObjectManager;
|
use zbus::fdo::ObjectManager;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("Starting asusd daemon...");
|
||||||
|
|
||||||
// console_subscriber::init();
|
// console_subscriber::init();
|
||||||
let mut logger = env_logger::Builder::new();
|
let mut logger = env_logger::Builder::new();
|
||||||
logger
|
logger
|
||||||
.parse_default_env()
|
.parse_default_env()
|
||||||
.target(env_logger::Target::Stdout)
|
.target(env_logger::Target::Stdout)
|
||||||
.format_timestamp(None)
|
.format_timestamp(None)
|
||||||
|
.filter_level(log::LevelFilter::Debug)
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
let is_service = match env::var_os("IS_SERVICE") {
|
let is_service = match env::var_os("IS_SERVICE") {
|
||||||
Some(val) => val == "1",
|
Some(val) => val == "1",
|
||||||
None => false,
|
None => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !is_service {
|
if !is_service {
|
||||||
@@ -59,76 +63,93 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
|||||||
// println!("{:?}", supported.supported_functions());
|
// println!("{:?}", supported.supported_functions());
|
||||||
|
|
||||||
// Start zbus server
|
// Start zbus server
|
||||||
let mut connection = Connection::system().await?;
|
let mut server = Connection::system().await?;
|
||||||
connection
|
if let Err(e) = server.object_server().at("/", ObjectManager).await {
|
||||||
.object_server()
|
error!("Failed to register ObjectManager at root '/': {e:?}");
|
||||||
.at("/org/asuslinux", ObjectManager)
|
}
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let config = Config::new().load();
|
let config = Config::new().load();
|
||||||
let cfg_path = config.file_path();
|
let cfg_path = config.file_path();
|
||||||
let config = Arc::new(Mutex::new(config));
|
let config = Arc::new(Mutex::new(config));
|
||||||
|
|
||||||
// supported.add_to_server(&mut connection).await;
|
// supported.add_to_server(&mut connection).await;
|
||||||
|
let platform = RogPlatform::new()?; // TODO: maybe needs async mutex?
|
||||||
|
let power = AsusPower::new()?; // TODO: maybe needs async mutex?
|
||||||
|
let attributes = FirmwareAttributes::new();
|
||||||
|
let armoury_registry = match start_attributes_zbus(
|
||||||
|
&server,
|
||||||
|
platform.clone(),
|
||||||
|
power.clone(),
|
||||||
|
attributes.clone(),
|
||||||
|
config.clone(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(registry) => {
|
||||||
|
info!("attribute on zbus initialized");
|
||||||
|
registry
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("Failed to initialize firmware attributes over zbus: {e:?}");
|
||||||
|
ArmouryAttributeRegistry::default()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
match CtrlFanCurveZbus::new() {
|
match CtrlFanCurveZbus::new() {
|
||||||
Ok(ctrl) => {
|
Ok(ctrl) => {
|
||||||
let sig_ctx = CtrlFanCurveZbus::signal_context(&connection)?;
|
info!("FanCurves: found supported fancurves");
|
||||||
start_tasks(ctrl, &mut connection, sig_ctx).await?;
|
let sig_ctx = CtrlFanCurveZbus::signal_context(&server)?;
|
||||||
|
start_tasks(ctrl, &mut server, sig_ctx).await?;
|
||||||
|
info!("FanCurves: initialized");
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("FanCurves: {}", err);
|
error!("FanCurves: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match CtrlBacklight::new(config.clone()) {
|
||||||
|
Ok(backlight) => {
|
||||||
|
info!("Backlight: found supported backlight");
|
||||||
|
backlight.start_watch_primary().await?;
|
||||||
|
backlight.add_to_server(&mut server).await;
|
||||||
|
info!("Backlight: initialized");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
error!("Backlight: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match CtrlPlatform::new(
|
match CtrlPlatform::new(
|
||||||
|
platform,
|
||||||
|
power,
|
||||||
|
attributes,
|
||||||
config.clone(),
|
config.clone(),
|
||||||
&cfg_path,
|
&cfg_path,
|
||||||
CtrlPlatform::signal_context(&connection)?,
|
CtrlPlatform::signal_context(&server)?,
|
||||||
|
server.clone(),
|
||||||
|
armoury_registry,
|
||||||
) {
|
) {
|
||||||
Ok(ctrl) => {
|
Ok(ctrl) => {
|
||||||
let sig_ctx = CtrlPlatform::signal_context(&connection)?;
|
info!("CtrlPlatform: initialized");
|
||||||
start_tasks(ctrl, &mut connection, sig_ctx).await?;
|
let sig_ctx = CtrlPlatform::signal_context(&server)?;
|
||||||
|
start_tasks(ctrl, &mut server, sig_ctx).await?;
|
||||||
|
info!("CtrlPlatform: tasks started");
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("CtrlPlatform: {}", err);
|
error!("CtrlPlatform: {}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match CtrlAnime::new() {
|
let _ = DeviceManager::new(server.clone()).await?;
|
||||||
Ok(ctrl) => {
|
|
||||||
let zbus = CtrlAnimeZbus(Arc::new(Mutex::new(ctrl)));
|
|
||||||
let sig_ctx = CtrlAnimeZbus::signal_context(&connection)?;
|
|
||||||
start_tasks(zbus, &mut connection, sig_ctx).await?;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
info!("AniMe control: {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match CtrlSlash::new() {
|
info!("DeviceManager initialized");
|
||||||
Ok(ctrl) => {
|
|
||||||
let zbus = CtrlSlashZbus(Arc::new(Mutex::new(ctrl)));
|
|
||||||
// Currently, the Slash has no need for a loop watching power events, however,
|
|
||||||
// it could be cool to have the slash do some power-on/off animation
|
|
||||||
// (It has a built-in power on animation which plays when u plug in the power
|
|
||||||
// supply)
|
|
||||||
let sig_ctx = CtrlSlashZbus::signal_context(&connection)?;
|
|
||||||
start_tasks(zbus, &mut connection, sig_ctx).await?;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
info!("AniMe control: {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let _ = AuraManager::new(connection.clone()).await?;
|
|
||||||
|
|
||||||
// Request dbus name after finishing initalizing all functions
|
// Request dbus name after finishing initalizing all functions
|
||||||
connection.request_name(DBUS_NAME).await?;
|
server.request_name(DBUS_NAME).await?;
|
||||||
|
|
||||||
|
info!("Startup success on dbus name {DBUS_NAME}: begining dbus server loop");
|
||||||
loop {
|
loop {
|
||||||
// This is just a blocker to idle and ensure the reator reacts
|
// This is just a blocker to idle and ensure the reator reacts
|
||||||
connection.executor().tick().await;
|
server.executor().tick().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,3 +142,10 @@ impl From<RogError> for zbus::fdo::Error {
|
|||||||
zbus::fdo::Error::Failed(format!("{}", err))
|
zbus::fdo::Error::Failed(format!("{}", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<RogError> for zbus::Error {
|
||||||
|
#[inline]
|
||||||
|
fn from(err: RogError) -> Self {
|
||||||
|
zbus::Error::Failure(format!("{}", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
#![deny(unused_must_use)]
|
#![deny(unused_must_use)]
|
||||||
/// Configuration loading, saving
|
/// Configuration loading, saving
|
||||||
pub mod config;
|
pub mod config;
|
||||||
/// Control of anime matrix display
|
pub mod ctrl_backlight;
|
||||||
pub mod ctrl_anime;
|
|
||||||
/// Keyboard LED brightness control, RGB, and LED display modes
|
|
||||||
pub mod ctrl_aura;
|
|
||||||
/// Control platform profiles + fan-curves if available
|
/// Control platform profiles + fan-curves if available
|
||||||
pub mod ctrl_fancurves;
|
pub mod ctrl_fancurves;
|
||||||
/// Control ASUS bios function such as boot sound, Optimus/Dedicated gfx mode
|
/// Control ASUS bios function such as boot sound, Optimus/Dedicated gfx mode
|
||||||
pub mod ctrl_platform;
|
pub mod ctrl_platform;
|
||||||
/// Control of Slash led bar
|
|
||||||
pub mod ctrl_slash;
|
|
||||||
|
|
||||||
|
pub mod asus_armoury;
|
||||||
|
pub mod aura_anime;
|
||||||
|
pub mod aura_laptop;
|
||||||
|
pub mod aura_manager;
|
||||||
|
pub mod aura_scsi;
|
||||||
|
pub mod aura_slash;
|
||||||
|
pub mod aura_types;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
@@ -22,15 +24,19 @@ use futures_lite::stream::StreamExt;
|
|||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use logind_zbus::manager::ManagerProxy;
|
use logind_zbus::manager::ManagerProxy;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
use zbus::object_server::{Interface, SignalEmitter};
|
||||||
|
use zbus::proxy::CacheProperties;
|
||||||
use zbus::zvariant::ObjectPath;
|
use zbus::zvariant::ObjectPath;
|
||||||
use zbus::{CacheProperties, Connection, SignalContext};
|
use zbus::Connection;
|
||||||
|
|
||||||
use crate::error::RogError;
|
use crate::error::RogError;
|
||||||
|
|
||||||
const CONFIG_PATH_BASE: &str = "/etc/asusd/";
|
const CONFIG_PATH_BASE: &str = "/etc/asusd/";
|
||||||
pub static DBUS_NAME: &str = "org.asuslinux.Daemon";
|
pub const ASUS_ZBUS_PATH: &str = "/xyz/ljones";
|
||||||
pub static DBUS_PATH: &str = "/org/asuslinux/Daemon";
|
|
||||||
pub static DBUS_IFACE: &str = "org.asuslinux.Daemon";
|
pub static DBUS_NAME: &str = "xyz.ljones.Asusd";
|
||||||
|
pub static DBUS_PATH: &str = "/xyz/ljones/Daemon";
|
||||||
|
pub static DBUS_IFACE: &str = "xyz.ljones.Asusd";
|
||||||
|
|
||||||
/// This macro adds a function which spawns an `inotify` task on the passed in
|
/// This macro adds a function which spawns an `inotify` task on the passed in
|
||||||
/// `Executor`.
|
/// `Executor`.
|
||||||
@@ -39,7 +45,7 @@ pub static DBUS_IFACE: &str = "org.asuslinux.Daemon";
|
|||||||
/// methods to be available:
|
/// methods to be available:
|
||||||
/// - `<name>() -> SomeValue`, functionally is a getter, but is allowed to have
|
/// - `<name>() -> SomeValue`, functionally is a getter, but is allowed to have
|
||||||
/// side effects.
|
/// side effects.
|
||||||
/// - `notify_<name>(SignalContext, SomeValue)`
|
/// - `notify_<name>(SignalEmitter, SomeValue)`
|
||||||
///
|
///
|
||||||
/// In most cases if `SomeValue` is stored in a config then `<name>()` getter is
|
/// In most cases if `SomeValue` is stored in a config then `<name>()` getter is
|
||||||
/// expected to update it. The getter should *never* write back to the path or
|
/// expected to update it. The getter should *never* write back to the path or
|
||||||
@@ -56,13 +62,13 @@ pub static DBUS_IFACE: &str = "org.asuslinux.Daemon";
|
|||||||
/// // TODO: this is kind of useless if it can't trigger some action
|
/// // TODO: this is kind of useless if it can't trigger some action
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! task_watch_item {
|
macro_rules! task_watch_item {
|
||||||
($name:ident $self_inner:ident) => {
|
($name:ident $name_str:literal $self_inner:ident) => {
|
||||||
concat_idents::concat_idents!(fn_name = watch_, $name {
|
concat_idents::concat_idents!(fn_name = watch_, $name {
|
||||||
async fn fn_name(
|
async fn fn_name(
|
||||||
&self,
|
&self,
|
||||||
signal_ctxt: SignalContext<'static>,
|
signal_ctxt: SignalEmitter<'static>,
|
||||||
) -> Result<(), RogError> {
|
) -> Result<(), RogError> {
|
||||||
use zbus::export::futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
|
|
||||||
let ctrl = self.clone();
|
let ctrl = self.clone();
|
||||||
concat_idents::concat_idents!(watch_fn = monitor_, $name {
|
concat_idents::concat_idents!(watch_fn = monitor_, $name {
|
||||||
@@ -72,12 +78,15 @@ macro_rules! task_watch_item {
|
|||||||
let mut buffer = [0; 32];
|
let mut buffer = [0; 32];
|
||||||
watch.into_event_stream(&mut buffer).unwrap().for_each(|_| async {
|
watch.into_event_stream(&mut buffer).unwrap().for_each(|_| async {
|
||||||
if let Ok(value) = ctrl.$name() { // get new value from zbus method
|
if let Ok(value) = ctrl.$name() { // get new value from zbus method
|
||||||
concat_idents::concat_idents!(notif_fn = $name, _changed {
|
if ctrl.config.lock().await.$name != value {
|
||||||
ctrl.notif_fn(&signal_ctxt).await.ok();
|
log::debug!("{} was changed to {} externally", $name_str, value);
|
||||||
});
|
concat_idents::concat_idents!(notif_fn = $name, _changed {
|
||||||
let mut lock = ctrl.config.lock().await;
|
ctrl.notif_fn(&signal_ctxt).await.ok();
|
||||||
lock.$name = value;
|
});
|
||||||
lock.write();
|
let mut lock = ctrl.config.lock().await;
|
||||||
|
lock.$name = value;
|
||||||
|
lock.write();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).await;
|
}).await;
|
||||||
});
|
});
|
||||||
@@ -97,9 +106,9 @@ macro_rules! task_watch_item_notify {
|
|||||||
concat_idents::concat_idents!(fn_name = watch_, $name {
|
concat_idents::concat_idents!(fn_name = watch_, $name {
|
||||||
async fn fn_name(
|
async fn fn_name(
|
||||||
&self,
|
&self,
|
||||||
signal_ctxt: SignalContext<'static>,
|
signal_ctxt: SignalEmitter<'static>,
|
||||||
) -> Result<(), RogError> {
|
) -> Result<(), RogError> {
|
||||||
use zbus::export::futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
|
|
||||||
let ctrl = self.clone();
|
let ctrl = self.clone();
|
||||||
concat_idents::concat_idents!(watch_fn = monitor_, $name {
|
concat_idents::concat_idents!(watch_fn = monitor_, $name {
|
||||||
@@ -140,7 +149,7 @@ pub trait ReloadAndNotify {
|
|||||||
|
|
||||||
fn reload_and_notify(
|
fn reload_and_notify(
|
||||||
&mut self,
|
&mut self,
|
||||||
signal_context: &SignalContext<'static>,
|
signal_context: &SignalEmitter<'static>,
|
||||||
data: Self::Data,
|
data: Self::Data,
|
||||||
) -> impl Future<Output = Result<(), RogError>> + Send;
|
) -> impl Future<Output = Result<(), RogError>> + Send;
|
||||||
}
|
}
|
||||||
@@ -149,7 +158,7 @@ pub trait ZbusRun {
|
|||||||
fn add_to_server(self, server: &mut Connection) -> impl Future<Output = ()> + Send;
|
fn add_to_server(self, server: &mut Connection) -> impl Future<Output = ()> + Send;
|
||||||
|
|
||||||
fn add_to_server_helper(
|
fn add_to_server_helper(
|
||||||
iface: impl zbus::Interface,
|
iface: impl Interface,
|
||||||
path: &str,
|
path: &str,
|
||||||
server: &mut Connection,
|
server: &mut Connection,
|
||||||
) -> impl Future<Output = ()> + Send {
|
) -> impl Future<Output = ()> + Send {
|
||||||
@@ -171,8 +180,8 @@ pub trait ZbusRun {
|
|||||||
pub trait CtrlTask {
|
pub trait CtrlTask {
|
||||||
fn zbus_path() -> &'static str;
|
fn zbus_path() -> &'static str;
|
||||||
|
|
||||||
fn signal_context(connection: &Connection) -> Result<SignalContext<'static>, zbus::Error> {
|
fn signal_context(connection: &Connection) -> Result<SignalEmitter<'static>, zbus::Error> {
|
||||||
SignalContext::new(connection, Self::zbus_path())
|
SignalEmitter::new(connection, Self::zbus_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement to set up various tasks that may be required, using the
|
/// Implement to set up various tasks that may be required, using the
|
||||||
@@ -180,7 +189,7 @@ pub trait CtrlTask {
|
|||||||
/// separate thread.
|
/// separate thread.
|
||||||
fn create_tasks(
|
fn create_tasks(
|
||||||
&self,
|
&self,
|
||||||
signal: SignalContext<'static>,
|
signal: SignalEmitter<'static>,
|
||||||
) -> impl Future<Output = Result<(), RogError>> + Send;
|
) -> impl Future<Output = Result<(), RogError>> + Send;
|
||||||
|
|
||||||
// /// Create a timed repeating task
|
// /// Create a timed repeating task
|
||||||
@@ -294,7 +303,7 @@ pub trait GetSupported {
|
|||||||
pub async fn start_tasks<T>(
|
pub async fn start_tasks<T>(
|
||||||
mut zbus: T,
|
mut zbus: T,
|
||||||
connection: &mut Connection,
|
connection: &mut Connection,
|
||||||
signal_ctx: SignalContext<'static>,
|
signal_ctx: SignalEmitter<'static>,
|
||||||
) -> Result<(), RogError>
|
) -> Result<(), RogError>
|
||||||
where
|
where
|
||||||
T: ZbusRun + Reloadable + CtrlTask + Clone,
|
T: ZbusRun + Reloadable + CtrlTask + Clone,
|
||||||
|
|||||||
@@ -13,6 +13,3 @@ serde.workspace = true
|
|||||||
ron.workspace = true
|
ron.workspace = true
|
||||||
|
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
cargo-husky.workspace = true
|
|
||||||
|
|||||||
@@ -146,11 +146,7 @@ where
|
|||||||
|
|
||||||
/// Renames the existing file to `<file>-old`
|
/// Renames the existing file to `<file>-old`
|
||||||
fn rename_file_old(&self) {
|
fn rename_file_old(&self) {
|
||||||
warn!(
|
warn!("Renaming {} to {}-old", self.file_name(), self.file_name());
|
||||||
"Renaming {} to {}-old and recreating config",
|
|
||||||
self.file_name(),
|
|
||||||
self.file_name()
|
|
||||||
);
|
|
||||||
let mut cfg_old = self.file_path().to_string_lossy().to_string();
|
let mut cfg_old = self.file_path().to_string_lossy().to_string();
|
||||||
cfg_old.push_str("-old");
|
cfg_old.push_str("-old");
|
||||||
std::fs::rename(self.file_path(), cfg_old).unwrap_or_else(|err| {
|
std::fs::rename(self.file_path(), cfg_old).unwrap_or_else(|err| {
|
||||||
@@ -207,7 +203,7 @@ macro_rules! std_config_load {
|
|||||||
/// new one created
|
/// new one created
|
||||||
pub trait $trait_name<$($generic),*>
|
pub trait $trait_name<$($generic),*>
|
||||||
where
|
where
|
||||||
Self: $crate::StdConfig +std::fmt::Debug + DeserializeOwned + Serialize,
|
Self: $crate::StdConfig + DeserializeOwned + Serialize,
|
||||||
$($generic: DeserializeOwned + Into<Self>),*
|
$($generic: DeserializeOwned + Into<Self>),*
|
||||||
{
|
{
|
||||||
fn load(mut self) -> Self {
|
fn load(mut self) -> Self {
|
||||||
@@ -274,6 +270,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let _ = Test {};
|
||||||
|
|
||||||
impl crate::StdConfigLoad1<Old1> for Test {}
|
impl crate::StdConfigLoad1<Old1> for Test {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,6 +321,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let _ = Test {};
|
||||||
|
|
||||||
impl crate::StdConfigLoad3<Old1, Old2, Old3> for Test {}
|
impl crate::StdConfigLoad3<Old1, Old2, Old3> for Test {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "cpuctl"
|
|
||||||
license.workspace = true
|
|
||||||
version.workspace = true
|
|
||||||
readme.workspace = true
|
|
||||||
authors.workspace = true
|
|
||||||
repository.workspace = true
|
|
||||||
homepage.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
pub fn add(left: usize, right: usize) -> usize {
|
|
||||||
left + right
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
let result = add(2, 2);
|
|
||||||
assert_eq!(result, 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,24 +3,24 @@
|
|||||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||||
<busconfig>
|
<busconfig>
|
||||||
<policy group="adm">
|
<policy group="adm">
|
||||||
<allow send_destination="org.asuslinux.Daemon"/>
|
<allow send_destination="xyz.ljones.Asusd"/>
|
||||||
<allow receive_sender="org.asuslinux.Daemon"/>
|
<allow receive_sender="xyz.ljones.Asusd"/>
|
||||||
</policy>
|
</policy>
|
||||||
<policy group="sudo">
|
<policy group="sudo">
|
||||||
<allow send_destination="org.asuslinux.Daemon"/>
|
<allow send_destination="xyz.ljones.Asusd"/>
|
||||||
<allow receive_sender="org.asuslinux.Daemon"/>
|
<allow receive_sender="xyz.ljones.Asusd"/>
|
||||||
</policy>
|
</policy>
|
||||||
<policy group="users">
|
<policy group="users">
|
||||||
<allow send_destination="org.asuslinux.Daemon"/>
|
<allow send_destination="xyz.ljones.Asusd"/>
|
||||||
<allow receive_sender="org.asuslinux.Daemon"/>
|
<allow receive_sender="xyz.ljones.Asusd"/>
|
||||||
</policy>
|
</policy>
|
||||||
<policy group="wheel">
|
<policy group="wheel">
|
||||||
<allow send_destination="org.asuslinux.Daemon"/>
|
<allow send_destination="xyz.ljones.Asusd"/>
|
||||||
<allow receive_sender="org.asuslinux.Daemon"/>
|
<allow receive_sender="xyz.ljones.Asusd"/>
|
||||||
</policy>
|
</policy>
|
||||||
<policy user="root">
|
<policy user="root">
|
||||||
<allow own="org.asuslinux.Daemon"/>
|
<allow own="xyz.ljones.Asusd"/>
|
||||||
<allow send_destination="org.asuslinux.Daemon"/>
|
<allow send_destination="xyz.ljones.Asusd"/>
|
||||||
<allow receive_sender="org.asuslinux.Daemon"/>
|
<allow receive_sender="xyz.ljones.Asusd"/>
|
||||||
</policy>
|
</policy>
|
||||||
</busconfig>
|
</busconfig>
|
||||||
|
|||||||
@@ -7,11 +7,16 @@ ENV{DMI_FAMILY}=="*ROG*", GOTO="asusd_start"
|
|||||||
ENV{DMI_FAMILY}=="*Zephyrus*", GOTO="asusd_start"
|
ENV{DMI_FAMILY}=="*Zephyrus*", GOTO="asusd_start"
|
||||||
ENV{DMI_FAMILY}=="*Strix*", GOTO="asusd_start"
|
ENV{DMI_FAMILY}=="*Strix*", GOTO="asusd_start"
|
||||||
ENV{DMI_FAMILY}=="*Vivo*ook*", GOTO="asusd_start"
|
ENV{DMI_FAMILY}=="*Vivo*ook*", GOTO="asusd_start"
|
||||||
|
ENV{DMI_FAMILY}=="*Zenbook*", GOTO="asusd_start"
|
||||||
|
ENV{DMI_FAMILY}=="*ProArt*", GOTO="asusd_start"
|
||||||
|
ENV{DMI_FAMILY}=="*TX Air*", GOTO="asusd_start"
|
||||||
|
ENV{DMI_FAMILY}=="*TX Gaming*", GOTO="asusd_start"
|
||||||
|
ENV{DMI_FAMILY}=="*EXPERTBOOK*", GOTO="asusd_start"
|
||||||
# No match so
|
# No match so
|
||||||
GOTO="asusd_end"
|
GOTO="asusd_end"
|
||||||
|
|
||||||
LABEL="asusd_start"
|
LABEL="asusd_start"
|
||||||
ACTION=="add|change", DRIVER=="asus-nb-wmi", TAG+="systemd", ENV{SYSTEMD_WANTS}="asusd.service"
|
ACTION=="add|change", DRIVER=="asus-nb-wmi", TAG+="systemd", ENV{SYSTEMD_WANTS}+="asusd.service"
|
||||||
ACTION=="add|remove", DRIVER=="asus-nb-wmi", TAG+="systemd", RUN+="systemctl restart asusd.service"
|
ACTION=="add|remove", DRIVER=="asus-nb-wmi", TAG+="systemd", ENV{SYSTEMD_WANTS}+="asusd.service"
|
||||||
|
|
||||||
LABEL="asusd_end"
|
LABEL="asusd_end"
|
||||||
|
|||||||
@@ -6,13 +6,17 @@ After=nvidia-powerd.service systemd-udevd.service
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Environment=IS_SERVICE=1
|
Environment=IS_SERVICE=1
|
||||||
Environment=RUST_LOG="info"
|
# Reduce noisy span logs while keeping useful debug info for asusd and related crates.
|
||||||
|
# Keep global level at info but allow debug for our crates; silence tracing::span (very noisy)
|
||||||
|
# RUST_LOG format: <module>=<level>,... (levels: error,warn,info,debug,trace)
|
||||||
|
Environment=RUST_LOG="info,asusd=debug,rog_platform=debug,tracing::span=error,zbus::object_server=error,zbus::connection::handshake::common=error,zbus::connection::handshake::client=error"
|
||||||
# required to prevent init issues with hid_asus and MCU
|
# required to prevent init issues with hid_asus and MCU
|
||||||
ExecStartPre=/bin/sleep 1
|
ExecStartPre=/bin/sleep 1
|
||||||
ExecStart=/usr/bin/asusd
|
ExecStart=/usr/bin/asusd
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=1
|
RestartSec=1
|
||||||
Type=dbus
|
Type=dbus
|
||||||
BusName=org.asuslinux.Daemon
|
BusName=xyz.ljones.Asusd
|
||||||
SELinuxContext=system_u:system_r:unconfined_t:s0
|
SELinuxContext=system_u:system_r:unconfined_t:s0
|
||||||
#SELinuxContext=system_u:object_r:modules_object_t:s0
|
#SELinuxContext=system_u:object_r:modules_object_t:s0
|
||||||
|
TimeoutSec=10
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 75 KiB |
@@ -135,7 +135,7 @@ impl crate::ZbusAdd for CtrlAnimeZbus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
#[dbus_interface(name = "xyz.ljones.Asusd")]
|
||||||
impl CtrlAnimeZbus {
|
impl CtrlAnimeZbus {
|
||||||
async fn <zbus method>() {
|
async fn <zbus method>() {
|
||||||
let lock = self.inner.lock().await;
|
let lock = self.inner.lock().await;
|
||||||
|
|||||||
134
distro-packaging/asusctl.spec
Executable file → Normal file
134
distro-packaging/asusctl.spec
Executable file → Normal file
@@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# spec file for package asus-nb-ctrl
|
# spec file for package asus-nb-ctrl
|
||||||
#
|
#
|
||||||
# Copyright (c) 2020-2021 Luke Jones <luke@ljones.dev>
|
# Copyright (c) 2020-2025 Luke Jones <luke@ljones.dev>
|
||||||
#
|
#
|
||||||
# All modifications and additions to the file contributed by third parties
|
# All modifications and additions to the file contributed by third parties
|
||||||
# remain the property of their copyright owners, unless otherwise agreed
|
# remain the property of their copyright owners, unless otherwise agreed
|
||||||
@@ -20,36 +20,43 @@
|
|||||||
%global debug_package %{nil}
|
%global debug_package %{nil}
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
%global rpm_dkms_opt 1
|
%define version 6.2.0
|
||||||
|
%define specrelease %{?dist}
|
||||||
|
%define pkg_release 1%{specrelease}
|
||||||
|
|
||||||
# Use hardening ldflags.
|
# Use hardening ldflags.
|
||||||
%global rustflags -Clink-arg=-Wl,-z,relro,-z,now
|
%global rustflags -Clink-arg=-Wl,-z,relro,-z,now
|
||||||
Name: asusctl
|
Name: asusctl
|
||||||
Version: 4.7.0
|
Version: %{version}
|
||||||
Release: 2
|
Release: %{pkg_release}
|
||||||
Summary: Control fan speeds, LEDs, graphics modes, and charge levels for ASUS notebooks
|
Summary: Control fan speeds, LEDs, graphics modes, and charge levels for ASUS notebooks
|
||||||
License: MPLv2
|
License: MPLv2
|
||||||
|
|
||||||
Group: System Environment/Kernel
|
Group: System Environment/Kernel
|
||||||
|
|
||||||
URL: https://gitlab.com/asus-linux/asusctl
|
URL: https://gitlab.com/asus-linux/asusctl
|
||||||
Source: %{name}-%{version}.tar.gz
|
Source: https://gitlab.com/asus-linux/asusctl/-/archive/%{version}/%{name}-%{version}.tar.gz
|
||||||
Source1: vendor-%{name}-%{version}.tar.gz
|
|
||||||
Source2: cargo_config
|
|
||||||
|
|
||||||
BuildRequires: cargo
|
%if %{defined fedora}
|
||||||
BuildRequires: rust-packaging
|
BuildRequires: rust-packaging
|
||||||
BuildRequires: systemd-rpm-macros
|
BuildRequires: systemd-rpm-macros
|
||||||
|
%else
|
||||||
|
BuildRequires: cargo-packaging
|
||||||
|
%endif
|
||||||
|
BuildRequires: git
|
||||||
BuildRequires: clang-devel
|
BuildRequires: clang-devel
|
||||||
|
BuildRequires: cargo
|
||||||
BuildRequires: cmake
|
BuildRequires: cmake
|
||||||
BuildRequires: rust
|
BuildRequires: rust
|
||||||
BuildRequires: rust-std-static
|
BuildRequires: rust-std-static
|
||||||
BuildRequires: pkgconfig(dbus-1)
|
BuildRequires: pkgconfig(gbm)
|
||||||
|
BuildRequires: pkgconfig(libinput)
|
||||||
|
BuildRequires: pkgconfig(libseat)
|
||||||
BuildRequires: pkgconfig(libudev)
|
BuildRequires: pkgconfig(libudev)
|
||||||
BuildRequires: pkgconfig(gtk+-3.0)
|
BuildRequires: pkgconfig(xkbcommon)
|
||||||
BuildRequires: pkgconfig(gdk-3.0)
|
BuildRequires: pkgconfig(libzstd)
|
||||||
|
BuildRequires: pkgconfig(fontconfig)
|
||||||
BuildRequires: desktop-file-utils
|
BuildRequires: desktop-file-utils
|
||||||
Requires: libappindicator-gtk3
|
|
||||||
|
|
||||||
%description
|
%description
|
||||||
asus-nb-ctrl is a utility for Linux to control many aspects of various
|
asus-nb-ctrl is a utility for Linux to control many aspects of various
|
||||||
@@ -61,6 +68,7 @@ asus-nb-ctrl enables third-party apps to use the above with dbus methods.
|
|||||||
|
|
||||||
%package rog-gui
|
%package rog-gui
|
||||||
Summary: An experimental GUI for %{name}
|
Summary: An experimental GUI for %{name}
|
||||||
|
Requires: %{name} = %{version}-%{release}
|
||||||
|
|
||||||
%description rog-gui
|
%description rog-gui
|
||||||
A one-stop-shop GUI tool for asusd/asusctl. It aims to provide most controls,
|
A one-stop-shop GUI tool for asusd/asusctl. It aims to provide most controls,
|
||||||
@@ -68,30 +76,85 @@ a notification service, and ability to run in the background.
|
|||||||
|
|
||||||
%prep
|
%prep
|
||||||
%autosetup
|
%autosetup
|
||||||
%setup -D -T -a 1 -c -n %{name}-%{version}/vendor
|
mkdir -p .cargo
|
||||||
cd ..
|
cat > .cargo/config.toml << 'EOF'
|
||||||
|
[term]
|
||||||
mv Cargo.lock{,.bak}
|
verbose = true
|
||||||
%cargo_prep
|
[net]
|
||||||
mv Cargo.lock{.bak,}
|
offline = false
|
||||||
sed -i 's|replace-with = "local-registry"|replace-with = "vendored-sources"|' .cargo/config
|
EOF
|
||||||
cat %{SOURCE2} >> .cargo/config
|
|
||||||
|
|
||||||
%build
|
%build
|
||||||
export RUSTFLAGS="%{rustflags}"
|
export RUSTFLAGS="%{rustflags}"
|
||||||
%cargo_build
|
%if %{defined fedora}
|
||||||
#cargo build --release --frozen --offline --config .cargo/config.toml
|
/usr/bin/cargo build --release --locked
|
||||||
|
%else
|
||||||
|
/usr/bin/cargo auditable build --release --locked
|
||||||
|
%endif
|
||||||
|
|
||||||
%install
|
%install
|
||||||
export RUSTFLAGS="%{rustflags}"
|
export RUSTFLAGS="%{rustflags}"
|
||||||
mkdir -p "%{buildroot}/%{_bindir}" "%{buildroot}%{_docdir}"
|
|
||||||
%make_install
|
|
||||||
|
|
||||||
install -D -m 0644 README.md %{buildroot}/%{_docdir}/%{name}/README.md
|
|
||||||
install -D -m 0644 rog-anime/README.md %{buildroot}/%{_docdir}/%{name}/README-anime.md
|
|
||||||
install -D -m 0644 rog-anime/data/diagonal-template.png %{buildroot}/%{_docdir}/%{name}/diagonal-template.png
|
|
||||||
|
|
||||||
desktop-file-validate %{buildroot}/%{_datadir}/applications/rog-control-center.desktop
|
%define _target_dir target/release
|
||||||
|
|
||||||
|
# Install binaries
|
||||||
|
install -D -m 0755 %{_target_dir}/asusd %{buildroot}%{_bindir}/asusd
|
||||||
|
install -D -m 0755 %{_target_dir}/asusd-user %{buildroot}%{_bindir}/asusd-user
|
||||||
|
install -D -m 0755 %{_target_dir}/asusctl %{buildroot}%{_bindir}/asusctl
|
||||||
|
install -D -m 0755 %{_target_dir}/rog-control-center %{buildroot}%{_bindir}/rog-control-center
|
||||||
|
|
||||||
|
# Install systemd units
|
||||||
|
install -D -m 0644 data/asusd.service %{buildroot}%{_unitdir}/asusd.service
|
||||||
|
install -D -m 0644 data/asusd-user.service %{buildroot}%{_userunitdir}/asusd-user.service
|
||||||
|
|
||||||
|
# Install udev rules
|
||||||
|
install -D -m 0644 data/asusd.rules %{buildroot}%{_udevrulesdir}/99-asusd.rules
|
||||||
|
|
||||||
|
# Install dbus config
|
||||||
|
install -D -m 0644 data/asusd.conf %{buildroot}%{_datadir}/dbus-1/system.d/asusd.conf
|
||||||
|
|
||||||
|
# Install asusd data
|
||||||
|
install -D -m 0644 rog-aura/data/aura_support.ron %{buildroot}%{_datadir}/asusd/aura_support.ron
|
||||||
|
cp -r rog-anime/data/anime %{buildroot}%{_datadir}/asusd/
|
||||||
|
|
||||||
|
# Install rog-gui data
|
||||||
|
install -D -m 0644 rog-control-center/data/rog-control-center.desktop %{buildroot}%{_datadir}/applications/rog-control-center.desktop
|
||||||
|
install -D -m 0644 rog-control-center/data/rog-control-center.png %{buildroot}%{_datadir}/icons/hicolor/512x512/apps/rog-control-center.png
|
||||||
|
mkdir -p %{buildroot}%{_datadir}/rog-gui/layouts
|
||||||
|
cp -r rog-aura/data/layouts/*.ron %{buildroot}%{_datadir}/rog-gui/layouts/
|
||||||
|
|
||||||
|
# Install icons
|
||||||
|
install -D -m 0644 data/icons/asus_notif_yellow.png %{buildroot}%{_datadir}/icons/hicolor/512x512/apps/asus_notif_yellow.png
|
||||||
|
install -D -m 0644 data/icons/asus_notif_green.png %{buildroot}%{_datadir}/icons/hicolor/512x512/apps/asus_notif_green.png
|
||||||
|
install -D -m 0644 data/icons/asus_notif_blue.png %{buildroot}%{_datadir}/icons/hicolor/512x512/apps/asus_notif_blue.png
|
||||||
|
install -D -m 0644 data/icons/asus_notif_red.png %{buildroot}%{_datadir}/icons/hicolor/512x512/apps/asus_notif_red.png
|
||||||
|
install -D -m 0644 data/icons/asus_notif_orange.png %{buildroot}%{_datadir}/icons/hicolor/512x512/apps/asus_notif_orange.png
|
||||||
|
install -D -m 0644 data/icons/asus_notif_white.png %{buildroot}%{_datadir}/icons/hicolor/512x512/apps/asus_notif_white.png
|
||||||
|
install -D -m 0644 data/icons/scalable/gpu-compute.svg %{buildroot}%{_datadir}/icons/hicolor/scalable/status/gpu-compute.svg
|
||||||
|
install -D -m 0644 data/icons/scalable/gpu-hybrid.svg %{buildroot}%{_datadir}/icons/hicolor/scalable/status/gpu-hybrid.svg
|
||||||
|
install -D -m 0644 data/icons/scalable/gpu-integrated.svg %{buildroot}%{_datadir}/icons/hicolor/scalable/status/gpu-integrated.svg
|
||||||
|
install -D -m 0644 data/icons/scalable/gpu-nvidia.svg %{buildroot}%{_datadir}/icons/hicolor/scalable/status/gpu-nvidia.svg
|
||||||
|
install -D -m 0644 data/icons/scalable/gpu-vfio.svg %{buildroot}%{_datadir}/icons/hicolor/scalable/status/gpu-vfio.svg
|
||||||
|
install -D -m 0644 data/icons/scalable/notification-reboot.svg %{buildroot}%{_datadir}/icons/hicolor/scalable/status/notification-reboot.svg
|
||||||
|
|
||||||
|
# Install docs
|
||||||
|
install -D -m 0644 README.md %{buildroot}%{_docdir}/%{name}/README.md
|
||||||
|
install -D -m 0644 rog-anime/README.md %{buildroot}%{_docdir}/%{name}/README-anime.md
|
||||||
|
install -D -m 0644 rog-anime/data/diagonal-template.png %{buildroot}%{_docdir}/%{name}/diagonal-template.png
|
||||||
|
|
||||||
|
# Install LICENSE to asusctl datadir
|
||||||
|
install -D -m 0644 LICENSE %{buildroot}%{_datadir}/asusctl/LICENSE
|
||||||
|
|
||||||
|
desktop-file-validate %{buildroot}%{_datadir}/applications/rog-control-center.desktop
|
||||||
|
|
||||||
|
%post
|
||||||
|
%systemd_post asusd.service
|
||||||
|
|
||||||
|
%preun
|
||||||
|
%systemd_preun asusd.service
|
||||||
|
|
||||||
|
%postun
|
||||||
|
%systemd_postun_with_restart asusd.service
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%license LICENSE
|
%license LICENSE
|
||||||
@@ -101,8 +164,6 @@ desktop-file-validate %{buildroot}/%{_datadir}/applications/rog-control-center.d
|
|||||||
%{_unitdir}/asusd.service
|
%{_unitdir}/asusd.service
|
||||||
%{_userunitdir}/asusd-user.service
|
%{_userunitdir}/asusd-user.service
|
||||||
%{_udevrulesdir}/99-asusd.rules
|
%{_udevrulesdir}/99-asusd.rules
|
||||||
#%dir %{_sysconfdir}/asusd/
|
|
||||||
%{_datadir}/asusd/aura_support.ron
|
|
||||||
%{_datadir}/dbus-1/system.d/asusd.conf
|
%{_datadir}/dbus-1/system.d/asusd.conf
|
||||||
%{_datadir}/icons/hicolor/512x512/apps/asus_notif_yellow.png
|
%{_datadir}/icons/hicolor/512x512/apps/asus_notif_yellow.png
|
||||||
%{_datadir}/icons/hicolor/512x512/apps/asus_notif_green.png
|
%{_datadir}/icons/hicolor/512x512/apps/asus_notif_green.png
|
||||||
@@ -117,6 +178,7 @@ desktop-file-validate %{buildroot}/%{_datadir}/applications/rog-control-center.d
|
|||||||
%{_datadir}/icons/hicolor/scalable/status/gpu-vfio.svg
|
%{_datadir}/icons/hicolor/scalable/status/gpu-vfio.svg
|
||||||
%{_datadir}/icons/hicolor/scalable/status/notification-reboot.svg
|
%{_datadir}/icons/hicolor/scalable/status/notification-reboot.svg
|
||||||
%{_docdir}/%{name}/
|
%{_docdir}/%{name}/
|
||||||
|
%{_datadir}/asusctl/
|
||||||
%{_datadir}/asusd/
|
%{_datadir}/asusd/
|
||||||
|
|
||||||
%files rog-gui
|
%files rog-gui
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use log::{info, warn};
|
use log::warn;
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Clone)]
|
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Clone)]
|
||||||
pub struct DMIID {
|
pub struct DMIID {
|
||||||
@@ -33,8 +33,6 @@ impl DMIID {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Some(device) = (result).next() {
|
if let Some(device) = (result).next() {
|
||||||
info!("Found dmi ID info at {:?}", device.sysname());
|
|
||||||
|
|
||||||
return Ok(Self {
|
return Ok(Self {
|
||||||
id_model: device
|
id_model: device
|
||||||
.property_value("ID_MODEL")
|
.property_value("ID_MODEL")
|
||||||
|
|||||||
@@ -28,17 +28,9 @@ gif.workspace = true
|
|||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
|
||||||
|
|
||||||
glam.workspace = true
|
glam.workspace = true
|
||||||
typeshare.workspace = true
|
|
||||||
|
|
||||||
zbus = { workspace = true, optional = true }
|
zbus = { workspace = true, optional = true }
|
||||||
|
|
||||||
dmi_id = { path = "../dmi-id", optional = true }
|
dmi_id = { path = "../dmi-id", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
cargo-husky.workspace = true
|
|
||||||
|
|
||||||
[package.metadata.cargo-machete]
|
|
||||||
ignored = ["serde"]
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ use std::str::FromStr;
|
|||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use dmi_id::DMIID;
|
||||||
use log::info;
|
use log::info;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use typeshare::typeshare;
|
|
||||||
#[cfg(feature = "dbus")]
|
#[cfg(feature = "dbus")]
|
||||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||||
|
|
||||||
@@ -22,15 +22,19 @@ const BLOCK_END: usize = 634;
|
|||||||
const PANE_LEN: usize = BLOCK_END - BLOCK_START;
|
const PANE_LEN: usize = BLOCK_END - BLOCK_START;
|
||||||
|
|
||||||
/// First packet is for GA401 + GA402
|
/// First packet is for GA401 + GA402
|
||||||
pub const USB_PREFIX1: [u8; 7] = [0x5e, 0xc0, 0x02, 0x01, 0x00, 0x73, 0x02];
|
pub const USB_PREFIX1: [u8; 7] = [
|
||||||
|
0x5e, 0xc0, 0x02, 0x01, 0x00, 0x73, 0x02,
|
||||||
|
];
|
||||||
/// Second packet is for GA401 + GA402
|
/// Second packet is for GA401 + GA402
|
||||||
pub const USB_PREFIX2: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02];
|
pub const USB_PREFIX2: [u8; 7] = [
|
||||||
|
0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02,
|
||||||
|
];
|
||||||
/// Third packet is for GA402 matrix
|
/// Third packet is for GA402 matrix
|
||||||
pub const USB_PREFIX3: [u8; 7] = [0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02];
|
pub const USB_PREFIX3: [u8; 7] = [
|
||||||
|
0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02,
|
||||||
|
];
|
||||||
|
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||||
#[typeshare]
|
|
||||||
#[derive(Default, Deserialize, PartialEq, Eq, Clone, Copy, Serialize, Debug)]
|
#[derive(Default, Deserialize, PartialEq, Eq, Clone, Copy, Serialize, Debug)]
|
||||||
pub struct Animations {
|
pub struct Animations {
|
||||||
pub boot: AnimBooting,
|
pub boot: AnimBooting,
|
||||||
@@ -40,9 +44,7 @@ pub struct Animations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move this out
|
// TODO: move this out
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||||
#[typeshare]
|
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||||
pub struct DeviceState {
|
pub struct DeviceState {
|
||||||
pub display_enabled: bool,
|
pub display_enabled: bool,
|
||||||
@@ -55,34 +57,61 @@ pub struct DeviceState {
|
|||||||
pub brightness_on_battery: Brightness,
|
pub brightness_on_battery: Brightness,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
|
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, Default)]
|
||||||
pub enum AnimeType {
|
pub enum AnimeType {
|
||||||
GA401,
|
GA401,
|
||||||
GA402,
|
GA402,
|
||||||
GU604,
|
GU604,
|
||||||
Unknown,
|
G635L,
|
||||||
|
G835L,
|
||||||
|
#[default]
|
||||||
|
Unsupported,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for AnimeType {
|
impl FromStr for AnimeType {
|
||||||
type Err = AnimeError;
|
type Err = AnimeError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||||
Ok(match s {
|
let dmi = s.to_uppercase();
|
||||||
"ga401" | "GA401" => Self::GA401,
|
|
||||||
"ga402" | "GA402" => Self::GA402,
|
if dmi.contains("GA401") {
|
||||||
"gu604" | "GU604" => Self::GU604,
|
return Ok(Self::GA401);
|
||||||
_ => Self::Unknown,
|
} else if dmi.contains("GA402") {
|
||||||
})
|
return Ok(Self::GA402);
|
||||||
|
} else if dmi.contains("GU604") {
|
||||||
|
return Ok(Self::GU604);
|
||||||
|
} else if dmi.contains("G635L") {
|
||||||
|
return Ok(Self::G635L);
|
||||||
|
} else if dmi.contains("G835L") {
|
||||||
|
return Ok(Self::G835L);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Self::Unsupported)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnimeType {
|
impl AnimeType {
|
||||||
|
pub fn from_dmi() -> Self {
|
||||||
|
let board_name = DMIID::new().unwrap_or_default().board_name.to_uppercase();
|
||||||
|
if board_name.contains("GA401I") || board_name.contains("GA401Q") {
|
||||||
|
AnimeType::GA401
|
||||||
|
} else if board_name.contains("GA402R") || board_name.contains("GA402X") {
|
||||||
|
AnimeType::GA402
|
||||||
|
} else if board_name.contains("GU604V") {
|
||||||
|
AnimeType::GU604
|
||||||
|
} else if board_name.contains("G635L") || board_name.contains("G635L") {
|
||||||
|
AnimeType::G635L
|
||||||
|
} else {
|
||||||
|
AnimeType::Unsupported
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The width of diagonal images
|
/// The width of diagonal images
|
||||||
pub fn width(&self) -> usize {
|
pub fn width(&self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
AnimeType::GU604 => 70,
|
AnimeType::GU604 => 70,
|
||||||
|
AnimeType::G835L => 74,
|
||||||
_ => 74,
|
_ => 74,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,6 +121,7 @@ impl AnimeType {
|
|||||||
match self {
|
match self {
|
||||||
AnimeType::GA401 => 36,
|
AnimeType::GA401 => 36,
|
||||||
AnimeType::GU604 => 43,
|
AnimeType::GU604 => 43,
|
||||||
|
AnimeType::G835L => 39,
|
||||||
_ => 39,
|
_ => 39,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,6 +131,7 @@ impl AnimeType {
|
|||||||
match self {
|
match self {
|
||||||
AnimeType::GA401 => PANE_LEN * 2,
|
AnimeType::GA401 => PANE_LEN * 2,
|
||||||
AnimeType::GU604 => PANE_LEN * 3,
|
AnimeType::GU604 => PANE_LEN * 3,
|
||||||
|
AnimeType::G835L => PANE_LEN * 3,
|
||||||
_ => PANE_LEN * 3,
|
_ => PANE_LEN * 3,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +196,13 @@ impl TryFrom<AnimeDataBuffer> for AnimePacketType {
|
|||||||
|
|
||||||
let mut buffers = match anime.anime {
|
let mut buffers = match anime.anime {
|
||||||
AnimeType::GA401 => vec![[0; 640]; 2],
|
AnimeType::GA401 => vec![[0; 640]; 2],
|
||||||
AnimeType::GA402 | AnimeType::GU604 | AnimeType::Unknown => vec![[0; 640]; 3],
|
AnimeType::GA402
|
||||||
|
| AnimeType::GU604
|
||||||
|
| AnimeType::G635L
|
||||||
|
| AnimeType::G835L
|
||||||
|
| AnimeType::Unsupported => {
|
||||||
|
vec![[0; 640]; 3]
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (idx, chunk) in anime.data.as_slice().chunks(PANE_LEN).enumerate() {
|
for (idx, chunk) in anime.data.as_slice().chunks(PANE_LEN).enumerate() {
|
||||||
@@ -176,7 +213,11 @@ impl TryFrom<AnimeDataBuffer> for AnimePacketType {
|
|||||||
|
|
||||||
if matches!(
|
if matches!(
|
||||||
anime.anime,
|
anime.anime,
|
||||||
AnimeType::GA402 | AnimeType::GU604 | AnimeType::Unknown
|
AnimeType::GA402
|
||||||
|
| AnimeType::GU604
|
||||||
|
| AnimeType::G635L
|
||||||
|
| AnimeType::G835L
|
||||||
|
| AnimeType::Unsupported
|
||||||
) {
|
) {
|
||||||
buffers[2][..7].copy_from_slice(&USB_PREFIX3);
|
buffers[2][..7].copy_from_slice(&USB_PREFIX3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use log::error;
|
||||||
|
|
||||||
use crate::data::AnimeDataBuffer;
|
use crate::data::AnimeDataBuffer;
|
||||||
use crate::error::{AnimeError, Result};
|
use crate::error::{AnimeError, Result};
|
||||||
use crate::AnimeType;
|
use crate::AnimeType;
|
||||||
@@ -49,7 +51,10 @@ impl AnimeDiagonal {
|
|||||||
bright: f32,
|
bright: f32,
|
||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let data = std::fs::read(path)?;
|
let data = std::fs::read(path).map_err(|e| {
|
||||||
|
error!("Could not open {path:?}: {e:?}");
|
||||||
|
e
|
||||||
|
})?;
|
||||||
let data = std::io::Cursor::new(data);
|
let data = std::io::Cursor::new(data);
|
||||||
let decoder = png_pong::Decoder::new(data)?.into_steps();
|
let decoder = png_pong::Decoder::new(data)?.into_steps();
|
||||||
let png_pong::Step { raster, delay: _ } = decoder.last().ok_or(AnimeError::NoFrames)??;
|
let png_pong::Step { raster, delay: _ } = decoder.last().ok_or(AnimeError::NoFrames)??;
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ use std::path::Path;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use log::error;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::{AnimeError, Result};
|
use crate::error::{AnimeError, Result};
|
||||||
use crate::{AnimeDataBuffer, AnimeDiagonal, AnimeImage, AnimeType, Pixel};
|
use crate::{AnimeDataBuffer, AnimeDiagonal, AnimeImage, AnimeType, Pixel};
|
||||||
@@ -107,7 +108,10 @@ impl AnimeGif {
|
|||||||
// Configure the decoder such that it will expand the image to RGBA.
|
// Configure the decoder such that it will expand the image to RGBA.
|
||||||
decoder.set_color_output(gif::ColorOutput::RGBA);
|
decoder.set_color_output(gif::ColorOutput::RGBA);
|
||||||
// Read the file header
|
// Read the file header
|
||||||
let file = File::open(file_name)?;
|
let file = File::open(file_name).map_err(|e| {
|
||||||
|
error!("Could not open {file_name:?}: {e:?}");
|
||||||
|
e
|
||||||
|
})?;
|
||||||
let mut decoder = decoder.read_info(file)?;
|
let mut decoder = decoder.read_info(file)?;
|
||||||
|
|
||||||
let mut frames = Vec::default();
|
let mut frames = Vec::default();
|
||||||
@@ -186,12 +190,14 @@ impl AnimeGif {
|
|||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let mut frames = Vec::new();
|
let mut frames = Vec::new();
|
||||||
|
|
||||||
let mut decoder = gif::DecodeOptions::new();
|
let mut decoder = gif::DecodeOptions::new();
|
||||||
// Configure the decoder such that it will expand the image to RGBA.
|
// Configure the decoder such that it will expand the image to RGBA.
|
||||||
decoder.set_color_output(gif::ColorOutput::RGBA);
|
decoder.set_color_output(gif::ColorOutput::RGBA);
|
||||||
// Read the file header
|
// Read the file header
|
||||||
let file = File::open(file_name)?;
|
let file = File::open(file_name).map_err(|e| {
|
||||||
|
error!("Could not open {file_name:?}: {e:?}");
|
||||||
|
e
|
||||||
|
})?;
|
||||||
let mut decoder = decoder.read_info(file)?;
|
let mut decoder = decoder.read_info(file)?;
|
||||||
|
|
||||||
let height = decoder.height();
|
let height = decoder.height();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::path::Path;
|
|||||||
|
|
||||||
pub use glam::Vec2;
|
pub use glam::Vec2;
|
||||||
use glam::{Mat3, Vec3};
|
use glam::{Mat3, Vec3};
|
||||||
|
use log::error;
|
||||||
|
|
||||||
use crate::data::AnimeDataBuffer;
|
use crate::data::AnimeDataBuffer;
|
||||||
use crate::error::{AnimeError, Result};
|
use crate::error::{AnimeError, Result};
|
||||||
@@ -168,7 +169,7 @@ impl AnimeImage {
|
|||||||
// first 5 rows for GA401 are always at X = 0
|
// first 5 rows for GA401 are always at X = 0
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
(y + 1) / 2 - 3
|
y.div_ceil(2) - 3
|
||||||
}
|
}
|
||||||
AnimeType::GU604 => {
|
AnimeType::GU604 => {
|
||||||
// first 9 rows start at zero
|
// first 9 rows start at zero
|
||||||
@@ -184,7 +185,7 @@ impl AnimeImage {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// and then their offset grows by one every two rows
|
// and then their offset grows by one every two rows
|
||||||
(y + 1) / 2 - 5
|
y.div_ceil(2) - 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,7 +213,7 @@ impl AnimeImage {
|
|||||||
// First 5 rows for GA401 are always 33 physical LEDs long
|
// First 5 rows for GA401 are always 33 physical LEDs long
|
||||||
return 33;
|
return 33;
|
||||||
}
|
}
|
||||||
36 - (y + 1) / 2
|
36 - y.div_ceil(2)
|
||||||
}
|
}
|
||||||
AnimeType::GU604 => {
|
AnimeType::GU604 => {
|
||||||
if y <= 9 {
|
if y <= 9 {
|
||||||
@@ -320,7 +321,9 @@ impl AnimeImage {
|
|||||||
let pos = Vec3::new(led.x(), led.y(), 1.0);
|
let pos = Vec3::new(led.x(), led.y(), 1.0);
|
||||||
let x0 = led_from_px.mul_vec3(pos + Vec3::new(0.0, -0.5, 0.0));
|
let x0 = led_from_px.mul_vec3(pos + Vec3::new(0.0, -0.5, 0.0));
|
||||||
|
|
||||||
const GROUP: [f32; 4] = [0.0, 0.5, 1.0, 1.5];
|
const GROUP: [f32; 4] = [
|
||||||
|
0.0, 0.5, 1.0, 1.5,
|
||||||
|
];
|
||||||
for u in &GROUP {
|
for u in &GROUP {
|
||||||
for v in &GROUP {
|
for v in &GROUP {
|
||||||
let sample = x0 + *u * du + *v * dv;
|
let sample = x0 + *u * du + *v * dv;
|
||||||
@@ -421,7 +424,10 @@ impl AnimeImage {
|
|||||||
bright: f32,
|
bright: f32,
|
||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let data = std::fs::read(path)?;
|
let data = std::fs::read(path).map_err(|e| {
|
||||||
|
error!("Could not open {path:?}: {e:?}");
|
||||||
|
e
|
||||||
|
})?;
|
||||||
let data = std::io::Cursor::new(data);
|
let data = std::io::Cursor::new(data);
|
||||||
let decoder = png_pong::Decoder::new(data)?.into_steps();
|
let decoder = png_pong::Decoder::new(data)?.into_steps();
|
||||||
let png_pong::Step { raster, delay: _ } = decoder.last().ok_or(AnimeError::NoFrames)??;
|
let png_pong::Step { raster, delay: _ } = decoder.last().ok_or(AnimeError::NoFrames)??;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::path::PathBuf;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
use crate::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType};
|
use crate::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType};
|
||||||
@@ -75,10 +75,7 @@ impl ActionData {
|
|||||||
time,
|
time,
|
||||||
brightness,
|
brightness,
|
||||||
} => ActionData::Animation(AnimeGif::from_diagonal_gif(
|
} => ActionData::Animation(AnimeGif::from_diagonal_gif(
|
||||||
file,
|
file, *time, *brightness, anime_type,
|
||||||
*time,
|
|
||||||
*brightness,
|
|
||||||
anime_type,
|
|
||||||
)?),
|
)?),
|
||||||
ActionLoader::AsusImage {
|
ActionLoader::AsusImage {
|
||||||
file,
|
file,
|
||||||
@@ -91,10 +88,7 @@ impl ActionData {
|
|||||||
ActionData::Image(Box::new(data))
|
ActionData::Image(Box::new(data))
|
||||||
}
|
}
|
||||||
_ => ActionData::Animation(AnimeGif::from_diagonal_png(
|
_ => ActionData::Animation(AnimeGif::from_diagonal_png(
|
||||||
file,
|
file, anime_type, *time, *brightness,
|
||||||
anime_type,
|
|
||||||
*time,
|
|
||||||
*brightness,
|
|
||||||
)?),
|
)?),
|
||||||
},
|
},
|
||||||
ActionLoader::ImageAnimation {
|
ActionLoader::ImageAnimation {
|
||||||
@@ -108,24 +102,12 @@ impl ActionData {
|
|||||||
if let Some(ext) = file.extension() {
|
if let Some(ext) = file.extension() {
|
||||||
if ext.to_string_lossy().to_lowercase() == "png" {
|
if ext.to_string_lossy().to_lowercase() == "png" {
|
||||||
return Ok(ActionData::Animation(AnimeGif::from_png(
|
return Ok(ActionData::Animation(AnimeGif::from_png(
|
||||||
file,
|
file, *scale, *angle, *translation, *time, *brightness, anime_type,
|
||||||
*scale,
|
|
||||||
*angle,
|
|
||||||
*translation,
|
|
||||||
*time,
|
|
||||||
*brightness,
|
|
||||||
anime_type,
|
|
||||||
)?));
|
)?));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ActionData::Animation(AnimeGif::from_gif(
|
ActionData::Animation(AnimeGif::from_gif(
|
||||||
file,
|
file, *scale, *angle, *translation, *time, *brightness, anime_type,
|
||||||
*scale,
|
|
||||||
*angle,
|
|
||||||
*translation,
|
|
||||||
*time,
|
|
||||||
*brightness,
|
|
||||||
anime_type,
|
|
||||||
)?)
|
)?)
|
||||||
}
|
}
|
||||||
ActionLoader::Image {
|
ActionLoader::Image {
|
||||||
@@ -140,24 +122,13 @@ impl ActionData {
|
|||||||
AnimTime::Infinite => {
|
AnimTime::Infinite => {
|
||||||
// If no time then create a plain static image
|
// If no time then create a plain static image
|
||||||
let image = AnimeImage::from_png(
|
let image = AnimeImage::from_png(
|
||||||
file,
|
file, *scale, *angle, *translation, *brightness, anime_type,
|
||||||
*scale,
|
|
||||||
*angle,
|
|
||||||
*translation,
|
|
||||||
*brightness,
|
|
||||||
anime_type,
|
|
||||||
)?;
|
)?;
|
||||||
let data = <AnimeDataBuffer>::try_from(&image)?;
|
let data = <AnimeDataBuffer>::try_from(&image)?;
|
||||||
ActionData::Image(Box::new(data))
|
ActionData::Image(Box::new(data))
|
||||||
}
|
}
|
||||||
_ => ActionData::Animation(AnimeGif::from_png(
|
_ => ActionData::Animation(AnimeGif::from_png(
|
||||||
file,
|
file, *scale, *angle, *translation, *time, *brightness, anime_type,
|
||||||
*scale,
|
|
||||||
*angle,
|
|
||||||
*translation,
|
|
||||||
*time,
|
|
||||||
*brightness,
|
|
||||||
anime_type,
|
|
||||||
)?),
|
)?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use dmi_id::DMIID;
|
use dmi_id::DMIID;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use typeshare::typeshare;
|
|
||||||
#[cfg(feature = "dbus")]
|
#[cfg(feature = "dbus")]
|
||||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||||
|
|
||||||
@@ -29,7 +28,6 @@ pub const PROD_ID: u16 = 0x193b;
|
|||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
zvariant(signature = "u")
|
zvariant(signature = "u")
|
||||||
)]
|
)]
|
||||||
#[typeshare]
|
|
||||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||||
/// Base LED brightness of the display
|
/// Base LED brightness of the display
|
||||||
pub enum Brightness {
|
pub enum Brightness {
|
||||||
@@ -82,7 +80,6 @@ impl From<Brightness> for i32 {
|
|||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
zvariant(signature = "s")
|
zvariant(signature = "s")
|
||||||
)]
|
)]
|
||||||
#[typeshare]
|
|
||||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||||
pub enum AnimBooting {
|
pub enum AnimBooting {
|
||||||
#[default]
|
#[default]
|
||||||
@@ -123,7 +120,6 @@ impl From<AnimBooting> for i32 {
|
|||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
zvariant(signature = "s")
|
zvariant(signature = "s")
|
||||||
)]
|
)]
|
||||||
#[typeshare]
|
|
||||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||||
pub enum AnimAwake {
|
pub enum AnimAwake {
|
||||||
#[default]
|
#[default]
|
||||||
@@ -164,7 +160,6 @@ impl From<AnimAwake> for i32 {
|
|||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
zvariant(signature = "s")
|
zvariant(signature = "s")
|
||||||
)]
|
)]
|
||||||
#[typeshare]
|
|
||||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||||
pub enum AnimSleeping {
|
pub enum AnimSleeping {
|
||||||
#[default]
|
#[default]
|
||||||
@@ -205,7 +200,6 @@ impl From<AnimSleeping> for i32 {
|
|||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
zvariant(signature = "s")
|
zvariant(signature = "s")
|
||||||
)]
|
)]
|
||||||
#[typeshare]
|
|
||||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||||
pub enum AnimShutdown {
|
pub enum AnimShutdown {
|
||||||
#[default]
|
#[default]
|
||||||
@@ -241,25 +235,29 @@ impl From<AnimShutdown> for i32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `get_anime_type` is very broad, matching on part of the laptop board name
|
/// `get_maybe_anime_type` is very broad, matching on part of the laptop board
|
||||||
/// only. For this reason `find_node()` must be used also to verify if the USB
|
/// name only. For this reason `find_node()` must be used also to verify if the
|
||||||
/// device is available.
|
/// USB device is available.
|
||||||
///
|
///
|
||||||
/// The currently known USB device is `19b6`.
|
/// The currently known USB device is `19b6`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_anime_type() -> Result<AnimeType, AnimeError> {
|
pub fn get_anime_type() -> AnimeType {
|
||||||
let dmi = DMIID::new().map_err(|_| AnimeError::NoDevice)?; // TODO: better error
|
let dmi = DMIID::new().unwrap_or_default();
|
||||||
let board_name = dmi.board_name;
|
let board_name = dmi.board_name.to_uppercase();
|
||||||
|
|
||||||
if board_name.contains("GA401I") || board_name.contains("GA401Q") {
|
if board_name.contains("GA401I") || board_name.contains("GA401Q") {
|
||||||
return Ok(AnimeType::GA401);
|
AnimeType::GA401
|
||||||
} else if board_name.contains("GA402R") {
|
} else if board_name.contains("GA402R") || board_name.contains("GA402X") {
|
||||||
return Ok(AnimeType::GA402);
|
AnimeType::GA402
|
||||||
} else if board_name.contains("GU604V") {
|
} else if board_name.contains("GU604V") {
|
||||||
return Ok(AnimeType::GU604);
|
AnimeType::GU604
|
||||||
|
} else if board_name.contains("G635L") {
|
||||||
|
AnimeType::G635L
|
||||||
|
} else if board_name.contains("G835L") {
|
||||||
|
AnimeType::G835L
|
||||||
|
} else {
|
||||||
|
AnimeType::Unsupported
|
||||||
}
|
}
|
||||||
log::warn!("AniMe Matrix device found but not yet supported, will default to a GA402 layout");
|
|
||||||
Ok(AnimeType::Unknown)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the two device initialization packets. These are required for device
|
/// Get the two device initialization packets. These are required for device
|
||||||
|
|||||||
@@ -18,15 +18,10 @@ dbus = ["zbus"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
|
||||||
zbus = { workspace = true, optional = true }
|
zbus = { workspace = true, optional = true }
|
||||||
dmi_id = { path = "../dmi-id" }
|
dmi_id = { path = "../dmi-id" }
|
||||||
|
|
||||||
# cli and logging
|
# cli and logging
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
typeshare.workspace = true
|
|
||||||
|
|
||||||
ron = { version = "*", optional = true }
|
ron = { version = "*", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
cargo-husky.workspace = true
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
375
rog-aura/data/layouts/g635l-per-key_US.ron
Normal file
375
rog-aura/data/layouts/g635l-per-key_US.ron
Normal file
@@ -0,0 +1,375 @@
|
|||||||
|
(
|
||||||
|
locale: "US",
|
||||||
|
key_shapes: {
|
||||||
|
"regular": Led(
|
||||||
|
width: 1.0,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"regular_spacing": Blank(
|
||||||
|
width: 1.2,
|
||||||
|
height: 0.0,
|
||||||
|
),
|
||||||
|
"rog_row": Led(
|
||||||
|
width: 1.0,
|
||||||
|
height: 0.7,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.6,
|
||||||
|
),
|
||||||
|
"rog_row_blocking": Blank(
|
||||||
|
width: 1.2,
|
||||||
|
height: 0.0,
|
||||||
|
),
|
||||||
|
"func_space": Blank(
|
||||||
|
width: 0.6,
|
||||||
|
height: 0.0,
|
||||||
|
),
|
||||||
|
"backspace": Led(
|
||||||
|
width: 2.2,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"tab": Led(
|
||||||
|
width: 1.6,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"backslash": Led(
|
||||||
|
width: 1.6,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"capsplonk": Led(
|
||||||
|
width: 2.0,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"return": Led(
|
||||||
|
width: 2.4,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"lshift": Led(
|
||||||
|
width: 2.6,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"rshift": Led(
|
||||||
|
width: 3.0,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"lctrl": Led(
|
||||||
|
width: 1.4,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"spacebar": Led(
|
||||||
|
width: 5.8,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"rctrl": Led(
|
||||||
|
width: 1.2,
|
||||||
|
height: 1.0,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"up_arrow": Led(
|
||||||
|
width: 0.8,
|
||||||
|
height: 0.8,
|
||||||
|
pad_left: 1.1,
|
||||||
|
pad_right: 1.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"arrows_spacer": Blank(
|
||||||
|
width: 15.0,
|
||||||
|
height: 0.0,
|
||||||
|
),
|
||||||
|
"arrows": Led(
|
||||||
|
width: 0.8,
|
||||||
|
height: 0.8,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: -0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
),
|
||||||
|
"row_end_spacing": Blank(
|
||||||
|
width: 0.4,
|
||||||
|
height: 0.0,
|
||||||
|
),
|
||||||
|
"lid_logo": Led(
|
||||||
|
width: 2.6,
|
||||||
|
height: 1.2,
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.8,
|
||||||
|
pad_bottom: 0.0,
|
||||||
|
),
|
||||||
|
"lightbar_left": Led(
|
||||||
|
width: 0.6,
|
||||||
|
height: 3.6,
|
||||||
|
pad_left: -1.2,
|
||||||
|
pad_right: 0.2,
|
||||||
|
pad_top: -3.0,
|
||||||
|
pad_bottom: 0.3,
|
||||||
|
),
|
||||||
|
"lightbar_corner_left": Led(
|
||||||
|
width: 0.8,
|
||||||
|
height: 0.6,
|
||||||
|
pad_left: -0.6,
|
||||||
|
pad_right: 0.2,
|
||||||
|
pad_top: 0.8,
|
||||||
|
pad_bottom: 0.0,
|
||||||
|
),
|
||||||
|
"lightbar_bottom": Led(
|
||||||
|
width: 12.6,
|
||||||
|
height: 0.5,
|
||||||
|
pad_left: -0.1,
|
||||||
|
pad_right: -0.1,
|
||||||
|
pad_top: 0.8,
|
||||||
|
pad_bottom: 0.0,
|
||||||
|
),
|
||||||
|
"lightbar_corner_right": Led(
|
||||||
|
width: 0.8,
|
||||||
|
height: 0.6,
|
||||||
|
pad_left: 0.0,
|
||||||
|
pad_right: 0.2,
|
||||||
|
pad_top: 0.8,
|
||||||
|
pad_bottom: 0.0,
|
||||||
|
),
|
||||||
|
"lightbar_right": Led(
|
||||||
|
width: 0.6,
|
||||||
|
height: 3.6,
|
||||||
|
pad_left: -0.8,
|
||||||
|
pad_right: 0.2,
|
||||||
|
pad_top: -3.0,
|
||||||
|
pad_bottom: 0.3,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
key_rows: [
|
||||||
|
(
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(Blocking, "rog_row_blocking"),
|
||||||
|
(Blocking, "rog_row_blocking"),
|
||||||
|
(VolDown, "rog_row"),
|
||||||
|
(VolUp, "rog_row"),
|
||||||
|
(MicMute, "rog_row"),
|
||||||
|
(RogFan, "rog_row"),
|
||||||
|
(RogApp, "rog_row"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(Esc, "regular"),
|
||||||
|
(Spacing, "regular_spacing"),
|
||||||
|
(F1, "regular"),
|
||||||
|
(F2, "regular"),
|
||||||
|
(F3, "regular"),
|
||||||
|
(F4, "regular"),
|
||||||
|
(Spacing, "func_space"),
|
||||||
|
(F5, "regular"),
|
||||||
|
(F6, "regular"),
|
||||||
|
(F7, "regular"),
|
||||||
|
(F8, "regular"),
|
||||||
|
(Spacing, "func_space"),
|
||||||
|
(F9, "regular"),
|
||||||
|
(F10, "regular"),
|
||||||
|
(F11, "regular"),
|
||||||
|
(F12, "regular"),
|
||||||
|
(Spacing, "row_end_spacing"),
|
||||||
|
(Del, "regular"), // Should be super/insert
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(Tilde, "regular"),
|
||||||
|
(N1, "regular"),
|
||||||
|
(N2, "regular"),
|
||||||
|
(N3, "regular"),
|
||||||
|
(N4, "regular"),
|
||||||
|
(N5, "regular"),
|
||||||
|
(N6, "regular"),
|
||||||
|
(N7, "regular"),
|
||||||
|
(N8, "regular"),
|
||||||
|
(N9, "regular"),
|
||||||
|
(N0, "regular"),
|
||||||
|
(Hyphen, "regular"),
|
||||||
|
(Equals, "regular"),
|
||||||
|
(Backspace, "backspace"),
|
||||||
|
(Spacing, "row_end_spacing"),
|
||||||
|
(MediaPlay, "regular"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(Tab, "tab"),
|
||||||
|
(Q, "regular"),
|
||||||
|
(W, "regular"),
|
||||||
|
(E, "regular"),
|
||||||
|
(R, "regular"),
|
||||||
|
(T, "regular"),
|
||||||
|
(Y, "regular"),
|
||||||
|
(U, "regular"),
|
||||||
|
(I, "regular"),
|
||||||
|
(O, "regular"),
|
||||||
|
(P, "regular"),
|
||||||
|
(LBracket, "regular"),
|
||||||
|
(RBracket, "regular"),
|
||||||
|
(BackSlash, "backslash"),
|
||||||
|
(Spacing, "row_end_spacing"),
|
||||||
|
(MediaStop, "regular"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(Caps, "capsplonk"),
|
||||||
|
(A, "regular"),
|
||||||
|
(S, "regular"),
|
||||||
|
(D, "regular"),
|
||||||
|
(F, "regular"),
|
||||||
|
(G, "regular"),
|
||||||
|
(H, "regular"),
|
||||||
|
(J, "regular"),
|
||||||
|
(K, "regular"),
|
||||||
|
(L, "regular"),
|
||||||
|
(SemiColon, "regular"),
|
||||||
|
(Quote, "regular"),
|
||||||
|
(Return, "return"),
|
||||||
|
(Spacing, "row_end_spacing"),
|
||||||
|
(MediaNext, "regular"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(LShift, "lshift"),
|
||||||
|
(Z, "regular"),
|
||||||
|
(X, "regular"),
|
||||||
|
(C, "regular"),
|
||||||
|
(V, "regular"),
|
||||||
|
(B, "regular"),
|
||||||
|
(N, "regular"),
|
||||||
|
(M, "regular"),
|
||||||
|
(Comma, "regular"),
|
||||||
|
(Period, "regular"),
|
||||||
|
(FwdSlash, "regular"),
|
||||||
|
(Rshift, "rshift"),
|
||||||
|
(Spacing, "row_end_spacing"),
|
||||||
|
(MediaPrev, "regular"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(LCtrl, "lctrl"),
|
||||||
|
(LFn, "regular"),
|
||||||
|
(Meta, "regular"),
|
||||||
|
(LAlt, "regular"),
|
||||||
|
(Spacebar, "spacebar"),
|
||||||
|
(RAlt, "regular"),
|
||||||
|
(PrtSc, "regular"),
|
||||||
|
(RCtrl, "rctrl"),
|
||||||
|
(Up, "up_arrow"),
|
||||||
|
(Spacing, "row_end_spacing"),
|
||||||
|
(PrtSc, "regular"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(Spacing, "arrows_spacer"),
|
||||||
|
(Left, "arrows"),
|
||||||
|
(Down, "arrows"),
|
||||||
|
(Right, "arrows"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
pad_left: 6.5,
|
||||||
|
pad_right: 6.5,
|
||||||
|
pad_top: 0.2,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(LidLogo, "lid_logo"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
pad_left: 0.1,
|
||||||
|
pad_right: 0.1,
|
||||||
|
pad_top: 0.1,
|
||||||
|
pad_bottom: 0.1,
|
||||||
|
row: [
|
||||||
|
(LightbarLeft, "lightbar_left"),
|
||||||
|
(LightbarLeftCorner, "lightbar_corner_left"),
|
||||||
|
(LightbarLeftBottom, "lightbar_bottom"),
|
||||||
|
(LightbarRightBottom, "lightbar_bottom"),
|
||||||
|
(LightbarRightCorner, "lightbar_corner_right"),
|
||||||
|
(LightbarRight, "lightbar_right"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
use std::env;
|
||||||
|
|
||||||
use dmi_id::DMIID;
|
use dmi_id::DMIID;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::keyboard::AdvancedAuraType;
|
use crate::keyboard::AdvancedAuraType;
|
||||||
use crate::{AuraModeNum, AuraZone, PowerZones};
|
use crate::{AuraModeNum, AuraZone, PowerZones};
|
||||||
@@ -60,17 +62,20 @@ impl LedSupportData {
|
|||||||
/// matches against laptops first, then will proceed with matching the
|
/// matches against laptops first, then will proceed with matching the
|
||||||
/// `device_name` if there are no DMI matches.
|
/// `device_name` if there are no DMI matches.
|
||||||
pub fn get_data(product_id: &str) -> Self {
|
pub fn get_data(product_id: &str) -> Self {
|
||||||
let dmi = DMIID::new().unwrap_or_default();
|
let mut dmi = DMIID::new().unwrap_or_default();
|
||||||
|
if let Ok(board_name) = env::var("BOARD_NAME") {
|
||||||
|
dmi.board_name = board_name;
|
||||||
|
}
|
||||||
// let prod_family = dmi.product_family().expect("Could not get
|
// let prod_family = dmi.product_family().expect("Could not get
|
||||||
// product_family");
|
// product_family");
|
||||||
|
|
||||||
if let Some(data) = LedSupportFile::load_from_supoprt_db() {
|
if let Some(data) = LedSupportFile::load_from_supoprt_db() {
|
||||||
if let Some(data) = data.match_device(&dmi.board_name, product_id) {
|
return data.match_device(&dmi.board_name, product_id);
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
info!("Using generic LED control for keyboard brightness only");
|
info!("Using generic LED control for keyboard brightness only. No aura_support file found");
|
||||||
LedSupportData::default()
|
let mut data = LedSupportData::default();
|
||||||
|
data.power_zones.push(PowerZones::Keyboard);
|
||||||
|
data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +89,7 @@ impl LedSupportFile {
|
|||||||
|
|
||||||
/// The list is stored in ordered format, so the iterator must be reversed
|
/// The list is stored in ordered format, so the iterator must be reversed
|
||||||
/// to ensure we match to *whole names* first before doing a glob match
|
/// to ensure we match to *whole names* first before doing a glob match
|
||||||
fn match_device(&self, device_name: &str, product_id: &str) -> Option<LedSupportData> {
|
fn match_device(&self, device_name: &str, product_id: &str) -> LedSupportData {
|
||||||
for config in self.0.iter().rev() {
|
for config in self.0.iter().rev() {
|
||||||
if device_name.contains(&config.device_name) {
|
if device_name.contains(&config.device_name) {
|
||||||
info!("Matched to {}", config.device_name);
|
info!("Matched to {}", config.device_name);
|
||||||
@@ -92,15 +97,27 @@ impl LedSupportFile {
|
|||||||
info!("Checking product ID");
|
info!("Checking product ID");
|
||||||
if config.product_id == product_id {
|
if config.product_id == product_id {
|
||||||
info!("Matched to {}", config.product_id);
|
info!("Matched to {}", config.product_id);
|
||||||
return Some(config.clone());
|
return config.clone();
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Some(config.clone());
|
return config.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
warn!(
|
||||||
|
"the aura_support.ron file has no entry for this model: {device_name}, {product_id}. \
|
||||||
|
Using a default"
|
||||||
|
);
|
||||||
|
LedSupportData {
|
||||||
|
device_name: device_name.to_owned(),
|
||||||
|
product_id: product_id.to_owned(),
|
||||||
|
layout_name: "Default".to_owned(),
|
||||||
|
basic_modes: vec![AuraModeNum::Static],
|
||||||
|
basic_zones: vec![],
|
||||||
|
advanced_type: AdvancedAuraType::None,
|
||||||
|
power_zones: vec![PowerZones::Keyboard],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load `LedSupportFile` from the `aura_support.ron` file at
|
/// Load `LedSupportFile` from the `aura_support.ron` file at
|
||||||
@@ -147,6 +164,25 @@ impl LedSupportFile {
|
|||||||
return Some(data);
|
return Some(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the system-wide files were not found (typical in CI or
|
||||||
|
// development environments), attempt to load the bundled
|
||||||
|
// `data/aura_support.ron` from the crate so tests and local runs
|
||||||
|
// behave the same as when the package is installed.
|
||||||
|
// Attempt to load a bundled `aura_support.ron` included at compile time.
|
||||||
|
// Using `include_str!` ensures the data is available regardless of
|
||||||
|
// runtime `CARGO_MANIFEST_DIR` or CI environment differences.
|
||||||
|
let bundled_buf = include_str!("../data/aura_support.ron");
|
||||||
|
if !bundled_buf.is_empty() {
|
||||||
|
if let Ok(tmp) = ron::from_str::<LedSupportFile>(bundled_buf) {
|
||||||
|
data.0.append(&mut tmp.0.clone());
|
||||||
|
data.0.sort_by(|a, b| a.device_name.cmp(&b.device_name));
|
||||||
|
info!("Loaded bundled LED support data (embedded)");
|
||||||
|
return Some(data);
|
||||||
|
} else {
|
||||||
|
warn!("Could not parse embedded bundled data file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
warn!("Does {} exist?", ASUS_LED_MODE_USER_CONF);
|
warn!("Does {} exist?", ASUS_LED_MODE_USER_CONF);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -154,6 +190,7 @@ impl LedSupportFile {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -173,9 +210,16 @@ mod tests {
|
|||||||
product_id: String::new(),
|
product_id: String::new(),
|
||||||
layout_name: "ga401".to_owned(),
|
layout_name: "ga401".to_owned(),
|
||||||
basic_modes: vec![AuraModeNum::Static],
|
basic_modes: vec![AuraModeNum::Static],
|
||||||
basic_zones: vec![AuraZone::Key1, AuraZone::Logo, AuraZone::BarLeft],
|
basic_zones: vec![
|
||||||
|
AuraZone::Key1,
|
||||||
|
AuraZone::Logo,
|
||||||
|
AuraZone::BarLeft,
|
||||||
|
],
|
||||||
advanced_type: AdvancedAuraType::Zoned(vec![LedCode::LightbarRight]),
|
advanced_type: AdvancedAuraType::Zoned(vec![LedCode::LightbarRight]),
|
||||||
power_zones: vec![PowerZones::Keyboard, PowerZones::RearGlow],
|
power_zones: vec![
|
||||||
|
PowerZones::Keyboard,
|
||||||
|
PowerZones::RearGlow,
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(ron::to_string(&led).is_ok());
|
assert!(ron::to_string(&led).is_ok());
|
||||||
@@ -195,6 +239,9 @@ mod tests {
|
|||||||
let mut tmp_sort = tmp.clone();
|
let mut tmp_sort = tmp.clone();
|
||||||
tmp_sort.0.sort_by(|a, b| a.product_id.cmp(&b.product_id));
|
tmp_sort.0.sort_by(|a, b| a.product_id.cmp(&b.product_id));
|
||||||
tmp_sort.0.sort_by(|a, b| a.device_name.cmp(&b.device_name));
|
tmp_sort.0.sort_by(|a, b| a.device_name.cmp(&b.device_name));
|
||||||
|
for model in tmp_sort.0.iter_mut() {
|
||||||
|
model.basic_modes.sort_by_key(|a| *a as u8);
|
||||||
|
}
|
||||||
if tmp != tmp_sort {
|
if tmp != tmp_sort {
|
||||||
let sorted =
|
let sorted =
|
||||||
ron::ser::to_string_pretty(&tmp_sort, PrettyConfig::new().depth_limit(2)).unwrap();
|
ron::ser::to_string_pretty(&tmp_sort, PrettyConfig::new().depth_limit(2)).unwrap();
|
||||||
@@ -217,4 +264,31 @@ mod tests {
|
|||||||
ron::ser::to_string_pretty(&tmp, my_config).unwrap()
|
ron::ser::to_string_pretty(&tmp, my_config).unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn find_data_file_groups() {
|
||||||
|
let mut data = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
data.push("data/aura_support.ron");
|
||||||
|
|
||||||
|
let buf = std::fs::read_to_string(&data).unwrap();
|
||||||
|
|
||||||
|
let tmp = ron::from_str::<LedSupportFile>(&buf).unwrap();
|
||||||
|
|
||||||
|
let mut modes: HashMap<Vec<AuraModeNum>, Vec<String>> = HashMap::new();
|
||||||
|
|
||||||
|
for entry in tmp.0 {
|
||||||
|
if let Some(modes) = modes.get_mut(&entry.basic_modes) {
|
||||||
|
modes.push(entry.device_name);
|
||||||
|
} else {
|
||||||
|
modes.insert(entry.basic_modes, vec![entry.device_name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dbg!(modes);
|
||||||
|
|
||||||
|
// let my_config = PrettyConfig::new().depth_limit(2);
|
||||||
|
// println!(
|
||||||
|
// "RON: {}",
|
||||||
|
// ron::ser::to_string_pretty(&tmp, my_config).unwrap()
|
||||||
|
// );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use typeshare::typeshare;
|
|
||||||
#[cfg(feature = "dbus")]
|
#[cfg(feature = "dbus")]
|
||||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::LED_MSG_LEN;
|
use crate::AURA_LAPTOP_LED_MSG_LEN;
|
||||||
|
|
||||||
#[typeshare]
|
|
||||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "dbus",
|
feature = "dbus",
|
||||||
@@ -79,7 +77,6 @@ impl From<i32> for LedBrightness {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Copy, Deserialize, Serialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Copy, Deserialize, Serialize)]
|
||||||
pub struct Colour {
|
pub struct Colour {
|
||||||
@@ -120,7 +117,11 @@ impl From<&[f32; 3]> for Colour {
|
|||||||
|
|
||||||
impl From<Colour> for [f32; 3] {
|
impl From<Colour> for [f32; 3] {
|
||||||
fn from(c: Colour) -> Self {
|
fn from(c: Colour) -> Self {
|
||||||
[c.r as f32 / 255.0, c.g as f32 / 255.0, c.b as f32 / 255.0]
|
[
|
||||||
|
c.r as f32 / 255.0,
|
||||||
|
c.g as f32 / 255.0,
|
||||||
|
c.b as f32 / 255.0,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +137,12 @@ impl From<&[u8; 3]> for Colour {
|
|||||||
|
|
||||||
impl From<Colour> for [u8; 3] {
|
impl From<Colour> for [u8; 3] {
|
||||||
fn from(c: Colour) -> Self {
|
fn from(c: Colour) -> Self {
|
||||||
[c.r, c.g, c.b]
|
[
|
||||||
|
c.r, c.g, c.b,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "dbus",
|
feature = "dbus",
|
||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
@@ -200,7 +202,6 @@ impl From<Speed> for u8 {
|
|||||||
/// Used for Rainbow mode.
|
/// Used for Rainbow mode.
|
||||||
///
|
///
|
||||||
/// Enum corresponds to the required integer value
|
/// Enum corresponds to the required integer value
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "dbus",
|
feature = "dbus",
|
||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
@@ -248,7 +249,6 @@ impl From<Direction> for i32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Enum of modes that convert to the actual number required by a USB HID packet
|
/// Enum of modes that convert to the actual number required by a USB HID packet
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "dbus",
|
feature = "dbus",
|
||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
@@ -261,8 +261,8 @@ pub enum AuraModeNum {
|
|||||||
#[default]
|
#[default]
|
||||||
Static = 0,
|
Static = 0,
|
||||||
Breathe = 1,
|
Breathe = 1,
|
||||||
Strobe = 2,
|
RainbowCycle = 2,
|
||||||
Rainbow = 3,
|
RainbowWave = 3,
|
||||||
Star = 4,
|
Star = 4,
|
||||||
Rain = 5,
|
Rain = 5,
|
||||||
Highlight = 6,
|
Highlight = 6,
|
||||||
@@ -290,8 +290,8 @@ impl From<&AuraModeNum> for &str {
|
|||||||
match mode {
|
match mode {
|
||||||
AuraModeNum::Static => "Static",
|
AuraModeNum::Static => "Static",
|
||||||
AuraModeNum::Breathe => "Breathe",
|
AuraModeNum::Breathe => "Breathe",
|
||||||
AuraModeNum::Strobe => "Strobe",
|
AuraModeNum::RainbowCycle => "RainbowCycle",
|
||||||
AuraModeNum::Rainbow => "Rainbow",
|
AuraModeNum::RainbowWave => "RainbowWave",
|
||||||
AuraModeNum::Star => "Stars",
|
AuraModeNum::Star => "Stars",
|
||||||
AuraModeNum::Rain => "Rain",
|
AuraModeNum::Rain => "Rain",
|
||||||
AuraModeNum::Highlight => "Highlight",
|
AuraModeNum::Highlight => "Highlight",
|
||||||
@@ -307,8 +307,8 @@ impl From<&str> for AuraModeNum {
|
|||||||
fn from(mode: &str) -> Self {
|
fn from(mode: &str) -> Self {
|
||||||
match mode {
|
match mode {
|
||||||
"Breathe" => AuraModeNum::Breathe,
|
"Breathe" => AuraModeNum::Breathe,
|
||||||
"Strobe" => AuraModeNum::Strobe,
|
"RainbowCycle" => AuraModeNum::RainbowCycle,
|
||||||
"Rainbow" => AuraModeNum::Rainbow,
|
"RainbowWave" => AuraModeNum::RainbowWave,
|
||||||
"Stars" => AuraModeNum::Star,
|
"Stars" => AuraModeNum::Star,
|
||||||
"Rain" => AuraModeNum::Rain,
|
"Rain" => AuraModeNum::Rain,
|
||||||
"Highlight" => AuraModeNum::Highlight,
|
"Highlight" => AuraModeNum::Highlight,
|
||||||
@@ -326,8 +326,8 @@ impl From<u8> for AuraModeNum {
|
|||||||
fn from(mode: u8) -> Self {
|
fn from(mode: u8) -> Self {
|
||||||
match mode {
|
match mode {
|
||||||
1 => AuraModeNum::Breathe,
|
1 => AuraModeNum::Breathe,
|
||||||
2 => AuraModeNum::Strobe,
|
2 => AuraModeNum::RainbowCycle,
|
||||||
3 => AuraModeNum::Rainbow,
|
3 => AuraModeNum::RainbowWave,
|
||||||
4 => AuraModeNum::Star,
|
4 => AuraModeNum::Star,
|
||||||
5 => AuraModeNum::Rain,
|
5 => AuraModeNum::Rain,
|
||||||
6 => AuraModeNum::Highlight,
|
6 => AuraModeNum::Highlight,
|
||||||
@@ -359,8 +359,13 @@ impl From<AuraEffect> for AuraModeNum {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dbus")]
|
||||||
|
impl zbus::zvariant::Basic for AuraModeNum {
|
||||||
|
const SIGNATURE_CHAR: char = 'u';
|
||||||
|
const SIGNATURE_STR: &'static str = "u";
|
||||||
|
}
|
||||||
|
|
||||||
/// Base effects have no zoning, while multizone is 1-4
|
/// Base effects have no zoning, while multizone is 1-4
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "dbus",
|
feature = "dbus",
|
||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
@@ -432,9 +437,8 @@ impl From<AuraZone> for i32 {
|
|||||||
/// ```rust
|
/// ```rust
|
||||||
/// // let bytes: [u8; LED_MSG_LEN] = mode.into();
|
/// // let bytes: [u8; LED_MSG_LEN] = mode.into();
|
||||||
/// ```
|
/// ```
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct AuraEffect {
|
pub struct AuraEffect {
|
||||||
/// The effect type
|
/// The effect type
|
||||||
pub mode: AuraModeNum,
|
pub mode: AuraModeNum,
|
||||||
@@ -494,56 +498,6 @@ impl Display for AuraEffect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AuraParameters {
|
|
||||||
pub zone: bool,
|
|
||||||
pub colour1: bool,
|
|
||||||
pub colour2: bool,
|
|
||||||
pub speed: bool,
|
|
||||||
pub direction: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::fn_params_excessive_bools)]
|
|
||||||
impl AuraParameters {
|
|
||||||
pub const fn new(
|
|
||||||
zone: bool,
|
|
||||||
colour1: bool,
|
|
||||||
colour2: bool,
|
|
||||||
speed: bool,
|
|
||||||
direction: bool,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
zone,
|
|
||||||
colour1,
|
|
||||||
colour2,
|
|
||||||
speed,
|
|
||||||
direction,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AuraEffect {
|
|
||||||
/// A helper to provide detail on what effects have which parameters, e.g
|
|
||||||
/// the static factory mode accepts only one colour.
|
|
||||||
pub const fn allowed_parameters(mode: AuraModeNum) -> AuraParameters {
|
|
||||||
match mode {
|
|
||||||
AuraModeNum::Static
|
|
||||||
| AuraModeNum::Highlight
|
|
||||||
| AuraModeNum::Pulse
|
|
||||||
| AuraModeNum::Comet
|
|
||||||
| AuraModeNum::Flash => AuraParameters::new(true, true, false, false, false),
|
|
||||||
AuraModeNum::Breathe => AuraParameters::new(true, true, true, true, false),
|
|
||||||
AuraModeNum::Strobe | AuraModeNum::Rain => {
|
|
||||||
AuraParameters::new(true, false, false, true, false)
|
|
||||||
}
|
|
||||||
AuraModeNum::Rainbow => AuraParameters::new(true, false, false, true, true),
|
|
||||||
AuraModeNum::Star => AuraParameters::new(true, true, true, true, true),
|
|
||||||
AuraModeNum::Laser | AuraModeNum::Ripple => {
|
|
||||||
AuraParameters::new(true, true, false, true, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses `AuraEffect` in to packet data for writing to the USB interface
|
/// Parses `AuraEffect` in to packet data for writing to the USB interface
|
||||||
///
|
///
|
||||||
/// Byte structure where colour is RGB, one byte per R, G, B:
|
/// Byte structure where colour is RGB, one byte per R, G, B:
|
||||||
@@ -552,9 +506,9 @@ impl AuraEffect {
|
|||||||
/// |---|---|-----|-----|---------|------|----------|---|-----------|
|
/// |---|---|-----|-----|---------|------|----------|---|-----------|
|
||||||
/// |5d |b3 |Zone |Mode |Colour 1 |Speed |Direction |00 |Colour 2 |
|
/// |5d |b3 |Zone |Mode |Colour 1 |Speed |Direction |00 |Colour 2 |
|
||||||
/// ```
|
/// ```
|
||||||
impl From<&AuraEffect> for [u8; LED_MSG_LEN] {
|
impl From<&AuraEffect> for [u8; AURA_LAPTOP_LED_MSG_LEN] {
|
||||||
fn from(aura: &AuraEffect) -> Self {
|
fn from(aura: &AuraEffect) -> Self {
|
||||||
let mut msg = [0u8; LED_MSG_LEN];
|
let mut msg = [0u8; AURA_LAPTOP_LED_MSG_LEN];
|
||||||
msg[0] = 0x5d;
|
msg[0] = 0x5d;
|
||||||
msg[1] = 0xb3;
|
msg[1] = 0xb3;
|
||||||
msg[2] = aura.zone as u8;
|
msg[2] = aura.zone as u8;
|
||||||
@@ -573,7 +527,7 @@ impl From<&AuraEffect> for [u8; LED_MSG_LEN] {
|
|||||||
|
|
||||||
impl From<&AuraEffect> for Vec<u8> {
|
impl From<&AuraEffect> for Vec<u8> {
|
||||||
fn from(aura: &AuraEffect) -> Self {
|
fn from(aura: &AuraEffect) -> Self {
|
||||||
let mut msg = vec![0u8; LED_MSG_LEN];
|
let mut msg = vec![0u8; AURA_LAPTOP_LED_MSG_LEN];
|
||||||
msg[0] = 0x5d;
|
msg[0] = 0x5d;
|
||||||
msg[1] = 0xb3;
|
msg[1] = 0xb3;
|
||||||
msg[2] = aura.zone as u8;
|
msg[2] = aura.zone as u8;
|
||||||
@@ -592,7 +546,9 @@ impl From<&AuraEffect> for Vec<u8> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{AuraEffect, AuraModeNum, AuraZone, Colour, Direction, Speed, LED_MSG_LEN};
|
use crate::{
|
||||||
|
AuraEffect, AuraModeNum, AuraZone, Colour, Direction, Speed, AURA_LAPTOP_LED_MSG_LEN,
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_led_static_packet() {
|
fn check_led_static_packet() {
|
||||||
@@ -608,7 +564,7 @@ mod tests {
|
|||||||
speed: Speed::Med,
|
speed: Speed::Med,
|
||||||
direction: Direction::Right,
|
direction: Direction::Right,
|
||||||
};
|
};
|
||||||
let ar = <[u8; LED_MSG_LEN]>::from(&st);
|
let ar = <[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st);
|
||||||
|
|
||||||
println!("{:02x?}", ar);
|
println!("{:02x?}", ar);
|
||||||
let check = [
|
let check = [
|
||||||
@@ -636,7 +592,10 @@ mod tests {
|
|||||||
0x5d, 0xb3, 0x01, 0x00, 0xff, 0x00, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
0x5d, 0xb3, 0x01, 0x00, 0xff, 0x00, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
0x0, 0x0,
|
0x0, 0x0,
|
||||||
];
|
];
|
||||||
assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]);
|
assert_eq!(
|
||||||
|
<[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9],
|
||||||
|
capture[..9]
|
||||||
|
);
|
||||||
|
|
||||||
st.zone = AuraZone::Key2;
|
st.zone = AuraZone::Key2;
|
||||||
st.colour1 = Colour {
|
st.colour1 = Colour {
|
||||||
@@ -648,7 +607,10 @@ mod tests {
|
|||||||
0x5d, 0xb3, 0x02, 0x00, 0xff, 0xff, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
0x5d, 0xb3, 0x02, 0x00, 0xff, 0xff, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
0x0, 0x0,
|
0x0, 0x0,
|
||||||
];
|
];
|
||||||
assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]);
|
assert_eq!(
|
||||||
|
<[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9],
|
||||||
|
capture[..9]
|
||||||
|
);
|
||||||
|
|
||||||
st.zone = AuraZone::Key3;
|
st.zone = AuraZone::Key3;
|
||||||
st.colour1 = Colour {
|
st.colour1 = Colour {
|
||||||
@@ -660,7 +622,10 @@ mod tests {
|
|||||||
0x5d, 0xb3, 0x03, 0x00, 0x00, 0xff, 0xff, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
0x5d, 0xb3, 0x03, 0x00, 0x00, 0xff, 0xff, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
0x0, 0x0,
|
0x0, 0x0,
|
||||||
];
|
];
|
||||||
assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]);
|
assert_eq!(
|
||||||
|
<[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9],
|
||||||
|
capture[..9]
|
||||||
|
);
|
||||||
|
|
||||||
st.zone = AuraZone::Key4;
|
st.zone = AuraZone::Key4;
|
||||||
st.colour1 = Colour {
|
st.colour1 = Colour {
|
||||||
@@ -672,7 +637,10 @@ mod tests {
|
|||||||
0x5d, 0xb3, 0x04, 0x00, 0xff, 0x00, 0xff, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
0x5d, 0xb3, 0x04, 0x00, 0xff, 0x00, 0xff, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
0x0, 0x0,
|
0x0, 0x0,
|
||||||
];
|
];
|
||||||
assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]);
|
assert_eq!(
|
||||||
|
<[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9],
|
||||||
|
capture[..9]
|
||||||
|
);
|
||||||
|
|
||||||
st.zone = AuraZone::Logo;
|
st.zone = AuraZone::Logo;
|
||||||
st.colour1 = Colour {
|
st.colour1 = Colour {
|
||||||
@@ -684,7 +652,10 @@ mod tests {
|
|||||||
0x5d, 0xb3, 0x05, 0x00, 0x2c, 0xff, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
0x5d, 0xb3, 0x05, 0x00, 0x2c, 0xff, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
0x0, 0x0,
|
0x0, 0x0,
|
||||||
];
|
];
|
||||||
assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]);
|
assert_eq!(
|
||||||
|
<[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9],
|
||||||
|
capture[..9]
|
||||||
|
);
|
||||||
|
|
||||||
st.zone = AuraZone::BarLeft;
|
st.zone = AuraZone::BarLeft;
|
||||||
st.colour1 = Colour {
|
st.colour1 = Colour {
|
||||||
@@ -696,7 +667,10 @@ mod tests {
|
|||||||
0x5d, 0xb3, 0x06, 0x00, 0xff, 0x00, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
0x5d, 0xb3, 0x06, 0x00, 0xff, 0x00, 0x00, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
0x0, 0x0,
|
0x0, 0x0,
|
||||||
];
|
];
|
||||||
assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]);
|
assert_eq!(
|
||||||
|
<[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9],
|
||||||
|
capture[..9]
|
||||||
|
);
|
||||||
|
|
||||||
st.zone = AuraZone::BarRight;
|
st.zone = AuraZone::BarRight;
|
||||||
st.colour1 = Colour {
|
st.colour1 = Colour {
|
||||||
@@ -708,13 +682,19 @@ mod tests {
|
|||||||
0x5d, 0xb3, 0x07, 0x00, 0xff, 0x00, 0xcd, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
0x5d, 0xb3, 0x07, 0x00, 0xff, 0x00, 0xcd, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
0x0, 0x0,
|
0x0, 0x0,
|
||||||
];
|
];
|
||||||
assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]);
|
assert_eq!(
|
||||||
|
<[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9],
|
||||||
|
capture[..9]
|
||||||
|
);
|
||||||
|
|
||||||
st.mode = AuraModeNum::Rainbow;
|
st.mode = AuraModeNum::RainbowWave;
|
||||||
let capture = [
|
let capture = [
|
||||||
0x5d, 0xb3, 0x07, 0x03, 0xff, 0x00, 0xcd, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
0x5d, 0xb3, 0x07, 0x03, 0xff, 0x00, 0xcd, 0xe1, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||||
0x0, 0x0,
|
0x0, 0x0,
|
||||||
];
|
];
|
||||||
assert_eq!(<[u8; LED_MSG_LEN]>::from(&st)[..9], capture[..9]);
|
assert_eq!(
|
||||||
|
<[u8; AURA_LAPTOP_LED_MSG_LEN]>::from(&st)[..9],
|
||||||
|
capture[..9]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use super::{EffectState, InputForEffect};
|
|||||||
use crate::keyboard::{KeyLayout, LedCode};
|
use crate::keyboard::{KeyLayout, LedCode};
|
||||||
use crate::Colour;
|
use crate::Colour;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct InputBased {
|
pub struct InputBased {
|
||||||
led: LedCode,
|
led: LedCode,
|
||||||
colour: Colour,
|
colour: Colour,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
mod doom;
|
mod doom;
|
||||||
pub use doom::*;
|
pub use doom::*;
|
||||||
@@ -12,7 +12,7 @@ pub use breathe::*;
|
|||||||
mod static_;
|
mod static_;
|
||||||
pub use static_::*;
|
pub use static_::*;
|
||||||
|
|
||||||
use crate::keyboard::{KeyLayout, LedCode, LedUsbPackets, UsbPackets};
|
use crate::keyboard::{AuraLaptopUsbPackets, KeyLayout, LedCode, LedUsbPackets};
|
||||||
use crate::Colour;
|
use crate::Colour;
|
||||||
|
|
||||||
// static mut RNDINDEX: usize = 0;
|
// static mut RNDINDEX: usize = 0;
|
||||||
@@ -106,7 +106,7 @@ impl AdvancedEffects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_packets(&self) -> UsbPackets {
|
pub fn create_packets(&self) -> AuraLaptopUsbPackets {
|
||||||
let mut usb_packets = if self.zoned {
|
let mut usb_packets = if self.zoned {
|
||||||
// TODO: figure out if that single byte difference for multizone actually
|
// TODO: figure out if that single byte difference for multizone actually
|
||||||
// matters
|
// matters
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use log::warn;
|
use log::warn;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use typeshare::typeshare;
|
|
||||||
#[cfg(feature = "dbus")]
|
#[cfg(feature = "dbus")]
|
||||||
use zbus::zvariant::Type;
|
use zbus::zvariant::Type;
|
||||||
|
|
||||||
@@ -194,8 +193,7 @@ impl LedCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the per-key raw USB packets
|
/// Represents the per-key raw USB packets
|
||||||
#[typeshare]
|
pub type AuraLaptopUsbPackets = Vec<Vec<u8>>;
|
||||||
pub type UsbPackets = Vec<Vec<u8>>;
|
|
||||||
|
|
||||||
/// A `UsbPackets` contains all data to change the full set of keyboard
|
/// A `UsbPackets` contains all data to change the full set of keyboard
|
||||||
/// key colours individually.
|
/// key colours individually.
|
||||||
@@ -204,12 +202,11 @@ pub type UsbPackets = Vec<Vec<u8>>;
|
|||||||
/// to the keyboard EC. One row controls one group of keys, these keys are not
|
/// to the keyboard EC. One row controls one group of keys, these keys are not
|
||||||
/// necessarily all on the same row of the keyboard, with some splitting between
|
/// necessarily all on the same row of the keyboard, with some splitting between
|
||||||
/// two rows.
|
/// two rows.
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct LedUsbPackets {
|
pub struct LedUsbPackets {
|
||||||
/// The packet data used to send data to the USB keyboard
|
/// The packet data used to send data to the USB keyboard
|
||||||
usb_packets: UsbPackets,
|
usb_packets: AuraLaptopUsbPackets,
|
||||||
/// Wether or not this packet collection is zoned. The determines which
|
/// Wether or not this packet collection is zoned. The determines which
|
||||||
/// starting bytes are used and what the indexing is for lightbar RGB
|
/// starting bytes are used and what the indexing is for lightbar RGB
|
||||||
/// colours
|
/// colours
|
||||||
@@ -472,22 +469,22 @@ impl LedUsbPackets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get(&self) -> UsbPackets {
|
pub fn get(&self) -> AuraLaptopUsbPackets {
|
||||||
self.usb_packets.clone()
|
self.usb_packets.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_ref(&self) -> &UsbPackets {
|
pub fn get_ref(&self) -> &AuraLaptopUsbPackets {
|
||||||
&self.usb_packets
|
&self.usb_packets
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_mut(&mut self) -> &mut UsbPackets {
|
pub fn get_mut(&mut self) -> &mut AuraLaptopUsbPackets {
|
||||||
&mut self.usb_packets
|
&mut self.usb_packets
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<LedUsbPackets> for UsbPackets {
|
impl From<LedUsbPackets> for AuraLaptopUsbPackets {
|
||||||
fn from(k: LedUsbPackets) -> Self {
|
fn from(k: LedUsbPackets) -> Self {
|
||||||
k.usb_packets
|
k.usb_packets
|
||||||
}
|
}
|
||||||
@@ -643,7 +640,7 @@ impl From<&LedCode> for &str {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::keyboard::{LedCode, LedUsbPackets, UsbPackets};
|
use crate::keyboard::{AuraLaptopUsbPackets, LedCode, LedUsbPackets};
|
||||||
|
|
||||||
macro_rules! colour_check_zoned {
|
macro_rules! colour_check_zoned {
|
||||||
($zone:expr, $pkt_idx_start:expr) => {
|
($zone:expr, $pkt_idx_start:expr) => {
|
||||||
@@ -653,7 +650,7 @@ mod tests {
|
|||||||
c[1] = 255;
|
c[1] = 255;
|
||||||
c[2] = 255;
|
c[2] = 255;
|
||||||
|
|
||||||
let pkt: UsbPackets = zone.into();
|
let pkt: AuraLaptopUsbPackets = zone.into();
|
||||||
assert_eq!(pkt[0][$pkt_idx_start], 0xff);
|
assert_eq!(pkt[0][$pkt_idx_start], 0xff);
|
||||||
assert_eq!(pkt[0][$pkt_idx_start + 1], 0xff);
|
assert_eq!(pkt[0][$pkt_idx_start + 1], 0xff);
|
||||||
assert_eq!(pkt[0][$pkt_idx_start + 2], 0xff);
|
assert_eq!(pkt[0][$pkt_idx_start + 2], 0xff);
|
||||||
@@ -663,7 +660,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn zone_to_packet_check() {
|
fn zone_to_packet_check() {
|
||||||
let zone = LedUsbPackets::new_zoned(true);
|
let zone = LedUsbPackets::new_zoned(true);
|
||||||
let pkt: UsbPackets = zone.into();
|
let pkt: AuraLaptopUsbPackets = zone.into();
|
||||||
assert_eq!(pkt[0][0], 0x5d);
|
assert_eq!(pkt[0][0], 0x5d);
|
||||||
assert_eq!(pkt[0][1], 0xbc);
|
assert_eq!(pkt[0][1], 0xbc);
|
||||||
assert_eq!(pkt[0][2], 0x01);
|
assert_eq!(pkt[0][2], 0x01);
|
||||||
@@ -686,7 +683,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn perkey_to_packet_check() {
|
fn perkey_to_packet_check() {
|
||||||
let per_key = LedUsbPackets::new_per_key();
|
let per_key = LedUsbPackets::new_per_key();
|
||||||
let pkt: UsbPackets = per_key.into();
|
let pkt: AuraLaptopUsbPackets = per_key.into();
|
||||||
assert_eq!(pkt[0][0], 0x5d);
|
assert_eq!(pkt[0][0], 0x5d);
|
||||||
assert_eq!(pkt[0][1], 0xbc);
|
assert_eq!(pkt[0][1], 0xbc);
|
||||||
assert_eq!(pkt[0][2], 0x00);
|
assert_eq!(pkt[0][2], 0x00);
|
||||||
@@ -712,7 +709,7 @@ mod tests {
|
|||||||
c[1] = 255;
|
c[1] = 255;
|
||||||
c[2] = 255;
|
c[2] = 255;
|
||||||
|
|
||||||
let pkt: UsbPackets = per_key.into();
|
let pkt: AuraLaptopUsbPackets = per_key.into();
|
||||||
assert_eq!(pkt[5][30], 0xff); // D, red
|
assert_eq!(pkt[5][30], 0xff); // D, red
|
||||||
assert_eq!(pkt[5][31], 0xff); // D
|
assert_eq!(pkt[5][31], 0xff); // D
|
||||||
assert_eq!(pkt[5][32], 0xff); // D
|
assert_eq!(pkt[5][32], 0xff); // D
|
||||||
|
|||||||
@@ -488,7 +488,7 @@ mod tests {
|
|||||||
let rows = &data.key_rows;
|
let rows = &data.key_rows;
|
||||||
for row in rows {
|
for row in rows {
|
||||||
for k in &row.row {
|
for k in &row.row {
|
||||||
if data.key_shapes.get(&k.1).is_some() {
|
if data.key_shapes.contains_key(&k.1) {
|
||||||
unused.remove(&k.1);
|
unused.remove(&k.1);
|
||||||
} else {
|
} else {
|
||||||
panic!("Key {:?} was missing matching shape {}", k.0, k.1);
|
panic!("Key {:?} was missing matching shape {}", k.0, k.1);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use std::ops::{BitAnd, BitOr};
|
|||||||
|
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use typeshare::typeshare;
|
|
||||||
#[cfg(feature = "dbus")]
|
#[cfg(feature = "dbus")]
|
||||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||||
|
|
||||||
@@ -16,7 +15,6 @@ use crate::{AuraDeviceType, PowerZones};
|
|||||||
/// - 2021+, the struct is a single zone with 4 states
|
/// - 2021+, the struct is a single zone with 4 states
|
||||||
/// - pre-2021, the struct is 1 or 2 zones and 3 states
|
/// - pre-2021, the struct is 1 or 2 zones and 3 states
|
||||||
/// - Tuf, the struct is 1 zone and 3 states
|
/// - Tuf, the struct is 1 zone and 3 states
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct AuraPowerState {
|
pub struct AuraPowerState {
|
||||||
@@ -53,7 +51,10 @@ impl AuraPowerState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tuf_to_bytes(&self) -> Vec<u8> {
|
fn tuf_to_bytes(&self) -> Vec<u8> {
|
||||||
todo!("0s and 1s for bool array")
|
// &cmd, &boot, &awake, &sleep, &keyboard
|
||||||
|
vec![
|
||||||
|
1, self.boot as u8, self.awake as u8, self.sleep as u8, 1,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Bits for older 0x1866 keyboard model
|
/// # Bits for older 0x1866 keyboard model
|
||||||
@@ -101,44 +102,49 @@ impl AuraPowerState {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_to_byte(&self) -> u32 {
|
pub fn new_to_byte(&self) -> u32 {
|
||||||
match self.zone {
|
match self.zone {
|
||||||
PowerZones::Logo => {
|
PowerZones::Logo => {
|
||||||
self.boot as u32
|
self.boot as u32
|
||||||
| (self.awake as u32) << 2
|
| ((self.awake as u32) << 2)
|
||||||
| (self.sleep as u32) << 4
|
| ((self.sleep as u32) << 4)
|
||||||
| (self.shutdown as u32) << 6
|
| ((self.shutdown as u32) << 6)
|
||||||
|
}
|
||||||
|
PowerZones::Ally => {
|
||||||
|
(self.boot as u32)
|
||||||
|
| ((self.awake as u32) << 1)
|
||||||
|
| ((self.sleep as u32) << 2)
|
||||||
|
| ((self.shutdown as u32) << 3)
|
||||||
}
|
}
|
||||||
PowerZones::Keyboard => {
|
PowerZones::Keyboard => {
|
||||||
(self.boot as u32) << 1
|
((self.boot as u32) << 1)
|
||||||
| (self.awake as u32) << 3
|
| ((self.awake as u32) << 3)
|
||||||
| (self.sleep as u32) << 5
|
| ((self.sleep as u32) << 5)
|
||||||
| (self.shutdown as u32) << 7
|
| ((self.shutdown as u32) << 7)
|
||||||
}
|
}
|
||||||
PowerZones::Lightbar => {
|
PowerZones::Lightbar => {
|
||||||
(self.boot as u32) << (7 + 2)
|
((self.boot as u32) << (7 + 2))
|
||||||
| (self.awake as u32) << (7 + 3)
|
| ((self.awake as u32) << (7 + 3))
|
||||||
| (self.sleep as u32) << (7 + 4)
|
| ((self.sleep as u32) << (7 + 4))
|
||||||
| (self.shutdown as u32) << (7 + 5)
|
| ((self.shutdown as u32) << (7 + 5))
|
||||||
}
|
}
|
||||||
PowerZones::Lid => {
|
PowerZones::Lid => {
|
||||||
(self.boot as u32) << (15 + 1)
|
((self.boot as u32) << (15 + 1))
|
||||||
| (self.awake as u32) << (15 + 2)
|
| ((self.awake as u32) << (15 + 2))
|
||||||
| (self.sleep as u32) << (15 + 3)
|
| ((self.sleep as u32) << (15 + 3))
|
||||||
| (self.shutdown as u32) << (15 + 4)
|
| ((self.shutdown as u32) << (15 + 4))
|
||||||
}
|
}
|
||||||
PowerZones::RearGlow => {
|
PowerZones::RearGlow => {
|
||||||
(self.boot as u32) << (23 + 1)
|
((self.boot as u32) << (23 + 1))
|
||||||
| (self.awake as u32) << (23 + 2)
|
| ((self.awake as u32) << (23 + 2))
|
||||||
| (self.sleep as u32) << (23 + 3)
|
| ((self.sleep as u32) << (23 + 3))
|
||||||
| (self.shutdown as u32) << (23 + 4)
|
| ((self.shutdown as u32) << (23 + 4))
|
||||||
}
|
}
|
||||||
PowerZones::KeyboardAndLightbar | PowerZones::None => 0,
|
PowerZones::None | PowerZones::KeyboardAndLightbar => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct LaptopAuraPower {
|
pub struct LaptopAuraPower {
|
||||||
@@ -186,14 +192,18 @@ impl LaptopAuraPower {
|
|||||||
// TODO: use support data to setup correct zones
|
// TODO: use support data to setup correct zones
|
||||||
pub fn new(aura_type: AuraDeviceType, support_data: &LedSupportData) -> Self {
|
pub fn new(aura_type: AuraDeviceType, support_data: &LedSupportData) -> Self {
|
||||||
match aura_type {
|
match aura_type {
|
||||||
AuraDeviceType::Unknown | AuraDeviceType::LaptopPost2021 => {
|
AuraDeviceType::Unknown | AuraDeviceType::Ally | AuraDeviceType::LaptopKeyboard2021 => {
|
||||||
let mut states = Vec::new();
|
let mut states = Vec::new();
|
||||||
for zone in support_data.power_zones.iter() {
|
for zone in support_data.power_zones.iter() {
|
||||||
states.push(AuraPowerState::default_for(*zone))
|
states.push(AuraPowerState::default_for(*zone))
|
||||||
}
|
}
|
||||||
Self { states }
|
Self { states }
|
||||||
}
|
}
|
||||||
AuraDeviceType::LaptopPre2021 => {
|
AuraDeviceType::LaptopKeyboardPre2021 => {
|
||||||
|
// The older devices are tri-state if have lightbar:
|
||||||
|
// 1. Keyboard
|
||||||
|
// 2. Lightbar
|
||||||
|
// 3. KeyboardAndLightbar
|
||||||
if support_data.power_zones.contains(&PowerZones::Lightbar) {
|
if support_data.power_zones.contains(&PowerZones::Lightbar) {
|
||||||
Self {
|
Self {
|
||||||
states: vec![AuraPowerState::default_for(PowerZones::KeyboardAndLightbar)],
|
states: vec![AuraPowerState::default_for(PowerZones::KeyboardAndLightbar)],
|
||||||
@@ -204,23 +214,48 @@ impl LaptopAuraPower {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AuraDeviceType::LaptopTuf => Self {
|
AuraDeviceType::LaptopKeyboardTuf => Self {
|
||||||
states: vec![AuraPowerState::default_for(PowerZones::Keyboard)],
|
states: vec![AuraPowerState::default_for(PowerZones::Keyboard)],
|
||||||
},
|
},
|
||||||
AuraDeviceType::ScsiExtDisk => todo!(),
|
AuraDeviceType::ScsiExtDisk => todo!(),
|
||||||
|
AuraDeviceType::AnimeOrSlash => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_bytes(&self, aura_type: AuraDeviceType) -> Vec<u8> {
|
pub fn to_bytes(&self, aura_type: AuraDeviceType) -> Vec<u8> {
|
||||||
|
if let Some(stuff) = self.states.first() {
|
||||||
|
if stuff.zone == PowerZones::Ally {
|
||||||
|
return vec![
|
||||||
|
0x5d,
|
||||||
|
0xd1,
|
||||||
|
0x09,
|
||||||
|
0x01,
|
||||||
|
stuff.new_to_byte() as u8,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
match aura_type {
|
match aura_type {
|
||||||
AuraDeviceType::LaptopPost2021 => self.new_to_bytes(),
|
AuraDeviceType::LaptopKeyboard2021 | AuraDeviceType::Ally => self.new_to_bytes(),
|
||||||
AuraDeviceType::LaptopPre2021 => self
|
AuraDeviceType::LaptopKeyboardPre2021 => {
|
||||||
.states
|
if self.states.len() == 1 {
|
||||||
.first()
|
self.states
|
||||||
.cloned()
|
.first()
|
||||||
.unwrap_or_default()
|
.cloned()
|
||||||
.old_to_bytes(),
|
.unwrap_or_default()
|
||||||
AuraDeviceType::LaptopTuf => self
|
.old_to_bytes()
|
||||||
|
} else {
|
||||||
|
let mut bytes: Vec<Vec<u8>> =
|
||||||
|
self.states.iter().map(|s| s.old_to_bytes()).collect();
|
||||||
|
let mut b = bytes.pop().unwrap();
|
||||||
|
for i in bytes {
|
||||||
|
for (i, n) in i.iter().enumerate() {
|
||||||
|
b[i] |= n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AuraDeviceType::LaptopKeyboardTuf => self
|
||||||
.states
|
.states
|
||||||
.first()
|
.first()
|
||||||
.cloned()
|
.cloned()
|
||||||
@@ -230,7 +265,8 @@ impl LaptopAuraPower {
|
|||||||
warn!("Trying to create bytes for an unknown device");
|
warn!("Trying to create bytes for an unknown device");
|
||||||
self.new_to_bytes()
|
self.new_to_bytes()
|
||||||
}
|
}
|
||||||
AuraDeviceType::ScsiExtDisk => todo!(),
|
AuraDeviceType::ScsiExtDisk => todo!("scsi disk not implemented yet"),
|
||||||
|
AuraDeviceType::AnimeOrSlash => todo!("anime/slash not implemented yet"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,254 +315,297 @@ mod test {
|
|||||||
use crate::keyboard::{AuraPowerState, LaptopAuraPower};
|
use crate::keyboard::{AuraPowerState, LaptopAuraPower};
|
||||||
use crate::{AuraDeviceType, PowerZones};
|
use crate::{AuraDeviceType, PowerZones};
|
||||||
|
|
||||||
|
fn to_binary_string_post2021(power: &LaptopAuraPower) -> String {
|
||||||
|
let bytes = power.to_bytes(AuraDeviceType::LaptopKeyboard2021);
|
||||||
|
format!(
|
||||||
|
"{:08b}, {:08b}, {:08b}, {:08b}",
|
||||||
|
bytes[0], bytes[1], bytes[2], bytes[3]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_0x1866_control_bytes() {
|
fn check_0x1866_control_bytes() {
|
||||||
let state = AuraPowerState {
|
let power = LaptopAuraPower {
|
||||||
zone: PowerZones::Keyboard,
|
states: vec![
|
||||||
awake: true,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Keyboard,
|
||||||
sleep: false,
|
boot: false,
|
||||||
shutdown: false,
|
awake: true,
|
||||||
|
sleep: false,
|
||||||
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
let bytes = state.old_to_bytes();
|
let bytes = power.to_bytes(AuraDeviceType::LaptopKeyboardPre2021);
|
||||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||||
assert_eq!(bytes, [0x08, 0x00, 0x02, 0x00]);
|
assert_eq!(bytes, [0x08, 0x00, 0x02, 0x00]);
|
||||||
|
|
||||||
let state = AuraPowerState {
|
let power = LaptopAuraPower {
|
||||||
zone: PowerZones::Lightbar,
|
states: vec![
|
||||||
awake: true,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Lightbar,
|
||||||
sleep: false,
|
boot: false,
|
||||||
shutdown: false,
|
awake: true,
|
||||||
|
sleep: false,
|
||||||
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
let bytes = state.old_to_bytes();
|
let bytes = power.to_bytes(AuraDeviceType::LaptopKeyboardPre2021);
|
||||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||||
assert_eq!(bytes, [0x04, 0x05, 0x02, 0x00]);
|
assert_eq!(bytes, [0x04, 0x05, 0x02, 0x00]);
|
||||||
|
|
||||||
let bytes = AuraPowerState {
|
// let bytes = [
|
||||||
zone: PowerZones::None,
|
// OldAuraPower::Keyboard,
|
||||||
awake: false,
|
// OldAuraPower::Lightbar,
|
||||||
boot: false,
|
// OldAuraPower::Awake,
|
||||||
sleep: true,
|
// OldAuraPower::Sleep,
|
||||||
shutdown: false,
|
// OldAuraPower::Boot,
|
||||||
|
// ];
|
||||||
|
let power = LaptopAuraPower {
|
||||||
|
states: vec![
|
||||||
|
AuraPowerState {
|
||||||
|
zone: PowerZones::Keyboard,
|
||||||
|
boot: true,
|
||||||
|
awake: true,
|
||||||
|
sleep: true,
|
||||||
|
shutdown: false,
|
||||||
|
},
|
||||||
|
AuraPowerState {
|
||||||
|
zone: PowerZones::Lightbar,
|
||||||
|
boot: true,
|
||||||
|
awake: true,
|
||||||
|
sleep: true,
|
||||||
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
let bytes = bytes.old_to_bytes();
|
let bytes = power.to_bytes(AuraDeviceType::LaptopKeyboardPre2021);
|
||||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
|
||||||
assert_eq!(bytes, [0x30, 0x08, 0x04, 0x00]);
|
|
||||||
|
|
||||||
let bytes = AuraPowerState {
|
|
||||||
zone: PowerZones::None,
|
|
||||||
awake: false,
|
|
||||||
boot: true,
|
|
||||||
sleep: false,
|
|
||||||
shutdown: false,
|
|
||||||
};
|
|
||||||
let bytes = bytes.old_to_bytes();
|
|
||||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
|
||||||
assert_eq!(bytes, [0xc3, 0x12, 0x09, 0x00]);
|
|
||||||
|
|
||||||
let power = AuraPowerState {
|
|
||||||
zone: PowerZones::KeyboardAndLightbar,
|
|
||||||
awake: true,
|
|
||||||
boot: true,
|
|
||||||
sleep: true,
|
|
||||||
shutdown: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let bytes = power.old_to_bytes();
|
|
||||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||||
assert_eq!(bytes, [0xff, 0x1f, 0x000f, 0x00]);
|
assert_eq!(bytes, [0xff, 0x1f, 0x000f, 0x00]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_0x19b6_control_bytes_binary_rep() {
|
fn check_0x19b6_control_bytes_binary_rep() {
|
||||||
fn to_binary_string(power: &LaptopAuraPower) -> String {
|
let boot_logo_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
let bytes = power.to_bytes(AuraDeviceType::LaptopPost2021);
|
states: vec![
|
||||||
format!(
|
AuraPowerState {
|
||||||
"{:08b}, {:08b}, {:08b}, {:08b}",
|
zone: PowerZones::Logo,
|
||||||
bytes[0], bytes[1], bytes[2], bytes[3]
|
boot: true,
|
||||||
)
|
awake: false,
|
||||||
}
|
sleep: false,
|
||||||
|
shutdown: false,
|
||||||
let boot_logo_ = to_binary_string(&LaptopAuraPower {
|
},
|
||||||
states: vec![AuraPowerState {
|
],
|
||||||
zone: PowerZones::Logo,
|
|
||||||
boot: true,
|
|
||||||
awake: false,
|
|
||||||
sleep: false,
|
|
||||||
shutdown: false,
|
|
||||||
}],
|
|
||||||
});
|
});
|
||||||
let boot_keyb_ = to_binary_string(&LaptopAuraPower {
|
let boot_keyb_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Keyboard,
|
AuraPowerState {
|
||||||
boot: true,
|
zone: PowerZones::Keyboard,
|
||||||
awake: false,
|
boot: true,
|
||||||
sleep: false,
|
awake: false,
|
||||||
shutdown: false,
|
sleep: false,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let sleep_logo = to_binary_string(&LaptopAuraPower {
|
let sleep_logo = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Logo,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Logo,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: true,
|
awake: false,
|
||||||
shutdown: false,
|
sleep: true,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let sleep_keyb = to_binary_string(&LaptopAuraPower {
|
let sleep_keyb = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Keyboard,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Keyboard,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: true,
|
awake: false,
|
||||||
shutdown: false,
|
sleep: true,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let awake_logo = to_binary_string(&LaptopAuraPower {
|
let awake_logo = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Logo,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Logo,
|
||||||
awake: true,
|
boot: false,
|
||||||
sleep: false,
|
awake: true,
|
||||||
shutdown: false,
|
sleep: false,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let awake_keyb = to_binary_string(&LaptopAuraPower {
|
let awake_keyb = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Keyboard,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Keyboard,
|
||||||
awake: true,
|
boot: false,
|
||||||
sleep: false,
|
awake: true,
|
||||||
shutdown: false,
|
sleep: false,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let shut_logo_ = to_binary_string(&LaptopAuraPower {
|
let shut_logo_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Logo,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Logo,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: false,
|
awake: false,
|
||||||
shutdown: true,
|
sleep: false,
|
||||||
}],
|
shutdown: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let shut_keyb_ = to_binary_string(&LaptopAuraPower {
|
let shut_keyb_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Keyboard,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Keyboard,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: false,
|
awake: false,
|
||||||
shutdown: true,
|
sleep: false,
|
||||||
}],
|
shutdown: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let boot_bar__ = to_binary_string(&LaptopAuraPower {
|
let boot_bar__ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Lightbar,
|
AuraPowerState {
|
||||||
boot: true,
|
zone: PowerZones::Lightbar,
|
||||||
awake: false,
|
boot: true,
|
||||||
sleep: false,
|
awake: false,
|
||||||
shutdown: false,
|
sleep: false,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let awake_bar_ = to_binary_string(&LaptopAuraPower {
|
let awake_bar_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Lightbar,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Lightbar,
|
||||||
awake: true,
|
boot: false,
|
||||||
sleep: false,
|
awake: true,
|
||||||
shutdown: false,
|
sleep: false,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let sleep_bar_ = to_binary_string(&LaptopAuraPower {
|
let sleep_bar_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Lightbar,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Lightbar,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: true,
|
awake: false,
|
||||||
shutdown: false,
|
sleep: true,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let shut_bar__ = to_binary_string(&LaptopAuraPower {
|
let shut_bar__ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Lightbar,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Lightbar,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: false,
|
awake: false,
|
||||||
shutdown: true,
|
sleep: false,
|
||||||
}],
|
shutdown: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let boot_lid__ = to_binary_string(&LaptopAuraPower {
|
let boot_lid__ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Lid,
|
AuraPowerState {
|
||||||
boot: true,
|
zone: PowerZones::Lid,
|
||||||
awake: false,
|
boot: true,
|
||||||
sleep: false,
|
awake: false,
|
||||||
shutdown: false,
|
sleep: false,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let awake_lid_ = to_binary_string(&LaptopAuraPower {
|
let awake_lid_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Lid,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Lid,
|
||||||
awake: true,
|
boot: false,
|
||||||
sleep: false,
|
awake: true,
|
||||||
shutdown: false,
|
sleep: false,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let sleep_lid_ = to_binary_string(&LaptopAuraPower {
|
let sleep_lid_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Lid,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Lid,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: true,
|
awake: false,
|
||||||
shutdown: false,
|
sleep: true,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let shut_lid__ = to_binary_string(&LaptopAuraPower {
|
let shut_lid__ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::Lid,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::Lid,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: false,
|
awake: false,
|
||||||
shutdown: true,
|
sleep: false,
|
||||||
}],
|
shutdown: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let boot_rear_ = to_binary_string(&LaptopAuraPower {
|
let boot_rear_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::RearGlow,
|
AuraPowerState {
|
||||||
boot: true,
|
zone: PowerZones::RearGlow,
|
||||||
awake: false,
|
boot: true,
|
||||||
sleep: false,
|
awake: false,
|
||||||
shutdown: false,
|
sleep: false,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let awake_rear = to_binary_string(&LaptopAuraPower {
|
let awake_rear = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::RearGlow,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::RearGlow,
|
||||||
awake: true,
|
boot: false,
|
||||||
sleep: false,
|
awake: true,
|
||||||
shutdown: false,
|
sleep: false,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let sleep_rear = to_binary_string(&LaptopAuraPower {
|
let sleep_rear = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::RearGlow,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::RearGlow,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: true,
|
awake: false,
|
||||||
shutdown: false,
|
sleep: true,
|
||||||
}],
|
shutdown: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
let shut_rear_ = to_binary_string(&LaptopAuraPower {
|
let shut_rear_ = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![AuraPowerState {
|
states: vec![
|
||||||
zone: PowerZones::RearGlow,
|
AuraPowerState {
|
||||||
boot: false,
|
zone: PowerZones::RearGlow,
|
||||||
awake: false,
|
boot: false,
|
||||||
sleep: false,
|
awake: false,
|
||||||
shutdown: true,
|
sleep: false,
|
||||||
}],
|
shutdown: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(boot_logo_, "00000001, 00000000, 00000000, 00000000");
|
assert_eq!(boot_logo_, "00000001, 00000000, 00000000, 00000000");
|
||||||
@@ -554,7 +633,7 @@ mod test {
|
|||||||
assert_eq!(shut_rear_, "00000000, 00000000, 00000000, 00001000");
|
assert_eq!(shut_rear_, "00000000, 00000000, 00000000, 00001000");
|
||||||
|
|
||||||
// All on
|
// All on
|
||||||
let byte1 = to_binary_string(&LaptopAuraPower {
|
let byte1 = to_binary_string_post2021(&LaptopAuraPower {
|
||||||
states: vec![
|
states: vec![
|
||||||
AuraPowerState {
|
AuraPowerState {
|
||||||
zone: PowerZones::Keyboard,
|
zone: PowerZones::Keyboard,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use typeshare::typeshare;
|
|
||||||
#[cfg(feature = "dbus")]
|
#[cfg(feature = "dbus")]
|
||||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ pub mod usb;
|
|||||||
|
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
|
|
||||||
pub const LED_MSG_LEN: usize = 17;
|
pub const AURA_LAPTOP_LED_MSG_LEN: usize = 17;
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
pub const RED: Colour = Colour {
|
pub const RED: Colour = Colour {
|
||||||
@@ -62,32 +61,39 @@ pub const ORANGE: Colour = Colour {
|
|||||||
g: 0xa4,
|
g: 0xa4,
|
||||||
b: 0x00,
|
b: 0x00,
|
||||||
};
|
};
|
||||||
pub const GRADIENT: [Colour; 7] = [RED, VIOLET, BLUE, TEAL, GREEN, YELLOW, ORANGE];
|
pub const GRADIENT: [Colour; 7] = [
|
||||||
|
RED, VIOLET, BLUE, TEAL, GREEN, YELLOW, ORANGE,
|
||||||
|
];
|
||||||
|
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
pub enum AuraDeviceType {
|
pub enum AuraDeviceType {
|
||||||
/// Most new laptops
|
/// Most new laptops
|
||||||
#[default]
|
#[default]
|
||||||
LaptopPost2021 = 0,
|
LaptopKeyboard2021 = 0,
|
||||||
LaptopPre2021 = 1,
|
LaptopKeyboardPre2021 = 1,
|
||||||
LaptopTuf = 2,
|
LaptopKeyboardTuf = 2,
|
||||||
ScsiExtDisk = 3,
|
ScsiExtDisk = 3,
|
||||||
|
Ally = 4,
|
||||||
|
AnimeOrSlash = 5,
|
||||||
Unknown = 255,
|
Unknown = 255,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuraDeviceType {
|
impl AuraDeviceType {
|
||||||
pub fn is_old_laptop(&self) -> bool {
|
pub fn is_old_laptop(&self) -> bool {
|
||||||
*self == Self::LaptopPre2021
|
*self == Self::LaptopKeyboardPre2021
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_tuf_laptop(&self) -> bool {
|
pub fn is_tuf_laptop(&self) -> bool {
|
||||||
*self == Self::LaptopTuf
|
*self == Self::LaptopKeyboardTuf
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_new_laptop(&self) -> bool {
|
pub fn is_new_laptop(&self) -> bool {
|
||||||
*self == Self::LaptopPost2021
|
*self == Self::LaptopKeyboard2021
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_ally(&self) -> bool {
|
||||||
|
*self == Self::Ally
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_scsi(&self) -> bool {
|
pub fn is_scsi(&self) -> bool {
|
||||||
@@ -98,16 +104,18 @@ impl AuraDeviceType {
|
|||||||
impl From<&str> for AuraDeviceType {
|
impl From<&str> for AuraDeviceType {
|
||||||
fn from(s: &str) -> Self {
|
fn from(s: &str) -> Self {
|
||||||
match s.to_lowercase().trim_start_matches("0x") {
|
match s.to_lowercase().trim_start_matches("0x") {
|
||||||
"tuf" => AuraDeviceType::LaptopTuf,
|
"tuf" => AuraDeviceType::LaptopKeyboardTuf,
|
||||||
"1932" => AuraDeviceType::ScsiExtDisk,
|
"1932" => AuraDeviceType::ScsiExtDisk,
|
||||||
"1866" | "18c6" | "1869" | "1854" => Self::LaptopPre2021,
|
"1866" | "18c6" | "1869" | "1854" => Self::LaptopKeyboardPre2021,
|
||||||
_ => Self::LaptopPost2021,
|
"1abe" | "1b4c" => Self::Ally,
|
||||||
|
"19b3" | "193b" => Self::AnimeOrSlash,
|
||||||
|
"19b6" => Self::LaptopKeyboard2021,
|
||||||
|
_ => Self::Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The powerr zones this laptop supports
|
/// The powerr zones this laptop supports
|
||||||
#[typeshare]
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "dbus",
|
feature = "dbus",
|
||||||
derive(Type, Value, OwnedValue),
|
derive(Type, Value, OwnedValue),
|
||||||
@@ -126,7 +134,9 @@ pub enum PowerZones {
|
|||||||
Lid = 3,
|
Lid = 3,
|
||||||
/// The led strip on the rear of some laptops
|
/// The led strip on the rear of some laptops
|
||||||
RearGlow = 4,
|
RearGlow = 4,
|
||||||
/// On pre-2021 laptops there is either 1 or 2 zones used
|
/// Exists for the older 0x1866 models
|
||||||
KeyboardAndLightbar = 5,
|
KeyboardAndLightbar = 5,
|
||||||
|
/// Ally specific for creating correct packet
|
||||||
|
Ally = 6,
|
||||||
None = 255,
|
None = 255,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
// Only these two packets must be 17 bytes
|
// Only these two packets must be 17 bytes
|
||||||
pub const LED_APPLY: [u8; 17] = [0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
pub const AURA_LAPTOP_LED_APPLY: [u8; 17] = [
|
||||||
pub const LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
];
|
||||||
/// Writes out the correct byte string for brightness
|
pub const AURA_LAPTOP_LED_SET: [u8; 17] = [
|
||||||
pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
|
0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
[
|
];
|
||||||
0x5a, 0xba, 0xc5, 0xc4, brightness, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,13 +9,17 @@ homepage.workspace = true
|
|||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
#default = ["mocking"]
|
default = []
|
||||||
#mocking = []
|
mocking = []
|
||||||
|
x11 = ["slint/backend-winit-x11"]
|
||||||
|
# Optional tokio debug feature does not require nightly; remove RUSTFLAGS note.
|
||||||
|
tokio-debug = ["console-subscriber"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nix = { version = "^0.28.0", features = ["fs"] }
|
console-subscriber = { version = "^0.4", optional = true }
|
||||||
tempfile = "3.3.0"
|
|
||||||
betrayer = { version = "0.2.0" }
|
ksni = { version = "0.3", default-features = false, features = ["async-io"] }
|
||||||
|
image = "0.25.5"
|
||||||
|
|
||||||
asusd = { path = "../asusd" }
|
asusd = { path = "../asusd" }
|
||||||
config-traits = { path = "../config-traits" }
|
config-traits = { path = "../config-traits" }
|
||||||
@@ -24,7 +28,7 @@ rog_dbus = { path = "../rog-dbus" }
|
|||||||
rog_aura = { path = "../rog-aura" }
|
rog_aura = { path = "../rog-aura" }
|
||||||
rog_profiles = { path = "../rog-profiles" }
|
rog_profiles = { path = "../rog-profiles" }
|
||||||
rog_platform = { path = "../rog-platform" }
|
rog_platform = { path = "../rog-platform" }
|
||||||
supergfxctl = { git = "https://gitlab.com/asus-linux/supergfxctl.git", rev = "4eb6e97c22b68ae8d1e80500709b0c0580776ad3", default-features = false }
|
supergfxctl = { git = "https://gitlab.com/asus-linux/supergfxctl.git", default-features = false }
|
||||||
dmi_id = { path = "../dmi-id" }
|
dmi_id = { path = "../dmi-id" }
|
||||||
|
|
||||||
gumdrop.workspace = true
|
gumdrop.workspace = true
|
||||||
@@ -33,11 +37,11 @@ env_logger.workspace = true
|
|||||||
|
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
dirs.workspace = true
|
dirs.workspace = true
|
||||||
notify-rust.workspace = true
|
notify-rust.workspace = true
|
||||||
concat-idents.workspace = true
|
concat-idents.workspace = true
|
||||||
|
futures-util.workspace = true
|
||||||
|
|
||||||
versions.workspace = true
|
versions.workspace = true
|
||||||
|
|
||||||
@@ -45,16 +49,26 @@ versions.workspace = true
|
|||||||
git = "https://github.com/slint-ui/slint.git"
|
git = "https://github.com/slint-ui/slint.git"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = [
|
features = [
|
||||||
"gettext",
|
|
||||||
"compat-1-2",
|
"compat-1-2",
|
||||||
"backend-linuxkms",
|
"gettext",
|
||||||
"backend-winit-wayland",
|
"backend-winit-wayland",
|
||||||
"renderer-winit-femtovg",
|
"renderer-femtovg",
|
||||||
# "renderer-skia-opengl",
|
# "renderer-skia-opengl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[build-dependencies.slint-build]
|
[build-dependencies.slint-build]
|
||||||
git = "https://github.com/slint-ui/slint.git"
|
git = "https://github.com/slint-ui/slint.git"
|
||||||
|
|
||||||
[dev-dependencies]
|
[package.metadata.deb]
|
||||||
cargo-husky.workspace = true
|
license-file = ["../LICENSE", "4"]
|
||||||
|
extended-description = """\
|
||||||
|
The dbus server for asusctl and rog-control-center applications."""
|
||||||
|
depends = "$auto"
|
||||||
|
section = "utility"
|
||||||
|
priority = "optional"
|
||||||
|
assets = [
|
||||||
|
["target/release/rog-control-center", "usr/bin/", "755"],
|
||||||
|
["../rog_gui-fakeinstall/usr/share/applications/*", "usr/share/share/applications/", "644"],
|
||||||
|
["../rog_gui-fakeinstall/usr/share/icons/hicolor/512x512/apps/*", "usr/share/icons/hicolor/512x512/apps", "644"],
|
||||||
|
["../rog_gui-fakeinstall/usr/share/icons/hicolor/scalable/status/*", "usr/share/icons/hicolor/scalable/status", "644"],
|
||||||
|
]
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
# ROGALOG
|
# ROGALOG
|
||||||
|
|
||||||
|
## X11 support
|
||||||
|
|
||||||
|
X11 is not supported at all, as in I will not help you with X11 issues if there are any due to limited time and it being unmaintained itself. You can however build `rog-control-center` with it enabled `cargo build --features x11`.
|
||||||
|
|
||||||
### Translations
|
### Translations
|
||||||
|
|
||||||
You can help with translations by following https://slint.dev/releases/1.1.0/docs/slint/src/concepts/translations#translate-the-strings
|
You can help with translations by following https://slint.dev/releases/1.1.0/docs/slint/src/concepts/translations#translate-the-strings
|
||||||
@@ -8,4 +12,4 @@ Begin by copying `rog-control-center/translations/en/rog-control-center.po` to `
|
|||||||
|
|
||||||
Run `msgfmt rog-control-center/translations/<YOUR LOCALE>/rog-control-center.po -o rog-control-center/translations/<YOUR LOCALE>/LC_MESSAGES/rog-control-center.mo` to make the binary formatted translation where `<YOUR LOCALE>` is changed to your translation locale.
|
Run `msgfmt rog-control-center/translations/<YOUR LOCALE>/rog-control-center.po -o rog-control-center/translations/<YOUR LOCALE>/LC_MESSAGES/rog-control-center.mo` to make the binary formatted translation where `<YOUR LOCALE>` is changed to your translation locale.
|
||||||
|
|
||||||
To test you local translations run `RUST_TRANSLATIONS=1 rog-control-center`.
|
To test you local translations run `RUST_TRANSLATIONS=1 rog-control-center`.
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use slint_build::CompilerConfiguration;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// write_locales();
|
// write_locales();
|
||||||
|
|
||||||
let root = env!("CARGO_MANIFEST_DIR");
|
let root = env!("CARGO_MANIFEST_DIR");
|
||||||
let mut main = PathBuf::from_str(root).unwrap();
|
let mut main = PathBuf::from_str(root).unwrap();
|
||||||
main.push("ui/main_window.slint");
|
main.push("ui/main_window.slint");
|
||||||
@@ -14,13 +13,12 @@ fn main() {
|
|||||||
include.push("ui");
|
include.push("ui");
|
||||||
|
|
||||||
slint_build::print_rustc_flags().unwrap();
|
slint_build::print_rustc_flags().unwrap();
|
||||||
// slint_build::compile("ui/main_window.slint").unwrap();
|
|
||||||
slint_build::compile_with_config(
|
slint_build::compile_with_config(
|
||||||
main,
|
main,
|
||||||
CompilerConfiguration::new()
|
CompilerConfiguration::new()
|
||||||
// .embed_resources(EmbedResourcesKind::EmbedFiles)
|
// .embed_resources(EmbedResourcesKind::EmbedFiles)
|
||||||
.with_include_paths(vec![include])
|
.with_include_paths(vec![include])
|
||||||
.with_style("fluent-dark".into()),
|
.with_style("fluent".into()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
Version=1.0
|
Version=1.0
|
||||||
Type=Application
|
Type=Application
|
||||||
|
|
||||||
Name=ROG Control Center
|
Name=ROG Control Center
|
||||||
Comment=Make your ASUS ROG Laptop go Brrrrr!
|
Comment=Make your ASUS ROG Laptop go Brrrrr!
|
||||||
Categories=Settings
|
Categories=Settings
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::fs::create_dir;
|
use std::fs::create_dir;
|
||||||
|
|
||||||
use config_traits::{StdConfig, StdConfigLoad1};
|
use config_traits::{StdConfig, StdConfigLoad1};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::notify::EnabledNotifications;
|
use crate::notify::EnabledNotifications;
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ pub type Result<T> = std::result::Result<T, Error>;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Io(std::io::Error),
|
Io(std::io::Error),
|
||||||
Nix(nix::Error),
|
|
||||||
ConfigLoadFail,
|
ConfigLoadFail,
|
||||||
ConfigLockFail,
|
ConfigLockFail,
|
||||||
XdgVars,
|
XdgVars,
|
||||||
Zbus(zbus::Error),
|
Zbus(zbus::Error),
|
||||||
|
ZbusFdo(zbus::fdo::Error),
|
||||||
Notification(notify_rust::error::Error),
|
Notification(notify_rust::error::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,11 +18,11 @@ impl fmt::Display for Error {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Error::Io(err) => write!(f, "Failed to open: {}", err),
|
Error::Io(err) => write!(f, "Failed to open: {}", err),
|
||||||
Error::Nix(err) => write!(f, "Error: {}", err),
|
|
||||||
Error::ConfigLoadFail => write!(f, "Failed to load user config"),
|
Error::ConfigLoadFail => write!(f, "Failed to load user config"),
|
||||||
Error::ConfigLockFail => write!(f, "Failed to lock user config"),
|
Error::ConfigLockFail => write!(f, "Failed to lock user config"),
|
||||||
Error::XdgVars => write!(f, "XDG environment vars appear unset"),
|
Error::XdgVars => write!(f, "XDG environment vars appear unset"),
|
||||||
Error::Zbus(err) => write!(f, "Error: {}", err),
|
Error::Zbus(err) => write!(f, "Error: {}", err),
|
||||||
|
Error::ZbusFdo(err) => write!(f, "Error: {}", err),
|
||||||
Error::Notification(err) => write!(f, "Notification Error: {}", err),
|
Error::Notification(err) => write!(f, "Notification Error: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,18 +36,18 @@ impl From<std::io::Error> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<nix::Error> for Error {
|
|
||||||
fn from(err: nix::Error) -> Self {
|
|
||||||
Error::Nix(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<zbus::Error> for Error {
|
impl From<zbus::Error> for Error {
|
||||||
fn from(err: zbus::Error) -> Self {
|
fn from(err: zbus::Error) -> Self {
|
||||||
Error::Zbus(err)
|
Error::Zbus(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<zbus::fdo::Error> for Error {
|
||||||
|
fn from(err: zbus::fdo::Error) -> Self {
|
||||||
|
Error::ZbusFdo(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<notify_rust::error::Error> for Error {
|
impl From<notify_rust::error::Error> for Error {
|
||||||
fn from(err: notify_rust::error::Error) -> Self {
|
fn from(err: notify_rust::error::Error) -> Self {
|
||||||
Error::Notification(err)
|
Error::Notification(err)
|
||||||
|
|||||||
@@ -2,14 +2,8 @@
|
|||||||
#![allow(clippy::redundant_clone, clippy::cmp_owned)]
|
#![allow(clippy::redundant_clone, clippy::cmp_owned)]
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
// Intentionally reexport slint so that GUI consumers don't need to add to
|
/// Intentionally reexport slint so that GUI consumers don't need to add to
|
||||||
// `Cargo.toml`
|
/// `Cargo.toml`
|
||||||
use std::fs::{remove_dir_all, File, OpenOptions};
|
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::process::exit;
|
|
||||||
use std::thread::sleep;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
pub use slint;
|
pub use slint;
|
||||||
|
|
||||||
pub mod cli_options;
|
pub mod cli_options;
|
||||||
@@ -21,11 +15,7 @@ pub mod notify;
|
|||||||
pub mod tray;
|
pub mod tray;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
|
pub mod zbus_proxies;
|
||||||
use nix::sys::stat;
|
|
||||||
use nix::unistd;
|
|
||||||
use tempfile::TempDir;
|
|
||||||
// use log::{error, info, warn};
|
|
||||||
|
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
pub const APP_ICON_PATH: &str = "/usr/share/icons/hicolor/512x512/apps/rog-control-center.png";
|
pub const APP_ICON_PATH: &str = "/usr/share/icons/hicolor/512x512/apps/rog-control-center.png";
|
||||||
@@ -42,10 +32,6 @@ pub fn print_versions() {
|
|||||||
println!("rog-platform v{}", rog_platform::VERSION);
|
println!("rog-platform v{}", rog_platform::VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const SHOWING_GUI: u8 = 1;
|
|
||||||
pub const SHOW_GUI: u8 = 2;
|
|
||||||
pub const QUIT_APP: u8 = 3;
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum Page {
|
pub enum Page {
|
||||||
AppSettings,
|
AppSettings,
|
||||||
@@ -54,59 +40,3 @@ pub enum Page {
|
|||||||
AnimeMatrix,
|
AnimeMatrix,
|
||||||
FanCurves,
|
FanCurves,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Either exit the process, or return with a refreshed tmp-dir
|
|
||||||
pub fn on_tmp_dir_exists() -> Result<TempDir, std::io::Error> {
|
|
||||||
let mut buf = [0u8; 2];
|
|
||||||
let path = std::env::temp_dir().join("rog-gui");
|
|
||||||
|
|
||||||
if path.read_dir()?.next().is_none() {
|
|
||||||
std::fs::remove_dir_all(path)?;
|
|
||||||
return tempfile::Builder::new()
|
|
||||||
.prefix("rog-gui")
|
|
||||||
.rand_bytes(0)
|
|
||||||
.tempdir();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut ipc_file = OpenOptions::new()
|
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
.create(false)
|
|
||||||
.open(path.join("ipc.pipe"))?;
|
|
||||||
|
|
||||||
// If the app is running this ends up stacked on top of SHOWING_GUI
|
|
||||||
ipc_file.write_all(&[SHOW_GUI, 0])?;
|
|
||||||
// tiny sleep to give the app a chance to respond
|
|
||||||
sleep(Duration::from_millis(10));
|
|
||||||
ipc_file.read_exact(&mut buf).ok();
|
|
||||||
|
|
||||||
// First entry is the actual state
|
|
||||||
if buf[0] == SHOWING_GUI {
|
|
||||||
ipc_file.write_all(&[SHOWING_GUI, 0])?; // Store state again as we drained the fifo
|
|
||||||
// Early exit is not an error and we don't want to pass back a dir
|
|
||||||
#[allow(clippy::exit)]
|
|
||||||
exit(0);
|
|
||||||
} else if buf[0] == SHOW_GUI {
|
|
||||||
remove_dir_all(&path)?;
|
|
||||||
return tempfile::Builder::new()
|
|
||||||
.prefix("rog-gui")
|
|
||||||
.rand_bytes(0)
|
|
||||||
.tempdir();
|
|
||||||
}
|
|
||||||
panic!("Invalid exit or app state");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_ipc_file() -> Result<File, crate::error::Error> {
|
|
||||||
let tmp_dir = std::env::temp_dir().join("rog-gui");
|
|
||||||
let fifo_path = tmp_dir.join("ipc.pipe");
|
|
||||||
if let Err(e) = unistd::mkfifo(&fifo_path, stat::Mode::S_IRWXU) {
|
|
||||||
if !matches!(e, nix::errno::Errno::EEXIST) {
|
|
||||||
Err(e)?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(OpenOptions::new()
|
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
// .truncate(true)
|
|
||||||
.open(&fifo_path)?)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use std::borrow::BorrowMut;
|
use std::env::{self, args};
|
||||||
use std::env::args;
|
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@@ -10,7 +8,7 @@ use std::time::Duration;
|
|||||||
use config_traits::{StdConfig, StdConfigLoad1};
|
use config_traits::{StdConfig, StdConfigLoad1};
|
||||||
use dmi_id::DMIID;
|
use dmi_id::DMIID;
|
||||||
use gumdrop::Options;
|
use gumdrop::Options;
|
||||||
use log::{info, LevelFilter};
|
use log::{debug, info, warn, LevelFilter};
|
||||||
use rog_control_center::cli_options::CliStart;
|
use rog_control_center::cli_options::CliStart;
|
||||||
use rog_control_center::config::Config;
|
use rog_control_center::config::Config;
|
||||||
use rog_control_center::error::Result;
|
use rog_control_center::error::Result;
|
||||||
@@ -18,37 +16,98 @@ use rog_control_center::notify::start_notifications;
|
|||||||
use rog_control_center::slint::ComponentHandle;
|
use rog_control_center::slint::ComponentHandle;
|
||||||
use rog_control_center::tray::init_tray;
|
use rog_control_center::tray::init_tray;
|
||||||
use rog_control_center::ui::setup_window;
|
use rog_control_center::ui::setup_window;
|
||||||
use rog_control_center::{
|
use rog_control_center::zbus_proxies::{
|
||||||
get_ipc_file, on_tmp_dir_exists, print_versions, MainWindow, QUIT_APP, SHOWING_GUI, SHOW_GUI,
|
AppState, ROGCCZbus, ROGCCZbusProxyBlocking, ZBUS_IFACE, ZBUS_PATH,
|
||||||
};
|
};
|
||||||
|
use rog_control_center::{print_versions, MainWindow};
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
// Ensure tracing spans are quiet by default unless user overrides
|
||||||
|
if std::env::var_os("RUST_LOG").is_none() {
|
||||||
|
std::env::set_var("RUST_LOG", "warn,tracing=error,zbus=error");
|
||||||
|
}
|
||||||
|
let mut logger = env_logger::Builder::new();
|
||||||
|
logger
|
||||||
|
.parse_default_env()
|
||||||
|
.filter_level(LevelFilter::Info)
|
||||||
|
.parse_default_env()
|
||||||
|
.target(env_logger::Target::Stderr)
|
||||||
|
.format_timestamp(None)
|
||||||
|
.init();
|
||||||
|
|
||||||
|
// If we're running under gamescope we have to set WAYLAND_DISPLAY for winit to
|
||||||
|
// use
|
||||||
|
if let Ok(gamescope) = env::var("GAMESCOPE_WAYLAND_DISPLAY") {
|
||||||
|
debug!("Gamescope detected");
|
||||||
|
if !gamescope.is_empty() {
|
||||||
|
debug!("Setting WAYLAND_DISPLAY to {}", gamescope);
|
||||||
|
env::set_var("WAYLAND_DISPLAY", gamescope);
|
||||||
|
}
|
||||||
|
// gamescope-0
|
||||||
|
else if let Ok(wayland) = env::var("WAYLAND_DISPLAY") {
|
||||||
|
debug!("Wayland display detected");
|
||||||
|
if wayland.is_empty() {
|
||||||
|
debug!("Setting WAYLAND_DISPLAY to gamescope-0");
|
||||||
|
env::set_var("WAYLAND_DISPLAY", "gamescope-0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to open a proxy and check for app state first
|
||||||
|
{
|
||||||
|
let user_con = zbus::blocking::Connection::session()?;
|
||||||
|
if let Ok(proxy) = ROGCCZbusProxyBlocking::new(&user_con) {
|
||||||
|
if let Ok(state) = proxy.state() {
|
||||||
|
info!("App is already running: {state:?}, opening the window");
|
||||||
|
// if there is a proxy connection assume the app is already running
|
||||||
|
proxy.set_state(AppState::MainWindowShouldOpen)?;
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// version checks
|
||||||
let self_version = env!("CARGO_PKG_VERSION");
|
let self_version = env!("CARGO_PKG_VERSION");
|
||||||
let conn = zbus::blocking::Connection::system()?;
|
let zbus_con = zbus::blocking::Connection::system()?;
|
||||||
let proxy = rog_dbus::zbus_platform::PlatformProxyBlocking::new(&conn)?;
|
let platform_proxy = rog_dbus::zbus_platform::PlatformProxyBlocking::new(&zbus_con)?;
|
||||||
let asusd_version = proxy.version().unwrap();
|
let asusd_version = platform_proxy
|
||||||
|
.version()
|
||||||
|
.map_err(|e| {
|
||||||
|
println!("Could not get asusd version: {e:?}\nIs asusd.service running?");
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
if asusd_version != self_version {
|
if asusd_version != self_version {
|
||||||
println!("Version mismatch: asusctl = {self_version}, asusd = {asusd_version}");
|
println!("Version mismatch: asusctl = {self_version}, asusd = {asusd_version}");
|
||||||
return Ok(());
|
// return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start tokio
|
||||||
|
let rt = Runtime::new().expect("Unable to create Runtime");
|
||||||
|
// Enter the runtime so that `tokio::spawn` is available immediately.
|
||||||
|
let _enter = rt.enter();
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio-debug")]
|
||||||
|
console_subscriber::init();
|
||||||
|
|
||||||
|
let state_zbus = ROGCCZbus::new();
|
||||||
|
let app_state = state_zbus.clone_state();
|
||||||
|
let _conn = zbus::connection::Builder::session()?
|
||||||
|
.name(ZBUS_IFACE)?
|
||||||
|
.serve_at(ZBUS_PATH, state_zbus)?
|
||||||
|
.build()
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("{}: add_to_server {}", ZBUS_PATH, err);
|
||||||
|
err
|
||||||
|
})?;
|
||||||
|
|
||||||
let dmi = DMIID::new().unwrap_or_default();
|
let dmi = DMIID::new().unwrap_or_default();
|
||||||
let board_name = dmi.board_name;
|
let board_name = dmi.board_name;
|
||||||
let prod_family = dmi.product_family;
|
let prod_family = dmi.product_family;
|
||||||
info!("Running on {board_name}, product: {prod_family}");
|
info!("Running on {board_name}, product: {prod_family}");
|
||||||
let is_rog_ally = prod_family == "RC71L";
|
let is_rog_ally = board_name == "RC71L" || board_name == "RC72L" || prod_family == "ROG Ally";
|
||||||
|
|
||||||
// tmp-dir must live to the end of program life
|
|
||||||
let _tmp_dir = match tempfile::Builder::new()
|
|
||||||
.prefix("rog-gui")
|
|
||||||
.rand_bytes(0)
|
|
||||||
.tempdir()
|
|
||||||
{
|
|
||||||
Ok(tmp) => tmp,
|
|
||||||
Err(_) => on_tmp_dir_exists().unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let args: Vec<String> = args().skip(1).collect();
|
let args: Vec<String> = args().skip(1).collect();
|
||||||
|
|
||||||
@@ -63,21 +122,7 @@ async fn main() -> Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut logger = env_logger::Builder::new();
|
let supported_properties = platform_proxy.supported_properties().unwrap_or_default();
|
||||||
logger
|
|
||||||
.filter_level(LevelFilter::Warn)
|
|
||||||
.parse_default_env()
|
|
||||||
.target(env_logger::Target::Stdout)
|
|
||||||
.format_timestamp(None)
|
|
||||||
.init();
|
|
||||||
|
|
||||||
let supported_properties = match proxy.supported_properties() {
|
|
||||||
Ok(s) => s,
|
|
||||||
Err(_e) => {
|
|
||||||
// TODO: show an error window
|
|
||||||
Vec::default()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Startup
|
// Startup
|
||||||
let mut config = Config::new().load();
|
let mut config = Config::new().load();
|
||||||
@@ -98,12 +143,7 @@ async fn main() -> Result<()> {
|
|||||||
config.enable_tray_icon = false;
|
config.enable_tray_icon = false;
|
||||||
config.run_in_background = false;
|
config.run_in_background = false;
|
||||||
config.startup_in_background = false;
|
config.startup_in_background = false;
|
||||||
}
|
config.start_fullscreen = true;
|
||||||
|
|
||||||
if config.startup_in_background {
|
|
||||||
config.run_in_background = true;
|
|
||||||
} else {
|
|
||||||
get_ipc_file().unwrap().write_all(&[SHOW_GUI, 0]).unwrap();
|
|
||||||
}
|
}
|
||||||
config.write();
|
config.write();
|
||||||
|
|
||||||
@@ -111,10 +151,6 @@ async fn main() -> Result<()> {
|
|||||||
let startup_in_background = config.startup_in_background;
|
let startup_in_background = config.startup_in_background;
|
||||||
let config = Arc::new(Mutex::new(config));
|
let config = Arc::new(Mutex::new(config));
|
||||||
|
|
||||||
// start tokio
|
|
||||||
let rt = Runtime::new().expect("Unable to create Runtime");
|
|
||||||
// Enter the runtime so that `tokio::spawn` is available immediately.
|
|
||||||
let _enter = rt.enter();
|
|
||||||
start_notifications(config.clone(), &rt)?;
|
start_notifications(config.clone(), &rt)?;
|
||||||
|
|
||||||
if enable_tray_icon {
|
if enable_tray_icon {
|
||||||
@@ -124,7 +160,11 @@ async fn main() -> Result<()> {
|
|||||||
thread_local! { pub static UI: std::cell::RefCell<Option<MainWindow>> = Default::default()};
|
thread_local! { pub static UI: std::cell::RefCell<Option<MainWindow>> = Default::default()};
|
||||||
// i_slint_backend_selector::with_platform(|_| Ok(())).unwrap();
|
// i_slint_backend_selector::with_platform(|_| Ok(())).unwrap();
|
||||||
|
|
||||||
let mut do_once = !startup_in_background;
|
if !startup_in_background {
|
||||||
|
if let Ok(mut app_state) = app_state.lock() {
|
||||||
|
*app_state = AppState::MainWindowShouldOpen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if std::env::var("RUST_TRANSLATIONS").is_ok() {
|
if std::env::var("RUST_TRANSLATIONS").is_ok() {
|
||||||
// don't care about content
|
// don't care about content
|
||||||
@@ -136,71 +176,104 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut buf = [0u8; 2];
|
let mut state = AppState::StartingUp;
|
||||||
// blocks until it is read, typically the read will happen after a second
|
|
||||||
// process writes to the IPC (so there is data to actually read)
|
|
||||||
loop {
|
loop {
|
||||||
if do_once {
|
if is_rog_ally {
|
||||||
buf[0] = SHOW_GUI;
|
let config_copy_2 = config.clone();
|
||||||
do_once = false;
|
let newui = setup_window(config.clone());
|
||||||
} else {
|
newui.window().on_close_requested(move || {
|
||||||
get_ipc_file().unwrap().read_exact(&mut buf).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
if buf[0] == SHOW_GUI {
|
|
||||||
// There's a balancing act with read/write timing of IPC, there needs to be a
|
|
||||||
// small sleep after this to give any other process a chance to
|
|
||||||
// read the IPC before looping
|
|
||||||
get_ipc_file()
|
|
||||||
.unwrap()
|
|
||||||
.write_all(&[SHOWING_GUI, 0])
|
|
||||||
.unwrap();
|
|
||||||
sleep(Duration::from_millis(50));
|
|
||||||
|
|
||||||
let config_copy = config.clone();
|
|
||||||
slint::invoke_from_event_loop(move || {
|
|
||||||
UI.with(|ui| {
|
|
||||||
let mut ui = ui.borrow_mut();
|
|
||||||
if let Some(ui) = ui.as_mut() {
|
|
||||||
ui.window().show().unwrap();
|
|
||||||
ui.window().on_close_requested(|| {
|
|
||||||
get_ipc_file().unwrap().write_all(&[0, 0]).unwrap();
|
|
||||||
slint::CloseRequestResponse::HideWindow
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
let newui = setup_window(config_copy);
|
|
||||||
newui.window().show().unwrap();
|
|
||||||
newui.window().on_close_requested(|| {
|
|
||||||
get_ipc_file().unwrap().write_all(&[0, 0]).unwrap();
|
|
||||||
slint::CloseRequestResponse::HideWindow
|
|
||||||
});
|
|
||||||
ui.replace(newui);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
} else {
|
|
||||||
if buf[1] == QUIT_APP {
|
|
||||||
slint::quit_event_loop().unwrap();
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
});
|
||||||
if buf[0] != SHOWING_GUI {
|
|
||||||
if let Ok(lock) = config.lock() {
|
let ui_copy = newui.as_weak();
|
||||||
if !lock.run_in_background {
|
newui
|
||||||
slint::quit_event_loop().unwrap();
|
.window()
|
||||||
exit(0);
|
.set_rendering_notifier(move |s, _| {
|
||||||
|
if let slint::RenderingState::BeforeRendering = s {
|
||||||
|
let config = config_copy_2.clone();
|
||||||
|
ui_copy
|
||||||
|
.upgrade_in_event_loop(move |w| {
|
||||||
|
let fullscreen =
|
||||||
|
config.lock().is_ok_and(|c| c.start_fullscreen);
|
||||||
|
if fullscreen && !w.window().is_fullscreen() {
|
||||||
|
w.window().set_fullscreen(fullscreen);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
} else {
|
||||||
|
// save as a var, don't hold the lock the entire time or deadlocks happen
|
||||||
|
if let Ok(app_state) = app_state.lock() {
|
||||||
|
state = *app_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This sleep is required to give the event loop time to react
|
||||||
|
sleep(Duration::from_millis(300));
|
||||||
|
if state == AppState::MainWindowShouldOpen {
|
||||||
|
if let Ok(mut app_state) = app_state.lock() {
|
||||||
|
*app_state = AppState::MainWindowOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let config_copy = config.clone();
|
||||||
|
let app_state_copy = app_state.clone();
|
||||||
slint::invoke_from_event_loop(move || {
|
slint::invoke_from_event_loop(move || {
|
||||||
UI.with(|ui| {
|
UI.with(|ui| {
|
||||||
let mut ui = ui.take();
|
let app_state_copy = app_state_copy.clone();
|
||||||
if let Some(ui) = ui.borrow_mut() {
|
let mut ui = ui.borrow_mut();
|
||||||
ui.window().hide().unwrap();
|
if let Some(ui) = ui.as_mut() {
|
||||||
|
ui.window().show().unwrap();
|
||||||
|
ui.window().on_close_requested(move || {
|
||||||
|
if let Ok(mut app_state) = app_state_copy.lock() {
|
||||||
|
*app_state = AppState::MainWindowClosed;
|
||||||
|
}
|
||||||
|
slint::CloseRequestResponse::HideWindow
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let config_copy_2 = config_copy.clone();
|
||||||
|
let newui = setup_window(config_copy);
|
||||||
|
newui.window().on_close_requested(move || {
|
||||||
|
if let Ok(mut app_state) = app_state_copy.lock() {
|
||||||
|
*app_state = AppState::MainWindowClosed;
|
||||||
|
}
|
||||||
|
slint::CloseRequestResponse::HideWindow
|
||||||
|
});
|
||||||
|
|
||||||
|
let ui_copy = newui.as_weak();
|
||||||
|
newui
|
||||||
|
.window()
|
||||||
|
.set_rendering_notifier(move |s, _| {
|
||||||
|
if let slint::RenderingState::RenderingSetup = s {
|
||||||
|
let config = config_copy_2.clone();
|
||||||
|
ui_copy
|
||||||
|
.upgrade_in_event_loop(move |w| {
|
||||||
|
let fullscreen = config
|
||||||
|
.lock()
|
||||||
|
.is_ok_and(|c| c.start_fullscreen);
|
||||||
|
if fullscreen && !w.window().is_fullscreen() {
|
||||||
|
w.window().set_fullscreen(fullscreen);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
ui.replace(newui);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
} else if state == AppState::QuitApp {
|
||||||
|
slint::quit_event_loop().unwrap();
|
||||||
|
exit(0);
|
||||||
|
} else if state != AppState::MainWindowOpen {
|
||||||
|
if let Ok(config) = config.lock() {
|
||||||
|
if !config.run_in_background {
|
||||||
|
slint::quit_event_loop().unwrap();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,42 +284,6 @@ async fn main() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Bah.. the icon dosn't work on wayland anyway, but we'll leave it in for
|
|
||||||
// now. fn load_icon() -> IconData {
|
|
||||||
// let path = PathBuf::from(APP_ICON_PATH);
|
|
||||||
// let mut rgba = Vec::new();
|
|
||||||
// let mut height = 512;
|
|
||||||
// let mut width = 512;
|
|
||||||
// if path.exists() {
|
|
||||||
// if let Ok(data) = std::fs::read(path)
|
|
||||||
// .map_err(|e| error!("Error reading app icon: {e:?}"))
|
|
||||||
// .map_err(|e| error!("Error opening app icon: {e:?}"))
|
|
||||||
// {
|
|
||||||
// let data = std::io::Cursor::new(data);
|
|
||||||
// let decoder = png_pong::Decoder::new(data).unwrap().into_steps();
|
|
||||||
// let png_pong::Step { raster, delay: _ } =
|
|
||||||
// decoder.last().unwrap().unwrap();
|
|
||||||
|
|
||||||
// if let png_pong::PngRaster::Rgba8(ras) = raster {
|
|
||||||
// rgba = ras.as_u8_slice().to_vec();
|
|
||||||
// width = ras.width();
|
|
||||||
// height = ras.height();
|
|
||||||
// info!("Loaded app icon. Not actually supported in Wayland
|
|
||||||
// yet"); }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// error!("Missing {APP_ICON_PATH}");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// IconData {
|
|
||||||
// height,
|
|
||||||
// width,
|
|
||||||
// rgba
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// / }
|
|
||||||
// }
|
|
||||||
|
|
||||||
fn do_cli_help(parsed: &CliStart) -> bool {
|
fn do_cli_help(parsed: &CliStart) -> bool {
|
||||||
if parsed.help {
|
if parsed.help {
|
||||||
println!("{}", CliStart::usage());
|
println!("{}", CliStart::usage());
|
||||||
|
|||||||
@@ -125,10 +125,18 @@ impl Profile {
|
|||||||
|
|
||||||
pub fn fan_curve_data(&self, _p: rog_profiles::Profile) -> Result<FanCurveSet> {
|
pub fn fan_curve_data(&self, _p: rog_profiles::Profile) -> Result<FanCurveSet> {
|
||||||
let mut curve = FanCurveSet::default();
|
let mut curve = FanCurveSet::default();
|
||||||
curve.cpu.pwm = [30, 40, 60, 100, 140, 180, 200, 250];
|
curve.cpu.pwm = [
|
||||||
curve.cpu.temp = [20, 30, 40, 50, 70, 80, 90, 100];
|
30, 40, 60, 100, 140, 180, 200, 250,
|
||||||
curve.gpu.pwm = [40, 80, 100, 140, 170, 200, 230, 250];
|
];
|
||||||
curve.gpu.temp = [20, 30, 40, 50, 70, 80, 90, 100];
|
curve.cpu.temp = [
|
||||||
|
20, 30, 40, 50, 70, 80, 90, 100,
|
||||||
|
];
|
||||||
|
curve.gpu.pwm = [
|
||||||
|
40, 80, 100, 140, 170, 200, 230, 250,
|
||||||
|
];
|
||||||
|
curve.gpu.temp = [
|
||||||
|
20, 30, 40, 50, 70, 80, 90, 100,
|
||||||
|
];
|
||||||
Ok(curve)
|
Ok(curve)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user