mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
Compare commits
100 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d76cb3b95a | ||
|
|
910f529a9b | ||
|
|
7583d070d3 | ||
|
|
1f85e30e42 | ||
|
|
d1bdf4dc7e | ||
|
|
79b108ceb7 | ||
|
|
7d14e8d900 | ||
|
|
493d61cf19 | ||
|
|
fb08d83999 | ||
|
|
71241b7127 | ||
|
|
09963534d8 | ||
|
|
64322044ac | ||
|
|
1a132d847f | ||
|
|
952a974e83 | ||
|
|
ebbfa58a76 | ||
|
|
414d610bd2 | ||
|
|
bff98ddf7b | ||
|
|
97481cd45e | ||
|
|
4f39c01139 | ||
|
|
40987ecd5d | ||
|
|
f378c54815 | ||
|
|
a8a99ac1d1 | ||
|
|
503aa20257 | ||
|
|
8c67836650 | ||
|
|
3fc839820e | ||
|
|
0ef524a94b | ||
|
|
f8cfacda47 | ||
|
|
f3876100ae | ||
|
|
fa1feaf9d9 | ||
|
|
45641c928d | ||
|
|
eba9dc8a52 | ||
|
|
a32527d1df | ||
|
|
1f697b5ff1 | ||
|
|
92009ef96c | ||
|
|
3fe5896596 | ||
|
|
f8cdde2adf | ||
|
|
033f2141ef | ||
|
|
f86bab6f8c | ||
|
|
4951bce961 | ||
|
|
fb92d65fa0 | ||
|
|
24fa075a44 | ||
|
|
a0f7cf3acd | ||
|
|
d35707f2e4 | ||
|
|
b20bde8116 | ||
|
|
308fba9413 | ||
|
|
45268bfb2b | ||
|
|
004982cea7 | ||
|
|
5ab24a624e | ||
|
|
700633e080 | ||
|
|
773c9902a5 | ||
|
|
e05d5bd143 | ||
|
|
3e244d7d3d | ||
|
|
ba4589f986 | ||
|
|
083134fc73 | ||
|
|
3cc04fba60 | ||
|
|
3a00e4f1a3 | ||
|
|
eb78fb613c | ||
|
|
d0b9aee85a | ||
|
|
3e94ef05fb | ||
|
|
fbb025875b | ||
|
|
ae816bd13c | ||
|
|
14f0693511 | ||
|
|
de7fb4a942 | ||
|
|
4164b4645d | ||
|
|
649b14fd0d | ||
|
|
6d97ef13a1 | ||
|
|
7abad979c8 | ||
|
|
0ec1574219 | ||
|
|
03042dd5c3 | ||
|
|
3330e4973f | ||
|
|
5e06aeabe9 | ||
|
|
e99d8766fc | ||
|
|
8f65b7e334 | ||
|
|
5a54b830bf | ||
|
|
85e08510f7 | ||
|
|
d56eeb7fb2 | ||
|
|
bbc520a7f2 | ||
|
|
10e43c64ca | ||
|
|
38be25174a | ||
|
|
2584d69930 | ||
|
|
523f39cf9c | ||
|
|
669760223e | ||
|
|
71ec13fa9f | ||
|
|
409528b286 | ||
|
|
17df3cf01d | ||
|
|
808a1d2470 | ||
|
|
840c500b5e | ||
|
|
42dc360d16 | ||
|
|
f6183597c9 | ||
|
|
79a45c4f10 | ||
|
|
19370215c0 | ||
|
|
030dd661b8 | ||
|
|
1fc12d9855 | ||
|
|
6c1b2b70ea | ||
|
|
23f9af35bf | ||
|
|
526626b80c | ||
|
|
10eaaac54b | ||
|
|
901a3ddcc9 | ||
|
|
e6ebf72a11 | ||
|
|
a313359ef6 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ cargo-config
|
||||
vendor-*
|
||||
vendor_*
|
||||
.vscode-ctags
|
||||
.vscode
|
||||
40
CHANGELOG.md
40
CHANGELOG.md
@@ -6,6 +6,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased ]
|
||||
|
||||
## [v4.4.0] - 2022-08-29
|
||||
### Added
|
||||
- Support for per-key config has been added to `asusd-user`. At the moment it is
|
||||
basic with only a few effects done. Please see the manual for more information.
|
||||
- Support for unzoned and per-zone effects on some laptops. As above.
|
||||
- Added three effects to use with Zoned or Per-Key:
|
||||
+ Static, Breathe, Flicker. More to come.
|
||||
- Support for G713RS LED modes
|
||||
- Support for TUF laptop RGB (kernel patches required, these are submitted upstream)
|
||||
### Changed
|
||||
- Create new rog-platform crate to manage all i/o in a universal way
|
||||
+ kbd-led handling (requires kernel patches, TUF specific)
|
||||
+ platform handling (asus-nb-wmi)
|
||||
+ power (basic, can be extended in future)
|
||||
+ hidraw
|
||||
+ usbraw
|
||||
- Refactor how ROGCC handles IPC for background open, run-in-bg
|
||||
- Refactor daemon task creation to be simpler (for development)
|
||||
- Rename dpu_only to gpu_mux. Update all related messages and info.
|
||||
### Breaking
|
||||
- DBUS: rename path `/org/asuslinux/RogBios` to `/org/asuslinux/Platform`
|
||||
- DBUS: renamed `dedicated_graphic_mode` to `gpu_mux_mode` (`GpuMuxMode`)
|
||||
- DBUS: renamed `set_dedicated_graphic_mode` to `set_gpu_mux_mode` (`SetGpuMuxMode`)
|
||||
+ The methods above take an enum: 0 = Discrete, 1 = Optimus
|
||||
|
||||
## [4.3.4] - 2022-08-03
|
||||
### Bugfix
|
||||
- ROGCC: Remove power setting from correct array
|
||||
|
||||
## [4.3.3] - 2022-08-02
|
||||
### Added
|
||||
- `rog-control-center` has now been moved in to the main workspace due to
|
||||
the heavy dependencies on most of the rog crates
|
||||
- Preliminary support of TUF RGB keyboards + power states
|
||||
- Support for G713RW LED modes (Author: jarvis2709)
|
||||
- Support for G713IC LED modes
|
||||
### Changed
|
||||
- The udev rules have been changed to make asusd load with all gamer variants when asus-nb-wmi is loaded
|
||||
- TUF, ROG, Zephyrus, Strix
|
||||
|
||||
## [4.3.0] - 2022-07-21
|
||||
### Added
|
||||
- Clear command for anime `asusctl anime --clear` will clear the display
|
||||
|
||||
1886
Cargo.lock
generated
1886
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
[workspace]
|
||||
members = ["asusctl", "asus-notify", "daemon", "daemon-user", "rog-supported", "rog-dbus", "rog-anime", "rog-aura", "rog-profiles"]
|
||||
members = ["asusctl", "asus-notify", "daemon", "daemon-user", "rog-platform", "rog-dbus", "rog-anime", "rog-aura", "rog-profiles", "rog-control-center"]
|
||||
|
||||
[profile.release]
|
||||
# thin = 57s, asusd = 9.0M
|
||||
|
||||
101
MANUAL.md
101
MANUAL.md
@@ -90,8 +90,8 @@ where the number is a percentage.
|
||||
|
||||
Some options that you find in Armory Crate are available under this controller, so far there is:
|
||||
|
||||
- POST sound: this is the sound you here on bios boot post
|
||||
- G-Sync: this controls if the dGPU (Nvidia) is the *only* GPU, making it the main GPU and disabling the iGPU
|
||||
- POST sound: this is the sound you hear on bios boot post
|
||||
- GPU MUX: this controls if the dGPU is the *only* GPU, making it the main GPU and disabling the iGPU
|
||||
|
||||
These options are not written to the config file as they are stored in efivars. The only way to change these is to use the exposed safe dbus methods, or use the `asusctl` CLI tool.
|
||||
|
||||
@@ -131,6 +131,101 @@ As of now only AniMe is active in this with configuration in `~/.config/rog/`. O
|
||||
|
||||
The main config is `~/.config/rog/rog-user.cfg`
|
||||
|
||||
#### Config options: Aura, per-key and zoned
|
||||
|
||||
I'm unsure of how many laptops this works on, so please try it.
|
||||
|
||||
`led_type: Key` works only on actual per-key RGB keyboards.
|
||||
|
||||
`led_type: Zone` works on zoned laptops.
|
||||
|
||||
`led_type: Zone` set to `None` works on zoned ROG laptops, unzoned ROG laptops, and TUF laptops (and yes this does mean an audio EQ can be done now).
|
||||
|
||||
`~/.config/rog/rog-user.cfg` contains a setting `"active_aura": "<FILENAME>"` where `<FILENAME>` is the name of the Aura config to use, located in the same directory and without the file postfix, e.g, `"active_anime": "aura-default"`
|
||||
|
||||
An Aura config itself is a file with contents:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "aura-default",
|
||||
"aura": [
|
||||
{
|
||||
"Breathe": {
|
||||
"led_type": {
|
||||
"Key": "W"
|
||||
},
|
||||
"start_colour1": [
|
||||
255,
|
||||
0,
|
||||
20
|
||||
],
|
||||
"start_colour2": [
|
||||
20,
|
||||
255,
|
||||
0
|
||||
],
|
||||
"speed": "Low"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Static": {
|
||||
"led_type": {
|
||||
"Key": "Esc"
|
||||
},
|
||||
"colour": [
|
||||
0,
|
||||
0,
|
||||
255
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Flicker": {
|
||||
"led_type": {
|
||||
"Key": "N9"
|
||||
},
|
||||
"start_colour": [
|
||||
0,
|
||||
0,
|
||||
255
|
||||
],
|
||||
"max_percentage": 80,
|
||||
"min_percentage": 40
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
If your laptop supports multizone, `"led_type"` can also be `"Zone": <one of the following>`
|
||||
- `"None"`
|
||||
- `"KeyboardLeft"`
|
||||
- `"KeyboardCenterLeft"`
|
||||
- `"KeyboardCenterRight"`
|
||||
- `"KeyboardRight"`
|
||||
- `"LightbarRight"`
|
||||
- `"LightbarRightCorner"`
|
||||
- `"LightbarRightBottom"`
|
||||
- `"LightbarLeftBottom"`
|
||||
- `"LightbarLeftCorner"`
|
||||
- `"LightbarLeft"`
|
||||
|
||||
At the moment there are only three effects available as shown in the example. More will come in the future
|
||||
but this may take me some time.
|
||||
|
||||
**Aura layouts**: `asusd-user` does its best to find a suitable layout to use based on `/sys/class/dmi/id/board_name`.
|
||||
It looks at each of the files in `/usr/share/rog-gui/layouts/` and matches against the toml block looking like:
|
||||
```toml
|
||||
matches = [
|
||||
'GX502',
|
||||
'GU502',
|
||||
]
|
||||
```
|
||||
|
||||
My laptop is a `GX502GW`, so `GX502` is a match. Note that these layouts are the physical representation of
|
||||
the keyboard and are used in the GUI also. The config that tells if per-key is supported is located in
|
||||
`/etc/asusd/asusd-ledmodes.toml`
|
||||
|
||||
#### Config options: AniMe
|
||||
|
||||
`~/.config/rog/rog-user.cfg` contains a setting `"active_anime": "<FILENAME>"` where `<FILENAME>` is the name of the AniMe config to use, located in the same directory and without the file postfix, e.g, `"active_anime": "anime-doom"`
|
||||
@@ -293,7 +388,7 @@ A plain non-float integer.
|
||||
|
||||
## asusctl
|
||||
|
||||
`asusctl` is a commandline interface which intends to be the main method of interacting with `asusd`. I can be used in any place a terminal app can be used.
|
||||
`asusctl` is a commandline interface which intends to be the main method of interacting with `asusd`. It can be used in any place a terminal app can be used.
|
||||
|
||||
This program will query `asusd` for the `Support` level of the laptop and show or hide options according to this support level.
|
||||
|
||||
|
||||
17
Makefile
17
Makefile
@@ -11,6 +11,7 @@ datarootdir = $(prefix)/share
|
||||
libdir = $(exec_prefix)/lib
|
||||
zshcpl = $(datarootdir)/zsh/site-functions
|
||||
|
||||
BIN_ROG := rog-control-center
|
||||
BIN_C := asusctl
|
||||
BIN_D := asusd
|
||||
BIN_U := asusd-user
|
||||
@@ -39,6 +40,11 @@ distclean:
|
||||
rm -rf .cargo vendor vendor.tar.xz
|
||||
|
||||
install:
|
||||
$(INSTALL_PROGRAM) "./target/release/$(BIN_ROG)" "$(DESTDIR)$(bindir)/$(BIN_ROG)"
|
||||
$(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"
|
||||
cd rog-aura/data/layouts && find . -type f -name "*.toml" -exec $(INSTALL_DATA) "{}" "$(DESTDIR)$(datarootdir)/rog-gui/layouts/{}" \;
|
||||
|
||||
$(INSTALL_PROGRAM) "./target/release/$(BIN_C)" "$(DESTDIR)$(bindir)/$(BIN_C)"
|
||||
$(INSTALL_PROGRAM) "./target/release/$(BIN_D)" "$(DESTDIR)$(bindir)/$(BIN_D)"
|
||||
$(INSTALL_PROGRAM) "./target/release/$(BIN_U)" "$(DESTDIR)$(bindir)/$(BIN_U)"
|
||||
@@ -63,11 +69,13 @@ install:
|
||||
$(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/_asusctl" "$(DESTDIR)$(zshcpl)/_asusctl"
|
||||
$(INSTALL_DATA) "./data/completions/asusctl.fish" "$(DESTDIR)$(datarootdir)/fish/vendor_completions.d/asusctl.fish"
|
||||
cd rog-anime/data && find "./anime" -type f -exec install -Dm 755 "{}" "$(DESTDIR)$(datarootdir)/asusd/{}" \;
|
||||
cd rog-anime/data && find "./anime" -type f -exec $(INSTALL_DATA) "{}" "$(DESTDIR)$(datarootdir)/asusd/{}" \;
|
||||
|
||||
uninstall:
|
||||
rm -f "$(DESTDIR)$(bindir)/$(BIN_ROG)"
|
||||
rm -r "$(DESTDIR)$(datarootdir)/applications/$(BIN_ROG).desktop"
|
||||
rm -r "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/$(BIN_ROG).png"
|
||||
|
||||
rm -f "$(DESTDIR)$(bindir)/$(BIN_C)"
|
||||
rm -f "$(DESTDIR)$(bindir)/$(BIN_D)"
|
||||
rm -f "$(DESTDIR)$(bindir)/$(BIN_N)"
|
||||
@@ -85,9 +93,8 @@ uninstall:
|
||||
rm -r "$(DESTDIR)$(datarootdir)/icons/hicolor/scalable/status/gpu-nvidia.svg"
|
||||
rm -r "$(DESTDIR)$(datarootdir)/icons/hicolor/scalable/status/gpu-vfio.svg"
|
||||
rm -r "$(DESTDIR)$(datarootdir)/icons/hicolor/scalable/status/notification-reboot.svg"
|
||||
rm -f "$(DESTDIR)$(zshcpl)/_asusctl"
|
||||
rm -f "$(DESTDIR)$(datarootdir)/fish/vendor_completions.d/asusctl.fish"
|
||||
rm -rf "$(DESTDIR)$(datarootdir)/asusd"
|
||||
rm -rf "$(DESTDIR)$(datarootdir)/rog-gui"
|
||||
|
||||
update:
|
||||
cargo update
|
||||
|
||||
30
README.md
30
README.md
@@ -2,14 +2,16 @@
|
||||
|
||||
[](https://www.paypal.com/donate/?hosted_button_id=4V2DEPS7K6APC) - [Asus Linux Website](https://asus-linux.org/)
|
||||
|
||||
**WARNING:** Do not run the main branch of this repo unless you have all the asus-wmi kernel patches. You should use stable kernels + tagged releases.
|
||||
|
||||
`asusd` is a utility for Linux to control many aspects of various ASUS laptops
|
||||
but can also be used with non-asus laptops with reduced features.
|
||||
|
||||
Now includes a GUI, `rog-control-center`.
|
||||
|
||||
## Kernel support
|
||||
|
||||
**The minimum supported kernel version is 5.15**
|
||||
|
||||
Fan curve control on laptops with this feature require [this patch](https://lkml.org/lkml/2021/10/23/250) which has been merged for 5.17 upstream.
|
||||
**The minimum supported kernel version is 5.17**
|
||||
|
||||
## Goals
|
||||
|
||||
@@ -19,8 +21,8 @@ Fan curve control on laptops with this feature require [this patch](https://lkml
|
||||
4. Respect the users resources: be small, light, and fast
|
||||
|
||||
Point 3 means that the list of supported distros is very narrow - fedora is explicitly
|
||||
supported, while Ubuntu and openSUSE are level-2 support. All other distros are *not*
|
||||
supported (while asusd might still run fine on them). For best support use fedora 32+ Workstation.
|
||||
supported. All other distros are *not* supported (while asusd might still run fine on them).
|
||||
For best support use fedora 36+ Workstation.
|
||||
|
||||
Point 4? asusd currently uses a tiny fraction of cpu time, and less than 1Mb of ram, the way
|
||||
a system-level daemon should.
|
||||
@@ -39,12 +41,14 @@ Bus 001 Device 002: ID 0b05:1866 ASUSTek Computer, Inc. N-KEY Device
|
||||
```
|
||||
|
||||
then it may work without tweaks. Technically all other functions except the LED
|
||||
and AniMe parts should work regardless of your latop make. Eventually this project
|
||||
will probably suffer another rename once it becomes generic enough to do so.
|
||||
and AniMe parts should work regardless of your latop make.
|
||||
|
||||
**TUF Laptops**: now supported provided the kernel is patched. These patches are submitted upstream and will be in version 6.1.x of the kernel (or thereabouts). See the blog on asus-linux.org for more info.
|
||||
|
||||
## Implemented
|
||||
|
||||
- [X] System daemon
|
||||
- [X] GUI app
|
||||
- [X] User notifications daemon
|
||||
- [X] Setting/modifying built-in LED modes
|
||||
- [X] Per-key LED setting
|
||||
@@ -52,9 +56,17 @@ will probably suffer another rename once it becomes generic enough to do so.
|
||||
- [X] Saving settings for reload
|
||||
- [X] AniMatrix display on G14 models that include it
|
||||
- [X] Set battery charge limit (with kernel supporting this)
|
||||
- [X] Fan curve control on G14 + G15. Requires kernel patch (should reach 5.15 kernel)
|
||||
- [X] Fan curve control on supported laptops (G14/G15, some TUF like FA507)
|
||||
- [X] Toggle bios setting for boot/POST sound
|
||||
- [X] Toggle bios setting for "dedicated gfx" mode on supported laptops (g-sync)
|
||||
- [X] Toggle GPU MUX (g-sync, or called MUX on 2022+ laptops)
|
||||
|
||||
# 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.
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
# BUILDING
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ zbus = "^2.2"
|
||||
serde_json = "^1.0"
|
||||
rog_dbus = { path = "../rog-dbus" }
|
||||
rog_aura = { path = "../rog-aura" }
|
||||
rog_supported = { path = "../rog-supported" }
|
||||
rog_platform = { path = "../rog-platform" }
|
||||
rog_profiles = { path = "../rog-profiles" }
|
||||
smol = "^1.2"
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use notify_rust::{Hint, Notification, NotificationHandle};
|
||||
use rog_aura::AuraEffect;
|
||||
use rog_dbus::{
|
||||
zbus_charge::ChargeProxy, zbus_led::LedProxy, zbus_profile::ProfileProxy,
|
||||
zbus_rogbios::RogBiosProxy,
|
||||
zbus_charge::ChargeProxy, zbus_led::LedProxy, zbus_platform::RogBiosProxy,
|
||||
zbus_profile::ProfileProxy,
|
||||
};
|
||||
use rog_profiles::Profile;
|
||||
use smol::{future, Executor};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "asusctl"
|
||||
version = "4.3.0"
|
||||
version = "4.3.3"
|
||||
authors = ["Luke D Jones <luke@ljones.dev>"]
|
||||
edition = "2018"
|
||||
|
||||
@@ -12,7 +12,7 @@ rog_anime = { path = "../rog-anime" }
|
||||
rog_aura = { path = "../rog-aura" }
|
||||
rog_dbus = { path = "../rog-dbus" }
|
||||
rog_profiles = { path = "../rog-profiles" }
|
||||
rog_supported = { path = "../rog-supported" }
|
||||
rog_platform = { path = "../rog-platform" }
|
||||
daemon = { path = "../daemon" }
|
||||
gumdrop = "^0.8"
|
||||
toml = "^0.5.8"
|
||||
@@ -21,6 +21,6 @@ sysfs-class = "^0.1.2"
|
||||
|
||||
[dev-dependencies]
|
||||
tinybmp = "^0.3.3"
|
||||
glam = "0.20.5"
|
||||
glam = "^0.21.2"
|
||||
rog_dbus = { path = "../rog-dbus" }
|
||||
gif = "^0.11.2"
|
||||
|
||||
113
asusctl/examples/aura-rgb-ball.rs
Normal file
113
asusctl/examples/aura-rgb-ball.rs
Normal file
@@ -0,0 +1,113 @@
|
||||
//! Very bad rushed example. The better way to do this would be to have
|
||||
//! the balles move on their own square grid, then translate that to the
|
||||
//! key layout via shape by pitch etc.
|
||||
use rog_aura::{
|
||||
layouts::{KeyLayout, KeyRow},
|
||||
KeyColourArray,
|
||||
};
|
||||
use rog_dbus::RogDbusClientBlocking;
|
||||
use std::collections::LinkedList;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Ball {
|
||||
position: (f32, f32),
|
||||
direction: (f32, f32),
|
||||
trail: LinkedList<(f32, f32)>,
|
||||
}
|
||||
impl Ball {
|
||||
fn new(x: f32, y: f32, trail_len: u32) -> Self {
|
||||
let mut trail = LinkedList::new();
|
||||
for _ in 1..=trail_len {
|
||||
trail.push_back((x, y));
|
||||
}
|
||||
|
||||
Ball {
|
||||
position: (x, y),
|
||||
direction: (1.0, 1.0),
|
||||
trail,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::if_same_then_else)]
|
||||
fn update(&mut self, key_map: &[KeyRow]) {
|
||||
self.position.0 += self.direction.0;
|
||||
self.position.1 += self.direction.1;
|
||||
|
||||
if self.position.1.abs() as usize >= key_map.len() {
|
||||
self.direction.1 *= -1.0;
|
||||
self.position.1 += self.direction.1;
|
||||
self.direction.0 *= -1.0;
|
||||
self.position.0 += self.direction.0;
|
||||
}
|
||||
if self.position.0.abs() as usize >= key_map[self.position.1.abs() as usize].row_ref().len()
|
||||
{
|
||||
self.direction.1 *= -1.0;
|
||||
self.position.1 += self.direction.1;
|
||||
}
|
||||
if self.position.0 as usize >= key_map[self.position.1.abs() as usize].row_ref().len() {
|
||||
self.direction.0 *= -1.0;
|
||||
self.position.0 += self.direction.0;
|
||||
}
|
||||
|
||||
let pos = self.position;
|
||||
|
||||
if pos.1 == key_map[pos.1.abs() as usize].row_ref().len() as f32 - 1.0 || pos.1 <= 0.0 {
|
||||
self.direction.0 *= -1.0;
|
||||
} else if key_map[(pos.1) as usize].row_ref()[(pos.0) as usize].is_placeholder() {
|
||||
self.direction.0 *= -1.0;
|
||||
}
|
||||
|
||||
if pos.0 == key_map.len() as f32 - 1.0 || pos.0 <= 0.0 {
|
||||
self.direction.1 *= -1.0;
|
||||
} else if key_map[(pos.1) as usize].row_ref()[(pos.0) as usize].is_placeholder() {
|
||||
self.direction.1 *= -1.0;
|
||||
}
|
||||
|
||||
self.trail.pop_front();
|
||||
self.trail.push_back(self.position);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (dbus, _) = RogDbusClientBlocking::new()?;
|
||||
|
||||
let mut colours = KeyColourArray::new();
|
||||
let layout = KeyLayout::gx502_layout();
|
||||
|
||||
let mut balls = [Ball::new(2.0, 1.0, 12), Ball::new(5.0, 2.0, 12)];
|
||||
// let mut balls = [Ball::new(2, 1, 12)];
|
||||
|
||||
loop {
|
||||
for (n, ball) in balls.iter_mut().enumerate() {
|
||||
ball.update(layout.rows_ref());
|
||||
for (i, pos) in ball.trail.iter().enumerate() {
|
||||
if let Some(c) = colours
|
||||
.rgb_for_key(layout.rows_ref()[pos.1.abs() as usize].row_ref()[pos.0 as usize])
|
||||
{
|
||||
c[0] = 0;
|
||||
c[1] = 0;
|
||||
c[2] = 0;
|
||||
if n == 0 {
|
||||
c[0] = i as u8 * (255 / ball.trail.len() as u8);
|
||||
} else if n == 1 {
|
||||
c[1] = i as u8 * (255 / ball.trail.len() as u8);
|
||||
} else if n == 2 {
|
||||
c[2] = i as u8 * (255 / ball.trail.len() as u8);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if let Some(c) = colours.rgb_for_key(
|
||||
layout.rows_ref()[ball.position.1.abs() as usize].row_ref()
|
||||
[ball.position.0 as usize],
|
||||
) {
|
||||
c[0] = 255;
|
||||
c[1] = 255;
|
||||
c[2] = 255;
|
||||
};
|
||||
}
|
||||
dbus.proxies().led().per_key_raw(colours.get())?;
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(150));
|
||||
}
|
||||
}
|
||||
59
asusctl/examples/aura-rgb-breathe.rs
Normal file
59
asusctl/examples/aura-rgb-breathe.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
//! Using a combination of key-colour array plus a key layout to generate outputs.
|
||||
|
||||
use rog_aura::{keys::Key, layouts::KeyLayout, Breathe, Colour, Effect, LedType, Sequences, Speed};
|
||||
use rog_dbus::RogDbusClientBlocking;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let layout = KeyLayout::gx502_layout();
|
||||
|
||||
let (client, _) = RogDbusClientBlocking::new().unwrap();
|
||||
|
||||
let mut seq = Sequences::new();
|
||||
let mut key = Effect::Breathe(Breathe::new(
|
||||
LedType::Key(Key::W),
|
||||
Colour(255, 127, 0),
|
||||
Colour(127, 0, 255),
|
||||
Speed::Med,
|
||||
));
|
||||
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::A));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::S));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::D));
|
||||
seq.push(key.clone());
|
||||
|
||||
let mut key = Effect::Breathe(Breathe::new(
|
||||
LedType::Key(Key::Q),
|
||||
Colour(127, 127, 127),
|
||||
Colour(127, 255, 255),
|
||||
Speed::Low,
|
||||
));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::E));
|
||||
seq.push(key.clone());
|
||||
|
||||
let mut key = Effect::Breathe(Breathe::new(
|
||||
LedType::Key(Key::N1),
|
||||
Colour(166, 127, 166),
|
||||
Colour(127, 155, 20),
|
||||
Speed::High,
|
||||
));
|
||||
key.set_led_type(LedType::Key(Key::Tilde));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::N2));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::N3));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::N4));
|
||||
seq.push(key.clone());
|
||||
|
||||
loop {
|
||||
seq.next_state(&layout);
|
||||
let packets = seq.create_packets();
|
||||
|
||||
client.proxies().led().per_key_raw(packets)?;
|
||||
std::thread::sleep(std::time::Duration::from_millis(60));
|
||||
}
|
||||
}
|
||||
34
asusctl/examples/aura-rgb-iterate-keys.rs
Normal file
34
asusctl/examples/aura-rgb-iterate-keys.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
//! Using a combination of key-colour array plus a key layout to generate outputs.
|
||||
|
||||
use rog_aura::{layouts::KeyLayout, KeyColourArray};
|
||||
use rog_dbus::RogDbusClientBlocking;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (client, _) = RogDbusClientBlocking::new().unwrap();
|
||||
let layout = KeyLayout::gx502_layout();
|
||||
loop {
|
||||
let mut key_colours = KeyColourArray::new();
|
||||
for row in layout.rows() {
|
||||
for (k, key) in row.row().enumerate() {
|
||||
if k != 0 {
|
||||
if let Some(prev) = row.row().nth(k - 1) {
|
||||
if let Some(c) = key_colours.rgb_for_key(*prev) {
|
||||
c[0] = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if key.is_placeholder() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(c) = key_colours.rgb_for_key(*key) {
|
||||
c[0] = 255;
|
||||
};
|
||||
|
||||
client.proxies().led().per_key_raw(key_colours.get())?;
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
asusctl/examples/aura-zoned-breathe.rs
Normal file
44
asusctl/examples/aura-zoned-breathe.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
//! Using a combination of key-colour array plus a key layout to generate outputs.
|
||||
|
||||
use rog_aura::{layouts::KeyLayout, Breathe, Colour, Effect, LedType, PerZone, Sequences, Speed};
|
||||
use rog_dbus::RogDbusClientBlocking;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let layout = KeyLayout::gx502_layout();
|
||||
|
||||
let (client, _) = RogDbusClientBlocking::new().unwrap();
|
||||
|
||||
let mut seq = Sequences::new();
|
||||
|
||||
let zone = Effect::Breathe(Breathe::new(
|
||||
LedType::Zone(PerZone::KeyboardLeft),
|
||||
Colour(166, 127, 166),
|
||||
Colour(127, 155, 20),
|
||||
Speed::High,
|
||||
));
|
||||
seq.push(zone);
|
||||
|
||||
let zone = Effect::Breathe(Breathe::new(
|
||||
LedType::Zone(PerZone::KeyboardCenterLeft),
|
||||
Colour(16, 127, 255),
|
||||
Colour(127, 15, 20),
|
||||
Speed::Low,
|
||||
));
|
||||
seq.push(zone);
|
||||
|
||||
let zone = Effect::Breathe(Breathe::new(
|
||||
LedType::Zone(PerZone::LightbarRightCorner),
|
||||
Colour(0, 255, 255),
|
||||
Colour(255, 0, 255),
|
||||
Speed::Med,
|
||||
));
|
||||
seq.push(zone);
|
||||
|
||||
loop {
|
||||
seq.next_state(&layout);
|
||||
let packets = seq.create_packets();
|
||||
|
||||
client.proxies().led().per_key_raw(packets)?;
|
||||
std::thread::sleep(std::time::Duration::from_millis(60));
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,8 @@ pub struct AuraEnabled {
|
||||
pub logo: Option<bool>,
|
||||
#[options(meta = "", help = "<true/false>")]
|
||||
pub lightbar: Option<bool>,
|
||||
#[options(meta = "", help = "<true/false>")]
|
||||
pub lid: Option<bool>,
|
||||
}
|
||||
|
||||
// impl FromStr for AuraEnabled {
|
||||
@@ -56,7 +58,6 @@ pub struct AuraEnabled {
|
||||
|
||||
// fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// let s = s.to_lowercase();
|
||||
// dbg!(s);
|
||||
// Ok(Self {
|
||||
// help: false,
|
||||
// keyboard: None,
|
||||
|
||||
@@ -80,11 +80,11 @@ pub struct BiosCommand {
|
||||
meta = "",
|
||||
short = "D",
|
||||
no_long,
|
||||
help = "activate dGPU dedicated/G-Sync: asusctl -d <true/false>, reboot required"
|
||||
help = "Switch GPU MUX mode: 0 = Discrete, 1 = Optimus, reboot required"
|
||||
)]
|
||||
pub dedicated_gfx_set: Option<bool>,
|
||||
pub gpu_mux_mode_set: Option<u8>,
|
||||
#[options(no_long, short = "d", help = "get GPU mode")]
|
||||
pub dedicated_gfx_get: bool,
|
||||
pub gpu_mux_mode_get: bool,
|
||||
#[options(
|
||||
meta = "",
|
||||
short = "O",
|
||||
|
||||
@@ -10,15 +10,13 @@ use anime_cli::{AnimeActions, AnimeCommand};
|
||||
use profiles_cli::{FanCurveCommand, ProfileCommand};
|
||||
use rog_anime::usb::get_anime_type;
|
||||
use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, Vec2};
|
||||
use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraPowerDev};
|
||||
|
||||
use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraDevTuf, AuraDevice, AuraPowerDev};
|
||||
use rog_aura::{self, AuraEffect};
|
||||
use rog_dbus::RogDbusClientBlocking;
|
||||
use rog_platform::platform::GpuMode;
|
||||
use rog_platform::supported::*;
|
||||
use rog_profiles::error::ProfileError;
|
||||
use rog_supported::SupportedFunctions;
|
||||
use rog_supported::{
|
||||
AnimeSupportedFunctions, LedSupportedFunctions, PlatformProfileFunctions,
|
||||
RogBiosSupportedFunctions,
|
||||
};
|
||||
|
||||
use crate::aura_cli::LedBrightness;
|
||||
use crate::cli_opts::*;
|
||||
@@ -101,7 +99,7 @@ fn print_versions() {
|
||||
println!(" rog-aura v{}", rog_aura::VERSION);
|
||||
println!(" rog-dbus v{}", rog_dbus::VERSION);
|
||||
println!(" rog-profiles v{}", rog_profiles::VERSION);
|
||||
println!("rog-supported v{}", rog_supported::VERSION);
|
||||
println!("rog-platform v{}", rog_platform::VERSION);
|
||||
}
|
||||
|
||||
fn print_laptop_info() {
|
||||
@@ -159,12 +157,17 @@ fn do_parsed(
|
||||
if let Some(cmdlist) = CliStart::command_list() {
|
||||
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_string()).collect();
|
||||
for command in commands.iter().filter(|command| {
|
||||
if supported.keyboard_led.prod_id != "1866"
|
||||
&& command.trim().starts_with("led-pow-1")
|
||||
if !matches!(
|
||||
supported.keyboard_led.prod_id,
|
||||
AuraDevice::X1854
|
||||
| AuraDevice::X1869
|
||||
| AuraDevice::X1866
|
||||
| AuraDevice::Tuf
|
||||
) && command.trim().starts_with("led-pow-1")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if supported.keyboard_led.prod_id != "19b6"
|
||||
if supported.keyboard_led.prod_id != AuraDevice::X19B6
|
||||
&& command.trim().starts_with("led-pow-2")
|
||||
{
|
||||
return false;
|
||||
@@ -455,11 +458,27 @@ fn handle_led_power1(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if supported.prod_id != "1866" {
|
||||
println!("These options are for keyboards of product ID 0x1866 only");
|
||||
if matches!(
|
||||
supported.prod_id,
|
||||
AuraDevice::X1854 | AuraDevice::X1869 | AuraDevice::X1866
|
||||
) {
|
||||
handle_led_power_1_do_1866(dbus, power)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if matches!(supported.prod_id, AuraDevice::Tuf) {
|
||||
handle_led_power_1_do_tuf(dbus, power)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
println!("These options are for keyboards of product ID 0x1866 or TUF only");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn handle_led_power_1_do_1866(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
power: &LedPowerCommand1,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut enabled: Vec<AuraDev1866> = Vec::new();
|
||||
let mut disabled: Vec<AuraDev1866> = Vec::new();
|
||||
|
||||
@@ -482,12 +501,54 @@ fn handle_led_power1(
|
||||
let data = AuraPowerDev {
|
||||
x1866: enabled,
|
||||
x19b6: vec![],
|
||||
tuf: vec![],
|
||||
};
|
||||
dbus.proxies().led().set_leds_power(data, true)?;
|
||||
|
||||
let data = AuraPowerDev {
|
||||
x1866: disabled,
|
||||
x19b6: vec![],
|
||||
tuf: vec![],
|
||||
};
|
||||
dbus.proxies().led().set_leds_power(data, false)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_led_power_1_do_tuf(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
power: &LedPowerCommand1,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut enabled: Vec<AuraDevTuf> = Vec::new();
|
||||
let mut disabled: Vec<AuraDevTuf> = Vec::new();
|
||||
|
||||
let mut check = |e: Option<bool>, a: AuraDevTuf| {
|
||||
if let Some(arg) = e {
|
||||
if arg {
|
||||
enabled.push(a);
|
||||
} else {
|
||||
disabled.push(a);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
check(power.awake, AuraDevTuf::Awake);
|
||||
check(power.boot, AuraDevTuf::Boot);
|
||||
check(power.sleep, AuraDevTuf::Sleep);
|
||||
check(power.keyboard, AuraDevTuf::Keyboard);
|
||||
|
||||
let data = AuraPowerDev {
|
||||
x1866: vec![],
|
||||
x19b6: vec![],
|
||||
tuf: enabled,
|
||||
};
|
||||
dbg!(&data);
|
||||
dbus.proxies().led().set_leds_power(data, true)?;
|
||||
|
||||
let data = AuraPowerDev {
|
||||
x1866: vec![],
|
||||
x19b6: vec![],
|
||||
tuf: disabled,
|
||||
};
|
||||
dbus.proxies().led().set_leds_power(data, false)?;
|
||||
|
||||
@@ -523,8 +584,8 @@ fn handle_led_power2(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if supported.prod_id == "1866" {
|
||||
println!("This option does not apply to keyboards with product ID 0x1866")
|
||||
if supported.prod_id != AuraDevice::X19B6 {
|
||||
println!("This option applies only to keyboards with product ID 0x19b6")
|
||||
}
|
||||
|
||||
let mut enabled: Vec<AuraDev19b6> = Vec::new();
|
||||
@@ -544,26 +605,31 @@ fn handle_led_power2(
|
||||
check(arg.keyboard, AuraDev19b6::BootKeyb);
|
||||
check(arg.logo, AuraDev19b6::BootLogo);
|
||||
check(arg.lightbar, AuraDev19b6::BootBar);
|
||||
check(arg.lid, AuraDev19b6::AwakeLid);
|
||||
}
|
||||
aura_cli::SetAuraEnabled::Sleep(arg) => {
|
||||
check(arg.keyboard, AuraDev19b6::SleepKeyb);
|
||||
check(arg.logo, AuraDev19b6::SleepLogo);
|
||||
check(arg.lightbar, AuraDev19b6::SleepBar);
|
||||
check(arg.lid, AuraDev19b6::SleepLid);
|
||||
}
|
||||
aura_cli::SetAuraEnabled::Awake(arg) => {
|
||||
check(arg.keyboard, AuraDev19b6::AwakeKeyb);
|
||||
check(arg.logo, AuraDev19b6::AwakeLogo);
|
||||
check(arg.lightbar, AuraDev19b6::AwakeBar);
|
||||
check(arg.lid, AuraDev19b6::AwakeLid);
|
||||
}
|
||||
aura_cli::SetAuraEnabled::Shutdown(arg) => {
|
||||
check(arg.keyboard, AuraDev19b6::ShutdownKeyb);
|
||||
check(arg.logo, AuraDev19b6::ShutdownLogo);
|
||||
check(arg.lightbar, AuraDev19b6::ShutdownBar);
|
||||
check(arg.lid, AuraDev19b6::ShutdownBar);
|
||||
}
|
||||
}
|
||||
|
||||
if !enabled.is_empty() {
|
||||
let data = AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: vec![],
|
||||
x19b6: enabled,
|
||||
};
|
||||
@@ -572,6 +638,7 @@ fn handle_led_power2(
|
||||
|
||||
if !disabled.is_empty() {
|
||||
let data = AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: vec![],
|
||||
x19b6: disabled,
|
||||
};
|
||||
@@ -691,8 +758,8 @@ fn handle_bios_option(
|
||||
cmd: &BiosCommand,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
{
|
||||
if (cmd.dedicated_gfx_set.is_none()
|
||||
&& !cmd.dedicated_gfx_get
|
||||
if (cmd.gpu_mux_mode_set.is_none()
|
||||
&& !cmd.gpu_mux_mode_get
|
||||
&& cmd.post_sound_set.is_none()
|
||||
&& !cmd.post_sound_get
|
||||
&& cmd.panel_overdrive_set.is_none()
|
||||
@@ -708,7 +775,7 @@ fn handle_bios_option(
|
||||
|
||||
for line in usage.iter().filter(|line| {
|
||||
line.contains("sound") && supported.post_sound
|
||||
|| line.contains("GPU") && supported.dedicated_gfx
|
||||
|| line.contains("GPU") && supported.gpu_mux
|
||||
|| line.contains("panel") && supported.panel_overdrive
|
||||
}) {
|
||||
println!("{}", line);
|
||||
@@ -723,28 +790,23 @@ fn handle_bios_option(
|
||||
println!("Bios POST sound on: {}", res);
|
||||
}
|
||||
|
||||
if let Some(opt) = cmd.dedicated_gfx_set {
|
||||
if let Some(opt) = cmd.gpu_mux_mode_set {
|
||||
println!("Rebuilding initrd to include drivers");
|
||||
dbus.proxies().rog_bios().set_dedicated_graphic_mode(opt)?;
|
||||
dbus.proxies()
|
||||
.rog_bios()
|
||||
.set_gpu_mux_mode(GpuMode::from_mux(opt))?;
|
||||
println!("The mode change is not active until you reboot, on boot the bios will make the required change");
|
||||
if opt {
|
||||
println!(
|
||||
"NOTE: on reboot your display manager will be forced to use Nvidia drivers"
|
||||
);
|
||||
} else {
|
||||
println!("NOTE: after reboot you can then select regular graphics modes");
|
||||
}
|
||||
}
|
||||
if cmd.dedicated_gfx_get {
|
||||
let res = dbus.proxies().rog_bios().dedicated_graphic_mode()? == 1;
|
||||
println!("Bios dedicated GPU on: {}", res);
|
||||
if cmd.gpu_mux_mode_get {
|
||||
let res = dbus.proxies().rog_bios().gpu_mux_mode()?;
|
||||
println!("Bios GPU MUX: {:?}", res);
|
||||
}
|
||||
|
||||
if let Some(opt) = cmd.panel_overdrive_set {
|
||||
dbus.proxies().rog_bios().set_panel_overdrive(opt)?;
|
||||
}
|
||||
if cmd.panel_overdrive_get {
|
||||
let res = dbus.proxies().rog_bios().panel_overdrive()? == 1;
|
||||
let res = dbus.proxies().rog_bios().panel_overdrive()?;
|
||||
println!("Panel overdrive on: {}", res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "daemon-user"
|
||||
version = "1.3.0"
|
||||
version = "1.3.1"
|
||||
authors = ["Luke D Jones <luke@ljones.dev>"]
|
||||
edition = "2018"
|
||||
description = "Usermode daemon for user settings, anime, per-key lighting"
|
||||
@@ -20,8 +20,9 @@ serde_json = "^1.0"
|
||||
serde_derive = "^1.0"
|
||||
|
||||
rog_anime = { path = "../rog-anime" }
|
||||
rog_aura = { path = "../rog-aura" }
|
||||
rog_dbus = { path = "../rog-dbus" }
|
||||
rog_supported = { path = "../rog-supported" }
|
||||
rog_platform = { path = "../rog-platform" }
|
||||
|
||||
dirs = "^4.0"
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use zbus::dbus_interface;
|
||||
use zvariant::ObjectPath;
|
||||
use zvariant_derive::Type;
|
||||
|
||||
use crate::user_config::ConfigLoadSave;
|
||||
use crate::{error::Error, user_config::UserAnimeConfig};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Type)]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use rog_anime::usb::get_anime_type;
|
||||
use rog_aura::layouts::KeyLayout;
|
||||
use rog_dbus::RogDbusClientBlocking;
|
||||
use rog_user::{
|
||||
ctrl_anime::{CtrlAnime, CtrlAnimeInner},
|
||||
@@ -6,64 +7,104 @@ use rog_user::{
|
||||
DBUS_NAME,
|
||||
};
|
||||
use smol::Executor;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::{fs::OpenOptions, io::Read, path::PathBuf, sync::Arc};
|
||||
use zbus::Connection;
|
||||
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
#[cfg(not(feature = "local_data"))]
|
||||
const DATA_DIR: &str = "/usr/share/rog-gui/";
|
||||
#[cfg(feature = "local_data")]
|
||||
const DATA_DIR: &str = env!("CARGO_MANIFEST_DIR");
|
||||
const BOARD_NAME: &str = "/sys/class/dmi/id/board_name";
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!(" user daemon v{}", rog_user::VERSION);
|
||||
println!(" rog-anime v{}", rog_anime::VERSION);
|
||||
println!(" rog-dbus v{}", rog_dbus::VERSION);
|
||||
println!("rog-supported v{}", rog_supported::VERSION);
|
||||
println!("rog-platform v{}", rog_platform::VERSION);
|
||||
|
||||
let (client, _) = RogDbusClientBlocking::new()?;
|
||||
let supported = client.proxies().supported().supported_functions()?;
|
||||
|
||||
let mut config = UserConfig::new();
|
||||
config.load_config()?;
|
||||
config.load()?;
|
||||
|
||||
let executor = Executor::new();
|
||||
|
||||
let early_return = Arc::new(AtomicBool::new(false));
|
||||
// Set up the anime data and run loop/thread
|
||||
if supported.anime_ctrl.0 {
|
||||
let anime_type = get_anime_type()?;
|
||||
let anime_config = UserAnimeConfig::load_config(config.active_anime)?;
|
||||
let anime = anime_config.create_anime(anime_type)?;
|
||||
let anime_config = Arc::new(Mutex::new(anime_config));
|
||||
if let Some(cfg) = config.active_anime {
|
||||
let anime_type = get_anime_type()?;
|
||||
let anime_config = UserAnimeConfig::load(cfg)?;
|
||||
let anime = anime_config.create(anime_type)?;
|
||||
let anime_config = Arc::new(Mutex::new(anime_config));
|
||||
|
||||
executor
|
||||
.spawn(async move {
|
||||
// Create server
|
||||
let mut connection = Connection::session().await.unwrap();
|
||||
connection.request_name(DBUS_NAME).await.unwrap();
|
||||
|
||||
// Inner behind mutex required for thread safety
|
||||
let inner = Arc::new(Mutex::new(
|
||||
CtrlAnimeInner::new(anime, client, early_return.clone()).unwrap(),
|
||||
));
|
||||
// Need new client object for dbus control part
|
||||
let (client, _) = RogDbusClientBlocking::new().unwrap();
|
||||
let anime_control =
|
||||
CtrlAnime::new(anime_config, inner.clone(), client, early_return).unwrap();
|
||||
anime_control.add_to_server(&mut connection).await;
|
||||
loop {
|
||||
if let Ok(inner) = inner.clone().try_lock() {
|
||||
inner.run().ok();
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
|
||||
// if supported.keyboard_led.per_key_led_mode {
|
||||
if let Some(cfg) = config.active_aura {
|
||||
let mut aura_config = UserAuraConfig::load(cfg)?;
|
||||
|
||||
// Find and load a matching layout for laptop
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(PathBuf::from(BOARD_NAME))
|
||||
.map_err(|e| {
|
||||
println!("{BOARD_NAME}, {e}");
|
||||
e
|
||||
})?;
|
||||
let mut board_name = String::new();
|
||||
file.read_to_string(&mut board_name)?;
|
||||
|
||||
let layout = KeyLayout::find_layout(board_name.as_str(), PathBuf::from(DATA_DIR))
|
||||
.map_err(|e| {
|
||||
println!("{BOARD_NAME}, {e}");
|
||||
})
|
||||
.unwrap_or(KeyLayout::ga401_layout());
|
||||
|
||||
executor
|
||||
.spawn(async move {
|
||||
// Create server
|
||||
let mut connection = Connection::session().await.unwrap();
|
||||
connection.request_name(DBUS_NAME).await.unwrap();
|
||||
|
||||
// Inner behind mutex required for thread safety
|
||||
let inner = Arc::new(Mutex::new(
|
||||
CtrlAnimeInner::new(anime, client, early_return.clone()).unwrap(),
|
||||
));
|
||||
// Need new client object for dbus control part
|
||||
let (client, _) = RogDbusClientBlocking::new().unwrap();
|
||||
let anime_control =
|
||||
CtrlAnime::new(anime_config, inner.clone(), client, early_return).unwrap();
|
||||
anime_control.add_to_server(&mut connection).await;
|
||||
// let connection = Connection::session().await.unwrap();
|
||||
// connection.request_name(DBUS_NAME).await.unwrap();
|
||||
|
||||
loop {
|
||||
if let Ok(inner) = inner.clone().try_lock() {
|
||||
inner.run().ok();
|
||||
}
|
||||
aura_config.aura.next_state(&layout);
|
||||
let packets = aura_config.aura.create_packets();
|
||||
|
||||
client.proxies().led().per_key_raw(packets).unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(33));
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
// if supported.keyboard_led.per_key_led_mode {
|
||||
// executor
|
||||
// .spawn(async move {
|
||||
// //
|
||||
// })
|
||||
// .detach();
|
||||
// }
|
||||
|
||||
loop {
|
||||
|
||||
@@ -5,28 +5,21 @@ use std::{
|
||||
};
|
||||
|
||||
use rog_anime::{ActionLoader, AnimTime, AnimeType, Fade, Sequences, Vec2};
|
||||
use rog_aura::{keys::Key, Breathe, Colour, Effect, Flicker, LedType, Speed, Static};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct UserAnimeConfig {
|
||||
pub name: String,
|
||||
pub anime: Vec<ActionLoader>,
|
||||
}
|
||||
pub trait ConfigLoadSave<T: DeserializeOwned + serde::Serialize> {
|
||||
fn name(&self) -> String;
|
||||
|
||||
impl UserAnimeConfig {
|
||||
pub fn create_anime(&self, anime_type: AnimeType) -> Result<Sequences, Error> {
|
||||
let mut seq = Sequences::new(anime_type);
|
||||
fn default_with_name(name: String) -> T;
|
||||
|
||||
for (idx, action) in self.anime.iter().enumerate() {
|
||||
seq.insert(idx, action)?;
|
||||
}
|
||||
|
||||
Ok(seq)
|
||||
}
|
||||
|
||||
pub fn write(&self) -> Result<(), Error> {
|
||||
fn write(&self) -> Result<(), Error>
|
||||
where
|
||||
Self: serde::Serialize,
|
||||
{
|
||||
let mut path = if let Some(dir) = dirs::config_dir() {
|
||||
dir
|
||||
} else {
|
||||
@@ -37,7 +30,7 @@ impl UserAnimeConfig {
|
||||
if !path.exists() {
|
||||
create_dir(path.clone())?;
|
||||
}
|
||||
let name = self.name.clone();
|
||||
let name = self.name().clone();
|
||||
path.push(name + ".cfg");
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
@@ -51,7 +44,7 @@ impl UserAnimeConfig {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_config(name: String) -> Result<UserAnimeConfig, Error> {
|
||||
fn load(name: String) -> Result<T, Error> {
|
||||
let mut path = if let Some(dir) = dirs::config_dir() {
|
||||
dir
|
||||
} else {
|
||||
@@ -75,14 +68,11 @@ impl UserAnimeConfig {
|
||||
|
||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||
if read_len == 0 {
|
||||
let default = UserAnimeConfig {
|
||||
name,
|
||||
..Default::default()
|
||||
};
|
||||
let default = Self::default_with_name(name);
|
||||
let json = serde_json::to_string_pretty(&default).unwrap();
|
||||
file.write_all(json.as_bytes())?;
|
||||
return Ok(default);
|
||||
} else if let Ok(data) = serde_json::from_str::<UserAnimeConfig>(&buf) {
|
||||
} else if let Ok(data) = serde_json::from_str::<T>(&buf) {
|
||||
return Ok(data);
|
||||
}
|
||||
}
|
||||
@@ -90,6 +80,37 @@ impl UserAnimeConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct UserAnimeConfig {
|
||||
pub name: String,
|
||||
pub anime: Vec<ActionLoader>,
|
||||
}
|
||||
|
||||
impl UserAnimeConfig {
|
||||
pub fn create(&self, anime_type: AnimeType) -> Result<Sequences, Error> {
|
||||
let mut seq = Sequences::new(anime_type);
|
||||
|
||||
for (idx, action) in self.anime.iter().enumerate() {
|
||||
seq.insert(idx, action)?;
|
||||
}
|
||||
|
||||
Ok(seq)
|
||||
}
|
||||
}
|
||||
|
||||
impl ConfigLoadSave<UserAnimeConfig> for UserAnimeConfig {
|
||||
fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn default_with_name(name: String) -> Self {
|
||||
UserAnimeConfig {
|
||||
name,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for UserAnimeConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -151,20 +172,91 @@ impl Default for UserAnimeConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct UserAuraConfig {
|
||||
pub name: String,
|
||||
pub aura: rog_aura::Sequences,
|
||||
}
|
||||
|
||||
impl ConfigLoadSave<UserAuraConfig> for UserAuraConfig {
|
||||
fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn default_with_name(name: String) -> Self {
|
||||
UserAuraConfig {
|
||||
name,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for UserAuraConfig {
|
||||
fn default() -> Self {
|
||||
let mut seq = rog_aura::Sequences::new();
|
||||
let mut key = Effect::Breathe(Breathe::new(
|
||||
LedType::Key(Key::W),
|
||||
Colour(255, 0, 20),
|
||||
Colour(20, 255, 0),
|
||||
Speed::Low,
|
||||
));
|
||||
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::A));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::S));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::D));
|
||||
seq.push(key);
|
||||
|
||||
let key = Effect::Breathe(Breathe::new(
|
||||
LedType::Key(Key::F),
|
||||
Colour(255, 0, 0),
|
||||
Colour(255, 0, 0),
|
||||
Speed::High,
|
||||
));
|
||||
seq.push(key);
|
||||
|
||||
let mut key = Effect::Static(Static::new(LedType::Key(Key::RCtrl), Colour(0, 0, 255)));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::LCtrl));
|
||||
seq.push(key.clone());
|
||||
key.set_led_type(LedType::Key(Key::Esc));
|
||||
seq.push(key);
|
||||
|
||||
let key = Effect::Flicker(Flicker::new(
|
||||
LedType::Key(Key::N9),
|
||||
Colour(0, 0, 255),
|
||||
80,
|
||||
40,
|
||||
));
|
||||
seq.push(key.clone());
|
||||
|
||||
Self {
|
||||
name: "default".to_string(),
|
||||
aura: seq,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct UserConfig {
|
||||
/// Name of active anime config file in the user config directory
|
||||
pub active_anime: String,
|
||||
pub active_anime: Option<String>,
|
||||
/// Name of active aura config file in the user config directory
|
||||
pub active_aura: Option<String>,
|
||||
}
|
||||
|
||||
impl UserConfig {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
active_anime: "anime-default".to_string(),
|
||||
active_anime: Some("anime-default".to_string()),
|
||||
active_aura: Some("aura-default".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_config(&mut self) -> Result<(), Error> {
|
||||
pub fn load(&mut self) -> Result<(), Error> {
|
||||
let mut path = if let Some(dir) = dirs::config_dir() {
|
||||
dir
|
||||
} else {
|
||||
@@ -192,6 +284,7 @@ impl UserConfig {
|
||||
file.write_all(json.as_bytes())?;
|
||||
} else if let Ok(data) = serde_json::from_str::<UserConfig>(&buf) {
|
||||
self.active_anime = data.active_anime;
|
||||
self.active_aura = data.active_aura;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "daemon"
|
||||
version = "4.3.0"
|
||||
version = "4.4.0"
|
||||
license = "MPL-2.0"
|
||||
readme = "README.md"
|
||||
authors = ["Luke <luke@ljones.dev>"]
|
||||
@@ -20,16 +20,13 @@ path = "src/daemon.rs"
|
||||
[dependencies]
|
||||
rog_anime = { path = "../rog-anime", features = ["dbus"] }
|
||||
rog_aura = { path = "../rog-aura", features = ["dbus"] }
|
||||
rog_supported = { path = "../rog-supported" }
|
||||
rog_platform = { path = "../rog-platform" }
|
||||
rog_profiles = { path = "../rog-profiles" }
|
||||
rog_dbus = { path = "../rog-dbus" }
|
||||
|
||||
async-trait = "^0.1"
|
||||
smol = "^1.2"
|
||||
|
||||
rusb = "^0.9"
|
||||
udev = "^0.6"
|
||||
|
||||
# cli and logging
|
||||
log = "^0.4"
|
||||
env_logger = "^0.9"
|
||||
|
||||
@@ -7,15 +7,18 @@ use std::path::PathBuf;
|
||||
pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
|
||||
|
||||
#[derive(Deserialize, Serialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
/// Save charge limit for restoring on boot
|
||||
pub bat_charge_limit: u8,
|
||||
pub panel_od: bool,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
fn new() -> Self {
|
||||
Config {
|
||||
bat_charge_limit: 100,
|
||||
panel_od: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,25 @@
|
||||
pub mod config;
|
||||
pub mod zbus;
|
||||
|
||||
use ::zbus::Connection;
|
||||
use async_trait::async_trait;
|
||||
use log::{error, info, warn};
|
||||
use logind_zbus::manager::ManagerProxy;
|
||||
use rog_anime::{
|
||||
error::AnimeError,
|
||||
usb::{
|
||||
find_node, get_anime_type, pkt_for_apply, pkt_for_flush, pkt_for_set_boot, pkt_for_set_on,
|
||||
pkts_for_init, PROD_ID, VENDOR_ID,
|
||||
get_anime_type, pkt_for_apply, pkt_for_flush, pkt_for_set_boot, pkt_for_set_on,
|
||||
pkts_for_init,
|
||||
},
|
||||
ActionData, AnimeDataBuffer, AnimePacketType, AnimeType,
|
||||
};
|
||||
use rog_supported::AnimeSupportedFunctions;
|
||||
use rusb::{Device, DeviceHandle};
|
||||
use smol::{stream::StreamExt, Executor};
|
||||
use rog_platform::{hid_raw::HidRaw, supported::AnimeSupportedFunctions, usb_raw::USBRaw};
|
||||
use smol::Executor;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
convert::TryFrom,
|
||||
error::Error,
|
||||
sync::{Arc, Mutex, MutexGuard},
|
||||
thread::sleep,
|
||||
};
|
||||
use std::{
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use crate::{error::RogError, GetSupported};
|
||||
|
||||
@@ -36,14 +29,13 @@ impl GetSupported for CtrlAnime {
|
||||
type A = AnimeSupportedFunctions;
|
||||
|
||||
fn get_supported() -> Self::A {
|
||||
AnimeSupportedFunctions(CtrlAnime::get_device(VENDOR_ID, PROD_ID).is_ok())
|
||||
AnimeSupportedFunctions(HidRaw::new("193b").is_ok())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CtrlAnime {
|
||||
_node: String,
|
||||
node: USBRaw,
|
||||
anime_type: AnimeType,
|
||||
handle: RefCell<DeviceHandle<rusb::GlobalContext>>,
|
||||
cache: AnimeConfigCached,
|
||||
config: AnimeConfig,
|
||||
// set to force thread to exit
|
||||
@@ -55,57 +47,26 @@ pub struct CtrlAnime {
|
||||
impl CtrlAnime {
|
||||
#[inline]
|
||||
pub fn new(config: AnimeConfig) -> Result<CtrlAnime, Box<dyn Error>> {
|
||||
let node = find_node("193b")?;
|
||||
let node = USBRaw::new(0x193b)?;
|
||||
let anime_type = get_anime_type()?;
|
||||
let device = Self::get_dev_handle()?;
|
||||
|
||||
info!("Device has an AniMe Matrix display");
|
||||
let mut cache = AnimeConfigCached::default();
|
||||
cache.init_from_config(&config, anime_type)?;
|
||||
|
||||
let ctrl = CtrlAnime {
|
||||
_node: node,
|
||||
node,
|
||||
anime_type,
|
||||
handle: RefCell::new(device),
|
||||
cache,
|
||||
config,
|
||||
thread_exit: Arc::new(AtomicBool::new(false)),
|
||||
thread_running: Arc::new(AtomicBool::new(false)),
|
||||
};
|
||||
ctrl.do_initialization();
|
||||
ctrl.do_initialization()?;
|
||||
|
||||
Ok(ctrl)
|
||||
}
|
||||
|
||||
fn get_dev_handle() -> Result<DeviceHandle<rusb::GlobalContext>, Box<dyn Error>> {
|
||||
// We don't expect this ID to ever change
|
||||
let device = CtrlAnime::get_device(0x0b05, 0x193b)?;
|
||||
|
||||
let mut device = device.open()?;
|
||||
device.reset()?;
|
||||
|
||||
device.set_auto_detach_kernel_driver(true).map_err(|err| {
|
||||
error!("Auto-detach kernel driver failed: {}", err);
|
||||
err
|
||||
})?;
|
||||
|
||||
device.claim_interface(0).map_err(|err| {
|
||||
error!("Could not claim device interface: {}", err);
|
||||
err
|
||||
})?;
|
||||
|
||||
Ok(device)
|
||||
}
|
||||
|
||||
fn get_device(vendor: u16, product: u16) -> Result<Device<rusb::GlobalContext>, rusb::Error> {
|
||||
for device in rusb::devices()?.iter() {
|
||||
let device_desc = device.device_descriptor()?;
|
||||
if device_desc.vendor_id() == vendor && device_desc.product_id() == product {
|
||||
return Ok(device);
|
||||
}
|
||||
}
|
||||
Err(rusb::Error::NoDevice)
|
||||
}
|
||||
// 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.
|
||||
@@ -230,49 +191,10 @@ impl CtrlAnime {
|
||||
.ok();
|
||||
}
|
||||
|
||||
fn write_bytes(&self, message: &[u8]) {
|
||||
// if let Ok(mut file) = OpenOptions::new().write(true).open(&self.node) {
|
||||
// println!("write: {:02x?}", &message);
|
||||
// return file
|
||||
// .write_all(message).unwrap();
|
||||
// }
|
||||
let mut error = false;
|
||||
|
||||
match self.handle.borrow().write_control(
|
||||
0x21, // request_type
|
||||
0x09, // request
|
||||
0x35e, // value
|
||||
0x00, // index
|
||||
message,
|
||||
Duration::from_millis(200),
|
||||
) {
|
||||
Ok(_) => {}
|
||||
Err(err) => match err {
|
||||
rusb::Error::Timeout => {}
|
||||
_ => {
|
||||
error = true;
|
||||
error!("Failed to write to led interrupt: {}", err);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
if error {
|
||||
warn!("Will attempt to get AniMe device handle again");
|
||||
match Self::get_dev_handle() {
|
||||
Ok(dev) => {
|
||||
self.handle.replace(dev);
|
||||
}
|
||||
Err(err) => {
|
||||
error!("Failed to get AniMe device: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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()[7..].iter_mut() {
|
||||
for led in buffer.data_mut().iter_mut() {
|
||||
let mut bright = *led as f32 * self.config.brightness;
|
||||
if bright > 254.0 {
|
||||
bright = 254.0;
|
||||
@@ -281,16 +203,17 @@ impl CtrlAnime {
|
||||
}
|
||||
let data = AnimePacketType::try_from(buffer)?;
|
||||
for row in data.iter() {
|
||||
self.write_bytes(row);
|
||||
self.node.write_bytes(row)?;
|
||||
}
|
||||
self.write_bytes(&pkt_for_flush());
|
||||
self.node.write_bytes(&pkt_for_flush())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn do_initialization(&self) {
|
||||
fn do_initialization(&self) -> Result<(), RogError> {
|
||||
let pkts = pkts_for_init();
|
||||
self.write_bytes(&pkts[0]);
|
||||
self.write_bytes(&pkts[1]);
|
||||
self.node.write_bytes(&pkts[0])?;
|
||||
self.node.write_bytes(&pkts[1])?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,14 +230,6 @@ impl CtrlAnimeTask {
|
||||
#[async_trait]
|
||||
impl crate::CtrlTask for CtrlAnimeTask {
|
||||
async fn create_tasks(&self, executor: &mut Executor) -> Result<(), RogError> {
|
||||
let connection = Connection::system()
|
||||
.await
|
||||
.expect("CtrlAnimeTask could not create dbus connection");
|
||||
|
||||
let manager = ManagerProxy::new(&connection)
|
||||
.await
|
||||
.expect("CtrlAnimeTask could not create ManagerProxy");
|
||||
|
||||
let run_action =
|
||||
|start: bool, lock: MutexGuard<CtrlAnime>, inner: Arc<Mutex<CtrlAnime>>| {
|
||||
if start {
|
||||
@@ -326,50 +241,40 @@ impl crate::CtrlTask for CtrlAnimeTask {
|
||||
}
|
||||
};
|
||||
|
||||
let inner = self.inner.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
if let Ok(notif) = manager.receive_prepare_for_sleep().await {
|
||||
notif
|
||||
.for_each(|event| {
|
||||
if let Ok(args) = event.args() {
|
||||
// Loop is required to try an attempt to get the mutex *without* blocking
|
||||
// other threads - it is possible to end up with deadlocks otherwise.
|
||||
loop {
|
||||
if let Ok(lock) = inner.clone().try_lock() {
|
||||
run_action(args.start, lock, inner.clone());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
let inner1 = self.inner.clone();
|
||||
let inner2 = self.inner.clone();
|
||||
let inner3 = self.inner.clone();
|
||||
let inner4 = self.inner.clone();
|
||||
self.create_sys_event_tasks(
|
||||
executor,
|
||||
// Loop is required to try an attempt to get the mutex *without* blocking
|
||||
// other threads - it is possible to end up with deadlocks otherwise.
|
||||
move || loop {
|
||||
if let Ok(lock) = inner1.clone().try_lock() {
|
||||
run_action(true, lock, inner1.clone());
|
||||
break;
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let manager = ManagerProxy::new(&connection)
|
||||
.await
|
||||
.expect("CtrlAnimeTask could not create ManagerProxy");
|
||||
|
||||
let inner = self.inner.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
if let Ok(notif) = manager.receive_prepare_for_shutdown().await {
|
||||
notif
|
||||
.for_each(|event| {
|
||||
if let Ok(args) = event.args() {
|
||||
loop {
|
||||
if let Ok(lock) = inner.clone().try_lock() {
|
||||
run_action(args.start, lock, inner.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
},
|
||||
move || loop {
|
||||
if let Ok(lock) = inner2.clone().try_lock() {
|
||||
run_action(false, lock, inner2.clone());
|
||||
break;
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
},
|
||||
move || loop {
|
||||
if let Ok(lock) = inner3.clone().try_lock() {
|
||||
run_action(true, lock, inner3.clone());
|
||||
break;
|
||||
}
|
||||
},
|
||||
move || loop {
|
||||
if let Ok(lock) = inner4.clone().try_lock() {
|
||||
run_action(false, lock, inner4.clone());
|
||||
break;
|
||||
}
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -380,10 +285,12 @@ pub struct CtrlAnimeReloader(pub Arc<Mutex<CtrlAnime>>);
|
||||
impl crate::Reloadable for CtrlAnimeReloader {
|
||||
fn reload(&mut self) -> Result<(), RogError> {
|
||||
if let Ok(lock) = self.0.try_lock() {
|
||||
lock.write_bytes(&pkt_for_set_on(lock.config.awake_enabled));
|
||||
lock.write_bytes(&pkt_for_apply());
|
||||
lock.write_bytes(&pkt_for_set_boot(lock.config.boot_anim_enabled));
|
||||
lock.write_bytes(&pkt_for_apply());
|
||||
lock.node
|
||||
.write_bytes(&pkt_for_set_on(lock.config.awake_enabled))?;
|
||||
lock.node.write_bytes(&pkt_for_apply())?;
|
||||
lock.node
|
||||
.write_bytes(&pkt_for_set_boot(lock.config.boot_anim_enabled))?;
|
||||
lock.node.write_bytes(&pkt_for_apply())?;
|
||||
|
||||
let action = lock.cache.boot.clone();
|
||||
CtrlAnime::run_thread(self.0.clone(), action, true);
|
||||
|
||||
@@ -64,7 +64,12 @@ impl CtrlAnimeZbus {
|
||||
let states;
|
||||
'outer: loop {
|
||||
if let Ok(mut lock) = self.0.try_lock() {
|
||||
lock.write_bytes(&pkt_for_set_on(status));
|
||||
lock.node
|
||||
.write_bytes(&pkt_for_set_on(status))
|
||||
.map_err(|err| {
|
||||
warn!("rog_anime::run_animation:callback {}", err);
|
||||
})
|
||||
.ok();
|
||||
lock.config.awake_enabled = status;
|
||||
lock.config.write();
|
||||
|
||||
@@ -86,8 +91,18 @@ impl CtrlAnimeZbus {
|
||||
let states;
|
||||
'outer: loop {
|
||||
if let Ok(mut lock) = self.0.try_lock() {
|
||||
lock.write_bytes(&pkt_for_set_boot(on));
|
||||
lock.write_bytes(&pkt_for_apply());
|
||||
lock.node
|
||||
.write_bytes(&pkt_for_set_boot(on))
|
||||
.map_err(|err| {
|
||||
warn!("rog_anime::run_animation:callback {}", err);
|
||||
})
|
||||
.ok();
|
||||
lock.node
|
||||
.write_bytes(&pkt_for_apply())
|
||||
.map_err(|err| {
|
||||
warn!("rog_anime::run_animation:callback {}", err);
|
||||
})
|
||||
.ok();
|
||||
lock.config.boot_anim_enabled = on;
|
||||
lock.config.write();
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use crate::laptops::{LaptopLedData, ASUS_KEYBOARD_DEVICES};
|
||||
use log::{error, warn};
|
||||
use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraPowerDev};
|
||||
use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraDevTuf, AuraDevice, AuraPowerDev};
|
||||
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Direction, LedBrightness, Speed, GRADIENT};
|
||||
use rog_platform::hid_raw::HidRaw;
|
||||
use rog_platform::keyboard_led::KeyboardLed;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use super::controller::CtrlKbdLed;
|
||||
|
||||
pub static AURA_CONFIG_PATH: &str = "/etc/asusd/aura.conf";
|
||||
|
||||
/// Enable/disable LED control in various states such as
|
||||
@@ -16,13 +16,16 @@ pub static AURA_CONFIG_PATH: &str = "/etc/asusd/aura.conf";
|
||||
/// booting.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum AuraPowerConfig {
|
||||
AuraDevTuf(HashSet<AuraDevTuf>),
|
||||
AuraDev1866(HashSet<AuraDev1866>),
|
||||
AuraDev19b6(HashSet<AuraDev19b6>),
|
||||
}
|
||||
|
||||
impl AuraPowerConfig {
|
||||
/// Invalid for TUF laptops
|
||||
pub fn to_bytes(control: &Self) -> [u8; 3] {
|
||||
match control {
|
||||
AuraPowerConfig::AuraDevTuf(_) => [0, 0, 0],
|
||||
AuraPowerConfig::AuraDev1866(c) => {
|
||||
let c: Vec<AuraDev1866> = c.iter().map(|v| *v).collect();
|
||||
AuraDev1866::to_bytes(&c)
|
||||
@@ -34,6 +37,39 @@ impl AuraPowerConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_tuf_bool_array(control: &Self) -> Option<[bool; 5]> {
|
||||
if let Self::AuraDevTuf(c) = control {
|
||||
return Some([
|
||||
true,
|
||||
c.contains(&AuraDevTuf::Boot),
|
||||
c.contains(&AuraDevTuf::Awake),
|
||||
c.contains(&AuraDevTuf::Sleep),
|
||||
c.contains(&AuraDevTuf::Keyboard),
|
||||
]);
|
||||
}
|
||||
|
||||
if let Self::AuraDev1866(c) = control {
|
||||
return Some([
|
||||
true,
|
||||
c.contains(&AuraDev1866::Boot),
|
||||
c.contains(&AuraDev1866::Awake),
|
||||
c.contains(&AuraDev1866::Sleep),
|
||||
c.contains(&AuraDev1866::Keyboard),
|
||||
]);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn set_tuf(&mut self, power: AuraDevTuf, on: bool) {
|
||||
if let Self::AuraDevTuf(p) = self {
|
||||
if on {
|
||||
p.insert(power);
|
||||
} else {
|
||||
p.remove(&power);
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn set_0x1866(&mut self, power: AuraDev1866, on: bool) {
|
||||
if let Self::AuraDev1866(p) = self {
|
||||
if on {
|
||||
@@ -58,11 +94,18 @@ impl AuraPowerConfig {
|
||||
impl From<&AuraPowerConfig> for AuraPowerDev {
|
||||
fn from(config: &AuraPowerConfig) -> Self {
|
||||
match config {
|
||||
AuraPowerConfig::AuraDevTuf(d) => AuraPowerDev {
|
||||
tuf: d.iter().map(|o| *o).collect(),
|
||||
x1866: vec![],
|
||||
x19b6: vec![],
|
||||
},
|
||||
AuraPowerConfig::AuraDev1866(d) => AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: d.iter().map(|o| *o).collect(),
|
||||
x19b6: vec![],
|
||||
},
|
||||
AuraPowerConfig::AuraDev19b6(d) => AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: vec![],
|
||||
x19b6: d.iter().map(|o| *o).collect(),
|
||||
},
|
||||
@@ -83,15 +126,23 @@ pub struct AuraConfig {
|
||||
|
||||
impl Default for AuraConfig {
|
||||
fn default() -> Self {
|
||||
let mut prod_id = String::new();
|
||||
let mut prod_id = AuraDevice::Unknown;
|
||||
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
||||
if let Ok(_) = CtrlKbdLed::find_led_node(prod) {
|
||||
prod_id = prod.to_string();
|
||||
if let Ok(_) = HidRaw::new(prod) {
|
||||
prod_id = AuraDevice::from(*prod);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let enabled = if prod_id == "19b6" {
|
||||
if prod_id == AuraDevice::Unknown {
|
||||
if let Ok(p) = KeyboardLed::new() {
|
||||
if p.has_kbd_rgb_mode() {
|
||||
prod_id = AuraDevice::Tuf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let enabled = if prod_id == AuraDevice::X19B6 {
|
||||
AuraPowerConfig::AuraDev19b6(HashSet::from([
|
||||
AuraDev19b6::BootLogo,
|
||||
AuraDev19b6::BootKeyb,
|
||||
@@ -101,11 +152,18 @@ impl Default for AuraConfig {
|
||||
AuraDev19b6::AwakeKeyb,
|
||||
AuraDev19b6::ShutdownLogo,
|
||||
AuraDev19b6::ShutdownKeyb,
|
||||
AuraDev19b6::AwakeBar,
|
||||
AuraDev19b6::BootBar,
|
||||
AuraDev19b6::AwakeBar,
|
||||
AuraDev19b6::SleepBar,
|
||||
AuraDev19b6::ShutdownBar,
|
||||
]))
|
||||
} else if prod_id == AuraDevice::Tuf {
|
||||
AuraPowerConfig::AuraDevTuf(HashSet::from([
|
||||
AuraDevTuf::Awake,
|
||||
AuraDevTuf::Boot,
|
||||
AuraDevTuf::Sleep,
|
||||
AuraDevTuf::Keyboard,
|
||||
]))
|
||||
} else {
|
||||
AuraPowerConfig::AuraDev1866(HashSet::from([
|
||||
AuraDev1866::Awake,
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// Only these two packets must be 17 bytes
|
||||
static KBD_BRIGHT_PATH: &str = "/sys/class/leds/asus::kbd_backlight/brightness";
|
||||
|
||||
use crate::{
|
||||
error::RogError,
|
||||
laptops::{LaptopLedData, ASUS_KEYBOARD_DEVICES},
|
||||
@@ -8,23 +5,17 @@ use crate::{
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use log::{error, info, warn};
|
||||
use logind_zbus::manager::ManagerProxy;
|
||||
use rog_aura::{
|
||||
usb::{LED_APPLY, LED_SET},
|
||||
AuraEffect, LedBrightness, LED_MSG_LEN,
|
||||
usb::{AuraDevice, LED_APPLY, LED_SET},
|
||||
AuraEffect, KeyColourArray, LedBrightness, PerKeyRaw, LED_MSG_LEN,
|
||||
};
|
||||
use rog_aura::{AuraZone, Direction, Speed, GRADIENT};
|
||||
use rog_supported::LedSupportedFunctions;
|
||||
use smol::{stream::StreamExt, Executor};
|
||||
use std::path::Path;
|
||||
use rog_platform::{hid_raw::HidRaw, keyboard_led::KeyboardLed, supported::LedSupportedFunctions};
|
||||
use smol::Executor;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
io::{Read, Write},
|
||||
};
|
||||
use std::{fs::OpenOptions, sync::MutexGuard};
|
||||
use zbus::Connection;
|
||||
use std::sync::MutexGuard;
|
||||
|
||||
use crate::GetSupported;
|
||||
|
||||
@@ -40,17 +31,24 @@ impl GetSupported for CtrlKbdLed {
|
||||
let multizone_led_mode = laptop.multizone;
|
||||
let per_key_led_mode = laptop.per_key;
|
||||
|
||||
let mut prod_id = String::new();
|
||||
let mut prod_id = AuraDevice::Unknown;
|
||||
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
||||
if let Ok(_) = Self::find_led_node(prod) {
|
||||
prod_id = prod.to_string();
|
||||
if let Ok(_) = HidRaw::new(prod) {
|
||||
prod_id = AuraDevice::from(*prod);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let rgb = KeyboardLed::new();
|
||||
if let Ok(p) = rgb.as_ref() {
|
||||
if p.has_kbd_rgb_mode() {
|
||||
prod_id = AuraDevice::Tuf;
|
||||
}
|
||||
}
|
||||
|
||||
LedSupportedFunctions {
|
||||
prod_id,
|
||||
brightness_set: CtrlKbdLed::get_kbd_bright_path().is_some(),
|
||||
brightness_set: rgb.is_ok(),
|
||||
stock_led_modes,
|
||||
multizone_led_mode,
|
||||
per_key_led_mode,
|
||||
@@ -58,13 +56,21 @@ impl GetSupported for CtrlKbdLed {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, PartialOrd)]
|
||||
pub enum LEDNode {
|
||||
KbdLed(KeyboardLed),
|
||||
Rog(HidRaw),
|
||||
None,
|
||||
}
|
||||
|
||||
pub struct CtrlKbdLed {
|
||||
// TODO: config stores the keyboard type as an AuraPower, use or update this
|
||||
pub led_prod: Option<String>,
|
||||
pub led_node: Option<String>,
|
||||
pub bright_node: String,
|
||||
pub led_node: LEDNode,
|
||||
pub kd_brightness: KeyboardLed,
|
||||
pub supported_modes: LaptopLedData,
|
||||
pub flip_effect_write: bool,
|
||||
pub per_key_mode_active: bool,
|
||||
pub config: AuraConfig,
|
||||
}
|
||||
|
||||
@@ -78,41 +84,17 @@ impl CtrlKbdLedTask {
|
||||
}
|
||||
|
||||
fn update_config(lock: &mut CtrlKbdLed) -> Result<(), RogError> {
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(&lock.bright_node)
|
||||
.map_err(|err| match err.kind() {
|
||||
std::io::ErrorKind::NotFound => {
|
||||
RogError::MissingLedBrightNode((&lock.bright_node).into(), err)
|
||||
}
|
||||
_ => RogError::Path((&lock.bright_node).into(), err),
|
||||
})?;
|
||||
let mut buf = [0u8; 1];
|
||||
file.read_exact(&mut buf)
|
||||
.map_err(|err| RogError::Read("buffer".into(), err))?;
|
||||
if let Some(num) = char::from(buf[0]).to_digit(10) {
|
||||
if lock.config.brightness != num.into() {
|
||||
lock.config.read();
|
||||
lock.config.brightness = num.into();
|
||||
lock.config.write();
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
Err(RogError::ParseLed)
|
||||
let bright = lock.kd_brightness.get_brightness()?;
|
||||
lock.config.read();
|
||||
lock.config.brightness = (bright as u32).into();
|
||||
lock.config.write();
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CtrlTask for CtrlKbdLedTask {
|
||||
async fn create_tasks(&self, executor: &mut Executor) -> Result<(), RogError> {
|
||||
let connection = Connection::system()
|
||||
.await
|
||||
.expect("CtrlKbdLedTask could not create dbus connection");
|
||||
|
||||
let manager = ManagerProxy::new(&connection)
|
||||
.await
|
||||
.expect("CtrlKbdLedTask could not create ManagerProxy");
|
||||
|
||||
let load_save = |start: bool, mut lock: MutexGuard<CtrlKbdLed>| {
|
||||
// If waking up
|
||||
if !start {
|
||||
@@ -131,41 +113,41 @@ impl CtrlTask for CtrlKbdLedTask {
|
||||
}
|
||||
};
|
||||
|
||||
let inner = self.inner.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
if let Ok(notif) = manager.receive_prepare_for_sleep().await {
|
||||
notif
|
||||
.for_each(|event| {
|
||||
if let Ok(args) = event.args() {
|
||||
loop {
|
||||
// Loop so that we do aquire the lock but also don't block other
|
||||
// threads (prevents potential deadlocks)
|
||||
if let Ok(lock) = inner.clone().try_lock() {
|
||||
load_save(args.start, lock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
let inner1 = self.inner.clone();
|
||||
let inner2 = self.inner.clone();
|
||||
let inner3 = self.inner.clone();
|
||||
let inner4 = self.inner.clone();
|
||||
self.create_sys_event_tasks(
|
||||
executor,
|
||||
// Loop so that we do aquire the lock but also don't block other
|
||||
// threads (prevents potential deadlocks)
|
||||
move || loop {
|
||||
if let Ok(lock) = inner1.clone().try_lock() {
|
||||
load_save(true, lock);
|
||||
break;
|
||||
}
|
||||
if let Ok(notif) = manager.receive_prepare_for_shutdown().await {
|
||||
notif
|
||||
.for_each(|event| {
|
||||
if let Ok(args) = event.args() {
|
||||
loop {
|
||||
if let Ok(lock) = inner.clone().try_lock() {
|
||||
load_save(args.start, lock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
},
|
||||
move || loop {
|
||||
if let Ok(lock) = inner2.clone().try_lock() {
|
||||
load_save(false, lock);
|
||||
break;
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
},
|
||||
move || loop {
|
||||
if let Ok(lock) = inner3.clone().try_lock() {
|
||||
load_save(false, lock);
|
||||
break;
|
||||
}
|
||||
},
|
||||
move || loop {
|
||||
if let Ok(lock) = inner4.clone().try_lock() {
|
||||
load_save(false, lock);
|
||||
break;
|
||||
}
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -176,9 +158,7 @@ impl crate::Reloadable for CtrlKbdLedReloader {
|
||||
fn reload(&mut self) -> Result<(), RogError> {
|
||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||
ctrl.write_current_config_mode()?;
|
||||
ctrl.set_power_states(&ctrl.config)
|
||||
.map_err(|err| warn!("{err}"))
|
||||
.ok();
|
||||
ctrl.set_power_states().map_err(|err| warn!("{err}")).ok();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -194,11 +174,10 @@ impl CtrlKbdLedZbus {
|
||||
|
||||
impl CtrlKbdLed {
|
||||
pub fn new(supported_modes: LaptopLedData, config: AuraConfig) -> Result<Self, RogError> {
|
||||
// TODO: return error if *all* nodes are None
|
||||
let mut led_prod = None;
|
||||
let mut led_node = None;
|
||||
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
||||
match Self::find_led_node(prod) {
|
||||
match HidRaw::new(prod) {
|
||||
Ok(node) => {
|
||||
led_prod = Some(prod.to_string());
|
||||
led_node = Some(node);
|
||||
@@ -209,67 +188,50 @@ impl CtrlKbdLed {
|
||||
}
|
||||
}
|
||||
|
||||
let bright_node = Self::get_kbd_bright_path();
|
||||
let rgb_led = KeyboardLed::new()?;
|
||||
|
||||
if led_node.is_none() {
|
||||
if led_node.is_none() && !rgb_led.has_kbd_rgb_mode() {
|
||||
let dmi = sysfs_class::DmiId::default();
|
||||
if let Ok(prod_family) = dmi.product_family() {
|
||||
if prod_family.contains("TUF") {
|
||||
warn!("A kernel patch is in progress for TUF RGB support");
|
||||
}
|
||||
}
|
||||
return Err(RogError::NoAuraKeyboard);
|
||||
}
|
||||
|
||||
if bright_node.is_none() {
|
||||
return Err(RogError::MissingFunction(
|
||||
"No brightness control, you may require a v5.11 series kernel or newer".into(),
|
||||
));
|
||||
}
|
||||
let led_node = if let Some(rog) = led_node {
|
||||
info!("Found ROG USB keyboard");
|
||||
LEDNode::Rog(rog)
|
||||
} else if rgb_led.has_kbd_rgb_mode() {
|
||||
info!("Found TUF keyboard");
|
||||
LEDNode::KbdLed(rgb_led.clone())
|
||||
} else {
|
||||
LEDNode::None
|
||||
};
|
||||
|
||||
let ctrl = CtrlKbdLed {
|
||||
led_prod,
|
||||
led_node,
|
||||
bright_node: bright_node.unwrap(), // If was none then we already returned above
|
||||
kd_brightness: rgb_led, // If was none then we already returned above
|
||||
supported_modes,
|
||||
flip_effect_write: false,
|
||||
per_key_mode_active: false,
|
||||
config,
|
||||
};
|
||||
Ok(ctrl)
|
||||
}
|
||||
|
||||
fn get_kbd_bright_path() -> Option<String> {
|
||||
if Path::new(KBD_BRIGHT_PATH).exists() {
|
||||
return Some(KBD_BRIGHT_PATH.to_string());
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub(super) fn get_brightness(&self) -> Result<u8, RogError> {
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(&self.bright_node)
|
||||
.map_err(|err| match err.kind() {
|
||||
std::io::ErrorKind::NotFound => {
|
||||
RogError::MissingLedBrightNode((&self.bright_node).into(), err)
|
||||
}
|
||||
_ => RogError::Path((&self.bright_node).into(), err),
|
||||
})?;
|
||||
let mut buf = [0u8; 1];
|
||||
file.read_exact(&mut buf)
|
||||
.map_err(|err| RogError::Read("buffer".into(), err))?;
|
||||
Ok(buf[0])
|
||||
self.kd_brightness
|
||||
.get_brightness()
|
||||
.map_err(|e| RogError::Platform(e))
|
||||
}
|
||||
|
||||
pub(super) fn set_brightness(&self, brightness: LedBrightness) -> Result<(), RogError> {
|
||||
let path = Path::new(&self.bright_node);
|
||||
let mut file =
|
||||
OpenOptions::new()
|
||||
.write(true)
|
||||
.open(&path)
|
||||
.map_err(|err| match err.kind() {
|
||||
std::io::ErrorKind::NotFound => {
|
||||
RogError::MissingLedBrightNode((&self.bright_node).into(), err)
|
||||
}
|
||||
_ => RogError::Path((&self.bright_node).into(), err),
|
||||
})?;
|
||||
file.write_all(&[brightness.as_char_code()])
|
||||
.map_err(|err| RogError::Read("buffer".into(), err))?;
|
||||
Ok(())
|
||||
self.kd_brightness
|
||||
.set_brightness(brightness as u8)
|
||||
.map_err(|e| RogError::Platform(e))
|
||||
}
|
||||
|
||||
pub fn next_brightness(&mut self) -> Result<(), RogError> {
|
||||
@@ -295,53 +257,22 @@ impl CtrlKbdLed {
|
||||
}
|
||||
|
||||
/// Set combination state for boot animation/sleep animation/all leds/keys leds/side leds LED active
|
||||
pub(super) fn set_power_states(&self, config: &AuraConfig) -> Result<(), RogError> {
|
||||
let bytes = AuraPowerConfig::to_bytes(&config.enabled);
|
||||
let message = [0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2]];
|
||||
|
||||
self.write_bytes(&message)?;
|
||||
self.write_bytes(&LED_SET)?;
|
||||
// Changes won't persist unless apply is set
|
||||
self.write_bytes(&LED_APPLY)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn find_led_node(id_product: &str) -> Result<String, RogError> {
|
||||
let mut enumerator = udev::Enumerator::new().map_err(|err| {
|
||||
warn!("{}", err);
|
||||
RogError::Udev("enumerator failed".into(), err)
|
||||
})?;
|
||||
enumerator.match_subsystem("hidraw").map_err(|err| {
|
||||
warn!("{}", err);
|
||||
RogError::Udev("match_subsystem failed".into(), err)
|
||||
})?;
|
||||
|
||||
for device in enumerator.scan_devices().map_err(|err| {
|
||||
warn!("{}", err);
|
||||
RogError::Udev("scan_devices failed".into(), err)
|
||||
})? {
|
||||
if let Some(parent) = device
|
||||
.parent_with_subsystem_devtype("usb", "usb_device")
|
||||
.map_err(|err| {
|
||||
warn!("{}", err);
|
||||
RogError::Udev("parent_with_subsystem_devtype failed".into(), err)
|
||||
})?
|
||||
{
|
||||
if parent
|
||||
.attribute_value("idProduct")
|
||||
.ok_or_else(|| RogError::NotFound("LED idProduct".into()))?
|
||||
== id_product
|
||||
{
|
||||
if let Some(dev_node) = device.devnode() {
|
||||
info!("Using device at: {:?} for LED control", dev_node);
|
||||
return Ok(dev_node.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
pub(super) fn set_power_states(&mut self) -> Result<(), RogError> {
|
||||
if let LEDNode::KbdLed(platform) = &mut self.led_node {
|
||||
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 = AuraPowerConfig::to_bytes(&self.config.enabled);
|
||||
let message = [0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2]];
|
||||
|
||||
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)?;
|
||||
}
|
||||
Err(RogError::MissingFunction(
|
||||
"ASUS LED device node not found".into(),
|
||||
))
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set an Aura effect if the effect mode or zone is supported.
|
||||
@@ -364,31 +295,42 @@ impl CtrlKbdLed {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Should only be used if the bytes you are writing are verified correct
|
||||
fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
||||
if let Some(led_node) = &self.led_node {
|
||||
if let Ok(mut file) = OpenOptions::new().write(true).open(led_node) {
|
||||
// println!("write: {:02x?}", &message);
|
||||
return file
|
||||
.write_all(message)
|
||||
.map_err(|err| RogError::Write("write_bytes".into(), err));
|
||||
}
|
||||
}
|
||||
Err(RogError::NoAuraNode)
|
||||
}
|
||||
/// 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: &PerKeyRaw) -> Result<(), RogError> {
|
||||
let pkt_type = effect[0][1];
|
||||
const PER_KEY_TYPE: u8 = 0xbc;
|
||||
|
||||
/// Write an effect block. This is for per-key
|
||||
fn _write_effect(&mut self, effect: &[Vec<u8>]) -> Result<(), RogError> {
|
||||
if self.flip_effect_write {
|
||||
for row in effect.iter().rev() {
|
||||
self.write_bytes(row)?;
|
||||
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 {
|
||||
for row in effect.iter() {
|
||||
self.write_bytes(row)?;
|
||||
if !self.per_key_mode_active {
|
||||
if let LEDNode::Rog(hid_raw) = &self.led_node {
|
||||
let init = KeyColourArray::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])?;
|
||||
}
|
||||
}
|
||||
self.flip_effect_write = !self.flip_effect_write;
|
||||
}
|
||||
self.flip_effect_write = !self.flip_effect_write;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -417,22 +359,37 @@ impl CtrlKbdLed {
|
||||
let next = self.supported_modes.standard[idx];
|
||||
|
||||
self.config.read();
|
||||
if self.config.builtins.contains_key(&next) {
|
||||
self.config.current_mode = next;
|
||||
self.write_current_config_mode()?;
|
||||
}
|
||||
// if self.config.builtins.contains_key(&next) {
|
||||
self.config.current_mode = next;
|
||||
self.write_current_config_mode()?;
|
||||
// }
|
||||
self.config.write();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_mode(&self, mode: &AuraEffect) -> Result<(), RogError> {
|
||||
let bytes: [u8; LED_MSG_LEN] = mode.into();
|
||||
self.write_bytes(&bytes)?;
|
||||
self.write_bytes(&LED_SET)?;
|
||||
// Changes won't persist unless apply is set
|
||||
self.write_bytes(&LED_APPLY)?;
|
||||
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.0,
|
||||
mode.colour1.1,
|
||||
mode.colour1.2,
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -455,17 +412,17 @@ impl CtrlKbdLed {
|
||||
self.create_multizone_default()?;
|
||||
}
|
||||
|
||||
if let Some(multizones) = self.config.multizone.as_ref() {
|
||||
if let Some(multizones) = self.config.multizone.as_mut() {
|
||||
if let Some(set) = multizones.get(&mode) {
|
||||
for mode in set {
|
||||
self.write_mode(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) {
|
||||
self.write_mode(effect)?;
|
||||
if let Some(effect) = self.config.builtins.get(&mode).cloned() {
|
||||
self.write_mode(&effect)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,8 +460,12 @@ impl CtrlKbdLed {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour};
|
||||
use rog_platform::keyboard_led::KeyboardLed;
|
||||
|
||||
use crate::{ctrl_aura::config::AuraConfig, laptops::LaptopLedData};
|
||||
use crate::{
|
||||
ctrl_aura::{config::AuraConfig, controller::LEDNode},
|
||||
laptops::LaptopLedData,
|
||||
};
|
||||
|
||||
use super::CtrlKbdLed;
|
||||
|
||||
@@ -522,10 +483,11 @@ mod tests {
|
||||
};
|
||||
let mut controller = CtrlKbdLed {
|
||||
led_prod: None,
|
||||
led_node: None,
|
||||
bright_node: String::new(),
|
||||
led_node: LEDNode::None,
|
||||
kd_brightness: KeyboardLed::default(),
|
||||
supported_modes,
|
||||
flip_effect_write: false,
|
||||
per_key_mode_active: false,
|
||||
config,
|
||||
};
|
||||
|
||||
@@ -539,7 +501,7 @@ mod tests {
|
||||
.set_effect(effect.clone())
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"No Aura keyboard node found"
|
||||
"No supported Aura keyboard"
|
||||
);
|
||||
|
||||
effect.mode = AuraModeNum::Laser;
|
||||
@@ -567,7 +529,7 @@ mod tests {
|
||||
.set_effect(effect.clone())
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"No Aura keyboard node found"
|
||||
"No supported Aura keyboard"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -584,10 +546,11 @@ mod tests {
|
||||
};
|
||||
let mut controller = CtrlKbdLed {
|
||||
led_prod: None,
|
||||
led_node: None,
|
||||
bright_node: String::new(),
|
||||
led_node: LEDNode::None,
|
||||
kd_brightness: KeyboardLed::default(),
|
||||
supported_modes,
|
||||
flip_effect_write: false,
|
||||
per_key_mode_active: false,
|
||||
config,
|
||||
};
|
||||
|
||||
@@ -621,10 +584,11 @@ mod tests {
|
||||
};
|
||||
let mut controller = CtrlKbdLed {
|
||||
led_prod: None,
|
||||
led_node: None,
|
||||
bright_node: String::new(),
|
||||
led_node: LEDNode::None,
|
||||
kd_brightness: KeyboardLed::default(),
|
||||
supported_modes,
|
||||
flip_effect_write: false,
|
||||
per_key_mode_active: false,
|
||||
config,
|
||||
};
|
||||
|
||||
@@ -637,7 +601,7 @@ mod tests {
|
||||
.write_current_config_mode()
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"No Aura keyboard node found"
|
||||
"No supported Aura keyboard"
|
||||
);
|
||||
assert!(controller.config.multizone.is_some());
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use log::warn;
|
||||
use rog_aura::{usb::AuraPowerDev, AuraEffect, LedBrightness};
|
||||
use rog_aura::{usb::AuraPowerDev, AuraEffect, AuraModeNum, LedBrightness, PerKeyRaw};
|
||||
use zbus::{dbus_interface, Connection, SignalContext};
|
||||
|
||||
use super::controller::CtrlKbdLedZbus;
|
||||
@@ -27,8 +29,21 @@ impl CtrlKbdLedZbus {
|
||||
}
|
||||
|
||||
/// Set a variety of states, input is array of enum.
|
||||
/// `enabled` sets if the sent array should be disabled or enabled
|
||||
///
|
||||
/// enum AuraControl {
|
||||
/// ```text
|
||||
/// pub struct AuraPowerDev {
|
||||
/// pub x1866: Vec<AuraDev1866>,
|
||||
/// pub x19b6: Vec<AuraDev19b6>,
|
||||
/// }
|
||||
/// pub enum AuraDev1866 {
|
||||
/// Awake,
|
||||
/// Keyboard,
|
||||
/// Lightbar,
|
||||
/// Boot,
|
||||
/// Sleep,
|
||||
/// }
|
||||
/// enum AuraDev19b6 {
|
||||
/// BootLogo,
|
||||
/// BootKeyb,
|
||||
/// AwakeLogo,
|
||||
@@ -42,6 +57,7 @@ impl CtrlKbdLedZbus {
|
||||
/// SleepBar,
|
||||
/// ShutdownBar,
|
||||
/// }
|
||||
/// ```
|
||||
async fn set_leds_power(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
@@ -50,6 +66,9 @@ impl CtrlKbdLedZbus {
|
||||
) -> zbus::fdo::Result<()> {
|
||||
let mut states = None;
|
||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||
for p in options.tuf {
|
||||
ctrl.config.enabled.set_tuf(p, enabled);
|
||||
}
|
||||
for p in options.x1866 {
|
||||
ctrl.config.enabled.set_0x1866(p, enabled);
|
||||
}
|
||||
@@ -59,7 +78,7 @@ impl CtrlKbdLedZbus {
|
||||
|
||||
ctrl.config.write();
|
||||
|
||||
ctrl.set_power_states(&ctrl.config).map_err(|e| {
|
||||
ctrl.set_power_states().map_err(|e| {
|
||||
warn!("{}", e);
|
||||
e
|
||||
})?;
|
||||
@@ -166,7 +185,7 @@ impl CtrlKbdLedZbus {
|
||||
|
||||
// As property doesn't work for AuraPowerDev (complexity of serialization?)
|
||||
// #[dbus_interface(property)]
|
||||
async fn leds_power(&self) -> AuraPowerDev {
|
||||
async fn leds_enabled(&self) -> AuraPowerDev {
|
||||
loop {
|
||||
if let Ok(ctrl) = self.0.try_lock() {
|
||||
return AuraPowerDev::from(&ctrl.config.enabled);
|
||||
@@ -175,29 +194,27 @@ impl CtrlKbdLedZbus {
|
||||
}
|
||||
|
||||
/// Return the current mode data
|
||||
#[dbus_interface(property)]
|
||||
async fn led_mode(&self) -> String {
|
||||
async fn led_mode(&self) -> AuraModeNum {
|
||||
if let Ok(ctrl) = self.0.try_lock() {
|
||||
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
||||
if let Ok(json) = serde_json::to_string(&mode) {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
return ctrl.config.current_mode;
|
||||
}
|
||||
warn!("SetKeyBacklight could not deserialise");
|
||||
"SetKeyBacklight could not deserialise".to_string()
|
||||
AuraModeNum::Static
|
||||
}
|
||||
|
||||
/// Return a list of available modes
|
||||
#[dbus_interface(property)]
|
||||
async fn led_modes(&self) -> String {
|
||||
if let Ok(ctrl) = self.0.try_lock() {
|
||||
if let Ok(json) = serde_json::to_string(&ctrl.config.builtins) {
|
||||
return json;
|
||||
async fn led_modes(&self) -> BTreeMap<AuraModeNum, AuraEffect> {
|
||||
loop {
|
||||
if let Ok(ctrl) = self.0.try_lock() {
|
||||
return ctrl.config.builtins.clone();
|
||||
}
|
||||
}
|
||||
warn!("SetKeyBacklight could not deserialise");
|
||||
"SetKeyBacklight could not serialise".to_string()
|
||||
}
|
||||
|
||||
async fn per_key_raw(&self, data: PerKeyRaw) -> zbus::fdo::Result<()> {
|
||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||
ctrl.write_effect_block(&data)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Return the current LED brightness
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
use crate::CtrlTask;
|
||||
use crate::{config::Config, error::RogError, GetSupported};
|
||||
use async_trait::async_trait;
|
||||
use log::{info, warn};
|
||||
use logind_zbus::manager::ManagerProxy;
|
||||
use rog_supported::ChargeSupportedFunctions;
|
||||
use smol::stream::StreamExt;
|
||||
use smol::Executor;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use zbus::dbus_interface;
|
||||
use zbus::Connection;
|
||||
use zbus::SignalContext;
|
||||
|
||||
static BAT_CHARGE_PATH0: &str = "/sys/class/power_supply/BAT0/charge_control_end_threshold";
|
||||
static BAT_CHARGE_PATH1: &str = "/sys/class/power_supply/BAT1/charge_control_end_threshold";
|
||||
static BAT_CHARGE_PATH2: &str = "/sys/class/power_supply/BAT2/charge_control_end_threshold";
|
||||
|
||||
impl GetSupported for CtrlCharge {
|
||||
type A = ChargeSupportedFunctions;
|
||||
|
||||
fn get_supported() -> Self::A {
|
||||
ChargeSupportedFunctions {
|
||||
charge_level_set: CtrlCharge::get_battery_path().is_ok(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CtrlCharge {
|
||||
config: Arc<Mutex<Config>>,
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
||||
impl CtrlCharge {
|
||||
async fn set_limit(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
limit: u8,
|
||||
) -> zbus::fdo::Result<()> {
|
||||
if !(20..=100).contains(&limit) {
|
||||
return Err(RogError::ChargeLimit(limit))?;
|
||||
}
|
||||
if let Ok(mut config) = self.config.try_lock() {
|
||||
Self::set(limit, &mut config)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlCharge: set_limit {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
Self::notify_charge(&ctxt, limit).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn limit(&self) -> i8 {
|
||||
if let Ok(config) = self.config.try_lock() {
|
||||
return config.bat_charge_limit as i8;
|
||||
}
|
||||
-1
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_charge(ctxt: &SignalContext<'_>, limit: u8) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl crate::ZbusAdd for CtrlCharge {
|
||||
async fn add_to_server(self, server: &mut Connection) {
|
||||
Self::add_to_server_helper(self, "/org/asuslinux/Charge", server).await;
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Reloadable for CtrlCharge {
|
||||
fn reload(&mut self) -> Result<(), RogError> {
|
||||
if let Ok(mut config) = self.config.try_lock() {
|
||||
config.read();
|
||||
Self::set(config.bat_charge_limit, &mut config)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl CtrlCharge {
|
||||
pub fn new(config: Arc<Mutex<Config>>) -> Result<Self, RogError> {
|
||||
CtrlCharge::get_battery_path()?;
|
||||
Ok(CtrlCharge { config })
|
||||
}
|
||||
|
||||
fn get_battery_path() -> Result<&'static str, RogError> {
|
||||
if Path::new(BAT_CHARGE_PATH0).exists() {
|
||||
Ok(BAT_CHARGE_PATH0)
|
||||
} else if Path::new(BAT_CHARGE_PATH1).exists() {
|
||||
Ok(BAT_CHARGE_PATH1)
|
||||
} else if Path::new(BAT_CHARGE_PATH2).exists() {
|
||||
Ok(BAT_CHARGE_PATH2)
|
||||
} else {
|
||||
Err(RogError::MissingFunction(
|
||||
"Charge control not available, you may require a v5.8.10 series kernel or newer"
|
||||
.into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn set(limit: u8, config: &mut Config) -> Result<(), RogError> {
|
||||
if !(20..=100).contains(&limit) {
|
||||
return Err(RogError::ChargeLimit(limit));
|
||||
}
|
||||
|
||||
let path = Self::get_battery_path()?;
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.open(path)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
file.write_all(limit.to_string().as_bytes())
|
||||
.map_err(|err| RogError::Write(path.into(), err))?;
|
||||
info!("Battery charge limit: {}", limit);
|
||||
|
||||
config.read();
|
||||
config.bat_charge_limit = limit;
|
||||
config.write();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CtrlTask for CtrlCharge {
|
||||
async fn create_tasks(&self, executor: &mut Executor) -> Result<(), RogError> {
|
||||
let connection = Connection::system()
|
||||
.await
|
||||
.expect("CtrlCharge could not create dbus connection");
|
||||
|
||||
let manager = ManagerProxy::new(&connection)
|
||||
.await
|
||||
.expect("CtrlCharge could not create ManagerProxy");
|
||||
|
||||
let config1 = self.config.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
if let Ok(notif) = manager.receive_prepare_for_sleep().await {
|
||||
notif
|
||||
.for_each(|event| {
|
||||
if let Ok(args) = event.args() {
|
||||
// If waking up
|
||||
if !args.start {
|
||||
info!("CtrlCharge reloading charge limit");
|
||||
if let Ok(mut lock) = config1.try_lock() {
|
||||
Self::set(lock.bat_charge_limit, &mut lock)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlCharge: set_limit {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let manager = ManagerProxy::new(&connection)
|
||||
.await
|
||||
.expect("CtrlCharge could not create ManagerProxy");
|
||||
|
||||
let config = self.config.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
if let Ok(notif) = manager.receive_prepare_for_shutdown().await {
|
||||
notif
|
||||
.for_each(|event| {
|
||||
if let Ok(args) = event.args() {
|
||||
// If waking up - intention is to catch hibernation event
|
||||
if !args.start {
|
||||
info!("CtrlCharge reloading charge limit");
|
||||
loop {
|
||||
if let Ok(mut lock) = config.clone().try_lock() {
|
||||
Self::set(lock.bat_charge_limit, &mut lock)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlCharge: set_limit {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
302
daemon/src/ctrl_platform.rs
Normal file
302
daemon/src/ctrl_platform.rs
Normal file
@@ -0,0 +1,302 @@
|
||||
use crate::CtrlTask;
|
||||
use crate::{config::Config, error::RogError, GetSupported};
|
||||
use async_trait::async_trait;
|
||||
use log::{info, warn};
|
||||
use rog_platform::platform::{AsusPlatform, GpuMode};
|
||||
use rog_platform::supported::RogBiosSupportedFunctions;
|
||||
use smol::Executor;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use zbus::Connection;
|
||||
use zbus::{dbus_interface, SignalContext};
|
||||
|
||||
static ASUS_POST_LOGO_SOUND: &str =
|
||||
"/sys/firmware/efi/efivars/AsusPostLogoSound-607005d5-3f75-4b2e-98f0-85ba66797a3e";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CtrlRogBios {
|
||||
platform: AsusPlatform,
|
||||
config: Arc<Mutex<Config>>,
|
||||
}
|
||||
|
||||
impl GetSupported for CtrlRogBios {
|
||||
type A = RogBiosSupportedFunctions;
|
||||
|
||||
fn get_supported() -> Self::A {
|
||||
let mut panel_overdrive = false;
|
||||
let mut dgpu_disable = false;
|
||||
let mut egpu_enable = false;
|
||||
let mut gpu_mux = false;
|
||||
|
||||
if let Ok(platform) = AsusPlatform::new() {
|
||||
panel_overdrive = platform.has_panel_od();
|
||||
dgpu_disable = platform.has_dgpu_disable();
|
||||
egpu_enable = platform.has_egpu_enable();
|
||||
gpu_mux = platform.has_gpu_mux_mode();
|
||||
}
|
||||
|
||||
RogBiosSupportedFunctions {
|
||||
post_sound: Path::new(ASUS_POST_LOGO_SOUND).exists(),
|
||||
gpu_mux,
|
||||
panel_overdrive,
|
||||
dgpu_disable,
|
||||
egpu_enable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CtrlRogBios {
|
||||
pub fn new(config: Arc<Mutex<Config>>) -> Result<Self, RogError> {
|
||||
let platform = AsusPlatform::new()?;
|
||||
|
||||
if !platform.has_gpu_mux_mode() {
|
||||
info!("G-Sync Switchable Graphics or GPU MUX not detected");
|
||||
info!("Standard graphics switching will still work.");
|
||||
}
|
||||
|
||||
if Path::new(ASUS_POST_LOGO_SOUND).exists() {
|
||||
CtrlRogBios::set_path_mutable(ASUS_POST_LOGO_SOUND)?;
|
||||
} else {
|
||||
info!("Switch for POST boot sound not detected");
|
||||
}
|
||||
|
||||
Ok(CtrlRogBios { platform, config })
|
||||
}
|
||||
|
||||
fn set_path_mutable(path: &str) -> Result<(), RogError> {
|
||||
let output = Command::new("/usr/bin/chattr")
|
||||
.arg("-i")
|
||||
.arg(path)
|
||||
.output()
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
info!("Set {} writeable: status: {}", path, output.status);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_gfx_mode(&self, mode: GpuMode) -> Result<(), RogError> {
|
||||
self.platform.set_gpu_mux_mode(mode.to_mux())?;
|
||||
// self.update_initramfs(enable)?;
|
||||
if mode == GpuMode::Discrete {
|
||||
info!("Set system-level graphics mode: Dedicated Nvidia");
|
||||
} else {
|
||||
info!("Set system-level graphics mode: Optimus");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_boot_sound() -> Result<i8, RogError> {
|
||||
let path = ASUS_POST_LOGO_SOUND;
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(path)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)
|
||||
.map_err(|err| RogError::Read(path.into(), err))?;
|
||||
|
||||
let idx = data.len() - 1;
|
||||
Ok(data[idx] as i8)
|
||||
}
|
||||
|
||||
pub(super) fn set_boot_sound(on: bool) -> Result<(), RogError> {
|
||||
let path = ASUS_POST_LOGO_SOUND;
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(path)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)
|
||||
.map_err(|err| RogError::Read(path.into(), err))?;
|
||||
|
||||
let idx = data.len() - 1;
|
||||
if on {
|
||||
data[idx] = 1;
|
||||
info!("Set boot POST sound on");
|
||||
} else {
|
||||
data[idx] = 0;
|
||||
info!("Set boot POST sound off");
|
||||
}
|
||||
file.write_all(&data)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_panel_od(&self, enable: bool) -> Result<(), RogError> {
|
||||
self.platform.set_panel_od(enable).map_err(|err| {
|
||||
warn!("CtrlRogBios: set_panel_overdrive {}", err);
|
||||
err
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
||||
impl CtrlRogBios {
|
||||
async fn set_gpu_mux_mode(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
mode: GpuMode,
|
||||
) {
|
||||
self.set_gfx_mode(mode)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_asus_switch_graphic_mode {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
Self::notify_gpu_mux_mode(&ctxt, mode).await.ok();
|
||||
}
|
||||
|
||||
fn gpu_mux_mode(&self) -> GpuMode {
|
||||
match self.platform.get_gpu_mux_mode() {
|
||||
Ok(m) => GpuMode::from_mux(m),
|
||||
Err(e) => {
|
||||
warn!("CtrlRogBios: get_gfx_mode {}", e);
|
||||
GpuMode::Error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_gpu_mux_mode(
|
||||
signal_ctxt: &SignalContext<'_>,
|
||||
mode: GpuMode,
|
||||
) -> zbus::Result<()> {
|
||||
}
|
||||
|
||||
async fn set_post_boot_sound(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
on: bool,
|
||||
) {
|
||||
Self::set_boot_sound(on)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_post_boot_sound {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
Self::notify_post_boot_sound(&ctxt, on).await.ok();
|
||||
}
|
||||
|
||||
fn post_boot_sound(&self) -> i8 {
|
||||
Self::get_boot_sound()
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: get_boot_sound {}", err);
|
||||
err
|
||||
})
|
||||
.unwrap_or(-1)
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_post_boot_sound(ctxt: &SignalContext<'_>, on: bool) -> zbus::Result<()> {}
|
||||
|
||||
async fn set_panel_overdrive(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
overdrive: bool,
|
||||
) {
|
||||
if self
|
||||
.set_panel_od(overdrive)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_panel_overdrive {}", err);
|
||||
err
|
||||
})
|
||||
.is_ok()
|
||||
{
|
||||
if let Ok(mut lock) = self.config.try_lock() {
|
||||
lock.panel_od = overdrive;
|
||||
lock.write();
|
||||
}
|
||||
Self::notify_panel_overdrive(&ctxt, overdrive).await.ok();
|
||||
}
|
||||
}
|
||||
|
||||
fn panel_overdrive(&self) -> bool {
|
||||
self.platform
|
||||
.get_panel_od()
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: get panel overdrive {}", err);
|
||||
err
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_panel_overdrive(
|
||||
signal_ctxt: &SignalContext<'_>,
|
||||
overdrive: bool,
|
||||
) -> zbus::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl crate::ZbusAdd for CtrlRogBios {
|
||||
async fn add_to_server(self, server: &mut Connection) {
|
||||
Self::add_to_server_helper(self, "/org/asuslinux/Platform", server).await;
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Reloadable for CtrlRogBios {
|
||||
fn reload(&mut self) -> Result<(), RogError> {
|
||||
if self.platform.has_panel_od() {
|
||||
let p = if let Ok(lock) = self.config.try_lock() {
|
||||
lock.panel_od
|
||||
} else {
|
||||
false
|
||||
};
|
||||
self.set_panel_od(p)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CtrlTask for CtrlRogBios {
|
||||
async fn create_tasks(&self, executor: &mut Executor) -> Result<(), RogError> {
|
||||
let platform1 = self.clone();
|
||||
let platform2 = self.clone();
|
||||
self.create_sys_event_tasks(
|
||||
executor,
|
||||
move || {},
|
||||
move || {
|
||||
info!("CtrlRogBios reloading panel_od");
|
||||
if let Ok(lock) = platform1.config.try_lock() {
|
||||
if platform1.platform.has_panel_od() {
|
||||
platform1
|
||||
.set_panel_od(lock.panel_od)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlCharge: set_limit {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
},
|
||||
move || {},
|
||||
move || {
|
||||
info!("CtrlRogBios reloading panel_od");
|
||||
if let Ok(lock) = platform2.config.try_lock() {
|
||||
if platform2.platform.has_panel_od() {
|
||||
platform2
|
||||
.set_panel_od(lock.panel_od)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlCharge: set_limit {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
147
daemon/src/ctrl_power.rs
Normal file
147
daemon/src/ctrl_power.rs
Normal file
@@ -0,0 +1,147 @@
|
||||
use crate::CtrlTask;
|
||||
use crate::{config::Config, error::RogError, GetSupported};
|
||||
use async_trait::async_trait;
|
||||
use log::{info, warn};
|
||||
use rog_platform::power::AsusPower;
|
||||
use rog_platform::supported::ChargeSupportedFunctions;
|
||||
use smol::Executor;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use zbus::dbus_interface;
|
||||
use zbus::Connection;
|
||||
use zbus::SignalContext;
|
||||
|
||||
impl GetSupported for CtrlPower {
|
||||
type A = ChargeSupportedFunctions;
|
||||
|
||||
fn get_supported() -> Self::A {
|
||||
ChargeSupportedFunctions {
|
||||
charge_level_set: if let Ok(power) = AsusPower::new() {
|
||||
power.has_charge_control_end_threshold()
|
||||
} else {
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CtrlPower {
|
||||
power: AsusPower,
|
||||
config: Arc<Mutex<Config>>,
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
||||
impl CtrlPower {
|
||||
async fn set_limit(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
limit: u8,
|
||||
) -> zbus::fdo::Result<()> {
|
||||
if !(20..=100).contains(&limit) {
|
||||
return Err(RogError::ChargeLimit(limit))?;
|
||||
}
|
||||
self.set(limit)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlCharge: set_limit {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
Self::notify_charge(&ctxt, limit).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn limit(&self) -> i8 {
|
||||
if let Ok(config) = self.config.try_lock() {
|
||||
return config.bat_charge_limit as i8;
|
||||
}
|
||||
-1
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_charge(ctxt: &SignalContext<'_>, limit: u8) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl crate::ZbusAdd for CtrlPower {
|
||||
async fn add_to_server(self, server: &mut Connection) {
|
||||
Self::add_to_server_helper(self, "/org/asuslinux/Charge", server).await;
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Reloadable for CtrlPower {
|
||||
fn reload(&mut self) -> Result<(), RogError> {
|
||||
if let Ok(mut config) = self.config.try_lock() {
|
||||
config.read();
|
||||
self.set(config.bat_charge_limit)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl CtrlPower {
|
||||
pub fn new(config: Arc<Mutex<Config>>) -> Result<Self, RogError> {
|
||||
Ok(CtrlPower {
|
||||
power: AsusPower::new()?,
|
||||
config,
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn set(&self, limit: u8) -> Result<(), RogError> {
|
||||
if !(20..=100).contains(&limit) {
|
||||
return Err(RogError::ChargeLimit(limit));
|
||||
}
|
||||
|
||||
self.power.set_charge_control_end_threshold(limit)?;
|
||||
|
||||
info!("Battery charge limit: {}", limit);
|
||||
|
||||
if let Ok(mut config) = self.config.try_lock() {
|
||||
config.read();
|
||||
config.bat_charge_limit = limit;
|
||||
config.write();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CtrlTask for CtrlPower {
|
||||
async fn create_tasks(&self, executor: &mut Executor) -> Result<(), RogError> {
|
||||
let power1 = self.clone();
|
||||
let power2 = self.clone();
|
||||
self.create_sys_event_tasks(
|
||||
executor,
|
||||
move || {},
|
||||
move || {
|
||||
info!("CtrlCharge reloading charge limit");
|
||||
if let Ok(lock) = power1.config.try_lock() {
|
||||
power1
|
||||
.set(lock.bat_charge_limit)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlCharge: set_limit {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
},
|
||||
move || {},
|
||||
move || {
|
||||
info!("CtrlCharge reloading charge limit");
|
||||
if let Ok(lock) = power2.config.try_lock() {
|
||||
power2
|
||||
.set(lock.bat_charge_limit)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlCharge: set_limit {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -23,17 +23,6 @@ impl ProfileConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_defaults_and_save(&mut self) {
|
||||
self.active_profile = Profile::get_active_profile().unwrap_or(Profile::Balanced);
|
||||
if let Ok(res) = FanCurveProfiles::is_supported() {
|
||||
if res {
|
||||
let curves = FanCurveProfiles::default();
|
||||
self.fan_curves = Some(curves);
|
||||
}
|
||||
}
|
||||
self.write();
|
||||
}
|
||||
|
||||
pub fn load(config_path: String) -> Self {
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
@@ -46,7 +35,6 @@ impl ProfileConfig {
|
||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||
if read_len == 0 {
|
||||
config = Self::new(config_path);
|
||||
config.set_defaults_and_save();
|
||||
} else if let Ok(data) = toml::from_str(&buf) {
|
||||
config = data;
|
||||
config.config_path = config_path;
|
||||
@@ -63,11 +51,9 @@ impl ProfileConfig {
|
||||
)
|
||||
});
|
||||
config = Self::new(config_path);
|
||||
config.set_defaults_and_save();
|
||||
}
|
||||
} else {
|
||||
config = Self::new(config_path);
|
||||
config.set_defaults_and_save();
|
||||
}
|
||||
config
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::error::RogError;
|
||||
use crate::{CtrlTask, GetSupported};
|
||||
use async_trait::async_trait;
|
||||
use log::{info, warn};
|
||||
use rog_platform::supported::PlatformProfileFunctions;
|
||||
use rog_profiles::error::ProfileError;
|
||||
use rog_profiles::{FanCurveProfiles, Profile};
|
||||
use rog_supported::PlatformProfileFunctions;
|
||||
use smol::Executor;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use super::config::ProfileConfig;
|
||||
|
||||
@@ -20,12 +19,7 @@ impl GetSupported for CtrlPlatformProfile {
|
||||
|
||||
fn get_supported() -> Self::A {
|
||||
if !Profile::is_platform_profile_supported() {
|
||||
warn!(
|
||||
r#"
|
||||
platform_profile kernel interface not found, your laptop does not support this, or the interface is missing.
|
||||
To enable profile support you require a kernel version 5.15.2 minimum.
|
||||
"#
|
||||
);
|
||||
warn!("platform_profile kernel interface not found, your laptop does not support this, or the interface is missing.");
|
||||
}
|
||||
|
||||
let res = FanCurveProfiles::is_supported();
|
||||
@@ -35,14 +29,7 @@ To enable profile support you require a kernel version 5.15.2 minimum.
|
||||
};
|
||||
|
||||
if !fan_curve_supported {
|
||||
info!(
|
||||
r#"
|
||||
fan curves kernel interface not found, your laptop does not support this, or the interface is missing.
|
||||
To enable fan-curve support you require a kernel with the following patch applied:
|
||||
https://lkml.org/lkml/2021/10/23/250
|
||||
This patch has been accepted upstream for 5.17 kernel release.
|
||||
"#
|
||||
);
|
||||
info!("fan curves kernel interface not found, your laptop does not support this, or the interface is missing.");
|
||||
}
|
||||
|
||||
PlatformProfileFunctions {
|
||||
@@ -72,11 +59,27 @@ impl CtrlPlatformProfile {
|
||||
if Profile::is_platform_profile_supported() {
|
||||
info!("Device has profile control available");
|
||||
|
||||
let mut controller = CtrlPlatformProfile { config };
|
||||
if FanCurveProfiles::get_device().is_ok() {
|
||||
info!("Device has fan curves available");
|
||||
if controller.config.fan_curves.is_none() {
|
||||
controller.config.fan_curves = Some(Default::default());
|
||||
for _ in [Profile::Balanced, Profile::Performance, Profile::Quiet] {
|
||||
controller.set_next_profile()?;
|
||||
controller.set_active_curve_to_defaults()?;
|
||||
|
||||
let active = Profile::get_active_profile().unwrap_or(Profile::Balanced);
|
||||
if let Some(curves) = controller.config.fan_curves.as_ref() {
|
||||
info!(
|
||||
"{active:?}: {}",
|
||||
String::from(curves.get_fan_curves_for(active))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(CtrlPlatformProfile { config });
|
||||
return Ok(controller);
|
||||
}
|
||||
|
||||
Err(ProfileError::NotSupported.into())
|
||||
|
||||
@@ -174,6 +174,30 @@ impl ProfileZbus {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reset the stored (self) and device curve to the defaults of the platform.
|
||||
///
|
||||
/// Each platform_profile has a different default and the defualt can be read
|
||||
/// only for the currently active profile.
|
||||
fn reset_profile_curves(&self, profile: Profile) -> zbus::fdo::Result<()> {
|
||||
if let Ok(mut ctrl) = self.inner.try_lock() {
|
||||
ctrl.config.read();
|
||||
let active = Profile::get_active_profile().unwrap_or(Profile::Balanced);
|
||||
|
||||
Profile::set_profile(profile)
|
||||
.map_err(|e| warn!("set_profile, {}", e))
|
||||
.ok();
|
||||
ctrl.set_active_curve_to_defaults()
|
||||
.map_err(|e| warn!("Profile::set_active_curve_to_defaults, {}", e))
|
||||
.ok();
|
||||
|
||||
Profile::set_profile(active)
|
||||
.map_err(|e| warn!("set_profile, {}", e))
|
||||
.ok();
|
||||
ctrl.save_config();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_profile(signal_ctxt: &SignalContext<'_>, profile: Profile) -> zbus::Result<()> {
|
||||
}
|
||||
|
||||
@@ -1,399 +0,0 @@
|
||||
use crate::{config::Config, error::RogError, GetSupported};
|
||||
use async_trait::async_trait;
|
||||
use log::{error, info, warn};
|
||||
use rog_supported::RogBiosSupportedFunctions;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::BufRead;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use zbus::Connection;
|
||||
use zbus::{dbus_interface, SignalContext};
|
||||
|
||||
const INITRAMFS_PATH: &str = "/usr/sbin/update-initramfs";
|
||||
const DRACUT_PATH: &str = "/usr/bin/dracut";
|
||||
|
||||
static ASUS_SWITCH_GRAPHIC_MODE: &str =
|
||||
"/sys/firmware/efi/efivars/AsusSwitchGraphicMode-607005d5-3f75-4b2e-98f0-85ba66797a3e";
|
||||
static ASUS_POST_LOGO_SOUND: &str =
|
||||
"/sys/firmware/efi/efivars/AsusPostLogoSound-607005d5-3f75-4b2e-98f0-85ba66797a3e";
|
||||
static ASUS_PANEL_OD_PATH: &str = "/sys/devices/platform/asus-nb-wmi/panel_od";
|
||||
static ASUS_DGPU_DISABLE_PATH: &str = "/sys/devices/platform/asus-nb-wmi/dgpu_disable";
|
||||
static ASUS_EGPU_ENABLE_PATH: &str = "/sys/devices/platform/asus-nb-wmi/egpu_enable";
|
||||
|
||||
pub struct CtrlRogBios {
|
||||
_config: Arc<Mutex<Config>>,
|
||||
}
|
||||
|
||||
impl GetSupported for CtrlRogBios {
|
||||
type A = RogBiosSupportedFunctions;
|
||||
|
||||
fn get_supported() -> Self::A {
|
||||
RogBiosSupportedFunctions {
|
||||
post_sound: Path::new(ASUS_POST_LOGO_SOUND).exists(),
|
||||
dedicated_gfx: Path::new(ASUS_SWITCH_GRAPHIC_MODE).exists(),
|
||||
panel_overdrive: Path::new(ASUS_PANEL_OD_PATH).exists(),
|
||||
dgpu_disable: Path::new(ASUS_DGPU_DISABLE_PATH).exists(),
|
||||
egpu_enable: Path::new(ASUS_EGPU_ENABLE_PATH).exists(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
||||
impl CtrlRogBios {
|
||||
async fn set_dedicated_graphic_mode(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
dedicated: bool,
|
||||
) {
|
||||
self.set_gfx_mode(dedicated)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_asus_switch_graphic_mode {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
Self::notify_dedicated_graphic_mode(&ctxt, dedicated)
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
|
||||
fn dedicated_graphic_mode(&self) -> i8 {
|
||||
Self::get_gfx_mode()
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: get_gfx_mode {}", err);
|
||||
err
|
||||
})
|
||||
.unwrap_or(-1)
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_dedicated_graphic_mode(
|
||||
signal_ctxt: &SignalContext<'_>,
|
||||
dedicated: bool,
|
||||
) -> zbus::Result<()> {
|
||||
}
|
||||
|
||||
async fn set_post_boot_sound(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
on: bool,
|
||||
) {
|
||||
Self::set_boot_sound(on)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_post_boot_sound {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
Self::notify_post_boot_sound(&ctxt, on).await.ok();
|
||||
}
|
||||
|
||||
fn post_boot_sound(&self) -> i8 {
|
||||
Self::get_boot_sound()
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: get_boot_sound {}", err);
|
||||
err
|
||||
})
|
||||
.unwrap_or(-1)
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_post_boot_sound(ctxt: &SignalContext<'_>, on: bool) -> zbus::Result<()> {}
|
||||
|
||||
async fn set_panel_overdrive(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
overdrive: bool,
|
||||
) {
|
||||
if self
|
||||
.set_panel_od(overdrive)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_panel_overdrive {}", err);
|
||||
err
|
||||
})
|
||||
.is_ok()
|
||||
{
|
||||
Self::notify_panel_overdrive(&ctxt, overdrive).await.ok();
|
||||
}
|
||||
}
|
||||
|
||||
fn panel_overdrive(&self) -> i8 {
|
||||
let path = ASUS_PANEL_OD_PATH;
|
||||
if let Ok(mut file) = OpenOptions::new().read(true).open(path).map_err(|err| {
|
||||
warn!("CtrlRogBios: panel_overdrive {}", err);
|
||||
err
|
||||
}) {
|
||||
let mut buf = Vec::new();
|
||||
file.read_to_end(&mut buf)
|
||||
.map_err(|err| {
|
||||
warn!("CtrlRogBios: set_panel_overdrive {}", err);
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
|
||||
if buf.len() >= 1 {
|
||||
let tmp = String::from_utf8_lossy(&buf[0..1]);
|
||||
return tmp.parse::<i8>().unwrap_or(-1);
|
||||
}
|
||||
}
|
||||
-1
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
async fn notify_panel_overdrive(
|
||||
signal_ctxt: &SignalContext<'_>,
|
||||
overdrive: bool,
|
||||
) -> zbus::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl crate::ZbusAdd for CtrlRogBios {
|
||||
async fn add_to_server(self, server: &mut Connection) {
|
||||
Self::add_to_server_helper(self, "/org/asuslinux/RogBios", server).await;
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Reloadable for CtrlRogBios {
|
||||
fn reload(&mut self) -> Result<(), RogError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl CtrlRogBios {
|
||||
pub fn new(config: Arc<Mutex<Config>>) -> Result<Self, RogError> {
|
||||
if Path::new(ASUS_SWITCH_GRAPHIC_MODE).exists() {
|
||||
CtrlRogBios::set_path_mutable(ASUS_SWITCH_GRAPHIC_MODE)?;
|
||||
} else {
|
||||
info!("G-Sync Switchable Graphics not detected");
|
||||
info!("If your laptop is not a G-Sync enabled laptop then you can ignore this. Standard graphics switching will still work.");
|
||||
}
|
||||
|
||||
if Path::new(ASUS_POST_LOGO_SOUND).exists() {
|
||||
CtrlRogBios::set_path_mutable(ASUS_POST_LOGO_SOUND)?;
|
||||
} else {
|
||||
info!("Switch for POST boot sound not detected");
|
||||
}
|
||||
|
||||
Ok(CtrlRogBios { _config: config })
|
||||
}
|
||||
|
||||
fn set_path_mutable(path: &str) -> Result<(), RogError> {
|
||||
let output = Command::new("/usr/bin/chattr")
|
||||
.arg("-i")
|
||||
.arg(path)
|
||||
.output()
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
info!("Set {} writeable: status: {}", path, output.status);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn has_dedicated_gfx_toggle() -> bool {
|
||||
Path::new(ASUS_SWITCH_GRAPHIC_MODE).exists()
|
||||
}
|
||||
|
||||
pub fn get_gfx_mode() -> Result<i8, RogError> {
|
||||
let path = ASUS_SWITCH_GRAPHIC_MODE;
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(path)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)
|
||||
.map_err(|err| RogError::Read(path.into(), err))?;
|
||||
|
||||
let idx = data.len() - 1;
|
||||
Ok(data[idx] as i8)
|
||||
}
|
||||
|
||||
pub(super) fn set_gfx_mode(&self, dedicated: bool) -> Result<(), RogError> {
|
||||
let path = ASUS_SWITCH_GRAPHIC_MODE;
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(path)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)?;
|
||||
|
||||
let idx = data.len() - 1;
|
||||
if dedicated {
|
||||
data[idx] = 1;
|
||||
info!("Set system-level graphics mode: Dedicated Nvidia");
|
||||
} else {
|
||||
data[idx] = 0;
|
||||
info!("Set system-level graphics mode: Optimus");
|
||||
}
|
||||
file.write_all(&data)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
self.update_initramfs(dedicated)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_boot_sound() -> Result<i8, RogError> {
|
||||
let path = ASUS_POST_LOGO_SOUND;
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(path)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)
|
||||
.map_err(|err| RogError::Read(path.into(), err))?;
|
||||
|
||||
let idx = data.len() - 1;
|
||||
Ok(data[idx] as i8)
|
||||
}
|
||||
|
||||
pub(super) fn set_boot_sound(on: bool) -> Result<(), RogError> {
|
||||
let path = ASUS_POST_LOGO_SOUND;
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(path)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data)
|
||||
.map_err(|err| RogError::Read(path.into(), err))?;
|
||||
|
||||
let idx = data.len() - 1;
|
||||
if on {
|
||||
data[idx] = 1;
|
||||
info!("Set boot POST sound on");
|
||||
} else {
|
||||
data[idx] = 0;
|
||||
info!("Set boot POST sound off");
|
||||
}
|
||||
file.write_all(&data)
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// required for g-sync mode
|
||||
fn update_initramfs(&self, dedicated: bool) -> Result<(), RogError> {
|
||||
let mut initfs_cmd = None;
|
||||
|
||||
if Path::new(INITRAMFS_PATH).exists() {
|
||||
let mut cmd = Command::new("update-initramfs");
|
||||
cmd.arg("-u");
|
||||
initfs_cmd = Some(cmd);
|
||||
info!("Using initramfs update command 'update-initramfs'");
|
||||
} else if Path::new(DRACUT_PATH).exists() {
|
||||
let mut cmd = Command::new("dracut");
|
||||
cmd.arg("-f");
|
||||
cmd.arg("-q");
|
||||
initfs_cmd = Some(cmd);
|
||||
info!("Using initramfs update command 'dracut'");
|
||||
}
|
||||
|
||||
if let Some(mut cmd) = initfs_cmd {
|
||||
info!("Updating initramfs");
|
||||
|
||||
// If switching to Nvidia dedicated we need these modules included
|
||||
if Path::new(DRACUT_PATH).exists() && dedicated {
|
||||
cmd.arg("--add-drivers");
|
||||
cmd.arg("nvidia nvidia-drm nvidia-modeset nvidia-uvm");
|
||||
info!("System uses dracut, forcing nvidia modules to be included in init");
|
||||
} else if Path::new(INITRAMFS_PATH).exists() {
|
||||
let modules = vec![
|
||||
"nvidia\n",
|
||||
"nvidia-drm\n",
|
||||
"nvidia-modeset\n",
|
||||
"nvidia-uvm\n",
|
||||
];
|
||||
|
||||
let module_include = Path::new("/etc/initramfs-tools/modules");
|
||||
|
||||
if dedicated {
|
||||
let mut file = std::fs::OpenOptions::new()
|
||||
.append(true)
|
||||
.open(module_include)
|
||||
.map_err(|err| {
|
||||
RogError::Write(module_include.to_string_lossy().to_string(), err)
|
||||
})?;
|
||||
// add nvidia modules to module_include
|
||||
file.write_all(modules.concat().as_bytes())?;
|
||||
} else {
|
||||
let file = std::fs::OpenOptions::new()
|
||||
.read(true)
|
||||
.open(module_include)
|
||||
.map_err(|err| {
|
||||
RogError::Write(module_include.to_string_lossy().to_string(), err)
|
||||
})?;
|
||||
|
||||
let mut buf = Vec::new();
|
||||
// remove modules
|
||||
for line in std::io::BufReader::new(file).lines().flatten() {
|
||||
if !modules.contains(&line.as_str()) {
|
||||
buf.append(&mut line.as_bytes().to_vec());
|
||||
}
|
||||
}
|
||||
|
||||
let file = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.open(module_include)
|
||||
.map_err(|err| {
|
||||
RogError::Write(module_include.to_string_lossy().to_string(), err)
|
||||
})?;
|
||||
std::io::BufWriter::new(file).write_all(&buf)?;
|
||||
}
|
||||
}
|
||||
|
||||
let status = cmd
|
||||
.status()
|
||||
.map_err(|err| RogError::Write(format!("{:?}", cmd), err))?;
|
||||
if !status.success() {
|
||||
error!("Ram disk update failed");
|
||||
return Err(RogError::Initramfs("Ram disk update failed".into()));
|
||||
} else {
|
||||
info!("Successfully updated initramfs");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_panel_od(&mut self, overdrive: bool) -> Result<(), RogError> {
|
||||
let path = ASUS_PANEL_OD_PATH;
|
||||
let mut file = OpenOptions::new().write(true).open(path).map_err(|err| {
|
||||
warn!("CtrlRogBios: set_panel_overdrive {}", err);
|
||||
err
|
||||
})?;
|
||||
|
||||
let s = if overdrive { '1' } else { '0' };
|
||||
file.write(&[s as u8]).map_err(|err| {
|
||||
warn!("CtrlRogBios: set_panel_overdrive {}", err);
|
||||
err
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::CtrlRogBios;
|
||||
use crate::config::Config;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[test]
|
||||
#[ignore = "Must be manually tested"]
|
||||
fn set_multizone_4key_config() {
|
||||
let config = Config::default();
|
||||
|
||||
let controller = CtrlRogBios {
|
||||
_config: Arc::new(Mutex::new(config)),
|
||||
};
|
||||
|
||||
let res = controller.panel_overdrive();
|
||||
assert_eq!(res, 1);
|
||||
|
||||
// controller.set_panel_od(false).unwrap();
|
||||
// let res = controller.panel_overdrive();
|
||||
// assert_eq!(res, 0);
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,11 @@ use zbus::Connection;
|
||||
use zvariant::Type;
|
||||
|
||||
use crate::{
|
||||
ctrl_anime::CtrlAnime, ctrl_aura::controller::CtrlKbdLed, ctrl_charge::CtrlCharge,
|
||||
ctrl_profiles::controller::CtrlPlatformProfile, ctrl_rog_bios::CtrlRogBios, GetSupported,
|
||||
ctrl_anime::CtrlAnime, ctrl_aura::controller::CtrlKbdLed, ctrl_platform::CtrlRogBios,
|
||||
ctrl_power::CtrlPower, ctrl_profiles::controller::CtrlPlatformProfile, GetSupported,
|
||||
};
|
||||
|
||||
use rog_supported::{
|
||||
AnimeSupportedFunctions, ChargeSupportedFunctions, LedSupportedFunctions,
|
||||
PlatformProfileFunctions, RogBiosSupportedFunctions,
|
||||
};
|
||||
use rog_platform::supported::*;
|
||||
|
||||
#[derive(Serialize, Deserialize, Type)]
|
||||
pub struct SupportedFunctions {
|
||||
@@ -44,7 +41,7 @@ impl GetSupported for SupportedFunctions {
|
||||
SupportedFunctions {
|
||||
anime_ctrl: CtrlAnime::get_supported(),
|
||||
keyboard_led: CtrlKbdLed::get_supported(),
|
||||
charge_ctrl: CtrlCharge::get_supported(),
|
||||
charge_ctrl: CtrlPower::get_supported(),
|
||||
platform_profile: CtrlPlatformProfile::get_supported(),
|
||||
rog_bios_ctrl: CtrlRogBios::get_supported(),
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ use daemon::ctrl_aura::config::AuraConfig;
|
||||
use daemon::ctrl_aura::controller::{
|
||||
CtrlKbdLed, CtrlKbdLedReloader, CtrlKbdLedTask, CtrlKbdLedZbus,
|
||||
};
|
||||
use daemon::ctrl_charge::CtrlCharge;
|
||||
use daemon::ctrl_platform::CtrlRogBios;
|
||||
use daemon::ctrl_power::CtrlPower;
|
||||
use daemon::ctrl_profiles::config::ProfileConfig;
|
||||
use daemon::ctrl_rog_bios::CtrlRogBios;
|
||||
use daemon::{
|
||||
config::Config, ctrl_supported::SupportedFunctions, laptops::print_board_info, GetSupported,
|
||||
};
|
||||
@@ -59,7 +59,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
info!(" rog-aura v{}", rog_aura::VERSION);
|
||||
info!(" rog-dbus v{}", rog_dbus::VERSION);
|
||||
info!(" rog-profiles v{}", rog_profiles::VERSION);
|
||||
info!("rog-supported v{}", rog_supported::VERSION);
|
||||
info!("rog-platform v{}", rog_platform::VERSION);
|
||||
|
||||
let mut executor = Executor::new();
|
||||
|
||||
@@ -85,24 +85,27 @@ async fn start_daemon(executor: &mut Executor<'_>) -> Result<(), Box<dyn Error>>
|
||||
Ok(mut ctrl) => {
|
||||
// Do a reload of any settings
|
||||
ctrl.reload()
|
||||
.unwrap_or_else(|err| warn!("Battery charge limit: {}", err));
|
||||
.unwrap_or_else(|err| warn!("CtrlRogBios: {}", err));
|
||||
// Then register to dbus server
|
||||
ctrl.add_to_server(&mut connection).await;
|
||||
|
||||
let task = CtrlRogBios::new(config.clone())?;
|
||||
task.create_tasks(executor).await.ok();
|
||||
}
|
||||
Err(err) => {
|
||||
error!("rog_bios_control: {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
match CtrlCharge::new(config.clone()) {
|
||||
match CtrlPower::new(config.clone()) {
|
||||
Ok(mut ctrl) => {
|
||||
// Do a reload of any settings
|
||||
ctrl.reload()
|
||||
.unwrap_or_else(|err| warn!("Battery charge limit: {}", err));
|
||||
.unwrap_or_else(|err| warn!("CtrlPower: {}", err));
|
||||
// Then register to dbus server
|
||||
ctrl.add_to_server(&mut connection).await;
|
||||
|
||||
let task = CtrlCharge::new(config)?;
|
||||
let task = CtrlPower::new(config)?;
|
||||
task.create_tasks(executor).await.ok();
|
||||
}
|
||||
Err(err) => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use rog_anime::error::AnimeError;
|
||||
use rog_platform::error::PlatformError;
|
||||
use rog_profiles::error::ProfileError;
|
||||
use std::convert::From;
|
||||
use std::fmt;
|
||||
@@ -28,6 +29,7 @@ pub enum RogError {
|
||||
NoAuraKeyboard,
|
||||
NoAuraNode,
|
||||
Anime(AnimeError),
|
||||
Platform(PlatformError),
|
||||
}
|
||||
|
||||
impl fmt::Display for RogError {
|
||||
@@ -57,6 +59,7 @@ impl fmt::Display for RogError {
|
||||
RogError::NoAuraKeyboard => write!(f, "No supported Aura keyboard"),
|
||||
RogError::NoAuraNode => write!(f, "No Aura keyboard node found"),
|
||||
RogError::Anime(deets) => write!(f, "AniMe Matrix error: {}", deets),
|
||||
RogError::Platform(deets) => write!(f, "Asus Platform error: {}", deets),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,6 +78,12 @@ impl From<AnimeError> for RogError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PlatformError> for RogError {
|
||||
fn from(err: PlatformError) -> Self {
|
||||
RogError::Platform(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<zbus::Error> for RogError {
|
||||
fn from(err: zbus::Error) -> Self {
|
||||
RogError::Zbus(err)
|
||||
|
||||
@@ -5,22 +5,12 @@ pub mod config;
|
||||
pub mod ctrl_anime;
|
||||
/// Keyboard LED brightness control, RGB, and LED display modes
|
||||
pub mod ctrl_aura;
|
||||
/// Control of battery charge level
|
||||
pub mod ctrl_charge;
|
||||
/// Control CPU min/max freq and turbo, fan mode, fan curves
|
||||
///
|
||||
/// Intel machines can control:
|
||||
/// - CPU min/max frequency
|
||||
/// - CPU turbo enable/disable
|
||||
/// - Fan mode (normal, boost, silent)
|
||||
///
|
||||
/// AMD machines can control:
|
||||
/// - CPU turbo enable/disable
|
||||
/// - Fan mode (normal, boost, silent)
|
||||
/// - Fan min/max RPM curve
|
||||
pub mod ctrl_profiles;
|
||||
/// Control ASUS bios function such as boot sound, Optimus/Dedicated gfx mode
|
||||
pub mod ctrl_rog_bios;
|
||||
pub mod ctrl_platform;
|
||||
/// Control of battery charge level
|
||||
pub mod ctrl_power;
|
||||
/// Control platform profiles + fan-curves if available
|
||||
pub mod ctrl_profiles;
|
||||
/// Laptop matching to determine capabilities
|
||||
pub mod laptops;
|
||||
|
||||
@@ -35,11 +25,12 @@ use crate::error::RogError;
|
||||
use async_trait::async_trait;
|
||||
use config::Config;
|
||||
use log::warn;
|
||||
use logind_zbus::manager::ManagerProxy;
|
||||
use smol::{stream::StreamExt, Executor, Timer};
|
||||
use zbus::Connection;
|
||||
use zvariant::ObjectPath;
|
||||
|
||||
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
pub trait Reloadable {
|
||||
fn reload(&mut self) -> Result<(), RogError>;
|
||||
@@ -87,6 +78,64 @@ pub trait CtrlTask {
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
/// Free helper method to create tasks to run on: sleep, wake, shutdown, boot
|
||||
async fn create_sys_event_tasks(
|
||||
&self,
|
||||
executor: &mut Executor,
|
||||
mut on_sleep: impl FnMut() + Send + 'static,
|
||||
mut on_wake: impl FnMut() + Send + 'static,
|
||||
mut on_shutdown: impl FnMut() + Send + 'static,
|
||||
mut on_boot: impl FnMut() + Send + 'static,
|
||||
) {
|
||||
let connection = Connection::system()
|
||||
.await
|
||||
.expect("Controller could not create dbus connection");
|
||||
|
||||
let manager = ManagerProxy::new(&connection)
|
||||
.await
|
||||
.expect("Controller could not create ManagerProxy");
|
||||
|
||||
executor
|
||||
.spawn(async move {
|
||||
if let Ok(notif) = manager.receive_prepare_for_sleep().await {
|
||||
notif
|
||||
.for_each(|event| {
|
||||
if let Ok(args) = event.args() {
|
||||
if args.start {
|
||||
on_sleep();
|
||||
} else if !args.start() {
|
||||
on_wake();
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let manager = ManagerProxy::new(&connection)
|
||||
.await
|
||||
.expect("Controller could not create ManagerProxy");
|
||||
|
||||
executor
|
||||
.spawn(async move {
|
||||
if let Ok(notif) = manager.receive_prepare_for_shutdown().await {
|
||||
notif
|
||||
.for_each(|event| {
|
||||
if let Ok(args) = event.args() {
|
||||
if args.start {
|
||||
on_shutdown();
|
||||
} else if !args.start() {
|
||||
on_boot();
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CtrlTaskComplex {
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
function _asusctl() {
|
||||
local line
|
||||
|
||||
_arguments -C \
|
||||
{-h,--help}'[print help message]' \
|
||||
{-v,--version}'[print version number]' \
|
||||
{-k,--kbd-bright}':[Set keyboard brightness (off, low, med, high)]' \
|
||||
{-p,--pwr-profile}':[Set power profile (silent, normal, boost)]' \
|
||||
{-c,--chg-limit}':[Set charging limit (20-100)]' \
|
||||
': :((led-mode\:"Set the keyboard lighting from built-in modes" profile\:"Create and configure profiles" graphics\:"Set the graphics mode"))' \
|
||||
'*::arg:->args'
|
||||
case $line[1] in
|
||||
led-mode)
|
||||
_arguments ': :((static\:"set a single static colour"
|
||||
breathe\:"pulse between one or two colours"
|
||||
strobe\:"strobe through all colours"
|
||||
rainbow\:"rainbow cycling in one of four directions"
|
||||
star\:"rain pattern mimicking raindrops"
|
||||
rain\:"rain pattern of three preset colours"
|
||||
highlight\:"pressed keys are highlighted to fade"
|
||||
laser\:"pressed keys generate horizontal laser"
|
||||
ripple\:"pressed keys ripple outwards like a splash"
|
||||
pulse\:"set a rapid pulse"
|
||||
comet\:"set a vertical line zooming from left"
|
||||
flash\:"set a wide vertical line zooming from left"
|
||||
multi-static\:"4-zone multi-colour"))' \
|
||||
{-h,--help}'[print help message]' \
|
||||
'-c:[set the RGB value e.g, ff00ff]' \
|
||||
'-s:[set the speed (low, med, high)]'
|
||||
;;
|
||||
profile)
|
||||
_arguments {-h,--help}'[print help message]' \
|
||||
{-c,--create}"[create the profile if it doesn't exist]" \
|
||||
{-t,--turbo}':[enable or disable cpu turbo]' \
|
||||
{-m,--min-percentage}':[set min cpu scaling (intel)]' \
|
||||
{-M,--max-percentage}':[set max cpu scaling (intel)]' \
|
||||
{-p,--preset}':[<silent, normal, boost>]' \
|
||||
{-C,--curve}':[set fan curve]'
|
||||
|
||||
;;
|
||||
graphics)
|
||||
_arguments {-h,--help}'[print help message]' \
|
||||
{-m,--mode}':[Set graphics mode (nvidia, hybrid, compute, integrated)]' \
|
||||
{-g,--get}'[Get the current mode]' \
|
||||
{-p,--pow}'[Get the current power status]' \
|
||||
{-f,--force}'[Do not ask for confirmation]'
|
||||
;;
|
||||
esac
|
||||
}
|
||||
compdef _asusctl asusctl
|
||||
@@ -1,13 +0,0 @@
|
||||
[Unit]
|
||||
Description=ASUS Notebook Control
|
||||
After=basic.target syslog.target
|
||||
|
||||
[Service]
|
||||
Environment=IS_SERVICE=1
|
||||
ExecStart=/usr/bin/asusd
|
||||
Restart=on-failure
|
||||
Type=dbus
|
||||
BusName=org.asuslinux.Daemon
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,3 +1,17 @@
|
||||
[[led_data]]
|
||||
prod_family = "TUF"
|
||||
board_names = ["FA507"]
|
||||
standard = ["Static", "Breathe", "Strobe", "Pulse"]
|
||||
multizone = []
|
||||
per_key = false
|
||||
|
||||
[[led_data]]
|
||||
prod_family = "TUF Gaming"
|
||||
board_names = ["FX505D"]
|
||||
standard = ["Static", "Breathe", "Strobe", "Rainbow", "Pulse"]
|
||||
multizone = []
|
||||
per_key = false
|
||||
|
||||
[[led_data]]
|
||||
prod_family = "Zephyrus S"
|
||||
board_names = ["GX502", "GX701", "G531", "GL531", "G532"]
|
||||
@@ -50,14 +64,14 @@ per_key = false
|
||||
|
||||
[[led_data]]
|
||||
prod_family = "ROG Strix"
|
||||
board_names = ["G531GW", "G533QR", "G533QS", "G733QS", "G733QR", "G513QR", "G713QR", "G513QM"]
|
||||
board_names = ["G531GW", "G533QR", "G533QS", "G733QS", "G733QR", "G513QR", "G713QR", "G513QM", "G713IC", "G713RS"]
|
||||
standard = ["Static", "Breathe", "Strobe", "Rainbow", "Star", "Rain", "Highlight", "Laser", "Ripple", "Pulse", "Comet", "Flash"]
|
||||
multizone = []
|
||||
per_key = true
|
||||
|
||||
[[led_data]]
|
||||
prod_family = "ROG Strix"
|
||||
board_names = ["G513QE", "GX531", "G512LV", "G712LV", "G712LW", "G513IH", "G513QY", "G713QM", "G512"]
|
||||
board_names = ["G513QE", "GX531", "G512LV", "G712LV", "G712LW", "G513IH", "G513QY", "G713QM", "G512", "G713RW"]
|
||||
standard = ["Static", "Breathe", "Strobe", "Rainbow", "Pulse"]
|
||||
multizone = ["Key1", "Key2", "Key3", "Key4"]
|
||||
per_key = false
|
||||
@@ -162,8 +176,8 @@ multizone = []
|
||||
per_key = false
|
||||
|
||||
[[led_data]]
|
||||
prod_family = "ROG Strix"
|
||||
board_names = ["G513IC"]
|
||||
prod_family = "ROG Strix"
|
||||
board_names = ["G513IC", "G513RC"]
|
||||
standard = ["Static", "Breathe", "Strobe", "Rainbow", "Pulse"]
|
||||
multizone = []
|
||||
per_key = false
|
||||
|
||||
@@ -1,2 +1,19 @@
|
||||
ACTION=="add|change", SUBSYSTEM=="input", ENV{ID_VENDOR_ID}=="0b05", ENV{ID_MODEL_ID}=="1[89][a-zA-Z0-9][a-zA-Z0-9]|193b", ENV{ID_TYPE}=="hid", TAG+="systemd", ENV{SYSTEMD_WANTS}="asusd.service"
|
||||
ACTION=="add|remove", SUBSYSTEM=="input", ENV{ID_VENDOR_ID}=="0b05", ENV{ID_MODEL_ID}=="1[89][a-zA-Z0-9][a-zA-Z0-9]|193b", RUN+="systemctl restart asusd.service"
|
||||
#ACTION=="add|change", SUBSYSTEM=="input", ENV{ID_VENDOR_ID}=="0b05", ENV{ID_MODEL_ID}=="1[89][a-zA-Z0-9][a-zA-Z0-9]|193b", ENV{ID_TYPE}=="hid", TAG+="systemd", ENV{SYSTEMD_WANTS}="asusd.service"
|
||||
#ACTION=="add|remove", SUBSYSTEM=="input", ENV{ID_VENDOR_ID}=="0b05", ENV{ID_MODEL_ID}=="1[89][a-zA-Z0-9][a-zA-Z0-9]|193b", RUN+="systemctl restart asusd.service"
|
||||
|
||||
ENV{DMI_VENDOR}="$attr{[dmi/id]sys_vendor}"
|
||||
ENV{DMI_VENDOR}!="ASUSTeK COMPUTER INC.", GOTO="asusd_end"
|
||||
|
||||
ENV{DMI_FAMILY}="$attr{[dmi/id]product_family}"
|
||||
ENV{DMI_FAMILY}=="*TUF*", GOTO="asusd_start"
|
||||
ENV{DMI_FAMILY}=="*ROG*", GOTO="asusd_start"
|
||||
ENV{DMI_FAMILY}=="*Zephyrus*", GOTO="asusd_start"
|
||||
ENV{DMI_FAMILY}=="*Strix*", GOTO="asusd_start"
|
||||
# No match so
|
||||
GOTO="asusd_end"
|
||||
|
||||
LABEL="asusd_start"
|
||||
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"
|
||||
|
||||
LABEL="asusd_end"
|
||||
@@ -1,77 +0,0 @@
|
||||
# Author: AlenPaulVarghese <alenpaul2001@gmail.com>
|
||||
|
||||
set -l progname asusctl
|
||||
|
||||
set -l noopt "not __fish_contains_opt -s -s h -s v -s s -s k -s f -s c help version show-supported kbd-bright fan-mode chg-limit; and not __fish_seen_subcommand_from led-mode profile graphics;"
|
||||
|
||||
|
||||
set -l gmod_options '__fish_contains_opt -s m mode;'
|
||||
set -l fan_options '__fish_contains_opt -s f fan-mode;'
|
||||
set -l led_options '__fish_seen_subcommand_from led-mode;'
|
||||
set -l profile_options '__fish_seen_subcommand_from profile;'
|
||||
set -l keyboard_options '__fish_contains_opt -s k kbd-bright;'
|
||||
set -l graphics_options '__fish_seen_subcommand_from graphics;'
|
||||
|
||||
set -l fan_modes 'silent normal boost'
|
||||
set -l brightness_modes 'off low med high'
|
||||
set -l led_modes 'static breathe strobe rainbow comet'
|
||||
set -l graphics_modes 'nvidia hybird compute integrated'
|
||||
|
||||
|
||||
complete -c $progname -e
|
||||
complete -c $progname -f
|
||||
|
||||
# asusctl completion
|
||||
complete -c $progname -s h -f -l help -n "$noopt" -d "print help message"
|
||||
complete -c $progname -s v -f -l version -n "$noopt" -d "show program version number"
|
||||
complete -c $progname -s s -f -l show-supported -n "$noopt" -d "show supported functions of this laptop"
|
||||
complete -c $progname -s k -f -l kbd-bright -n "$noopt" -d "set led brightness"
|
||||
complete -c $progname -s f -f -l fan-mode -n "$noopt" -d "set fan mode independent of profile"
|
||||
complete -c $progname -s c -f -l chg-limit -n "$noopt" -d "set charge limit <20-100>"
|
||||
complete -c $progname -f -a "led-mode" -n "$noopt" -d "Set the keyboard lighting from built-in modes"
|
||||
complete -c $progname -f -a "profile" -n "$noopt" -d "Create and configure profiles"
|
||||
complete -c $progname -f -a "graphics" -n "$noopt" -d "Set the graphics mode"
|
||||
|
||||
# brightness completion
|
||||
complete -c $progname -n "$keyboard_options" -d "available brightness modes" -a "$brightness_modes"
|
||||
|
||||
# fan completion
|
||||
complete -c $progname -n "$fan_options" -d "available fan modes" -a $fan_modes
|
||||
|
||||
# graphics completion
|
||||
set -l gopt 'not __fish_contains_opt -s h -s g -s m -s p help mode get pow;'
|
||||
|
||||
complete -c $progname -n "$graphics_options and $gopt" -a "-h" -d "print help message"
|
||||
complete -c $progname -n "$graphics_options and $gopt" -a "-g" -d "Get the current mode"
|
||||
|
||||
complete -c $progname -s h -f -l help -n "$graphics_options and $gopt" -d "print help message"
|
||||
complete -c $progname -s m -f -l mode -n "$graphics_options and $gopt" -d "Set graphics mode: <nvidia, hybrid, compute, integrated>"
|
||||
complete -c $progname -s g -f -l get -n "$graphics_options and $gopt" -d "Get the current mode"
|
||||
complete -c $progname -s p -f -l pow -n "$graphics_options and $gopt" -d "Get the current power status"
|
||||
|
||||
complete -c $progname -n "$graphics_options and $gmod_options" -d "available graphics modes" -a "$graphics_modes"
|
||||
|
||||
# led-mode completion
|
||||
complete -c $progname -n "$led_options" -a "-h" -d "print help message"
|
||||
complete -c $progname -n "$led_options" -a "-n" -d "switch to next aura mode"
|
||||
|
||||
complete -c $progname -s h -f -l help -n "$led_options" -d "print help message"
|
||||
complete -c $progname -s n -f -l next-mode -n "$led_options" -d "switch to nex aura mode"
|
||||
complete -c $progname -s p -f -l prev-mode -n "$led_options" -d "switch to previous aura mode"
|
||||
complete -c $progname -n "$led_options" -d "available led modes" -a "$led_modes"
|
||||
|
||||
# profile completion
|
||||
set -l popt 'not __fish_contains_opt -s h -s n -s c -s t -s m -s M -s f help next create turbo min-percentage max-percentage fan-preset;'
|
||||
|
||||
complete -c $progname -n "$profile_options and $popt" -a "-h" -d "print help message"
|
||||
complete -c $progname -n "$profile_options and $popt" -a "-n" -d "toggle to next profile in list"
|
||||
|
||||
complete -c $progname -s h -f -l help -n "$profile_options and $popt" -d "print help message"
|
||||
complete -c $progname -s n -f -l next -n "$profile_options and $popt" -d "toggle to next profile in list"
|
||||
complete -c $progname -s c -f -l create -n "$profile_options and $popt" -d "create the profile if it doesn't exist"
|
||||
complete -c $progname -s t -f -l turbo -n "$profile_options and $popt" -d "enable or disable cpu turbo"
|
||||
complete -c $progname -s m -f -l min-percentage -n "$profile_options and $popt" -d "set min cpu scaling (intel)"
|
||||
complete -c $progname -s M -f -l max-percentage -n "$profile_options and $popt" -d "set max cpu scaling (intel)"
|
||||
complete -c $progname -s f -f -l fan-preset -n "$profile_options and $popt" -d "<silent, normal, boost>"
|
||||
complete -c $progname -n "$profile_option and __fish_contains_opt fan-preset" -d "available fan modes" -a $fan_modes
|
||||
|
||||
BIN
extra/fan-curves.png
Normal file
BIN
extra/fan-curves.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
BIN
extra/keyboard.png
Normal file
BIN
extra/keyboard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
BIN
extra/system.png
Normal file
BIN
extra/system.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
@@ -15,7 +15,7 @@ exclude = ["data"]
|
||||
[features]
|
||||
default = ["dbus", "detect"]
|
||||
dbus = ["zvariant", "zbus"]
|
||||
detect = ["udev", "sysfs-class"]
|
||||
detect = ["sysfs-class"]
|
||||
|
||||
[dependencies]
|
||||
png_pong = "^0.8.0"
|
||||
@@ -26,10 +26,9 @@ log = "*"
|
||||
serde = "^1.0"
|
||||
serde_derive = "^1.0"
|
||||
|
||||
glam = { version = "0.20.5", features = ["serde"] }
|
||||
glam = { version = "^0.21.2", features = ["serde"] }
|
||||
|
||||
zvariant = { version = "^3.0", optional = true }
|
||||
zbus = { version = "^2.2", optional = true }
|
||||
|
||||
udev = { version = "^0.6", optional = true }
|
||||
sysfs-class = { version = "^0.1", optional = true }
|
||||
@@ -32,4 +32,4 @@ pub mod error;
|
||||
/// Provides const methods to create the USB HID control packets
|
||||
pub mod usb;
|
||||
|
||||
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
@@ -36,30 +36,6 @@ pub fn get_anime_type() -> Result<AnimeType, AnimeError> {
|
||||
Err(AnimeError::UnsupportedDevice)
|
||||
}
|
||||
|
||||
/// Find the USB device node - known devices so far: `19b6`
|
||||
#[inline]
|
||||
pub fn find_node(id_product: &str) -> Result<String, AnimeError> {
|
||||
let mut enumerator =
|
||||
udev::Enumerator::new().map_err(|err| AnimeError::Udev("enumerator failed".into(), err))?;
|
||||
enumerator
|
||||
.match_subsystem("usb")
|
||||
.map_err(|err| AnimeError::Udev("match_subsystem failed".into(), err))?;
|
||||
|
||||
for device in enumerator
|
||||
.scan_devices()
|
||||
.map_err(|err| AnimeError::Udev("scan_devices failed".into(), err))?
|
||||
{
|
||||
if let Some(attr) = device.attribute_value("idProduct") {
|
||||
if attr == id_product {
|
||||
if let Some(dev_node) = device.devnode() {
|
||||
return Ok(dev_node.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(AnimeError::NoDevice)
|
||||
}
|
||||
|
||||
/// Get the two device initialization packets. These are required for device start
|
||||
/// after the laptop boots.
|
||||
#[inline]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rog_aura"
|
||||
version = "1.2.0"
|
||||
version = "1.3.3"
|
||||
license = "MPL-2.0"
|
||||
readme = "README.md"
|
||||
authors = ["Luke <luke@ljones.dev>"]
|
||||
@@ -13,11 +13,14 @@ edition = "2018"
|
||||
exclude = ["data"]
|
||||
|
||||
[features]
|
||||
default = ["dbus"]
|
||||
default = ["dbus", "toml"]
|
||||
dbus = ["zvariant"]
|
||||
|
||||
[dependencies]
|
||||
serde = "^1.0"
|
||||
serde_derive = "^1.0"
|
||||
|
||||
toml = { version = "^0.5", optional = true }
|
||||
zvariant = { version = "^3.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "^1.0"
|
||||
161
rog-aura/data/layouts/g513_US.toml
Normal file
161
rog-aura/data/layouts/g513_US.toml
Normal file
@@ -0,0 +1,161 @@
|
||||
matches = [
|
||||
'G513',
|
||||
]
|
||||
|
||||
locale = "US"
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'NormalSpacer',
|
||||
'FuncSpacer',
|
||||
'VolDown',
|
||||
'VolUp',
|
||||
'MicMute',
|
||||
'Fan',
|
||||
'Rog',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'Esc',
|
||||
'FuncSpacer',
|
||||
'F1',
|
||||
'F2',
|
||||
'F3',
|
||||
'F4',
|
||||
'FuncSpacer',
|
||||
'F5',
|
||||
'F6',
|
||||
'F7',
|
||||
'F8',
|
||||
'FuncSpacer',
|
||||
'F9',
|
||||
'F10',
|
||||
'F11',
|
||||
'F12',
|
||||
'RowEndSpacer',
|
||||
'NumPadDel',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tilde',
|
||||
'N1',
|
||||
'N2',
|
||||
'N3',
|
||||
'N4',
|
||||
'N5',
|
||||
'N6',
|
||||
'N7',
|
||||
'N8',
|
||||
'N9',
|
||||
'N0',
|
||||
'Hyphen',
|
||||
'Equals',
|
||||
'BkSpc',
|
||||
'RowEndSpacer',
|
||||
'Home',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tab',
|
||||
'Q',
|
||||
'W',
|
||||
'E',
|
||||
'R',
|
||||
'T',
|
||||
'Y',
|
||||
'U',
|
||||
'I',
|
||||
'O',
|
||||
'P',
|
||||
'LBracket',
|
||||
'RBracket',
|
||||
'BackSlash',
|
||||
'RowEndSpacer',
|
||||
'PgUp',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Caps',
|
||||
'A',
|
||||
'S',
|
||||
'D',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'SemiColon',
|
||||
'Quote',
|
||||
'Return',
|
||||
'RowEndSpacer',
|
||||
'PgDn',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'LShift',
|
||||
'Z',
|
||||
'X',
|
||||
'C',
|
||||
'V',
|
||||
'B',
|
||||
'N',
|
||||
'M',
|
||||
'Comma',
|
||||
'Period',
|
||||
'FwdSlash',
|
||||
'Rshift',
|
||||
'RowEndSpacer',
|
||||
'End',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.2
|
||||
row = [
|
||||
'LCtrl',
|
||||
'LFn',
|
||||
'Meta',
|
||||
'LAlt',
|
||||
'Space',
|
||||
'RAlt',
|
||||
'PrtSc',
|
||||
'RCtrl',
|
||||
'ArrowSpacer',
|
||||
'Up',
|
||||
'ArrowSpacer',
|
||||
'RowEndSpacer',
|
||||
'RFn',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'ArrowSpacer',
|
||||
'Left',
|
||||
'Down',
|
||||
'Right',
|
||||
'ArrowSpacer',
|
||||
]
|
||||
135
rog-aura/data/layouts/g533_US.toml
Normal file
135
rog-aura/data/layouts/g533_US.toml
Normal file
@@ -0,0 +1,135 @@
|
||||
matches = [
|
||||
'G533',
|
||||
]
|
||||
|
||||
locale = "US"
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'NormalSpacer',
|
||||
'FuncSpacer',
|
||||
'VolDown',
|
||||
'VolUp',
|
||||
'MicMute',
|
||||
'Fan',
|
||||
'Rog',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'Esc',
|
||||
'FuncSpacer',
|
||||
'F1',
|
||||
'F2',
|
||||
'F3',
|
||||
'F4',
|
||||
'FuncSpacer',
|
||||
'F5',
|
||||
'F6',
|
||||
'F7',
|
||||
'F8',
|
||||
'FuncSpacer',
|
||||
'F9',
|
||||
'F10',
|
||||
'F11',
|
||||
'F12',
|
||||
'Del',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tilde',
|
||||
'N1',
|
||||
'N2',
|
||||
'N3',
|
||||
'N4',
|
||||
'N5',
|
||||
'N6',
|
||||
'N7',
|
||||
'N8',
|
||||
'N9',
|
||||
'N0',
|
||||
'Hyphen',
|
||||
'Equals',
|
||||
'BkSpc',
|
||||
'MediaPlay',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tab',
|
||||
'Q',
|
||||
'W',
|
||||
'E',
|
||||
'R',
|
||||
'T',
|
||||
'Y',
|
||||
'U',
|
||||
'I',
|
||||
'O',
|
||||
'P',
|
||||
'LBracket',
|
||||
'RBracket',
|
||||
'BackSlash',
|
||||
'MediaStop',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Caps',
|
||||
'A',
|
||||
'S',
|
||||
'D',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'SemiColon',
|
||||
'Quote',
|
||||
'Return',
|
||||
'MediaPrev',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'LShift',
|
||||
'Z',
|
||||
'X',
|
||||
'C',
|
||||
'V',
|
||||
'B',
|
||||
'N',
|
||||
'M',
|
||||
'Comma',
|
||||
'Period',
|
||||
'FwdSlash',
|
||||
'RshiftSmall',
|
||||
'UpRegular',
|
||||
'MediaNext',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'LCtrlMed',
|
||||
'LFn',
|
||||
'Meta',
|
||||
'LAlt',
|
||||
'Space',
|
||||
'RAlt',
|
||||
'PrtSc',
|
||||
'RCtrl',
|
||||
'ArrowRegularSpacer',
|
||||
'LeftRegular',
|
||||
'DownRegular',
|
||||
'RightRegular',
|
||||
]
|
||||
|
||||
154
rog-aura/data/layouts/ga401_US.toml
Normal file
154
rog-aura/data/layouts/ga401_US.toml
Normal file
@@ -0,0 +1,154 @@
|
||||
matches = [
|
||||
'GA401',
|
||||
'GA402',
|
||||
'GU603',
|
||||
'GV301',
|
||||
'GA502',
|
||||
'GA503',
|
||||
]
|
||||
|
||||
locale = "US"
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'NormalSpacer',
|
||||
'FuncSpacer',
|
||||
'VolDown',
|
||||
'VolUp',
|
||||
'MicMute',
|
||||
'Rog',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'Esc',
|
||||
'FuncSpacer',
|
||||
'F1',
|
||||
'F2',
|
||||
'F3',
|
||||
'F4',
|
||||
'FuncSpacer',
|
||||
'F5',
|
||||
'F6',
|
||||
'F7',
|
||||
'F8',
|
||||
'FuncSpacer',
|
||||
'F9',
|
||||
'F10',
|
||||
'F11',
|
||||
'F12',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tilde',
|
||||
'N1',
|
||||
'N2',
|
||||
'N3',
|
||||
'N4',
|
||||
'N5',
|
||||
'N6',
|
||||
'N7',
|
||||
'N8',
|
||||
'N9',
|
||||
'N0',
|
||||
'Hyphen',
|
||||
'Equals',
|
||||
'BkSpc',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tab',
|
||||
'Q',
|
||||
'W',
|
||||
'E',
|
||||
'R',
|
||||
'T',
|
||||
'Y',
|
||||
'U',
|
||||
'I',
|
||||
'O',
|
||||
'P',
|
||||
'LBracket',
|
||||
'RBracket',
|
||||
'BackSlash',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Caps',
|
||||
'A',
|
||||
'S',
|
||||
'D',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'SemiColon',
|
||||
'Quote',
|
||||
'Return',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'LShift',
|
||||
'Z',
|
||||
'X',
|
||||
'C',
|
||||
'V',
|
||||
'B',
|
||||
'N',
|
||||
'M',
|
||||
'Comma',
|
||||
'Period',
|
||||
'FwdSlash',
|
||||
'Rshift',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.2
|
||||
row = [
|
||||
'LCtrl',
|
||||
'LFn',
|
||||
'Meta',
|
||||
'LAlt',
|
||||
'Space',
|
||||
'RAlt',
|
||||
'PrtSc',
|
||||
'RCtrl',
|
||||
'ArrowSpacer',
|
||||
'Up',
|
||||
'ArrowSpacer',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'FuncSpacer',
|
||||
'FuncSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'Left',
|
||||
'Down',
|
||||
'Right',
|
||||
'ArrowSpacer',
|
||||
]
|
||||
|
||||
180
rog-aura/data/layouts/gl504_US.toml
Normal file
180
rog-aura/data/layouts/gl504_US.toml
Normal file
@@ -0,0 +1,180 @@
|
||||
matches = [
|
||||
'GL504',
|
||||
]
|
||||
|
||||
locale = "US"
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'NormalSpacer',
|
||||
'FuncSpacer',
|
||||
'VolDown',
|
||||
'VolUp',
|
||||
'MicMute',
|
||||
'Rog',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'Esc',
|
||||
'FuncSpacer',
|
||||
'F1',
|
||||
'F2',
|
||||
'F3',
|
||||
'F4',
|
||||
'FuncSpacer',
|
||||
'F5',
|
||||
'F6',
|
||||
'F7',
|
||||
'F8',
|
||||
'FuncSpacer',
|
||||
'F9',
|
||||
'F10',
|
||||
'F11',
|
||||
'F12',
|
||||
'RowEndSpacer',
|
||||
'Del',
|
||||
'NumPadPause',
|
||||
'NumPadPrtSc',
|
||||
'NumPadHome',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tilde',
|
||||
'N1',
|
||||
'N2',
|
||||
'N3',
|
||||
'N4',
|
||||
'N5',
|
||||
'N6',
|
||||
'N7',
|
||||
'N8',
|
||||
'N9',
|
||||
'N0',
|
||||
'Hyphen',
|
||||
'Equals',
|
||||
'BkSpc',
|
||||
'RowEndSpacer',
|
||||
'NumLock',
|
||||
'FwdSlash',
|
||||
'Star',
|
||||
'Hyphen',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tab',
|
||||
'Q',
|
||||
'W',
|
||||
'E',
|
||||
'R',
|
||||
'T',
|
||||
'Y',
|
||||
'U',
|
||||
'I',
|
||||
'O',
|
||||
'P',
|
||||
'LBracket',
|
||||
'RBracket',
|
||||
'BackSlash',
|
||||
'RowEndSpacer',
|
||||
'N7',
|
||||
'N8',
|
||||
'N9',
|
||||
'NumPadPlus',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Caps',
|
||||
'A',
|
||||
'S',
|
||||
'D',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'SemiColon',
|
||||
'Quote',
|
||||
'Return',
|
||||
'RowEndSpacer',
|
||||
'N4',
|
||||
'N5',
|
||||
'N6',
|
||||
'NumPadPlus',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'LShift',
|
||||
'Z',
|
||||
'X',
|
||||
'C',
|
||||
'V',
|
||||
'B',
|
||||
'N',
|
||||
'M',
|
||||
'Comma',
|
||||
'Period',
|
||||
'FwdSlash',
|
||||
'Rshift',
|
||||
'RowEndSpacer',
|
||||
'N1',
|
||||
'N2',
|
||||
'N3',
|
||||
'NumPadEnter',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'LCtrl',
|
||||
'LFn',
|
||||
'Meta',
|
||||
'LAlt',
|
||||
'Space',
|
||||
'RAlt',
|
||||
'RFn',
|
||||
'RFn',
|
||||
'RCtrlLarge',
|
||||
'RowEndSpacer',
|
||||
'UpRegular',
|
||||
'N0',
|
||||
'NumPadDel',
|
||||
'NumPadEnter',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'FuncSpacer',
|
||||
'FuncSpacer',
|
||||
'FuncSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'LeftRegular',
|
||||
'RowEndSpacer',
|
||||
'DownRegular',
|
||||
'RightRegular',
|
||||
'NormalSpacer',
|
||||
]
|
||||
|
||||
172
rog-aura/data/layouts/gx502_US.toml
Normal file
172
rog-aura/data/layouts/gx502_US.toml
Normal file
@@ -0,0 +1,172 @@
|
||||
matches = [
|
||||
'GX502',
|
||||
'GU502',
|
||||
]
|
||||
|
||||
locale = "US"
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'NormalSpacer',
|
||||
'FuncSpacer',
|
||||
'VolDown',
|
||||
'VolUp',
|
||||
'MicMute',
|
||||
'Rog',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'Esc',
|
||||
'FuncSpacer',
|
||||
'F1',
|
||||
'F2',
|
||||
'F3',
|
||||
'F4',
|
||||
'FuncSpacer',
|
||||
'F5',
|
||||
'F6',
|
||||
'F7',
|
||||
'F8',
|
||||
'FuncSpacer',
|
||||
'F9',
|
||||
'F10',
|
||||
'F11',
|
||||
'F12',
|
||||
'RowEndSpacer',
|
||||
'Del',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tilde',
|
||||
'N1',
|
||||
'N2',
|
||||
'N3',
|
||||
'N4',
|
||||
'N5',
|
||||
'N6',
|
||||
'N7',
|
||||
'N8',
|
||||
'N9',
|
||||
'N0',
|
||||
'Hyphen',
|
||||
'Equals',
|
||||
'BkSpc3_1',
|
||||
'BkSpc3_2',
|
||||
'BkSpc3_3',
|
||||
'RowEndSpacer',
|
||||
'Home',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Tab',
|
||||
'Q',
|
||||
'W',
|
||||
'E',
|
||||
'R',
|
||||
'T',
|
||||
'Y',
|
||||
'U',
|
||||
'I',
|
||||
'O',
|
||||
'P',
|
||||
'LBracket',
|
||||
'RBracket',
|
||||
'BackSlash',
|
||||
'RowEndSpacer',
|
||||
'PgUp',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'Caps',
|
||||
'A',
|
||||
'S',
|
||||
'D',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'SemiColon',
|
||||
'Quote',
|
||||
'Return3_1',
|
||||
'Return3_2',
|
||||
'Return3_3',
|
||||
'RowEndSpacer',
|
||||
'PgDn',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.0
|
||||
row = [
|
||||
'LShift',
|
||||
'Z',
|
||||
'X',
|
||||
'C',
|
||||
'V',
|
||||
'B',
|
||||
'N',
|
||||
'M',
|
||||
'Comma',
|
||||
'Period',
|
||||
'FwdSlash',
|
||||
'Rshift3_1',
|
||||
'Rshift3_2',
|
||||
'Rshift3_3',
|
||||
'RowEndSpacer',
|
||||
'End',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 1.2
|
||||
row = [
|
||||
'LCtrl',
|
||||
'LFn',
|
||||
'Meta',
|
||||
'LAlt',
|
||||
'Space5_1',
|
||||
'Space5_2',
|
||||
'Space5_3',
|
||||
'Space5_4',
|
||||
'Space5_5',
|
||||
'RAlt',
|
||||
'PrtSc',
|
||||
'RCtrl',
|
||||
'ArrowSpacer',
|
||||
'Up',
|
||||
'ArrowSpacer',
|
||||
'RowEndSpacer',
|
||||
'RFn',
|
||||
]
|
||||
|
||||
[[rows]]
|
||||
height = 0.8
|
||||
row = [
|
||||
'FuncSpacer',
|
||||
'FuncSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'NormalSpacer',
|
||||
'Left',
|
||||
'Down',
|
||||
'Right',
|
||||
'ArrowSpacer',
|
||||
]
|
||||
|
||||
@@ -20,13 +20,6 @@ pub enum LedBrightness {
|
||||
High,
|
||||
}
|
||||
|
||||
impl LedBrightness {
|
||||
pub fn as_char_code(&self) -> u8 {
|
||||
std::char::from_digit(*self as u32, 10)
|
||||
.expect("LedBrightness.as_char_code failed to convert") as u8
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for LedBrightness {
|
||||
fn from(bright: u32) -> Self {
|
||||
match bright {
|
||||
@@ -40,7 +33,7 @@ impl From<u32> for LedBrightness {
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Clone, PartialEq, Copy, Deserialize, Serialize)]
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Copy, Deserialize, Serialize)]
|
||||
pub struct Colour(pub u8, pub u8, pub u8);
|
||||
|
||||
impl Default for Colour {
|
||||
@@ -63,6 +56,34 @@ impl FromStr for Colour {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[f32; 3]> for Colour {
|
||||
fn from(c: &[f32; 3]) -> Self {
|
||||
Self(
|
||||
(255.0 * c[0]) as u8,
|
||||
(255.0 * c[1]) as u8,
|
||||
(255.0 * c[2]) as u8,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Colour> for [f32; 3] {
|
||||
fn from(c: Colour) -> Self {
|
||||
[c.0 as f32 / 255.0, c.1 as f32 / 255.0, c.2 as f32 / 255.0]
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[u8; 3]> for Colour {
|
||||
fn from(c: &[u8; 3]) -> Self {
|
||||
Self(c[0], c[1], c[2])
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Colour> for [u8; 3] {
|
||||
fn from(c: Colour) -> Self {
|
||||
[c.0, c.1, c.2]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub enum Speed {
|
||||
@@ -89,6 +110,15 @@ impl FromStr for Speed {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Speed> for u8 {
|
||||
fn from(s: Speed) -> u8 {
|
||||
match s {
|
||||
Speed::Low => 0,
|
||||
Speed::Med => 1,
|
||||
Speed::High => 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Used for Rainbow mode.
|
||||
///
|
||||
/// Enum corresponds to the required integer value
|
||||
@@ -122,8 +152,11 @@ impl FromStr for Direction {
|
||||
|
||||
/// Enum of modes that convert to the actual number required by a USB HID packet
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Deserialize, Serialize)]
|
||||
#[derive(
|
||||
Debug, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Deserialize, Serialize,
|
||||
)]
|
||||
pub enum AuraModeNum {
|
||||
#[default]
|
||||
Static = 0,
|
||||
Breathe = 1,
|
||||
Strobe = 2,
|
||||
@@ -218,9 +251,10 @@ impl From<u8> for AuraModeNum {
|
||||
|
||||
/// Base effects have no zoning, while multizone is 1-4
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub enum AuraZone {
|
||||
/// Used if keyboard has no zones, or if setting all
|
||||
#[default]
|
||||
None,
|
||||
/// Leftmost zone
|
||||
Key1,
|
||||
@@ -238,12 +272,6 @@ pub enum AuraZone {
|
||||
BarRight,
|
||||
}
|
||||
|
||||
impl Default for AuraZone {
|
||||
fn default() -> Self {
|
||||
AuraZone::None
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for AuraZone {
|
||||
type Err = Error;
|
||||
|
||||
@@ -330,6 +358,53 @@ impl Default for AuraEffect {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AuraParameters {
|
||||
pub zone: bool,
|
||||
pub colour1: bool,
|
||||
pub colour2: bool,
|
||||
pub speed: bool,
|
||||
pub direction: bool,
|
||||
}
|
||||
|
||||
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 => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Breathe => AuraParameters::new(true, true, true, true, false),
|
||||
AuraModeNum::Strobe => 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::Rain => AuraParameters::new(true, false, false, true, false),
|
||||
AuraModeNum::Highlight => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Laser => AuraParameters::new(true, true, false, true, false),
|
||||
AuraModeNum::Ripple => AuraParameters::new(true, true, false, true, false),
|
||||
AuraModeNum::Pulse => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Comet => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Flash => AuraParameters::new(true, true, false, false, false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses `AuraEffect` in to packet data for writing to the USB interface
|
||||
///
|
||||
/// Byte structure where colour is RGB, one byte per R, G, B:
|
||||
@@ -357,6 +432,25 @@ impl From<&AuraEffect> for [u8; LED_MSG_LEN] {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&AuraEffect> for Vec<u8> {
|
||||
fn from(aura: &AuraEffect) -> Self {
|
||||
let mut msg = vec![0u8; LED_MSG_LEN];
|
||||
msg[0] = 0x5d;
|
||||
msg[1] = 0xb3;
|
||||
msg[2] = aura.zone as u8;
|
||||
msg[3] = aura.mode as u8;
|
||||
msg[4] = aura.colour1.0;
|
||||
msg[5] = aura.colour1.1;
|
||||
msg[6] = aura.colour1.2;
|
||||
msg[7] = aura.speed as u8;
|
||||
msg[8] = aura.direction as u8;
|
||||
msg[10] = aura.colour2.0;
|
||||
msg[11] = aura.colour2.1;
|
||||
msg[12] = aura.colour2.2;
|
||||
msg
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{AuraEffect, AuraModeNum, AuraZone, Colour, Direction, Speed, LED_MSG_LEN};
|
||||
|
||||
@@ -7,7 +7,8 @@ pub enum Error {
|
||||
ParseSpeed,
|
||||
ParseDirection,
|
||||
ParseBrightness,
|
||||
ParseAnime,
|
||||
Io(std::io::Error),
|
||||
Toml(toml::de::Error),
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
@@ -18,9 +19,22 @@ impl fmt::Display for Error {
|
||||
Error::ParseSpeed => write!(f, "Could not parse speed"),
|
||||
Error::ParseDirection => write!(f, "Could not parse direction"),
|
||||
Error::ParseBrightness => write!(f, "Could not parse brightness"),
|
||||
Error::ParseAnime => write!(f, "Could not parse anime"),
|
||||
Error::Io(io) => write!(f, "IO Error: {io}"),
|
||||
Error::Toml(e) => write!(f, "TOML Parse Error: {e}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for Error {}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(e: std::io::Error) -> Self {
|
||||
Self::Io(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<toml::de::Error> for Error {
|
||||
fn from(e: toml::de::Error) -> Self {
|
||||
Self::Toml(e)
|
||||
}
|
||||
}
|
||||
|
||||
155
rog-aura/src/key_to_str.rs
Normal file
155
rog-aura/src/key_to_str.rs
Normal file
@@ -0,0 +1,155 @@
|
||||
use crate::keys::Key;
|
||||
|
||||
impl From<Key> for &str {
|
||||
fn from(k: Key) -> Self {
|
||||
(&k).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Key> for &str {
|
||||
fn from(k: &Key) -> Self {
|
||||
match k {
|
||||
Key::VolUp => "Volume Up",
|
||||
Key::VolDown => "Volume Down",
|
||||
Key::MicMute => "Mute Mic",
|
||||
Key::Rog => "ROG",
|
||||
Key::Fan => "Fan Control",
|
||||
Key::Esc => "Escape",
|
||||
Key::F1 => "F1",
|
||||
Key::F2 => "F2",
|
||||
Key::F3 => "F3",
|
||||
Key::F4 => "F4",
|
||||
Key::F5 => "F5",
|
||||
Key::F6 => "F6",
|
||||
Key::F7 => "F7",
|
||||
Key::F8 => "F8",
|
||||
Key::F9 => "F9",
|
||||
Key::F10 => "F10",
|
||||
Key::F11 => "F11",
|
||||
Key::F12 => "F12",
|
||||
Key::Del => "Delete",
|
||||
Key::Tilde => "Tilde",
|
||||
Key::N1 => "1",
|
||||
Key::N2 => "2",
|
||||
Key::N3 => "3",
|
||||
Key::N4 => "4",
|
||||
Key::N5 => "5",
|
||||
Key::N6 => "6",
|
||||
Key::N7 => "7",
|
||||
Key::N8 => "8",
|
||||
Key::N9 => "9",
|
||||
Key::N0 => "0",
|
||||
Key::Hyphen => "-",
|
||||
Key::Equals => "=",
|
||||
Key::BkSpc => "Backspace",
|
||||
Key::BkSpc3_1 => "Backspace LED 1",
|
||||
Key::BkSpc3_2 => "Backspace LED 2",
|
||||
Key::BkSpc3_3 => "Backspace LED 3",
|
||||
Key::Home => "Home",
|
||||
Key::Tab => "Tab",
|
||||
Key::Q => "Q",
|
||||
Key::W => "W",
|
||||
Key::E => "E",
|
||||
Key::R => "R",
|
||||
Key::T => "T",
|
||||
Key::Y => "Y",
|
||||
Key::U => "U",
|
||||
Key::I => "I",
|
||||
Key::O => "O",
|
||||
Key::P => "P",
|
||||
Key::LBracket => "[",
|
||||
Key::RBracket => "]",
|
||||
Key::BackSlash => "\\",
|
||||
Key::PgUp => "Page Up",
|
||||
Key::Caps => "Caps Lock",
|
||||
Key::A => "A",
|
||||
Key::S => "S",
|
||||
Key::D => "D",
|
||||
Key::F => "F",
|
||||
Key::G => "G",
|
||||
Key::H => "H",
|
||||
Key::J => "J",
|
||||
Key::K => "K",
|
||||
Key::L => "L",
|
||||
Key::SemiColon => ";",
|
||||
Key::Quote => "'",
|
||||
Key::Return => "Return",
|
||||
Key::Return3_1 => "Return LED 1",
|
||||
Key::Return3_2 => "Return LED 2",
|
||||
Key::Return3_3 => "Return LED 3",
|
||||
Key::PgDn => "Page Down",
|
||||
Key::LShift => "Left Shift",
|
||||
Key::LShift3_1 => "Left Shift LED 1",
|
||||
Key::LShift3_2 => "Left Shift LED 2",
|
||||
Key::LShift3_3 => "Left Shift LED 3",
|
||||
Key::Z => "Z",
|
||||
Key::X => "X",
|
||||
Key::C => "C",
|
||||
Key::V => "V",
|
||||
Key::B => "B",
|
||||
Key::N => "N",
|
||||
Key::M => "M",
|
||||
Key::Comma => ",",
|
||||
Key::Period => ".",
|
||||
Key::Star => "*",
|
||||
Key::NumPadDel => "Delete",
|
||||
Key::NumPadPlus => "+",
|
||||
Key::NumPadEnter => "Enter",
|
||||
Key::NumPadPause => "Pause",
|
||||
Key::NumPadPrtSc => "Print Screen",
|
||||
Key::NumPadHome => "Home",
|
||||
Key::NumLock => "Num-Lock",
|
||||
Key::FwdSlash => "/",
|
||||
Key::Rshift => "Right Shift",
|
||||
Key::RshiftSmall => "Right Shift",
|
||||
Key::Rshift3_1 => "Right Shift LED 1",
|
||||
Key::Rshift3_2 => "Right Shift LED 2",
|
||||
Key::Rshift3_3 => "Right Shift LED 3",
|
||||
Key::End => "End",
|
||||
Key::LCtrl => "Left Control",
|
||||
Key::LCtrlMed => "Left Control",
|
||||
Key::LFn => "Left Fn",
|
||||
Key::Meta => "Meta",
|
||||
Key::LAlt => "Left Alt",
|
||||
Key::Space => "Space",
|
||||
Key::Space5_1 => "Space LED 1",
|
||||
Key::Space5_2 => "Space LED 2",
|
||||
Key::Space5_3 => "Space LED 3",
|
||||
Key::Space5_4 => "Space LED 4",
|
||||
Key::Space5_5 => "Space LED 5",
|
||||
Key::RAlt => "Right Alt",
|
||||
Key::PrtSc => "Print Screen",
|
||||
Key::RCtrl => "Right Control",
|
||||
Key::RCtrlLarge => "Right Control",
|
||||
Key::Pause => "Pause",
|
||||
Key::Up => "Up",
|
||||
Key::Down => "Down",
|
||||
Key::Left => "Left",
|
||||
Key::Right => "Right",
|
||||
Key::UpRegular => "Up",
|
||||
Key::DownRegular => "Down",
|
||||
Key::LeftRegular => "Left",
|
||||
Key::RightRegular => "Right",
|
||||
Key::UpSplit => "Up",
|
||||
Key::DownSplit => "Down",
|
||||
Key::LeftSplit => "Left",
|
||||
Key::RightSplit => "Right",
|
||||
Key::RFn => "Right Fn",
|
||||
Key::MediaPlay => "Media Play",
|
||||
Key::MediaStop => "Media Stop",
|
||||
Key::MediaNext => "Media Next",
|
||||
Key::MediaPrev => "Media Previous",
|
||||
Key::NormalBlank => "",
|
||||
Key::NormalSpacer => "",
|
||||
Key::FuncBlank => "",
|
||||
Key::FuncSpacer => "",
|
||||
Key::ArrowBlank => "",
|
||||
Key::ArrowSpacer => "",
|
||||
Key::ArrowRegularBlank => "",
|
||||
Key::ArrowRegularSpacer => "",
|
||||
Key::ArrowSplitBlank => "",
|
||||
Key::ArrowSplitSpacer => "",
|
||||
Key::RowEndSpacer => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
363
rog-aura/src/keys.rs
Normal file
363
rog-aura/src/keys.rs
Normal file
@@ -0,0 +1,363 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Copy, Clone, Serialize, Deserialize)]
|
||||
pub enum Key {
|
||||
VolUp,
|
||||
VolDown,
|
||||
MicMute,
|
||||
#[default]
|
||||
Rog,
|
||||
Fan,
|
||||
Esc,
|
||||
F1,
|
||||
F2,
|
||||
F3,
|
||||
F4,
|
||||
F5,
|
||||
F6,
|
||||
F7,
|
||||
F8,
|
||||
F9,
|
||||
F10,
|
||||
F11,
|
||||
F12,
|
||||
Del,
|
||||
Tilde,
|
||||
N1,
|
||||
N2,
|
||||
N3,
|
||||
N4,
|
||||
N5,
|
||||
N6,
|
||||
N7,
|
||||
N8,
|
||||
N9,
|
||||
N0,
|
||||
Hyphen,
|
||||
Equals,
|
||||
BkSpc,
|
||||
BkSpc3_1,
|
||||
BkSpc3_2,
|
||||
BkSpc3_3,
|
||||
Home,
|
||||
Tab,
|
||||
Q,
|
||||
W,
|
||||
E,
|
||||
R,
|
||||
T,
|
||||
Y,
|
||||
U,
|
||||
I,
|
||||
O,
|
||||
P,
|
||||
LBracket,
|
||||
RBracket,
|
||||
BackSlash,
|
||||
PgUp,
|
||||
Caps,
|
||||
A,
|
||||
S,
|
||||
D,
|
||||
F,
|
||||
G,
|
||||
H,
|
||||
J,
|
||||
K,
|
||||
L,
|
||||
SemiColon,
|
||||
Quote,
|
||||
Return,
|
||||
Return3_1,
|
||||
Return3_2,
|
||||
Return3_3,
|
||||
PgDn,
|
||||
LShift,
|
||||
LShift3_1,
|
||||
LShift3_2,
|
||||
LShift3_3,
|
||||
Z,
|
||||
X,
|
||||
C,
|
||||
V,
|
||||
B,
|
||||
N,
|
||||
M,
|
||||
Comma,
|
||||
Period,
|
||||
FwdSlash,
|
||||
Star,
|
||||
NumPadDel,
|
||||
NumPadPlus,
|
||||
NumPadEnter,
|
||||
NumPadPause,
|
||||
NumPadPrtSc,
|
||||
NumPadHome,
|
||||
NumLock,
|
||||
Rshift,
|
||||
RshiftSmall,
|
||||
Rshift3_1,
|
||||
Rshift3_2,
|
||||
Rshift3_3,
|
||||
End,
|
||||
LCtrl,
|
||||
LCtrlMed,
|
||||
LFn,
|
||||
Meta,
|
||||
LAlt,
|
||||
Space,
|
||||
Space5_1,
|
||||
Space5_2,
|
||||
Space5_3,
|
||||
Space5_4,
|
||||
Space5_5,
|
||||
Pause,
|
||||
RAlt,
|
||||
PrtSc,
|
||||
RCtrl,
|
||||
RCtrlLarge,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
UpRegular,
|
||||
DownRegular,
|
||||
LeftRegular,
|
||||
RightRegular,
|
||||
UpSplit,
|
||||
DownSplit,
|
||||
LeftSplit,
|
||||
RightSplit,
|
||||
RFn,
|
||||
MediaPlay,
|
||||
MediaStop,
|
||||
MediaNext,
|
||||
MediaPrev,
|
||||
NormalBlank,
|
||||
/// To be ignored by per-key effects
|
||||
NormalSpacer,
|
||||
FuncBlank,
|
||||
/// To be ignored by per-key effects
|
||||
FuncSpacer,
|
||||
ArrowBlank,
|
||||
/// To be ignored by per-key effects
|
||||
ArrowSpacer,
|
||||
ArrowRegularBlank,
|
||||
/// To be ignored by per-key effects
|
||||
ArrowRegularSpacer,
|
||||
ArrowSplitBlank,
|
||||
/// To be ignored by per-key effects
|
||||
ArrowSplitSpacer,
|
||||
/// A gap between regular rows and the rightside buttons
|
||||
RowEndSpacer,
|
||||
}
|
||||
|
||||
impl Key {
|
||||
pub fn is_placeholder(&self) -> bool {
|
||||
let shape = KeyShape::from(self);
|
||||
shape.is_blank() || shape.is_spacer()
|
||||
}
|
||||
}
|
||||
|
||||
/// Types of shapes of LED on keyboards. The shape is used for visual representations
|
||||
///
|
||||
/// A post fix of Spacer *must be ignored by per-key effects
|
||||
#[derive(Debug, Default, Clone, Copy, Deserialize, Serialize)]
|
||||
pub enum KeyShape {
|
||||
Tilde,
|
||||
#[default]
|
||||
Normal,
|
||||
NormalBlank,
|
||||
NormalSpacer,
|
||||
Func,
|
||||
FuncBlank,
|
||||
FuncSpacer,
|
||||
Space,
|
||||
Space5,
|
||||
LCtrlMed,
|
||||
LShift,
|
||||
/// Used in a group of 3 (LED's)
|
||||
LShift3,
|
||||
RShift,
|
||||
RshiftSmall,
|
||||
/// Used in a group of 3 (LED's)
|
||||
RShift3,
|
||||
Return,
|
||||
Return3,
|
||||
Tab,
|
||||
Caps,
|
||||
Backspace,
|
||||
/// Used in a group of 3 (LED's)
|
||||
Backspace3,
|
||||
Arrow,
|
||||
ArrowBlank,
|
||||
ArrowSpacer,
|
||||
ArrowSplit,
|
||||
ArrowSplitBlank,
|
||||
ArrowSplitSpacer,
|
||||
ArrowRegularBlank,
|
||||
ArrowRegularSpacer,
|
||||
RowEndSpacer,
|
||||
}
|
||||
|
||||
impl KeyShape {
|
||||
pub const fn width(&self) -> f32 {
|
||||
match self {
|
||||
Self::Tilde => 0.8,
|
||||
Self::Normal => 1.0,
|
||||
Self::NormalBlank => 1.0,
|
||||
Self::NormalSpacer => 1.0,
|
||||
Self::Func => 1.0,
|
||||
Self::FuncBlank => 1.0,
|
||||
Self::FuncSpacer => 0.6,
|
||||
Self::Space => 5.0,
|
||||
Self::Space5 => 1.0,
|
||||
Self::LCtrlMed => 1.1,
|
||||
Self::LShift => 2.0,
|
||||
Self::LShift3 => 0.67,
|
||||
Self::RShift => 2.8,
|
||||
Self::RshiftSmall => 1.8,
|
||||
Self::RShift3 => 0.93,
|
||||
Self::Return => 2.2,
|
||||
Self::Return3 => 0.7333,
|
||||
Self::Tab => 1.4,
|
||||
Self::Caps => 1.6,
|
||||
Self::Backspace => 2.0,
|
||||
Self::Backspace3 => 0.666,
|
||||
Self::ArrowRegularBlank | Self::ArrowRegularSpacer => 0.7,
|
||||
Self::Arrow => 0.8,
|
||||
Self::ArrowBlank | Self::ArrowSpacer => 1.0,
|
||||
Self::ArrowSplit | Self::ArrowSplitBlank | Self::ArrowSplitSpacer => 1.0,
|
||||
Self::RowEndSpacer => 0.1,
|
||||
}
|
||||
}
|
||||
|
||||
/// A blank is used to space keys out in GUI's and can be used or ignored
|
||||
/// depednign on the per-key effect
|
||||
pub const fn is_blank(&self) -> bool {
|
||||
match self {
|
||||
Self::NormalBlank
|
||||
| Self::FuncBlank
|
||||
| Self::ArrowBlank
|
||||
| Self::ArrowSplitBlank
|
||||
| Self::ArrowRegularBlank => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// A spacer is used to space keys out in GUI's, but ignored in per-key effects
|
||||
pub const fn is_spacer(&self) -> bool {
|
||||
match self {
|
||||
Self::FuncSpacer
|
||||
| Self::NormalSpacer
|
||||
| Self::ArrowSpacer
|
||||
| Self::ArrowSplitSpacer
|
||||
| Self::ArrowRegularSpacer => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// All keys with a postfix of some number
|
||||
pub const fn is_group(&self) -> bool {
|
||||
match self {
|
||||
Self::LShift3 | Self::RShift3 => true,
|
||||
Self::Return3 | Self::Space5 | Self::Backspace3 => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Mostly intended as a helper for signalling when to draw a
|
||||
/// split/compact arrow cluster
|
||||
pub const fn is_arrow_cluster(&self) -> bool {
|
||||
match self {
|
||||
Self::Arrow | Self::ArrowBlank | Self::ArrowSpacer => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn is_arrow_splits(&self) -> bool {
|
||||
match self {
|
||||
Self::ArrowSplit | Self::ArrowSplitBlank | Self::ArrowSplitSpacer => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Key> for KeyShape {
|
||||
fn from(k: Key) -> Self {
|
||||
match k {
|
||||
Key::VolUp
|
||||
| Key::VolDown
|
||||
| Key::MicMute
|
||||
| Key::Rog
|
||||
| Key::Fan
|
||||
| Key::Esc
|
||||
| Key::F1
|
||||
| Key::F2
|
||||
| Key::F3
|
||||
| Key::F4
|
||||
| Key::F5
|
||||
| Key::F6
|
||||
| Key::F7
|
||||
| Key::F8
|
||||
| Key::F9
|
||||
| Key::F10
|
||||
| Key::F11
|
||||
| Key::F12
|
||||
| Key::Del => KeyShape::Func,
|
||||
Key::Tilde => KeyShape::Tilde,
|
||||
|
||||
Key::BkSpc => KeyShape::Backspace,
|
||||
Key::BkSpc3_1 | Key::BkSpc3_2 | Key::BkSpc3_3 => KeyShape::Backspace3,
|
||||
Key::Tab | Key::BackSlash => KeyShape::Tab,
|
||||
Key::Caps => KeyShape::Caps,
|
||||
|
||||
Key::Return => KeyShape::Return,
|
||||
Key::Return3_1 | Key::Return3_2 | Key::Return3_3 => KeyShape::Return3,
|
||||
Key::LCtrlMed => KeyShape::LCtrlMed,
|
||||
Key::LShift => KeyShape::LShift,
|
||||
|
||||
Key::Rshift | Key::RCtrlLarge => KeyShape::RShift,
|
||||
Key::RshiftSmall => KeyShape::RshiftSmall,
|
||||
Key::Rshift3_1 | Key::Rshift3_2 | Key::Rshift3_3 => KeyShape::RShift3,
|
||||
|
||||
Key::Space => KeyShape::Space,
|
||||
Key::Space5_1 | Key::Space5_2 | Key::Space5_3 | Key::Space5_4 | Key::Space5_5 => {
|
||||
KeyShape::Space5
|
||||
}
|
||||
|
||||
Key::NumPadPause | Key::NumPadPrtSc | Key::NumPadHome | Key::NumPadDel => {
|
||||
KeyShape::Func
|
||||
}
|
||||
|
||||
Key::NormalBlank => KeyShape::NormalBlank,
|
||||
Key::NormalSpacer => KeyShape::NormalSpacer,
|
||||
|
||||
Key::FuncBlank => KeyShape::FuncBlank,
|
||||
Key::FuncSpacer => KeyShape::FuncSpacer,
|
||||
|
||||
Key::Up | Key::Down | Key::Left | Key::Right => KeyShape::Arrow,
|
||||
Key::ArrowBlank => KeyShape::ArrowBlank,
|
||||
Key::ArrowSpacer => KeyShape::ArrowSpacer,
|
||||
|
||||
Key::ArrowRegularBlank => KeyShape::ArrowRegularBlank,
|
||||
Key::ArrowRegularSpacer => KeyShape::ArrowRegularSpacer,
|
||||
|
||||
Key::UpSplit | Key::LeftSplit | Key::DownSplit | Key::RightSplit => {
|
||||
KeyShape::ArrowSplit
|
||||
}
|
||||
Key::ArrowSplitBlank => KeyShape::ArrowSplitBlank,
|
||||
Key::ArrowSplitSpacer => KeyShape::ArrowSplitSpacer,
|
||||
|
||||
Key::RowEndSpacer => KeyShape::RowEndSpacer,
|
||||
|
||||
_ => KeyShape::Normal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Key> for KeyShape {
|
||||
fn from(k: &Key) -> Self {
|
||||
(*k).into()
|
||||
}
|
||||
}
|
||||
170
rog-aura/src/layouts/g513.rs
Normal file
170
rog-aura/src/layouts/g513.rs
Normal file
@@ -0,0 +1,170 @@
|
||||
use super::{KeyLayout, KeyRow};
|
||||
use crate::keys::Key;
|
||||
|
||||
impl KeyLayout {
|
||||
/// Similar to GX502, but not per-key enabled
|
||||
pub fn g513_layout() -> Self {
|
||||
Self {
|
||||
matches: vec!["G513".into()],
|
||||
locale: "US".to_string(),
|
||||
rows: vec![
|
||||
KeyRow::new(
|
||||
0.8,
|
||||
vec![
|
||||
Key::NormalSpacer,
|
||||
Key::FuncSpacer,
|
||||
Key::VolDown,
|
||||
Key::VolUp,
|
||||
Key::MicMute,
|
||||
Key::Fan,
|
||||
Key::Rog,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
0.8,
|
||||
vec![
|
||||
Key::Esc,
|
||||
Key::FuncSpacer,
|
||||
Key::F1,
|
||||
Key::F2,
|
||||
Key::F3,
|
||||
Key::F4,
|
||||
Key::FuncSpacer, // not sure which key to put here
|
||||
Key::F5,
|
||||
Key::F6,
|
||||
Key::F7,
|
||||
Key::F8,
|
||||
Key::FuncSpacer,
|
||||
Key::F9,
|
||||
Key::F10,
|
||||
Key::F11,
|
||||
Key::F12,
|
||||
Key::RowEndSpacer,
|
||||
Key::Del,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::Tilde,
|
||||
Key::N1,
|
||||
Key::N2,
|
||||
Key::N3,
|
||||
Key::N4,
|
||||
Key::N5,
|
||||
Key::N6,
|
||||
Key::N7,
|
||||
Key::N8,
|
||||
Key::N9,
|
||||
Key::N0,
|
||||
Key::Hyphen,
|
||||
Key::Equals,
|
||||
Key::BkSpc,
|
||||
Key::RowEndSpacer,
|
||||
Key::Home,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::Tab,
|
||||
Key::Q,
|
||||
Key::W,
|
||||
Key::E,
|
||||
Key::R,
|
||||
Key::T,
|
||||
Key::Y,
|
||||
Key::U,
|
||||
Key::I,
|
||||
Key::O,
|
||||
Key::P,
|
||||
Key::LBracket,
|
||||
Key::RBracket,
|
||||
Key::BackSlash,
|
||||
Key::RowEndSpacer,
|
||||
Key::PgUp,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::Caps,
|
||||
Key::A,
|
||||
Key::S,
|
||||
Key::D,
|
||||
Key::F,
|
||||
Key::G,
|
||||
Key::H,
|
||||
Key::J,
|
||||
Key::K,
|
||||
Key::L,
|
||||
Key::SemiColon,
|
||||
Key::Quote,
|
||||
Key::Return,
|
||||
Key::RowEndSpacer,
|
||||
Key::PgDn,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::LShift,
|
||||
Key::Z,
|
||||
Key::X,
|
||||
Key::C,
|
||||
Key::V,
|
||||
Key::B,
|
||||
Key::N,
|
||||
Key::M,
|
||||
Key::Comma,
|
||||
Key::Period,
|
||||
Key::FwdSlash,
|
||||
Key::Rshift,
|
||||
Key::RowEndSpacer,
|
||||
Key::End,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::LCtrl,
|
||||
Key::LFn,
|
||||
Key::Meta,
|
||||
Key::LAlt,
|
||||
Key::Space,
|
||||
Key::RAlt,
|
||||
Key::PrtSc,
|
||||
Key::RCtrl,
|
||||
Key::ArrowSpacer,
|
||||
Key::Up,
|
||||
Key::ArrowSpacer,
|
||||
Key::RowEndSpacer,
|
||||
Key::RFn,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::Left,
|
||||
Key::Down,
|
||||
Key::Right,
|
||||
Key::ArrowSpacer,
|
||||
],
|
||||
),
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
156
rog-aura/src/layouts/ga401.rs
Normal file
156
rog-aura/src/layouts/ga401.rs
Normal file
@@ -0,0 +1,156 @@
|
||||
use super::{KeyLayout, KeyRow};
|
||||
use crate::keys::Key;
|
||||
|
||||
impl KeyLayout {
|
||||
pub fn ga401_layout() -> Self {
|
||||
Self {
|
||||
matches: vec!["GA401".into(), "GA402".into()],
|
||||
locale: "US".to_string(),
|
||||
rows: vec![
|
||||
KeyRow::new(
|
||||
0.8,
|
||||
vec![
|
||||
Key::NormalSpacer,
|
||||
Key::FuncSpacer,
|
||||
Key::VolDown,
|
||||
Key::VolUp,
|
||||
Key::MicMute,
|
||||
Key::Rog,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
0.8,
|
||||
vec![
|
||||
Key::Esc,
|
||||
Key::FuncSpacer,
|
||||
Key::F1,
|
||||
Key::F2,
|
||||
Key::F3,
|
||||
Key::F4,
|
||||
Key::FuncSpacer, // not sure which key to put here
|
||||
Key::F5,
|
||||
Key::F6,
|
||||
Key::F7,
|
||||
Key::F8,
|
||||
Key::FuncSpacer,
|
||||
Key::F9,
|
||||
Key::F10,
|
||||
Key::F11,
|
||||
Key::F12,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::Tilde,
|
||||
Key::N1,
|
||||
Key::N2,
|
||||
Key::N3,
|
||||
Key::N4,
|
||||
Key::N5,
|
||||
Key::N6,
|
||||
Key::N7,
|
||||
Key::N8,
|
||||
Key::N9,
|
||||
Key::N0,
|
||||
Key::Hyphen,
|
||||
Key::Equals,
|
||||
Key::BkSpc,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::Tab,
|
||||
Key::Q,
|
||||
Key::W,
|
||||
Key::E,
|
||||
Key::R,
|
||||
Key::T,
|
||||
Key::Y,
|
||||
Key::U,
|
||||
Key::I,
|
||||
Key::O,
|
||||
Key::P,
|
||||
Key::LBracket,
|
||||
Key::RBracket,
|
||||
Key::BackSlash,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::Caps,
|
||||
Key::A,
|
||||
Key::S,
|
||||
Key::D,
|
||||
Key::F,
|
||||
Key::G,
|
||||
Key::H,
|
||||
Key::J,
|
||||
Key::K,
|
||||
Key::L,
|
||||
Key::SemiColon,
|
||||
Key::Quote,
|
||||
Key::Return,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::LShift,
|
||||
Key::Z,
|
||||
Key::X,
|
||||
Key::C,
|
||||
Key::V,
|
||||
Key::B,
|
||||
Key::N,
|
||||
Key::M,
|
||||
Key::Comma,
|
||||
Key::Period,
|
||||
Key::FwdSlash,
|
||||
Key::Rshift,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::LCtrl,
|
||||
Key::LFn,
|
||||
Key::Meta,
|
||||
Key::LAlt,
|
||||
Key::Space,
|
||||
Key::RAlt,
|
||||
Key::PrtSc,
|
||||
Key::RCtrl,
|
||||
Key::ArrowSpacer,
|
||||
Key::Up,
|
||||
Key::ArrowSpacer,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.2,
|
||||
vec![
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::Left,
|
||||
Key::Down,
|
||||
Key::Right,
|
||||
Key::ArrowSpacer,
|
||||
],
|
||||
),
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
178
rog-aura/src/layouts/gx502.rs
Normal file
178
rog-aura/src/layouts/gx502.rs
Normal file
@@ -0,0 +1,178 @@
|
||||
use super::{KeyLayout, KeyRow};
|
||||
use crate::keys::Key;
|
||||
|
||||
impl KeyLayout {
|
||||
pub fn gx502_layout() -> Self {
|
||||
Self {
|
||||
matches: vec!["GX502".into(), "GU502".into()],
|
||||
locale: "US".to_string(),
|
||||
rows: vec![
|
||||
KeyRow::new(
|
||||
0.8,
|
||||
vec![
|
||||
Key::NormalSpacer,
|
||||
Key::FuncSpacer,
|
||||
Key::VolDown,
|
||||
Key::VolUp,
|
||||
Key::MicMute,
|
||||
Key::Rog,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
0.8,
|
||||
vec![
|
||||
Key::Esc,
|
||||
Key::FuncSpacer,
|
||||
Key::F1,
|
||||
Key::F2,
|
||||
Key::F3,
|
||||
Key::F4,
|
||||
Key::FuncSpacer, // not sure which key to put here
|
||||
Key::F5,
|
||||
Key::F6,
|
||||
Key::F7,
|
||||
Key::F8,
|
||||
Key::FuncSpacer,
|
||||
Key::F9,
|
||||
Key::F10,
|
||||
Key::F11,
|
||||
Key::F12,
|
||||
Key::RowEndSpacer,
|
||||
Key::Del,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::Tilde,
|
||||
Key::N1,
|
||||
Key::N2,
|
||||
Key::N3,
|
||||
Key::N4,
|
||||
Key::N5,
|
||||
Key::N6,
|
||||
Key::N7,
|
||||
Key::N8,
|
||||
Key::N9,
|
||||
Key::N0,
|
||||
Key::Hyphen,
|
||||
Key::Equals,
|
||||
Key::BkSpc3_1,
|
||||
Key::BkSpc3_2,
|
||||
Key::BkSpc3_3,
|
||||
Key::RowEndSpacer,
|
||||
Key::Home,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::Tab,
|
||||
Key::Q,
|
||||
Key::W,
|
||||
Key::E,
|
||||
Key::R,
|
||||
Key::T,
|
||||
Key::Y,
|
||||
Key::U,
|
||||
Key::I,
|
||||
Key::O,
|
||||
Key::P,
|
||||
Key::LBracket,
|
||||
Key::RBracket,
|
||||
Key::BackSlash,
|
||||
Key::RowEndSpacer,
|
||||
Key::PgUp,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::Caps,
|
||||
Key::A,
|
||||
Key::S,
|
||||
Key::D,
|
||||
Key::F,
|
||||
Key::G,
|
||||
Key::H,
|
||||
Key::J,
|
||||
Key::K,
|
||||
Key::L,
|
||||
Key::SemiColon,
|
||||
Key::Quote,
|
||||
Key::Return3_1,
|
||||
Key::Return3_2,
|
||||
Key::Return3_3,
|
||||
Key::RowEndSpacer,
|
||||
Key::PgDn,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::LShift,
|
||||
Key::Z,
|
||||
Key::X,
|
||||
Key::C,
|
||||
Key::V,
|
||||
Key::B,
|
||||
Key::N,
|
||||
Key::M,
|
||||
Key::Comma,
|
||||
Key::Period,
|
||||
Key::FwdSlash,
|
||||
Key::Rshift3_1,
|
||||
Key::Rshift3_2,
|
||||
Key::Rshift3_3,
|
||||
Key::RowEndSpacer,
|
||||
Key::End,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::LCtrl,
|
||||
Key::LFn,
|
||||
Key::Meta,
|
||||
Key::LAlt,
|
||||
Key::Space5_1,
|
||||
Key::Space5_2,
|
||||
Key::Space5_3,
|
||||
Key::Space5_4,
|
||||
Key::Space5_5,
|
||||
Key::RAlt,
|
||||
Key::PrtSc,
|
||||
Key::RCtrl,
|
||||
Key::ArrowSpacer,
|
||||
Key::Up,
|
||||
Key::ArrowSpacer,
|
||||
Key::RowEndSpacer,
|
||||
Key::RFn,
|
||||
],
|
||||
),
|
||||
KeyRow::new(
|
||||
1.0,
|
||||
vec![
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::ArrowSpacer,
|
||||
Key::Left,
|
||||
Key::Down,
|
||||
Key::Right,
|
||||
Key::ArrowSpacer,
|
||||
],
|
||||
),
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
105
rog-aura/src/layouts/mod.rs
Normal file
105
rog-aura/src/layouts/mod.rs
Normal file
@@ -0,0 +1,105 @@
|
||||
//! A series of pre-defined layouts. These were mostly used to generate an editable
|
||||
//! config.
|
||||
|
||||
/// Hardcoded layout. Was used to generate a toml default
|
||||
pub mod g513;
|
||||
/// Hardcoded layout. Was used to generate a toml default
|
||||
pub mod ga401;
|
||||
/// Hardcoded layout. Was used to generate a toml default
|
||||
pub mod gx502;
|
||||
|
||||
use crate::{error::Error, keys::Key};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
fs::{self, OpenOptions},
|
||||
io::Read,
|
||||
path::{Path, PathBuf},
|
||||
slice::Iter,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct KeyLayout {
|
||||
/// A series of board names that this layout can be used for. The board names
|
||||
/// stored with the layout can be globbed, e.g, GA401 will match all of the
|
||||
/// GA401I and GA401Q range variants.
|
||||
///
|
||||
/// `/sys/class/dmi/id/board_name`
|
||||
matches: Vec<String>,
|
||||
locale: String,
|
||||
rows: Vec<KeyRow>,
|
||||
}
|
||||
|
||||
impl KeyLayout {
|
||||
pub fn from_file(path: &Path) -> Result<Self, Error> {
|
||||
let mut file = OpenOptions::new().read(true).open(path)?;
|
||||
let mut buf = String::new();
|
||||
let read_len = file.read_to_string(&mut buf)?;
|
||||
if read_len == 0 {
|
||||
return Err(Error::Io(std::io::ErrorKind::InvalidData.into()));
|
||||
} else {
|
||||
return Ok(toml::from_str::<Self>(&buf)?);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn matches(&self, board_name: &str) -> bool {
|
||||
let board = board_name.to_ascii_uppercase();
|
||||
for tmp in self.matches.iter() {
|
||||
if board.contains(tmp.as_str()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub fn rows(&self) -> Iter<KeyRow> {
|
||||
self.rows.iter()
|
||||
}
|
||||
|
||||
pub fn rows_ref(&self) -> &[KeyRow] {
|
||||
&self.rows
|
||||
}
|
||||
|
||||
/// Find a layout matching the provided board name in the provided dir
|
||||
pub fn find_layout(board_name: &str, mut data_path: PathBuf) -> Result<Self, Error> {
|
||||
let mut layout = KeyLayout::ga401_layout(); // default
|
||||
|
||||
data_path.push("layouts");
|
||||
let path = data_path.as_path();
|
||||
for p in fs::read_dir(path).map_err(|e| {
|
||||
println!("{:?}, {e}", path);
|
||||
e
|
||||
})? {
|
||||
let tmp = KeyLayout::from_file(&p?.path()).unwrap();
|
||||
if tmp.matches(board_name) {
|
||||
layout = tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(layout)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct KeyRow {
|
||||
height: f32,
|
||||
row: Vec<Key>,
|
||||
}
|
||||
|
||||
impl KeyRow {
|
||||
pub fn new(height: f32, row: Vec<Key>) -> Self {
|
||||
Self { height, row }
|
||||
}
|
||||
|
||||
pub fn row(&self) -> Iter<Key> {
|
||||
self.row.iter()
|
||||
}
|
||||
|
||||
pub fn row_ref(&self) -> &[Key] {
|
||||
&self.row
|
||||
}
|
||||
|
||||
pub fn height(&self) -> f32 {
|
||||
self.height
|
||||
}
|
||||
}
|
||||
168
rog-aura/src/layouts/old_gx502.rs
Normal file
168
rog-aura/src/layouts/old_gx502.rs
Normal file
@@ -0,0 +1,168 @@
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub struct GX502Layout(Vec<[Key; 17]>);
|
||||
|
||||
impl KeyLayout for GX502Layout {
|
||||
fn get_rows(&self) -> &Vec<[Key; 17]> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GX502Layout {
|
||||
fn default() -> Self {
|
||||
GX502Layout(vec![
|
||||
[
|
||||
Key::NormalSpacer,
|
||||
Key::FuncSpacer,
|
||||
Key::VolDown,
|
||||
Key::VolUp,
|
||||
Key::MicMute,
|
||||
Key::Rog,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
],
|
||||
[
|
||||
Key::Esc,
|
||||
Key::NormalBlank,
|
||||
Key::F1,
|
||||
Key::F2,
|
||||
Key::F3,
|
||||
Key::F4,
|
||||
Key::NormalBlank, // not sure which key to put here
|
||||
Key::F5,
|
||||
Key::F6,
|
||||
Key::F7,
|
||||
Key::F8,
|
||||
Key::NormalBlank,
|
||||
Key::F9,
|
||||
Key::F10,
|
||||
Key::F11,
|
||||
Key::F12,
|
||||
Key::Del,
|
||||
],
|
||||
[
|
||||
Key::Tilde,
|
||||
Key::N1,
|
||||
Key::N2,
|
||||
Key::N3,
|
||||
Key::N4,
|
||||
Key::N5,
|
||||
Key::N6,
|
||||
Key::N7,
|
||||
Key::N8,
|
||||
Key::N9,
|
||||
Key::N0,
|
||||
Key::Hyphen,
|
||||
Key::Equals,
|
||||
Key::BkSpc3_1,
|
||||
Key::BkSpc3_2,
|
||||
Key::BkSpc3_3,
|
||||
Key::Home,
|
||||
],
|
||||
[
|
||||
Key::Tab,
|
||||
Key::Q,
|
||||
Key::W,
|
||||
Key::E,
|
||||
Key::R,
|
||||
Key::T,
|
||||
Key::Y,
|
||||
Key::U,
|
||||
Key::I,
|
||||
Key::O,
|
||||
Key::P,
|
||||
Key::LBracket,
|
||||
Key::RBracket,
|
||||
Key::BackSlash,
|
||||
Key::BackSlash,
|
||||
Key::BackSlash,
|
||||
Key::PgUp,
|
||||
],
|
||||
[
|
||||
Key::Caps,
|
||||
Key::A,
|
||||
Key::S,
|
||||
Key::D,
|
||||
Key::F,
|
||||
Key::G,
|
||||
Key::H,
|
||||
Key::J,
|
||||
Key::K,
|
||||
Key::L,
|
||||
Key::SemiColon,
|
||||
Key::Quote,
|
||||
Key::Quote,
|
||||
Key::Return3_1,
|
||||
Key::Return3_2,
|
||||
Key::Return3_3,
|
||||
Key::PgDn,
|
||||
],
|
||||
[
|
||||
Key::LShift,
|
||||
Key::LShift,
|
||||
Key::Z,
|
||||
Key::X,
|
||||
Key::C,
|
||||
Key::V,
|
||||
Key::B,
|
||||
Key::N,
|
||||
Key::M,
|
||||
Key::Comma,
|
||||
Key::Period,
|
||||
Key::FwdSlash,
|
||||
Key::FwdSlash,
|
||||
Key::Rshift3_1,
|
||||
Key::Rshift3_2,
|
||||
Key::Rshift3_3,
|
||||
Key::End,
|
||||
],
|
||||
[
|
||||
Key::LCtrl,
|
||||
Key::LFn,
|
||||
Key::Meta,
|
||||
Key::LAlt,
|
||||
Key::Space5_1,
|
||||
Key::Space5_2,
|
||||
Key::Space5_3,
|
||||
Key::Space5_4,
|
||||
Key::Space5_5,
|
||||
Key::RAlt,
|
||||
Key::PrtSc,
|
||||
Key::RCtrl,
|
||||
Key::RCtrl,
|
||||
Key::Left,
|
||||
Key::Up,
|
||||
Key::Right,
|
||||
Key::RFn,
|
||||
],
|
||||
[
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::NormalBlank,
|
||||
Key::Left,
|
||||
Key::Down,
|
||||
Key::Right,
|
||||
Key::NormalBlank,
|
||||
],
|
||||
])
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,18 @@ pub use builtin_modes::*;
|
||||
mod per_key_rgb;
|
||||
pub use per_key_rgb::*;
|
||||
|
||||
pub mod usb;
|
||||
mod per_zone;
|
||||
pub use per_zone::*;
|
||||
|
||||
pub mod error;
|
||||
pub mod key_to_str;
|
||||
pub mod keys;
|
||||
pub use key_to_str::*;
|
||||
pub mod layouts;
|
||||
pub mod usb;
|
||||
|
||||
pub const LED_MSG_LEN: usize = 17;
|
||||
|
||||
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
pub const RED: Colour = Colour(0xff, 0x00, 0x00);
|
||||
pub const GREEN: Colour = Colour(0x00, 0xff, 0x00);
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
use crate::keys::Key;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
#[cfg(feature = "dbus")]
|
||||
use zvariant::Type;
|
||||
|
||||
/// Represents the per-key raw USB packets
|
||||
pub type PerKeyRaw = Vec<Vec<u8>>;
|
||||
|
||||
/// A `KeyColourArray` contains all data to change the full set of keyboard
|
||||
/// key colours individually.
|
||||
///
|
||||
@@ -5,16 +13,20 @@
|
||||
/// to the keyboard EC. One row controls one group of keys, these keys are not
|
||||
/// necessarily all on the same row of the keyboard, with some splitting between
|
||||
/// two rows.
|
||||
#[derive(Clone)]
|
||||
pub struct KeyColourArray([[u8; 64]; 11]);
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct KeyColourArray(PerKeyRaw);
|
||||
|
||||
impl Default for KeyColourArray {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyColourArray {
|
||||
pub fn new() -> Self {
|
||||
let mut set = [[0u8; 64]; 11];
|
||||
let mut set = vec![vec![0u8; 64]; 11];
|
||||
// set[0].copy_from_slice(&KeyColourArray::get_init_msg());
|
||||
for (count, row) in set.iter_mut().enumerate() {
|
||||
row[0] = 0x5d; // Report ID
|
||||
row[1] = 0xbc; // Mode = custom??, 0xb3 is builtin
|
||||
@@ -45,16 +57,16 @@ impl KeyColourArray {
|
||||
|
||||
#[inline]
|
||||
pub fn set(&mut self, key: Key, r: u8, g: u8, b: u8) {
|
||||
if let Some((rr, gg, bb)) = self.key(key) {
|
||||
*rr = r;
|
||||
*gg = g;
|
||||
*bb = b;
|
||||
if let Some(c) = self.rgb_for_key(key) {
|
||||
c[0] = r;
|
||||
c[1] = g;
|
||||
c[2] = b;
|
||||
}
|
||||
}
|
||||
|
||||
/// Indexes in to `KeyColourArray` at the correct row and column
|
||||
/// to set a series of three bytes to the chosen R,G,B values
|
||||
pub fn key(&mut self, key: Key) -> Option<(&mut u8, &mut u8, &mut u8)> {
|
||||
pub fn rgb_for_key(&mut self, key: Key) -> Option<&mut [u8]> {
|
||||
// Tuples are indexes in to array
|
||||
let (row, col) = match key {
|
||||
Key::VolDown => (0, 15),
|
||||
@@ -91,9 +103,9 @@ impl KeyColourArray {
|
||||
Key::N0 => (3, 21),
|
||||
Key::Hyphen => (3, 24),
|
||||
Key::Equals => (3, 27),
|
||||
Key::BkSpc1 => (3, 30),
|
||||
Key::BkSpc2 => (3, 33),
|
||||
Key::BkSpc3 => (3, 36),
|
||||
Key::BkSpc3_1 => (3, 30),
|
||||
Key::BkSpc3_2 => (3, 33),
|
||||
Key::BkSpc3_3 => (3, 36),
|
||||
Key::Home => (3, 39),
|
||||
Key::Tab => (3, 54),
|
||||
//
|
||||
@@ -125,11 +137,16 @@ impl KeyColourArray {
|
||||
Key::SemiColon => (5, 51),
|
||||
Key::Quote => (5, 54),
|
||||
//
|
||||
Key::Ret1 => (6, 12),
|
||||
Key::Ret2 => (6, 15),
|
||||
Key::Ret3 => (6, 18),
|
||||
Key::Return => (6, 9),
|
||||
Key::Return3_1 => (6, 12),
|
||||
Key::Return3_2 => (6, 15),
|
||||
Key::Return3_3 => (6, 18),
|
||||
Key::PgDn => (6, 21),
|
||||
Key::LShift => (6, 36),
|
||||
// TODO: Find correct locations
|
||||
Key::LShift3_1 => (6, 36),
|
||||
Key::LShift3_2 => (6, 36),
|
||||
Key::LShift3_3 => (6, 36),
|
||||
Key::Z => (6, 42),
|
||||
Key::X => (6, 45),
|
||||
Key::C => (6, 48),
|
||||
@@ -141,19 +158,21 @@ impl KeyColourArray {
|
||||
Key::Comma => (7, 15),
|
||||
Key::Period => (7, 18),
|
||||
Key::FwdSlash => (7, 21),
|
||||
Key::Rshift1 => (7, 27),
|
||||
Key::Rshift2 => (7, 30),
|
||||
Key::Rshift3 => (7, 33),
|
||||
Key::Rshift => (7, 24),
|
||||
Key::Rshift3_1 => (7, 27),
|
||||
Key::Rshift3_2 => (7, 30),
|
||||
Key::Rshift3_3 => (7, 33),
|
||||
Key::End => (7, 36),
|
||||
Key::LCtrl => (7, 51),
|
||||
Key::LFn => (7, 54),
|
||||
//
|
||||
Key::Meta => (8, 9),
|
||||
Key::LAlt => (8, 12),
|
||||
Key::Space1 => (8, 15),
|
||||
Key::Space2 => (8, 18),
|
||||
Key::Space3 => (8, 21),
|
||||
Key::Space4 => (8, 24),
|
||||
Key::Space5_1 => (8, 15),
|
||||
Key::Space5_2 => (8, 18),
|
||||
Key::Space5_3 => (8, 21),
|
||||
Key::Space5_4 => (8, 24),
|
||||
Key::Space5_5 => (8, 27),
|
||||
Key::RAlt => (8, 30),
|
||||
Key::PrtSc => (8, 33),
|
||||
Key::RCtrl => (8, 36),
|
||||
@@ -164,294 +183,65 @@ impl KeyColourArray {
|
||||
//
|
||||
Key::Down => (10, 9),
|
||||
Key::Right => (10, 12),
|
||||
Key::None => return None,
|
||||
Key::NormalBlank
|
||||
| Key::FuncBlank
|
||||
| Key::NormalSpacer
|
||||
| Key::FuncSpacer
|
||||
| Key::ArrowBlank
|
||||
| Key::ArrowSpacer
|
||||
| Key::UpRegular
|
||||
| Key::DownRegular
|
||||
| Key::LeftRegular
|
||||
| Key::RightRegular
|
||||
| Key::UpSplit
|
||||
| Key::DownSplit
|
||||
| Key::LeftSplit
|
||||
| Key::RightSplit
|
||||
| Key::ArrowRegularBlank
|
||||
| Key::ArrowRegularSpacer
|
||||
| Key::ArrowSplitBlank
|
||||
| Key::ArrowSplitSpacer
|
||||
| Key::RshiftSmall
|
||||
| Key::LCtrlMed
|
||||
| Key::MediaPlay
|
||||
| Key::MediaStop
|
||||
| Key::MediaPrev
|
||||
| Key::MediaNext
|
||||
| Key::Pause
|
||||
| Key::NumLock
|
||||
| Key::Star
|
||||
| Key::NumPadDel
|
||||
| Key::NumPadPlus
|
||||
| Key::NumPadEnter
|
||||
| Key::NumPadPause
|
||||
| Key::NumPadPrtSc
|
||||
| Key::NumPadHome
|
||||
| Key::RCtrlLarge
|
||||
| Key::RowEndSpacer => return None,
|
||||
Key::Fan | Key::Space | Key::BkSpc => return None,
|
||||
};
|
||||
// LOLOLOLOLOLOLOL! Look it's safe okay
|
||||
unsafe {
|
||||
Some((
|
||||
&mut *(&mut self.0[row][col] as *mut u8),
|
||||
&mut *(&mut self.0[row][col + 1] as *mut u8),
|
||||
&mut *(&mut self.0[row][col + 2] as *mut u8),
|
||||
))
|
||||
}
|
||||
|
||||
Some(&mut self.0[row][col..=col + 2])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&self) -> &[[u8; 64]; 11] {
|
||||
pub fn get(&self) -> PerKeyRaw {
|
||||
self.0.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_ref(&self) -> &PerKeyRaw {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum Key {
|
||||
VolUp,
|
||||
VolDown,
|
||||
MicMute,
|
||||
Rog,
|
||||
Esc,
|
||||
F1,
|
||||
F2,
|
||||
F3,
|
||||
F4,
|
||||
F5,
|
||||
F6,
|
||||
F7,
|
||||
F8,
|
||||
F9,
|
||||
F10,
|
||||
F11,
|
||||
F12,
|
||||
Del,
|
||||
Tilde,
|
||||
N1,
|
||||
N2,
|
||||
N3,
|
||||
N4,
|
||||
N5,
|
||||
N6,
|
||||
N7,
|
||||
N8,
|
||||
N9,
|
||||
N0,
|
||||
Hyphen,
|
||||
Equals,
|
||||
BkSpc1,
|
||||
BkSpc2,
|
||||
BkSpc3,
|
||||
Home,
|
||||
Tab,
|
||||
Q,
|
||||
W,
|
||||
E,
|
||||
R,
|
||||
T,
|
||||
Y,
|
||||
U,
|
||||
I,
|
||||
O,
|
||||
P,
|
||||
LBracket,
|
||||
RBracket,
|
||||
BackSlash,
|
||||
PgUp,
|
||||
Caps,
|
||||
A,
|
||||
S,
|
||||
D,
|
||||
F,
|
||||
G,
|
||||
H,
|
||||
J,
|
||||
K,
|
||||
L,
|
||||
SemiColon,
|
||||
Quote,
|
||||
Ret1,
|
||||
Ret2,
|
||||
Ret3,
|
||||
PgDn,
|
||||
LShift,
|
||||
Z,
|
||||
X,
|
||||
C,
|
||||
V,
|
||||
B,
|
||||
N,
|
||||
M,
|
||||
Comma,
|
||||
Period,
|
||||
FwdSlash,
|
||||
Rshift1,
|
||||
Rshift2,
|
||||
Rshift3,
|
||||
End,
|
||||
LCtrl,
|
||||
LFn,
|
||||
Meta,
|
||||
LAlt,
|
||||
Space1,
|
||||
Space2,
|
||||
Space3,
|
||||
Space4,
|
||||
RAlt,
|
||||
PrtSc,
|
||||
RCtrl,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
RFn,
|
||||
None,
|
||||
}
|
||||
|
||||
pub trait KeyLayout {
|
||||
fn get_rows(&self) -> &Vec<[Key; 17]>;
|
||||
}
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub struct GX502Layout(Vec<[Key; 17]>);
|
||||
|
||||
impl KeyLayout for GX502Layout {
|
||||
fn get_rows(&self) -> &Vec<[Key; 17]> {
|
||||
&self.0
|
||||
#[inline]
|
||||
pub fn get_mut(&mut self) -> &mut PerKeyRaw {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GX502Layout {
|
||||
fn default() -> Self {
|
||||
GX502Layout(vec![
|
||||
[
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::VolDown,
|
||||
Key::VolUp,
|
||||
Key::MicMute,
|
||||
Key::Rog,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
],
|
||||
[
|
||||
Key::Esc,
|
||||
Key::None,
|
||||
Key::F1,
|
||||
Key::F2,
|
||||
Key::F3,
|
||||
Key::F4,
|
||||
Key::None, // not sure which key to put here
|
||||
Key::F5,
|
||||
Key::F6,
|
||||
Key::F7,
|
||||
Key::F8,
|
||||
Key::F9,
|
||||
Key::F9,
|
||||
Key::F10,
|
||||
Key::F11,
|
||||
Key::F12,
|
||||
Key::Del,
|
||||
],
|
||||
[
|
||||
Key::Tilde,
|
||||
Key::N1,
|
||||
Key::N2,
|
||||
Key::N3,
|
||||
Key::N4,
|
||||
Key::N5,
|
||||
Key::N6,
|
||||
Key::N7,
|
||||
Key::N8,
|
||||
Key::N9,
|
||||
Key::N0,
|
||||
Key::Hyphen,
|
||||
Key::Equals,
|
||||
Key::BkSpc1,
|
||||
Key::BkSpc2,
|
||||
Key::BkSpc3,
|
||||
Key::Home,
|
||||
],
|
||||
[
|
||||
Key::Tab,
|
||||
Key::Q,
|
||||
Key::W,
|
||||
Key::E,
|
||||
Key::R,
|
||||
Key::T,
|
||||
Key::Y,
|
||||
Key::U,
|
||||
Key::I,
|
||||
Key::O,
|
||||
Key::P,
|
||||
Key::LBracket,
|
||||
Key::RBracket,
|
||||
Key::BackSlash,
|
||||
Key::BackSlash,
|
||||
Key::BackSlash,
|
||||
Key::PgUp,
|
||||
],
|
||||
[
|
||||
Key::Caps,
|
||||
Key::A,
|
||||
Key::S,
|
||||
Key::D,
|
||||
Key::F,
|
||||
Key::G,
|
||||
Key::H,
|
||||
Key::J,
|
||||
Key::K,
|
||||
Key::L,
|
||||
Key::SemiColon,
|
||||
Key::Quote,
|
||||
Key::Quote,
|
||||
Key::Ret1,
|
||||
Key::Ret2,
|
||||
Key::Ret3,
|
||||
Key::PgDn,
|
||||
],
|
||||
[
|
||||
Key::LShift,
|
||||
Key::LShift,
|
||||
Key::Z,
|
||||
Key::X,
|
||||
Key::C,
|
||||
Key::V,
|
||||
Key::B,
|
||||
Key::N,
|
||||
Key::M,
|
||||
Key::Comma,
|
||||
Key::Period,
|
||||
Key::FwdSlash,
|
||||
Key::FwdSlash,
|
||||
Key::Rshift1,
|
||||
Key::Rshift2,
|
||||
Key::Rshift3,
|
||||
Key::End,
|
||||
],
|
||||
[
|
||||
Key::LCtrl,
|
||||
Key::LFn,
|
||||
Key::Meta,
|
||||
Key::LAlt,
|
||||
Key::Space1,
|
||||
Key::Space2,
|
||||
Key::Space3,
|
||||
Key::Space4,
|
||||
Key::Space4,
|
||||
Key::RAlt,
|
||||
Key::PrtSc,
|
||||
Key::RCtrl,
|
||||
Key::RCtrl,
|
||||
Key::Left,
|
||||
Key::Up,
|
||||
Key::Right,
|
||||
Key::RFn,
|
||||
],
|
||||
[
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::None,
|
||||
Key::Left,
|
||||
Key::Down,
|
||||
Key::Right,
|
||||
Key::None,
|
||||
],
|
||||
])
|
||||
impl From<KeyColourArray> for PerKeyRaw {
|
||||
fn from(k: KeyColourArray) -> Self {
|
||||
k.0
|
||||
}
|
||||
}
|
||||
|
||||
124
rog-aura/src/per_zone.rs
Normal file
124
rog-aura/src/per_zone.rs
Normal file
@@ -0,0 +1,124 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
#[cfg(feature = "dbus")]
|
||||
use zvariant::Type;
|
||||
|
||||
/// Represents the zoned raw USB packets
|
||||
pub type ZonedRaw = Vec<u8>;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
|
||||
pub enum PerZone {
|
||||
None,
|
||||
KeyboardLeft,
|
||||
KeyboardCenterLeft,
|
||||
KeyboardCenterRight,
|
||||
KeyboardRight,
|
||||
LightbarRight,
|
||||
LightbarRightCorner,
|
||||
LightbarRightBottom,
|
||||
LightbarLeftBottom,
|
||||
LightbarLeftCorner,
|
||||
LightbarLeft,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct ZonedColourArray(ZonedRaw);
|
||||
|
||||
impl Default for ZonedColourArray {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl ZonedColourArray {
|
||||
pub fn new() -> Self {
|
||||
let mut pkt = vec![0u8; 64];
|
||||
pkt[0] = 0x5d; // Report ID
|
||||
pkt[1] = 0xbc; // Mode = custom??, 0xb3 is builtin
|
||||
pkt[2] = 0x01;
|
||||
pkt[3] = 0x01; // ??
|
||||
pkt[4] = 0x04; // ??, 4,5,6 are normally RGB for builtin mode colours
|
||||
ZonedColourArray(pkt)
|
||||
}
|
||||
|
||||
pub fn rgb_for_zone(&mut self, zone: PerZone) -> &mut [u8] {
|
||||
match zone {
|
||||
PerZone::None => &mut self.0[9..=11],
|
||||
PerZone::KeyboardLeft => &mut self.0[9..=11],
|
||||
PerZone::KeyboardCenterLeft => &mut self.0[12..=14],
|
||||
PerZone::KeyboardCenterRight => &mut self.0[15..=17],
|
||||
PerZone::KeyboardRight => &mut self.0[18..=20],
|
||||
// Two sections missing here?
|
||||
PerZone::LightbarRight => &mut self.0[27..=29],
|
||||
PerZone::LightbarRightCorner => &mut self.0[30..=32],
|
||||
PerZone::LightbarRightBottom => &mut self.0[33..=35],
|
||||
PerZone::LightbarLeftBottom => &mut self.0[36..=38],
|
||||
PerZone::LightbarLeftCorner => &mut self.0[39..=41],
|
||||
PerZone::LightbarLeft => &mut self.0[42..=44],
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&self) -> ZonedRaw {
|
||||
self.0.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_ref(&self) -> &ZonedRaw {
|
||||
&self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_mut(&mut self) -> &mut ZonedRaw {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ZonedColourArray> for ZonedRaw {
|
||||
fn from(k: ZonedColourArray) -> Self {
|
||||
k.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{PerZone, ZonedColourArray, ZonedRaw};
|
||||
|
||||
macro_rules! colour_check {
|
||||
($zone:expr, $pkt_idx_start:expr) => {
|
||||
let mut zone = ZonedColourArray::new();
|
||||
let c = zone.rgb_for_zone($zone);
|
||||
c[0] = 255;
|
||||
c[1] = 255;
|
||||
c[2] = 255;
|
||||
|
||||
let pkt: ZonedRaw = zone.get();
|
||||
assert_eq!(pkt[$pkt_idx_start], 0xff);
|
||||
assert_eq!(pkt[$pkt_idx_start + 1], 0xff);
|
||||
assert_eq!(pkt[$pkt_idx_start + 2], 0xff);
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zone_to_packet_check() {
|
||||
let zone = ZonedColourArray::new();
|
||||
let pkt: ZonedRaw = zone.into();
|
||||
assert_eq!(pkt[0], 0x5d);
|
||||
assert_eq!(pkt[1], 0xbc);
|
||||
assert_eq!(pkt[2], 0x01);
|
||||
assert_eq!(pkt[3], 0x01);
|
||||
assert_eq!(pkt[4], 0x04);
|
||||
|
||||
colour_check!(PerZone::KeyboardLeft, 9);
|
||||
colour_check!(PerZone::KeyboardCenterLeft, 12);
|
||||
colour_check!(PerZone::KeyboardCenterRight, 15);
|
||||
colour_check!(PerZone::KeyboardRight, 18);
|
||||
|
||||
colour_check!(PerZone::LightbarRight, 27);
|
||||
colour_check!(PerZone::LightbarRightCorner, 30);
|
||||
colour_check!(PerZone::LightbarRightBottom, 33);
|
||||
colour_check!(PerZone::LightbarLeftBottom, 36);
|
||||
colour_check!(PerZone::LightbarLeftCorner, 39);
|
||||
colour_check!(PerZone::LightbarLeft, 42);
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
/// All the possible AniMe actions that can be used. The enum is intended to be
|
||||
/// used in a array allowing the user to cycle through a series of actions.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum ActionData {
|
||||
Static,
|
||||
}
|
||||
|
||||
/// An optimised precomputed set of actions that the user can cycle through
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
pub struct Sequences(Vec<ActionData>);
|
||||
|
||||
impl Sequences {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
Self(Vec::new())
|
||||
}
|
||||
|
||||
/// Use a base `AnimeAction` to generate the precomputed data and insert in to
|
||||
/// the run buffer
|
||||
#[inline]
|
||||
pub fn insert(&mut self, _index: usize) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove an item at this position from the run buffer. If the `index` supplied
|
||||
/// is not in range then `None` is returned, otherwise the `ActionData` at that location
|
||||
/// is yeeted and returned.
|
||||
#[inline]
|
||||
pub fn remove_item(&mut self, index: usize) -> Option<ActionData> {
|
||||
if index < self.0.len() {
|
||||
return Some(self.0.remove(index));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> ActionIterator {
|
||||
ActionIterator {
|
||||
actions: self,
|
||||
next_idx: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Iteractor helper for iterating over all the actions in `Sequences`
|
||||
pub struct ActionIterator<'a> {
|
||||
actions: &'a Sequences,
|
||||
next_idx: usize,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for ActionIterator<'a> {
|
||||
type Item = &'a ActionData;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<&'a ActionData> {
|
||||
if self.next_idx == self.actions.0.len() {
|
||||
self.next_idx = 0;
|
||||
return None;
|
||||
}
|
||||
|
||||
let current = self.next_idx;
|
||||
self.next_idx += 1;
|
||||
|
||||
Some(&self.actions.0[current])
|
||||
}
|
||||
}
|
||||
255
rog-aura/src/sequencer/effects.rs
Normal file
255
rog-aura/src/sequencer/effects.rs
Normal file
@@ -0,0 +1,255 @@
|
||||
use crate::{layouts::KeyLayout, p_random, Colour, EffectState, LedType, Speed};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
macro_rules! effect_state_impl {
|
||||
() => {
|
||||
fn get_colour(&self) -> Colour {
|
||||
self.colour
|
||||
}
|
||||
|
||||
fn get_led_type(&self) -> LedType {
|
||||
self.led_type.clone()
|
||||
}
|
||||
|
||||
/// Change the led type
|
||||
fn set_led_type(&mut self, led_type: LedType) {
|
||||
self.led_type = led_type;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! effect_impl {
|
||||
($($effect:ident),*) => {
|
||||
impl Effect {
|
||||
/// Get the type of LED set
|
||||
pub fn get_led_type(&self) -> LedType {
|
||||
match self {
|
||||
$(Effect::$effect(c) => c.get_led_type(),)*
|
||||
}
|
||||
}
|
||||
|
||||
/// Change the led type
|
||||
pub fn set_led_type(&mut self, led_type: LedType) {
|
||||
match self {
|
||||
$(Effect::$effect(c) => c.set_led_type(led_type),)*
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculate the next state of the effect
|
||||
pub fn next_state(&mut self, layout: &KeyLayout) {
|
||||
match self {
|
||||
$(Effect::$effect(c) => c.next_colour_state(layout),)*
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the calculated colour
|
||||
pub fn get_colour(&self) -> Colour {
|
||||
match self {
|
||||
$(Effect::$effect(c) => c.get_colour(),)*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub enum Effect {
|
||||
Static(Static),
|
||||
Breathe(Breathe),
|
||||
Flicker(Flicker),
|
||||
}
|
||||
|
||||
impl Default for Effect {
|
||||
fn default() -> Self {
|
||||
Self::Static(Static::new(LedType::default(), Colour::default()))
|
||||
}
|
||||
}
|
||||
|
||||
effect_impl!(Static, Breathe, Flicker);
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Static {
|
||||
led_type: LedType,
|
||||
/// The starting colour
|
||||
colour: Colour,
|
||||
}
|
||||
|
||||
impl Static {
|
||||
pub fn new(led_type: LedType, colour: Colour) -> Self {
|
||||
Self { led_type, colour }
|
||||
}
|
||||
}
|
||||
|
||||
impl EffectState for Static {
|
||||
fn next_colour_state(&mut self, _layout: &KeyLayout) {}
|
||||
|
||||
effect_state_impl!();
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Breathe {
|
||||
led_type: LedType,
|
||||
/// The starting colour
|
||||
start_colour1: Colour,
|
||||
/// The secondary starting colour
|
||||
start_colour2: Colour,
|
||||
/// The speed at which to cycle between the colours
|
||||
speed: Speed,
|
||||
/// Temporary data to help keep state
|
||||
#[serde(skip)]
|
||||
colour: Colour,
|
||||
#[serde(skip)]
|
||||
count_flipped: bool,
|
||||
#[serde(skip)]
|
||||
use_colour1: bool,
|
||||
}
|
||||
|
||||
impl Breathe {
|
||||
pub fn new(led_type: LedType, colour1: Colour, colour2: Colour, speed: Speed) -> Self {
|
||||
Self {
|
||||
led_type,
|
||||
start_colour1: colour1,
|
||||
start_colour2: colour2,
|
||||
speed,
|
||||
colour: colour1,
|
||||
count_flipped: false,
|
||||
use_colour1: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EffectState for Breathe {
|
||||
fn next_colour_state(&mut self, _layout: &KeyLayout) {
|
||||
let Self {
|
||||
start_colour1: colour1,
|
||||
start_colour2: colour2,
|
||||
speed,
|
||||
colour: colour_actual,
|
||||
count_flipped: flipped,
|
||||
use_colour1,
|
||||
..
|
||||
} = self;
|
||||
|
||||
let speed = 4 - <u8>::from(*speed);
|
||||
|
||||
let colour: &mut Colour;
|
||||
if *colour_actual == Colour(0, 0, 0) {
|
||||
*use_colour1 = !*use_colour1;
|
||||
}
|
||||
|
||||
if !*use_colour1 {
|
||||
colour = colour2;
|
||||
} else {
|
||||
colour = colour1;
|
||||
}
|
||||
|
||||
let r1_scale = colour.0 / speed / 2;
|
||||
let g1_scale = colour.1 / speed / 2;
|
||||
let b1_scale = colour.2 / speed / 2;
|
||||
|
||||
if *colour_actual == Colour(0, 0, 0) {
|
||||
*flipped = true;
|
||||
} else if colour_actual >= colour {
|
||||
*flipped = false;
|
||||
}
|
||||
|
||||
if !*flipped {
|
||||
colour_actual.0 = colour_actual.0.saturating_sub(r1_scale);
|
||||
colour_actual.1 = colour_actual.1.saturating_sub(g1_scale);
|
||||
colour_actual.2 = colour_actual.2.saturating_sub(b1_scale);
|
||||
} else {
|
||||
colour_actual.0 = colour_actual.0.saturating_add(r1_scale);
|
||||
colour_actual.1 = colour_actual.1.saturating_add(g1_scale);
|
||||
colour_actual.2 = colour_actual.2.saturating_add(b1_scale);
|
||||
}
|
||||
}
|
||||
|
||||
effect_state_impl!();
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Flicker {
|
||||
led_type: LedType,
|
||||
start_colour: Colour,
|
||||
max_percentage: u8,
|
||||
min_percentage: u8,
|
||||
#[serde(skip)]
|
||||
count: u8,
|
||||
#[serde(skip)]
|
||||
colour: Colour,
|
||||
}
|
||||
|
||||
impl Flicker {
|
||||
pub fn new(led_type: LedType, colour: Colour, max_percentage: u8, min_percentage: u8) -> Self {
|
||||
Self {
|
||||
led_type,
|
||||
colour,
|
||||
count: 4,
|
||||
max_percentage,
|
||||
min_percentage,
|
||||
start_colour: colour,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EffectState for Flicker {
|
||||
fn next_colour_state(&mut self, _layout: &KeyLayout) {
|
||||
let Self {
|
||||
max_percentage,
|
||||
min_percentage,
|
||||
colour,
|
||||
start_colour,
|
||||
..
|
||||
} = self;
|
||||
|
||||
if self.count == 0 {
|
||||
self.count = 4;
|
||||
}
|
||||
self.count -= 1;
|
||||
if self.count != 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: make a "percentage" method on Colour.
|
||||
let max_light = Colour(
|
||||
(start_colour.0 as f32 / 100.0 * *max_percentage as f32) as u8,
|
||||
(start_colour.1 as f32 / 100.0 * *max_percentage as f32) as u8,
|
||||
(start_colour.2 as f32 / 100.0 * *max_percentage as f32) as u8,
|
||||
);
|
||||
// min light is a percentage of the set colour
|
||||
let min_light = Colour(
|
||||
(start_colour.0 as f32 / 100.0 * *min_percentage as f32) as u8,
|
||||
(start_colour.1 as f32 / 100.0 * *min_percentage as f32) as u8,
|
||||
(start_colour.2 as f32 / 100.0 * *min_percentage as f32) as u8,
|
||||
);
|
||||
|
||||
// Convert the 255 to percentage
|
||||
let amount = (p_random() & 7) as f32 * 8.0;
|
||||
|
||||
let set_colour = |colour: &mut u8, max: f32, min: f32| {
|
||||
let pc = amount / max * 100.0;
|
||||
let min_amount = pc * min / 100.0; // percentage of min colour
|
||||
let max_amount = pc * max / 100.0; // percentage of max colour
|
||||
if *colour as f32 - min_amount < min {
|
||||
*colour = min as u8;
|
||||
} else {
|
||||
*colour = (max - max_amount) as u8;
|
||||
}
|
||||
};
|
||||
set_colour(&mut colour.0, max_light.0 as f32, min_light.0 as f32);
|
||||
set_colour(&mut colour.1, max_light.1 as f32, min_light.1 as f32);
|
||||
set_colour(&mut colour.2, max_light.2 as f32, min_light.2 as f32);
|
||||
|
||||
self.count = 4;
|
||||
}
|
||||
|
||||
effect_state_impl!();
|
||||
}
|
||||
219
rog-aura/src/sequencer/mod.rs
Normal file
219
rog-aura/src/sequencer/mod.rs
Normal file
@@ -0,0 +1,219 @@
|
||||
mod effects;
|
||||
pub use effects::*;
|
||||
|
||||
use crate::{
|
||||
keys::Key, layouts::KeyLayout, Colour, KeyColourArray, PerKeyRaw, PerZone, ZonedColourArray,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
// static mut RNDINDEX: usize = 0;
|
||||
static mut PRNDINDEX: usize = 0;
|
||||
|
||||
/// Pseudo random table ripped straight out of Room4Doom
|
||||
pub const RNDTABLE: [i32; 256] = [
|
||||
0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66, 74, 21, 211, 47, 80, 242, 154,
|
||||
27, 205, 128, 161, 89, 77, 36, 95, 110, 85, 48, 212, 140, 211, 249, 22, 79, 200, 50, 28, 188,
|
||||
52, 140, 202, 120, 68, 145, 62, 70, 184, 190, 91, 197, 152, 224, 149, 104, 25, 178, 252, 182,
|
||||
202, 182, 141, 197, 4, 81, 181, 242, 145, 42, 39, 227, 156, 198, 225, 193, 219, 93, 122, 175,
|
||||
249, 0, 175, 143, 70, 239, 46, 246, 163, 53, 163, 109, 168, 135, 2, 235, 25, 92, 20, 145, 138,
|
||||
77, 69, 166, 78, 176, 173, 212, 166, 113, 94, 161, 41, 50, 239, 49, 111, 164, 70, 60, 2, 37,
|
||||
171, 75, 136, 156, 11, 56, 42, 146, 138, 229, 73, 146, 77, 61, 98, 196, 135, 106, 63, 197, 195,
|
||||
86, 96, 203, 113, 101, 170, 247, 181, 113, 80, 250, 108, 7, 255, 237, 129, 226, 79, 107, 112,
|
||||
166, 103, 241, 24, 223, 239, 120, 198, 58, 60, 82, 128, 3, 184, 66, 143, 224, 145, 224, 81,
|
||||
206, 163, 45, 63, 90, 168, 114, 59, 33, 159, 95, 28, 139, 123, 98, 125, 196, 15, 70, 194, 253,
|
||||
54, 14, 109, 226, 71, 17, 161, 93, 186, 87, 244, 138, 20, 52, 123, 251, 26, 36, 17, 46, 52,
|
||||
231, 232, 76, 31, 221, 84, 37, 216, 165, 212, 106, 197, 242, 98, 43, 39, 175, 254, 145, 190,
|
||||
84, 118, 222, 187, 136, 120, 163, 236, 249,
|
||||
];
|
||||
|
||||
pub fn p_random() -> i32 {
|
||||
unsafe {
|
||||
PRNDINDEX = (PRNDINDEX + 1) & 0xFF;
|
||||
RNDTABLE[PRNDINDEX]
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait EffectState {
|
||||
/// Calculate the next colour state
|
||||
fn next_colour_state(&mut self, _layout: &KeyLayout);
|
||||
|
||||
/// Return the resulting colour. Implementers should store the colour to return it.
|
||||
fn get_colour(&self) -> Colour;
|
||||
|
||||
fn get_led_type(&self) -> LedType;
|
||||
|
||||
fn set_led_type(&mut self, led_type: LedType);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub enum LedType {
|
||||
Key(Key),
|
||||
Zone(PerZone),
|
||||
}
|
||||
|
||||
impl Default for LedType {
|
||||
fn default() -> Self {
|
||||
Self::Zone(PerZone::None)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Default)]
|
||||
pub struct Sequences(Vec<Effect>);
|
||||
|
||||
impl Sequences {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
Self(Vec::new())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn push(&mut self, action: Effect) {
|
||||
self.0.push(action);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn insert(&mut self, index: usize, action: Effect) {
|
||||
self.0.insert(index, action);
|
||||
}
|
||||
|
||||
/// Remove an item at this position from the run buffer. If the `index` supplied
|
||||
/// is not in range then `None` is returned, otherwise the `ActionData` at that location
|
||||
/// is yeeted and returned.
|
||||
#[inline]
|
||||
pub fn remove_item(&mut self, index: usize) -> Option<Effect> {
|
||||
if index < self.0.len() {
|
||||
return Some(self.0.remove(index));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn next_state(&mut self, layout: &KeyLayout) {
|
||||
for effect in self.0.iter_mut() {
|
||||
effect.next_state(layout);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_packets(&self) -> PerKeyRaw {
|
||||
let mut keys = KeyColourArray::new();
|
||||
let mut zones = ZonedColourArray::new();
|
||||
let mut is_per_key = false;
|
||||
for effect in self.0.iter() {
|
||||
match effect.get_led_type() {
|
||||
LedType::Key(key) => {
|
||||
is_per_key = true;
|
||||
if let Some(rgb) = keys.rgb_for_key(key) {
|
||||
let c = effect.get_colour();
|
||||
rgb[0] = c.0;
|
||||
rgb[1] = c.1;
|
||||
rgb[2] = c.2;
|
||||
}
|
||||
}
|
||||
LedType::Zone(z) => {
|
||||
let rgb = zones.rgb_for_zone(z);
|
||||
let c = effect.get_colour();
|
||||
rgb[0] = c.0;
|
||||
rgb[1] = c.1;
|
||||
rgb[2] = c.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if is_per_key {
|
||||
keys.into()
|
||||
} else {
|
||||
vec![zones.into()]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
keys::Key, layouts::KeyLayout, Breathe, Colour, Effect, Flicker, LedType, Sequences, Speed,
|
||||
Static,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn single_key_next_state_then_create() {
|
||||
let layout = KeyLayout::gx502_layout();
|
||||
let mut seq = Sequences::new();
|
||||
seq.0.push(Effect::Static(Static::new(
|
||||
LedType::Key(Key::F),
|
||||
Colour(255, 127, 0),
|
||||
)));
|
||||
|
||||
seq.next_state(&layout);
|
||||
let packets = seq.create_packets();
|
||||
|
||||
assert_eq!(packets[0][0], 0x5d);
|
||||
assert_eq!(packets[5][33], 255);
|
||||
assert_eq!(packets[5][34], 127);
|
||||
assert_eq!(packets[5][35], 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cycle_breathe() {
|
||||
let layout = KeyLayout::gx502_layout();
|
||||
let mut seq = Sequences::new();
|
||||
seq.0.push(Effect::Breathe(Breathe::new(
|
||||
LedType::Key(Key::F),
|
||||
Colour(255, 127, 0),
|
||||
Colour(127, 0, 255),
|
||||
Speed::Med,
|
||||
)));
|
||||
|
||||
let s = serde_json::to_string_pretty(&seq).unwrap();
|
||||
println!("{s}");
|
||||
|
||||
seq.next_state(&layout);
|
||||
let packets = seq.create_packets();
|
||||
|
||||
assert_eq!(packets[0][0], 0x5d);
|
||||
assert_eq!(packets[5][33], 213);
|
||||
assert_eq!(packets[5][34], 106);
|
||||
assert_eq!(packets[5][35], 0);
|
||||
|
||||
// dbg!(&packets[5][33..=35]);
|
||||
|
||||
seq.next_state(&layout);
|
||||
let packets = seq.create_packets();
|
||||
|
||||
assert_eq!(packets[0][0], 0x5d);
|
||||
assert_eq!(packets[5][33], 171);
|
||||
assert_eq!(packets[5][34], 85);
|
||||
assert_eq!(packets[5][35], 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cycle_flicker() {
|
||||
let layout = KeyLayout::gx502_layout();
|
||||
let mut seq = Sequences::new();
|
||||
seq.0.push(Effect::Flicker(Flicker::new(
|
||||
LedType::Key(Key::F),
|
||||
Colour(255, 127, 80),
|
||||
100,
|
||||
10,
|
||||
)));
|
||||
|
||||
seq.next_state(&layout);
|
||||
let packets = seq.create_packets();
|
||||
|
||||
assert_eq!(packets[0][0], 0x5d);
|
||||
assert_eq!(packets[5][33], 255);
|
||||
assert_eq!(packets[5][34], 127);
|
||||
assert_eq!(packets[5][35], 80);
|
||||
|
||||
// The random is deterministic
|
||||
seq.next_state(&layout);
|
||||
seq.next_state(&layout);
|
||||
seq.next_state(&layout);
|
||||
seq.next_state(&layout);
|
||||
seq.next_state(&layout);
|
||||
seq.next_state(&layout);
|
||||
seq.next_state(&layout);
|
||||
|
||||
let packets = seq.create_packets();
|
||||
assert_eq!(packets[5][33], 215);
|
||||
assert_eq!(packets[5][34], 87);
|
||||
assert_eq!(packets[5][35], 40);
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,60 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Clone, Debug, PartialEq, PartialOrd, Serialize, Deserialize, Default)]
|
||||
pub enum AuraDevice {
|
||||
Tuf,
|
||||
X1854,
|
||||
X1869,
|
||||
X1866,
|
||||
#[default]
|
||||
X19B6,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl From<&str> for AuraDevice {
|
||||
fn from(s: &str) -> Self {
|
||||
match s.to_lowercase().as_str() {
|
||||
"tuf" => AuraDevice::Tuf,
|
||||
"1866" => AuraDevice::X1866,
|
||||
"1869" => AuraDevice::X1869,
|
||||
"1854" => AuraDevice::X1854,
|
||||
"19b6" => AuraDevice::X19B6,
|
||||
"0x1866" => AuraDevice::X1866,
|
||||
"0x1869" => AuraDevice::X1869,
|
||||
"0x1854" => AuraDevice::X1854,
|
||||
"0x19b6" => AuraDevice::X19B6,
|
||||
_ => AuraDevice::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This struct is intended as a helper to pass args to generic dbus interface
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct AuraPowerDev {
|
||||
pub tuf: Vec<AuraDevTuf>,
|
||||
pub x1866: Vec<AuraDev1866>,
|
||||
pub x19b6: Vec<AuraDev19b6>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)]
|
||||
#[repr(u32)]
|
||||
pub enum AuraDevTuf {
|
||||
Boot,
|
||||
Awake,
|
||||
Sleep,
|
||||
Keyboard,
|
||||
}
|
||||
|
||||
impl AuraDevTuf {
|
||||
pub const fn dev_id() -> &'static str {
|
||||
"tuf"
|
||||
}
|
||||
}
|
||||
|
||||
/// # Bits for older 0x1866 keyboard model
|
||||
///
|
||||
/// Keybord and Lightbar require Awake, Boot and Sleep apply to both
|
||||
@@ -122,7 +168,7 @@ impl BitAnd<AuraDev1866> for AuraDev1866 {
|
||||
///
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)]
|
||||
#[repr(u16)]
|
||||
#[repr(u32)]
|
||||
pub enum AuraDev19b6 {
|
||||
BootLogo = 1,
|
||||
BootKeyb = 1 << 1,
|
||||
@@ -132,25 +178,33 @@ pub enum AuraDev19b6 {
|
||||
SleepKeyb = 1 << 5,
|
||||
ShutdownLogo = 1 << 6,
|
||||
ShutdownKeyb = 1 << 7,
|
||||
AwakeBar = 1 << 7 + 2,
|
||||
BootBar = 1 << 7 + 3,
|
||||
BootBar = 1 << 7 + 2,
|
||||
AwakeBar = 1 << 7 + 3,
|
||||
SleepBar = 1 << 7 + 4,
|
||||
ShutdownBar = 1 << 7 + 5,
|
||||
BootLid = 1 << 15 + 1,
|
||||
AwakeLid = 1 << 15 + 2,
|
||||
SleepLid = 1 << 15 + 3,
|
||||
ShutdownLid = 1 << 15 + 4,
|
||||
}
|
||||
|
||||
impl From<AuraDev19b6> for u16 {
|
||||
impl From<AuraDev19b6> for u32 {
|
||||
fn from(a: AuraDev19b6) -> Self {
|
||||
a as u16
|
||||
a as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl AuraDev19b6 {
|
||||
pub fn to_bytes(control: &[Self]) -> [u8; 3] {
|
||||
let mut a: u16 = 0;
|
||||
let mut a: u32 = 0;
|
||||
control.iter().for_each(|n| {
|
||||
a |= *n as u16;
|
||||
a |= *n as u32;
|
||||
});
|
||||
[(a & 0xff) as u8, ((a & 0xff00) >> 8) as u8, 0x00]
|
||||
[
|
||||
(a & 0xff) as u8,
|
||||
((a & 0xff00) >> 8) as u8,
|
||||
((a & 0xff0000) >> 16) as u8,
|
||||
]
|
||||
}
|
||||
|
||||
pub const fn dev_id() -> &'static str {
|
||||
@@ -229,7 +283,7 @@ mod tests {
|
||||
AuraDev19b6::ShutdownKeyb,
|
||||
];
|
||||
let bytes = AuraDev19b6::to_bytes(&byte1);
|
||||
println!("{:08b}", bytes[0]);
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes[0], 0xff);
|
||||
|
||||
//
|
||||
@@ -290,23 +344,73 @@ mod tests {
|
||||
assert_eq!(bytes[0], 0xdf);
|
||||
|
||||
let byte2 = [
|
||||
AuraDev19b6::AwakeBar,
|
||||
AuraDev19b6::BootBar,
|
||||
AuraDev19b6::AwakeBar,
|
||||
AuraDev19b6::SleepBar,
|
||||
AuraDev19b6::ShutdownBar,
|
||||
];
|
||||
let bytes = AuraDev19b6::to_bytes(&byte2);
|
||||
println!("{:08b}", bytes[1]);
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes[1], 0x1e);
|
||||
|
||||
let byte2 = [
|
||||
AuraDev19b6::AwakeBar,
|
||||
AuraDev19b6::BootBar,
|
||||
AuraDev19b6::AwakeBar,
|
||||
// AuraControl::SleepBar,
|
||||
AuraDev19b6::ShutdownBar,
|
||||
];
|
||||
let bytes = AuraDev19b6::to_bytes(&byte2);
|
||||
println!("{:08b}", bytes[1]);
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes[1], 0x16);
|
||||
|
||||
let byte3 = [
|
||||
AuraDev19b6::AwakeLid,
|
||||
AuraDev19b6::BootLid,
|
||||
AuraDev19b6::SleepLid,
|
||||
AuraDev19b6::ShutdownLid,
|
||||
];
|
||||
let bytes = AuraDev19b6::to_bytes(&byte3);
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes[2], 0x0f);
|
||||
|
||||
let byte3 = [
|
||||
//AuraDev19b6::AwakeLid,
|
||||
AuraDev19b6::BootLid,
|
||||
AuraDev19b6::SleepLid,
|
||||
AuraDev19b6::ShutdownLid,
|
||||
];
|
||||
let bytes = AuraDev19b6::to_bytes(&byte3);
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes[2], 0x0d);
|
||||
|
||||
let byte3 = [
|
||||
AuraDev19b6::AwakeLid,
|
||||
AuraDev19b6::BootLid,
|
||||
// AuraControl::SleepLid,
|
||||
AuraDev19b6::ShutdownLid,
|
||||
];
|
||||
let bytes = AuraDev19b6::to_bytes(&byte3);
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes[2], 0x0b);
|
||||
|
||||
let byte3 = [
|
||||
AuraDev19b6::AwakeLid,
|
||||
AuraDev19b6::BootLid,
|
||||
AuraDev19b6::SleepLid,
|
||||
//AuraDev19b6::ShutdownLid,
|
||||
];
|
||||
let bytes = AuraDev19b6::to_bytes(&byte3);
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes[2], 0x07);
|
||||
|
||||
let byte3 = [
|
||||
AuraDev19b6::AwakeLid,
|
||||
//AuraDev19b6::BootLid,
|
||||
AuraDev19b6::SleepLid,
|
||||
//AuraDev19b6::ShutdownLid,
|
||||
];
|
||||
let bytes = AuraDev19b6::to_bytes(&byte3);
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes[2], 0x06);
|
||||
}
|
||||
}
|
||||
|
||||
37
rog-control-center/Cargo.toml
Normal file
37
rog-control-center/Cargo.toml
Normal file
@@ -0,0 +1,37 @@
|
||||
[package]
|
||||
name = "rog-control-center"
|
||||
version = "1.1.1"
|
||||
authors = ["Luke D. Jones <luke@ljones.dev>"]
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
mocking = []
|
||||
|
||||
[dependencies]
|
||||
egui = { git = "https://github.com/emilk/egui" }
|
||||
eframe= { git = "https://github.com/emilk/egui" }
|
||||
#eframe= { git = "https://github.com/emilk/egui", default-features = false, features = ["dark-light", "default_fonts", "wgpu"] }
|
||||
|
||||
daemon = { path = "../daemon" }
|
||||
rog_anime = { path = "../rog-anime" }
|
||||
rog_dbus = { path = "../rog-dbus" }
|
||||
rog_aura = { path = "../rog-aura" }
|
||||
rog_profiles = { path = "../rog-profiles" }
|
||||
rog_platform = { path = "../rog-platform" }
|
||||
# supergfxctl = { git = "https://gitlab.com/asus-linux/supergfxctl.git" }
|
||||
|
||||
smol = "^1.2"
|
||||
|
||||
serde = "^1.0"
|
||||
toml = "^0.5"
|
||||
serde_json = "^1.0"
|
||||
serde_derive = "^1.0"
|
||||
zbus = "^2.3"
|
||||
nix = "^0.20.0"
|
||||
tempfile = "3.2.0"
|
||||
dirs = "3.0.1"
|
||||
|
||||
[dependencies.notify-rust]
|
||||
version = "^4.3"
|
||||
default-features = false
|
||||
features = ["z"]
|
||||
22
rog-control-center/README.md
Normal file
22
rog-control-center/README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# App template
|
||||
|
||||
This is a trial app cut down to bare essentials to show how to create an app that can run in the background
|
||||
with some user-config options.
|
||||
|
||||
egui based. Keep in mind that this is very much a bit of a mess due to experimenting.
|
||||
|
||||
## Running
|
||||
|
||||
Use `WINIT_UNIX_BACKEND=x11 rog-control-center`. `WINIT_UNIX_BACKEND` is required due to window decorations not updating and the window not really being set as visible/invisible on wayland.
|
||||
|
||||
## Build features
|
||||
|
||||
For testing some features that are typically not available on all laptops:
|
||||
|
||||
```rust
|
||||
cargo run --features mocking
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
- Add notification watch for certain UI elements to enforce an update (for example when a user changes Aura via a hot key).
|
||||
11
rog-control-center/data/rog-control-center.desktop
Normal file
11
rog-control-center/data/rog-control-center.desktop
Normal file
@@ -0,0 +1,11 @@
|
||||
[Desktop Entry]
|
||||
Version=1.0
|
||||
Type=Application
|
||||
|
||||
Name=ROG Control Center
|
||||
Comment=Make your ASUS ROG Laptop go Brrrrr!
|
||||
Categories=Settings
|
||||
|
||||
Icon=rog-control-center
|
||||
Exec=rog-control-center
|
||||
Terminal=false
|
||||
BIN
rog-control-center/data/rog-control-center.png
Normal file
BIN
rog-control-center/data/rog-control-center.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
161
rog-control-center/src/app.rs
Normal file
161
rog-control-center/src/app.rs
Normal file
@@ -0,0 +1,161 @@
|
||||
use std::{
|
||||
f64::consts::PI,
|
||||
sync::{
|
||||
atomic::{AtomicBool, AtomicU8, Ordering},
|
||||
Arc,
|
||||
},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use egui::{Button, RichText};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
|
||||
use crate::{
|
||||
config::Config, error::Result, page_states::PageDataStates, Page, RogDbusClientBlocking,
|
||||
};
|
||||
|
||||
pub struct RogApp<'a> {
|
||||
pub page: Page,
|
||||
pub states: PageDataStates,
|
||||
pub supported: SupportedFunctions,
|
||||
// TODO: can probably just open and read whenever
|
||||
pub config: Config,
|
||||
pub asus_dbus: RogDbusClientBlocking<'a>,
|
||||
/// Oscillator in percentage
|
||||
pub oscillator1: Arc<AtomicU8>,
|
||||
pub oscillator2: Arc<AtomicU8>,
|
||||
pub oscillator3: Arc<AtomicU8>,
|
||||
/// Frequency of oscillation
|
||||
pub oscillator_freq: Arc<AtomicU8>,
|
||||
/// A toggle that toggles true/false when the oscillator reaches 0
|
||||
pub oscillator_toggle: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl<'a> RogApp<'a> {
|
||||
/// Called once before the first frame.
|
||||
pub fn new(
|
||||
config: Config,
|
||||
states: PageDataStates,
|
||||
_cc: &eframe::CreationContext<'_>,
|
||||
) -> Result<Self> {
|
||||
let (dbus, _) = RogDbusClientBlocking::new()?;
|
||||
let supported = dbus.proxies().supported().supported_functions()?;
|
||||
|
||||
// Set up an oscillator to run on a thread.
|
||||
// Helpful for visual effects like colour pulse.
|
||||
let oscillator1 = Arc::new(AtomicU8::new(0));
|
||||
let oscillator2 = Arc::new(AtomicU8::new(0));
|
||||
let oscillator3 = Arc::new(AtomicU8::new(0));
|
||||
|
||||
let oscillator1_1 = oscillator1.clone();
|
||||
let oscillator1_2 = oscillator2.clone();
|
||||
let oscillator1_3 = oscillator3.clone();
|
||||
|
||||
let oscillator_freq = Arc::new(AtomicU8::new(5));
|
||||
let oscillator_freq1 = oscillator_freq.clone();
|
||||
let oscillator_toggle = Arc::new(AtomicBool::new(false));
|
||||
let oscillator_toggle1 = oscillator_toggle.clone();
|
||||
std::thread::spawn(move || {
|
||||
let started = Instant::now();
|
||||
let mut toggled = false;
|
||||
loop {
|
||||
let time = started.elapsed();
|
||||
// 32 = slow, 16 = med, 8 = fast
|
||||
let scale = oscillator_freq1.load(Ordering::SeqCst) as f64;
|
||||
let elapsed1 = (time.as_millis() as f64 + 333.0) / 10000.0;
|
||||
let elapsed2 = (time.as_millis() as f64 + 666.0) / 10000.0;
|
||||
let elapsed3 = (time.as_millis() as f64 + 999.0) / 10000.0;
|
||||
let tmp1 = ((scale * elapsed1 * PI).cos()).abs();
|
||||
let tmp2 = ((scale * 0.85 * elapsed2 * PI).cos()).abs();
|
||||
let tmp3 = ((scale * 0.7 * elapsed3 * PI).cos()).abs();
|
||||
if tmp1 <= 0.1 && !toggled {
|
||||
let s = oscillator_toggle1.load(Ordering::SeqCst);
|
||||
oscillator_toggle1.store(!s, Ordering::SeqCst);
|
||||
toggled = true;
|
||||
} else if tmp1 > 0.9 {
|
||||
toggled = false;
|
||||
}
|
||||
|
||||
let tmp1 = (255.0 * tmp1 * 100.0 / 255.0) as u8;
|
||||
let tmp2 = (255.0 * tmp2 * 100.0 / 255.0) as u8;
|
||||
let tmp3 = (255.0 * tmp3 * 100.0 / 255.0) as u8;
|
||||
|
||||
oscillator1_1.store(tmp1, Ordering::SeqCst);
|
||||
oscillator1_2.store(tmp2, Ordering::SeqCst);
|
||||
oscillator1_3.store(tmp3, Ordering::SeqCst);
|
||||
std::thread::sleep(Duration::from_millis(33));
|
||||
}
|
||||
});
|
||||
|
||||
Ok(Self {
|
||||
supported,
|
||||
states,
|
||||
page: Page::System,
|
||||
config,
|
||||
asus_dbus: dbus,
|
||||
oscillator1,
|
||||
oscillator2,
|
||||
oscillator3,
|
||||
oscillator_toggle,
|
||||
oscillator_freq,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> eframe::App for RogApp<'a> {
|
||||
/// Called each time the UI needs repainting, which may be many times per second.
|
||||
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
let Self {
|
||||
supported,
|
||||
asus_dbus: dbus,
|
||||
states,
|
||||
..
|
||||
} = self;
|
||||
states
|
||||
.refresh_if_notfied(supported, dbus)
|
||||
.map(|repaint| {
|
||||
if repaint {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
})
|
||||
.map_err(|e| self.states.error = Some(e.to_string()))
|
||||
.ok();
|
||||
|
||||
let page = self.page;
|
||||
|
||||
self.top_bar(ctx, frame);
|
||||
self.side_panel(ctx);
|
||||
|
||||
if let Some(err) = self.states.error.clone() {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading(RichText::new("Error!").size(28.0));
|
||||
|
||||
ui.centered_and_justified(|ui| {
|
||||
ui.label(RichText::new(format!("The error was: {:?}", err)).size(22.0));
|
||||
});
|
||||
});
|
||||
egui::TopBottomPanel::bottom("error_bar")
|
||||
.default_height(26.0)
|
||||
.show(ctx, |ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
||||
if ui
|
||||
.add(Button::new(RichText::new("Okay").size(20.0)))
|
||||
.clicked()
|
||||
{
|
||||
self.states.error = None;
|
||||
}
|
||||
});
|
||||
});
|
||||
} else if page == Page::System {
|
||||
self.system_page(ctx);
|
||||
} else if page == Page::AuraEffects {
|
||||
self.aura_page(ctx);
|
||||
// TODO: Anime page is not complete
|
||||
// } else if page == Page::AnimeMatrix {
|
||||
// self.anime_page(ctx);
|
||||
} else if page == Page::FanCurves {
|
||||
self.fan_curve_page(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
92
rog-control-center/src/config.rs
Normal file
92
rog-control-center/src/config.rs
Normal file
@@ -0,0 +1,92 @@
|
||||
use std::{
|
||||
fs::{create_dir, OpenOptions},
|
||||
io::{Read, Write},
|
||||
};
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
//use log::{error, info, warn};
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
const CFG_DIR: &str = "rog";
|
||||
const CFG_FILE_NAME: &str = "rog-control-center.cfg";
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
pub run_in_background: bool,
|
||||
pub startup_in_background: bool,
|
||||
pub enable_notifications: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
run_in_background: true,
|
||||
startup_in_background: false,
|
||||
enable_notifications: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> Result<Config, Error> {
|
||||
let mut path = if let Some(dir) = dirs::config_dir() {
|
||||
dir
|
||||
} else {
|
||||
return Err(Error::XdgVars);
|
||||
};
|
||||
|
||||
path.push(CFG_DIR);
|
||||
if !path.exists() {
|
||||
create_dir(path.clone())?;
|
||||
}
|
||||
|
||||
path.push(CFG_FILE_NAME);
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(&path)?;
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||
if read_len == 0 {
|
||||
let default = Config::default();
|
||||
let t = toml::to_string_pretty(&default).unwrap();
|
||||
file.write_all(t.as_bytes())?;
|
||||
return Ok(default);
|
||||
} else if let Ok(data) = toml::from_str::<Config>(&buf) {
|
||||
return Ok(data);
|
||||
}
|
||||
}
|
||||
Err(Error::ConfigLoadFail)
|
||||
}
|
||||
|
||||
pub fn save(&self) -> Result<(), Error> {
|
||||
let mut path = if let Some(dir) = dirs::config_dir() {
|
||||
dir
|
||||
} else {
|
||||
return Err(Error::XdgVars);
|
||||
};
|
||||
|
||||
path.push(CFG_DIR);
|
||||
if !path.exists() {
|
||||
create_dir(path.clone())?;
|
||||
}
|
||||
|
||||
path.push(CFG_FILE_NAME);
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(&path)?;
|
||||
|
||||
let t = toml::to_string_pretty(&self).unwrap();
|
||||
file.write_all(t.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
47
rog-control-center/src/error.rs
Normal file
47
rog-control-center/src/error.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use std::fmt;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Io(std::io::Error),
|
||||
Nix(nix::Error),
|
||||
ConfigLoadFail,
|
||||
ConfigLockFail,
|
||||
XdgVars,
|
||||
Zbus(zbus::Error),
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
// This trait requires `fmt` with this exact signature.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
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::ConfigLockFail => write!(f, "Failed to lock user config"),
|
||||
Error::XdgVars => write!(f, "XDG environment vars appear unset"),
|
||||
Error::Zbus(err) => write!(f, "Error: {}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Error::Io(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<nix::Error> for Error {
|
||||
fn from(err: nix::Error) -> Self {
|
||||
Error::Nix(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<zbus::Error> for Error {
|
||||
fn from(err: zbus::Error) -> Self {
|
||||
Error::Zbus(err)
|
||||
}
|
||||
}
|
||||
108
rog-control-center/src/lib.rs
Normal file
108
rog-control-center/src/lib.rs
Normal file
@@ -0,0 +1,108 @@
|
||||
pub mod app;
|
||||
use std::{
|
||||
fs::{remove_dir_all, File, OpenOptions},
|
||||
io::{Read, Write},
|
||||
process::exit,
|
||||
thread::sleep,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
pub use app::RogApp;
|
||||
|
||||
pub mod config;
|
||||
pub mod error;
|
||||
#[cfg(feature = "mocking")]
|
||||
pub mod mocking;
|
||||
pub mod notify;
|
||||
pub mod page_states;
|
||||
pub mod pages;
|
||||
pub mod startup_error;
|
||||
pub mod widgets;
|
||||
|
||||
#[cfg(feature = "mocking")]
|
||||
pub use mocking::RogDbusClientBlocking;
|
||||
#[cfg(not(feature = "mocking"))]
|
||||
pub use rog_dbus::RogDbusClientBlocking;
|
||||
|
||||
use nix::{sys::stat, unistd};
|
||||
use tempfile::TempDir;
|
||||
//use log::{error, info, warn};
|
||||
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
pub fn print_versions() {
|
||||
println!("App and daemon versions:");
|
||||
println!(" rog-gui v{}", VERSION);
|
||||
println!(" asusd v{}", daemon::VERSION);
|
||||
println!("\nComponent crate versions:");
|
||||
println!(" rog-anime v{}", rog_anime::VERSION);
|
||||
println!(" rog-aura v{}", rog_aura::VERSION);
|
||||
println!(" rog-dbus v{}", rog_dbus::VERSION);
|
||||
println!(" rog-profiles v{}", rog_profiles::VERSION);
|
||||
println!("rog-platform v{}", rog_platform::VERSION);
|
||||
}
|
||||
|
||||
pub const SHOWING_GUI: u8 = 1;
|
||||
pub const SHOW_GUI: u8 = 2;
|
||||
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
pub enum Page {
|
||||
System,
|
||||
AuraEffects,
|
||||
AnimeMatrix,
|
||||
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; 4];
|
||||
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])?;
|
||||
// tiny sleep to give the app a chance to respond
|
||||
sleep(Duration::from_millis(10));
|
||||
ipc_file.read(&mut buf).ok();
|
||||
|
||||
// First entry is the actual state
|
||||
if buf[0] == SHOWING_GUI {
|
||||
ipc_file.write_all(&[SHOWING_GUI])?; // Store state again as we drained the fifo
|
||||
exit(0);
|
||||
} else if buf[0] == SHOW_GUI {
|
||||
remove_dir_all(&path)?;
|
||||
return tempfile::Builder::new()
|
||||
.prefix("rog-gui")
|
||||
.rand_bytes(0)
|
||||
.tempdir();
|
||||
}
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
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::Error::Sys(nix::errno::Errno::EEXIST)) {
|
||||
return Err(e)?;
|
||||
}
|
||||
}
|
||||
Ok(OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.open(&fifo_path)?)
|
||||
}
|
||||
162
rog-control-center/src/main.rs
Normal file
162
rog-control-center/src/main.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
use rog_aura::layouts::KeyLayout;
|
||||
use rog_control_center::{
|
||||
config::Config, get_ipc_file, notify::start_notifications, on_tmp_dir_exists,
|
||||
page_states::PageDataStates, print_versions, startup_error::AppErrorShow, RogApp,
|
||||
RogDbusClientBlocking, SHOWING_GUI, SHOW_GUI,
|
||||
};
|
||||
|
||||
use std::{
|
||||
fs::OpenOptions,
|
||||
io::{Read, Write},
|
||||
path::PathBuf,
|
||||
sync::{atomic::AtomicBool, Arc},
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "mocking"))]
|
||||
const DATA_DIR: &str = "/usr/share/rog-gui/";
|
||||
#[cfg(feature = "mocking")]
|
||||
const DATA_DIR: &str = env!("CARGO_MANIFEST_DIR");
|
||||
const BOARD_NAME: &str = "/sys/class/dmi/id/board_name";
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
print_versions();
|
||||
|
||||
let native_options = eframe::NativeOptions {
|
||||
decorated: false,
|
||||
transparent: false,
|
||||
min_window_size: Some(egui::vec2(840.0, 600.0)),
|
||||
max_window_size: Some(egui::vec2(840.0, 600.0)),
|
||||
run_and_return: true,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let (dbus, _) = RogDbusClientBlocking::new()
|
||||
.map_err(|e| {
|
||||
eframe::run_native(
|
||||
"ROG Control Center",
|
||||
native_options.clone(),
|
||||
Box::new(move |_| Box::new(AppErrorShow::new(e.to_string()))),
|
||||
);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
// Startup
|
||||
let mut config = Config::load()?;
|
||||
let mut start_closed = config.startup_in_background;
|
||||
|
||||
if config.startup_in_background {
|
||||
config.run_in_background = true;
|
||||
config.save()?;
|
||||
}
|
||||
|
||||
// Find and load a matching layout for laptop
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(PathBuf::from(BOARD_NAME))
|
||||
.map_err(|e| {
|
||||
println!("{BOARD_NAME}, {e}");
|
||||
e
|
||||
})?;
|
||||
let mut board_name = String::new();
|
||||
file.read_to_string(&mut board_name)?;
|
||||
|
||||
#[cfg(feature = "mocking")]
|
||||
{
|
||||
board_name = "gl504".to_string();
|
||||
path.pop();
|
||||
path.push("rog-aura");
|
||||
path.push("data");
|
||||
}
|
||||
|
||||
let layout = KeyLayout::find_layout(board_name.as_str(), PathBuf::from(DATA_DIR))
|
||||
.map_err(|e| {
|
||||
println!("{BOARD_NAME}, {e}");
|
||||
})
|
||||
.unwrap_or(KeyLayout::ga401_layout());
|
||||
|
||||
// Cheap method to alert to notifications rather than spinning a thread for each
|
||||
// This is quite different when done in a retained mode app
|
||||
let charge_notified = Arc::new(AtomicBool::new(false));
|
||||
let bios_notified = Arc::new(AtomicBool::new(false));
|
||||
let aura_notified = Arc::new(AtomicBool::new(false));
|
||||
let anime_notified = Arc::new(AtomicBool::new(false));
|
||||
let profiles_notified = Arc::new(AtomicBool::new(false));
|
||||
let fans_notified = Arc::new(AtomicBool::new(false));
|
||||
let notifs_enabled = Arc::new(AtomicBool::new(config.enable_notifications));
|
||||
|
||||
start_notifications(
|
||||
charge_notified.clone(),
|
||||
bios_notified.clone(),
|
||||
aura_notified.clone(),
|
||||
anime_notified.clone(),
|
||||
profiles_notified.clone(),
|
||||
fans_notified.clone(),
|
||||
notifs_enabled.clone(),
|
||||
)?;
|
||||
|
||||
// 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(),
|
||||
};
|
||||
|
||||
loop {
|
||||
let states = {
|
||||
let supported = match dbus.proxies().supported().supported_functions() {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
eframe::run_native(
|
||||
"ROG Control Center",
|
||||
native_options.clone(),
|
||||
Box::new(move |_| Box::new(AppErrorShow::new(e.to_string()))),
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
PageDataStates::new(
|
||||
layout.clone(),
|
||||
notifs_enabled.clone(),
|
||||
charge_notified.clone(),
|
||||
bios_notified.clone(),
|
||||
aura_notified.clone(),
|
||||
anime_notified.clone(),
|
||||
profiles_notified.clone(),
|
||||
fans_notified.clone(),
|
||||
&supported,
|
||||
&dbus,
|
||||
)?
|
||||
};
|
||||
|
||||
if !start_closed {
|
||||
let mut ipc_file = get_ipc_file().unwrap();
|
||||
ipc_file.write_all(&[SHOWING_GUI]).unwrap();
|
||||
eframe::run_native(
|
||||
"ROG Control Center",
|
||||
native_options.clone(),
|
||||
Box::new(move |cc| {
|
||||
Box::new(RogApp::new(Config::load().unwrap(), states, cc).unwrap())
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
let config = Config::load().unwrap();
|
||||
if !config.run_in_background {
|
||||
break;
|
||||
}
|
||||
|
||||
let mut buf = [0u8; 4];
|
||||
// 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)
|
||||
if get_ipc_file().unwrap().read(&mut buf).is_ok() && buf[0] == SHOW_GUI {
|
||||
start_closed = false;
|
||||
continue;
|
||||
}
|
||||
dbg!("asda");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
226
rog-control-center/src/mocking.rs
Normal file
226
rog-control-center/src/mocking.rs
Normal file
@@ -0,0 +1,226 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use rog_aura::{
|
||||
usb::{AuraDev19b6, AuraDevice, AuraPowerDev},
|
||||
AuraEffect, AuraModeNum, AuraZone,
|
||||
};
|
||||
use rog_profiles::fan_curve_set::{CurveData, FanCurveSet};
|
||||
use rog_supported::{
|
||||
AnimeSupportedFunctions, ChargeSupportedFunctions, LedSupportedFunctions,
|
||||
PlatformProfileFunctions, RogBiosSupportedFunctions, SupportedFunctions,
|
||||
};
|
||||
|
||||
use crate::error::Result;
|
||||
|
||||
const NOPE: &'static str = "";
|
||||
|
||||
pub struct RogDbusClientBlocking<'a> {
|
||||
_phantom: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Default for RogDbusClientBlocking<'a> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
_phantom: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RogDbusClientBlocking<'a> {
|
||||
pub fn new() -> Result<(Self, bool)> {
|
||||
Ok((Self { _phantom: NOPE }, true))
|
||||
}
|
||||
pub fn proxies(&self) -> Proxies {
|
||||
Proxies
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Proxies;
|
||||
impl Proxies {
|
||||
pub fn rog_bios(&self) -> Bios {
|
||||
Bios
|
||||
}
|
||||
pub fn profile(&self) -> Profile {
|
||||
Profile
|
||||
}
|
||||
pub fn led(&self) -> Led {
|
||||
Led
|
||||
}
|
||||
pub fn anime(&self) -> Anime {
|
||||
Anime
|
||||
}
|
||||
pub fn charge(&self) -> Profile {
|
||||
Profile
|
||||
}
|
||||
pub fn supported(&self) -> Supported {
|
||||
Supported
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Bios;
|
||||
impl Bios {
|
||||
pub fn post_boot_sound(&self) -> Result<i16> {
|
||||
Ok(1)
|
||||
}
|
||||
pub fn gpu_mux_mode(&self) -> Result<i16> {
|
||||
Ok(1)
|
||||
}
|
||||
pub fn panel_overdrive(&self) -> Result<i16> {
|
||||
Ok(1)
|
||||
}
|
||||
pub fn set_post_boot_sound(&self, _b: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_gpu_mux_mode(&self, _b: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_panel_overdrive(&self, _b: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Profile;
|
||||
impl Profile {
|
||||
pub fn profiles(&self) -> Result<Vec<rog_profiles::Profile>> {
|
||||
Ok(vec![
|
||||
rog_profiles::Profile::Balanced,
|
||||
rog_profiles::Profile::Performance,
|
||||
rog_profiles::Profile::Quiet,
|
||||
])
|
||||
}
|
||||
pub fn active_profile(&self) -> Result<rog_profiles::Profile> {
|
||||
Ok(rog_profiles::Profile::Performance)
|
||||
}
|
||||
pub fn enabled_fan_profiles(&self) -> Result<Vec<rog_profiles::Profile>> {
|
||||
Ok(vec![
|
||||
rog_profiles::Profile::Performance,
|
||||
rog_profiles::Profile::Balanced,
|
||||
])
|
||||
}
|
||||
pub fn fan_curve_data(&self, _p: rog_profiles::Profile) -> Result<FanCurveSet> {
|
||||
let mut curve = FanCurveSet::default();
|
||||
curve.cpu.pwm = [30, 40, 60, 100, 140, 180, 200, 250];
|
||||
curve.cpu.temp = [20, 30, 40, 50, 70, 80, 90, 100];
|
||||
curve.gpu.pwm = [40, 80, 100, 140, 170, 200, 230, 250];
|
||||
curve.gpu.temp = [20, 30, 40, 50, 70, 80, 90, 100];
|
||||
Ok(curve)
|
||||
}
|
||||
pub fn set_fan_curve(&self, _p: rog_profiles::Profile, _c: CurveData) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_fan_curve_enabled(&self, _p: rog_profiles::Profile, _b: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
pub fn limit(&self) -> Result<i16> {
|
||||
Ok(66)
|
||||
}
|
||||
pub fn set_limit(&self, _l: u8) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_active_profile(&self, _p: rog_profiles::Profile) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Led;
|
||||
impl Led {
|
||||
pub fn led_modes(&self) -> Result<BTreeMap<AuraModeNum, AuraEffect>> {
|
||||
let mut data = BTreeMap::new();
|
||||
data.insert(AuraModeNum::Static, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Star, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Strobe, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Rain, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Rainbow, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Ripple, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Breathe, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Comet, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Flash, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Laser, AuraEffect::default());
|
||||
data.insert(AuraModeNum::Pulse, AuraEffect::default());
|
||||
Ok(data)
|
||||
}
|
||||
pub fn led_mode(&self) -> Result<AuraModeNum> {
|
||||
Ok(AuraModeNum::Rainbow)
|
||||
}
|
||||
pub fn led_brightness(&self) -> Result<i16> {
|
||||
Ok(1)
|
||||
}
|
||||
pub fn leds_enabled(&self) -> Result<AuraPowerDev> {
|
||||
Ok(AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: vec![],
|
||||
x19b6: vec![
|
||||
AuraDev19b6::BootKeyb,
|
||||
AuraDev19b6::AwakeKeyb,
|
||||
AuraDev19b6::SleepLogo,
|
||||
AuraDev19b6::AwakeLogo,
|
||||
],
|
||||
})
|
||||
}
|
||||
pub fn set_leds_power(&self, _a: AuraPowerDev, _b: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_led_mode(&self, _a: &AuraEffect) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Anime;
|
||||
impl Anime {
|
||||
pub fn boot_enabled(&self) -> Result<bool> {
|
||||
Ok(true)
|
||||
}
|
||||
pub fn awake_enabled(&self) -> Result<bool> {
|
||||
Ok(true)
|
||||
}
|
||||
pub fn set_on_off(&self, _b: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_boot_on_off(&self, _b: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Supported;
|
||||
impl Supported {
|
||||
pub fn supported_functions(&self) -> Result<SupportedFunctions> {
|
||||
Ok(SupportedFunctions {
|
||||
anime_ctrl: AnimeSupportedFunctions(true),
|
||||
charge_ctrl: ChargeSupportedFunctions {
|
||||
charge_level_set: true,
|
||||
},
|
||||
platform_profile: PlatformProfileFunctions {
|
||||
platform_profile: true,
|
||||
fan_curves: true,
|
||||
},
|
||||
keyboard_led: LedSupportedFunctions {
|
||||
prod_id: AuraDevice::X19B6,
|
||||
brightness_set: true,
|
||||
stock_led_modes: vec![
|
||||
AuraModeNum::Rain,
|
||||
AuraModeNum::Rainbow,
|
||||
AuraModeNum::Star,
|
||||
AuraModeNum::Static,
|
||||
AuraModeNum::Strobe,
|
||||
],
|
||||
multizone_led_mode: vec![
|
||||
AuraZone::Key1,
|
||||
AuraZone::Key2,
|
||||
AuraZone::Key3,
|
||||
AuraZone::Key4,
|
||||
AuraZone::BarLeft,
|
||||
AuraZone::BarRight,
|
||||
AuraZone::Logo,
|
||||
],
|
||||
per_key_led_mode: true,
|
||||
},
|
||||
rog_bios_ctrl: RogBiosSupportedFunctions {
|
||||
post_sound: true,
|
||||
dedicated_gfx: true,
|
||||
panel_overdrive: true,
|
||||
dgpu_disable: true,
|
||||
egpu_enable: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
256
rog-control-center/src/notify.rs
Normal file
256
rog-control-center/src/notify.rs
Normal file
@@ -0,0 +1,256 @@
|
||||
//TODO: a lot of app state refresh depends on this so there needs
|
||||
// to be an extra AtomicBool for checking if notifications are enabled
|
||||
|
||||
use notify_rust::{Hint, Notification, NotificationHandle};
|
||||
use rog_aura::AuraEffect;
|
||||
use rog_dbus::{
|
||||
zbus_anime::AnimeProxy, zbus_charge::ChargeProxy, zbus_led::LedProxy,
|
||||
zbus_platform::RogBiosProxy, zbus_profile::ProfileProxy,
|
||||
};
|
||||
use rog_profiles::Profile;
|
||||
use smol::{future, Executor};
|
||||
use std::{
|
||||
error::Error,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
thread::spawn,
|
||||
};
|
||||
use zbus::export::futures_util::StreamExt;
|
||||
|
||||
const NOTIF_HEADER: &str = "ROG Control";
|
||||
|
||||
macro_rules! notify {
|
||||
($notifier:ident, $last_notif:ident, $data:expr) => {
|
||||
if let Some(notif) = $last_notif.take() {
|
||||
notif.close();
|
||||
}
|
||||
if let Ok(x) = $notifier($data) {
|
||||
$last_notif.replace(x);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! base_notification {
|
||||
($body:expr) => {
|
||||
Notification::new()
|
||||
.summary(NOTIF_HEADER)
|
||||
.body($body)
|
||||
.timeout(2000)
|
||||
.show()
|
||||
};
|
||||
}
|
||||
|
||||
type SharedHandle = Arc<Mutex<Option<NotificationHandle>>>;
|
||||
|
||||
pub fn start_notifications(
|
||||
charge_notified: Arc<AtomicBool>,
|
||||
bios_notified: Arc<AtomicBool>,
|
||||
aura_notified: Arc<AtomicBool>,
|
||||
anime_notified: Arc<AtomicBool>,
|
||||
profiles_notified: Arc<AtomicBool>,
|
||||
_fans_notified: Arc<AtomicBool>,
|
||||
notifs_enabled: Arc<AtomicBool>,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let last_notification: SharedHandle = Arc::new(Mutex::new(None));
|
||||
|
||||
let executor = Executor::new();
|
||||
// BIOS notif
|
||||
let last_notif = last_notification.clone();
|
||||
let notifs_enabled1 = notifs_enabled.clone();
|
||||
let bios_notified1 = bios_notified.clone();
|
||||
// TODO: make a macro or generic function or something...
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = RogBiosProxy::new(&conn).await.unwrap();
|
||||
if let Ok(p) = proxy.receive_notify_post_boot_sound().await {
|
||||
p.for_each(|e| {
|
||||
if let Ok(out) = e.args() {
|
||||
if notifs_enabled1.load(Ordering::SeqCst) {
|
||||
if let Ok(ref mut lock) = last_notif.try_lock() {
|
||||
notify!(do_post_sound_notif, lock, &out.sound());
|
||||
}
|
||||
}
|
||||
bios_notified1.store(true, Ordering::SeqCst);
|
||||
}
|
||||
future::ready(())
|
||||
})
|
||||
.await;
|
||||
};
|
||||
})
|
||||
.detach();
|
||||
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = RogBiosProxy::new(&conn).await.unwrap();
|
||||
if let Ok(p) = proxy.receive_notify_panel_overdrive().await {
|
||||
p.for_each(|_| {
|
||||
bios_notified.store(true, Ordering::SeqCst);
|
||||
future::ready(())
|
||||
})
|
||||
.await;
|
||||
};
|
||||
})
|
||||
.detach();
|
||||
|
||||
// Charge notif
|
||||
let last_notif = last_notification.clone();
|
||||
let notifs_enabled1 = notifs_enabled.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = ChargeProxy::new(&conn).await.unwrap();
|
||||
if let Ok(p) = proxy.receive_notify_charge().await {
|
||||
p.for_each(|e| {
|
||||
if let Ok(out) = e.args() {
|
||||
if notifs_enabled1.load(Ordering::SeqCst) {
|
||||
if let Ok(ref mut lock) = last_notif.try_lock() {
|
||||
notify!(do_charge_notif, lock, &out.limit);
|
||||
}
|
||||
}
|
||||
charge_notified.store(true, Ordering::SeqCst);
|
||||
}
|
||||
future::ready(())
|
||||
})
|
||||
.await;
|
||||
};
|
||||
})
|
||||
.detach();
|
||||
|
||||
// Profile notif
|
||||
let last_notif = last_notification.clone();
|
||||
let notifs_enabled1 = notifs_enabled.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = ProfileProxy::new(&conn).await.unwrap();
|
||||
if let Ok(p) = proxy.receive_notify_profile().await {
|
||||
p.for_each(|e| {
|
||||
if let Ok(out) = e.args() {
|
||||
if notifs_enabled1.load(Ordering::SeqCst) {
|
||||
if let Ok(ref mut lock) = last_notif.try_lock() {
|
||||
notify!(do_thermal_notif, lock, &out.profile);
|
||||
}
|
||||
}
|
||||
profiles_notified.store(true, Ordering::SeqCst);
|
||||
}
|
||||
future::ready(())
|
||||
})
|
||||
.await;
|
||||
};
|
||||
})
|
||||
.detach();
|
||||
|
||||
// LED notif
|
||||
let last_notif = last_notification.clone();
|
||||
let aura_notif = aura_notified.clone();
|
||||
let notifs_enabled1 = notifs_enabled.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = LedProxy::new(&conn).await.unwrap();
|
||||
if let Ok(p) = proxy.receive_notify_led().await {
|
||||
p.for_each(|e| {
|
||||
if let Ok(out) = e.args() {
|
||||
if notifs_enabled1.load(Ordering::SeqCst) {
|
||||
if let Ok(ref mut lock) = last_notif.try_lock() {
|
||||
notify!(do_led_notif, lock, &out.data);
|
||||
}
|
||||
}
|
||||
aura_notif.store(true, Ordering::SeqCst);
|
||||
}
|
||||
future::ready(())
|
||||
})
|
||||
.await;
|
||||
};
|
||||
})
|
||||
.detach();
|
||||
|
||||
let aura_notif = aura_notified.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = LedProxy::new(&conn).await.unwrap();
|
||||
if let Ok(p) = proxy.receive_notify_led().await {
|
||||
p.for_each(|_| {
|
||||
aura_notif.store(true, Ordering::SeqCst);
|
||||
future::ready(())
|
||||
})
|
||||
.await;
|
||||
};
|
||||
})
|
||||
.detach();
|
||||
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = LedProxy::new(&conn).await.unwrap();
|
||||
if let Ok(p) = proxy.receive_all_signals().await {
|
||||
p.for_each(|_| {
|
||||
aura_notified.store(true, Ordering::SeqCst);
|
||||
future::ready(())
|
||||
})
|
||||
.await;
|
||||
};
|
||||
})
|
||||
.detach();
|
||||
|
||||
executor
|
||||
.spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = AnimeProxy::new(&conn).await.unwrap();
|
||||
if let Ok(p) = proxy.receive_power_states().await {
|
||||
p.for_each(|_| {
|
||||
anime_notified.store(true, Ordering::SeqCst);
|
||||
future::ready(())
|
||||
})
|
||||
.await;
|
||||
};
|
||||
})
|
||||
.detach();
|
||||
|
||||
spawn(move || loop {
|
||||
smol::block_on(executor.tick());
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn do_thermal_notif(profile: &Profile) -> Result<NotificationHandle, Box<dyn Error>> {
|
||||
let icon = match profile {
|
||||
Profile::Balanced => "asus_notif_yellow",
|
||||
Profile::Performance => "asus_notif_red",
|
||||
Profile::Quiet => "asus_notif_green",
|
||||
};
|
||||
let profile: &str = (*profile).into();
|
||||
let x = Notification::new()
|
||||
.summary("ASUS ROG")
|
||||
.body(&format!(
|
||||
"Thermal profile changed to {}",
|
||||
profile.to_uppercase(),
|
||||
))
|
||||
.hint(Hint::Resident(true))
|
||||
.timeout(2000)
|
||||
.hint(Hint::Category("device".into()))
|
||||
//.hint(Hint::Transient(true))
|
||||
.icon(icon)
|
||||
.show()?;
|
||||
Ok(x)
|
||||
}
|
||||
|
||||
fn do_led_notif(ledmode: &AuraEffect) -> Result<NotificationHandle, notify_rust::error::Error> {
|
||||
base_notification!(&format!(
|
||||
"Keyboard LED mode changed to {}",
|
||||
ledmode.mode_name()
|
||||
))
|
||||
}
|
||||
|
||||
fn do_charge_notif(limit: &u8) -> Result<NotificationHandle, notify_rust::error::Error> {
|
||||
base_notification!(&format!("Battery charge limit changed to {}", limit))
|
||||
}
|
||||
|
||||
fn do_post_sound_notif(on: &bool) -> Result<NotificationHandle, notify_rust::error::Error> {
|
||||
base_notification!(&format!("BIOS Post sound {}", on))
|
||||
}
|
||||
385
rog-control-center/src/page_states.rs
Normal file
385
rog-control-center/src/page_states.rs
Normal file
@@ -0,0 +1,385 @@
|
||||
use std::{
|
||||
collections::{BTreeMap, HashSet},
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
},
|
||||
};
|
||||
|
||||
use egui::Vec2;
|
||||
use rog_aura::{layouts::KeyLayout, usb::AuraPowerDev, AuraEffect, AuraModeNum};
|
||||
use rog_platform::{platform::GpuMode, supported::SupportedFunctions};
|
||||
use rog_profiles::{fan_curve_set::FanCurveSet, FanCurvePU, Profile};
|
||||
|
||||
use crate::{error::Result, RogDbusClientBlocking};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BiosState {
|
||||
/// To be shared to a thread that checks notifications.
|
||||
/// It's a bit general in that it won't provide *what* was
|
||||
/// updated, so the full state needs refresh
|
||||
pub was_notified: Arc<AtomicBool>,
|
||||
pub post_sound: bool,
|
||||
pub dedicated_gfx: GpuMode,
|
||||
pub panel_overdrive: bool,
|
||||
pub dgpu_disable: bool,
|
||||
pub egpu_enable: bool,
|
||||
}
|
||||
|
||||
impl BiosState {
|
||||
pub fn new(
|
||||
was_notified: Arc<AtomicBool>,
|
||||
supported: &SupportedFunctions,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
was_notified,
|
||||
post_sound: if supported.rog_bios_ctrl.post_sound {
|
||||
dbus.proxies().rog_bios().post_boot_sound()? != 0
|
||||
} else {
|
||||
false
|
||||
},
|
||||
dedicated_gfx: if supported.rog_bios_ctrl.gpu_mux {
|
||||
dbus.proxies().rog_bios().gpu_mux_mode()?
|
||||
} else {
|
||||
GpuMode::NotSupported
|
||||
},
|
||||
panel_overdrive: if supported.rog_bios_ctrl.panel_overdrive {
|
||||
dbus.proxies().rog_bios().panel_overdrive()?
|
||||
} else {
|
||||
false
|
||||
},
|
||||
// TODO: needs supergfx
|
||||
dgpu_disable: supported.rog_bios_ctrl.dgpu_disable,
|
||||
egpu_enable: supported.rog_bios_ctrl.egpu_enable,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ProfilesState {
|
||||
pub was_notified: Arc<AtomicBool>,
|
||||
pub list: Vec<Profile>,
|
||||
pub current: Profile,
|
||||
}
|
||||
|
||||
impl ProfilesState {
|
||||
pub fn new(
|
||||
was_notified: Arc<AtomicBool>,
|
||||
supported: &SupportedFunctions,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
was_notified,
|
||||
list: if supported.platform_profile.platform_profile {
|
||||
let mut list = dbus.proxies().profile().profiles()?;
|
||||
list.sort();
|
||||
list
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
current: if supported.platform_profile.platform_profile {
|
||||
dbus.proxies().profile().active_profile()?
|
||||
} else {
|
||||
Profile::Balanced
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FanCurvesState {
|
||||
pub was_notified: Arc<AtomicBool>,
|
||||
pub show_curve: Profile,
|
||||
pub show_graph: FanCurvePU,
|
||||
pub enabled: HashSet<Profile>,
|
||||
pub curves: BTreeMap<Profile, FanCurveSet>,
|
||||
pub drag_delta: Vec2,
|
||||
}
|
||||
|
||||
impl FanCurvesState {
|
||||
pub fn new(
|
||||
was_notified: Arc<AtomicBool>,
|
||||
supported: &SupportedFunctions,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
) -> Result<Self> {
|
||||
let profiles = if supported.platform_profile.platform_profile {
|
||||
dbus.proxies().profile().profiles()?
|
||||
} else {
|
||||
vec![Profile::Balanced, Profile::Quiet, Profile::Performance]
|
||||
};
|
||||
let enabled = if supported.platform_profile.fan_curves {
|
||||
HashSet::from_iter(
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
.enabled_fan_profiles()?
|
||||
.iter()
|
||||
.cloned(),
|
||||
)
|
||||
} else {
|
||||
HashSet::from([Profile::Balanced, Profile::Quiet, Profile::Performance])
|
||||
};
|
||||
|
||||
let mut curves: BTreeMap<Profile, FanCurveSet> = BTreeMap::new();
|
||||
profiles.iter().for_each(|p| {
|
||||
if supported.platform_profile.fan_curves {
|
||||
if let Ok(curve) = dbus.proxies().profile().fan_curve_data(*p) {
|
||||
curves.insert(*p, curve);
|
||||
}
|
||||
} else {
|
||||
let mut curve = FanCurveSet::default();
|
||||
curve.cpu.pwm = [30, 40, 60, 100, 140, 180, 200, 250];
|
||||
curve.cpu.temp = [20, 30, 40, 50, 70, 80, 90, 100];
|
||||
curve.gpu.pwm = [40, 80, 100, 140, 170, 200, 230, 250];
|
||||
curve.gpu.temp = [20, 30, 40, 50, 70, 80, 90, 100];
|
||||
curves.insert(*p, curve);
|
||||
}
|
||||
});
|
||||
|
||||
let show_curve = if supported.platform_profile.fan_curves {
|
||||
dbus.proxies().profile().active_profile()?
|
||||
} else {
|
||||
Profile::Balanced
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
was_notified,
|
||||
show_curve,
|
||||
show_graph: FanCurvePU::CPU,
|
||||
enabled,
|
||||
curves,
|
||||
drag_delta: Vec2::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AuraState {
|
||||
pub was_notified: Arc<AtomicBool>,
|
||||
pub current_mode: AuraModeNum,
|
||||
pub modes: BTreeMap<AuraModeNum, AuraEffect>,
|
||||
pub enabled: AuraPowerDev,
|
||||
/// Brightness from 0-3
|
||||
pub bright: i16,
|
||||
pub wave_red: [u8; 22],
|
||||
pub wave_green: [u8; 22],
|
||||
pub wave_blue: [u8; 22],
|
||||
}
|
||||
|
||||
impl AuraState {
|
||||
pub fn new(
|
||||
was_notified: Arc<AtomicBool>,
|
||||
supported: &SupportedFunctions,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
was_notified,
|
||||
current_mode: if !supported.keyboard_led.stock_led_modes.is_empty() {
|
||||
dbus.proxies().led().led_mode().unwrap_or_default()
|
||||
} else {
|
||||
AuraModeNum::Static
|
||||
},
|
||||
|
||||
modes: if !supported.keyboard_led.stock_led_modes.is_empty() {
|
||||
dbus.proxies().led().led_modes().unwrap_or_default()
|
||||
} else {
|
||||
BTreeMap::new()
|
||||
},
|
||||
enabled: dbus.proxies().led().leds_enabled().unwrap_or_default(),
|
||||
bright: if !supported.keyboard_led.brightness_set {
|
||||
dbus.proxies().led().led_brightness().unwrap_or_default()
|
||||
} else {
|
||||
2
|
||||
},
|
||||
wave_red: [0u8; 22],
|
||||
wave_green: [0u8; 22],
|
||||
wave_blue: [0u8; 22],
|
||||
})
|
||||
}
|
||||
|
||||
/// Bump value in to the wave and surf all along.
|
||||
pub fn nudge_wave(&mut self, r: u8, g: u8, b: u8) {
|
||||
for i in (0..self.wave_red.len()).rev() {
|
||||
if i > 0 {
|
||||
self.wave_red[i] = self.wave_red[i - 1];
|
||||
self.wave_green[i] = self.wave_green[i - 1];
|
||||
self.wave_blue[i] = self.wave_blue[i - 1];
|
||||
}
|
||||
}
|
||||
self.wave_red[0] = r;
|
||||
self.wave_green[0] = g;
|
||||
self.wave_blue[0] = b;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AnimeState {
|
||||
pub was_notified: Arc<AtomicBool>,
|
||||
pub bright: u8,
|
||||
pub boot: bool,
|
||||
pub awake: bool,
|
||||
pub sleep: bool,
|
||||
}
|
||||
|
||||
impl AnimeState {
|
||||
pub fn new(
|
||||
was_notified: Arc<AtomicBool>,
|
||||
supported: &SupportedFunctions,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
was_notified,
|
||||
boot: if supported.anime_ctrl.0 {
|
||||
dbus.proxies().anime().boot_enabled()?
|
||||
} else {
|
||||
false
|
||||
},
|
||||
awake: if supported.anime_ctrl.0 {
|
||||
dbus.proxies().anime().awake_enabled()?
|
||||
} else {
|
||||
false
|
||||
},
|
||||
// TODO:
|
||||
sleep: false,
|
||||
bright: 200,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PageDataStates {
|
||||
pub keyboard_layout: KeyLayout,
|
||||
pub notifs_enabled: Arc<AtomicBool>,
|
||||
pub was_notified: Arc<AtomicBool>,
|
||||
/// Because much of the app state here is the same as `RogBiosSupportedFunctions`
|
||||
/// we can re-use that structure.
|
||||
pub bios: BiosState,
|
||||
pub aura: AuraState,
|
||||
pub anime: AnimeState,
|
||||
pub profiles: ProfilesState,
|
||||
pub fan_curves: FanCurvesState,
|
||||
pub charge_limit: i16,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
impl PageDataStates {
|
||||
pub fn new(
|
||||
keyboard_layout: KeyLayout,
|
||||
notifs_enabled: Arc<AtomicBool>,
|
||||
charge_notified: Arc<AtomicBool>,
|
||||
bios_notified: Arc<AtomicBool>,
|
||||
aura_notified: Arc<AtomicBool>,
|
||||
anime_notified: Arc<AtomicBool>,
|
||||
profiles_notified: Arc<AtomicBool>,
|
||||
fans_notified: Arc<AtomicBool>,
|
||||
supported: &SupportedFunctions,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
keyboard_layout,
|
||||
notifs_enabled,
|
||||
was_notified: charge_notified,
|
||||
charge_limit: dbus.proxies().charge().limit()?,
|
||||
bios: BiosState::new(bios_notified, supported, dbus)?,
|
||||
aura: AuraState::new(aura_notified, supported, dbus)?,
|
||||
anime: AnimeState::new(anime_notified, supported, dbus)?,
|
||||
profiles: ProfilesState::new(profiles_notified, supported, dbus)?,
|
||||
fan_curves: FanCurvesState::new(fans_notified, supported, dbus)?,
|
||||
error: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn refresh_if_notfied(
|
||||
&mut self,
|
||||
supported: &SupportedFunctions,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
) -> Result<bool> {
|
||||
let mut notified = false;
|
||||
if self.was_notified.load(Ordering::SeqCst) {
|
||||
self.charge_limit = dbus.proxies().charge().limit()?;
|
||||
self.was_notified.store(false, Ordering::SeqCst);
|
||||
notified = true;
|
||||
}
|
||||
|
||||
if self.aura.was_notified.load(Ordering::SeqCst) {
|
||||
self.aura = AuraState::new(self.aura.was_notified.clone(), supported, dbus)?;
|
||||
self.aura.was_notified.store(false, Ordering::SeqCst);
|
||||
notified = true;
|
||||
}
|
||||
|
||||
if self.bios.was_notified.load(Ordering::SeqCst) {
|
||||
self.bios = BiosState::new(self.bios.was_notified.clone(), supported, dbus)?;
|
||||
self.bios.was_notified.store(false, Ordering::SeqCst);
|
||||
notified = true;
|
||||
}
|
||||
|
||||
if self.profiles.was_notified.load(Ordering::SeqCst) {
|
||||
self.profiles =
|
||||
ProfilesState::new(self.profiles.was_notified.clone(), supported, dbus)?;
|
||||
self.profiles.was_notified.store(false, Ordering::SeqCst);
|
||||
notified = true;
|
||||
}
|
||||
|
||||
if self.fan_curves.was_notified.load(Ordering::SeqCst) {
|
||||
self.fan_curves =
|
||||
FanCurvesState::new(self.fan_curves.was_notified.clone(), supported, dbus)?;
|
||||
self.fan_curves.was_notified.store(false, Ordering::SeqCst);
|
||||
notified = true;
|
||||
}
|
||||
Ok(notified)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PageDataStates {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
keyboard_layout: KeyLayout::ga401_layout(),
|
||||
notifs_enabled: Default::default(),
|
||||
was_notified: Default::default(),
|
||||
bios: BiosState {
|
||||
was_notified: Default::default(),
|
||||
post_sound: Default::default(),
|
||||
dedicated_gfx: GpuMode::NotSupported,
|
||||
panel_overdrive: Default::default(),
|
||||
dgpu_disable: Default::default(),
|
||||
egpu_enable: Default::default(),
|
||||
},
|
||||
aura: AuraState {
|
||||
was_notified: Default::default(),
|
||||
current_mode: AuraModeNum::Static,
|
||||
modes: Default::default(),
|
||||
enabled: AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: vec![],
|
||||
x19b6: vec![],
|
||||
},
|
||||
bright: Default::default(),
|
||||
wave_red: Default::default(),
|
||||
wave_green: Default::default(),
|
||||
wave_blue: Default::default(),
|
||||
},
|
||||
anime: AnimeState {
|
||||
was_notified: Default::default(),
|
||||
bright: Default::default(),
|
||||
boot: Default::default(),
|
||||
awake: Default::default(),
|
||||
sleep: Default::default(),
|
||||
},
|
||||
profiles: ProfilesState {
|
||||
was_notified: Default::default(),
|
||||
list: Default::default(),
|
||||
current: Default::default(),
|
||||
},
|
||||
fan_curves: FanCurvesState {
|
||||
was_notified: Default::default(),
|
||||
show_curve: Default::default(),
|
||||
show_graph: Default::default(),
|
||||
enabled: Default::default(),
|
||||
curves: Default::default(),
|
||||
drag_delta: Default::default(),
|
||||
},
|
||||
charge_limit: Default::default(),
|
||||
error: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
9
rog-control-center/src/pages/anime_page.rs
Normal file
9
rog-control-center/src/pages/anime_page.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use crate::RogApp;
|
||||
|
||||
impl<'a> RogApp<'a> {
|
||||
pub fn anime_page(&mut self, ctx: &egui::Context) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.label("In progress");
|
||||
});
|
||||
}
|
||||
}
|
||||
83
rog-control-center/src/pages/aura_page.rs
Normal file
83
rog-control-center/src/pages/aura_page.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use std::{sync::atomic::Ordering, time::Duration};
|
||||
|
||||
use egui::Color32;
|
||||
use rog_aura::{AuraEffect, AuraModeNum};
|
||||
|
||||
use crate::{
|
||||
widgets::{aura_modes_group, keyboard},
|
||||
RogApp,
|
||||
};
|
||||
|
||||
impl<'a> RogApp<'a> {
|
||||
pub fn aura_page(&mut self, ctx: &egui::Context) {
|
||||
let Self {
|
||||
supported,
|
||||
states,
|
||||
asus_dbus: dbus,
|
||||
oscillator1,
|
||||
oscillator2,
|
||||
oscillator3,
|
||||
oscillator_freq,
|
||||
..
|
||||
} = self;
|
||||
|
||||
let red = oscillator1.load(Ordering::SeqCst) as u32;
|
||||
let green = oscillator2.load(Ordering::SeqCst) as u32;
|
||||
let blue = oscillator3.load(Ordering::SeqCst) as u32;
|
||||
states.aura.nudge_wave(red as u8, green as u8, blue as u8);
|
||||
// let osc = c.0 * 255 / osc;
|
||||
// dbg!(osc);
|
||||
let c1 = states
|
||||
.aura
|
||||
.modes
|
||||
.get(&states.aura.current_mode)
|
||||
.unwrap_or(&AuraEffect::default())
|
||||
.colour1;
|
||||
|
||||
let c2 = states
|
||||
.aura
|
||||
.modes
|
||||
.get(&states.aura.current_mode)
|
||||
.unwrap_or(&AuraEffect::default())
|
||||
.colour2;
|
||||
|
||||
let mut colour = Color32::from_rgb(c1.0, c1.1, c1.2);
|
||||
if states.aura.current_mode == AuraModeNum::Pulse {
|
||||
colour = Color32::from_rgb(
|
||||
(red * c1.0 as u32 / 100) as u8,
|
||||
(red * c1.1 as u32 / 100) as u8,
|
||||
(red * c1.2 as u32 / 100) as u8,
|
||||
);
|
||||
} else if states.aura.current_mode == AuraModeNum::Breathe {
|
||||
if self.oscillator_toggle.load(Ordering::SeqCst) {
|
||||
colour = Color32::from_rgb(
|
||||
(red * c2.0 as u32 / 100) as u8,
|
||||
(red * c2.1 as u32 / 100) as u8,
|
||||
(red * c2.2 as u32 / 100) as u8,
|
||||
);
|
||||
} else {
|
||||
colour = Color32::from_rgb(
|
||||
(red * c1.0 as u32 / 100) as u8,
|
||||
(red * c1.1 as u32 / 100) as u8,
|
||||
(red * c1.2 as u32 / 100) as u8,
|
||||
);
|
||||
}
|
||||
} else if states.aura.current_mode == AuraModeNum::Strobe {
|
||||
colour = Color32::from_rgb(
|
||||
(red * 255 / 100) as u8,
|
||||
(green * 255 / 100) as u8,
|
||||
(blue * 255 / 100) as u8,
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: animation of colour changes/periods/blending
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
aura_modes_group(supported, states, oscillator_freq, dbus, ui);
|
||||
|
||||
keyboard(ui, &states.keyboard_layout, &mut states.aura, colour);
|
||||
});
|
||||
|
||||
// Only do repaint request if on this page
|
||||
ctx.request_repaint_after(Duration::from_millis(33));
|
||||
}
|
||||
}
|
||||
89
rog-control-center/src/pages/fan_curve_page.rs
Normal file
89
rog-control-center/src/pages/fan_curve_page.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
use crate::{
|
||||
page_states::{FanCurvesState, ProfilesState},
|
||||
widgets::fan_graphs,
|
||||
RogApp, RogDbusClientBlocking,
|
||||
};
|
||||
use egui::Ui;
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
use rog_profiles::Profile;
|
||||
|
||||
impl<'a> RogApp<'a> {
|
||||
pub fn fan_curve_page(&mut self, ctx: &egui::Context) {
|
||||
let Self {
|
||||
supported,
|
||||
states,
|
||||
asus_dbus: dbus,
|
||||
..
|
||||
} = self;
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Custom fan curves");
|
||||
ui.label("A fan curve is only active when the related profile is active and the curve is enabled");
|
||||
Self::fan_curve(
|
||||
supported,
|
||||
&mut states.profiles,
|
||||
&mut states.fan_curves,
|
||||
dbus, &mut states.error,
|
||||
ui,
|
||||
);
|
||||
|
||||
fan_graphs(supported, &mut states.profiles, &mut states.fan_curves, dbus, &mut states.error, ui);
|
||||
});
|
||||
}
|
||||
|
||||
fn fan_curve(
|
||||
supported: &SupportedFunctions,
|
||||
profiles: &mut ProfilesState,
|
||||
curves: &mut FanCurvesState,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
do_error: &mut Option<String>,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
ui.separator();
|
||||
ui.label("Enabled fan-curves");
|
||||
|
||||
let mut changed = false;
|
||||
ui.horizontal(|ui| {
|
||||
let mut item = |p: Profile, curves: &mut FanCurvesState, mut checked: bool| {
|
||||
if ui
|
||||
.add(egui::Checkbox::new(&mut checked, format!("{:?}", p)))
|
||||
.changed()
|
||||
{
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
.set_fan_curve_enabled(p, checked)
|
||||
.map_err(|err| {
|
||||
*do_error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
|
||||
if !checked {
|
||||
curves.enabled.remove(&p);
|
||||
} else {
|
||||
curves.enabled.insert(p);
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
};
|
||||
|
||||
profiles.list.sort();
|
||||
for f in profiles.list.iter() {
|
||||
item(*f, curves, curves.enabled.contains(f));
|
||||
}
|
||||
});
|
||||
|
||||
if changed {
|
||||
let selected_profile = curves.show_curve;
|
||||
let selected_pu = curves.show_graph;
|
||||
|
||||
let notif = curves.was_notified.clone();
|
||||
match FanCurvesState::new(notif, supported, dbus) {
|
||||
Ok(f) => *curves = f,
|
||||
Err(e) => *do_error = Some(e.to_string()),
|
||||
}
|
||||
|
||||
curves.show_curve = selected_profile;
|
||||
curves.show_graph = selected_pu;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
rog-control-center/src/pages/mod.rs
Normal file
9
rog-control-center/src/pages/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
mod anime_page;
|
||||
mod aura_page;
|
||||
mod fan_curve_page;
|
||||
mod system_page;
|
||||
|
||||
pub use anime_page::*;
|
||||
pub use aura_page::*;
|
||||
pub use fan_curve_page::*;
|
||||
pub use system_page::*;
|
||||
68
rog-control-center/src/pages/system_page.rs
Normal file
68
rog-control-center/src/pages/system_page.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use crate::{
|
||||
widgets::{
|
||||
anime_power_group, app_settings, aura_power_group, platform_profile, rog_bios_group,
|
||||
},
|
||||
RogApp,
|
||||
};
|
||||
|
||||
impl<'a> RogApp<'a> {
|
||||
pub fn system_page(&mut self, ctx: &egui::Context) {
|
||||
let Self {
|
||||
config,
|
||||
supported,
|
||||
states,
|
||||
asus_dbus: dbus,
|
||||
..
|
||||
} = self;
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Experimental application for asusd");
|
||||
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
ui.spacing_mut().item_spacing = egui::vec2(8.0, 10.0);
|
||||
let rect = ui.available_rect_before_wrap();
|
||||
egui::Grid::new("grid_of_bits")
|
||||
.min_col_width(rect.width() / 2.0)
|
||||
.show(ui, |ui| {
|
||||
/******************************************************/
|
||||
ui.vertical(|ui| {
|
||||
ui.separator();
|
||||
app_settings(config, states, ui);
|
||||
});
|
||||
|
||||
ui.vertical(|ui| {
|
||||
ui.separator();
|
||||
if supported.platform_profile.platform_profile {
|
||||
platform_profile(states, dbus, ui);
|
||||
}
|
||||
});
|
||||
ui.end_row();
|
||||
|
||||
/******************************************************/
|
||||
ui.vertical(|ui| {
|
||||
ui.separator();
|
||||
aura_power_group(supported, states, dbus, ui);
|
||||
});
|
||||
|
||||
ui.vertical(|ui| {
|
||||
ui.separator();
|
||||
rog_bios_group(supported, states, dbus, ui);
|
||||
});
|
||||
ui.end_row();
|
||||
|
||||
/******************************************************/
|
||||
ui.vertical(|ui| {
|
||||
ui.separator();
|
||||
if supported.anime_ctrl.0 {
|
||||
anime_power_group(supported, states, dbus, ui);
|
||||
}
|
||||
});
|
||||
ui.vertical(|ui| {
|
||||
ui.separator();
|
||||
});
|
||||
ui.end_row();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
36
rog-control-center/src/startup_error.rs
Normal file
36
rog-control-center/src/startup_error.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use egui::{Button, RichText};
|
||||
|
||||
pub struct AppErrorShow {
|
||||
error: String,
|
||||
}
|
||||
|
||||
impl AppErrorShow {
|
||||
pub fn new(error: String) -> Self {
|
||||
Self { error }
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for AppErrorShow {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("ROG ERROR");
|
||||
|
||||
ui.centered_and_justified(|ui| {
|
||||
ui.label(RichText::new(format!("The error was: {:?}", self.error)).size(22.0));
|
||||
});
|
||||
|
||||
egui::TopBottomPanel::bottom("error_bar_2")
|
||||
.default_height(26.0)
|
||||
.show(ctx, |ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
||||
if ui
|
||||
.add(Button::new(RichText::new("Okay").size(20.0)))
|
||||
.clicked()
|
||||
{
|
||||
frame.quit();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
73
rog-control-center/src/widgets/anime_power.rs
Normal file
73
rog-control-center/src/widgets/anime_power.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
use egui::{RichText, Ui};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
|
||||
use crate::{page_states::PageDataStates, RogDbusClientBlocking};
|
||||
|
||||
pub fn anime_power_group(
|
||||
_supported: &SupportedFunctions,
|
||||
states: &mut PageDataStates,
|
||||
dbus: &mut RogDbusClientBlocking,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
ui.heading("AniMe Matrix Settings");
|
||||
ui.label("Options are incomplete. Awake + Boot should work");
|
||||
|
||||
let mut changed = false;
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
let h = 16.0;
|
||||
ui.set_row_height(22.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Brightness").size(h));
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Boot").size(h));
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Awake").size(h));
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Sleep").size(h));
|
||||
});
|
||||
});
|
||||
ui.vertical(|ui| {
|
||||
ui.set_row_height(22.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui
|
||||
.add(egui::Slider::new(&mut states.anime.bright, 0..=254))
|
||||
.changed()
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui.checkbox(&mut states.anime.boot, "Enable").changed() {
|
||||
dbus.proxies()
|
||||
.anime()
|
||||
.set_boot_on_off(states.anime.boot)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui.checkbox(&mut states.anime.awake, "Enable").changed() {
|
||||
dbus.proxies()
|
||||
.anime()
|
||||
.set_on_off(states.anime.awake)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui.checkbox(&mut states.anime.sleep, "Enable").changed() {
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
31
rog-control-center/src/widgets/app_settings.rs
Normal file
31
rog-control-center/src/widgets/app_settings.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use egui::Ui;
|
||||
|
||||
use crate::{config::Config, page_states::PageDataStates};
|
||||
|
||||
pub fn app_settings(config: &mut Config, states: &mut PageDataStates, ui: &mut Ui) {
|
||||
ui.heading("ROG GUI Settings");
|
||||
// ui.label("Options are incomplete. Awake + Boot should work");
|
||||
|
||||
if ui
|
||||
.checkbox(&mut config.run_in_background, "Run in Background")
|
||||
.clicked()
|
||||
|| ui
|
||||
.checkbox(&mut config.startup_in_background, "Startup Hidden")
|
||||
.clicked()
|
||||
|| ui
|
||||
.checkbox(&mut config.enable_notifications, "Enable Notifications")
|
||||
.clicked()
|
||||
{
|
||||
states
|
||||
.notifs_enabled
|
||||
.store(config.enable_notifications, Ordering::SeqCst);
|
||||
config
|
||||
.save()
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
213
rog-control-center/src/widgets/aura_modes.rs
Normal file
213
rog-control-center/src/widgets/aura_modes.rs
Normal file
@@ -0,0 +1,213 @@
|
||||
use std::sync::{
|
||||
atomic::{AtomicU8, Ordering},
|
||||
Arc,
|
||||
};
|
||||
|
||||
use egui::{RichText, Ui};
|
||||
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour, Speed};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
|
||||
use crate::{
|
||||
page_states::{AuraState, PageDataStates},
|
||||
RogDbusClientBlocking,
|
||||
};
|
||||
|
||||
pub fn aura_modes_group(
|
||||
supported: &SupportedFunctions,
|
||||
states: &mut PageDataStates,
|
||||
freq: &mut Arc<AtomicU8>,
|
||||
dbus: &mut RogDbusClientBlocking,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
let mut changed = false;
|
||||
let mut selected = states.aura.current_mode;
|
||||
let allowed = AuraEffect::allowed_parameters(selected);
|
||||
|
||||
let has_keyzones = supported
|
||||
.keyboard_led
|
||||
.multizone_led_mode
|
||||
.contains(&AuraZone::Key2);
|
||||
let has_logo = supported
|
||||
.keyboard_led
|
||||
.multizone_led_mode
|
||||
.contains(&AuraZone::Logo);
|
||||
let has_lightbar = supported
|
||||
.keyboard_led
|
||||
.multizone_led_mode
|
||||
.contains(&AuraZone::BarLeft)
|
||||
|| supported
|
||||
.keyboard_led
|
||||
.multizone_led_mode
|
||||
.contains(&AuraZone::BarRight);
|
||||
|
||||
ui.heading("Aura modes");
|
||||
let mut item = |a: AuraModeNum, ui: &mut Ui| {
|
||||
if ui
|
||||
.selectable_value(&mut selected, a, format!("{:?}", a))
|
||||
.clicked()
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
};
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for a in states.aura.modes.keys() {
|
||||
item(*a, ui);
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(effect) = states.aura.modes.get_mut(&selected) {
|
||||
let mut zone_button = |a: AuraZone, ui: &mut Ui| {
|
||||
ui.selectable_value(&mut effect.zone, a, format!("{:?}", a));
|
||||
};
|
||||
let mut speed_button = |a: Speed, ui: &mut Ui| {
|
||||
if ui
|
||||
.selectable_value(&mut effect.speed, a, format!("{:?}", a))
|
||||
.clicked()
|
||||
{
|
||||
let val = match effect.speed {
|
||||
Speed::Low => 6,
|
||||
Speed::Med => 8,
|
||||
Speed::High => 10,
|
||||
};
|
||||
freq.store(val, Ordering::SeqCst);
|
||||
}
|
||||
};
|
||||
let mut dir_button = |a: rog_aura::Direction, ui: &mut Ui| {
|
||||
ui.selectable_value(&mut effect.direction, a, format!("{:?}", a));
|
||||
};
|
||||
|
||||
let mut c1: [u8; 3] = effect.colour1.into();
|
||||
let mut c2: [u8; 3] = effect.colour2.into();
|
||||
|
||||
ui.separator();
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
let h = 16.0;
|
||||
ui.set_row_height(22.0);
|
||||
ui.add_enabled_ui(allowed.zone, |ui| {
|
||||
if has_keyzones || has_lightbar || has_logo {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Zone").size(h));
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.add_enabled_ui(allowed.colour1, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Colour 1").size(h));
|
||||
});
|
||||
});
|
||||
ui.add_enabled_ui(allowed.colour2, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Colour 2").size(h));
|
||||
});
|
||||
});
|
||||
ui.add_enabled_ui(allowed.speed, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.set_enabled(allowed.speed);
|
||||
ui.label(RichText::new("Speed").size(h));
|
||||
});
|
||||
});
|
||||
ui.add_enabled_ui(allowed.direction, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.set_enabled(allowed.direction);
|
||||
ui.label(RichText::new("Direction").size(h));
|
||||
});
|
||||
});
|
||||
ui.set_enabled(true);
|
||||
});
|
||||
ui.vertical(|ui| {
|
||||
ui.set_row_height(22.0);
|
||||
ui.add_enabled_ui(allowed.zone, |ui| {
|
||||
if has_keyzones || has_lightbar || has_logo {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
zone_button(AuraZone::None, ui);
|
||||
if has_keyzones {
|
||||
zone_button(AuraZone::Key1, ui);
|
||||
zone_button(AuraZone::Key2, ui);
|
||||
zone_button(AuraZone::Key3, ui);
|
||||
zone_button(AuraZone::Key4, ui);
|
||||
}
|
||||
if has_logo {
|
||||
zone_button(AuraZone::Logo, ui);
|
||||
}
|
||||
if has_lightbar {
|
||||
zone_button(AuraZone::BarLeft, ui);
|
||||
zone_button(AuraZone::BarRight, ui);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_enabled_ui(allowed.colour1, |ui| {
|
||||
egui::color_picker::color_edit_button_srgb(ui, &mut c1)
|
||||
});
|
||||
ui.add_enabled_ui(allowed.colour2, |ui| {
|
||||
egui::color_picker::color_edit_button_srgb(ui, &mut c2)
|
||||
});
|
||||
|
||||
ui.add_enabled_ui(allowed.speed, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
speed_button(Speed::Low, ui);
|
||||
speed_button(Speed::Med, ui);
|
||||
speed_button(Speed::High, ui);
|
||||
});
|
||||
});
|
||||
|
||||
ui.add_enabled_ui(allowed.direction, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
dir_button(rog_aura::Direction::Left, ui);
|
||||
dir_button(rog_aura::Direction::Down, ui);
|
||||
dir_button(rog_aura::Direction::Right, ui);
|
||||
dir_button(rog_aura::Direction::Up, ui);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
effect.colour1 = Colour::from(&c1);
|
||||
effect.colour2 = Colour::from(&c2);
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
||||
if ui.add(egui::Button::new("Cancel")).clicked() {
|
||||
let notif = states.aura.was_notified.clone();
|
||||
match AuraState::new(notif, supported, dbus) {
|
||||
Ok(a) => states.aura.modes = a.modes,
|
||||
Err(e) => states.error = Some(e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
if ui.add(egui::Button::new("Apply")).clicked() {
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
|
||||
// egui::TopBottomPanel::bottom("error_bar")
|
||||
// .default_height(26.0)
|
||||
// .show(ctx, |ui| {
|
||||
// ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
||||
// if ui.add(egui::Button::new("Cancel")).clicked() {
|
||||
// let notif = states.aura.was_notified.clone();
|
||||
// states.aura.modes = AuraState::new(notif, supported, dbus).modes;
|
||||
// }
|
||||
|
||||
// if ui.add(egui::Button::new("Apply")).clicked() {
|
||||
// changed = true;
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
|
||||
if changed {
|
||||
states.aura.current_mode = selected;
|
||||
|
||||
dbus.proxies()
|
||||
.led()
|
||||
.set_led_mode(states.aura.modes.get(&selected).unwrap())
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
345
rog-control-center/src/widgets/aura_power.rs
Normal file
345
rog-control-center/src/widgets/aura_power.rs
Normal file
@@ -0,0 +1,345 @@
|
||||
use egui::{RichText, Ui};
|
||||
use rog_aura::{
|
||||
usb::{AuraDev1866, AuraDev19b6, AuraDevTuf, AuraDevice, AuraPowerDev},
|
||||
AuraZone,
|
||||
};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
|
||||
use crate::{page_states::PageDataStates, RogDbusClientBlocking};
|
||||
|
||||
pub fn aura_power_group(
|
||||
supported: &SupportedFunctions,
|
||||
states: &mut PageDataStates,
|
||||
dbus: &mut RogDbusClientBlocking,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
ui.heading("LED settings");
|
||||
|
||||
match supported.keyboard_led.prod_id {
|
||||
AuraDevice::X1854 | AuraDevice::X1869 | AuraDevice::X1866 => {
|
||||
aura_power1(supported, states, dbus, ui)
|
||||
}
|
||||
AuraDevice::X19B6 => aura_power2(supported, states, dbus, ui),
|
||||
AuraDevice::Tuf => aura_power1(supported, states, dbus, ui),
|
||||
AuraDevice::Unknown => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn aura_power1(
|
||||
supported: &SupportedFunctions,
|
||||
states: &mut PageDataStates,
|
||||
dbus: &mut RogDbusClientBlocking,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
let enabled_states = &mut states.aura.enabled;
|
||||
let mut boot = enabled_states.x1866.contains(&AuraDev1866::Boot);
|
||||
let mut sleep = enabled_states.x1866.contains(&AuraDev1866::Sleep);
|
||||
let mut keyboard = enabled_states.x1866.contains(&AuraDev1866::Keyboard);
|
||||
let mut lightbar = enabled_states.x1866.contains(&AuraDev1866::Lightbar);
|
||||
if supported.keyboard_led.prod_id == AuraDevice::Tuf {
|
||||
boot = enabled_states.tuf.contains(&AuraDevTuf::Boot);
|
||||
sleep = enabled_states.tuf.contains(&AuraDevTuf::Sleep);
|
||||
keyboard = enabled_states.tuf.contains(&AuraDevTuf::Awake);
|
||||
}
|
||||
let mut changed = false;
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
let h = 16.0;
|
||||
ui.set_row_height(22.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Boot").size(h));
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Awake").size(h));
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Sleep").size(h));
|
||||
});
|
||||
// if supported.keyboard_led.brightness_set {
|
||||
// ui.horizontal_wrapped(|ui| {
|
||||
// ui.label(RichText::new("Brightness").size(h));
|
||||
// });
|
||||
// }
|
||||
});
|
||||
ui.vertical(|ui| {
|
||||
ui.set_row_height(22.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui.checkbox(&mut boot, "Enable").changed() {
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui.toggle_value(&mut keyboard, "Keyboard").changed() {
|
||||
changed = true;
|
||||
}
|
||||
if !supported.keyboard_led.multizone_led_mode.is_empty() {
|
||||
if ui.toggle_value(&mut lightbar, "Lightbar").changed() {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui.checkbox(&mut sleep, "Enable").changed() {
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
|
||||
// We currently don't have a watch for system changes here
|
||||
// if supported.keyboard_led.brightness_set {
|
||||
// if ui
|
||||
// .add(egui::Slider::new(
|
||||
// &mut states.aura.bright,
|
||||
// 0..=3,
|
||||
// ))
|
||||
// .changed()
|
||||
// {
|
||||
// let bright = LedBrightness::from(states.aura.bright as u32);
|
||||
// dbus.proxies()
|
||||
// .led()
|
||||
// .set_brightness(bright)
|
||||
// .map_err(|err| {
|
||||
// states.error = Some(err.to_string());
|
||||
// })
|
||||
// .ok();
|
||||
// }
|
||||
// }
|
||||
});
|
||||
});
|
||||
|
||||
if changed {
|
||||
if supported.keyboard_led.prod_id == AuraDevice::Tuf {
|
||||
let mut enabled = Vec::new();
|
||||
let mut disabled = Vec::new();
|
||||
|
||||
let mut modify_tuf = |b: bool, a: AuraDevTuf| {
|
||||
if b {
|
||||
enabled.push(a);
|
||||
if !enabled_states.tuf.contains(&a) {
|
||||
enabled_states.tuf.push(a);
|
||||
}
|
||||
} else {
|
||||
disabled.push(a);
|
||||
// This would be so much better as a hashset
|
||||
if enabled_states.tuf.contains(&a) {
|
||||
let mut idx = 0;
|
||||
for (i, n) in enabled_states.tuf.iter().enumerate() {
|
||||
if *n == a {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
enabled_states.tuf.remove(idx);
|
||||
}
|
||||
}
|
||||
};
|
||||
modify_tuf(boot, AuraDevTuf::Boot);
|
||||
modify_tuf(sleep, AuraDevTuf::Sleep);
|
||||
modify_tuf(keyboard, AuraDevTuf::Awake);
|
||||
|
||||
let mut send = |enable: bool, data: Vec<AuraDevTuf>| {
|
||||
let options = AuraPowerDev {
|
||||
tuf: data,
|
||||
x1866: vec![],
|
||||
x19b6: vec![],
|
||||
};
|
||||
// build data to send
|
||||
dbus.proxies()
|
||||
.led()
|
||||
.set_leds_power(options, enable)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
};
|
||||
send(true, enabled);
|
||||
send(false, disabled);
|
||||
} else {
|
||||
let mut enabled = Vec::new();
|
||||
let mut disabled = Vec::new();
|
||||
|
||||
let mut modify_x1866 = |b: bool, a: AuraDev1866| {
|
||||
if b {
|
||||
enabled.push(a);
|
||||
if !enabled_states.x1866.contains(&a) {
|
||||
enabled_states.x1866.push(a);
|
||||
}
|
||||
} else {
|
||||
disabled.push(a);
|
||||
// This would be so much better as a hashset
|
||||
if enabled_states.x1866.contains(&a) {
|
||||
let mut idx = 0;
|
||||
for (i, n) in enabled_states.x1866.iter().enumerate() {
|
||||
if *n == a {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
enabled_states.x1866.remove(idx);
|
||||
}
|
||||
}
|
||||
};
|
||||
modify_x1866(boot, AuraDev1866::Boot);
|
||||
modify_x1866(sleep, AuraDev1866::Sleep);
|
||||
modify_x1866(keyboard, AuraDev1866::Keyboard);
|
||||
if !supported.keyboard_led.multizone_led_mode.is_empty() {
|
||||
modify_x1866(lightbar, AuraDev1866::Lightbar);
|
||||
}
|
||||
|
||||
let mut send = |enable: bool, data: Vec<AuraDev1866>| {
|
||||
let options = AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: data,
|
||||
x19b6: vec![],
|
||||
};
|
||||
// build data to send
|
||||
dbus.proxies()
|
||||
.led()
|
||||
.set_leds_power(options, enable)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
};
|
||||
send(true, enabled);
|
||||
send(false, disabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn aura_power2(
|
||||
supported: &SupportedFunctions,
|
||||
states: &mut PageDataStates,
|
||||
dbus: &mut RogDbusClientBlocking,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
let enabled_states = &mut states.aura.enabled;
|
||||
let has_logo = supported
|
||||
.keyboard_led
|
||||
.multizone_led_mode
|
||||
.contains(&AuraZone::Logo);
|
||||
let has_lightbar = supported
|
||||
.keyboard_led
|
||||
.multizone_led_mode
|
||||
.contains(&AuraZone::BarLeft)
|
||||
|| supported
|
||||
.keyboard_led
|
||||
.multizone_led_mode
|
||||
.contains(&AuraZone::BarRight);
|
||||
|
||||
let boot_bar = &mut enabled_states.x19b6.contains(&AuraDev19b6::AwakeBar);
|
||||
let boot_logo = &mut enabled_states.x19b6.contains(&AuraDev19b6::BootLogo);
|
||||
let boot_keyb = &mut enabled_states.x19b6.contains(&AuraDev19b6::BootKeyb);
|
||||
|
||||
let awake_bar = &mut enabled_states.x19b6.contains(&AuraDev19b6::BootBar);
|
||||
let awake_logo = &mut enabled_states.x19b6.contains(&AuraDev19b6::AwakeLogo);
|
||||
let awake_keyb = &mut enabled_states.x19b6.contains(&AuraDev19b6::AwakeKeyb);
|
||||
|
||||
let sleep_bar = &mut enabled_states.x19b6.contains(&AuraDev19b6::SleepBar);
|
||||
let sleep_logo = &mut enabled_states.x19b6.contains(&AuraDev19b6::SleepLogo);
|
||||
let sleep_keyb = &mut enabled_states.x19b6.contains(&AuraDev19b6::SleepKeyb);
|
||||
|
||||
let mut changed = false;
|
||||
|
||||
let mut item = |keyboard: &mut bool, logo: &mut bool, lightbar: &mut bool, ui: &mut Ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
if ui.checkbox(keyboard, "Keyboard").changed() {
|
||||
changed = true;
|
||||
}
|
||||
if has_logo && ui.checkbox(logo, "Logo").changed() {
|
||||
changed = true;
|
||||
}
|
||||
if has_lightbar && ui.checkbox(lightbar, "Lightbar").changed() {
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
let h = 16.0;
|
||||
ui.set_row_height(22.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Boot").size(h));
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Awake").size(h));
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label(RichText::new("Sleep").size(h));
|
||||
});
|
||||
});
|
||||
ui.vertical(|ui| {
|
||||
ui.set_row_height(22.0);
|
||||
item(boot_keyb, boot_logo, boot_bar, ui);
|
||||
item(awake_keyb, awake_logo, awake_bar, ui);
|
||||
item(sleep_keyb, sleep_logo, sleep_bar, ui);
|
||||
});
|
||||
});
|
||||
|
||||
if changed {
|
||||
let mut enabled = Vec::new();
|
||||
let mut disabled = Vec::new();
|
||||
|
||||
let mut modify = |b: bool, a: AuraDev19b6| {
|
||||
if b {
|
||||
enabled.push(a);
|
||||
if !enabled_states.x19b6.contains(&a) {
|
||||
enabled_states.x19b6.push(a);
|
||||
}
|
||||
} else {
|
||||
disabled.push(a);
|
||||
// This would be so much better as a hashset
|
||||
if enabled_states.x19b6.contains(&a) {
|
||||
let mut idx = 0;
|
||||
for (i, n) in enabled_states.x19b6.iter().enumerate() {
|
||||
if *n == a {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
enabled_states.x19b6.remove(idx);
|
||||
}
|
||||
}
|
||||
};
|
||||
modify(*boot_keyb, AuraDev19b6::BootKeyb);
|
||||
modify(*sleep_keyb, AuraDev19b6::SleepKeyb);
|
||||
modify(*awake_keyb, AuraDev19b6::AwakeKeyb);
|
||||
if supported
|
||||
.keyboard_led
|
||||
.multizone_led_mode
|
||||
.contains(&AuraZone::Logo)
|
||||
{
|
||||
modify(*boot_logo, AuraDev19b6::BootLogo);
|
||||
modify(*sleep_logo, AuraDev19b6::SleepLogo);
|
||||
modify(*awake_logo, AuraDev19b6::AwakeLogo);
|
||||
}
|
||||
if supported
|
||||
.keyboard_led
|
||||
.multizone_led_mode
|
||||
.contains(&AuraZone::BarLeft)
|
||||
{
|
||||
modify(*boot_bar, AuraDev19b6::AwakeBar);
|
||||
modify(*sleep_bar, AuraDev19b6::SleepBar);
|
||||
modify(*awake_bar, AuraDev19b6::BootBar);
|
||||
}
|
||||
|
||||
let mut send = |enable: bool, data: Vec<AuraDev19b6>| {
|
||||
let options = AuraPowerDev {
|
||||
tuf: vec![],
|
||||
x1866: vec![],
|
||||
x19b6: data,
|
||||
};
|
||||
// build data to send
|
||||
dbus.proxies()
|
||||
.led()
|
||||
.set_leds_power(options, enable)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
};
|
||||
send(true, enabled);
|
||||
send(false, disabled);
|
||||
}
|
||||
}
|
||||
145
rog-control-center/src/widgets/fan_graph.rs
Normal file
145
rog-control-center/src/widgets/fan_graph.rs
Normal file
@@ -0,0 +1,145 @@
|
||||
use egui::{plot::Points, Ui};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
use rog_profiles::{FanCurvePU, Profile};
|
||||
|
||||
use crate::{
|
||||
page_states::{FanCurvesState, ProfilesState},
|
||||
RogDbusClientBlocking,
|
||||
};
|
||||
|
||||
pub fn fan_graphs(
|
||||
supported: &SupportedFunctions,
|
||||
profiles: &mut ProfilesState,
|
||||
curves: &mut FanCurvesState,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
do_error: &mut Option<String>,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
ui.separator();
|
||||
|
||||
let mut item = |p: Profile, ui: &mut Ui| {
|
||||
ui.group(|ui| {
|
||||
ui.selectable_value(&mut curves.show_curve, p, format!("{p:?}"));
|
||||
ui.add_enabled_ui(curves.show_curve == p, |ui| {
|
||||
ui.selectable_value(
|
||||
&mut curves.show_graph,
|
||||
FanCurvePU::CPU,
|
||||
format!("{:?}", FanCurvePU::CPU),
|
||||
);
|
||||
ui.selectable_value(
|
||||
&mut curves.show_graph,
|
||||
FanCurvePU::GPU,
|
||||
format!("{:?}", FanCurvePU::GPU),
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for a in curves.curves.iter() {
|
||||
item(*a.0, ui);
|
||||
}
|
||||
});
|
||||
|
||||
let curve = curves.curves.get_mut(&curves.show_curve).unwrap();
|
||||
|
||||
use egui::plot::{Line, Plot, PlotPoints};
|
||||
|
||||
let data = if curves.show_graph == FanCurvePU::CPU {
|
||||
&mut curve.cpu
|
||||
} else {
|
||||
&mut curve.gpu
|
||||
};
|
||||
|
||||
let points = data.temp.iter().enumerate().map(|(idx, x)| {
|
||||
let x = *x as f64;
|
||||
let y = ((data.pwm[idx] as u32) * 100 / 255) as f64;
|
||||
[x, y]
|
||||
});
|
||||
|
||||
let line = Line::new(PlotPoints::from_iter(points.clone())).width(2.0);
|
||||
let points = Points::new(PlotPoints::from_iter(points)).radius(3.0);
|
||||
|
||||
Plot::new("fan_curves")
|
||||
.view_aspect(1.666)
|
||||
// .center_x_axis(true)
|
||||
// .center_y_axis(true)
|
||||
.include_x(0.0)
|
||||
.include_x(104.0)
|
||||
.include_y(0.0)
|
||||
.include_y(106.0)
|
||||
.allow_scroll(false)
|
||||
.allow_drag(false)
|
||||
.allow_boxed_zoom(false)
|
||||
.x_axis_formatter(|d, _r| format!("{}", d))
|
||||
.y_axis_formatter(|d, _r| format!("{:.*}%", 1, d))
|
||||
.label_formatter(|name, value| {
|
||||
if !name.is_empty() {
|
||||
format!("{}: {:.*}%", name, 1, value.y)
|
||||
} else {
|
||||
format!("Temp {}c\nFan {:.*}%", value.x as u8, 1, value.y)
|
||||
}
|
||||
})
|
||||
.show(ui, |plot_ui| {
|
||||
if plot_ui.plot_hovered() {
|
||||
let mut idx = 0;
|
||||
|
||||
if let Some(point) = plot_ui.pointer_coordinate() {
|
||||
let mut x: i32 = 255;
|
||||
for (i, n) in data.temp.iter().enumerate() {
|
||||
let tmp = x.min((point.x as i32 - *n as i32).abs());
|
||||
if tmp < x {
|
||||
x = tmp;
|
||||
idx = i;
|
||||
}
|
||||
}
|
||||
|
||||
if plot_ui.plot_clicked() {
|
||||
data.temp[idx] = point.x as u8;
|
||||
data.pwm[idx] = (point.y * 255.0 / 100.0) as u8;
|
||||
} else {
|
||||
let drag = plot_ui.pointer_coordinate_drag_delta();
|
||||
if drag.length_sq() != 0.0 {
|
||||
data.temp[idx] = (point.x as f32 + drag.x) as u8;
|
||||
data.pwm[idx] = ((point.y as f32 + drag.y) * 255.0 / 100.0) as u8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plot_ui.line(line);
|
||||
plot_ui.points(points)
|
||||
});
|
||||
|
||||
let mut set = false;
|
||||
let mut reset = false;
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
||||
set = ui.add(egui::Button::new("Apply Fan-curve")).clicked();
|
||||
reset = ui.add(egui::Button::new("Reset Profile")).clicked();
|
||||
});
|
||||
|
||||
if set {
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
.set_fan_curve(profiles.current, data.clone())
|
||||
.map_err(|err| {
|
||||
*do_error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
if reset {
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
.reset_profile_curves(profiles.current)
|
||||
.map_err(|err| {
|
||||
*do_error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
|
||||
let notif = curves.was_notified.clone();
|
||||
match FanCurvesState::new(notif, supported, dbus) {
|
||||
Ok(f) => *curves = f,
|
||||
Err(e) => *do_error = Some(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
123
rog-control-center/src/widgets/keyboard_layout.rs
Normal file
123
rog-control-center/src/widgets/keyboard_layout.rs
Normal file
@@ -0,0 +1,123 @@
|
||||
use egui::{Align, Color32, Vec2};
|
||||
use rog_aura::{keys::KeyShape, layouts::KeyLayout, AuraModeNum};
|
||||
|
||||
use crate::page_states::AuraState;
|
||||
|
||||
pub fn keyboard(
|
||||
ui: &mut egui::Ui,
|
||||
keyboard_layout: &KeyLayout,
|
||||
states: &mut AuraState,
|
||||
mut colour: Color32,
|
||||
) {
|
||||
ui.spacing_mut().item_spacing = egui::vec2(0.0, 0.0);
|
||||
let mut arrows_done = false;
|
||||
let mut rog_done = false;
|
||||
for row in keyboard_layout.rows() {
|
||||
ui.horizontal_top(|ui| {
|
||||
for (i, key) in row.row().enumerate() {
|
||||
if states.current_mode == AuraModeNum::Rainbow {
|
||||
colour = Color32::from_rgb(
|
||||
(states.wave_red[i] as u32 * 255 / 100) as u8,
|
||||
(states.wave_green[i] as u32 * 255 / 100) as u8,
|
||||
(states.wave_blue[i] as u32 * 255 / 100) as u8,
|
||||
);
|
||||
}
|
||||
// your boat
|
||||
let height = if rog_done {
|
||||
row.height()
|
||||
} else {
|
||||
// Use the first item (always a blank) to stand off the row
|
||||
rog_done = true;
|
||||
1.2
|
||||
};
|
||||
let shape = KeyShape::from(key);
|
||||
|
||||
let label = <&str>::from(key);
|
||||
if shape.is_arrow_cluster() {
|
||||
if !arrows_done {
|
||||
arrow_cluster(ui, colour);
|
||||
arrows_done = true;
|
||||
}
|
||||
} else if shape.is_blank() || shape.is_spacer() {
|
||||
blank(ui, shape.width(), height);
|
||||
} else if shape.is_group() {
|
||||
key_group(ui, colour, shape.width(), height).on_hover_text(label);
|
||||
} else {
|
||||
key_shape(ui, colour, shape.width(), height).on_hover_text(label);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn key_shape(ui: &mut egui::Ui, colour: Color32, ux: f32, uy: f32) -> egui::Response {
|
||||
let desired_size = ui.spacing().interact_size.y * egui::vec2(2.0 * ux, 2.0 * uy);
|
||||
let (mut rect, mut response) = ui.allocate_exact_size(desired_size, egui::Sense::click());
|
||||
rect = rect.shrink(3.0);
|
||||
if response.clicked() {
|
||||
response.mark_changed();
|
||||
}
|
||||
response.widget_info(|| {
|
||||
egui::WidgetInfo::selected(egui::WidgetType::Checkbox, response.clicked(), "")
|
||||
});
|
||||
|
||||
if ui.is_rect_visible(rect) {
|
||||
let visuals = ui.style().interact_selectable(&response, true);
|
||||
let rect = rect.expand(visuals.expansion);
|
||||
ui.painter().rect(rect, 0.1, colour, visuals.fg_stroke);
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
|
||||
fn key_group(ui: &mut egui::Ui, colour: Color32, ux: f32, uy: f32) -> egui::Response {
|
||||
let desired_size = ui.spacing().interact_size.y * egui::vec2(2.0 * ux, 2.0 * uy);
|
||||
let (mut rect, mut response) = ui.allocate_exact_size(desired_size, egui::Sense::click());
|
||||
rect = rect.shrink2(Vec2::new(3.0, 3.0));
|
||||
if response.clicked() {
|
||||
response.mark_changed();
|
||||
}
|
||||
response.widget_info(|| {
|
||||
egui::WidgetInfo::selected(egui::WidgetType::Checkbox, response.clicked(), "")
|
||||
});
|
||||
|
||||
if ui.is_rect_visible(rect) {
|
||||
let visuals = ui.style().interact_selectable(&response, true);
|
||||
let rect = rect.expand(visuals.expansion);
|
||||
let mut stroke = visuals.fg_stroke;
|
||||
stroke.color = visuals.bg_fill;
|
||||
ui.painter().rect(rect, 0.1, colour, stroke);
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
|
||||
fn blank(ui: &mut egui::Ui, ux: f32, uy: f32) {
|
||||
let desired_size = ui.spacing().interact_size.y * egui::vec2(2.0 * ux, 2.0 * uy);
|
||||
ui.allocate_exact_size(desired_size, egui::Sense::click());
|
||||
}
|
||||
|
||||
/// Draws entire arrow cluster block. This is visibly different to the split-arrows.
|
||||
fn arrow_cluster(ui: &mut egui::Ui, colour: Color32) {
|
||||
let height = 0.7;
|
||||
let space = KeyShape::ArrowSpacer;
|
||||
let shape = KeyShape::Arrow;
|
||||
ui.horizontal_top(|ui| {
|
||||
ui.with_layout(egui::Layout::top_down(Align::LEFT), |ui| {
|
||||
blank(ui, space.width(), height);
|
||||
ui.horizontal(|ui| {
|
||||
blank(ui, KeyShape::RowEndSpacer.width(), height);
|
||||
blank(ui, KeyShape::RowEndSpacer.width(), height);
|
||||
key_shape(ui, colour, shape.width(), height).on_hover_text("Left");
|
||||
});
|
||||
});
|
||||
ui.with_layout(egui::Layout::top_down(Align::LEFT), |ui| {
|
||||
key_shape(ui, colour, shape.width(), height).on_hover_text("Up");
|
||||
key_shape(ui, colour, shape.width(), height).on_hover_text("Down");
|
||||
});
|
||||
ui.with_layout(egui::Layout::top_down(Align::LEFT), |ui| {
|
||||
blank(ui, space.width(), height);
|
||||
key_shape(ui, colour, shape.width(), height).on_hover_text("Right");
|
||||
});
|
||||
});
|
||||
}
|
||||
19
rog-control-center/src/widgets/mod.rs
Normal file
19
rog-control-center/src/widgets/mod.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
mod anime_power;
|
||||
mod app_settings;
|
||||
mod aura_modes;
|
||||
mod aura_power;
|
||||
mod fan_graph;
|
||||
mod keyboard_layout;
|
||||
mod rog_bios;
|
||||
mod side_panel;
|
||||
mod top_bar;
|
||||
|
||||
pub use anime_power::*;
|
||||
pub use app_settings::*;
|
||||
pub use aura_modes::*;
|
||||
pub use aura_power::*;
|
||||
pub use fan_graph::*;
|
||||
pub use keyboard_layout::*;
|
||||
pub use rog_bios::*;
|
||||
pub use side_panel::*;
|
||||
pub use top_bar::*;
|
||||
127
rog-control-center/src/widgets/rog_bios.rs
Normal file
127
rog-control-center/src/widgets/rog_bios.rs
Normal file
@@ -0,0 +1,127 @@
|
||||
use crate::{page_states::PageDataStates, RogDbusClientBlocking};
|
||||
use egui::Ui;
|
||||
use rog_platform::{platform::GpuMode, supported::SupportedFunctions};
|
||||
use rog_profiles::Profile;
|
||||
|
||||
pub fn platform_profile(states: &mut PageDataStates, dbus: &RogDbusClientBlocking, ui: &mut Ui) {
|
||||
ui.heading("Platform profile");
|
||||
|
||||
let mut changed = false;
|
||||
let mut item = |p: Profile, ui: &mut Ui| {
|
||||
if ui
|
||||
.selectable_value(&mut states.profiles.current, p, format!("{p:?}"))
|
||||
.clicked()
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
};
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for a in states.profiles.list.iter() {
|
||||
item(*a, ui);
|
||||
}
|
||||
});
|
||||
|
||||
if changed {
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
.set_active_profile(states.profiles.current)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
};
|
||||
}
|
||||
|
||||
pub fn rog_bios_group(
|
||||
supported: &SupportedFunctions,
|
||||
states: &mut PageDataStates,
|
||||
dbus: &mut RogDbusClientBlocking,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
ui.heading("Bios options");
|
||||
|
||||
let slider = egui::Slider::new(&mut states.charge_limit, 20..=100)
|
||||
.text("Charging limit")
|
||||
.step_by(1.0);
|
||||
if ui.add(slider).drag_released() {
|
||||
dbus.proxies()
|
||||
.charge()
|
||||
.set_limit(states.charge_limit as u8)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
if supported.rog_bios_ctrl.post_sound {
|
||||
if ui
|
||||
.add(egui::Checkbox::new(
|
||||
&mut states.bios.post_sound,
|
||||
"POST sound",
|
||||
))
|
||||
.changed()
|
||||
{
|
||||
dbus.proxies()
|
||||
.rog_bios()
|
||||
.set_post_boot_sound(states.bios.post_sound)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
if supported.rog_bios_ctrl.post_sound {
|
||||
if ui
|
||||
.add(egui::Checkbox::new(
|
||||
&mut states.bios.panel_overdrive,
|
||||
"Panel overdrive",
|
||||
))
|
||||
.changed()
|
||||
{
|
||||
dbus.proxies()
|
||||
.rog_bios()
|
||||
.set_panel_overdrive(states.bios.panel_overdrive)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
if supported.rog_bios_ctrl.gpu_mux {
|
||||
let mut changed = false;
|
||||
ui.group(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.horizontal_wrapped(|ui| ui.label("GPU MUX mode (reboot required)"));
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
changed = ui
|
||||
.selectable_value(
|
||||
&mut states.bios.dedicated_gfx,
|
||||
GpuMode::Discrete,
|
||||
"Dedicated (Ultimate)",
|
||||
)
|
||||
.clicked()
|
||||
|| ui
|
||||
.selectable_value(
|
||||
&mut states.bios.dedicated_gfx,
|
||||
GpuMode::Optimus,
|
||||
"Optimus (Hybrid)",
|
||||
)
|
||||
.clicked();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if changed {
|
||||
dbus.proxies()
|
||||
.rog_bios()
|
||||
.set_gpu_mux_mode(states.bios.dedicated_gfx)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
64
rog-control-center/src/widgets/side_panel.rs
Normal file
64
rog-control-center/src/widgets/side_panel.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use crate::{Page, RogApp};
|
||||
|
||||
impl<'a> RogApp<'a> {
|
||||
pub fn side_panel(&mut self, ctx: &egui::Context) {
|
||||
egui::SidePanel::left("side_panel")
|
||||
.resizable(false)
|
||||
.default_width(60.0) // TODO: set size to match icon buttons when done
|
||||
.show(ctx, |ui| {
|
||||
let Self { page, .. } = self;
|
||||
|
||||
ui.heading("Functions");
|
||||
|
||||
ui.separator();
|
||||
if ui
|
||||
.selectable_value(page, Page::System, "System Settings")
|
||||
.clicked()
|
||||
{
|
||||
*page = Page::System;
|
||||
}
|
||||
|
||||
if self.supported.platform_profile.fan_curves {
|
||||
ui.separator();
|
||||
if ui
|
||||
.selectable_value(page, Page::FanCurves, "Fan Curves")
|
||||
.clicked()
|
||||
{
|
||||
*page = Page::FanCurves;
|
||||
}
|
||||
}
|
||||
|
||||
if !self.supported.keyboard_led.stock_led_modes.is_empty() {
|
||||
ui.separator();
|
||||
if ui
|
||||
.selectable_value(page, Page::AuraEffects, "Keyboard Aura")
|
||||
.clicked()
|
||||
{
|
||||
*page = Page::AuraEffects;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Anime page is not complete
|
||||
// if self.supported.anime_ctrl.0 {
|
||||
// ui.separator();
|
||||
// if ui
|
||||
// .selectable_value(page, Page::AnimeMatrix, "AniMe Matrix")
|
||||
// .clicked()
|
||||
// {
|
||||
// *page = Page::AnimeMatrix;
|
||||
// }
|
||||
// }
|
||||
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.label("Source code ");
|
||||
ui.hyperlink_to(
|
||||
"rog-gui.",
|
||||
"https://gitlab.com/asus-linux/asusctl/-/tree/main/rog-control-center",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
47
rog-control-center/src/widgets/top_bar.rs
Normal file
47
rog-control-center/src/widgets/top_bar.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use egui::{vec2, Align2, Button, FontId, Id, Rect, RichText, Sense, Vec2};
|
||||
|
||||
use crate::{RogApp, VERSION};
|
||||
|
||||
impl<'a> RogApp<'a> {
|
||||
pub fn top_bar(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
||||
// The top panel is often a good place for a menu bar:
|
||||
egui::menu::bar(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
egui::global_dark_light_mode_buttons(ui);
|
||||
egui::warn_if_debug_build(ui);
|
||||
});
|
||||
|
||||
/***********************************************************/
|
||||
// Drag area
|
||||
let text_color = ctx.style().visuals.text_color();
|
||||
let mut titlebar_rect = ui.available_rect_before_wrap();
|
||||
titlebar_rect.max.x -= titlebar_rect.height();
|
||||
if ui
|
||||
.interact(titlebar_rect, Id::new("title_bar"), Sense::drag())
|
||||
.drag_started()
|
||||
{
|
||||
frame.drag_window();
|
||||
}
|
||||
/***********************************************************/
|
||||
let height = titlebar_rect.height();
|
||||
// Paint the title:
|
||||
ui.painter().text(
|
||||
titlebar_rect.center_top() + vec2(0.0, height / 2.0),
|
||||
Align2::CENTER_CENTER,
|
||||
format!("ROG Control Center v{}", VERSION),
|
||||
FontId::proportional(height - 2.0),
|
||||
text_color,
|
||||
);
|
||||
// Add the close button:
|
||||
let close_response = ui.put(
|
||||
Rect::from_min_size(titlebar_rect.right_top(), Vec2::splat(height)),
|
||||
Button::new(RichText::new("❌").size(height - 4.0)).frame(false),
|
||||
);
|
||||
if close_response.clicked() {
|
||||
frame.quit();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user