forked from drath/libratbag
Compare commits
326 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
925b2a2a0a | ||
|
|
df42eeb1ca | ||
|
|
aab91b4b11 | ||
|
|
c39640d943 | ||
|
|
0c3cfe71a0 | ||
|
|
dcba13152f | ||
|
|
61da98ffd4 | ||
|
|
98eec0941a | ||
|
|
d8301414c7 | ||
|
|
a4da425298 | ||
|
|
ea7b4b6821 | ||
|
|
833468b292 | ||
|
|
cc954af7a7 | ||
|
|
213ccce0a8 | ||
|
|
bb6ab46a1a | ||
|
|
05c5815fb9 | ||
|
|
0fc6764b47 | ||
|
|
07b40316fb | ||
|
|
260e4adffc | ||
|
|
8c3c6598c3 | ||
|
|
1140875cd8 | ||
|
|
f87bccb370 | ||
|
|
c1955598fe | ||
|
|
d261458cae | ||
|
|
ef3822af82 | ||
|
|
2d8115d2bf | ||
|
|
4c102358a2 | ||
|
|
d133d30f62 | ||
|
|
16a1028e1d | ||
|
|
704d5d2e65 | ||
|
|
bef26c1890 | ||
|
|
85241fdd1b | ||
|
|
2dea887d2f | ||
|
|
2004a3c13e | ||
|
|
48bccf4c98 | ||
|
|
3ea0d44176 | ||
|
|
3e1bc79aac | ||
|
|
9715c5c150 | ||
|
|
07f0eafa57 | ||
|
|
72f8708e0e | ||
|
|
6ac5ba6dbb | ||
|
|
45a8fd9ec3 | ||
|
|
e9dff40258 | ||
|
|
94f28df134 | ||
|
|
4d646db24f | ||
|
|
e21366e5e5 | ||
|
|
21ac98e5f9 | ||
|
|
567d666b96 | ||
|
|
b62565da56 | ||
|
|
3ff3705dbf | ||
|
|
2aa9f012fe | ||
|
|
e7cc62a9c8 | ||
|
|
0608a0156d | ||
|
|
3723c5177f | ||
|
|
9d59c1992a | ||
|
|
ee54001032 | ||
|
|
7f0d058b66 | ||
|
|
cd2ad37db7 | ||
|
|
d08f1f21b7 | ||
|
|
2d21c0dac1 | ||
|
|
7016b50f1b | ||
|
|
217847adde | ||
|
|
c12edcd4c7 | ||
|
|
ae53f6123b | ||
|
|
6dbaeaf506 | ||
|
|
75c8cf83c3 | ||
|
|
706fe34382 | ||
|
|
5e57aa07ea | ||
|
|
1f4bf8fe5f | ||
|
|
dadfb06b98 | ||
|
|
d3c37a6836 | ||
|
|
1b04bcffba | ||
|
|
e5093e1009 | ||
|
|
132fc21212 | ||
|
|
3793e32ebd | ||
|
|
4e931cb712 | ||
|
|
e1682171ce | ||
|
|
e1334214b8 | ||
|
|
fd0954dbdc | ||
|
|
aa1ab47f59 | ||
|
|
7585d73ff5 | ||
|
|
81ca281f2c | ||
|
|
48d654827e | ||
|
|
6c9306b199 | ||
|
|
a9c0060029 | ||
|
|
a289612d85 | ||
|
|
f7b7007897 | ||
|
|
16333068b7 | ||
|
|
eace92870a | ||
|
|
c176825051 | ||
|
|
ba3547457c | ||
|
|
3f936eff68 | ||
|
|
c25864c18a | ||
|
|
cf64aac5f1 | ||
|
|
0a39552a65 | ||
|
|
03d2d71f82 | ||
|
|
1edb6df25b | ||
|
|
9c7494c5c0 | ||
|
|
7f29c0423f | ||
|
|
07307b85d3 | ||
|
|
219218118d | ||
|
|
1e2489c9e7 | ||
|
|
479c4352af | ||
|
|
763655516c | ||
|
|
944c4f0af5 | ||
|
|
268ccab111 | ||
|
|
603b0ca1fc | ||
|
|
4e50c506de | ||
|
|
4351eb3d72 | ||
|
|
9f4a1ba405 | ||
|
|
451894b1b4 | ||
|
|
c6051cb9ea | ||
|
|
34fafbc0f8 | ||
|
|
75d075cc67 | ||
|
|
2f330b6466 | ||
|
|
c7adc9b9f6 | ||
|
|
16a7b6ed18 | ||
|
|
7ff73c8515 | ||
|
|
f11e31d671 | ||
|
|
f69457c280 | ||
|
|
756fee1202 | ||
|
|
d4126463e4 | ||
|
|
00832cb9f0 | ||
|
|
866d4e6433 | ||
|
|
cbba00f997 | ||
|
|
d2e4fcc23e | ||
|
|
f0c66d0e1f | ||
|
|
b2fb91e261 | ||
|
|
1a64d2b85d | ||
|
|
8f5fdf8590 | ||
|
|
baad36060d | ||
|
|
7ecabea70d | ||
|
|
c0c8d6c544 | ||
|
|
37587bb99c | ||
|
|
cc2fff9c06 | ||
|
|
b80d3ac0a3 | ||
|
|
a757180d60 | ||
|
|
8c0124d654 | ||
|
|
b5d41e3657 | ||
|
|
bfd2fc9969 | ||
|
|
566d160de3 | ||
|
|
e0dc0a3a5b | ||
|
|
5b7af0ec14 | ||
|
|
44a9959344 | ||
|
|
755dbddfb3 | ||
|
|
1e3a85433a | ||
|
|
b3b3e3f838 | ||
|
|
f05b671dc1 | ||
|
|
bfadfc3c91 | ||
|
|
96d93ae387 | ||
|
|
03891189da | ||
|
|
02f3487f52 | ||
|
|
d2f1ff0ca2 | ||
|
|
d5a7ad3730 | ||
|
|
e98f86fa2a | ||
|
|
fb14cb576b | ||
|
|
2c83f9c3ef | ||
|
|
b71f439ed6 | ||
|
|
dff102be43 | ||
|
|
6bb92dc313 | ||
|
|
92c5923255 | ||
|
|
6c8a2d36fe | ||
|
|
875aae6985 | ||
|
|
a55297e0fa | ||
|
|
fa95abbc33 | ||
|
|
48d1b21036 | ||
|
|
904aedc555 | ||
|
|
4fa8663cfb | ||
|
|
58086882a3 | ||
|
|
aef92645b7 | ||
|
|
514ce5419f | ||
|
|
2a0a3cf203 | ||
|
|
f96ba13f07 | ||
|
|
724d31c8fe | ||
|
|
66e44d76b9 | ||
|
|
e908871e82 | ||
|
|
9732aa009e | ||
|
|
92299d4673 | ||
|
|
5c3df3b218 | ||
|
|
62f26e797e | ||
|
|
d460743bd7 | ||
|
|
d47f2ed946 | ||
|
|
2ce254e51b | ||
|
|
c7c9c908e1 | ||
|
|
b339370b6a | ||
|
|
37ae638a7c | ||
|
|
6a071dc1ee | ||
|
|
7c9a75da9e | ||
|
|
dd1c72a1d0 | ||
|
|
8d7cbcba4f | ||
|
|
4075227eb7 | ||
|
|
abcec1d349 | ||
|
|
206bc5996d | ||
|
|
366f19abdd | ||
|
|
952bd9dc07 | ||
|
|
6b97d94a2f | ||
|
|
ccaa8d1b6c | ||
|
|
abe451df33 | ||
|
|
a3fa876c3d | ||
|
|
230647c7f3 | ||
|
|
3f99446a1b | ||
|
|
a766f8e909 | ||
|
|
9ae975f9a9 | ||
|
|
780934b1a1 | ||
|
|
337fb935c4 | ||
|
|
c9cf5fe90c | ||
|
|
18af0f97d2 | ||
|
|
286f13c654 | ||
|
|
c6b9cc0c2a | ||
|
|
7d82bb51a6 | ||
|
|
8976033da7 | ||
|
|
c9c6a1675f | ||
|
|
f1e2a4ccff | ||
|
|
104543fdf1 | ||
|
|
b3275e10d7 | ||
|
|
120908bda8 | ||
|
|
32d6443553 | ||
|
|
ae943eaee7 | ||
|
|
4a9503f2da | ||
|
|
e268100d31 | ||
|
|
8ec0e8bbc5 | ||
|
|
e6a9fba498 | ||
|
|
e753db72f9 | ||
|
|
e1f4fac9a2 | ||
|
|
8f981c8b87 | ||
|
|
01d2cf8477 | ||
|
|
f7c22ed88c | ||
|
|
aeda65cbfa | ||
|
|
ed2439e5e2 | ||
|
|
f407521e8f | ||
|
|
3c4fe23f70 | ||
|
|
9e2ac55dbc | ||
|
|
1e72ebaa7b | ||
|
|
920bc2b993 | ||
|
|
20b573668e | ||
|
|
49acc11db3 | ||
|
|
364e3fd965 | ||
|
|
bb230d390d | ||
|
|
93a076bed9 | ||
|
|
e7b50c9061 | ||
|
|
9d533bdc3e | ||
|
|
d7906b54b4 | ||
|
|
f1eba370ed | ||
|
|
7b5ab2ed99 | ||
|
|
d2d5471836 | ||
|
|
9cfc1e98e3 | ||
|
|
691661276f | ||
|
|
25ed99db84 | ||
|
|
02226d0428 | ||
|
|
f822fb0fa7 | ||
|
|
b88be0add0 | ||
|
|
9fc6d12486 | ||
|
|
0c64dad9e1 | ||
|
|
f61485c603 | ||
|
|
8c295479d8 | ||
|
|
e55b04ec7d | ||
|
|
1231415470 | ||
|
|
660da27021 | ||
|
|
481b6f029a | ||
|
|
768d93a45a | ||
|
|
1c6e039d01 | ||
|
|
d16df8d100 | ||
|
|
4b1e49d522 | ||
|
|
786cebcb0b | ||
|
|
d53454bcb3 | ||
|
|
a0def65b64 | ||
|
|
2a40279903 | ||
|
|
02c95422f0 | ||
|
|
4ce1cf2807 | ||
|
|
89168f2187 | ||
|
|
bb92337268 | ||
|
|
a8316c07f3 | ||
|
|
39769c57dd | ||
|
|
200a8af7a7 | ||
|
|
fcf9f7745d | ||
|
|
633c9fc55d | ||
|
|
ee73434ead | ||
|
|
d60b1c9d71 | ||
|
|
88a60f55b4 | ||
|
|
dba202ae8b | ||
|
|
6cdcce9de4 | ||
|
|
e2c3373145 | ||
|
|
02575a9008 | ||
|
|
1097b1ba68 | ||
|
|
77b67775da | ||
|
|
5b23c9ebae | ||
|
|
6d0974be25 | ||
|
|
ea9111a2a6 | ||
|
|
42787ee422 | ||
|
|
611dd9be0d | ||
|
|
fd20f9e642 | ||
|
|
9be5576967 | ||
|
|
9fe511fcc5 | ||
|
|
f0b69aab19 | ||
|
|
7610b80ced | ||
|
|
f0a05bb522 | ||
|
|
2669cc28b2 | ||
|
|
302702d94a | ||
|
|
e1136c4d30 | ||
|
|
0012853a1d | ||
|
|
afb85f868c | ||
|
|
b76fcdadde | ||
|
|
ba7c092ee2 | ||
|
|
3483bd8c14 | ||
|
|
0fb0eb3d42 | ||
|
|
5fb1f4429d | ||
|
|
5f5e294598 | ||
|
|
b4218737cd | ||
|
|
3875bb70fd | ||
|
|
e9d67b7235 | ||
|
|
8a476a8724 | ||
|
|
d67cbec5f8 | ||
|
|
f82c6f72b6 | ||
|
|
af30fc28cd | ||
|
|
3fb8a51456 | ||
|
|
ceaa3c3ad5 | ||
|
|
551b918ba8 | ||
|
|
3105428ba1 | ||
|
|
b3f2406180 | ||
|
|
902160f430 | ||
|
|
fd6d0b6198 | ||
|
|
5ed98fdb22 | ||
|
|
e0e73c2971 | ||
|
|
0d3b4f1b64 | ||
|
|
20b6e3deeb | ||
|
|
ffcdee912d |
@@ -1,236 +0,0 @@
|
||||
# vim: set expandtab shiftwidth=2 tabstop=8:
|
||||
libratbag_references:
|
||||
default_settings: &default_settings
|
||||
working_directory: ~/libratbag
|
||||
environment:
|
||||
LANG: C.UTF-8
|
||||
build_default: &build_default
|
||||
name: Build
|
||||
command: |
|
||||
rm -rf build
|
||||
meson build ${MESON_PARAMS}
|
||||
meson configure build
|
||||
ninja -v -C build ${NINJA_ARGS}
|
||||
environment:
|
||||
MESON_PARAMS: --prefix=/usr
|
||||
build_buildtype_plain: &build_buildtype_plain
|
||||
run:
|
||||
<<: *build_default
|
||||
name: Build with buildtype plain
|
||||
environment:
|
||||
MESON_PARAMS: --prefix=/usr -Dbuildtype=plain
|
||||
build_buildtype_release: &build_buildtype_release
|
||||
run:
|
||||
<<: *build_default
|
||||
name: Build with buildtype release
|
||||
environment:
|
||||
MESON_PARAMS: --prefix=/usr -Dbuildtype=release
|
||||
build_and_test: &build_and_test
|
||||
run:
|
||||
<<: *build_default
|
||||
name: Build and test
|
||||
environment:
|
||||
NINJA_ARGS: test
|
||||
build_with_docs: &build_with_docs
|
||||
run:
|
||||
<<: *build_default
|
||||
name: Build with documentation
|
||||
environment:
|
||||
MESON_PARAMS: -Ddocumentation=true
|
||||
install: &install
|
||||
run:
|
||||
name: Installing
|
||||
command: ninja -C build install
|
||||
check_install: &check_install
|
||||
run:
|
||||
name: Checking installation
|
||||
command: |
|
||||
PREFIX=/usr/local/
|
||||
diff -u <(cd data/devices; ls *.device) <(cd $PREFIX/share/libratbag; ls *.device)
|
||||
check_uninstall: &check_uninstall
|
||||
run:
|
||||
name: Checking if any files are left after uninstall
|
||||
command: |
|
||||
PREFIX=/root/test_install
|
||||
# workaround until https://github.com/mesonbuild/meson/pull/2033 is merged
|
||||
# and a new release appears
|
||||
git clone https://github.com/whot/meson -b wip/remove-directories-on-uninstall
|
||||
./meson/meson.py build_install --prefix=$PREFIX
|
||||
ninja -C build_install install
|
||||
ninja -C build_install uninstall
|
||||
if [ -d $PREFIX ]
|
||||
then
|
||||
tree $PREFIX
|
||||
exit 1
|
||||
fi
|
||||
export_logs: &export_logs
|
||||
store_artifacts:
|
||||
path: ~/libratbag/build/meson-logs
|
||||
start_dbus: &start_dbus
|
||||
run:
|
||||
name: Start dbus daemon
|
||||
command: |
|
||||
mkdir /run/dbus
|
||||
/usr/bin/dbus-daemon --system --fork
|
||||
|
||||
fedora_prep_cache: &fedora_prep_cache
|
||||
<<: *default_settings
|
||||
steps:
|
||||
- run:
|
||||
name: Initializing Fedora dnf cache
|
||||
command: dnf install -y --downloadonly libsolv tree git gcc gcc-c++ meson check-devel libudev-devel libevdev-devel valgrind python3-gobject python3-evdev glib2-devel python3-lxml libunistring-devel dbus-daemon json-glib-devel diffutils
|
||||
- persist_to_workspace:
|
||||
root: /var/cache/
|
||||
paths:
|
||||
- dnf/*
|
||||
|
||||
fedora_fetch_cache: &fedora_fetch_cache
|
||||
attach_workspace:
|
||||
at: /var/cache/
|
||||
|
||||
fedora_install: &fedora_install
|
||||
run:
|
||||
name: Install prerequisites
|
||||
command: |
|
||||
echo keepcache=1 >> /etc/dnf/dnf.conf
|
||||
dnf upgrade -y libsolv
|
||||
dnf install -y tree git gcc gcc-c++ meson check-devel libudev-devel libevdev-devel valgrind python3-gobject python3-evdev glib2-devel python3-lxml python3-devel swig libunistring-devel dbus-daemon json-glib-devel diffutils
|
||||
sed -i 's/systemd//' /etc/nsswitch.conf
|
||||
|
||||
fedora_settings: &fedora_settings
|
||||
<<: *default_settings
|
||||
steps:
|
||||
- *fedora_fetch_cache
|
||||
- *fedora_install
|
||||
- checkout
|
||||
- *start_dbus
|
||||
- *build_and_test
|
||||
- *install
|
||||
- *check_install
|
||||
- *check_uninstall
|
||||
- *build_buildtype_plain
|
||||
- *build_buildtype_release
|
||||
- *export_logs
|
||||
|
||||
|
||||
ubuntu_settings: &ubuntu_settings
|
||||
<<: *default_settings
|
||||
steps:
|
||||
- run:
|
||||
name: Install prerequisites
|
||||
command: |
|
||||
apt-get update
|
||||
apt-get install -y software-properties-common
|
||||
apt-get remove -y libnss-systemd
|
||||
add-apt-repository universe
|
||||
apt-get update
|
||||
apt-get install -y tree git gcc g++ pkg-config meson check libudev-dev libevdev-dev libsystemd-dev valgrind python3-gi python3-evdev libglib2.0-dev python3-lxml python3-dev swig systemd libunistring-dev libjson-glib-dev
|
||||
- checkout
|
||||
- *start_dbus
|
||||
- *build_and_test
|
||||
- *install
|
||||
- *check_install
|
||||
- *check_uninstall
|
||||
- *build_buildtype_plain
|
||||
- *build_buildtype_release
|
||||
- *export_logs
|
||||
|
||||
doc_build: &doc_build
|
||||
<<: *default_settings
|
||||
steps:
|
||||
- *fedora_fetch_cache
|
||||
- *fedora_install
|
||||
- run:
|
||||
name: Install documentation build-deps
|
||||
command: dnf install -y python3-sphinx python3-sphinx_rtd_theme
|
||||
- checkout
|
||||
- *build_with_docs
|
||||
- *export_logs
|
||||
- store_artifacts:
|
||||
path: ~/libratbag/build/doc/html
|
||||
- persist_to_workspace:
|
||||
root: build
|
||||
paths:
|
||||
- doc/html/*
|
||||
|
||||
docs_deploy: &docs_deploy
|
||||
<<: *default_settings
|
||||
steps:
|
||||
- *fedora_fetch_cache
|
||||
- run:
|
||||
name: Install prerequisites
|
||||
command: dnf install -y git tree
|
||||
- checkout
|
||||
- attach_workspace:
|
||||
at: build
|
||||
- run:
|
||||
name: Setup the deploy SSH key
|
||||
command: |
|
||||
ssh-add -L | tail -n1 > ~/.ssh/deploy.pub
|
||||
cat <<EOF > ~/.ssh/config
|
||||
Host github.com
|
||||
IdentityFile /root/.ssh/deploy.pub
|
||||
IdentitiesOnly yes
|
||||
EOF
|
||||
- run:
|
||||
name: Clone doc repository
|
||||
command: |
|
||||
cd ~
|
||||
git clone ssh://git@github.com/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_PROJECT_REPONAME}.github.io
|
||||
- run:
|
||||
name: Copy the doc, commit and push
|
||||
command: |
|
||||
set +e
|
||||
cd ~/${CIRCLE_PROJECT_REPONAME}.github.io
|
||||
\cp -r ~/${CIRCLE_PROJECT_REPONAME}/build/doc/html/* .
|
||||
if ! git diff-index --quiet HEAD --; then
|
||||
git config --global user.email "libratbag@librabtag.github.io"
|
||||
git config --global user.name "The libratbag crew"
|
||||
git add .
|
||||
git commit -m "update docs from ${CIRCLE_SHA1}"
|
||||
git push
|
||||
fi
|
||||
|
||||
version: 2
|
||||
jobs:
|
||||
fedora_cache:
|
||||
<<: *fedora_prep_cache
|
||||
docker:
|
||||
- image: fedora:31
|
||||
fedora_31:
|
||||
<<: *fedora_settings
|
||||
docker:
|
||||
- image: fedora:31
|
||||
ubuntu_19_04:
|
||||
<<: *ubuntu_settings
|
||||
docker:
|
||||
- image: ubuntu:19.04
|
||||
doc_build:
|
||||
<<: *doc_build
|
||||
docker:
|
||||
- image: fedora:31
|
||||
doc_deploy:
|
||||
<<: *docs_deploy
|
||||
docker:
|
||||
- image: fedora:31
|
||||
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
compile_and_test:
|
||||
jobs:
|
||||
- fedora_cache
|
||||
- ubuntu_19_04
|
||||
- fedora_31:
|
||||
requires:
|
||||
- fedora_cache
|
||||
- doc_build:
|
||||
requires:
|
||||
- fedora_cache
|
||||
- doc_deploy:
|
||||
requires:
|
||||
- fedora_cache
|
||||
- doc_build
|
||||
filters:
|
||||
branches:
|
||||
only: master
|
||||
20
.editorconfig
Normal file
20
.editorconfig
Normal file
@@ -0,0 +1,20 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{c,h}]
|
||||
indent_style = tab
|
||||
tab_width = 8
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[{*.{py,py.in},tools/ratbagctl.*.in}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.{yml,xsl}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
6
.github/ISSUE_TEMPLATE/bug_report.md
vendored
6
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -13,6 +13,12 @@ assignees: ''
|
||||
- Distribution:
|
||||
- Kernel version (ex. `uname -srmo`): `KERNEL VERSION HERE`
|
||||
|
||||
Device info (if applicable):
|
||||
```
|
||||
$ ratbagctl <device> info
|
||||
OUTPUT HERE
|
||||
```
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
|
||||
39
.github/actions/meson/action.yml
vendored
Normal file
39
.github/actions/meson/action.yml
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# A Github Action to build a repository with meson
|
||||
name: "Setup and run meson"
|
||||
description: "Setup and run meson"
|
||||
inputs:
|
||||
builddir:
|
||||
description: "The build directory"
|
||||
default: "builddir"
|
||||
srcdir:
|
||||
description: "The source directory"
|
||||
default: "."
|
||||
meson_args:
|
||||
description: "Arguments passed to meson setup"
|
||||
default: ""
|
||||
meson_skip_test:
|
||||
description: "Set to a nonempty string to skip meson test"
|
||||
default: ""
|
||||
meson_test_args:
|
||||
description: "Arguments passed to meson test"
|
||||
default: ""
|
||||
meson_precmd:
|
||||
description: "Set to 'sudo' to run with sudo"
|
||||
default: ""
|
||||
ninja_args:
|
||||
description: "Arguments passed to ninja"
|
||||
default: ""
|
||||
ninja_precmd:
|
||||
description: "Set to 'sudo' to run with sudo"
|
||||
default: ""
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- run: |
|
||||
${{inputs.meson_precmd}} meson setup ${{inputs.builddir}} ${{inputs.srcdir}} ${{inputs.meson_args}}
|
||||
${{inputs.meson_precmd}} meson configure ${{inputs.builddir}}
|
||||
${{inputs.ninja_precmd}} ninja -C ${{inputs.builddir}} ${{inputs.ninja_args}}
|
||||
if [[ -z "${{inputs.meson_skip_test}}" ]]; then
|
||||
${{inputs.meson_precmd}} meson test -C ${{inputs.builddir}} --print-errorlogs ${{inputs.meson_test_args}};
|
||||
fi
|
||||
shell: bash
|
||||
17
.github/actions/pkginstall/action.yml
vendored
Normal file
17
.github/actions/pkginstall/action.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
name: "Install packages"
|
||||
description: "Install a set of packages from sources"
|
||||
inputs:
|
||||
apt:
|
||||
description: "The package list to install with apt"
|
||||
pip:
|
||||
description: "The package list to install with pip"
|
||||
pip_precmd:
|
||||
description: "Set to the string 'sudo' to run through sudo"
|
||||
default: ""
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- run: sudo ${{ github.action_path }}/install-apt.sh ${{ inputs.apt }}
|
||||
shell: bash
|
||||
- run: ${{inputs.pip_precmd}} ${{ github.action_path }}/install-pip.sh ${{ inputs.pip }}
|
||||
shell: bash
|
||||
14
.github/actions/pkginstall/install-apt.sh
vendored
Executable file
14
.github/actions/pkginstall/install-apt.sh
vendored
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
# If called without arguments, just skip the rest
|
||||
if [[ -z "$@" ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
# Don't care about these bits
|
||||
echo 'path-exclude=/usr/share/doc/*' > /etc/dpkg/dpkg.cfg.d/99-exclude-cruft
|
||||
echo 'path-exclude=/usr/share/locale/*' >> /etc/dpkg/dpkg.cfg.d/99-exclude-cruft
|
||||
echo 'path-exclude=/usr/share/man/*' >> /etc/dpkg/dpkg.cfg.d/99-exclude-cruft
|
||||
|
||||
apt-get update
|
||||
apt-get install -yq --no-install-suggests --no-install-recommends $@
|
||||
9
.github/actions/pkginstall/install-pip.sh
vendored
Executable file
9
.github/actions/pkginstall/install-pip.sh
vendored
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
# If called without arguments, just skip the rest
|
||||
if [[ -z "$@" ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install --upgrade "$@"
|
||||
50
.github/workflows/main.yml
vendored
Normal file
50
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
name: linux
|
||||
|
||||
on: [ push, pull_request ]
|
||||
|
||||
env:
|
||||
UBUNTU_DEP_BUILD: |
|
||||
gcc g++ pkg-config systemd libevdev-dev libglib2.0-dev
|
||||
libjson-glib-dev libsystemd-dev libudev-dev libunistring-dev
|
||||
python3-dev python3-evdev swig python3-sphinx
|
||||
UBUNTU_DEP_TEST: check python3-gi python3-lxml valgrind
|
||||
PIP_PACKAGES: meson ninja libevdev pyudev pytest sphinx_rtd_theme
|
||||
|
||||
jobs:
|
||||
build-and-dist:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
meson_args:
|
||||
- ''
|
||||
- '-Dbuildtype=plain'
|
||||
- '-Dbuildtype=release'
|
||||
- '-Ddocumentation=true'
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./.github/actions/pkginstall
|
||||
with:
|
||||
apt: $UBUNTU_DEP_BUILD $UBUNTU_DEP_TEST
|
||||
pip: $PIP_PACKAGES
|
||||
- name: meson test ${{matrix.meson_args}}
|
||||
uses: ./.github/actions/meson
|
||||
with:
|
||||
meson_args: --prefix=$PWD/_instdir ${{matrix.meson_args}}
|
||||
ninja_args: install
|
||||
- name: check installation of data files
|
||||
run: diff -u <(cd data/devices; ls *.device) <(cd _instdir/share/libratbag; ls *.device)
|
||||
- name: ninja uninstall
|
||||
uses: ./.github/actions/meson
|
||||
with:
|
||||
meson_args: --prefix=$PWD/_instdir
|
||||
ninja_args: uninstall
|
||||
- name: check if any files are left after uninstall
|
||||
run: (test -d _instdir && tree _instdir && exit 1) || exit 0
|
||||
# Capture all the meson logs, even if we failed
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: ${{ always() }} # even if we fail
|
||||
with:
|
||||
name: meson test logs
|
||||
path: |
|
||||
builddir/meson-logs/testlog*.txt
|
||||
builddir/meson-logs/meson-log.txt
|
||||
31
.github/workflows/pages.yml
vendored
Normal file
31
.github/workflows/pages.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
name: pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
UBUNTU_DEP_BUILD: gcc g++ pkg-config systemd libevdev-dev libglib2.0-dev libjson-glib-dev libsystemd-dev libudev-dev libunistring-dev python3-dev python3-evdev python3-pip swig python3-sphinx python3-sphinx-rtd-theme
|
||||
PIP_PACKAGES: meson ninja
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./.github/actions/pkginstall
|
||||
with:
|
||||
apt: $UBUNTU_DEP_BUILD
|
||||
pip: $PIP_PACKAGES
|
||||
- name: Build docs
|
||||
uses: ./.github/actions/meson
|
||||
with:
|
||||
meson_args: -Ddocumentation=true -Dtests=false
|
||||
meson_skip_test: yes
|
||||
- name: Deploy to GitHub Pages
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./builddir/doc/html/
|
||||
allow_empty_commit: true
|
||||
13
README.md
13
README.md
@@ -3,9 +3,10 @@ libratbag
|
||||
|
||||
<img src="https://libratbag.github.io/_images/logo.svg" alt="" width="30%" align="right">
|
||||
|
||||
libratbag provides **ratbagd**, a DBus daemon to configure gaming mice.
|
||||
The daemon provides a generic way to access the various features exposed by
|
||||
these mice and abstracts away hardware-specific and kernel-specific quirks.
|
||||
libratbag provides **ratbagd**, a DBus daemon to configure input devices,
|
||||
mainly gaming mice. The daemon provides a generic way to access the various
|
||||
features exposed by these mice and abstracts away hardware-specific and
|
||||
kernel-specific quirks.
|
||||
|
||||
libratbag currently supports devices from Logitech, Etekcity, GSkill,
|
||||
Roccat, Steelseries. See [the device
|
||||
@@ -44,6 +45,10 @@ And to build or re-build after code-changes, run:
|
||||
|
||||
ninja -C builddir
|
||||
sudo ninja -C builddir install
|
||||
|
||||
To remove/uninstal simply run:
|
||||
|
||||
sudo ninja -C builddir uninstall
|
||||
|
||||
Note: `builddir` is the build output directory and can be changed to any
|
||||
other directory name. To set configure-time options, use e.g.
|
||||
@@ -168,5 +173,3 @@ libratbag is licensed under the MIT license.
|
||||
> Software is furnished to do so, subject to the following conditions: [...]
|
||||
|
||||
See the COPYING file for the full license information.
|
||||
|
||||
[](https://circleci.com/gh/libratbag/libratbag)
|
||||
|
||||
11
data/devices/asus-rog-buzzard.device
Normal file
11
data/devices/asus-rog-buzzard.device
Normal file
@@ -0,0 +1,11 @@
|
||||
[Device]
|
||||
Name=ASUS ROG GX860 Buzzard Mouse
|
||||
DeviceMatch=usb:0b05:1816
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=3
|
||||
Buttons=10
|
||||
Leds=0
|
||||
Dpis=2
|
||||
DpiRange=100:8200@100
|
||||
13
data/devices/asus-rog-chakram.device
Normal file
13
data/devices/asus-rog-chakram.device
Normal file
@@ -0,0 +1,13 @@
|
||||
[Device]
|
||||
Name=ASUS ROG Chakram
|
||||
DeviceMatch=usb:0b05:18e3;usb:0b05:18e5
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=3
|
||||
Buttons=5
|
||||
Leds=3
|
||||
Dpis=4
|
||||
Wireless=1
|
||||
DpiRange=100:16000@100
|
||||
Quirks=DOUBLE_DPI;STRIX_PROFILE
|
||||
13
data/devices/asus-rog-gladius2-origin-pink.device
Normal file
13
data/devices/asus-rog-gladius2-origin-pink.device
Normal file
@@ -0,0 +1,13 @@
|
||||
[Device]
|
||||
Name=ASUS ROG Gladius II Origin PNK LTD
|
||||
DeviceMatch=usb:0b05:18cd
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=3
|
||||
Buttons=8
|
||||
Leds=3
|
||||
Dpis=2
|
||||
DpiRange=100:12000@100
|
||||
ButtonMapping=0;1;2;7;8;5;3;4
|
||||
Quirks=DOUBLE_DPI
|
||||
14
data/devices/asus-rog-gladius2-origin.device
Normal file
14
data/devices/asus-rog-gladius2-origin.device
Normal file
@@ -0,0 +1,14 @@
|
||||
# "ASUS ROG Gladius II" without "DPI target button"
|
||||
[Device]
|
||||
Name=ASUS ROG Gladius II Origin
|
||||
DeviceMatch=usb:0b05:1877
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=3
|
||||
Buttons=8
|
||||
Leds=3
|
||||
Dpis=2
|
||||
DpiRange=100:12000@100
|
||||
ButtonMapping=0;1;2;7;8;5;3;4
|
||||
Quirks=DOUBLE_DPI
|
||||
12
data/devices/asus-rog-gladius2.device
Normal file
12
data/devices/asus-rog-gladius2.device
Normal file
@@ -0,0 +1,12 @@
|
||||
[Device]
|
||||
Name=ASUS ROG Gladius II
|
||||
DeviceMatch=usb:0b05:1845
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=3
|
||||
Buttons=8
|
||||
Leds=3
|
||||
Dpis=2
|
||||
DpiRange=100:12000@100
|
||||
ButtonMapping=0;1;2;7;8;5;3;4
|
||||
13
data/devices/asus-rog-keris-wireless.device
Normal file
13
data/devices/asus-rog-keris-wireless.device
Normal file
@@ -0,0 +1,13 @@
|
||||
[Device]
|
||||
Name=ASUS ROG Keris Wireless
|
||||
DeviceMatch=usb:0b05:195e;usb:0b05:1960
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=3
|
||||
Buttons=8
|
||||
Leds=2
|
||||
Dpis=4
|
||||
Wireless=1
|
||||
DpiRange=100:16000@100
|
||||
Quirks=DOUBLE_DPI
|
||||
14
data/devices/asus-rog-pugio.device
Normal file
14
data/devices/asus-rog-pugio.device
Normal file
@@ -0,0 +1,14 @@
|
||||
[Device]
|
||||
Name=ASUS ROG Pugio
|
||||
DeviceMatch=usb:0b05:1846
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=3
|
||||
Buttons=10
|
||||
Leds=3
|
||||
Dpis=2
|
||||
DpiRange=100:7200@100
|
||||
|
||||
# Mappings the same as the Gladius II but with an extra 2 buttons
|
||||
ButtonMapping=0;1;2;7;8;5;3;4;9;10
|
||||
13
data/devices/asus-rog-strix-carry.device
Normal file
13
data/devices/asus-rog-strix-carry.device
Normal file
@@ -0,0 +1,13 @@
|
||||
[Device]
|
||||
Name=ASUS ROG Strix Carry
|
||||
DeviceMatch=usb:0b05:18b4
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=3
|
||||
Buttons=8
|
||||
Leds=0
|
||||
Dpis=2
|
||||
Wireless=1
|
||||
DpiRange=100:7200@100
|
||||
Quirks=STRIX_PROFILE
|
||||
11
data/devices/asus-rog-strix-impact.device
Normal file
11
data/devices/asus-rog-strix-impact.device
Normal file
@@ -0,0 +1,11 @@
|
||||
[Device]
|
||||
Name=ASUS ROG Strix Impact
|
||||
DeviceMatch=usb:0b05:1847
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=0
|
||||
Buttons=6
|
||||
Leds=1
|
||||
Dpis=2
|
||||
DpiRange=100:5000@100
|
||||
12
data/devices/asus-rog-strix-impact2-wireless.device
Normal file
12
data/devices/asus-rog-strix-impact2-wireless.device
Normal file
@@ -0,0 +1,12 @@
|
||||
[Device]
|
||||
Name=ASUS ROG Strix Impact II Wireless
|
||||
DeviceMatch=usb:0b05:1947;usb:0b05:1949
|
||||
Driver=asus
|
||||
|
||||
[Driver/asus]
|
||||
Profiles=3
|
||||
Buttons=8
|
||||
Leds=3
|
||||
Dpis=4
|
||||
Wireless=1
|
||||
DpiRange=100:16000@100
|
||||
@@ -52,3 +52,29 @@ Leds=1
|
||||
# The HID++ 2.0 device index
|
||||
# Should be unset unless required
|
||||
# DeviceIndex=1
|
||||
|
||||
|
||||
[Driver/asus]
|
||||
# Number of profiles
|
||||
Profiles=3
|
||||
|
||||
# Number of buttons
|
||||
Buttons=8
|
||||
|
||||
# Number of LEDs
|
||||
Leds=3
|
||||
|
||||
# Number of DPI presets
|
||||
Dpis=2
|
||||
|
||||
# Set if device is wireless
|
||||
# Wireless=1
|
||||
|
||||
# DPI range in format min:max@step
|
||||
DpiRange=100:16000@100
|
||||
|
||||
# Button index mapping
|
||||
# ButtonMapping=0;1;2;6;7;5;3;4
|
||||
|
||||
# Device quirks
|
||||
# Quirk=DOUBLE_DPI;STRIX_PROFILE
|
||||
|
||||
11
data/devices/glorious-model-d.device
Normal file
11
data/devices/glorious-model-d.device
Normal file
@@ -0,0 +1,11 @@
|
||||
[Device]
|
||||
Name=Glorious Model D
|
||||
DeviceMatch=usb:258a:0033
|
||||
Driver=sinowealth
|
||||
|
||||
[Driver/sinowealth/devices/GloriousModelD]
|
||||
ButtonCount=6
|
||||
DeviceName=Glorious Model D
|
||||
FwVersion=V102
|
||||
LedType=RBG
|
||||
SensorType=PMW3360
|
||||
11
data/devices/glorious-model-o.device
Normal file
11
data/devices/glorious-model-o.device
Normal file
@@ -0,0 +1,11 @@
|
||||
[Device]
|
||||
Name=Glorious Model O/O-
|
||||
DeviceMatch=usb:258a:0036
|
||||
Driver=sinowealth
|
||||
|
||||
[Driver/sinowealth/devices/GloriousModelO]
|
||||
ButtonCount=6
|
||||
DeviceName=Glorious Model O/O- (updated firmware)
|
||||
FwVersion=V103
|
||||
LedType=RBG
|
||||
SensorType=PMW3360
|
||||
5
data/devices/logitech-M500s.device
Normal file
5
data/devices/logitech-M500s.device
Normal file
@@ -0,0 +1,5 @@
|
||||
# Logitech M500s
|
||||
[Device]
|
||||
Name=Logitech M500s
|
||||
DeviceMatch=usb:046d:c093
|
||||
Driver=hidpp20
|
||||
5
data/devices/logitech-M545.device
Normal file
5
data/devices/logitech-M545.device
Normal file
@@ -0,0 +1,5 @@
|
||||
# Logitech M545
|
||||
[Device]
|
||||
Name=Logitech M545
|
||||
DeviceMatch=usb:046d:4052
|
||||
Driver=hidpp20
|
||||
@@ -1,5 +1,5 @@
|
||||
# Logitech M585/M590
|
||||
[Device]
|
||||
Name=Logitech M585/M590
|
||||
DeviceMatch=usb:046d:406b
|
||||
DeviceMatch=usb:046d:406b;bluetooth:046d:b01b
|
||||
Driver=hidpp20
|
||||
|
||||
4
data/devices/logitech-M720.device
Normal file
4
data/devices/logitech-M720.device
Normal file
@@ -0,0 +1,4 @@
|
||||
[Device]
|
||||
Name=Logitech M720
|
||||
DeviceMatch=usb:046d:405e;bluetooth:046d:b015
|
||||
Driver=hidpp20
|
||||
5
data/devices/logitech-MX-Anywhere-3.device
Normal file
5
data/devices/logitech-MX-Anywhere-3.device
Normal file
@@ -0,0 +1,5 @@
|
||||
# Logitech MX Anywhere 3
|
||||
[Device]
|
||||
Name=Logitech MX Anywhere 3
|
||||
DeviceMatch=bluetooth:046d:b025;usb:046d:4090
|
||||
Driver=hidpp20
|
||||
@@ -1,4 +1,4 @@
|
||||
[Device]
|
||||
Name=Logitech MX Anywhere 2
|
||||
DeviceMatch=usb:046d:404a;bluetooth:046d:b013;bluetooth:046d:b018
|
||||
DeviceMatch=usb:046d:404a;usb:046d:4072;usb:046d:4063;bluetooth:046d:b013;bluetooth:046d:b018;bluetooth:046d:b01f
|
||||
Driver=hidpp20
|
||||
|
||||
4
data/devices/logitech-MX-Anywhere3B.device
Normal file
4
data/devices/logitech-MX-Anywhere3B.device
Normal file
@@ -0,0 +1,4 @@
|
||||
# Logitech MX Anywhere 3B
|
||||
[Device]
|
||||
Name=Logitech MX Anywhere 3B
|
||||
DeviceMatch=bluetooth:046d:b02d
|
||||
@@ -1,4 +1,4 @@
|
||||
[Device]
|
||||
Name=Logitech MX Vertical
|
||||
DeviceMatch=usb:046d:407b
|
||||
DeviceMatch=bluetooth:046d:b020;usb:046d:407b;usb:046d:c08a
|
||||
Driver=hidpp20
|
||||
|
||||
8
data/devices/logitech-g-powerplay.device
Normal file
8
data/devices/logitech-g-powerplay.device
Normal file
@@ -0,0 +1,8 @@
|
||||
[Device]
|
||||
Name=Logitech G Powerplay
|
||||
DeviceMatch=usb:046d:405f
|
||||
LedTypes=logo
|
||||
Driver=hidpp20
|
||||
|
||||
[Driver/hidpp20]
|
||||
DeviceIndex=7
|
||||
5
data/devices/logitech-g-pro-x-wireless-superlight.device
Normal file
5
data/devices/logitech-g-pro-x-wireless-superlight.device
Normal file
@@ -0,0 +1,5 @@
|
||||
[Device]
|
||||
Name=Logitech G Pro X Wireless Superlight
|
||||
DeviceMatch=usb:046d:4093;usb:046d:c094
|
||||
LedTypes=logo;battery;dpi;
|
||||
Driver=hidpp20
|
||||
@@ -1,6 +1,6 @@
|
||||
# G102 and G203 (USB)
|
||||
# G102, G103 and G203 (USB)
|
||||
[Device]
|
||||
Name=Logitech Gaming Mouse G102/G103
|
||||
DeviceMatch=usb:046d:c084
|
||||
Name=Logitech Gaming Mouse G102/G103/G203
|
||||
DeviceMatch=usb:046d:c084;usb:046d:c092
|
||||
Driver=hidpp20
|
||||
LedTypes=logo;side;
|
||||
|
||||
@@ -4,4 +4,5 @@ DeviceMatch=usb:046d:4074
|
||||
Driver=hidpp20
|
||||
|
||||
[Driver/hidpp20]
|
||||
Leds=0
|
||||
Quirk=G305
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
[Device]
|
||||
Name=Logitech G402 Gaming Mouse
|
||||
DeviceMatch=usb:046d:c07e
|
||||
LedTypes=logo
|
||||
Driver=hidpp20
|
||||
|
||||
@@ -7,3 +7,4 @@ Driver=hidpp10
|
||||
[Driver/hidpp10]
|
||||
DpiList=400;800;1600;2000
|
||||
Profiles=1
|
||||
ProfileType=G500
|
||||
|
||||
4
data/devices/logitech-g502-x-wireless.device
Normal file
4
data/devices/logitech-g502-x-wireless.device
Normal file
@@ -0,0 +1,4 @@
|
||||
[Device]
|
||||
Name=Logitech G502 X Wireless
|
||||
DeviceMatch=usb:046d:c098
|
||||
Driver=hidpp20
|
||||
4
data/devices/logitech-g502-x.device
Normal file
4
data/devices/logitech-g502-x.device
Normal file
@@ -0,0 +1,4 @@
|
||||
[Device]
|
||||
Name=Logitech G502 X
|
||||
DeviceMatch=usb:046d:c099
|
||||
Driver=hidpp20
|
||||
5
data/devices/logitech-g513.device
Normal file
5
data/devices/logitech-g513.device
Normal file
@@ -0,0 +1,5 @@
|
||||
[Device]
|
||||
Name=Logitech G513
|
||||
DeviceMatch=usb:046d:c33c
|
||||
LedTypes=switches
|
||||
Driver=hidpp20
|
||||
8
data/devices/logitech-g635.device
Normal file
8
data/devices/logitech-g635.device
Normal file
@@ -0,0 +1,8 @@
|
||||
[Device]
|
||||
Name=Logitech G635
|
||||
DeviceMatch=usb:046d:0a89
|
||||
LedTypes=logo;side
|
||||
Driver=hidpp20
|
||||
|
||||
[Driver/hidpp20]
|
||||
Buttons=0
|
||||
7
data/devices/logitech-g733.device
Normal file
7
data/devices/logitech-g733.device
Normal file
@@ -0,0 +1,7 @@
|
||||
[Device]
|
||||
Name=Logitech G733 Gaming Headset
|
||||
DeviceMatch=usb:046d:0ab5
|
||||
Driver=hidpp20
|
||||
|
||||
[Driver/hidpp20]
|
||||
Buttons=0
|
||||
5
data/devices/logitech-g815.device
Normal file
5
data/devices/logitech-g815.device
Normal file
@@ -0,0 +1,5 @@
|
||||
[Device]
|
||||
Name=Logitech G815
|
||||
DeviceMatch=usb:046d:c33f
|
||||
LedTypes=logo;switches
|
||||
Driver=hidpp20
|
||||
8
data/devices/logitech-g910.device
Normal file
8
data/devices/logitech-g910.device
Normal file
@@ -0,0 +1,8 @@
|
||||
[Device]
|
||||
Name=Logitech G910
|
||||
DeviceMatch=usb:046d:c335
|
||||
LedTypes=logo;switches
|
||||
Driver=hidpp20
|
||||
|
||||
[Driver/hidpp20]
|
||||
DeviceIndex=ff
|
||||
8
data/devices/logitech-g915-tkl.device
Normal file
8
data/devices/logitech-g915-tkl.device
Normal file
@@ -0,0 +1,8 @@
|
||||
[Device]
|
||||
Name=Logitech G915 TKL
|
||||
DeviceMatch=usb:046d:c343;bluetooth:046d:b35f
|
||||
LedTypes=logo;switches
|
||||
Driver=hidpp20
|
||||
|
||||
[Driver/hidpp20]
|
||||
DeviceIndex=1
|
||||
8
data/devices/logitech-g915.device
Normal file
8
data/devices/logitech-g915.device
Normal file
@@ -0,0 +1,8 @@
|
||||
[Device]
|
||||
Name=Logitech G915
|
||||
DeviceMatch=usb:046d:c33e
|
||||
LedTypes=logo;switches
|
||||
Driver=hidpp20
|
||||
|
||||
[Driver/hidpp20]
|
||||
DeviceIndex=1
|
||||
5
data/devices/logitech-g935.device
Normal file
5
data/devices/logitech-g935.device
Normal file
@@ -0,0 +1,5 @@
|
||||
[Device]
|
||||
Name=Logitech G935
|
||||
DeviceMatch=usb:046d:0a87
|
||||
LedTypes=logo;side
|
||||
Driver=hidpp20
|
||||
@@ -4,8 +4,10 @@
|
||||
Name=G9x [Original]
|
||||
DeviceMatch=usb:046d:c066
|
||||
Driver=hidpp10
|
||||
LedTypes=dpi
|
||||
|
||||
[Driver/hidpp10]
|
||||
DpiRange=0:5700@23.53
|
||||
DpiRange=200:5700@50
|
||||
ProfileType=G500
|
||||
Profiles=5
|
||||
Leds=1
|
||||
|
||||
5
data/devices/nubwo-x7-spectrum.device
Normal file
5
data/devices/nubwo-x7-spectrum.device
Normal file
@@ -0,0 +1,5 @@
|
||||
[Device]
|
||||
Name=Nubwo x7 spectrum
|
||||
DeviceMatch=usb:258a:0012
|
||||
Driver=sinowealth_nubwo
|
||||
|
||||
4
data/devices/openinput.device
Normal file
4
data/devices/openinput.device
Normal file
@@ -0,0 +1,4 @@
|
||||
[Device]
|
||||
Name=openinput
|
||||
DeviceMatch=usb:1d50:616a
|
||||
Driver=openinput
|
||||
4
data/devices/roccat-kone-emp.device
Normal file
4
data/devices/roccat-kone-emp.device
Normal file
@@ -0,0 +1,4 @@
|
||||
[Device]
|
||||
Name=Roccat Kone EMP
|
||||
DeviceMatch=usb:1e7d:2e24
|
||||
Driver=roccat-kone-emp
|
||||
@@ -1,4 +1,4 @@
|
||||
[Device]
|
||||
Name=Roccat Kone Pure
|
||||
DeviceMatch=usb:1e7d:2dc2
|
||||
DeviceMatch=usb:1e7d:2dc2;usb:1e7d:2dbe;usb:1e7d:2dcb
|
||||
Driver=roccat-kone-pure
|
||||
|
||||
38
data/devices/sinowealth-0027.device
Normal file
38
data/devices/sinowealth-0027.device
Normal file
@@ -0,0 +1,38 @@
|
||||
[Device]
|
||||
DeviceMatch=usb:258a:0027
|
||||
Driver=sinowealth
|
||||
Name=SinoWealth Generic Mouse (0027)
|
||||
|
||||
[Driver/sinowealth/devices/DreamMachinesDM5Blink]
|
||||
ButtonCount=8
|
||||
DeviceName=DreamMachines DM5 Blink
|
||||
FwVersion=3106
|
||||
LedType=RGB
|
||||
SensorType=PMW3389
|
||||
|
||||
[Driver/sinowealth/devices/GWolvesHatiHTM]
|
||||
ButtonCount=6
|
||||
# Can be both `Ace` and `Classic` version.
|
||||
DeviceName=G-Wolves Hati HT-M Wired
|
||||
FwVersion=V161
|
||||
LedType=None
|
||||
# Can also be PMW3389
|
||||
SensorType=PMW3360
|
||||
|
||||
[Driver/sinowealth/devices/GenesysXenon770]
|
||||
# There are 5 main buttons.
|
||||
# Side buttons are detachable.
|
||||
# There can be either 3 or 9 buttons on the side.
|
||||
# Going for the maximum count: 5 + 9 = 14.
|
||||
ButtonCount=14
|
||||
DeviceName=Genesys Xenon 770
|
||||
FwVersion=3110
|
||||
LedType=RGB
|
||||
SensorType=PMW3327
|
||||
|
||||
[Driver/sinowealth/devices/GloriousModelOOld]
|
||||
ButtonCount=6
|
||||
DeviceName=Glorious Model O (old firmware)
|
||||
FwVersion=V102
|
||||
LedType=RBG
|
||||
SensorType=PMW3360
|
||||
12
data/devices/sinowealth-0029.device
Normal file
12
data/devices/sinowealth-0029.device
Normal file
@@ -0,0 +1,12 @@
|
||||
[Device]
|
||||
DeviceMatch=usb:258a:0029
|
||||
Driver=sinowealth
|
||||
Name=SinoWealth Generic Mouse (0029)
|
||||
|
||||
# Configuration data size is 131 bytes.
|
||||
[Driver/sinowealth/devices/MachenikeM620]
|
||||
ButtonCount=6
|
||||
DeviceName=Machenike M620
|
||||
FwVersion=V127
|
||||
LedType=RGB
|
||||
SensorType=PMW3389
|
||||
20
data/devices/sinowealth-1007.device
Normal file
20
data/devices/sinowealth-1007.device
Normal file
@@ -0,0 +1,20 @@
|
||||
[Device]
|
||||
DeviceMatch=usb:258a:1007
|
||||
Driver=sinowealth
|
||||
Name=SinoWealth Generic Mouse (1007)
|
||||
|
||||
# This does NOT work. See libratbag/libratbag#1296.
|
||||
# For future: ID of A3050 sensor is 0x2, and maximum DPI is 4000.
|
||||
#[Driver/sinowealth/devices/AntEsportsGM500]
|
||||
#ButtonCount=7
|
||||
#DeviceName=Ant Esports GM500
|
||||
#FwVersion=0910
|
||||
#LedType=RBG
|
||||
#SensorType=A3050
|
||||
|
||||
[Driver/sinowealth/devices/MarvoScorpionG961]
|
||||
ButtonCount=6
|
||||
DeviceName=Marvo Scorpion G961
|
||||
FwVersion=9677
|
||||
LedType=RGB
|
||||
SensorType=PMW3327
|
||||
11
data/devices/steelseries-kinzu-v2-pro.device
Normal file
11
data/devices/steelseries-kinzu-v2-pro.device
Normal file
@@ -0,0 +1,11 @@
|
||||
[Device]
|
||||
Name=SteelSeries Kinzu V2 Pro Edition
|
||||
DeviceMatch=usb:1038:1366
|
||||
Driver=steelseries
|
||||
|
||||
[Driver/steelseries]
|
||||
DeviceVersion=1
|
||||
Buttons=3
|
||||
Leds=0
|
||||
DpiList=400;800;1600;3200
|
||||
MacroLength=0
|
||||
13
data/devices/steelseries-rival-100.device
Normal file
13
data/devices/steelseries-rival-100.device
Normal file
@@ -0,0 +1,13 @@
|
||||
[Device]
|
||||
# 100; 100 (Dell China); 100 Dota 2 Edition (retail); 100 Dota 2 Edition (Lenovo); 105.
|
||||
DeviceMatch=usb:1038:1702;usb:1038:170a;usb:1038:170b;usb:1038:170c;usb:1038:1814
|
||||
Driver=steelseries
|
||||
Name=SteelSeries Rival 100/105
|
||||
|
||||
[Driver/steelseries]
|
||||
# Actually 6.
|
||||
Buttons=0
|
||||
DeviceVersion=1
|
||||
DpiList=250;500;1000;1250;1500;1750;2000;4000
|
||||
Leds=1
|
||||
Quirk=Rival100
|
||||
@@ -1,6 +1,6 @@
|
||||
[Device]
|
||||
Name=SteelSeries Rival
|
||||
DeviceMatch=usb:1038:1384
|
||||
DeviceMatch=usb:1038:1384;usb:1038:1392;usb:1038:1710;usb:1038:1712;usb:1038:171c;usb:1038:1394;usb:1038:171a;usb:1038:1716;usb:1038:1714;usb:1038:1718
|
||||
Driver=steelseries
|
||||
|
||||
[Driver/steelseries]
|
||||
|
||||
@@ -10,5 +10,4 @@ Buttons=8
|
||||
Leds=1
|
||||
DpiRange=90:5670@90
|
||||
MacroLength=1
|
||||
MonoLed=1
|
||||
ShortButton=1
|
||||
Quirk=SenseiRAW
|
||||
|
||||
12
doc/dbus.rst
12
doc/dbus.rst
@@ -85,13 +85,13 @@ interact with ratbagd.
|
||||
:type: i
|
||||
:flags: read-only,constant
|
||||
|
||||
The DBus API version. This is a stopgap feature while the DBus API
|
||||
is still in flux. The version has no backwards or
|
||||
forward-compatibilty guarantees - your client must understand
|
||||
**exactly** the same version, it is not enough to support an older
|
||||
or a newer version.
|
||||
The DBus API version. This is a stopgap feature while the DBus API
|
||||
is still in flux. The version has no backwards or
|
||||
forward-compatibilty guarantees - your client must understand
|
||||
**exactly** the same version, it is not enough to support an older
|
||||
or a newer version.
|
||||
|
||||
This API will be removed once the DBus API is declared stable.
|
||||
This API will be removed once the DBus API is declared stable.
|
||||
|
||||
.. attribute:: Devices
|
||||
|
||||
|
||||
171
meson.build
171
meson.build
@@ -1,8 +1,8 @@
|
||||
project('libratbag', 'c',
|
||||
version : '0.12',
|
||||
version : '0.17',
|
||||
license : 'MIT/Expat',
|
||||
default_options : [ 'c_std=gnu99', 'warning_level=2' ],
|
||||
meson_version : '>= 0.40.0')
|
||||
meson_version : '>= 0.50.0')
|
||||
|
||||
# The DBus API version. Increase this every time the DBus API changes.
|
||||
# No backwards/forwards guarantee, clients are expected to understand
|
||||
@@ -121,6 +121,18 @@ lib_libhidpp = static_library('hidpp',
|
||||
dependencies : deps_libhidpp)
|
||||
dep_libhidpp = declare_dependency(link_with: lib_libhidpp)
|
||||
|
||||
### libasus.a ####
|
||||
src_libasus = [
|
||||
'src/asus.c',
|
||||
]
|
||||
|
||||
deps_libasus = [ ]
|
||||
|
||||
lib_libasus = static_library('asus',
|
||||
src_libasus,
|
||||
dependencies : deps_libasus)
|
||||
dep_libasus = declare_dependency(link_with: lib_libasus)
|
||||
|
||||
### liblur ####
|
||||
#
|
||||
# liblur is the library to handle logitech unifying receivers.
|
||||
@@ -135,6 +147,7 @@ src_liblur = [
|
||||
deps_liblur = [
|
||||
dep_libutil,
|
||||
dep_libhidpp,
|
||||
dep_libasus,
|
||||
]
|
||||
|
||||
lur_mapfile = 'src/liblur.sym'
|
||||
@@ -166,15 +179,22 @@ pkgconfig.generate (
|
||||
src_libratbag = [
|
||||
'src/libratbag-enums.h',
|
||||
'src/libratbag.h',
|
||||
'src/driver-asus.c',
|
||||
'src/driver-etekcity.c',
|
||||
'src/driver-hidpp20.c',
|
||||
'src/driver-hidpp10.c',
|
||||
'src/driver-logitech-g300.c',
|
||||
'src/driver-logitech-g600.c',
|
||||
'src/driver-roccat.c',
|
||||
'src/driver-roccat-kone-emp.c',
|
||||
'src/driver-roccat-kone-pure.c',
|
||||
'src/driver-gskill.c',
|
||||
'src/driver-openinput.c',
|
||||
'src/driver-steelseries.c',
|
||||
'src/driver-steelseries.h',
|
||||
'src/driver-sinowealth.c',
|
||||
'src/driver-sinowealth.h',
|
||||
'src/driver-sinowealth-nubwo.c',
|
||||
'src/driver-test.c',
|
||||
'src/libratbag.c',
|
||||
'src/libratbag.h',
|
||||
@@ -195,6 +215,7 @@ deps_libratbag = [
|
||||
dep_json_glib,
|
||||
dep_libutil,
|
||||
dep_libhidpp,
|
||||
dep_libasus,
|
||||
]
|
||||
|
||||
lib_libratbag = static_library('ratbag',
|
||||
@@ -276,82 +297,19 @@ man_lur_command = configure_file (
|
||||
)
|
||||
|
||||
#### data files ####
|
||||
# list ordered by git ls-files data/devices/*.device
|
||||
data_files = files(
|
||||
'data/devices/etekcity-scroll-alpha.device',
|
||||
'data/devices/gskill-MX-780.device',
|
||||
'data/devices/logitech-M325.device',
|
||||
'data/devices/logitech-M570.device',
|
||||
'data/devices/logitech-M585-M590.device',
|
||||
'data/devices/logitech-M705.device',
|
||||
'data/devices/logitech-MX-Ergo.device',
|
||||
'data/devices/logitech-MX-Master.device',
|
||||
'data/devices/logitech-MX-Master-2S.device',
|
||||
'data/devices/logitech-MX-Master-3.device',
|
||||
'data/devices/logitech-MX518.device',
|
||||
'data/devices/logitech-T650.device',
|
||||
'data/devices/logitech-Wireless-Touchpad.device',
|
||||
'data/devices/logitech-g-pro-wireless.device',
|
||||
'data/devices/logitech-g-pro.device',
|
||||
'data/devices/logitech-g102-g203.device',
|
||||
'data/devices/logitech-g300.device',
|
||||
'data/devices/logitech-g302.device',
|
||||
'data/devices/logitech-g303.device',
|
||||
'data/devices/logitech-g305.device',
|
||||
'data/devices/logitech-g402.device',
|
||||
'data/devices/logitech-g403-hero.device',
|
||||
'data/devices/logitech-g403-wireless.device',
|
||||
'data/devices/logitech-g403.device',
|
||||
'data/devices/logitech-g5-2007.device',
|
||||
'data/devices/logitech-g5.device',
|
||||
'data/devices/logitech-g500.device',
|
||||
'data/devices/logitech-g500s.device',
|
||||
'data/devices/logitech-g502-hero-wireless.device',
|
||||
'data/devices/logitech-g502-hero.device',
|
||||
'data/devices/logitech-g502-proteus-core.device',
|
||||
'data/devices/logitech-g502-proteus-spectrum.device',
|
||||
'data/devices/logitech-g600.device',
|
||||
'data/devices/logitech-g602.device',
|
||||
'data/devices/logitech-g603.device',
|
||||
'data/devices/logitech-g604.device',
|
||||
'data/devices/logitech-g7.device',
|
||||
'data/devices/logitech-g700-wireless.device',
|
||||
'data/devices/logitech-g700.device',
|
||||
'data/devices/logitech-g700s.device',
|
||||
'data/devices/logitech-g703-hero.device',
|
||||
'data/devices/logitech-g703.device',
|
||||
'data/devices/logitech-g9.device',
|
||||
'data/devices/logitech-g900.device',
|
||||
'data/devices/logitech-g903-hero.device',
|
||||
'data/devices/logitech-g903.device',
|
||||
'data/devices/logitech-g9x-Call-of-Duty-MW3-Edition.device',
|
||||
'data/devices/logitech-g9x-Original.device',
|
||||
'data/devices/logitech-Marathon-M705.device',
|
||||
'data/devices/logitech-MX-Anywhere2.device',
|
||||
'data/devices/logitech-MX-Anywhere2S.device',
|
||||
'data/devices/logitech-MX-Vertical.device',
|
||||
'data/devices/roccat-kone-pure.device',
|
||||
'data/devices/roccat-kone-xtd.device',
|
||||
'data/devices/steelseries-kinzu-v2.device',
|
||||
'data/devices/steelseries-kinzu-v3.device',
|
||||
'data/devices/steelseries-rival-310.device',
|
||||
'data/devices/steelseries-rival-600.device',
|
||||
'data/devices/steelseries-rival.device',
|
||||
'data/devices/steelseries-sensei-310.device',
|
||||
'data/devices/steelseries-sensei-raw.device',
|
||||
)
|
||||
install_subdir('data/devices',
|
||||
strip_directory : true,
|
||||
exclude_files : ['device.example', 'README.md'],
|
||||
install_dir : join_paths(get_option('datadir'), 'libratbag'))
|
||||
|
||||
install_data(data_files,
|
||||
install_dir : join_paths(get_option('datadir'), 'libratbag'))
|
||||
data_parse_test = find_program(join_paths(meson.source_root(), 'test/data-parse-test.py'))
|
||||
test('data-parse-test', data_parse_test, args: 'data/devices')
|
||||
|
||||
data_parse_test = find_program(join_paths(meson.source_root(), 'data/devices/data-parse-test.py'))
|
||||
test('data-parse-test', data_parse_test, args: data_files)
|
||||
duplicate_test = find_program(join_paths(meson.source_root(), 'test/duplicate-check.py'))
|
||||
test('duplicate-test', duplicate_test, args : 'data/devices')
|
||||
|
||||
duplicate_test = find_program(join_paths(meson.source_root(), 'data/devices/duplicate-check.py'))
|
||||
test('duplicate-test', duplicate_test, args : data_files)
|
||||
|
||||
reciever_id_test = find_program(join_paths(meson.source_root(), 'data/devices/receiver-check.py'))
|
||||
test('receiver-id-test', reciever_id_test, args : data_files)
|
||||
receiver_id_test = find_program(join_paths(meson.source_root(), 'test/receiver-check.py'))
|
||||
test('receiver-id-test', receiver_id_test, args : 'data/devices')
|
||||
|
||||
#### tests ####
|
||||
enable_tests = get_option('tests')
|
||||
@@ -387,16 +345,18 @@ if enable_tests
|
||||
test('test-util', test_util)
|
||||
test('test-iconv-helper', test_iconv_helper)
|
||||
|
||||
valgrind = find_program('valgrind')
|
||||
valgrind_suppressions_file = join_paths(meson.source_root(), 'test', 'valgrind.suppressions')
|
||||
add_test_setup('valgrind',
|
||||
exe_wrapper : [
|
||||
valgrind,
|
||||
'--leak-check=full',
|
||||
'--quiet',
|
||||
'--error-exitcode=3',
|
||||
'--suppressions=' + valgrind_suppressions_file ],
|
||||
timeout_multiplier: 5)
|
||||
valgrind = find_program('valgrind', required : false)
|
||||
if valgrind.found()
|
||||
valgrind_suppressions_file = join_paths(meson.source_root(), 'test', 'valgrind.suppressions')
|
||||
add_test_setup('valgrind',
|
||||
exe_wrapper : [
|
||||
valgrind,
|
||||
'--leak-check=full',
|
||||
'--quiet',
|
||||
'--error-exitcode=3',
|
||||
'--suppressions=' + valgrind_suppressions_file ],
|
||||
timeout_multiplier: 5)
|
||||
endif
|
||||
endif
|
||||
|
||||
#### ratbagd ####
|
||||
@@ -444,10 +404,9 @@ install_man('ratbagd/ratbagd.8')
|
||||
# (org.freedesktop.ratbag_devel1). This server is used by ratbagdctl.devel.
|
||||
#
|
||||
|
||||
config_ratbagd_devel = configuration_data()
|
||||
dbus_devel_policy = configure_file(input : 'dbus/org.freedesktop.ratbag_devel1.conf.in',
|
||||
output : 'org.freedesktop.ratbag_devel1.conf',
|
||||
configuration : config_ratbagd_devel)
|
||||
copy: true)
|
||||
|
||||
# This is a hack. We always install the devel policy file into
|
||||
# /etc/dbus-1/system.d, independent of any prefixes we use otherwise.
|
||||
@@ -532,12 +491,23 @@ configure_file(input : 'dbus/org.freedesktop.ratbag1.conf.in',
|
||||
|
||||
#### tools ####
|
||||
|
||||
if meson.version().version_compare('<0.48.0')
|
||||
python = import('python3')
|
||||
py3 = python.find_python()
|
||||
else
|
||||
pymod = import('python')
|
||||
py3 = pymod.find_installation()
|
||||
# This is a special idiomatic construct in meson to get a fast dependency that
|
||||
# doesn't exist and isn't logged as "not found".
|
||||
dep_python3 = dependency('', required : false)
|
||||
pymod = import('python')
|
||||
py3 = pymod.find_installation()
|
||||
if meson.version().version_compare('>= 0.53.0')
|
||||
dep_python3 = py3.dependency(embed : true)
|
||||
endif
|
||||
py_version = py3.language_version()
|
||||
|
||||
# From python 3.8 we neeed python3-embed
|
||||
embed = py_version.version_compare('>= 3.8') ? '-embed' : ''
|
||||
if not dep_python3.found()
|
||||
dep_python3 = dependency('python-@0@@1@'.format(py_version, embed), required : false)
|
||||
if not dep_python3.found()
|
||||
dep_python3 = dependency('python3@0@'.format(embed))
|
||||
endif
|
||||
endif
|
||||
|
||||
config_ratbagctl = configuration_data()
|
||||
@@ -601,12 +571,6 @@ swig_gen = generator(
|
||||
'@INPUT@'],
|
||||
)
|
||||
|
||||
# From python 3.8 we neeed python3-embed
|
||||
dep_python3 = dependency('python3-embed', required: false)
|
||||
if not dep_python3.found()
|
||||
dep_python3 = dependency('python3')
|
||||
endif
|
||||
|
||||
wrapper_deps = [
|
||||
dep_python3,
|
||||
dep_libratbag,
|
||||
@@ -619,7 +583,9 @@ shared_library(
|
||||
'libratbag',
|
||||
c_source,
|
||||
name_prefix: '_',
|
||||
c_args : ['-Wno-missing-prototypes', '-Wno-format-nonliteral'],
|
||||
c_args : ['-Wno-missing-prototypes',
|
||||
'-Wno-format-nonliteral',
|
||||
'-Wno-missing-field-initializers'],
|
||||
extra_files: [ i_source ] + src_libratbag ,
|
||||
dependencies: deps_libratbag + wrapper_deps,
|
||||
include_directories : include_directories('src', 'tools'),
|
||||
@@ -632,7 +598,10 @@ shared_library(
|
||||
'hidpp',
|
||||
c_source,
|
||||
name_prefix: '_',
|
||||
c_args : ['-Wno-missing-prototypes', '-Wno-format-nonliteral'],
|
||||
c_args : ['-Wno-missing-prototypes',
|
||||
'-Wno-format-nonliteral',
|
||||
'-Wno-missing-field-initializers',
|
||||
'-Wno-strict-prototypes'],
|
||||
extra_files: [ i_source ] + src_libratbag ,
|
||||
dependencies: deps_libratbag + wrapper_deps,
|
||||
include_directories : include_directories('src', 'tools'),
|
||||
|
||||
@@ -172,6 +172,8 @@ static void ratbagd_device_commit_pending(void *data)
|
||||
int r;
|
||||
|
||||
r = ratbag_device_commit(device->lib_device);
|
||||
if (r)
|
||||
log_error("error committing device (%d)\n", r);
|
||||
if (r < 0)
|
||||
ratbagd_device_resync(device, device->ctx->bus);
|
||||
ratbagd_device_unref(device);
|
||||
|
||||
@@ -170,7 +170,7 @@ static void parse_led_member(JsonObject *obj, const gchar *name,
|
||||
if (streq(name, "type")) {
|
||||
gboolean v = json_object_get_int_member(obj, name);
|
||||
|
||||
if (v < 0 || v > RATBAG_LED_TYPE_WHEEL)
|
||||
if (v < 0 || v > RATBAG_LED_TYPE_SWITCHES)
|
||||
parser_error("type");
|
||||
|
||||
led->type = v;
|
||||
@@ -241,7 +241,7 @@ special_lookup(const char *string)
|
||||
{ "wheel-down", RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_DOWN},
|
||||
{ "ratchet-mode-switch", RATBAG_BUTTON_ACTION_SPECIAL_RATCHET_MODE_SWITCH},
|
||||
{ "resolution-cycle-up", RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_CYCLE_UP},
|
||||
{ "resolution-cycledown", RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_CYCLE_DOWN},
|
||||
{ "resolution-cycle-down", RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_CYCLE_DOWN},
|
||||
{ "resolution-up", RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_UP},
|
||||
{ "resolution-down", RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_DOWN},
|
||||
{ "resolution-alternate", RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_ALTERNATE},
|
||||
@@ -515,6 +515,7 @@ int ratbagd_parse_json(const char *data, struct ratbag_test_device *device)
|
||||
JsonArray *arr;
|
||||
int r = -EINVAL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GList) list = NULL;
|
||||
|
||||
error = 0;
|
||||
parser = json_parser_new();
|
||||
@@ -540,7 +541,7 @@ int ratbagd_parse_json(const char *data, struct ratbag_test_device *device)
|
||||
num_buttons = device->num_buttons;
|
||||
num_leds = device->num_leds;
|
||||
|
||||
g_autoptr(GList) list = json_array_get_elements(arr);
|
||||
list = json_array_get_elements(arr);
|
||||
GList *l = list;
|
||||
int idx = 0;
|
||||
while (l != NULL) {
|
||||
|
||||
@@ -507,10 +507,8 @@ ratbagd_profile_set_report_rate(sd_bus *bus,
|
||||
return r;
|
||||
|
||||
/* basic sanity check */
|
||||
if (rate > 5000)
|
||||
rate = 5000;
|
||||
else if (rate % 100)
|
||||
rate = rate - (rate % 100);
|
||||
if (rate > 8000)
|
||||
rate = 8000;
|
||||
|
||||
r = ratbag_profile_set_report_rate(profile->lib_profile, rate);
|
||||
if (r == 0) {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <libratbag.h>
|
||||
#include <libudev.h>
|
||||
#include <stdio.h>
|
||||
@@ -547,6 +548,13 @@ static bool install_ratbagd_devel_dbus_policy(void)
|
||||
log_error("Failed to source policy file: %m\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (mkdir_p(dirname(strdupa(DBUS_POLICY_DST)), 0755)) {
|
||||
log_error("Failed to create destination path: %m\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
out = open(DBUS_POLICY_DST, O_CREAT|O_WRONLY, 0644);
|
||||
if (out == -1) {
|
||||
log_error("Failed to open destination: %m\n");
|
||||
@@ -606,7 +614,7 @@ static void remove_ratbagd_devel_dbus_policy(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct ratbagd *ctx = NULL;
|
||||
int r;
|
||||
int r = 0;
|
||||
|
||||
#if DISABLE_COREDUMP
|
||||
const struct rlimit corelimit = { 0, 0 };
|
||||
@@ -689,5 +697,5 @@ void ratbagd_schedule_task(struct ratbagd *ctx,
|
||||
cb->callback = callback;
|
||||
cb->userdata = userdata;
|
||||
|
||||
sd_event_add_post(ctx->event, &source, ratbagd_callback_handler, cb);
|
||||
sd_event_add_defer(ctx->event, &source, ratbagd_callback_handler, cb);
|
||||
}
|
||||
|
||||
496
src/asus.c
Normal file
496
src/asus.c
Normal file
@@ -0,0 +1,496 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Kyoken, kyoken@kyoken.ninja
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "asus.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "libratbag-data.h"
|
||||
#include "libratbag-private.h"
|
||||
|
||||
/* ASUS commands */
|
||||
#define ASUS_CMD_GET_LED_DATA 0x0312 /* get all LEDs */
|
||||
#define ASUS_CMD_GET_SETTINGS 0x0412 /* dpi, rate, button response, angle snapping */
|
||||
#define ASUS_CMD_GET_BUTTON_DATA 0x0512 /* get all buttons */
|
||||
#define ASUS_CMD_GET_PROFILE_DATA 0x0012 /* get current profile info */
|
||||
#define ASUS_CMD_SET_LED 0x2851 /* set single led */
|
||||
#define ASUS_CMD_SET_SETTING 0x3151 /* dpi / rate / button response / angle snapping */
|
||||
#define ASUS_CMD_SET_BUTTON 0x2151 /* set single button */
|
||||
#define ASUS_CMD_SET_PROFILE 0x0250 /* switch profile */
|
||||
#define ASUS_CMD_SAVE 0x0350 /* save settings */
|
||||
|
||||
/* fields order in _asus_dpiX_data, used for setting with ASUS_CMD_SET_SETTING */
|
||||
#define ASUS_FIELD_RATE 0
|
||||
#define ASUS_FIELD_RESPONSE 1
|
||||
#define ASUS_FIELD_SNAPPING 2
|
||||
|
||||
/* order is mandatory because index is mapped from ButtonMapping configuration property */
|
||||
static struct asus_button ASUS_BUTTON_MAPPING[] = {
|
||||
{ 0xf0, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 1, 0 }, /* left */
|
||||
{ 0xf1, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 2, 0 }, /* right (button 3 in xev) */
|
||||
{ 0xf2, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 3, 0 }, /* middle (button 2 in xev) */
|
||||
{ 0xe4, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 4, 0 }, /* backward (on left side) */
|
||||
{ 0xe5, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 5, 0 }, /* forward (on left side) */
|
||||
{ 0xe6, RATBAG_BUTTON_ACTION_TYPE_SPECIAL, 0, RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_CYCLE_UP },
|
||||
{ 0xe8, RATBAG_BUTTON_ACTION_TYPE_SPECIAL, 0, RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_UP },
|
||||
{ 0xe9, RATBAG_BUTTON_ACTION_TYPE_SPECIAL, 0, RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_DOWN },
|
||||
{ 0xe1, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 4, 0 }, /* backward on right side */
|
||||
{ 0xe2, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 5, 0 }, /* forward on right side */
|
||||
{ 0xff, RATBAG_BUTTON_ACTION_TYPE_NONE, 0, 0 }, /* placeholder */
|
||||
{ 0xff, RATBAG_BUTTON_ACTION_TYPE_NONE, 0, 0 }, /* placeholder */
|
||||
{ 0xff, RATBAG_BUTTON_ACTION_TYPE_NONE, 0, 0 }, /* placeholder */
|
||||
{ 0xff, RATBAG_BUTTON_ACTION_TYPE_NONE, 0, 0 }, /* placeholder */
|
||||
{ 0xff, RATBAG_BUTTON_ACTION_TYPE_NONE, 0, 0 }, /* placeholder */
|
||||
{ 0xff, RATBAG_BUTTON_ACTION_TYPE_NONE, 0, 0 }, /* placeholder */
|
||||
};
|
||||
|
||||
/* key mapping, the index is actual ASUS code */
|
||||
static unsigned char ASUS_KEY_MAPPING[] = {
|
||||
/* 00 */ 0, 0, 0, 0,
|
||||
/* 04 */ KEY_A, KEY_B, KEY_C, KEY_D,
|
||||
/* 08 */ KEY_E, KEY_F, KEY_G, KEY_H,
|
||||
/* 0C */ KEY_I, KEY_J, KEY_K, KEY_L,
|
||||
/* 0E */ KEY_M, KEY_N, KEY_O, KEY_P,
|
||||
/* 14 */ KEY_Q, KEY_R, KEY_S, KEY_T,
|
||||
/* 18 */ KEY_U, KEY_V, KEY_W, KEY_X,
|
||||
/* 1C */ KEY_Y, KEY_Z, KEY_1, KEY_2,
|
||||
/* 1E */ KEY_3, KEY_4, KEY_5, KEY_6,
|
||||
/* 24 */ KEY_7, KEY_8, KEY_9, KEY_0,
|
||||
/* 28 */ KEY_ENTER, KEY_ESC, KEY_BACKSPACE, KEY_TAB,
|
||||
/* 2C */ KEY_SPACE, KEY_MINUS, KEY_KPPLUS, 0,
|
||||
/* 2E */ 0, 0, 0, 0,
|
||||
/* 34 */ 0, KEY_GRAVE, KEY_EQUAL, 0,
|
||||
/* 38 */ KEY_SLASH, 0, KEY_F1, KEY_F2,
|
||||
/* 3C */ KEY_F3, KEY_F4, KEY_F5, KEY_F6,
|
||||
/* 3E */ KEY_F7, KEY_F8, KEY_F9, KEY_F10,
|
||||
/* 44 */ KEY_F11, KEY_F12, 0, 0,
|
||||
/* 48 */ 0, 0, KEY_HOME, KEY_PAGEUP,
|
||||
/* 4C */ KEY_DELETE, 0, KEY_PAGEDOWN, KEY_RIGHT,
|
||||
/* 4E */ KEY_LEFT, KEY_DOWN, KEY_UP, 0,
|
||||
/* 54 */ 0, 0, 0, 0,
|
||||
/* 58 */ 0, KEY_KP1, KEY_KP2, KEY_KP3,
|
||||
/* 5C */ KEY_KP4, KEY_KP5, KEY_KP6, KEY_KP7,
|
||||
/* 5E */ KEY_KP8, KEY_KP9, 0,
|
||||
};
|
||||
|
||||
static unsigned int ASUS_LED_TYPE[] = {
|
||||
RATBAG_LED_TYPE_LOGO, /* Mouse logo */
|
||||
RATBAG_LED_TYPE_WHEEL, /* Mouse wheel */
|
||||
RATBAG_LED_TYPE_SIDE, /* Bottom of the mouse */
|
||||
};
|
||||
|
||||
static unsigned int ASUS_POLLING_RATES[] = { 125, 250, 500, 1000 };
|
||||
|
||||
/* search for ASUS button by ratbag types */
|
||||
struct asus_button *
|
||||
asus_find_button_by_action(struct ratbag_button_action action)
|
||||
{
|
||||
struct asus_button *asus_button;
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH(ASUS_BUTTON_MAPPING); i++) {
|
||||
asus_button = &ASUS_BUTTON_MAPPING[i];
|
||||
if ((action.type == RATBAG_BUTTON_ACTION_TYPE_BUTTON && asus_button->button == action.action.button) ||
|
||||
(action.type == RATBAG_BUTTON_ACTION_TYPE_SPECIAL && asus_button->special == action.action.special))
|
||||
return asus_button;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* search for ASUS button by ASUS button code */
|
||||
struct asus_button *
|
||||
asus_find_button_by_code(uint8_t asus_code)
|
||||
{
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH(ASUS_BUTTON_MAPPING); i++) {
|
||||
if (ASUS_BUTTON_MAPPING[i].asus_code == asus_code)
|
||||
return &ASUS_BUTTON_MAPPING[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* search for ASUS key code by Linux key code */
|
||||
int
|
||||
asus_find_key_code(unsigned int linux_code)
|
||||
{
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH(ASUS_KEY_MAPPING); i++) {
|
||||
if (ASUS_KEY_MAPPING[i] == linux_code)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* convert ASUS key code to Linux key code */
|
||||
int
|
||||
asus_get_linux_key_code(uint8_t asus_code) {
|
||||
assert(asus_code <= ARRAY_LENGTH(ASUS_KEY_MAPPING));
|
||||
return ASUS_KEY_MAPPING[asus_code];
|
||||
}
|
||||
|
||||
int
|
||||
asus_query(struct ratbag_device *device,
|
||||
union asus_request *request, union asus_response *response)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ratbag_hidraw_output_report(device, request->raw, ASUS_PACKET_SIZE);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
memset(response, 0, sizeof(union asus_response));
|
||||
rc = ratbag_hidraw_read_input_report(device, response->raw, ASUS_PACKET_SIZE, NULL);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
/* invalid state, disconnected or sleeping */
|
||||
if (response->data.code == 0xaaff) {
|
||||
return ASUS_STATUS_ERROR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
asus_setup_profile(struct ratbag_device *device, struct ratbag_profile *profile)
|
||||
{
|
||||
ratbag_profile_set_report_rate_list(
|
||||
profile, ASUS_POLLING_RATES, ARRAY_LENGTH(ASUS_POLLING_RATES));
|
||||
}
|
||||
|
||||
void
|
||||
asus_setup_button(struct ratbag_device *device, struct ratbag_button *button)
|
||||
{
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_BUTTON);
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_SPECIAL);
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_KEY);
|
||||
}
|
||||
|
||||
void
|
||||
asus_setup_resolution(struct ratbag_device *device, struct ratbag_resolution *resolution)
|
||||
{
|
||||
const struct dpi_range *dpirange = ratbag_device_data_asus_get_dpi_range(device->data);
|
||||
if (!dpirange)
|
||||
return;
|
||||
|
||||
ratbag_resolution_set_dpi_list_from_range(
|
||||
resolution, dpirange->min, dpirange->max);
|
||||
}
|
||||
|
||||
void
|
||||
asus_setup_led(struct ratbag_device *device, struct ratbag_led *led)
|
||||
{
|
||||
led->colordepth = RATBAG_LED_COLORDEPTH_RGB_888;
|
||||
led->type = ASUS_LED_TYPE[led->index];
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_ON);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_CYCLE);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
|
||||
}
|
||||
|
||||
int
|
||||
asus_save_profile(struct ratbag_device *device)
|
||||
{
|
||||
int rc;
|
||||
union asus_response response;
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_SAVE,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
asus_get_profile_data(struct ratbag_device *device, struct asus_profile_data *data)
|
||||
{
|
||||
int rc;
|
||||
uint32_t quirks = ratbag_device_data_asus_get_quirks(device->data);
|
||||
union asus_response response;
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_GET_PROFILE_DATA,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
if (quirks & ASUS_QUIRK_STRIX_PROFILE)
|
||||
data->profile_id = response.data.results[7];
|
||||
else
|
||||
data->profile_id = response.data.results[8];
|
||||
|
||||
data->version_primary_major = response.data.results[13];
|
||||
data->version_primary_minor = response.data.results[12];
|
||||
data->version_primary_build = response.data.results[11];
|
||||
|
||||
data->version_secondary_major = response.data.results[4];
|
||||
data->version_secondary_minor = response.data.results[3];
|
||||
data->version_secondary_build = response.data.results[2];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
asus_set_profile(struct ratbag_device *device, unsigned int index)
|
||||
{
|
||||
int rc;
|
||||
union asus_response response;
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_SET_PROFILE,
|
||||
.data.params[0] = index,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* read button bindings using ButtonMapping configuration property */
|
||||
int
|
||||
asus_get_binding_data(struct ratbag_device *device, union asus_binding_data *data)
|
||||
{
|
||||
int rc;
|
||||
union asus_response response;
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_GET_BUTTON_DATA,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
memcpy(data->raw, response.raw, sizeof(data->raw));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set button binding using ASUS code of the button */
|
||||
int
|
||||
asus_set_button_action(struct ratbag_device *device, unsigned int asus_index, uint8_t asus_code, uint8_t asus_type)
|
||||
{
|
||||
int rc;
|
||||
union asus_response response;
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_SET_BUTTON,
|
||||
};
|
||||
|
||||
/* source (physical mouse button) */
|
||||
request.data.params[2] = ASUS_BUTTON_MAPPING[asus_index].asus_code;
|
||||
request.data.params[3] = ASUS_BUTTON_ACTION_TYPE_BUTTON;
|
||||
|
||||
/* destination (mouse button or keyboard key action) */
|
||||
request.data.params[4] = asus_code;
|
||||
request.data.params[5] = asus_type;
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
asus_get_resolution_data(struct ratbag_device *device, union asus_resolution_data *data)
|
||||
{
|
||||
int rc;
|
||||
uint32_t quirks = ratbag_device_data_asus_get_quirks(device->data);
|
||||
union asus_response response;
|
||||
unsigned int dpi_count = ratbag_device_get_profile(device, 0)->num_resolutions;
|
||||
unsigned int i;
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_GET_SETTINGS,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
memcpy(data->raw, response.raw, sizeof(data->raw));
|
||||
|
||||
/* convert DPI rates */
|
||||
switch (dpi_count) {
|
||||
case 2: /* 2 DPI presets */
|
||||
for (i = 0; i < dpi_count; i++) {
|
||||
data->data2.dpi[i] = data->data2.dpi[i] * 50 + 50;
|
||||
if (quirks & ASUS_QUIRK_DOUBLE_DPI)
|
||||
data->data2.dpi[i] *= 2;
|
||||
}
|
||||
data->data2.rate = ASUS_POLLING_RATES[data->data2.rate];
|
||||
break;
|
||||
|
||||
case 4: /* 4 DPI presets */
|
||||
for (i = 0; i < dpi_count; i++) {
|
||||
data->data4.dpi[i] = data->data4.dpi[i] * 50 + 50;
|
||||
if (quirks & ASUS_QUIRK_DOUBLE_DPI)
|
||||
data->data4.dpi[i] *= 2;
|
||||
}
|
||||
data->data4.rate = ASUS_POLLING_RATES[data->data4.rate];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set DPI for the specified preset */
|
||||
int
|
||||
asus_set_dpi(struct ratbag_device *device, unsigned int index, unsigned int dpi)
|
||||
{
|
||||
int rc;
|
||||
uint32_t quirks = ratbag_device_data_asus_get_quirks(device->data);
|
||||
union asus_response response;
|
||||
unsigned int idpi;
|
||||
|
||||
idpi = dpi;
|
||||
if (quirks & ASUS_QUIRK_DOUBLE_DPI)
|
||||
idpi /= 2;
|
||||
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_SET_SETTING,
|
||||
.data.params[0] = index,
|
||||
.data.params[2] = (idpi - 50) / 50,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set polling rate in Hz */
|
||||
int
|
||||
asus_set_polling_rate(struct ratbag_device *device, unsigned int hz)
|
||||
{
|
||||
int rc;
|
||||
union asus_response response;
|
||||
unsigned int dpi_count = ratbag_device_get_profile(device, 0)->num_resolutions;
|
||||
unsigned int i;
|
||||
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_SET_SETTING,
|
||||
.data.params[0] = dpi_count + ASUS_FIELD_RATE, /* field index to set */
|
||||
};
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(ASUS_POLLING_RATES); i++) {
|
||||
if (ASUS_POLLING_RATES[i] == hz) {
|
||||
request.data.params[2] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set button response/debounce in ms (from 4 to 32 with step of 4) */
|
||||
int
|
||||
asus_set_button_response(struct ratbag_device *device, unsigned int ms)
|
||||
{
|
||||
assert(ms >= 4);
|
||||
|
||||
int rc;
|
||||
unsigned int dpi_count = ratbag_device_get_profile(device, 0)->num_resolutions;
|
||||
union asus_response response;
|
||||
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_SET_SETTING,
|
||||
.data.params[0] = dpi_count + ASUS_FIELD_RESPONSE, /* field index to set */
|
||||
.data.params[2] = ms / 4 - 1,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
asus_set_angle_snapping(struct ratbag_device *device, bool is_enabled)
|
||||
{
|
||||
int rc;
|
||||
union asus_response response;
|
||||
unsigned int dpi_count = ratbag_device_get_profile(device, 0)->num_resolutions;
|
||||
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_SET_SETTING,
|
||||
.data.params[0] = dpi_count + ASUS_FIELD_SNAPPING, /* field index to set */
|
||||
.data.params[2] = is_enabled ? 1 : 0,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
asus_get_led_data(struct ratbag_device *device, union asus_led_data *data)
|
||||
{
|
||||
int rc;
|
||||
union asus_response response;
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_GET_LED_DATA,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
memcpy(data->raw, response.raw, sizeof(data->raw));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set LED mode, brightness (0-4) and color */
|
||||
int
|
||||
asus_set_led(struct ratbag_device *device,
|
||||
uint8_t index, uint8_t mode, uint8_t brightness,
|
||||
struct ratbag_color color)
|
||||
{
|
||||
int rc;
|
||||
union asus_response response;
|
||||
union asus_request request = {
|
||||
.data.cmd = ASUS_CMD_SET_LED,
|
||||
.data.params[0] = index,
|
||||
.data.params[2] = mode,
|
||||
.data.params[3] = brightness,
|
||||
.data.params[4] = color.red,
|
||||
.data.params[5] = color.green,
|
||||
.data.params[6] = color.blue,
|
||||
};
|
||||
|
||||
rc = asus_query(device, &request, &response);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
214
src/asus.h
Normal file
214
src/asus.h
Normal file
@@ -0,0 +1,214 @@
|
||||
#pragma once
|
||||
|
||||
#include <linux/input.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libratbag-private.h"
|
||||
#include "libratbag-hidraw.h"
|
||||
|
||||
#define ASUS_QUIRK_DOUBLE_DPI 1 << 0
|
||||
#define ASUS_QUIRK_STRIX_PROFILE 1 << 1
|
||||
|
||||
#define ASUS_PACKET_SIZE 64
|
||||
#define ASUS_BUTTON_ACTION_TYPE_KEY 0 /* keyboard key */
|
||||
#define ASUS_BUTTON_ACTION_TYPE_BUTTON 1 /* mouse button */
|
||||
#define ASUS_BUTTON_CODE_DISABLED 0xff /* disabled mouse button */
|
||||
#define ASUS_STATUS_ERROR 0xffaa /* invalid state/request, disconnected or sleeping */
|
||||
|
||||
/* maximum number of buttons across all ASUS devices */
|
||||
#define ASUS_MAX_NUM_BUTTON 16
|
||||
|
||||
/* maximum number of DPI presets across all ASUS devices */
|
||||
/* for 4 DPI devices: 0 - red, 1 - purple, 2 - blue (default), 3 - green */
|
||||
/* for 2 DPI devices: 0 - main (default), 1 - alternative */
|
||||
#define ASUS_MAX_NUM_DPI 4
|
||||
|
||||
/* maximum number of LEDs across all ASUS devices */
|
||||
#define ASUS_MAX_NUM_LED 3
|
||||
|
||||
/* base request */
|
||||
|
||||
struct _asus_request {
|
||||
uint16_t cmd;
|
||||
uint8_t params[ASUS_PACKET_SIZE - 2];
|
||||
} __attribute__((packed));
|
||||
_Static_assert(sizeof(struct _asus_request) == ASUS_PACKET_SIZE, "The size of `_asus_request` is wrong.");
|
||||
|
||||
union asus_request {
|
||||
struct _asus_request data;
|
||||
uint8_t raw[ASUS_PACKET_SIZE];
|
||||
};
|
||||
|
||||
/* base response */
|
||||
|
||||
struct _asus_response {
|
||||
uint16_t code;
|
||||
uint8_t results[ASUS_PACKET_SIZE - 2];
|
||||
} __attribute__((packed));
|
||||
_Static_assert(sizeof(struct _asus_response) == ASUS_PACKET_SIZE, "The size of `_asus_response` is wrong.");
|
||||
|
||||
union asus_response {
|
||||
struct _asus_response data;
|
||||
uint8_t raw[ASUS_PACKET_SIZE];
|
||||
};
|
||||
|
||||
/* current profile ID and firmware info */
|
||||
|
||||
struct asus_profile_data {
|
||||
unsigned int profile_id;
|
||||
uint8_t version_primary_major;
|
||||
uint8_t version_primary_minor;
|
||||
uint8_t version_primary_build;
|
||||
uint8_t version_secondary_major;
|
||||
uint8_t version_secondary_minor;
|
||||
uint8_t version_secondary_build;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* button bindings */
|
||||
|
||||
struct _asus_binding {
|
||||
uint8_t action; /* ASUS code (for both keyboard keys and mouse buttons) */
|
||||
uint8_t type; /* ASUS action type */
|
||||
} __attribute__((packed));
|
||||
|
||||
struct _asus_binding_data {
|
||||
uint32_t pad;
|
||||
struct _asus_binding binding[ASUS_MAX_NUM_BUTTON];
|
||||
} __attribute__((packed));
|
||||
|
||||
union asus_binding_data {
|
||||
struct _asus_binding_data data;
|
||||
uint8_t raw[ASUS_PACKET_SIZE];
|
||||
};
|
||||
|
||||
/* DPI data */
|
||||
|
||||
struct _asus_dpi2_data {
|
||||
uint32_t pad;
|
||||
uint16_t dpi[2]; /* DPI presets */
|
||||
uint16_t rate; /* polling rate */
|
||||
uint16_t response; /* button response */
|
||||
uint16_t snapping; /* angle snapping (on/off) */
|
||||
} __attribute__((packed)); /* struct for storing 2 DPI presets and extra settings */
|
||||
|
||||
struct _asus_dpi4_data {
|
||||
uint32_t pad;
|
||||
uint16_t dpi[4];
|
||||
uint16_t rate;
|
||||
uint16_t response;
|
||||
uint16_t snapping;
|
||||
} __attribute__((packed)); /* struct for storing 4 DPI presets and extra settings */
|
||||
|
||||
union asus_resolution_data {
|
||||
struct _asus_dpi2_data data2; /* data for 2 DPI presets */
|
||||
struct _asus_dpi4_data data4; /* data for 4 DPI presets */
|
||||
uint8_t raw[sizeof(struct _asus_dpi4_data)];
|
||||
};
|
||||
|
||||
/* LED data */
|
||||
|
||||
struct _asus_led {
|
||||
uint8_t mode;
|
||||
uint8_t brightness; /* 0-4 */
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct _asus_led_data {
|
||||
uint32_t pad;
|
||||
struct _asus_led led[ASUS_MAX_NUM_LED]; /* LEDs */
|
||||
} __attribute__((packed));
|
||||
|
||||
union asus_led_data {
|
||||
struct _asus_led_data data;
|
||||
uint8_t raw[sizeof(struct _asus_led_data)];
|
||||
};
|
||||
|
||||
/* button define */
|
||||
struct asus_button {
|
||||
uint8_t asus_code; /* used for button action */
|
||||
enum ratbag_button_action_type type;
|
||||
uint8_t button; /* mouse button number, optional */
|
||||
enum ratbag_button_action_special special; /* special action, optional */
|
||||
};
|
||||
|
||||
struct asus_button *
|
||||
asus_find_button_by_action(struct ratbag_button_action action);
|
||||
|
||||
struct asus_button *
|
||||
asus_find_button_by_code(uint8_t asus_code);
|
||||
|
||||
int
|
||||
asus_find_key_code(unsigned int linux_code);
|
||||
|
||||
int
|
||||
asus_get_linux_key_code(uint8_t asus_code);
|
||||
|
||||
/* initializers of ratbag data */
|
||||
|
||||
void
|
||||
asus_setup_profile(struct ratbag_device *device, struct ratbag_profile *profile);
|
||||
|
||||
void
|
||||
asus_setup_button(struct ratbag_device *device, struct ratbag_button *button);
|
||||
|
||||
void
|
||||
asus_setup_resolution(struct ratbag_device *device, struct ratbag_resolution *resolution);
|
||||
|
||||
void
|
||||
asus_setup_led(struct ratbag_device *device, struct ratbag_led *led);
|
||||
|
||||
/* generic i/o */
|
||||
|
||||
int
|
||||
asus_query(struct ratbag_device *device, union asus_request *request, union asus_response *response);
|
||||
|
||||
/* commit */
|
||||
|
||||
int
|
||||
asus_save_profile(struct ratbag_device *device);
|
||||
|
||||
/* profiles */
|
||||
|
||||
int
|
||||
asus_get_profile_data(struct ratbag_device *device, struct asus_profile_data *data);
|
||||
|
||||
int
|
||||
asus_set_profile(struct ratbag_device *device, unsigned int index);
|
||||
|
||||
/* button bindings */
|
||||
|
||||
int
|
||||
asus_get_binding_data(struct ratbag_device *device, union asus_binding_data *data);
|
||||
|
||||
int
|
||||
asus_set_button_action(struct ratbag_device *device, unsigned int index,
|
||||
uint8_t asus_code, uint8_t asus_type);
|
||||
|
||||
/* resolution settings */
|
||||
|
||||
int
|
||||
asus_get_resolution_data(struct ratbag_device *device, union asus_resolution_data *data);
|
||||
|
||||
int
|
||||
asus_set_dpi(struct ratbag_device *device, unsigned int index, unsigned int dpi);
|
||||
|
||||
int
|
||||
asus_set_polling_rate(struct ratbag_device *device, unsigned int hz);
|
||||
|
||||
int
|
||||
asus_set_button_response(struct ratbag_device *device, unsigned int ms);
|
||||
|
||||
int
|
||||
asus_set_angle_snapping(struct ratbag_device *device, bool is_enabled);
|
||||
|
||||
/* LED settings */
|
||||
|
||||
int
|
||||
asus_get_led_data(struct ratbag_device *device, union asus_led_data *data);
|
||||
|
||||
int
|
||||
asus_set_led(struct ratbag_device *device,
|
||||
uint8_t index, uint8_t mode, uint8_t brightness,
|
||||
struct ratbag_color color);
|
||||
517
src/driver-asus.c
Normal file
517
src/driver-asus.c
Normal file
@@ -0,0 +1,517 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Kyoken, kyoken@kyoken.ninja
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <libevdev/libevdev.h>
|
||||
#include <linux/input.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libratbag-private.h"
|
||||
#include "libratbag-hidraw.h"
|
||||
#include "libratbag-data.h"
|
||||
|
||||
#include "asus.h"
|
||||
|
||||
/* ButtonMapping configuration property defaults, stores indices for ASUS_BUTTON_MAPPING */
|
||||
static int8_t ASUS_BUTTON_MAPPING_INDEX[] = {
|
||||
0, /* left */
|
||||
1, /* right (button 3 in xev) */
|
||||
2, /* middle (button 2 in xev) */
|
||||
6, /* wheel up */
|
||||
7, /* wheel down */
|
||||
5, /* DPI */
|
||||
3, /* backward */
|
||||
4, /* forward */
|
||||
-1, /* placeholder */
|
||||
-1, /* placeholder */
|
||||
-1, /* placeholder */
|
||||
-1, /* placeholder */
|
||||
-1, /* placeholder */
|
||||
-1, /* placeholder */
|
||||
-1, /* placeholder */
|
||||
-1, /* placeholder */
|
||||
};
|
||||
|
||||
static unsigned int ASUS_LED_MODE[] = {
|
||||
RATBAG_LED_ON,
|
||||
RATBAG_LED_BREATHING,
|
||||
RATBAG_LED_CYCLE,
|
||||
RATBAG_LED_ON, /* rainbow wave */
|
||||
RATBAG_LED_ON, /* reactive - react to clicks */
|
||||
RATBAG_LED_ON, /* custom - depends on mouse type */
|
||||
RATBAG_LED_ON, /* battery - battery indicator */
|
||||
};
|
||||
|
||||
struct asus_data {
|
||||
uint8_t is_ready;
|
||||
};
|
||||
|
||||
static int
|
||||
asus_driver_load_profile(struct ratbag_device *device, struct ratbag_profile *profile)
|
||||
{
|
||||
int rc;
|
||||
const int8_t *bmi = ratbag_device_data_asus_get_button_mapping(device->data);
|
||||
struct _asus_binding *asus_binding;
|
||||
struct _asus_led *asus_led;
|
||||
struct asus_button *asus_button;
|
||||
struct ratbag_button *button;
|
||||
struct ratbag_led *led;
|
||||
struct ratbag_resolution *resolution;
|
||||
union asus_binding_data binding_data;
|
||||
union asus_led_data led_data;
|
||||
union asus_resolution_data resolution_data;
|
||||
unsigned int dpi_count = ratbag_device_get_profile(device, 0)->num_resolutions;
|
||||
|
||||
/* get buttons */
|
||||
|
||||
log_debug(device->ratbag, "Loading buttons data\n");
|
||||
rc = asus_get_binding_data(device, &binding_data);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
ratbag_profile_for_each_button(profile, button) {
|
||||
int asus_index = bmi[button->index] != -1 ? bmi[button->index] : ASUS_BUTTON_MAPPING_INDEX[button->index];
|
||||
if (asus_index == -1) {
|
||||
log_debug(device->ratbag, "No mapping for button %d\n", button->index);
|
||||
continue;
|
||||
}
|
||||
|
||||
asus_binding = &binding_data.data.binding[asus_index];
|
||||
|
||||
/* disabled */
|
||||
if (asus_binding->action == ASUS_BUTTON_CODE_DISABLED) {
|
||||
button->action.type = RATBAG_BUTTON_ACTION_TYPE_NONE;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* got action */
|
||||
switch (asus_binding->type) {
|
||||
case ASUS_BUTTON_ACTION_TYPE_KEY:
|
||||
button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
|
||||
/* ASUS code to Linux code */
|
||||
button->action.action.key.key = asus_get_linux_key_code(asus_binding->action);
|
||||
break;
|
||||
|
||||
case ASUS_BUTTON_ACTION_TYPE_BUTTON:
|
||||
asus_button = asus_find_button_by_code(asus_binding->action);
|
||||
if (asus_button != NULL) { /* found button to bind to */
|
||||
button->action.type = asus_button->type;
|
||||
if (asus_button->type == RATBAG_BUTTON_ACTION_TYPE_BUTTON)
|
||||
button->action.action.button = asus_button->button;
|
||||
else if (asus_button->type == RATBAG_BUTTON_ACTION_TYPE_SPECIAL)
|
||||
button->action.action.special = asus_button->special;
|
||||
} else {
|
||||
log_debug(device->ratbag, "Unknown action code %02x\n", asus_binding->action);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get DPIs */
|
||||
|
||||
log_debug(device->ratbag, "Loading resolutions data\n");
|
||||
rc = asus_get_resolution_data(device, &resolution_data);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
switch (dpi_count) {
|
||||
case 2: /* 2 DPI presets */
|
||||
ratbag_profile_set_report_rate(profile, resolution_data.data2.rate);
|
||||
ratbag_profile_for_each_resolution(profile, resolution)
|
||||
ratbag_resolution_set_resolution(
|
||||
resolution,
|
||||
resolution_data.data2.dpi[resolution->index],
|
||||
resolution_data.data2.dpi[resolution->index]);
|
||||
break;
|
||||
|
||||
case 4: /* 4 DPI presets */
|
||||
ratbag_profile_set_report_rate(profile, resolution_data.data4.rate);
|
||||
ratbag_profile_for_each_resolution(profile, resolution)
|
||||
ratbag_resolution_set_resolution(
|
||||
resolution,
|
||||
resolution_data.data4.dpi[resolution->index],
|
||||
resolution_data.data4.dpi[resolution->index]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* get LEDs */
|
||||
|
||||
log_debug(device->ratbag, "Loading LEDs data\n");
|
||||
rc = asus_get_led_data(device, &led_data);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
ratbag_profile_for_each_led(profile, led) {
|
||||
asus_led = &led_data.data.led[led->index];
|
||||
led->mode = ASUS_LED_MODE[asus_led->mode];
|
||||
/* convert brightness from 0-4 to 0-256 */
|
||||
led->brightness = asus_led->brightness * 64;
|
||||
led->color.red = asus_led->r;
|
||||
led->color.green = asus_led->g;
|
||||
led->color.blue = asus_led->b;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
asus_driver_save_profile(struct ratbag_device *device, struct ratbag_profile *profile)
|
||||
{
|
||||
int rc = 0;
|
||||
const int8_t *bmi = ratbag_device_data_asus_get_button_mapping(device->data);
|
||||
struct asus_button *asus_button;
|
||||
struct ratbag_button *button;
|
||||
struct ratbag_led *led;
|
||||
struct ratbag_resolution *resolution;
|
||||
|
||||
/* set buttons */
|
||||
ratbag_profile_for_each_button(profile, button) {
|
||||
if (!button->dirty)
|
||||
continue;
|
||||
|
||||
int asus_index = bmi[button->index] != -1 ? bmi[button->index] : ASUS_BUTTON_MAPPING_INDEX[button->index];
|
||||
int asus_code;
|
||||
if (asus_index == -1) {
|
||||
log_debug(device->ratbag, "No mapping for button %d\n", button->index);
|
||||
continue;
|
||||
}
|
||||
|
||||
log_debug(device->ratbag, "Button %d (%d) changed\n", button->index, asus_index);
|
||||
|
||||
switch (button->action.type) {
|
||||
case RATBAG_BUTTON_ACTION_TYPE_NONE:
|
||||
rc = asus_set_button_action(
|
||||
device, asus_index,
|
||||
ASUS_BUTTON_CODE_DISABLED,
|
||||
ASUS_BUTTON_ACTION_TYPE_BUTTON);
|
||||
break;
|
||||
|
||||
case RATBAG_BUTTON_ACTION_TYPE_KEY:
|
||||
/* Linux code to ASUS code */
|
||||
asus_code = asus_find_key_code(button->action.action.key.key);
|
||||
if (asus_code >= 0)
|
||||
rc = asus_set_button_action(
|
||||
device, asus_index,
|
||||
asus_code,
|
||||
ASUS_BUTTON_ACTION_TYPE_KEY);
|
||||
break;
|
||||
|
||||
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
|
||||
case RATBAG_BUTTON_ACTION_TYPE_SPECIAL:
|
||||
asus_button = asus_find_button_by_action(button->action);
|
||||
if (asus_button != NULL) /* found button to bind to */
|
||||
rc = asus_set_button_action(
|
||||
device, asus_index,
|
||||
asus_button->asus_code,
|
||||
ASUS_BUTTON_ACTION_TYPE_BUTTON);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* set extra settings */
|
||||
if (profile->rate_dirty) {
|
||||
log_debug(device->ratbag, "Polling rate changed to %d Hz\n", profile->hz);
|
||||
rc = asus_set_polling_rate(device, profile->hz);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* set DPIs */
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
if (!resolution->dirty)
|
||||
continue;
|
||||
|
||||
log_debug(
|
||||
device->ratbag, "Resolution %d changed to %d\n",
|
||||
resolution->index, resolution->dpi_x);
|
||||
|
||||
rc = asus_set_dpi(device, resolution->index, resolution->dpi_x);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* set LEDs */
|
||||
ratbag_profile_for_each_led(profile, led) {
|
||||
if (!led->dirty)
|
||||
continue;
|
||||
|
||||
log_debug(device->ratbag, "LED %d changed\n", led->index);
|
||||
uint8_t led_mode = 0;
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH(ASUS_LED_MODE); i++) {
|
||||
if (ASUS_LED_MODE[i] == led->mode) {
|
||||
led_mode = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* convert brightness from 0-256 to 0-4 */
|
||||
uint8_t led_brightness = (uint8_t)round((double)led->brightness / 64.0);
|
||||
rc = asus_set_led(device, led->index, led_mode, led_brightness, led->color);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
asus_driver_load_profiles(struct ratbag_device *device)
|
||||
{
|
||||
int rc;
|
||||
struct asus_profile_data profile_data;
|
||||
struct ratbag_profile *profile;
|
||||
unsigned int current_profile_id;
|
||||
|
||||
/* get current profile id */
|
||||
rc = asus_get_profile_data(device, &profile_data);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
current_profile_id = profile_data.profile_id;
|
||||
log_debug(device->ratbag, "Initial profile is %d\n", current_profile_id);
|
||||
log_debug(
|
||||
device->ratbag, "Primary version %02X.%02X.%02X\n",
|
||||
profile_data.version_primary_major,
|
||||
profile_data.version_primary_minor,
|
||||
profile_data.version_primary_build);
|
||||
log_debug(
|
||||
device->ratbag, "Secondary version %02X.%02X.%02X\n",
|
||||
profile_data.version_secondary_major,
|
||||
profile_data.version_secondary_minor,
|
||||
profile_data.version_secondary_build);
|
||||
|
||||
/* read ratbag profiles */
|
||||
ratbag_device_for_each_profile(device, profile) {
|
||||
if (profile->index == current_profile_id) { /* profile is already selected */
|
||||
profile->is_active = true;
|
||||
} else { /* switch profile */
|
||||
profile->is_active = false;
|
||||
|
||||
log_debug(device->ratbag, "Switching to profile %d\n", profile->index);
|
||||
rc = asus_set_profile(device, profile->index);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = asus_driver_load_profile(device, profile);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* back to initial profile */
|
||||
if (device->num_profiles > 1) {
|
||||
log_debug(device->ratbag, "Switching back to initial profile %d\n", current_profile_id);
|
||||
rc = asus_set_profile(device, current_profile_id);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
asus_driver_save_profiles(struct ratbag_device *device)
|
||||
{
|
||||
int rc;
|
||||
struct asus_profile_data profile_data;
|
||||
struct ratbag_profile *profile;
|
||||
unsigned int current_profile_id;
|
||||
|
||||
/* get current profile id */
|
||||
rc = asus_get_profile_data(device, &profile_data);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
current_profile_id = profile_data.profile_id;
|
||||
log_debug(device->ratbag, "Initial profile is %d\n", current_profile_id);
|
||||
|
||||
ratbag_device_for_each_profile(device, profile) {
|
||||
if (!profile->dirty)
|
||||
continue;
|
||||
|
||||
log_debug(device->ratbag, "Profile %d changed\n", profile->index);
|
||||
|
||||
/* switch profile */
|
||||
if (profile->index != current_profile_id) {
|
||||
log_debug(device->ratbag, "Switching to profile %d\n", profile->index);
|
||||
rc = asus_set_profile(device, profile->index);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = asus_driver_save_profile(device, profile);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
/* save profile */
|
||||
log_debug(device->ratbag, "Saving profile\n");
|
||||
rc = asus_save_profile(device);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* back to initial profile */
|
||||
if (device->num_profiles > 1) {
|
||||
log_debug(device->ratbag, "Switching back to initial profile %d\n", current_profile_id);
|
||||
rc = asus_set_profile(device, current_profile_id);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
asus_driver_probe(struct ratbag_device *device)
|
||||
{
|
||||
int rc;
|
||||
unsigned int profile_count, dpi_count, button_count, led_count;
|
||||
struct asus_data *drv_data;
|
||||
struct ratbag_profile *profile;
|
||||
struct ratbag_button *button;
|
||||
struct ratbag_resolution *resolution;
|
||||
struct ratbag_led *led;
|
||||
|
||||
rc = ratbag_open_hidraw(device);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
/* create device state data */
|
||||
drv_data = zalloc(sizeof(*drv_data));
|
||||
ratbag_set_drv_data(device, drv_data);
|
||||
drv_data->is_ready = 1;
|
||||
|
||||
/* get device properties from configuration file */
|
||||
profile_count = ratbag_device_data_asus_get_profile_count(device->data);
|
||||
dpi_count = ratbag_device_data_asus_get_dpi_count(device->data);
|
||||
button_count = ratbag_device_data_asus_get_button_count(device->data);
|
||||
led_count = ratbag_device_data_asus_get_led_count(device->data);
|
||||
|
||||
/* init profiles */
|
||||
ratbag_device_init_profiles(
|
||||
device,
|
||||
max(profile_count, 1),
|
||||
max(dpi_count, 2),
|
||||
max(button_count, 8),
|
||||
max(led_count, 0));
|
||||
|
||||
/* setup profiles */
|
||||
ratbag_device_for_each_profile(device, profile) {
|
||||
if (profile->index == 0) {
|
||||
profile->is_active = true;
|
||||
}
|
||||
|
||||
asus_setup_profile(device, profile);
|
||||
|
||||
ratbag_profile_for_each_button(profile, button)
|
||||
asus_setup_button(device, button);
|
||||
|
||||
ratbag_profile_for_each_resolution(profile, resolution)
|
||||
asus_setup_resolution(device, resolution);
|
||||
|
||||
ratbag_profile_for_each_led(profile, led)
|
||||
asus_setup_led(device, led);
|
||||
}
|
||||
|
||||
/* load profiles */
|
||||
rc = asus_driver_load_profiles(device);
|
||||
if (rc == ASUS_STATUS_ERROR) { /* mouse in invalid state */
|
||||
drv_data->is_ready = 0;
|
||||
} else if (rc) { /* other errors */
|
||||
log_error(
|
||||
device->ratbag, "Can't talk to the mouse: '%s' (%d)\n",
|
||||
strerror(-rc), rc);
|
||||
free(drv_data);
|
||||
ratbag_set_drv_data(device, NULL);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
asus_driver_remove(struct ratbag_device *device)
|
||||
{
|
||||
ratbag_close_hidraw(device);
|
||||
free(ratbag_get_drv_data(device));
|
||||
}
|
||||
|
||||
static int
|
||||
asus_driver_commit(struct ratbag_device *device)
|
||||
{
|
||||
int rc;
|
||||
struct asus_data *drv_data;
|
||||
|
||||
/* check last device state */
|
||||
drv_data = ratbag_get_drv_data(device);
|
||||
if (!drv_data->is_ready) { /* device was not ready */
|
||||
log_error(device->ratbag, "Device was not ready, trying to reload\n");
|
||||
rc = asus_driver_load_profiles(device);
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "Device reloading failed (%d)\n", rc);
|
||||
if (rc != ASUS_STATUS_ERROR)
|
||||
return rc;
|
||||
} else {
|
||||
drv_data->is_ready = 1;
|
||||
log_error(device->ratbag, "Device was successfully reloaded\n");
|
||||
}
|
||||
return RATBAG_ERROR_DEVICE; /* fail in any case because we tried to rollback instead of commit */
|
||||
}
|
||||
|
||||
/* save profiles */
|
||||
rc = asus_driver_save_profiles(device);
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "Commit failed (%d)\n", rc);
|
||||
if (rc != ASUS_STATUS_ERROR)
|
||||
return rc;
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ratbag_driver asus_driver = {
|
||||
.name = "ASUS",
|
||||
.id = "asus",
|
||||
.probe = asus_driver_probe,
|
||||
.remove = asus_driver_remove,
|
||||
.commit = asus_driver_commit,
|
||||
.set_active_profile = asus_set_profile,
|
||||
};
|
||||
@@ -496,9 +496,9 @@ etekcity_read_profile(struct ratbag_profile *profile)
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_write_macro(struct ratbag_button *button,
|
||||
const struct ratbag_button_action *action)
|
||||
etekcity_write_macro(struct ratbag_button *button)
|
||||
{
|
||||
const struct ratbag_button_action *action = &button->action;
|
||||
struct ratbag_device *device;
|
||||
struct etekcity_macro *macro;
|
||||
struct etekcity_data *drv_data;
|
||||
@@ -555,9 +555,9 @@ etekcity_write_macro(struct ratbag_button *button,
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_write_button(struct ratbag_button *button,
|
||||
const struct ratbag_button_action *action)
|
||||
etekcity_write_button(struct ratbag_button *button)
|
||||
{
|
||||
const struct ratbag_button_action *action = &button->action;
|
||||
struct ratbag_profile *profile = button->profile;
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct etekcity_data *drv_data = ratbag_get_drv_data(device);
|
||||
@@ -572,15 +572,7 @@ etekcity_write_button(struct ratbag_button *button,
|
||||
|
||||
*data = rc;
|
||||
|
||||
rc = etekcity_write_profile(button->profile);
|
||||
if (rc) {
|
||||
log_error(device->ratbag,
|
||||
"unable to write the profile to the device: '%s' (%d)\n",
|
||||
strerror(-rc), rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = etekcity_write_macro(button, action);
|
||||
rc = etekcity_write_macro(button);
|
||||
if (rc) {
|
||||
log_error(device->ratbag,
|
||||
"unable to write the macro to the device: '%s' (%d)\n",
|
||||
@@ -592,8 +584,7 @@ etekcity_write_button(struct ratbag_button *button,
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_write_resolution_dpi(struct ratbag_resolution *resolution,
|
||||
int dpi_x, int dpi_y)
|
||||
etekcity_write_resolution(struct ratbag_resolution *resolution)
|
||||
{
|
||||
struct ratbag_profile *profile = resolution->profile;
|
||||
struct ratbag_device *device = profile->device;
|
||||
@@ -602,6 +593,9 @@ etekcity_write_resolution_dpi(struct ratbag_resolution *resolution,
|
||||
uint8_t *buf;
|
||||
int rc;
|
||||
|
||||
const unsigned int dpi_x = resolution->dpi_x;
|
||||
const unsigned int dpi_y = resolution->dpi_y;
|
||||
|
||||
if (dpi_x < 50 || dpi_x > 8200 || dpi_x % 50)
|
||||
return -EINVAL;
|
||||
if (dpi_y < 50 || dpi_y > 8200 || dpi_y % 50)
|
||||
@@ -705,13 +699,49 @@ etekcity_remove(struct ratbag_device *device)
|
||||
free(ratbag_get_drv_data(device));
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_commit(struct ratbag_device *device)
|
||||
{
|
||||
int rc = 0;
|
||||
struct ratbag_button *button = NULL;
|
||||
struct ratbag_profile *profile = NULL;
|
||||
struct ratbag_resolution *resolution = NULL;
|
||||
|
||||
ratbag_device_for_each_profile(device, profile) {
|
||||
if (!profile->dirty)
|
||||
continue;
|
||||
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
if (!resolution->dirty)
|
||||
continue;
|
||||
|
||||
rc = etekcity_write_resolution(resolution);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
ratbag_profile_for_each_button(profile, button) {
|
||||
if (!button->dirty)
|
||||
continue;
|
||||
|
||||
rc = etekcity_write_button(button);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = etekcity_write_profile(profile);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ratbag_driver etekcity_driver = {
|
||||
.name = "EtekCity",
|
||||
.id = "etekcity",
|
||||
.probe = etekcity_probe,
|
||||
.remove = etekcity_remove,
|
||||
.write_profile = etekcity_write_profile,
|
||||
.commit = etekcity_commit,
|
||||
.set_active_profile = etekcity_set_current_profile,
|
||||
.write_button = etekcity_write_button,
|
||||
.write_resolution_dpi = etekcity_write_resolution_dpi,
|
||||
};
|
||||
|
||||
@@ -164,6 +164,7 @@ hidpp10drv_map_button(struct ratbag_device *device,
|
||||
{
|
||||
struct hidpp10_profile profile;
|
||||
int ret;
|
||||
unsigned int modifiers = 0;
|
||||
|
||||
ret = hidpp10_get_profile(hidpp10, button->profile->index, &profile);
|
||||
if (ret)
|
||||
@@ -178,6 +179,7 @@ hidpp10drv_map_button(struct ratbag_device *device,
|
||||
button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
|
||||
button->action.action.key.key = ratbag_hidraw_get_keycode_from_keyboard_usage(device,
|
||||
profile.buttons[button->index].keys.key);
|
||||
modifiers = profile.buttons[button->index].keys.modifier_flags;
|
||||
break;
|
||||
case PROFILE_BUTTON_TYPE_CONSUMER_CONTROL:
|
||||
button->action.type = RATBAG_BUTTON_ACTION_TYPE_KEY;
|
||||
@@ -199,6 +201,14 @@ hidpp10drv_map_button(struct ratbag_device *device,
|
||||
}
|
||||
}
|
||||
|
||||
if (button->action.type == RATBAG_BUTTON_ACTION_TYPE_KEY) {
|
||||
ret = ratbag_button_macro_new_from_keycode(button, button->action.action.key.key, modifiers);
|
||||
if (ret < 0) {
|
||||
log_error(device->ratbag, "hidpp10: error while reading button %d\n", button->index);
|
||||
button->action.type = RATBAG_BUTTON_ACTION_TYPE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_MACRO);
|
||||
}
|
||||
|
||||
@@ -299,6 +309,8 @@ hidpp10drv_write_button(struct hidpp10_profile *profile,
|
||||
struct hidpp10drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
struct hidpp10_device *hidpp10 = drv_data->dev;
|
||||
uint8_t code;
|
||||
unsigned int modifiers, key;
|
||||
int rc;
|
||||
|
||||
if (hidpp10->profile_type == HIDPP10_PROFILE_UNKNOWN)
|
||||
return -ENOTSUP;
|
||||
@@ -330,6 +342,26 @@ hidpp10drv_write_button(struct hidpp10_profile *profile,
|
||||
profile->buttons[button->index].special.special = code;
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_TYPE_MACRO:
|
||||
rc = ratbag_action_keycode_from_macro(action, &key, &modifiers);
|
||||
if (rc < 0) {
|
||||
log_error(device->ratbag, "hidpp10: can't convert macro action to keycode in button %d\n", button->index);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
code = ratbag_hidraw_get_keyboard_usage_from_keycode(device, key);
|
||||
if (code == 0) {
|
||||
code = ratbag_hidraw_get_consumer_usage_from_keycode(device, key);
|
||||
if (code == 0)
|
||||
return -EINVAL;
|
||||
|
||||
profile->buttons[button->index].consumer_control.type = PROFILE_BUTTON_TYPE_CONSUMER_CONTROL;
|
||||
profile->buttons[button->index].consumer_control.consumer_control = code;
|
||||
} else {
|
||||
profile->buttons[button->index].keys.type = PROFILE_BUTTON_TYPE_KEYS;
|
||||
profile->buttons[button->index].keys.key = code;
|
||||
profile->buttons[button->index].keys.modifier_flags = modifiers;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
@@ -416,7 +448,7 @@ hidpp10drv_read_profile(struct ratbag_profile *profile)
|
||||
free(profile->name);
|
||||
profile->name = NULL;
|
||||
}
|
||||
if (p.name && p.name[0] != '\0')
|
||||
if (p.name[0] != '\0')
|
||||
profile->name = strdup_safe((char*)p.name);
|
||||
|
||||
rc = hidpp10_get_current_profile(hidpp10, &idx);
|
||||
@@ -516,7 +548,7 @@ hidpp10_log(void *userdata, enum hidpp_log_priority priority, const char *format
|
||||
{
|
||||
struct ratbag_device *device = userdata;
|
||||
|
||||
log_msg_va(device->ratbag, priority, format, args);
|
||||
log_msg_va(device->ratbag, (enum ratbag_log_priority)priority, format, args);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -541,7 +573,8 @@ hidpp10drv_commit(struct ratbag_device *device)
|
||||
return rc;
|
||||
|
||||
p.enabled = profile->is_enabled;
|
||||
strncpy_safe((char*)p.name, profile->name, 24);
|
||||
if (profile->name != NULL)
|
||||
strncpy_safe((char*)p.name, profile->name, 24);
|
||||
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
p.dpi_modes[resolution->index].xres = resolution->dpi_x;
|
||||
@@ -558,8 +591,10 @@ hidpp10drv_commit(struct ratbag_device *device)
|
||||
continue;
|
||||
|
||||
rc = hidpp10drv_write_button(&p, button, &action);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "hidpp10: failed to update buttons (%d)\n", rc);
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
ratbag_profile_for_each_led(profile, led)
|
||||
@@ -567,8 +602,10 @@ hidpp10drv_commit(struct ratbag_device *device)
|
||||
|
||||
if (dev->profile_type != HIDPP10_PROFILE_UNKNOWN) {
|
||||
rc = hidpp10_set_profile(dev, profile->index, &p);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "hidpp10: failed to set profile (%d)\n", rc);
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update the current resolution in case it changed */
|
||||
@@ -576,8 +613,10 @@ hidpp10drv_commit(struct ratbag_device *device)
|
||||
rc = hidpp10_set_current_resolution(dev,
|
||||
active_resolution->dpi_x,
|
||||
active_resolution->dpi_y);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "hidpp10: failed to set active resolution (%d)\n", rc);
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
|
||||
active_resolution = NULL;
|
||||
}
|
||||
@@ -631,9 +670,9 @@ hidpp10drv_probe(struct ratbag_device *device)
|
||||
* If there is a special need like for G700(s), then add a DeviceIndex
|
||||
* entry to the .device file.
|
||||
*/
|
||||
dev = hidpp10_device_new(&base, device_idx, type, profile_count);
|
||||
rc = hidpp10_device_new(&base, device_idx, type, profile_count, &dev);
|
||||
|
||||
if (!dev) {
|
||||
if (rc) {
|
||||
log_error(device->ratbag,
|
||||
"Failed to get HID++1.0 device for %s\n",
|
||||
device->name);
|
||||
@@ -714,14 +753,14 @@ static void
|
||||
hidpp10drv_remove(struct ratbag_device *device)
|
||||
{
|
||||
struct hidpp10drv_data *drv_data;
|
||||
struct hidpp10_device *dev;
|
||||
|
||||
ratbag_close_hidraw(device);
|
||||
|
||||
drv_data = ratbag_get_drv_data(device);
|
||||
dev = drv_data->dev;
|
||||
if (!drv_data)
|
||||
return;
|
||||
|
||||
hidpp10_device_destroy(dev);
|
||||
hidpp10_device_destroy(drv_data->dev);
|
||||
|
||||
free(drv_data);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ struct hidpp20drv_data {
|
||||
unsigned num_controls;
|
||||
struct hidpp20_control_id *controls;
|
||||
struct hidpp20_profiles *profiles;
|
||||
struct hidpp20_led *leds;
|
||||
union hidpp20_generic_led_zone_info led_infos;
|
||||
|
||||
unsigned int report_rates[4];
|
||||
@@ -334,14 +335,24 @@ static void
|
||||
hidpp20drv_read_led_8070(struct ratbag_led *led, struct hidpp20drv_data* drv_data)
|
||||
{
|
||||
struct hidpp20_profile *profile;
|
||||
struct hidpp20_led *h_led;
|
||||
struct hidpp20_led h_led_val;
|
||||
struct hidpp20_led *h_led = &h_led_val;
|
||||
struct hidpp20_color_led_zone_info* led_info;
|
||||
struct hidpp20_color_led_info info;
|
||||
int rc;
|
||||
|
||||
led_info = &drv_data->led_infos.color_leds_8070[led->index];
|
||||
profile = &drv_data->profiles->profiles[led->profile->index];
|
||||
h_led = &profile->leds[led->index];
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
|
||||
profile = &drv_data->profiles->profiles[led->profile->index];
|
||||
h_led = &profile->leds[led->index];
|
||||
} else {
|
||||
rc = hidpp20_color_led_effects_get_zone_effect(drv_data->dev, led->index, h_led);
|
||||
if (rc) {
|
||||
log_debug(led->profile->device->ratbag,
|
||||
"Failed to read led settings\n");
|
||||
}
|
||||
}
|
||||
|
||||
switch (h_led->mode) {
|
||||
case HIDPP20_LED_ON:
|
||||
@@ -397,10 +408,10 @@ hidpp20drv_read_led_8070(struct ratbag_led *led, struct hidpp20drv_data* drv_dat
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
|
||||
break;
|
||||
default:
|
||||
log_bug_libratbag(led->profile->device->ratbag,
|
||||
"%s: Unknown effect id %d\n",
|
||||
led->profile->device->name,
|
||||
ei.effect_id);
|
||||
log_debug(led->profile->device->ratbag,
|
||||
"%s: Unsupported effect (%d)\n",
|
||||
led->profile->device->name,
|
||||
ei.effect_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -472,10 +483,10 @@ hidpp20drv_read_led_8071(struct ratbag_led *led, struct hidpp20drv_data* drv_dat
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
|
||||
break;
|
||||
default:
|
||||
log_bug_libratbag(led->profile->device->ratbag,
|
||||
"%s: Unknown effect id %d\n",
|
||||
led->profile->device->name,
|
||||
ei.effect_id);
|
||||
log_debug(led->profile->device->ratbag,
|
||||
"%s: Unsupported effect (%d)\n",
|
||||
led->profile->device->name,
|
||||
ei.effect_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -564,7 +575,7 @@ hidpp20drv_update_button_8100(struct ratbag_button *button)
|
||||
code = ratbag_hidraw_get_keyboard_usage_from_keycode(device, key);
|
||||
if (code == 0) {
|
||||
subtype = HIDPP20_BUTTON_HID_TYPE_CONSUMER_CONTROL;
|
||||
code = ratbag_hidraw_get_consumer_usage_from_keycode(device, action->action.key.key);
|
||||
code = ratbag_hidraw_get_consumer_usage_from_keycode(device, key);
|
||||
if (code == 0)
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -691,11 +702,13 @@ hidpp20drv_update_led_8070_8071(struct ratbag_led *led, struct ratbag_profile* p
|
||||
struct hidpp20drv_data *drv_data)
|
||||
{
|
||||
struct hidpp20_profile *h_profile;
|
||||
struct hidpp20_led *h_led;
|
||||
struct hidpp20_led h_led_val;
|
||||
struct hidpp20_led *h_led = &h_led_val;
|
||||
|
||||
h_profile = &drv_data->profiles->profiles[profile->index];
|
||||
|
||||
h_led = &(h_profile->leds[led->index]);
|
||||
if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
|
||||
h_profile = &drv_data->profiles->profiles[profile->index];
|
||||
h_led = &(h_profile->leds[led->index]);
|
||||
}
|
||||
|
||||
if (!h_led)
|
||||
return -EINVAL;
|
||||
@@ -720,6 +733,13 @@ hidpp20drv_update_led_8070_8071(struct ratbag_led *led, struct ratbag_profile* p
|
||||
h_led->period = led->ms;
|
||||
h_led->brightness = led->brightness * 100 / 255;
|
||||
|
||||
if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100)) {
|
||||
if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070)
|
||||
hidpp20_color_led_effects_set_zone_effect(drv_data->dev,
|
||||
led->index,
|
||||
h_led_val);
|
||||
}
|
||||
|
||||
return RATBAG_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -822,9 +842,12 @@ hidpp20drv_read_report_rate_8060(struct ratbag_device *device)
|
||||
{
|
||||
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
struct ratbag *ratbag = device->ratbag;
|
||||
struct ratbag_profile *profile;
|
||||
uint8_t bitflags_ms;
|
||||
int nrates = 0;
|
||||
int rc;
|
||||
uint8_t rate_ms;
|
||||
unsigned rate_hz;
|
||||
|
||||
rc = hidpp20_adjustable_report_rate_get_report_rate_list(drv_data->dev,
|
||||
&bitflags_ms);
|
||||
@@ -843,6 +866,37 @@ hidpp20drv_read_report_rate_8060(struct ratbag_device *device)
|
||||
|
||||
drv_data->num_report_rates = nrates;
|
||||
|
||||
if (!hidpp20_adjustable_report_rate_get_report_rate(drv_data->dev, &rate_ms)) {
|
||||
switch (rate_ms)
|
||||
{
|
||||
case 1:
|
||||
rate_hz = 1000;
|
||||
break;
|
||||
case 2:
|
||||
case 3: /* 3ms = 333.(3)Hz, we round to 500Hz */
|
||||
rate_hz = 500;
|
||||
break;
|
||||
case 4:
|
||||
case 5: /* 5ms = 200Hz, we round to 250Hz */
|
||||
rate_hz = 250;
|
||||
break;
|
||||
case 6: /* 6ms = 166.(6)Hz, we round to 125Hz */
|
||||
case 7: /* 7ms = 142Hz, we round to 125Hz */
|
||||
case 8:
|
||||
rate_hz = 125;
|
||||
break;
|
||||
default:
|
||||
rate_hz = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rate_hz) {
|
||||
log_debug(ratbag, "report rate is %u\n", rate_hz);
|
||||
ratbag_device_for_each_profile(device, profile)
|
||||
profile->hz = rate_hz;
|
||||
}
|
||||
}
|
||||
|
||||
log_debug(ratbag, "device has %d report rates\n", nrates);
|
||||
|
||||
return 0;
|
||||
@@ -903,7 +957,7 @@ hidpp20drv_read_resolution_dpi(struct ratbag_profile *profile)
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_ADJUSTIBLE_REPORT_RATE_8060) {
|
||||
rc = hidpp20drv_read_report_rate_8060(device);
|
||||
if (rc < 0)
|
||||
if (rc < 0 && drv_data->report_rates[0] == 0)
|
||||
return rc;
|
||||
|
||||
ratbag_profile_set_report_rate_list(profile,
|
||||
@@ -943,7 +997,7 @@ hidpp20drv_update_resolution_dpi(struct ratbag_resolution *resolution,
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
struct hidpp20_sensor *sensor;
|
||||
int rc, i;
|
||||
int i;
|
||||
int dpi = dpi_x; /* dpi_x == dpi_y if we don't have the individual resolution cap */
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100)
|
||||
@@ -959,14 +1013,13 @@ hidpp20drv_update_resolution_dpi(struct ratbag_resolution *resolution,
|
||||
sensor = &drv_data->sensors[0];
|
||||
|
||||
/* validate that the sensor accepts the given DPI */
|
||||
rc = -EINVAL;
|
||||
if (dpi < sensor->dpi_min || dpi > sensor->dpi_max)
|
||||
goto out;
|
||||
return -EINVAL;
|
||||
if (sensor->dpi_steps) {
|
||||
for (i = sensor->dpi_min; i < dpi; i += sensor->dpi_steps) {
|
||||
}
|
||||
if (i != dpi)
|
||||
goto out;
|
||||
return -EINVAL;
|
||||
} else {
|
||||
i = 0;
|
||||
while (sensor->dpi_list[i]) {
|
||||
@@ -974,13 +1027,24 @@ hidpp20drv_update_resolution_dpi(struct ratbag_resolution *resolution,
|
||||
break;
|
||||
}
|
||||
if (sensor->dpi_list[i] != dpi)
|
||||
goto out;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = hidpp20_adjustable_dpi_set_sensor_dpi(drv_data->dev, sensor, dpi);
|
||||
return hidpp20_adjustable_dpi_set_sensor_dpi(drv_data->dev, sensor, dpi);
|
||||
}
|
||||
|
||||
out:
|
||||
return rc;
|
||||
static int
|
||||
hidpp20drv_update_report_rate_8060(struct ratbag_profile *profile, int hz)
|
||||
{
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
int rc;
|
||||
|
||||
rc = hidpp20_adjustable_report_rate_set_report_rate(drv_data->dev, 1000/hz);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return RATBAG_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1001,12 +1065,20 @@ hidpp20drv_update_report_rate(struct ratbag_profile *profile, int hz)
|
||||
{
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
int rc;
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100)
|
||||
return hidpp20drv_update_report_rate_8100(profile, hz);
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_ADJUSTIBLE_REPORT_RATE_8060)
|
||||
return -ENOTSUP;
|
||||
if (drv_data->capabilities & HIDPP_CAP_ADJUSTIBLE_REPORT_RATE_8060) {
|
||||
rc = hidpp20drv_update_report_rate_8060(profile, hz);
|
||||
|
||||
/* re-populate the profile with the correct value if we fail */
|
||||
if (rc)
|
||||
hidpp20drv_read_report_rate_8060(profile->device);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
return -ENOTSUP;
|
||||
}
|
||||
@@ -1024,6 +1096,7 @@ hidpp20drv_read_special_key_mouse(struct ratbag_device *device)
|
||||
drv_data->controls = NULL;
|
||||
drv_data->num_controls = 0;
|
||||
rc = hidpp20_special_key_mouse_get_controls(drv_data->dev, &drv_data->controls);
|
||||
log_raw(device->ratbag, "num_control %d\n", rc);
|
||||
if (rc > 0) {
|
||||
drv_data->num_controls = rc;
|
||||
rc = 0;
|
||||
@@ -1136,9 +1209,7 @@ hidpp20drv_read_profile_8100(struct ratbag_profile *profile)
|
||||
|
||||
profile->is_enabled = drv_data->profiles->profiles[profile->index].enabled;
|
||||
|
||||
profile->is_active = false;
|
||||
if ((int)profile->index == hidpp20drv_current_profile(device))
|
||||
profile->is_active = true;
|
||||
profile->is_active = (profile->index == drv_data->profiles->active_profile_index);
|
||||
|
||||
if (profile->is_active)
|
||||
dpi_index = hidpp20_onboard_profiles_get_current_dpi_index(drv_data->dev);
|
||||
@@ -1179,6 +1250,60 @@ hidpp20drv_read_profile_8100(struct ratbag_profile *profile)
|
||||
ratbag_profile_set_report_rate(profile, p->report_rate);
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp20drv_init_leds_8070_8071(struct ratbag_device *device)
|
||||
{
|
||||
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
struct ratbag *ratbag = device->ratbag;
|
||||
|
||||
/* we only support 0x8071 via 0x8100 */
|
||||
if (!(drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) &&
|
||||
drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071) {
|
||||
log_debug(ratbag, "disabling 0x8071 (RGB Effects) feature because the device doesn't have 0x8100 (Onboard Memory Profiles)\n");
|
||||
drv_data->capabilities &= ~HIDPP_CAP_RGB_EFFECTS_8071;
|
||||
}
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070 ||
|
||||
drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071) {
|
||||
/* we read the profile once to get the correct number of
|
||||
* supported leds. */
|
||||
if (hidpp20drv_read_color_leds(device))
|
||||
return 0;
|
||||
|
||||
device->num_leds = drv_data->num_leds;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp20drv_init_profile_8100(struct ratbag_device *device)
|
||||
{
|
||||
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
struct ratbag *ratbag = device->ratbag;
|
||||
int rc;
|
||||
|
||||
log_debug(ratbag, "initializing onboard profiles\n");
|
||||
rc = hidpp20_onboard_profiles_allocate(drv_data->dev, &drv_data->profiles);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
rc = hidpp20_onboard_profiles_initialize(drv_data->dev, drv_data->profiles);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
drv_data->num_profiles = drv_data->profiles->num_profiles;
|
||||
drv_data->num_buttons = drv_data->profiles->num_buttons;
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201)
|
||||
drv_data->num_resolutions = drv_data->profiles->num_modes;
|
||||
/* We ignore the profile's num_leds and require
|
||||
* HIDPP_PAGE_COLOR_LED_EFFECTS to succeed instead
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
hidpp20drv_read_profile(struct ratbag_profile *profile)
|
||||
{
|
||||
@@ -1313,25 +1438,11 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature)
|
||||
|
||||
log_debug(ratbag, "device has color effects\n");
|
||||
drv_data->capabilities |= HIDPP_CAP_COLOR_LED_EFFECTS_8070;
|
||||
|
||||
/* we read the profile once to get the correct number of
|
||||
* supported leds. */
|
||||
if (hidpp20drv_read_color_leds(device))
|
||||
return 0;
|
||||
|
||||
device->num_leds = drv_data->num_leds;
|
||||
break;
|
||||
}
|
||||
case HIDPP_PAGE_RGB_EFFECTS: {
|
||||
log_debug(ratbag, "device has color effects\n");
|
||||
drv_data->capabilities |= HIDPP_CAP_RGB_EFFECTS_8071;
|
||||
|
||||
/* we read the profile once to get the correct number of
|
||||
* supported leds. */
|
||||
if (hidpp20drv_read_color_leds(device))
|
||||
return 0;
|
||||
|
||||
device->num_leds = drv_data->num_leds;
|
||||
break;
|
||||
}
|
||||
case HIDPP_PAGE_LED_SW_CONTROL: {
|
||||
@@ -1349,22 +1460,6 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature)
|
||||
case HIDPP_PAGE_ONBOARD_PROFILES: {
|
||||
log_debug(ratbag, "device has onboard profiles\n");
|
||||
drv_data->capabilities |= HIDPP_CAP_ONBOARD_PROFILES_8100;
|
||||
|
||||
rc = hidpp20_onboard_profiles_allocate(drv_data->dev, &drv_data->profiles);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
rc = hidpp20_onboard_profiles_initialize(drv_data->dev, drv_data->profiles);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
drv_data->num_profiles = drv_data->profiles->num_profiles;
|
||||
drv_data->num_resolutions = drv_data->profiles->num_modes;
|
||||
drv_data->num_buttons = drv_data->profiles->num_buttons;
|
||||
/* We ignore the profile's num_leds and require
|
||||
* HIDPP_PAGE_COLOR_LED_EFFECTS to succeed instead
|
||||
*/
|
||||
|
||||
break;
|
||||
}
|
||||
case HIDPP_PAGE_MOUSE_BUTTON_SPY: {
|
||||
@@ -1386,27 +1481,27 @@ hidpp20drv_commit(struct ratbag_device *device)
|
||||
struct ratbag_led *led;
|
||||
struct ratbag_resolution *resolution;
|
||||
int rc;
|
||||
unsigned int dpi_index = 0;
|
||||
|
||||
list_for_each(profile, &device->profiles, link) {
|
||||
if (!profile->dirty)
|
||||
continue;
|
||||
|
||||
rc = hidpp20drv_update_report_rate(profile, profile->hz);
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
if (profile->rate_dirty) {
|
||||
rc = hidpp20drv_update_report_rate(profile, profile->hz);
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "hidpp20: failed to update report rate (%d)\n", rc);
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
if (resolution->is_active) {
|
||||
log_raw(device->ratbag, "dpi index: %d, profile %d\n", resolution->index, profile->index);
|
||||
dpi_index = resolution->index;
|
||||
}
|
||||
|
||||
rc = hidpp20drv_update_resolution_dpi(resolution,
|
||||
resolution->dpi_x,
|
||||
resolution->dpi_y);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "hidpp20: failed to update resolution (%d)\n", rc);
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
list_for_each(button, &profile->buttons, link) {
|
||||
@@ -1414,8 +1509,10 @@ hidpp20drv_commit(struct ratbag_device *device)
|
||||
continue;
|
||||
|
||||
rc = hidpp20drv_update_button(button);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "hidpp20: failed to update button (%d)\n", rc);
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
list_for_each(led, &profile->leds, link) {
|
||||
@@ -1423,10 +1520,11 @@ hidpp20drv_commit(struct ratbag_device *device)
|
||||
continue;
|
||||
|
||||
rc = hidpp20drv_update_led(led);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "hidpp20: failed to update led (%d)\n", rc);
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
|
||||
@@ -1435,17 +1533,18 @@ hidpp20drv_commit(struct ratbag_device *device)
|
||||
|
||||
rc = hidpp20_onboard_profiles_commit(drv_data->dev,
|
||||
drv_data->profiles);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
log_error(device->ratbag, "hidpp20: failed to commit profile (%d)\n", rc);
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
|
||||
list_for_each(profile, &device->profiles, link) {
|
||||
if (profile->is_active) {
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
if (resolution->is_active)
|
||||
dpi_index = resolution->index;
|
||||
hidpp20_onboard_profiles_set_current_dpi_index(drv_data->dev,
|
||||
resolution->index);
|
||||
}
|
||||
hidpp20_onboard_profiles_set_current_dpi_index(drv_data->dev,
|
||||
dpi_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1476,8 +1575,21 @@ hidpp20drv_20_probe(struct ratbag_device *device)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
/* initializations that depend on other features */
|
||||
if (drv_data->capabilities & HIDPP_CAP_COLOR_LED_EFFECTS_8070 ||
|
||||
drv_data->capabilities & HIDPP_CAP_RGB_EFFECTS_8071) {
|
||||
rc = hidpp20drv_init_leds_8070_8071(device);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
|
||||
rc = hidpp20drv_init_profile_8100(device);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1491,7 +1603,7 @@ hidpp20_log(void *userdata, enum hidpp_log_priority priority, const char *format
|
||||
{
|
||||
struct ratbag_device *device = userdata;
|
||||
|
||||
log_msg_va(device->ratbag, priority, format, args);
|
||||
log_msg_va(device->ratbag, (enum ratbag_log_priority)priority, format, args);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1511,6 +1623,7 @@ hidpp20drv_remove(struct ratbag_device *device)
|
||||
free(drv_data->led_infos.color_leds_8070);
|
||||
free(drv_data->controls);
|
||||
free(drv_data->sensors);
|
||||
free(drv_data->leds);
|
||||
if (drv_data->dev)
|
||||
hidpp20_device_destroy(drv_data->dev);
|
||||
free(drv_data);
|
||||
@@ -1522,6 +1635,19 @@ hidpp20drv_init_device(struct ratbag_device *device,
|
||||
{
|
||||
struct ratbag_profile *profile;
|
||||
bool active_profile = false;
|
||||
int num;
|
||||
|
||||
num = ratbag_device_data_hidpp20_get_led_count(device->data);
|
||||
if (num >= 0)
|
||||
drv_data->num_leds = num;
|
||||
|
||||
num = ratbag_device_data_hidpp20_get_button_count(device->data);
|
||||
if (num >= 0)
|
||||
drv_data->num_buttons = num;
|
||||
|
||||
num = ratbag_device_data_hidpp20_get_report_rate(device->data);
|
||||
if (num >= 0)
|
||||
drv_data->report_rates[0] = num;
|
||||
|
||||
ratbag_device_init_profiles(device,
|
||||
drv_data->num_profiles,
|
||||
@@ -1592,7 +1718,7 @@ hidpp20drv_probe(struct ratbag_device *device)
|
||||
|
||||
/* add some defaults that will be overwritten by the device */
|
||||
drv_data->num_profiles = 1;
|
||||
drv_data->num_resolutions = 1;
|
||||
drv_data->num_resolutions = 0;
|
||||
drv_data->num_buttons = 8;
|
||||
drv_data->num_leds = 0;
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#define LOGITECH_G300_BUTTON_MAX 8
|
||||
#define LOGITECH_G300_NUM_DPI 4
|
||||
#define LOGITECH_G300_NUM_LED 1
|
||||
#define LOGITECH_G300_DPI_MIN 250
|
||||
#define LOGITECH_G300_DPI_MIN 100
|
||||
#define LOGITECH_G300_DPI_MAX 2500
|
||||
|
||||
#define LOGITECH_G300_REPORT_ID_GET_ACTIVE 0xF0
|
||||
@@ -51,7 +51,7 @@
|
||||
#define LOGITECH_G300_REPORT_SIZE_PROFILE 35
|
||||
|
||||
struct logitech_g300_resolution {
|
||||
uint8_t dpi :7; /* Range 1-10. dpi = 250*value */
|
||||
uint8_t dpi :7; /* Range 1-10. dpi = 100*value */
|
||||
uint8_t is_default :1;
|
||||
} __attribute__((packed));
|
||||
|
||||
@@ -449,11 +449,10 @@ logitech_g300_read_profile(struct ratbag_profile *profile)
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
struct logitech_g300_resolution *res =
|
||||
&report->dpi_levels[resolution->index];
|
||||
unsigned int dpis[10] = { 250, 500, 750, 1000, 1250, 1500, 1750,
|
||||
2000, 2250, 2500 };
|
||||
unsigned int dpis[49] = { 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, 1550, 1600, 1650, 1700, 1750, 1800, 1850, 1900, 1950, 2000, 2050, 2100, 2150, 2200, 2250, 2300, 2350, 2400, 2450, 2500, };
|
||||
|
||||
resolution->dpi_x = res->dpi * 250;
|
||||
resolution->dpi_y = res->dpi * 250;
|
||||
resolution->dpi_x = res->dpi * 50;
|
||||
resolution->dpi_y = res->dpi * 50;
|
||||
resolution->is_default = res->is_default;
|
||||
resolution->is_active = res->is_default;
|
||||
|
||||
@@ -546,7 +545,7 @@ logitech_g300_write_profile(struct ratbag_profile *profile)
|
||||
struct logitech_g300_resolution *res =
|
||||
&report->dpi_levels[resolution->index];
|
||||
|
||||
res->dpi = resolution->dpi_x / 250;
|
||||
res->dpi = resolution->dpi_x / 50;
|
||||
res->is_default = resolution->is_default;
|
||||
|
||||
if (profile->is_active && resolution->is_active)
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "libratbag-hidraw.h"
|
||||
|
||||
#define LOGITECH_G600_NUM_PROFILES 3
|
||||
#define LOGITECH_G600_NUM_BUTTONS 20
|
||||
#define LOGITECH_G600_NUM_BUTTONS 41 // 20 buttons + 1 color buffer + 20 G-shift
|
||||
#define LOGITECH_G600_NUM_DPI 4
|
||||
#define LOGITECH_G600_NUM_LED 1
|
||||
#define LOGITECH_G600_DPI_MIN 200
|
||||
@@ -109,20 +109,41 @@ static const struct logitech_g600_button_type_mapping logitech_g600_button_type_
|
||||
{ 3, RATBAG_BUTTON_TYPE_WHEEL_LEFT },
|
||||
{ 4, RATBAG_BUTTON_TYPE_WHEEL_RIGHT },
|
||||
{ 5, RATBAG_BUTTON_TYPE_PINKIE },
|
||||
{ 6, RATBAG_BUTTON_TYPE_PROFILE_CYCLE_UP },
|
||||
{ 7, RATBAG_BUTTON_TYPE_RESOLUTION_CYCLE_UP },
|
||||
{ 8, RATBAG_BUTTON_TYPE_SIDE }, // 8 = G9 ... 19 = G20
|
||||
{ 9, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 10, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 11, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 12, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 13, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 14, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 15, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 16, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 17, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 18, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 19, RATBAG_BUTTON_TYPE_SIDE },
|
||||
{ 6, RATBAG_BUTTON_TYPE_PROFILE_CYCLE_UP }, // G07
|
||||
{ 7, RATBAG_BUTTON_TYPE_RESOLUTION_CYCLE_UP }, // G08
|
||||
{ 8, RATBAG_BUTTON_TYPE_SIDE }, // G09
|
||||
{ 9, RATBAG_BUTTON_TYPE_SIDE }, // G10
|
||||
{ 10, RATBAG_BUTTON_TYPE_SIDE }, // G11
|
||||
{ 11, RATBAG_BUTTON_TYPE_SIDE }, // G12
|
||||
{ 12, RATBAG_BUTTON_TYPE_SIDE }, // G13
|
||||
{ 13, RATBAG_BUTTON_TYPE_SIDE }, // G14
|
||||
{ 14, RATBAG_BUTTON_TYPE_SIDE }, // G15
|
||||
{ 15, RATBAG_BUTTON_TYPE_SIDE }, // G16
|
||||
{ 16, RATBAG_BUTTON_TYPE_SIDE }, // G17
|
||||
{ 17, RATBAG_BUTTON_TYPE_SIDE }, // G18
|
||||
{ 18, RATBAG_BUTTON_TYPE_SIDE }, // G19
|
||||
{ 19, RATBAG_BUTTON_TYPE_SIDE }, // G20
|
||||
{ 20, RATBAG_BUTTON_TYPE_UNKNOWN }, //HACK is where the G-shift color information is located
|
||||
{ 21, RATBAG_BUTTON_TYPE_LEFT }, // G-shift + left
|
||||
{ 22, RATBAG_BUTTON_TYPE_RIGHT }, // G-shift + right click
|
||||
{ 23, RATBAG_BUTTON_TYPE_MIDDLE }, // G-shift + middle
|
||||
{ 24, RATBAG_BUTTON_TYPE_WHEEL_LEFT}, // G-shift + scroll left
|
||||
{ 25, RATBAG_BUTTON_TYPE_WHEEL_RIGHT}, // G-shift + scroll right
|
||||
{ 26, RATBAG_BUTTON_TYPE_PINKIE }, // G-shift + Pinky(shift modifer)
|
||||
{ 27, RATBAG_BUTTON_TYPE_PROFILE_CYCLE_UP }, // G-shift + 07
|
||||
{ 28, RATBAG_BUTTON_TYPE_RESOLUTION_CYCLE_UP }, // G-shift + G08
|
||||
{ 29, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G09
|
||||
{ 30, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G10
|
||||
{ 31, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G11
|
||||
{ 32, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G12
|
||||
{ 33, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G13
|
||||
{ 34, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G14
|
||||
{ 35, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G15
|
||||
{ 36, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G16
|
||||
{ 37, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G17
|
||||
{ 38, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G18
|
||||
{ 39, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G19
|
||||
{ 40, RATBAG_BUTTON_TYPE_SIDE }, // G-shift + G20
|
||||
};
|
||||
|
||||
static enum ratbag_button_type
|
||||
@@ -144,7 +165,7 @@ struct logitech_g600_button_mapping {
|
||||
};
|
||||
|
||||
static struct logitech_g600_button_mapping logitech_g600_button_mapping[] = {
|
||||
/* 0x00 is either key or unassigned. Must be handled separatly */
|
||||
/* 0x00 is either key or unassigned. Must be handled separately */
|
||||
{ 0x01, BUTTON_ACTION_BUTTON(1) },
|
||||
{ 0x02, BUTTON_ACTION_BUTTON(2) },
|
||||
{ 0x03, BUTTON_ACTION_BUTTON(3) },
|
||||
@@ -600,6 +621,12 @@ logitech_g600_write_profile(struct ratbag_profile *profile)
|
||||
report->led_duration = 0x0f;
|
||||
}
|
||||
|
||||
// For now the default will copy over the main color into the g-shift color
|
||||
// future update may add support to set this via cli command
|
||||
report->g_shift_color[0] = report->led_red;
|
||||
report->g_shift_color[1] = report->led_green;
|
||||
report->g_shift_color[2] = report->led_blue;
|
||||
|
||||
buf = (uint8_t*)report;
|
||||
|
||||
rc = ratbag_hidraw_raw_request(device, report->id,
|
||||
|
||||
498
src/driver-openinput.c
Normal file
498
src/driver-openinput.c
Normal file
@@ -0,0 +1,498 @@
|
||||
/*
|
||||
* Copyright © 2021 Filipe Laíns
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "libratbag-private.h"
|
||||
|
||||
|
||||
/* reports */
|
||||
#define OI_REPORT_SHORT 0x20
|
||||
#define OI_REPORT_LONG 0x21
|
||||
#define OI_REPORT_SHORT_SIZE 8
|
||||
#define OI_REPORT_LONG_SIZE 32
|
||||
|
||||
#define OI_REPORT_MAX_SIZE OI_REPORT_LONG_SIZE
|
||||
#define OI_REPORT_DATA_INDEX 3
|
||||
#define OI_REPORT_DATA_MAX_SIZE OI_REPORT_LONG_SIZE - OI_REPORT_DATA_INDEX
|
||||
|
||||
/* protocol function pages */
|
||||
#define OI_PAGE_INFO 0x00
|
||||
#define OI_PAGE_GIMMICKS 0xFD
|
||||
#define OI_PAGE_DEBUG 0xFE
|
||||
#define OI_PAGE_ERROR 0xFF
|
||||
|
||||
/* info page (0x00) functions */
|
||||
#define OI_FUNCTION_VERSION 0x00
|
||||
#define OI_FUNCTION_FW_INFO 0x01
|
||||
#define OI_FUNCTION_SUPPORTED_FUNCTION_PAGES 0x02
|
||||
#define OI_FUNCTION_SUPPORTED_FUNCTIONS 0x03
|
||||
|
||||
/* error page (0xFF) */
|
||||
#define OI_ERROR_INVALID_VALUE 0x01
|
||||
#define OI_ERROR_UNSUPPORTED_FUNCTION 0x02
|
||||
#define OI_ERROR_CUSTOM 0xFE
|
||||
|
||||
|
||||
static unsigned int report_rates[] = { 125, 250, 500, 750, 1000 };
|
||||
|
||||
struct openinput_drv_data {
|
||||
unsigned int num_profiles;
|
||||
unsigned int num_resolutions;
|
||||
unsigned int num_buttons;
|
||||
unsigned int num_leds;
|
||||
unsigned int fw_major;
|
||||
unsigned int fw_minor;
|
||||
unsigned int fw_patch;
|
||||
uint64_t supported;
|
||||
};
|
||||
|
||||
struct oi_report_t {
|
||||
uint8_t id;
|
||||
uint8_t function_page;
|
||||
uint8_t function;
|
||||
uint8_t data[29];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
|
||||
#define CASE_RETURN_STRING(a) case a: return #a; break
|
||||
static const char*
|
||||
openinput_function_page_get_name(uint8_t page)
|
||||
{
|
||||
static char numeric[16];
|
||||
char *str;
|
||||
|
||||
switch(page) {
|
||||
CASE_RETURN_STRING(OI_PAGE_INFO);
|
||||
CASE_RETURN_STRING(OI_PAGE_GIMMICKS);
|
||||
CASE_RETURN_STRING(OI_PAGE_DEBUG);
|
||||
CASE_RETURN_STRING(OI_PAGE_ERROR);
|
||||
default:
|
||||
sprintf_safe(numeric, "0x%02x", page);
|
||||
str = numeric;
|
||||
break;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static const char*
|
||||
openinput_function_get_name(uint8_t page, uint8_t function)
|
||||
{
|
||||
static char numeric[32];
|
||||
char *str = NULL;
|
||||
|
||||
switch(page) {
|
||||
case OI_PAGE_INFO:
|
||||
switch (function) {
|
||||
CASE_RETURN_STRING(OI_FUNCTION_VERSION);
|
||||
CASE_RETURN_STRING(OI_FUNCTION_FW_INFO);
|
||||
CASE_RETURN_STRING(OI_FUNCTION_SUPPORTED_FUNCTION_PAGES);
|
||||
CASE_RETURN_STRING(OI_FUNCTION_SUPPORTED_FUNCTIONS);
|
||||
}
|
||||
}
|
||||
|
||||
if (!str) {
|
||||
sprintf_safe(numeric, "0x%02x 0x%02x", page, function);
|
||||
str = numeric;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
#undef CASE_RETURN_STRING
|
||||
|
||||
static const char*
|
||||
openinput_get_error_string(struct oi_report_t *report)
|
||||
{
|
||||
char help_str[OI_REPORT_LONG_SIZE - OI_REPORT_DATA_INDEX + 1] = {0};
|
||||
char *str;
|
||||
|
||||
switch (report->function) {
|
||||
case OI_ERROR_INVALID_VALUE:
|
||||
xasprintf(&str, "Invalid value (in position %u)", report->data[2]);
|
||||
break;
|
||||
case OI_ERROR_CUSTOM:
|
||||
memcpy(help_str, report->data, sizeof(help_str)-1); /* copy error string */
|
||||
xasprintf(&str, "Custom error (%s)", help_str);
|
||||
break;
|
||||
case OI_ERROR_UNSUPPORTED_FUNCTION:
|
||||
xasprintf(&str, "Unsupported function (0x%02x, 0x%02x)", report->data[0], report->data[1]);
|
||||
break;
|
||||
default:
|
||||
xasprintf(&str, "Unknown error (%u)", report->function);
|
||||
break;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static size_t
|
||||
openinput_get_report_size(unsigned int report)
|
||||
{
|
||||
switch (report) {
|
||||
case OI_REPORT_SHORT:
|
||||
return OI_REPORT_SHORT_SIZE;
|
||||
case OI_REPORT_LONG:
|
||||
return OI_REPORT_LONG_SIZE;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
openinput_report_filter(uint8_t *buf, size_t len)
|
||||
{
|
||||
if (len < 1)
|
||||
return false;
|
||||
|
||||
switch(buf[0]) {
|
||||
case OI_REPORT_SHORT:
|
||||
return len == OI_REPORT_SHORT_SIZE;
|
||||
case OI_REPORT_LONG:
|
||||
return len == OI_REPORT_LONG_SIZE;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
openinput_send_report(struct ratbag_device *device, struct oi_report_t *report)
|
||||
{
|
||||
int ret;
|
||||
uint8_t buffer[OI_REPORT_MAX_SIZE];
|
||||
size_t size = openinput_get_report_size(report->id);
|
||||
|
||||
memcpy(buffer, report, size);
|
||||
|
||||
ret = ratbag_hidraw_output_report(device, buffer, size);
|
||||
if (ret < 0) {
|
||||
log_error(device->ratbag, "openinput: failed to send data to device (%s)\n",
|
||||
strerror(-ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ratbag_hidraw_read_input_report(device, buffer, OI_REPORT_MAX_SIZE, openinput_report_filter);
|
||||
if (ret < 0) {
|
||||
log_error(device->ratbag, "openinput: failed to read data from device (%s)\n",
|
||||
strerror(-ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(report, buffer, openinput_get_report_size(buffer[0]));
|
||||
|
||||
/* check for error */
|
||||
if (report->function_page == OI_PAGE_ERROR) {
|
||||
log_error(device->ratbag, "openinput: %s\n", openinput_get_error_string(report));
|
||||
return report->function;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
openinput_info_version(struct ratbag_device *device)
|
||||
{
|
||||
int ret;
|
||||
struct openinput_drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
struct oi_report_t report = {
|
||||
.id = OI_REPORT_SHORT,
|
||||
.function_page = OI_PAGE_INFO,
|
||||
.function = OI_FUNCTION_VERSION
|
||||
};
|
||||
|
||||
ret = openinput_send_report(device, &report);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
drv_data->fw_major = report.data[0];
|
||||
drv_data->fw_minor = report.data[1];
|
||||
drv_data->fw_patch = report.data[2];
|
||||
|
||||
log_info(device->ratbag, "openinput: protocol version %u.%u.%u\n",
|
||||
drv_data->fw_major, drv_data->fw_minor, drv_data->fw_patch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define OI_FUNCTION_FW_INFO_VENDOR 0x00
|
||||
#define OI_FUNCTION_FW_INFO_VERSION 0x01
|
||||
#define OI_FUNCTION_FW_INFO_DEVICE_NAME 0x02
|
||||
|
||||
static int
|
||||
openinput_info_fw_info(struct ratbag_device *device,
|
||||
uint8_t field_id,
|
||||
unsigned char *description,
|
||||
size_t description_size)
|
||||
{
|
||||
int ret;
|
||||
struct oi_report_t report = {
|
||||
.id = OI_REPORT_SHORT,
|
||||
.function_page = OI_PAGE_INFO,
|
||||
.function = OI_FUNCTION_FW_INFO,
|
||||
.data = {field_id}
|
||||
};
|
||||
|
||||
ret = openinput_send_report(device, &report);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
memcpy(description, report.data, min(sizeof(report.data), description_size));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
openinput_info_supported_function_pages(struct ratbag_device *device,
|
||||
uint8_t start_index,
|
||||
uint8_t *pages_count,
|
||||
uint8_t *pages_left,
|
||||
uint8_t *pages,
|
||||
size_t pages_size)
|
||||
{
|
||||
int ret;
|
||||
struct oi_report_t report = {
|
||||
.id = OI_REPORT_SHORT,
|
||||
.function_page = OI_PAGE_INFO,
|
||||
.function = OI_FUNCTION_SUPPORTED_FUNCTION_PAGES,
|
||||
.data = {start_index}
|
||||
};
|
||||
|
||||
ret = openinput_send_report(device, &report);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
*pages_count = report.data[0];
|
||||
*pages_left = report.data[1];
|
||||
memcpy(pages, report.data + 2, min(sizeof(report.data), pages_size));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
openinput_info_supported_functions(struct ratbag_device *device,
|
||||
uint8_t function_page,
|
||||
uint8_t start_index,
|
||||
uint8_t *functions_count,
|
||||
uint8_t *functions_left,
|
||||
uint8_t *functions,
|
||||
size_t functions_size)
|
||||
{
|
||||
int ret;
|
||||
struct oi_report_t report = {
|
||||
.id = OI_REPORT_SHORT,
|
||||
.function_page = OI_PAGE_INFO,
|
||||
.function = OI_FUNCTION_SUPPORTED_FUNCTIONS,
|
||||
.data = {function_page, start_index}
|
||||
};
|
||||
|
||||
ret = openinput_send_report(device, &report);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
*functions_count = report.data[0];
|
||||
*functions_left = report.data[1];
|
||||
memcpy(functions, report.data + 2, min(sizeof(report.data), functions_size));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
openinput_read_supported_functions(struct ratbag_device *device, uint8_t page)
|
||||
{
|
||||
struct ratbag *ratbag = device->ratbag;
|
||||
int ret;
|
||||
uint8_t i, total, read = 0, count = 0, left = 0;
|
||||
uint8_t buffer[OI_REPORT_DATA_MAX_SIZE];
|
||||
|
||||
ret = openinput_info_supported_functions(device,
|
||||
page,
|
||||
read,
|
||||
&count, &left,
|
||||
buffer, sizeof(buffer));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
total = count + left;
|
||||
uint8_t functions[total];
|
||||
|
||||
memcpy(functions, buffer, count);
|
||||
|
||||
/* there are still functions left to read! */
|
||||
while (left) {
|
||||
ret = openinput_info_supported_functions(device,
|
||||
page,
|
||||
read,
|
||||
&count, &left,
|
||||
buffer, sizeof(buffer));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* make sure the new size values make sense, to avoid deadlocks */
|
||||
if (total != (read + count + left)) {
|
||||
log_error(ratbag, "openinput: invalid number of functions left to read (%u)\n", left);
|
||||
return -EINVAL;
|
||||
}
|
||||
log_debug(ratbag, "openinput: read %u functions, %u left\n", count, left);
|
||||
|
||||
memcpy(functions + read, buffer, count);
|
||||
read += count;
|
||||
}
|
||||
|
||||
/* iterate over read functions */
|
||||
for (i = 0; i < total; i++) {
|
||||
log_debug(ratbag, "openinput: found function %s\n", openinput_function_get_name(page, functions[i]));
|
||||
/* TODO: set bits in drv_data->supported when we implement support for certain capabilities */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
openinput_read_supported_function_pages(struct ratbag_device *device)
|
||||
{
|
||||
struct ratbag *ratbag = device->ratbag;
|
||||
int ret;
|
||||
uint8_t i, total, read = 0, count = 0, left = 0;
|
||||
uint8_t buffer[OI_REPORT_DATA_MAX_SIZE];
|
||||
|
||||
log_debug(ratbag, "openinput: starting reading device functions...\n");
|
||||
|
||||
ret = openinput_info_supported_function_pages(device,
|
||||
read,
|
||||
&count, &left,
|
||||
buffer, sizeof(buffer));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
total = count + left;
|
||||
uint8_t pages[total];
|
||||
|
||||
memcpy(pages, buffer, count);
|
||||
|
||||
/* there are still function pages left to read! */
|
||||
while (left) {
|
||||
ret = openinput_info_supported_function_pages(device,
|
||||
read,
|
||||
&count, &left,
|
||||
buffer, sizeof(buffer));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* make sure the new size values make sense, to avoid deadlocks */
|
||||
if (total != (read + count + left)) {
|
||||
log_error(ratbag, "openinput: invalid number of function pages left to read (%u)\n", left);
|
||||
return -EINVAL;
|
||||
}
|
||||
log_debug(ratbag, "openinput: read %u pages, %u left\n", count, left);
|
||||
|
||||
memcpy(pages + read, buffer, count);
|
||||
read += count;
|
||||
}
|
||||
|
||||
/* iterate over read function pages, and read their functions */
|
||||
for (i = 0; i < total; i++) {
|
||||
log_debug(ratbag, "openinput: found function page %s\n", openinput_function_page_get_name(pages[i]));
|
||||
openinput_read_supported_functions(device, pages[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
openinput_read_profile(struct ratbag_profile *profile)
|
||||
{
|
||||
ratbag_profile_set_report_rate_list(profile, report_rates, sizeof(*report_rates));
|
||||
profile->is_active = true;
|
||||
}
|
||||
|
||||
static int
|
||||
openinput_test_hidraw(struct ratbag_device *device)
|
||||
{
|
||||
return ratbag_hidraw_has_report(device, OI_REPORT_SHORT);
|
||||
}
|
||||
|
||||
static int
|
||||
openinput_probe(struct ratbag_device *device)
|
||||
{
|
||||
int ret;
|
||||
struct openinput_drv_data *drv_data;
|
||||
struct ratbag_profile *profile;
|
||||
unsigned char str[OI_REPORT_DATA_MAX_SIZE];
|
||||
|
||||
ret = ratbag_find_hidraw(device, openinput_test_hidraw);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
drv_data = zalloc(sizeof(*drv_data));
|
||||
|
||||
drv_data->num_profiles = 1;
|
||||
|
||||
ratbag_set_drv_data(device, drv_data);
|
||||
|
||||
openinput_info_version(device);
|
||||
|
||||
ret = openinput_info_fw_info(device, OI_FUNCTION_FW_INFO_VENDOR, str, sizeof(str));
|
||||
if (ret)
|
||||
return ret;
|
||||
log_info(device->ratbag, "openinput: firmware vendor: %s\n", str);
|
||||
|
||||
ret = openinput_info_fw_info(device, OI_FUNCTION_FW_INFO_VERSION, str, sizeof(str));
|
||||
if (ret)
|
||||
return ret;
|
||||
log_info(device->ratbag, "openinput: firmware version: %s\n", str);
|
||||
|
||||
ret = openinput_info_fw_info(device, OI_FUNCTION_FW_INFO_DEVICE_NAME, str, sizeof(str));
|
||||
if (ret)
|
||||
return ret;
|
||||
log_info(device->ratbag, "openinput: device: %s\n", str);
|
||||
|
||||
ret = openinput_read_supported_function_pages(device);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ratbag_device_init_profiles(device,
|
||||
drv_data->num_profiles,
|
||||
drv_data->num_resolutions,
|
||||
drv_data->num_buttons,
|
||||
drv_data->num_leds);
|
||||
|
||||
ratbag_device_for_each_profile(device, profile)
|
||||
openinput_read_profile(profile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
openinput_remove(struct ratbag_device *device)
|
||||
{
|
||||
ratbag_close_hidraw(device);
|
||||
free(ratbag_get_drv_data(device));
|
||||
}
|
||||
|
||||
struct ratbag_driver openinput_driver = {
|
||||
.name = "openinput",
|
||||
.id = "openinput",
|
||||
.probe = openinput_probe,
|
||||
.remove = openinput_remove,
|
||||
};
|
||||
1131
src/driver-roccat-kone-emp.c
Normal file
1131
src/driver-roccat-kone-emp.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -603,9 +603,9 @@ roccat_write_macro(struct ratbag_button *button,
|
||||
}
|
||||
|
||||
static int
|
||||
roccat_write_button(struct ratbag_button *button,
|
||||
const struct ratbag_button_action *action)
|
||||
roccat_write_button(struct ratbag_button *button)
|
||||
{
|
||||
const struct ratbag_button_action *action = &button->action;
|
||||
struct ratbag_profile *profile = button->profile;
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct roccat_data *drv_data = ratbag_get_drv_data(device);
|
||||
@@ -639,8 +639,7 @@ roccat_write_button(struct ratbag_button *button,
|
||||
}
|
||||
|
||||
static int
|
||||
roccat_write_resolution_dpi(struct ratbag_resolution *resolution,
|
||||
int dpi_x, int dpi_y)
|
||||
roccat_write_resolution(struct ratbag_resolution *resolution)
|
||||
{
|
||||
struct ratbag_profile *profile = resolution->profile;
|
||||
struct ratbag_device *device = profile->device;
|
||||
@@ -649,7 +648,10 @@ roccat_write_resolution_dpi(struct ratbag_resolution *resolution,
|
||||
uint8_t *buf;
|
||||
int rc;
|
||||
|
||||
if (dpi_x < 100 || dpi_x > 5000 || dpi_x % 50)
|
||||
const unsigned int dpi_x = resolution->dpi_x;
|
||||
const unsigned int dpi_y = resolution->dpi_y;
|
||||
|
||||
if (dpi_x < 200 || dpi_x > 8200 || dpi_x % 50)
|
||||
return -EINVAL;
|
||||
if (dpi_y < 100 || dpi_y > 5000 || dpi_y % 50)
|
||||
return -EINVAL;
|
||||
@@ -833,13 +835,50 @@ roccat_remove(struct ratbag_device *device)
|
||||
free(ratbag_get_drv_data(device));
|
||||
}
|
||||
|
||||
struct ratbag_driver roccat_driver = {
|
||||
static int
|
||||
roccat_commit(struct ratbag_device *device)
|
||||
{
|
||||
|
||||
int rc = 0;
|
||||
struct ratbag_button *button = NULL;
|
||||
struct ratbag_profile *profile = NULL;
|
||||
struct ratbag_resolution *resolution = NULL;
|
||||
|
||||
ratbag_device_for_each_profile(device, profile) {
|
||||
if (!profile->dirty)
|
||||
continue;
|
||||
|
||||
rc = roccat_write_profile(profile);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
if (!resolution->dirty)
|
||||
continue;
|
||||
|
||||
rc = roccat_write_resolution(resolution);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
ratbag_profile_for_each_button(profile, button) {
|
||||
if (!button->dirty)
|
||||
continue;
|
||||
|
||||
rc = roccat_write_button(button);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ratbag_driver roccat_kone_pure_driver = {
|
||||
.name = "Roccat Kone Pure",
|
||||
.id = "roccat",
|
||||
.id = "roccat-kone-pure",
|
||||
.probe = roccat_probe,
|
||||
.remove = roccat_remove,
|
||||
.write_profile = roccat_write_profile,
|
||||
.commit = roccat_commit,
|
||||
.set_active_profile = roccat_set_current_profile,
|
||||
.write_button = roccat_write_button,
|
||||
.write_resolution_dpi = roccat_write_resolution_dpi,
|
||||
};
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
|
||||
struct roccat_settings_report {
|
||||
uint8_t reportID;
|
||||
uint8_t twoB;
|
||||
uint8_t report_length;
|
||||
uint8_t profileID;
|
||||
uint8_t x_y_linked;
|
||||
uint8_t x_sensitivity; /* 0x06 means 0 */
|
||||
@@ -78,8 +78,7 @@ struct roccat_settings_report {
|
||||
|
||||
struct roccat_macro {
|
||||
uint8_t reportID;
|
||||
uint8_t twentytwo;
|
||||
uint8_t height;
|
||||
uint16_t report_length;
|
||||
uint8_t profile;
|
||||
uint8_t button_index;
|
||||
uint8_t active;
|
||||
@@ -581,8 +580,7 @@ roccat_write_macro(struct ratbag_button *button,
|
||||
}
|
||||
|
||||
macro->reportID = ROCCAT_REPORT_ID_MACRO;
|
||||
macro->twentytwo = 0x22;
|
||||
macro->height = 0x08;
|
||||
macro->report_length = 0x0822;
|
||||
macro->profile = button->profile->index;
|
||||
macro->button_index = button->index;
|
||||
macro->active = 0x01;
|
||||
@@ -609,9 +607,9 @@ roccat_write_macro(struct ratbag_button *button,
|
||||
}
|
||||
|
||||
static int
|
||||
roccat_write_button(struct ratbag_button *button,
|
||||
const struct ratbag_button_action *action)
|
||||
roccat_write_button(struct ratbag_button *button)
|
||||
{
|
||||
const struct ratbag_button_action *action = &button->action;
|
||||
struct ratbag_profile *profile = button->profile;
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct roccat_data *drv_data = ratbag_get_drv_data(device);
|
||||
@@ -645,8 +643,7 @@ roccat_write_button(struct ratbag_button *button,
|
||||
}
|
||||
|
||||
static int
|
||||
roccat_write_resolution_dpi(struct ratbag_resolution *resolution,
|
||||
int dpi_x, int dpi_y)
|
||||
roccat_write_resolution(struct ratbag_resolution *resolution)
|
||||
{
|
||||
struct ratbag_profile *profile = resolution->profile;
|
||||
struct ratbag_device *device = profile->device;
|
||||
@@ -655,6 +652,9 @@ roccat_write_resolution_dpi(struct ratbag_resolution *resolution,
|
||||
uint8_t *buf;
|
||||
int rc;
|
||||
|
||||
const unsigned int dpi_x = resolution->dpi_x;
|
||||
const unsigned int dpi_y = resolution->dpi_y;
|
||||
|
||||
if (dpi_x < 200 || dpi_x > 8200 || dpi_x % 50)
|
||||
return -EINVAL;
|
||||
if (dpi_y < 200 || dpi_y > 8200 || dpi_y % 50)
|
||||
@@ -835,13 +835,50 @@ roccat_remove(struct ratbag_device *device)
|
||||
free(ratbag_get_drv_data(device));
|
||||
}
|
||||
|
||||
static int
|
||||
roccat_commit(struct ratbag_device *device)
|
||||
{
|
||||
|
||||
int rc = 0;
|
||||
struct ratbag_button *button = NULL;
|
||||
struct ratbag_profile *profile = NULL;
|
||||
struct ratbag_resolution *resolution = NULL;
|
||||
|
||||
ratbag_device_for_each_profile(device, profile) {
|
||||
if (!profile->dirty)
|
||||
continue;
|
||||
|
||||
rc = roccat_write_profile(profile);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
if (!resolution->dirty)
|
||||
continue;
|
||||
|
||||
rc = roccat_write_resolution(resolution);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
ratbag_profile_for_each_button(profile, button) {
|
||||
if (!button->dirty)
|
||||
continue;
|
||||
|
||||
rc = roccat_write_button(button);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ratbag_driver roccat_driver = {
|
||||
.name = "Roccat Kone XTD",
|
||||
.id = "roccat",
|
||||
.probe = roccat_probe,
|
||||
.remove = roccat_remove,
|
||||
.write_profile = roccat_write_profile,
|
||||
.commit = roccat_commit,
|
||||
.set_active_profile = roccat_set_current_profile,
|
||||
.write_button = roccat_write_button,
|
||||
.write_resolution_dpi = roccat_write_resolution_dpi,
|
||||
};
|
||||
|
||||
320
src/driver-sinowealth-nubwo.c
Normal file
320
src/driver-sinowealth-nubwo.c
Normal file
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
* Copyright © 2020 Pipat Saengow
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "libratbag-enums.h"
|
||||
#include "libratbag-hidraw.h"
|
||||
#include "libratbag-private.h"
|
||||
#include "libratbag-util.h"
|
||||
#include "shared-macro.h"
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SINOWEALTHNUBWO_PERF_CMD_REPORTID 0x02
|
||||
#define SINOWEALTHNUBWO_AESTHETIC_CMD_REPORTID 0x03
|
||||
#define SINOWEALTHNUBWO_GET_FIRMWARE_CMD_REPORTID 0x04
|
||||
|
||||
#define SINOWEALTHNUBWO_GET_FIRMWARE_MSGSIZE 256
|
||||
#define SINOWEALTHNUBWO_GET_FIRMWARE_MSGOFFSET 48
|
||||
|
||||
#define SINOWEALTHNUBWO_PERF_CMD_MSGSIZE 16
|
||||
|
||||
// Actually more but I only implemented one
|
||||
#define SINOWEALTHNUBWO_NUM_PROFILES 1
|
||||
#define SINOWEALTHNUBWO_NUM_RESOLUTIONS 1
|
||||
// Actually 8 but I am not going to implement macros.
|
||||
#define SINOWEALTHNUBWO_NUM_BUTTONS 0
|
||||
#define SINOWEALTHNUBWO_NUM_LEDS 1
|
||||
|
||||
//Magic set_feature that must be called before requesting firmware string
|
||||
static uint8_t PREFIRMWARE_QUERY_MSG[] = {0x02, 0x01, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
static unsigned int REPORT_RATES[] = { 125, 250, 333, 500, 1000 };
|
||||
static uint8_t REPORT_RATES_ENCODED[] = {0x08, 0x04, 0x03, 0x02, 0x01};
|
||||
static uint8_t REPORT_RATES_CMD[] = {0x02, 0x06, 0xbb, 0xaa, 0x28, 0x00, 0x01, 0x00};
|
||||
|
||||
static unsigned int DPILIST[] = { 1000, 2000, 3000, 5000, 15000};
|
||||
static uint8_t DPI_ENCODED[] = {0x04, 0x03, 0x02, 0x01, 0x00};
|
||||
static uint8_t DPI_CMD[] = { 0x02, 0x06, 0xbb, 0xaa, 0x32, 0x00, 0x01, 0x00 };
|
||||
|
||||
enum
|
||||
sinowealthnubwo_color_mode {
|
||||
SINOWEALTHNUBWO_COLOR_OFF = 0x00,
|
||||
SINOWEALTHNUBWO_COLOR_ON = 0x01,
|
||||
SINOWEALTHNUBWO_COLOR_BREATHING = 0x02,
|
||||
SINOWEALTHNUBWO_COLOR_COLOR_SHIFT = 0x03,
|
||||
SINOWEALTHNUBWO_COLOR_SPECTRUM = 0x04,
|
||||
SINOWEALTHNUBWO_COLOR_MARQUEE = 0x05,
|
||||
};
|
||||
|
||||
struct
|
||||
sinowealthnubwo_aesthetic_report {
|
||||
uint8_t report_id; //0x03
|
||||
uint8_t cmd[7];
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t color_mode;
|
||||
uint8_t padzero; // 0x00
|
||||
uint8_t brightness; // 0x01 to 0x03
|
||||
uint8_t tempo; // 0x05 0x03 0x01
|
||||
uint8_t padzero2[16*3+1];
|
||||
} __packed__;
|
||||
|
||||
static uint8_t AESTHETIC_CMD[] = {0x06, 0xbb, 0xaa, 0x2a, 0x00, 0x0a, 0x00};
|
||||
|
||||
static int
|
||||
sinowealthnubwo_test_hidraw(struct ratbag_device *device)
|
||||
{
|
||||
return
|
||||
ratbag_hidraw_has_report(device, SINOWEALTHNUBWO_AESTHETIC_CMD_REPORTID)
|
||||
&& ratbag_hidraw_has_report(device, SINOWEALTHNUBWO_PERF_CMD_REPORTID)
|
||||
&& ratbag_hidraw_has_report(device, SINOWEALTHNUBWO_GET_FIRMWARE_CMD_REPORTID);
|
||||
}
|
||||
|
||||
static int
|
||||
sinowealth_get_firmware_string(struct ratbag_device *device, char **output)
|
||||
{
|
||||
uint8_t buff[SINOWEALTHNUBWO_GET_FIRMWARE_MSGSIZE + 1] = {0}; //Purposefully overalloacate to prevent buffer overrun
|
||||
int size;
|
||||
|
||||
size = ratbag_hidraw_set_feature_report(device, SINOWEALTHNUBWO_PERF_CMD_REPORTID, PREFIRMWARE_QUERY_MSG, ARRAY_LENGTH(PREFIRMWARE_QUERY_MSG));
|
||||
if (size < 0) {
|
||||
log_error(device->ratbag, "Error while sending pre-firmware request message: %d\n", size);
|
||||
return size;
|
||||
}
|
||||
|
||||
size = ratbag_hidraw_get_feature_report(device, SINOWEALTHNUBWO_GET_FIRMWARE_CMD_REPORTID, buff, SINOWEALTHNUBWO_GET_FIRMWARE_MSGSIZE);
|
||||
if (size != SINOWEALTHNUBWO_GET_FIRMWARE_MSGSIZE) {
|
||||
log_error(device->ratbag ,"Firmware report reply size mismatch expected %d got %d\n", SINOWEALTHNUBWO_GET_FIRMWARE_MSGSIZE, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
*output = strdup_ascii_only((char *) buff + SINOWEALTHNUBWO_GET_FIRMWARE_MSGOFFSET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sinowealthnubwo_probe(struct ratbag_device *device)
|
||||
{
|
||||
int error;
|
||||
struct ratbag_profile *profile;
|
||||
struct ratbag_resolution *resolution;
|
||||
struct ratbag_led *led;
|
||||
|
||||
error = ratbag_find_hidraw(device, sinowealthnubwo_test_hidraw);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
char *fwstr;
|
||||
error = sinowealth_get_firmware_string(device, &fwstr);
|
||||
if (error)
|
||||
return error;
|
||||
log_info(device->ratbag, "Firmware: %s\n", fwstr);
|
||||
free(fwstr);
|
||||
|
||||
ratbag_device_init_profiles(device,
|
||||
SINOWEALTHNUBWO_NUM_PROFILES,
|
||||
SINOWEALTHNUBWO_NUM_RESOLUTIONS,
|
||||
SINOWEALTHNUBWO_NUM_BUTTONS,
|
||||
SINOWEALTHNUBWO_NUM_LEDS);
|
||||
|
||||
ratbag_device_for_each_profile(device, profile) {
|
||||
profile->is_active = true;
|
||||
|
||||
ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_WRITE_ONLY);
|
||||
ratbag_profile_set_report_rate_list(profile, REPORT_RATES, ARRAY_LENGTH(REPORT_RATES));
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
ratbag_resolution_set_dpi_list(resolution, DPILIST, ARRAY_LENGTH(DPILIST));
|
||||
resolution->dpi_x = resolution->dpi_y = DPILIST[ARRAY_LENGTH(DPILIST)-1];
|
||||
resolution->is_active = true;
|
||||
resolution->is_default = true;
|
||||
}
|
||||
ratbag_profile_for_each_led(profile, led) {
|
||||
led->mode = RATBAG_LED_OFF;
|
||||
led->color.red = led->color.green = led->color.blue = 0xFF;
|
||||
led->colordepth = RATBAG_LED_COLORDEPTH_RGB_888;
|
||||
led->type = RATBAG_LED_TYPE_SIDE;
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_OFF);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_ON);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_BREATHING);
|
||||
ratbag_led_set_mode_capability(led, RATBAG_LED_CYCLE);
|
||||
//Actually more
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t
|
||||
encode_dpi(unsigned int dpi)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_LENGTH(DPILIST); i++)
|
||||
if (DPILIST[i] == dpi)
|
||||
return DPI_ENCODED[i];
|
||||
return DPI_ENCODED[0];
|
||||
}
|
||||
|
||||
static uint8_t
|
||||
encode_report_rate(unsigned int reportrate)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_LENGTH(REPORT_RATES); i++)
|
||||
if (REPORT_RATES[i] == reportrate)
|
||||
return REPORT_RATES_ENCODED[i];
|
||||
return REPORT_RATES_ENCODED[0];
|
||||
}
|
||||
|
||||
static int
|
||||
sinowealthnubwo_set_dpi(struct ratbag_device *device, int dpi)
|
||||
{
|
||||
uint8_t buf[SINOWEALTHNUBWO_PERF_CMD_MSGSIZE] = {0};
|
||||
memcpy(buf, DPI_CMD, ARRAY_LENGTH(DPI_CMD));
|
||||
buf[ARRAY_LENGTH(DPI_CMD)] = encode_dpi(dpi);
|
||||
int error = ratbag_hidraw_set_feature_report(device, SINOWEALTHNUBWO_PERF_CMD_REPORTID, buf, SINOWEALTHNUBWO_PERF_CMD_MSGSIZE);
|
||||
if (error < 0)
|
||||
return error;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sinowealthnubwo_set_report_rate(struct ratbag_device *device, int reportrate)
|
||||
{
|
||||
uint8_t buf[SINOWEALTHNUBWO_PERF_CMD_MSGSIZE] = {0};
|
||||
memcpy(buf, REPORT_RATES_CMD, ARRAY_LENGTH(REPORT_RATES_CMD));
|
||||
buf[ARRAY_LENGTH(REPORT_RATES_CMD)] = encode_report_rate(reportrate);
|
||||
int error = ratbag_hidraw_set_feature_report(device, SINOWEALTHNUBWO_PERF_CMD_REPORTID, buf, SINOWEALTHNUBWO_PERF_CMD_MSGSIZE);
|
||||
if (error < 0)
|
||||
return error;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static enum sinowealthnubwo_color_mode encode_color(enum ratbag_led_mode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case RATBAG_LED_OFF:
|
||||
return SINOWEALTHNUBWO_COLOR_OFF;
|
||||
case RATBAG_LED_ON:
|
||||
return SINOWEALTHNUBWO_COLOR_ON;
|
||||
case RATBAG_LED_CYCLE:
|
||||
return SINOWEALTHNUBWO_COLOR_MARQUEE;
|
||||
case RATBAG_LED_BREATHING:
|
||||
return SINOWEALTHNUBWO_COLOR_BREATHING;
|
||||
default:
|
||||
return SINOWEALTHNUBWO_COLOR_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t normalize_duration(int duration)
|
||||
{
|
||||
const int MAX_DURATION = 10000;
|
||||
const uint8_t avail_dura[] = {0x01, 0x03, 0x05};
|
||||
const int selected = (duration * ((int) ARRAY_LENGTH(avail_dura)) - 1) / MAX_DURATION;
|
||||
return avail_dura[selected];
|
||||
}
|
||||
|
||||
static uint8_t normalize_brightness(int brightness)
|
||||
{
|
||||
const int MAX_BRIGHTNESS = 255;
|
||||
return 1 + (brightness * 3 - 1) / MAX_BRIGHTNESS;
|
||||
}
|
||||
|
||||
static int
|
||||
sinowealthnubwo_set_aesthetic(struct ratbag_device *device, struct ratbag_led *led) {
|
||||
struct sinowealthnubwo_aesthetic_report report;
|
||||
memset(&report, 0, sizeof(struct sinowealthnubwo_aesthetic_report));
|
||||
report.report_id = SINOWEALTHNUBWO_AESTHETIC_CMD_REPORTID;
|
||||
memcpy(report.cmd, AESTHETIC_CMD, ARRAY_LENGTH(AESTHETIC_CMD));
|
||||
report.r = led->color.red;
|
||||
report.g = led->color.green;
|
||||
report.b = led->color.blue;
|
||||
report.color_mode = encode_color(led->mode);
|
||||
report.tempo = normalize_duration(led->ms);
|
||||
report.brightness = normalize_brightness(led->brightness);
|
||||
|
||||
int size = ratbag_hidraw_set_feature_report(device, SINOWEALTHNUBWO_AESTHETIC_CMD_REPORTID, (uint8_t *) &report, sizeof(report));
|
||||
if (size < 0)
|
||||
return size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sinowealthnubwo_write_profile(struct ratbag_device *device, struct ratbag_profile *profile)
|
||||
{
|
||||
struct ratbag_resolution *resolution;
|
||||
struct ratbag_led *led;
|
||||
int error;
|
||||
|
||||
log_debug(device->ratbag, "Writing updates\n");
|
||||
|
||||
log_debug(device->ratbag, "Setting report rate\n");
|
||||
error = sinowealthnubwo_set_report_rate(device, profile->hz);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
if (!resolution->dirty)
|
||||
continue;
|
||||
log_debug(device->ratbag, "Setting DPI\n");
|
||||
error = sinowealthnubwo_set_dpi(device, resolution->dpi_x);
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
|
||||
ratbag_profile_for_each_led(profile, led) {
|
||||
if (!led->dirty)
|
||||
continue;
|
||||
log_debug(device->ratbag, "Setting aesthetic\n");
|
||||
error = sinowealthnubwo_set_aesthetic(device, led);
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sinowealthnubwo_commit(struct ratbag_device *device)
|
||||
{
|
||||
struct ratbag_profile *profile;
|
||||
list_for_each(profile, &device->profiles, link) {
|
||||
if (!profile->dirty) continue;
|
||||
|
||||
int error = sinowealthnubwo_write_profile(device, profile);
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
sinowealthnubwo_remove(struct ratbag_device *device)
|
||||
{
|
||||
ratbag_close_hidraw(device);
|
||||
}
|
||||
|
||||
struct ratbag_driver sinowealth_nubwo_driver = {
|
||||
.name = "Sinowealth Nubwo",
|
||||
.id = "sinowealth_nubwo",
|
||||
.probe = sinowealthnubwo_probe,
|
||||
.remove = sinowealthnubwo_remove,
|
||||
.commit = sinowealthnubwo_commit,
|
||||
};
|
||||
1796
src/driver-sinowealth.c
Normal file
1796
src/driver-sinowealth.c
Normal file
File diff suppressed because it is too large
Load Diff
41
src/driver-sinowealth.h
Normal file
41
src/driver-sinowealth.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright © 2022 Yaroslav Chvanov
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "libratbag-util.h"
|
||||
|
||||
enum sinowealth_led_format {
|
||||
SINOWEALTH_LED_TYPE_NONE,
|
||||
SINOWEALTH_LED_TYPE_RBG,
|
||||
SINOWEALTH_LED_TYPE_RGB,
|
||||
};
|
||||
|
||||
struct sinowealth_device_data {
|
||||
char *fw_version;
|
||||
char *device_name;
|
||||
enum sinowealth_led_format led_type;
|
||||
unsigned int button_count;
|
||||
|
||||
struct list link;
|
||||
};
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "driver-steelseries.h"
|
||||
#include "libratbag-private.h"
|
||||
#include "libratbag-hidraw.h"
|
||||
#include "libratbag-data.h"
|
||||
@@ -41,6 +42,7 @@
|
||||
#define STEELSERIES_INPUT_HIDRAW 1
|
||||
|
||||
/* not sure these two are used for */
|
||||
#define STEELSERIES_REPORT_ID 0x00 // steelseries doesn't use numbered reports
|
||||
#define STEELSERIES_REPORT_ID_1 0x01
|
||||
#define STEELSERIES_REPORT_ID_2 0x02
|
||||
|
||||
@@ -53,14 +55,16 @@
|
||||
#define STEELSERIES_ID_LED_INTENSITY_SHORT 0x05
|
||||
#define STEELSERIES_ID_LED_EFFECT_SHORT 0x07
|
||||
#define STEELSERIES_ID_LED_COLOR_SHORT 0x08
|
||||
#define STEELSERIES_ID_LED_COLOR_SHORT_RIVAL100 0x05
|
||||
#define STEELSERIES_ID_SAVE_SHORT 0x09
|
||||
#define STEELSERIES_ID_FIRMWARE_PROTOCOL1 0x10
|
||||
|
||||
#define STEELSERIES_ID_BUTTONS 0x31
|
||||
#define STEELSERIES_ID_DPI 0x53
|
||||
#define STEELSERIES_ID_REPORT_RATE 0x54
|
||||
#define STEELSERIES_ID_LED 0x5b
|
||||
#define STEELSERIES_ID_SAVE 0x59
|
||||
#define STEELSERIES_ID_FIRMWARE 0x90
|
||||
#define STEELSERIES_ID_FIRMWARE_PROTOCOL2 0x90
|
||||
#define STEELSERIES_ID_SETTTINGS 0x92
|
||||
|
||||
#define STEELSERIES_ID_DPI_PROTOCOL3 0x03
|
||||
@@ -112,11 +116,31 @@ struct steelseries_led_cycle_spec {
|
||||
int point_count_idx; /* index of the point counter field */
|
||||
};
|
||||
|
||||
struct _steelseries_message {
|
||||
uint8_t report_id;
|
||||
uint8_t parameters[STEELSERIES_REPORT_SIZE - 1];
|
||||
} __attribute__((packed));
|
||||
|
||||
union steelseries_message {
|
||||
struct _steelseries_message msg;
|
||||
uint8_t data[STEELSERIES_REPORT_SIZE];
|
||||
};
|
||||
|
||||
_Static_assert(sizeof(union steelseries_message) == STEELSERIES_REPORT_SIZE,
|
||||
"Size of union steelseries_message is wrong");
|
||||
|
||||
static int
|
||||
steelseries_test_hidraw(struct ratbag_device *device)
|
||||
{
|
||||
int device_version = ratbag_device_data_steelseries_get_device_version(device->data);
|
||||
|
||||
/* Rival mice are composite devices with multiple HID devices
|
||||
* and only the HID vendor device can be used to configure the
|
||||
* device.
|
||||
*/
|
||||
if (!ratbag_hidraw_has_vendor_page(device))
|
||||
return false;
|
||||
|
||||
if (device_version > 1)
|
||||
return ratbag_hidraw_has_report(device, STEELSERIES_REPORT_ID_1);
|
||||
else
|
||||
@@ -179,23 +203,38 @@ steelseries_get_firmware_version(struct ratbag_device *device)
|
||||
{
|
||||
struct steelseries_data *drv_data = device->drv_data;
|
||||
int device_version = ratbag_device_data_steelseries_get_device_version(device->data);
|
||||
size_t buf_len = STEELSERIES_REPORT_SIZE;
|
||||
uint8_t buf[STEELSERIES_REPORT_SIZE] = {0};
|
||||
size_t msg_len;
|
||||
uint8_t buf[2] = {0};
|
||||
int ret;
|
||||
|
||||
if (device_version == 2)
|
||||
buf[0] = STEELSERIES_ID_FIRMWARE;
|
||||
else if (device_version == 3)
|
||||
buf[0] = STEELSERIES_ID_FIRMWARE_PROTOCOL3;
|
||||
else
|
||||
union steelseries_message msg = {
|
||||
.msg.report_id = STEELSERIES_REPORT_ID,
|
||||
.msg.parameters = {0},
|
||||
};
|
||||
|
||||
switch (device_version) {
|
||||
case 1:
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_FIRMWARE_PROTOCOL1;
|
||||
msg_len = STEELSERIES_REPORT_SIZE_SHORT;
|
||||
break;
|
||||
case 2:
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_FIRMWARE_PROTOCOL2;
|
||||
msg_len = STEELSERIES_REPORT_SIZE;
|
||||
break;
|
||||
case 3:
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_FIRMWARE_PROTOCOL3;
|
||||
msg_len = STEELSERIES_REPORT_SIZE;
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
msleep(10);
|
||||
ret = ratbag_hidraw_output_report(device, buf, buf_len);
|
||||
ret = ratbag_hidraw_output_report(device, msg.data, msg_len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = ratbag_hidraw_read_input_report_index(device, buf, buf_len, STEELSERIES_INPUT_HIDRAW);
|
||||
ret = ratbag_hidraw_read_input_report_index(device, buf, sizeof(buf), STEELSERIES_INPUT_HIDRAW, NULL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@@ -213,24 +252,33 @@ steelseries_read_settings(struct ratbag_device *device)
|
||||
struct ratbag_resolution *resolution;
|
||||
struct ratbag_led *led;
|
||||
|
||||
size_t buf_len = STEELSERIES_REPORT_SIZE;
|
||||
uint8_t buf[STEELSERIES_REPORT_SIZE] = {0};
|
||||
int ret;
|
||||
unsigned int active_resolution;
|
||||
|
||||
if (device_version == 2)
|
||||
buf[0] = STEELSERIES_ID_SETTTINGS;
|
||||
else if (device_version == 3)
|
||||
buf[0] = STEELSERIES_ID_SETTTINGS_PROTOCOL3;
|
||||
else
|
||||
union steelseries_message msg = {
|
||||
.msg.report_id = STEELSERIES_REPORT_ID,
|
||||
.msg.parameters = {0},
|
||||
};
|
||||
|
||||
switch (device_version) {
|
||||
case 2:
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_SETTTINGS;
|
||||
break;
|
||||
case 3:
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_SETTTINGS_PROTOCOL3;
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
msleep(10);
|
||||
ret = ratbag_hidraw_output_report(device, buf, buf_len);
|
||||
ret = ratbag_hidraw_output_report(device, msg.data, STEELSERIES_REPORT_SIZE);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = ratbag_hidraw_read_input_report_index(device, buf, buf_len, STEELSERIES_INPUT_HIDRAW);
|
||||
ret = ratbag_hidraw_read_input_report_index(device, buf, STEELSERIES_REPORT_SIZE, STEELSERIES_INPUT_HIDRAW, NULL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@@ -270,7 +318,7 @@ steelseries_probe(struct ratbag_device *device)
|
||||
struct ratbag_resolution *resolution;
|
||||
struct ratbag_button *button;
|
||||
struct ratbag_led *led;
|
||||
int rc, button_count, led_count, device_version, mono_led, short_button;
|
||||
int rc, button_count, led_count, device_version, quirk;
|
||||
struct dpi_list *dpilist = NULL;
|
||||
struct dpi_range *dpirange = NULL;
|
||||
|
||||
@@ -287,12 +335,22 @@ steelseries_probe(struct ratbag_device *device)
|
||||
return rc;
|
||||
|
||||
device_version = ratbag_device_data_steelseries_get_device_version(device->data);
|
||||
if (device_version == -1) {
|
||||
log_error(device->ratbag, "Device version not set\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
button_count = ratbag_device_data_steelseries_get_button_count(device->data);
|
||||
if (button_count == -1)
|
||||
button_count = 0;
|
||||
|
||||
led_count = ratbag_device_data_steelseries_get_led_count(device->data);
|
||||
if (led_count == -1)
|
||||
led_count = 0;
|
||||
|
||||
dpirange = ratbag_device_data_steelseries_get_dpi_range(device->data);
|
||||
dpilist = ratbag_device_data_steelseries_get_dpi_list(device->data);
|
||||
mono_led = ratbag_device_data_steelseries_get_mono_led(device->data);
|
||||
short_button = ratbag_device_data_steelseries_get_short_button(device->data);
|
||||
quirk = ratbag_device_data_steelseries_get_quirk(device->data);
|
||||
|
||||
ratbag_device_init_profiles(device,
|
||||
STEELSERIES_NUM_PROFILES,
|
||||
@@ -336,7 +394,7 @@ steelseries_probe(struct ratbag_device *device)
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_BUTTON);
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_SPECIAL);
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_KEY);
|
||||
if (short_button == 0) {
|
||||
if (quirk != STEELSERIES_QUIRK_SENSEIRAW) {
|
||||
ratbag_button_enable_action_type(button, RATBAG_BUTTON_ACTION_TYPE_MACRO);
|
||||
}
|
||||
|
||||
@@ -346,7 +404,7 @@ steelseries_probe(struct ratbag_device *device)
|
||||
ratbag_profile_for_each_led(profile, led) {
|
||||
led->type = led->index == 0 ? RATBAG_LED_TYPE_LOGO : RATBAG_LED_TYPE_WHEEL;
|
||||
led->mode = RATBAG_LED_ON;
|
||||
if (mono_led) {
|
||||
if (quirk == STEELSERIES_QUIRK_SENSEIRAW) {
|
||||
led->colordepth = RATBAG_LED_COLORDEPTH_MONOCHROME;
|
||||
led->brightness = 255;
|
||||
} else {
|
||||
@@ -385,15 +443,19 @@ steelseries_write_dpi(struct ratbag_resolution *resolution)
|
||||
struct dpi_list *dpilist = NULL;
|
||||
struct dpi_range *dpirange = NULL;
|
||||
int ret;
|
||||
int i = 0;
|
||||
size_t buf_len;
|
||||
uint8_t buf[STEELSERIES_REPORT_SIZE] = {0};
|
||||
|
||||
union steelseries_message msg = {
|
||||
.msg.report_id = STEELSERIES_REPORT_ID,
|
||||
.msg.parameters = {0},
|
||||
};
|
||||
|
||||
dpirange = ratbag_device_data_steelseries_get_dpi_range(device->data);
|
||||
dpilist = ratbag_device_data_steelseries_get_dpi_list(device->data);
|
||||
|
||||
if (device_version == 1) {
|
||||
int i = 0;
|
||||
|
||||
switch (device_version) {
|
||||
case 1:
|
||||
/* when using lists the entries are enumerated in reverse */
|
||||
if (dpilist) {
|
||||
for (i = 0; i < (int)resolution->ndpis; i++) {
|
||||
@@ -406,27 +468,30 @@ steelseries_write_dpi(struct ratbag_resolution *resolution)
|
||||
}
|
||||
|
||||
buf_len = STEELSERIES_REPORT_SIZE_SHORT;
|
||||
buf[0] = STEELSERIES_ID_DPI_SHORT;
|
||||
buf[1] = resolution->index + 1;
|
||||
buf[2] = i;
|
||||
} else if (device_version == 2) {
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_DPI_SHORT;
|
||||
msg.msg.parameters[1] = resolution->index + 1;
|
||||
msg.msg.parameters[2] = i;
|
||||
break;
|
||||
case 2:
|
||||
buf_len = STEELSERIES_REPORT_SIZE;
|
||||
buf[0] = STEELSERIES_ID_DPI;
|
||||
buf[2] = resolution->index + 1;
|
||||
buf[3] = resolution->dpi_x / dpirange->step - 1;
|
||||
buf[6] = 0x42; /* not sure if needed */
|
||||
} else if (device_version == 3) {
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_DPI;
|
||||
msg.msg.parameters[2] = resolution->index + 1;
|
||||
msg.msg.parameters[3] = resolution->dpi_x / dpirange->step - 1;
|
||||
msg.msg.parameters[6] = 0x42; /* not sure if needed */
|
||||
break;
|
||||
case 3:
|
||||
buf_len = STEELSERIES_REPORT_SIZE;
|
||||
buf[0] = STEELSERIES_ID_DPI_PROTOCOL3;
|
||||
buf[2] = resolution->index + 1;
|
||||
buf[3] = resolution->dpi_x / dpirange->step - 1;
|
||||
buf[5] = 0x42; /* not sure if needed */
|
||||
} else {
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_DPI_PROTOCOL3;
|
||||
msg.msg.parameters[2] = resolution->index + 1;
|
||||
msg.msg.parameters[3] = resolution->dpi_x / dpirange->step - 1;
|
||||
msg.msg.parameters[5] = 0x42; /* not sure if needed */
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
msleep(10);
|
||||
ret = ratbag_hidraw_output_report(device, buf, buf_len);
|
||||
ret = ratbag_hidraw_output_report(device, msg.data, buf_len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@@ -440,26 +505,49 @@ steelseries_write_report_rate(struct ratbag_profile *profile)
|
||||
int device_version = ratbag_device_data_steelseries_get_device_version(device->data);
|
||||
int ret;
|
||||
size_t buf_len;
|
||||
uint8_t buf[STEELSERIES_REPORT_SIZE] = {0};
|
||||
uint8_t reported_rate = 0;
|
||||
|
||||
union steelseries_message msg = {
|
||||
.msg.report_id = STEELSERIES_REPORT_ID,
|
||||
.msg.parameters = {0},
|
||||
};
|
||||
|
||||
switch (device_version) {
|
||||
case 1:
|
||||
if (profile->hz >= 1000) {
|
||||
profile->hz = 1000;
|
||||
reported_rate = 0x01;
|
||||
} else if (profile->hz >= 375) {
|
||||
profile->hz = 500;
|
||||
reported_rate = 0x02;
|
||||
} else if (profile->hz <= 125) {
|
||||
profile->hz = 125;
|
||||
reported_rate = 0x04;
|
||||
} else {
|
||||
profile->hz = 250;
|
||||
reported_rate = 0x03;
|
||||
}
|
||||
|
||||
if (device_version == 1) {
|
||||
buf_len = STEELSERIES_REPORT_SIZE_SHORT;
|
||||
buf[0] = STEELSERIES_ID_REPORT_RATE_SHORT;
|
||||
buf[2] = 1000 / profile->hz;
|
||||
} else if (device_version == 2) {
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_REPORT_RATE_SHORT;
|
||||
msg.msg.parameters[2] = reported_rate;
|
||||
break;
|
||||
case 2:
|
||||
buf_len = STEELSERIES_REPORT_SIZE;
|
||||
buf[0] = STEELSERIES_ID_REPORT_RATE;
|
||||
buf[2] = 1000 / profile->hz;
|
||||
} else if (device_version == 3) {
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_REPORT_RATE;
|
||||
msg.msg.parameters[2] = 1000 / profile->hz;
|
||||
break;
|
||||
case 3:
|
||||
buf_len = STEELSERIES_REPORT_SIZE;
|
||||
buf[0] = STEELSERIES_ID_REPORT_RATE_PROTOCOL3;
|
||||
buf[2] = 1000 / profile->hz;
|
||||
} else {
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_REPORT_RATE_PROTOCOL3;
|
||||
msg.msg.parameters[2] = 1000 / profile->hz;
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
msleep(10);
|
||||
ret = ratbag_hidraw_output_report(device, buf, buf_len);
|
||||
ret = ratbag_hidraw_output_report(device, msg.data, buf_len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@@ -477,15 +565,17 @@ steelseries_write_buttons(struct ratbag_profile *profile)
|
||||
if (ratbag_device_data_steelseries_get_macro_length(device->data) == 0)
|
||||
return 0;
|
||||
|
||||
int short_button = ratbag_device_data_steelseries_get_short_button(device->data);
|
||||
int button_size = (short_button == 0) ? 5 : 3;
|
||||
int report_size = (short_button == 0) ? STEELSERIES_REPORT_LONG_SIZE : STEELSERIES_REPORT_SIZE_SHORT;
|
||||
int max_modifiers = (short_button == 0) ? 3 : 0;
|
||||
const bool is_senseiraw = ratbag_device_data_steelseries_get_quirk(device->data) == STEELSERIES_QUIRK_SENSEIRAW;
|
||||
const int button_size = is_senseiraw ? 3 : 5;
|
||||
const int report_size = is_senseiraw ? STEELSERIES_REPORT_SIZE_SHORT : STEELSERIES_REPORT_LONG_SIZE;
|
||||
const int max_modifiers = is_senseiraw ? 0 : 3;
|
||||
|
||||
uint8_t buf[report_size];
|
||||
memset(buf, 0, report_size);
|
||||
union steelseries_message msg = {
|
||||
.msg.report_id = STEELSERIES_REPORT_ID,
|
||||
.msg.parameters = {0},
|
||||
};
|
||||
|
||||
buf[0] = STEELSERIES_ID_BUTTONS;
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_BUTTONS;
|
||||
|
||||
ratbag_profile_for_each_button(profile, button) {
|
||||
struct ratbag_button_action *action = &button->action;
|
||||
@@ -498,7 +588,7 @@ steelseries_write_buttons(struct ratbag_profile *profile)
|
||||
|
||||
switch (action->type) {
|
||||
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
|
||||
buf[idx] = action->action.button;
|
||||
msg.msg.parameters[idx] = action->action.button;
|
||||
break;
|
||||
|
||||
case RATBAG_BUTTON_ACTION_TYPE_MACRO:
|
||||
@@ -515,48 +605,48 @@ steelseries_write_buttons(struct ratbag_profile *profile)
|
||||
code = ratbag_hidraw_get_keyboard_usage_from_keycode(
|
||||
device, key);
|
||||
if (code) {
|
||||
if (short_button) {
|
||||
buf[idx] = STEELSERIES_BUTTON_KEY;
|
||||
if (is_senseiraw) {
|
||||
msg.msg.parameters[idx] = STEELSERIES_BUTTON_KEY;
|
||||
} else {
|
||||
buf[idx] = STEELSERIES_BUTTON_KBD;
|
||||
msg.msg.parameters[idx] = STEELSERIES_BUTTON_KBD;
|
||||
|
||||
if (modifiers & MODIFIER_LEFTCTRL)
|
||||
buf[++idx] = 0xE0;
|
||||
msg.msg.parameters[++idx] = 0xE0;
|
||||
if (modifiers & MODIFIER_LEFTSHIFT)
|
||||
buf[++idx] = 0xE1;
|
||||
msg.msg.parameters[++idx] = 0xE1;
|
||||
if (modifiers & MODIFIER_LEFTALT)
|
||||
buf[++idx] = 0xE2;
|
||||
msg.msg.parameters[++idx] = 0xE2;
|
||||
if (modifiers & MODIFIER_LEFTMETA)
|
||||
buf[++idx] = 0xE3;
|
||||
msg.msg.parameters[++idx] = 0xE3;
|
||||
if (modifiers & MODIFIER_RIGHTCTRL)
|
||||
buf[++idx] = 0xE4;
|
||||
msg.msg.parameters[++idx] = 0xE4;
|
||||
if (modifiers & MODIFIER_RIGHTSHIFT)
|
||||
buf[++idx] = 0xE5;
|
||||
msg.msg.parameters[++idx] = 0xE5;
|
||||
if (modifiers & MODIFIER_RIGHTALT)
|
||||
buf[++idx] = 0xE6;
|
||||
msg.msg.parameters[++idx] = 0xE6;
|
||||
if (modifiers & MODIFIER_RIGHTMETA)
|
||||
buf[++idx] = 0xE7;
|
||||
msg.msg.parameters[++idx] = 0xE7;
|
||||
}
|
||||
|
||||
buf[idx + 1] = code;
|
||||
msg.msg.parameters[idx + 1] = code;
|
||||
} else {
|
||||
code = ratbag_hidraw_get_consumer_usage_from_keycode(
|
||||
device, action->action.key.key);
|
||||
buf[idx] = STEELSERIES_BUTTON_CONSUMER;
|
||||
buf[idx + 1] = code;
|
||||
msg.msg.parameters[idx] = STEELSERIES_BUTTON_CONSUMER;
|
||||
msg.msg.parameters[idx + 1] = code;
|
||||
}
|
||||
break;
|
||||
|
||||
case RATBAG_BUTTON_ACTION_TYPE_SPECIAL:
|
||||
switch (action->action.special) {
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_CYCLE_UP:
|
||||
buf[idx] = STEELSERIES_BUTTON_RES_CYCLE;
|
||||
msg.msg.parameters[idx] = STEELSERIES_BUTTON_RES_CYCLE;
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_UP:
|
||||
buf[idx] = STEELSERIES_BUTTON_WHEEL_UP;
|
||||
msg.msg.parameters[idx] = STEELSERIES_BUTTON_WHEEL_UP;
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_DOWN:
|
||||
buf[idx] = STEELSERIES_BUTTON_WHEEL_DOWN;
|
||||
msg.msg.parameters[idx] = STEELSERIES_BUTTON_WHEEL_DOWN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -566,7 +656,7 @@ steelseries_write_buttons(struct ratbag_profile *profile)
|
||||
case RATBAG_BUTTON_ACTION_TYPE_KEY:
|
||||
case RATBAG_BUTTON_ACTION_TYPE_NONE:
|
||||
default:
|
||||
buf[idx] = STEELSERIES_BUTTON_OFF;
|
||||
msg.msg.parameters[idx] = STEELSERIES_BUTTON_OFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -574,9 +664,10 @@ steelseries_write_buttons(struct ratbag_profile *profile)
|
||||
msleep(10);
|
||||
if (device_version == 3)
|
||||
ret = ratbag_hidraw_raw_request(device, STEELSERIES_ID_BUTTONS,
|
||||
buf,sizeof(buf),HID_FEATURE_REPORT,HID_REQ_SET_REPORT);
|
||||
msg.msg.parameters, report_size - 1,
|
||||
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
|
||||
else
|
||||
ret = ratbag_hidraw_output_report(device, buf, sizeof(buf));
|
||||
ret = ratbag_hidraw_output_report(device, msg.data, report_size);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@@ -588,19 +679,34 @@ static int
|
||||
steelseries_write_led_v1(struct ratbag_led *led)
|
||||
{
|
||||
struct ratbag_device *device = led->profile->device;
|
||||
uint8_t buf[STEELSERIES_REPORT_SIZE_SHORT] = {0};
|
||||
const enum steelseries_quirk quirk = ratbag_device_data_steelseries_get_quirk(device->data);
|
||||
int ret;
|
||||
|
||||
buf[0] = STEELSERIES_ID_LED_EFFECT_SHORT;
|
||||
buf[1] = led->index + 1;
|
||||
union steelseries_message msg = {
|
||||
.msg.report_id = STEELSERIES_REPORT_ID,
|
||||
.msg.parameters = {0},
|
||||
};
|
||||
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_LED_EFFECT_SHORT;
|
||||
msg.msg.parameters[1] = quirk == STEELSERIES_QUIRK_RIVAL100 ? 0x00 : led->index + 1;
|
||||
|
||||
switch(led->mode) {
|
||||
case RATBAG_LED_OFF:
|
||||
case RATBAG_LED_ON:
|
||||
buf[2] = 0x01;
|
||||
msg.msg.parameters[2] = 0x01;
|
||||
break;
|
||||
case RATBAG_LED_BREATHING:
|
||||
buf[2] = 0x03; /* 0x02: slow, 0x03: medium, 0x04: fast */
|
||||
/* 0x2/3/4 - speed (by eye it's 3, 5 and 7 seconds) */
|
||||
if (led->ms <= 3000) {
|
||||
led->ms = 3000;
|
||||
msg.msg.parameters[2] = 0x04;
|
||||
} else if (led->ms <= 5000) {
|
||||
led->ms = 5000;
|
||||
msg.msg.parameters[2] = 0x03;
|
||||
} else {
|
||||
led->ms = 7000;
|
||||
msg.msg.parameters[2] = 0x02;
|
||||
}
|
||||
break;
|
||||
case RATBAG_LED_CYCLE:
|
||||
/* Cycle mode is not supported on this version */
|
||||
@@ -609,31 +715,36 @@ steelseries_write_led_v1(struct ratbag_led *led)
|
||||
}
|
||||
|
||||
msleep(10);
|
||||
ret = ratbag_hidraw_output_report(device, buf, sizeof(buf));
|
||||
ret = ratbag_hidraw_output_report(device, msg.data, STEELSERIES_REPORT_SIZE_SHORT);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
int mono_led = ratbag_device_data_steelseries_get_mono_led(device->data);
|
||||
memset(msg.data, 0, STEELSERIES_REPORT_SIZE); // reset the msg buffer before reusing
|
||||
|
||||
if (mono_led) {
|
||||
buf[0] = STEELSERIES_ID_LED_INTENSITY_SHORT;
|
||||
buf[1] = led->index + 1;
|
||||
if (quirk == STEELSERIES_QUIRK_SENSEIRAW) {
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_LED_INTENSITY_SHORT;
|
||||
msg.msg.parameters[1] = led->index + 1;
|
||||
if (led->mode == RATBAG_LED_OFF || led->brightness == 0) {
|
||||
buf[2] = 1;
|
||||
msg.msg.parameters[2] = 1;
|
||||
} else {
|
||||
//split the brightness into roughly 3 equal intensities
|
||||
buf[2] = (led->brightness / 86) + 2;
|
||||
msg.msg.parameters[2] = (led->brightness / 86) + 2;
|
||||
}
|
||||
} else {
|
||||
buf[0] = STEELSERIES_ID_LED_COLOR_SHORT;
|
||||
buf[1] = led->index + 1;
|
||||
buf[2] = led->color.red;
|
||||
buf[3] = led->color.green;
|
||||
buf[4] = led->color.blue;
|
||||
if (quirk != STEELSERIES_QUIRK_RIVAL100) {
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_LED_COLOR_SHORT;
|
||||
msg.msg.parameters[1] = led->index + 1;
|
||||
} else {
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_LED_COLOR_SHORT_RIVAL100;
|
||||
msg.msg.parameters[1] = 0x00;
|
||||
}
|
||||
msg.msg.parameters[2] = led->color.red;
|
||||
msg.msg.parameters[3] = led->color.green;
|
||||
msg.msg.parameters[4] = led->color.blue;
|
||||
}
|
||||
|
||||
msleep(10);
|
||||
ret = ratbag_hidraw_output_report(device, buf, sizeof(buf));
|
||||
ret = ratbag_hidraw_output_report(device, msg.data, STEELSERIES_REPORT_SIZE_SHORT);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@@ -709,10 +820,14 @@ steelseries_write_led_cycle(struct ratbag_led *led,
|
||||
struct steelseries_led_cycle_spec *cycle_spec)
|
||||
{
|
||||
struct ratbag_device *device = led->profile->device;
|
||||
uint8_t buf[STEELSERIES_REPORT_SIZE] = {0};
|
||||
int device_version = ratbag_device_data_steelseries_get_device_version(device->data);
|
||||
int ret;
|
||||
|
||||
union steelseries_message msg = {
|
||||
.msg.report_id = STEELSERIES_REPORT_ID,
|
||||
.msg.parameters = {0},
|
||||
};
|
||||
|
||||
struct steelseries_led_cycle cycle;
|
||||
struct steelseries_point point[4];
|
||||
|
||||
@@ -781,14 +896,15 @@ steelseries_write_led_cycle(struct ratbag_led *led,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
construct_cycle_buffer(&cycle, cycle_spec, buf, sizeof(buf));
|
||||
construct_cycle_buffer(&cycle, cycle_spec, msg.msg.parameters, sizeof(msg.msg.parameters));
|
||||
|
||||
msleep(10);
|
||||
if (device_version == 3)
|
||||
ret = ratbag_hidraw_raw_request(device, cycle_spec->cmd_val, buf,
|
||||
sizeof(buf), cycle_spec->hid_report_type, HID_REQ_SET_REPORT);
|
||||
ret = ratbag_hidraw_raw_request(device, cycle_spec->cmd_val, msg.msg.parameters,
|
||||
sizeof(msg.msg.parameters), cycle_spec->hid_report_type,
|
||||
HID_REQ_SET_REPORT);
|
||||
else
|
||||
ret = ratbag_hidraw_output_report(device, buf, sizeof(buf));
|
||||
ret = ratbag_hidraw_output_report(device, msg.data, sizeof(msg.data));
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@@ -855,23 +971,27 @@ steelseries_write_save(struct ratbag_device *device)
|
||||
int device_version = ratbag_device_data_steelseries_get_device_version(device->data);
|
||||
int ret;
|
||||
size_t buf_len;
|
||||
uint8_t buf[STEELSERIES_REPORT_SIZE] = {0};
|
||||
|
||||
union steelseries_message msg = {
|
||||
.msg.report_id = STEELSERIES_REPORT_ID,
|
||||
.msg.parameters = {0},
|
||||
};
|
||||
|
||||
if (device_version == 1) {
|
||||
buf_len = STEELSERIES_REPORT_SIZE_SHORT;
|
||||
buf[0] = STEELSERIES_ID_SAVE_SHORT;
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_SAVE_SHORT;
|
||||
} else if (device_version == 2) {
|
||||
buf_len = STEELSERIES_REPORT_SIZE;
|
||||
buf[0] = STEELSERIES_ID_SAVE;
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_SAVE;
|
||||
} else if (device_version == 3) {
|
||||
buf_len = STEELSERIES_REPORT_SIZE;
|
||||
buf[0] = STEELSERIES_ID_SAVE_PROTOCOL3;
|
||||
msg.msg.parameters[0] = STEELSERIES_ID_SAVE_PROTOCOL3;
|
||||
} else {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
msleep(20);
|
||||
ret = ratbag_hidraw_output_report(device, buf, buf_len);
|
||||
ret = ratbag_hidraw_output_report(device, msg.data, buf_len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@@ -887,9 +1007,11 @@ steelseries_write_profile(struct ratbag_profile *profile)
|
||||
int rc;
|
||||
bool buttons_dirty = false;
|
||||
|
||||
rc = steelseries_write_report_rate(profile);
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
if (profile->rate_dirty) {
|
||||
rc = steelseries_write_report_rate(profile);
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
}
|
||||
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
if (!resolution->dirty)
|
||||
|
||||
7
src/driver-steelseries.h
Normal file
7
src/driver-steelseries.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
enum steelseries_quirk {
|
||||
STEELSERIES_QURIK_NONE,
|
||||
STEELSERIES_QUIRK_RIVAL100,
|
||||
STEELSERIES_QUIRK_SENSEIRAW,
|
||||
};
|
||||
@@ -29,14 +29,6 @@
|
||||
#include "libratbag-private.h"
|
||||
#include "libratbag-test.h"
|
||||
|
||||
static int
|
||||
test_write_profile(struct ratbag_profile *profile)
|
||||
{
|
||||
/* check if the device is still valid */
|
||||
assert(ratbag_get_drv_data(profile->device) != NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_set_active_profile(struct ratbag_device *device, unsigned int index)
|
||||
{
|
||||
@@ -136,26 +128,6 @@ test_read_led(struct ratbag_led *led)
|
||||
led->type = d->profiles[0].leds[led->index].type;
|
||||
}
|
||||
|
||||
static int
|
||||
test_write_button(struct ratbag_button *button,
|
||||
const struct ratbag_button_action *action)
|
||||
{
|
||||
/* check if the device is still valid */
|
||||
assert(ratbag_get_drv_data(button->profile->device) != NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_write_led(struct ratbag_led *led,
|
||||
enum ratbag_led_mode mode,
|
||||
struct ratbag_color color, unsigned int ms,
|
||||
unsigned int brightness)
|
||||
{
|
||||
/* check if the device is still valid */
|
||||
assert(ratbag_get_drv_data(led->profile->device) != NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_fake_probe(struct ratbag_device *device)
|
||||
{
|
||||
@@ -285,15 +257,21 @@ test_remove(struct ratbag_device *device)
|
||||
free(d);
|
||||
}
|
||||
|
||||
static int
|
||||
test_commit(struct ratbag_device *device)
|
||||
{
|
||||
/* check if the device is still valid */
|
||||
assert(ratbag_get_drv_data(device) != NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ratbag_driver test_driver = {
|
||||
.name = "Test driver",
|
||||
.id = "test_driver",
|
||||
.probe = test_fake_probe,
|
||||
.test_probe = test_probe,
|
||||
.remove = test_remove,
|
||||
.write_profile = test_write_profile,
|
||||
.commit = test_commit,
|
||||
.set_active_profile = test_set_active_profile,
|
||||
.write_button = test_write_button,
|
||||
.write_resolution_dpi = NULL,
|
||||
.write_led = test_write_led,
|
||||
};
|
||||
|
||||
@@ -106,7 +106,7 @@ struct hidpp_device {
|
||||
void *userdata;
|
||||
hidpp_log_handler log_handler;
|
||||
enum hidpp_log_priority log_priority;
|
||||
uint8_t supported_report_types;
|
||||
unsigned supported_report_types;
|
||||
};
|
||||
|
||||
#define HIDPP_REPORT_SHORT (1 << 0)
|
||||
|
||||
@@ -807,8 +807,12 @@ hidpp10_get_current_profile(struct hidpp10_device *dev, uint8_t *current_profile
|
||||
__CMD_PROFILE);
|
||||
|
||||
res = hidpp10_request_command(dev, &profile);
|
||||
if (res)
|
||||
return res;
|
||||
if (res) {
|
||||
/* Profiles not supported */
|
||||
hidpp_log_debug(&dev->base, "Profiles not supported\n");
|
||||
*current_profile = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
type = profile.msg.parameters[0];
|
||||
page = profile.msg.parameters[1];
|
||||
@@ -1144,6 +1148,9 @@ hidpp10_onboard_profiles_read_macro(struct hidpp10_device *device,
|
||||
}
|
||||
|
||||
if (rc == -ENOMEM) {
|
||||
if ((unsigned) offset + mem_index > 0xff)
|
||||
goto out_err;
|
||||
|
||||
offset += mem_index;
|
||||
if (offset & 0x01)
|
||||
offset--;
|
||||
@@ -1198,8 +1205,10 @@ hidpp10_onboard_profiles_parse_macro(struct hidpp10_device *device,
|
||||
hidpp_log_raw(&device->base, "*** macro starts at (0x%02x, 0x%04x) ***\n", page, offset);
|
||||
|
||||
rc = hidpp10_onboard_profiles_read_macro(device, page, offset, ¯o);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
hidpp_log_raw(&device->base, "hidpp10: failed to read macro\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
count = rc;
|
||||
|
||||
@@ -2754,12 +2763,14 @@ hidpp10_get_device_info(struct hidpp10_device *dev)
|
||||
return hidpp10_get_current_profile(dev, ¤t_profile);
|
||||
}
|
||||
|
||||
struct hidpp10_device*
|
||||
int
|
||||
hidpp10_device_new(const struct hidpp_device *base,
|
||||
int idx,
|
||||
enum hidpp10_profile_type type,
|
||||
unsigned int profile_count)
|
||||
unsigned int profile_count,
|
||||
struct hidpp10_device **out)
|
||||
{
|
||||
int rc;
|
||||
struct hidpp10_device *dev;
|
||||
|
||||
dev = zalloc(sizeof(*dev));
|
||||
@@ -2770,12 +2781,14 @@ hidpp10_device_new(const struct hidpp_device *base,
|
||||
dev->profile_count = profile_count;
|
||||
dev->profiles = zalloc(dev->profile_count * sizeof(struct hidpp10_profile));
|
||||
|
||||
if (hidpp10_get_device_info(dev) != 0) {
|
||||
if ((rc = hidpp10_get_device_info(dev)) != 0) {
|
||||
hidpp10_device_destroy(dev);
|
||||
dev = NULL;
|
||||
}
|
||||
|
||||
return dev;
|
||||
*out = dev;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -69,11 +69,12 @@ struct hidpp10_device {
|
||||
unsigned int profile_count;
|
||||
};
|
||||
|
||||
struct hidpp10_device*
|
||||
int
|
||||
hidpp10_device_new(const struct hidpp_device *base,
|
||||
int idx,
|
||||
enum hidpp10_profile_type type,
|
||||
unsigned int profile_count);
|
||||
unsigned int profile_count,
|
||||
struct hidpp10_device **out);
|
||||
|
||||
int
|
||||
hidpp10_device_read_profiles(struct hidpp10_device *dev);
|
||||
|
||||
252
src/hidpp20.c
252
src/hidpp20.c
@@ -58,6 +58,7 @@ hidpp20_feature_get_name(uint16_t feature)
|
||||
CASE_RETURN_STRING(HIDPP_PAGE_RESET);
|
||||
CASE_RETURN_STRING(HIDPP_PAGE_BATTERY_LEVEL_STATUS);
|
||||
CASE_RETURN_STRING(HIDPP_PAGE_BATTERY_VOLTAGE);
|
||||
CASE_RETURN_STRING(HIDPP_PAGE_LED_SW_CONTROL);
|
||||
CASE_RETURN_STRING(HIDPP_PAGE_KBD_REPROGRAMMABLE_KEYS);
|
||||
CASE_RETURN_STRING(HIDPP_PAGE_SPECIAL_KEYS_BUTTONS);
|
||||
CASE_RETURN_STRING(HIDPP_PAGE_WIRELESS_DEVICE_STATUS);
|
||||
@@ -260,7 +261,7 @@ hidpp_root_get_feature(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = HIDPP_PAGE_ROOT_IDX,
|
||||
.msg.address = CMD_ROOT_GET_FEATURE,
|
||||
@@ -287,7 +288,7 @@ hidpp20_root_get_protocol_version(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = HIDPP_PAGE_ROOT_IDX,
|
||||
.msg.address = CMD_ROOT_GET_PROTOCOL_VERSION,
|
||||
@@ -321,7 +322,7 @@ hidpp20_feature_set_get_count(struct hidpp20_device *device, uint8_t reg)
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_FEATURE_SET_GET_COUNT,
|
||||
@@ -343,7 +344,7 @@ hidpp20_feature_set_get_feature_id(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_FEATURE_SET_GET_FEATURE_ID,
|
||||
@@ -429,7 +430,7 @@ hidpp20_batterylevel_get_battery_level(struct hidpp20_device *device,
|
||||
{
|
||||
uint8_t feature_index;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_BATTERY_LEVEL_STATUS_GET_BATTERY_LEVEL_STATUS,
|
||||
};
|
||||
@@ -566,7 +567,7 @@ int hidpp20_led_sw_control_get_led_count(struct hidpp20_device* device)
|
||||
{
|
||||
union hidpp20_message msg = {
|
||||
.msg = {
|
||||
.report_id = REPORT_ID_LONG,
|
||||
.report_id = REPORT_ID_SHORT,
|
||||
.address = CMD_LED_SW_CONTROL_GET_LED_COUNT,
|
||||
.device_idx = device->index,
|
||||
},
|
||||
@@ -594,7 +595,7 @@ int hidpp20_led_sw_control_get_led_info(struct hidpp20_device* device,
|
||||
{
|
||||
union hidpp20_message msg = {
|
||||
.msg = {
|
||||
.report_id = REPORT_ID_LONG,
|
||||
.report_id = REPORT_ID_SHORT,
|
||||
.address = CMD_LED_SW_CONTROL_GET_LED_INFO,
|
||||
.device_idx = device->index,
|
||||
},
|
||||
@@ -682,7 +683,7 @@ int hidpp20_led_sw_control_get_led_state(struct hidpp20_device* device,
|
||||
uint8_t feature_idx;
|
||||
union hidpp20_message msg = {
|
||||
.msg = {
|
||||
.report_id = REPORT_ID_LONG,
|
||||
.report_id = REPORT_ID_SHORT,
|
||||
.address = CMD_LED_SW_CONTROL_GET_LED_STATE,
|
||||
.device_idx = device->index,
|
||||
}
|
||||
@@ -767,7 +768,7 @@ static int
|
||||
hidpp20_kbd_reprogrammable_keys_get_count(struct hidpp20_device *device, uint8_t reg)
|
||||
{
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_KBD_REPROGRAMMABLE_KEYS_GET_COUNT,
|
||||
@@ -788,7 +789,7 @@ hidpp20_kbd_reprogrammable_keys_get_info(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_KBD_REPROGRAMMABLE_KEYS_GET_CTRL_ID_INFO,
|
||||
@@ -868,6 +869,8 @@ err:
|
||||
#define CMD_COLOR_LED_EFFECTS_GET_INFO 0x00
|
||||
#define CMD_COLOR_LED_EFFECTS_GET_ZONE_INFO 0x10
|
||||
#define CMD_COLOR_LED_EFFECTS_GET_ZONE_EFFECT_INFO 0x20
|
||||
#define CMD_COLOR_LED_EFFECTS_SET_ZONE_EFFECT 0x30
|
||||
#define CMD_COLOR_LED_EFFECTS_GET_ZONE_EFFECT 0xe0
|
||||
|
||||
int
|
||||
hidpp20_color_led_effects_get_info(struct hidpp20_device *device,
|
||||
@@ -893,6 +896,7 @@ hidpp20_color_led_effects_get_info(struct hidpp20_device *device,
|
||||
return rc;
|
||||
|
||||
*info = *(struct hidpp20_color_led_info *)msg.msg.parameters;
|
||||
device->led_ext_caps = info->ext_caps;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -905,7 +909,7 @@ hidpp20_color_led_effects_get_zone_info(struct hidpp20_device *device,
|
||||
int rc;
|
||||
struct hidpp20_color_led_zone_info *msg_info;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_COLOR_LED_EFFECTS_GET_ZONE_INFO,
|
||||
@@ -1012,6 +1016,80 @@ hidpp20_color_led_effect_get_zone_effect_info(struct hidpp20_device *device,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
hidpp20_color_led_effects_set_zone_effect(struct hidpp20_device *device,
|
||||
uint8_t zone_index,
|
||||
struct hidpp20_led led)
|
||||
{
|
||||
uint8_t feature_index;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.address = CMD_COLOR_LED_EFFECTS_SET_ZONE_EFFECT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.parameters[0] = zone_index,
|
||||
.msg.parameters[12] = 1, /* write to RAM and flash */
|
||||
};
|
||||
int rc;
|
||||
struct hidpp20_internal_led *internal_led = (struct hidpp20_internal_led*) &msg.msg.parameters[1];
|
||||
|
||||
hidpp20_onboard_profiles_write_led(internal_led, &led);
|
||||
|
||||
feature_index = hidpp_root_get_feature_idx(device,
|
||||
HIDPP_PAGE_COLOR_LED_EFFECTS);
|
||||
if (feature_index == 0)
|
||||
return -ENOTSUP;
|
||||
|
||||
msg.msg.sub_id = feature_index;
|
||||
|
||||
rc = hidpp20_request_command(device, &msg);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
hidpp20_color_led_effects_get_zone_effect(struct hidpp20_device *device,
|
||||
uint8_t zone_index,
|
||||
struct hidpp20_led *led)
|
||||
{
|
||||
uint8_t feature_index;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.address = CMD_COLOR_LED_EFFECTS_GET_ZONE_EFFECT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.parameters[0] = zone_index,
|
||||
};
|
||||
struct hidpp20_internal_led *internal_led;
|
||||
int rc;
|
||||
|
||||
/* hidpp20_color_led_effects_get_info() must be called first to set the capabilities */
|
||||
if (!(device->led_ext_caps & HIDPP20_COLOR_LED_INFO_EXT_CAP_HAS_ZONE_EFFECT))
|
||||
return -ENOTSUP;
|
||||
|
||||
feature_index = hidpp_root_get_feature_idx(device,
|
||||
HIDPP_PAGE_COLOR_LED_EFFECTS);
|
||||
if (feature_index == 0)
|
||||
return -ENOTSUP;
|
||||
|
||||
msg.msg.sub_id = feature_index;
|
||||
|
||||
rc = hidpp20_request_command(device, &msg);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
if (msg.msg.parameters[0] != zone_index)
|
||||
return -EPROTO;
|
||||
|
||||
internal_led = (struct hidpp20_internal_led*) &msg.msg.parameters[1];
|
||||
|
||||
hidpp20_onboard_profiles_read_led(led, *internal_led);
|
||||
|
||||
hidpp_log_debug(&device->base, "zone %u has effect %u\n", zone_index, led->mode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 0x8071: RGB Effects */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -1032,7 +1110,7 @@ hidpp20_rgb_effects_get_device_info(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_RGB_EFFECTS_GET_INFO,
|
||||
.msg.parameters[0] = HIDPP20_RGB_EFFECTS_INDEX_ALL,
|
||||
@@ -1069,7 +1147,7 @@ hidpp20_rgb_effects_get_cluster_info(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_RGB_EFFECTS_GET_INFO,
|
||||
.msg.parameters[0] = cluster_index,
|
||||
@@ -1152,7 +1230,7 @@ hidpp20_rgb_effects_get_effect_info(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_RGB_EFFECTS_GET_INFO,
|
||||
.msg.parameters[0] = cluster_index,
|
||||
@@ -1196,7 +1274,7 @@ hidpp20_special_keys_buttons_get_count(struct hidpp20_device *device, uint8_t re
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_SPECIAL_KEYS_BUTTONS_GET_COUNT,
|
||||
@@ -1216,7 +1294,7 @@ hidpp20_special_keys_buttons_get_info(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_SPECIAL_KEYS_BUTTONS_GET_INFO,
|
||||
@@ -1246,7 +1324,7 @@ hidpp20_special_keys_buttons_get_reporting(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_SPECIAL_KEYS_BUTTONS_GET_REPORTING,
|
||||
@@ -1387,7 +1465,7 @@ hidpp20_mousepointer_get_mousepointer_info(struct hidpp20_device *device,
|
||||
{
|
||||
uint8_t feature_index;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_MOUSE_POINTER_BASIC_GET_INFO,
|
||||
};
|
||||
@@ -1424,7 +1502,7 @@ hidpp20_adjustable_dpi_get_count(struct hidpp20_device *device, uint8_t reg)
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_ADJUSTABLE_DPI_GET_SENSOR_COUNT,
|
||||
@@ -1445,7 +1523,7 @@ hidpp20_adjustable_dpi_get_dpi_list(struct hidpp20_device *device,
|
||||
int rc;
|
||||
unsigned i = 1, dpi_index = 0;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_ADJUSTABLE_DPI_GET_SENSOR_DPI_LIST,
|
||||
@@ -1493,7 +1571,7 @@ hidpp20_adjustable_dpi_get_dpi(struct hidpp20_device *device,
|
||||
{
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.sub_id = reg,
|
||||
.msg.address = CMD_ADJUSTABLE_DPI_GET_SENSOR_DPI,
|
||||
@@ -1576,7 +1654,7 @@ int hidpp20_adjustable_dpi_set_sensor_dpi(struct hidpp20_device *device,
|
||||
uint16_t returned_parameters;
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_ADJUSTABLE_DPI_SET_SENSOR_DPI,
|
||||
.msg.parameters[0] = sensor->index,
|
||||
@@ -1612,6 +1690,8 @@ int hidpp20_adjustable_dpi_set_sensor_dpi(struct hidpp20_device *device,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#define CMD_ADJUSTABLE_REPORT_RATE_GET_REPORT_RATE_LIST 0x00
|
||||
#define CMD_ADJUSTABLE_REPORT_RATE_GET_REPORT_RATE 0x10
|
||||
#define CMD_ADJUSTABLE_REPORT_RATE_SET_REPORT_RATE 0x20
|
||||
|
||||
int hidpp20_adjustable_report_rate_get_report_rate_list(struct hidpp20_device *device,
|
||||
uint8_t *bitflags_ms)
|
||||
@@ -1619,10 +1699,9 @@ int hidpp20_adjustable_report_rate_get_report_rate_list(struct hidpp20_device *d
|
||||
uint8_t feature_index;
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_LONG,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_ADJUSTABLE_REPORT_RATE_GET_REPORT_RATE_LIST,
|
||||
.msg.parameters[0] = 0,
|
||||
};
|
||||
|
||||
feature_index = hidpp_root_get_feature_idx(device,
|
||||
@@ -1641,6 +1720,60 @@ int hidpp20_adjustable_report_rate_get_report_rate_list(struct hidpp20_device *d
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hidpp20_adjustable_report_rate_get_report_rate(struct hidpp20_device *device,
|
||||
uint8_t *rate_ms)
|
||||
{
|
||||
uint8_t feature_index;
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_ADJUSTABLE_REPORT_RATE_GET_REPORT_RATE,
|
||||
.msg.parameters[0] = 0,
|
||||
};
|
||||
|
||||
feature_index = hidpp_root_get_feature_idx(device,
|
||||
HIDPP_PAGE_ADJUSTABLE_REPORT_RATE);
|
||||
if (feature_index == 0)
|
||||
return -ENOTSUP;
|
||||
|
||||
msg.msg.sub_id = feature_index;
|
||||
|
||||
rc = hidpp20_request_command(device, &msg);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
*rate_ms = msg.msg.parameters[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hidpp20_adjustable_report_rate_set_report_rate(struct hidpp20_device *device,
|
||||
uint8_t rate_ms)
|
||||
{
|
||||
uint8_t feature_index;
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_ADJUSTABLE_REPORT_RATE_SET_REPORT_RATE,
|
||||
.msg.parameters[0] = rate_ms,
|
||||
};
|
||||
|
||||
feature_index = hidpp_root_get_feature_idx(device,
|
||||
HIDPP_PAGE_ADJUSTABLE_REPORT_RATE);
|
||||
if (feature_index == 0)
|
||||
return -ENOTSUP;
|
||||
|
||||
msg.msg.sub_id = feature_index;
|
||||
|
||||
rc = hidpp20_request_command(device, &msg);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 0x8100 - Onboard Profiles */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -1950,7 +2083,7 @@ hidpp20_onboard_profiles_set_onboard_mode(struct hidpp20_device *device,
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
.msg.device_idx = device->index,
|
||||
.msg.address = CMD_ONBOARD_PROFILES_SET_ONBOARD_MODE,
|
||||
.msg.parameters[1] = onboard_mode,
|
||||
.msg.parameters[0] = onboard_mode,
|
||||
};
|
||||
|
||||
feature_index = hidpp_root_get_feature_idx(device,
|
||||
@@ -1970,7 +2103,7 @@ hidpp20_onboard_profiles_set_onboard_mode(struct hidpp20_device *device,
|
||||
int
|
||||
hidpp20_onboard_profiles_get_current_profile(struct hidpp20_device *device)
|
||||
{
|
||||
uint8_t feature_index;
|
||||
uint8_t feature_index, unknown_0, active_profile_index;
|
||||
int rc;
|
||||
union hidpp20_message msg = {
|
||||
.msg.report_id = REPORT_ID_SHORT,
|
||||
@@ -1989,7 +2122,15 @@ hidpp20_onboard_profiles_get_current_profile(struct hidpp20_device *device)
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return msg.msg.parameters[1];
|
||||
unknown_0 = msg.msg.parameters[0];
|
||||
active_profile_index = msg.msg.parameters[1];
|
||||
|
||||
hidpp_log_raw(
|
||||
&device->base,
|
||||
"current active profile is index: %d unknown_0: %d\n",
|
||||
active_profile_index, unknown_0);
|
||||
|
||||
return active_profile_index;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -2111,8 +2252,7 @@ hidpp20_onboard_profiles_allocate(struct hidpp20_device *device,
|
||||
{
|
||||
struct hidpp20_onboard_profiles_info info = { 0 };
|
||||
struct hidpp20_profiles *profiles;
|
||||
int onboard_mode;
|
||||
int rc;
|
||||
int onboard_mode, active_profile_index, rc;
|
||||
|
||||
rc = hidpp20_onboard_profiles_get_profiles_desc(device, &info);
|
||||
if (rc)
|
||||
@@ -2136,6 +2276,12 @@ hidpp20_onboard_profiles_allocate(struct hidpp20_device *device,
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = hidpp20_onboard_profiles_get_current_profile(device);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
active_profile_index = rc;
|
||||
|
||||
profiles = zalloc(sizeof(struct hidpp20_profiles));
|
||||
profiles->profiles = zalloc(info.profile_count * sizeof(struct hidpp20_profile));
|
||||
profiles->sector_size = info.sector_size;
|
||||
@@ -2147,6 +2293,7 @@ hidpp20_onboard_profiles_allocate(struct hidpp20_device *device,
|
||||
profiles->num_leds = HIDPP20_LED_COUNT;
|
||||
profiles->has_g_shift = (info.mechanical_layout & 0x03) == 0x02;
|
||||
profiles->has_dpi_shift = ((info.mechanical_layout & 0x0c) >> 2) == 0x02;
|
||||
profiles->active_profile_index = active_profile_index;
|
||||
switch(info.various_info & 0x07) {
|
||||
case 1:
|
||||
profiles->corded = 1;
|
||||
@@ -2399,6 +2546,9 @@ hidpp20_onboard_profiles_write_dict(struct hidpp20_device *device,
|
||||
sector_size,
|
||||
data,
|
||||
true);
|
||||
if (rc)
|
||||
hidpp_log_error(&device->base, "failed to write profile dictionary\n");
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2436,6 +2586,7 @@ hidpp20_buttons_to_cpu(struct hidpp20_device *device,
|
||||
break;
|
||||
case HIDPP20_BUTTON_SPECIAL:
|
||||
button->special.special = b->special.special;
|
||||
button->special.profile = b->special.profile;
|
||||
break;
|
||||
case HIDPP20_BUTTON_MACRO:
|
||||
if (profile->macros[i]) {
|
||||
@@ -2456,6 +2607,7 @@ hidpp20_buttons_to_cpu(struct hidpp20_device *device,
|
||||
case HIDPP20_BUTTON_DISABLED:
|
||||
break;
|
||||
default:
|
||||
memcpy(b, button, sizeof(*b));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2495,6 +2647,7 @@ hidpp20_buttons_from_cpu(struct hidpp20_profile *profile,
|
||||
break;
|
||||
case HIDPP20_BUTTON_SPECIAL:
|
||||
button->special.special = b->special.special;
|
||||
button->special.profile = b->special.profile;
|
||||
break;
|
||||
case HIDPP20_BUTTON_DISABLED:
|
||||
break;
|
||||
@@ -2505,12 +2658,13 @@ hidpp20_buttons_from_cpu(struct hidpp20_profile *profile,
|
||||
button->macro.zero = 0;
|
||||
break;
|
||||
default:
|
||||
memcpy(b, button, sizeof(*b));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
hidpp20_onboard_profiles_read_led(struct hidpp20_led *led,
|
||||
struct hidpp20_internal_led internal_led)
|
||||
{
|
||||
@@ -2526,6 +2680,10 @@ hidpp20_onboard_profiles_read_led(struct hidpp20_led *led,
|
||||
if (brightness == 0)
|
||||
brightness = 100;
|
||||
break;
|
||||
case HIDPP20_LED_STARLIGHT:
|
||||
led->color = internal_led.effect.starlight.color_sky;
|
||||
led->extra_color = internal_led.effect.starlight.color_star;
|
||||
break;
|
||||
case HIDPP20_LED_BREATHING:
|
||||
period = hidpp_be_u16_to_cpu(internal_led.effect.breath.period_or_speed);
|
||||
brightness = internal_led.effect.breath.intensity;
|
||||
@@ -2533,11 +2691,18 @@ hidpp20_onboard_profiles_read_led(struct hidpp20_led *led,
|
||||
brightness = 100;
|
||||
led->color = internal_led.effect.breath.color;
|
||||
break;
|
||||
case HIDPP20_LED_RIPPLE:
|
||||
period = hidpp_be_u16_to_cpu(internal_led.effect.breath.period_or_speed);
|
||||
led->color = internal_led.effect.ripple.color;
|
||||
break;
|
||||
case HIDPP20_LED_ON:
|
||||
led->color = internal_led.effect.fixed.color;
|
||||
break;
|
||||
case HIDPP20_LED_OFF:
|
||||
break;
|
||||
default:
|
||||
memcpy(led->original, &internal_led, sizeof(internal_led));
|
||||
break;
|
||||
}
|
||||
|
||||
led->period = period;
|
||||
@@ -2713,7 +2878,7 @@ read_profiles:
|
||||
return profiles->num_profiles;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
hidpp20_onboard_profiles_write_led(struct hidpp20_internal_led *internal_led,
|
||||
struct hidpp20_led *led)
|
||||
{
|
||||
@@ -2732,24 +2897,31 @@ hidpp20_onboard_profiles_write_led(struct hidpp20_internal_led *internal_led,
|
||||
else
|
||||
internal_led->effect.cycle.intensity = 0;
|
||||
break;
|
||||
case HIDPP20_LED_STARLIGHT:
|
||||
internal_led->effect.starlight.color_sky = led->color;
|
||||
internal_led->effect.starlight.color_star = led->extra_color;
|
||||
break;
|
||||
case HIDPP20_LED_BREATHING:
|
||||
internal_led->effect.breath.color.red = led->color.red;
|
||||
internal_led->effect.breath.color.blue = led->color.blue;
|
||||
internal_led->effect.breath.color.green = led->color.green;
|
||||
internal_led->effect.breath.color = led->color;
|
||||
internal_led->effect.breath.period_or_speed = hidpp_cpu_to_be_u16(period);
|
||||
if (brightness < 100)
|
||||
internal_led->effect.breath.intensity = brightness;
|
||||
else
|
||||
internal_led->effect.breath.intensity = 0;
|
||||
break;
|
||||
case HIDPP20_LED_RIPPLE:
|
||||
internal_led->effect.ripple.color = led->color;
|
||||
internal_led->effect.ripple.period = hidpp_cpu_to_be_u16(period);
|
||||
break;
|
||||
case HIDPP20_LED_ON:
|
||||
internal_led->effect.fixed.color.red = led->color.red;
|
||||
internal_led->effect.fixed.color.blue = led->color.blue;
|
||||
internal_led->effect.fixed.color.green = led->color.green;
|
||||
internal_led->effect.fixed.color = led->color;
|
||||
internal_led->effect.fixed.effect = 0;
|
||||
break;
|
||||
case HIDPP20_LED_OFF:
|
||||
break;
|
||||
default:
|
||||
memcpy(internal_led, led->original, sizeof(*internal_led));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2797,8 +2969,10 @@ hidpp20_onboard_profiles_write_profile(struct hidpp20_device *device,
|
||||
memcpy(pdata->profile.name.txt, profile->name, sizeof(profile->name));
|
||||
|
||||
rc = hidpp20_onboard_profiles_write_sector(device, sector, sector_size, data, true);
|
||||
if (rc < 0)
|
||||
if (rc < 0) {
|
||||
hidpp_log_error(&device->base, "failed to write profile\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2894,6 +3068,8 @@ hidpp20_device_new(const struct hidpp_device *base, unsigned int idx, struct hid
|
||||
dev->proto_major = 1;
|
||||
dev->proto_minor = 0;
|
||||
|
||||
dev->led_ext_caps = 0;
|
||||
|
||||
hidpp_get_supported_report_types(&(dev->base), reports, num_reports);
|
||||
|
||||
if (!(dev->base.supported_report_types & HIDPP_REPORT_SHORT) &&
|
||||
|
||||
119
src/hidpp20.h
119
src/hidpp20.h
@@ -65,6 +65,7 @@ struct hidpp20_device {
|
||||
unsigned feature_count;
|
||||
struct hidpp20_feature *feature_list;
|
||||
enum hidpp20_quirk quirk;
|
||||
unsigned int led_ext_caps;
|
||||
};
|
||||
|
||||
int hidpp20_request_command(struct hidpp20_device *dev, union hidpp20_message *msg);
|
||||
@@ -209,21 +210,21 @@ struct hidpp20_led_sw_ctrl_led_state {
|
||||
uint8_t index;
|
||||
uint16_t mode;
|
||||
union {
|
||||
struct {
|
||||
struct hidpp20_led_breathing {
|
||||
uint16_t brightness;
|
||||
uint16_t period;
|
||||
uint16_t timeout;
|
||||
} breathing;
|
||||
struct {
|
||||
struct hidpp20_led_traveling {
|
||||
uint16_t unused;
|
||||
uint16_t delay;
|
||||
} traveling;
|
||||
struct {
|
||||
struct hidpp20_led_blink {
|
||||
uint16_t index;
|
||||
uint16_t on_time;
|
||||
uint16_t off_time;
|
||||
} blink;
|
||||
struct {
|
||||
struct hidpp20_led_on {
|
||||
/* Logical information to display on the LED
|
||||
* Meaning and value range depend on the LED
|
||||
*/
|
||||
@@ -432,6 +433,12 @@ int hidpp20_adjustable_dpi_set_sensor_dpi(struct hidpp20_device *device,
|
||||
int hidpp20_adjustable_report_rate_get_report_rate_list(struct hidpp20_device *device,
|
||||
uint8_t *bitflags_ms);
|
||||
|
||||
int hidpp20_adjustable_report_rate_get_report_rate(struct hidpp20_device *device,
|
||||
uint8_t *rate_ms);
|
||||
|
||||
int hidpp20_adjustable_report_rate_set_report_rate(struct hidpp20_device *device,
|
||||
uint8_t rate_ms);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 0x8070v4 - Color LED effects */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -495,6 +502,18 @@ hidpp20_rgb_effects_get_effect_info(struct hidpp20_device *device,
|
||||
uint8_t effect_index,
|
||||
struct hidpp20_rgb_effect_info *info);
|
||||
|
||||
struct hidpp20_led;
|
||||
|
||||
int
|
||||
hidpp20_color_led_effects_set_zone_effect(struct hidpp20_device *device,
|
||||
uint8_t zone_index,
|
||||
struct hidpp20_led led);
|
||||
|
||||
int
|
||||
hidpp20_color_led_effects_get_zone_effect(struct hidpp20_device *device,
|
||||
uint8_t zone_index,
|
||||
struct hidpp20_led *led);
|
||||
|
||||
enum hidpp20_color_led_location {
|
||||
HIDPP20_COLOR_LED_LOCATION_UNDEFINED = 0,
|
||||
HIDPP20_COLOR_LED_LOCATION_PRIMARY,
|
||||
@@ -558,14 +577,42 @@ enum hidpp20_color_led_zone_effect {
|
||||
|
||||
#define HIDPP_PAGE_ONBOARD_PROFILES 0x8100
|
||||
|
||||
/* type */
|
||||
#define HIDPP20_BUTTON_HID_TYPE 0x80
|
||||
#define HIDPP20_BUTTON_SPECIAL 0x90
|
||||
|
||||
/* standard opcodes (0x80) */
|
||||
#define HIDPP20_BUTTON_HID_TYPE_NOOP 0x00
|
||||
#define HIDPP20_BUTTON_HID_TYPE_MOUSE 0x01
|
||||
#define HIDPP20_BUTTON_HID_TYPE_KEYBOARD 0x02
|
||||
#define HIDPP20_BUTTON_HID_TYPE_CONSUMER_CONTROL 0x03
|
||||
#define HIDPP20_BUTTON_SPECIAL 0x90
|
||||
|
||||
/* special opcodes (0x90) */
|
||||
#define HIDPP20_BUTTON_SPECIAL_NOOP 0x00
|
||||
#define HIDPP20_BUTTON_SPECIAL_TILT_LEFT 0x01
|
||||
#define HIDPP20_BUTTON_SPECIAL_TILT_RIGHT 0x02
|
||||
#define HIDPP20_BUTTON_SPECIAL_NEXT_DPI 0x03
|
||||
#define HIDPP20_BUTTON_SPECIAL_PREV_DPI 0x04
|
||||
#define HIDPP20_BUTTON_SPECIAL_CYCLE_DPI 0x05
|
||||
#define HIDPP20_BUTTON_SPECIAL_DEFAULT_DPI 0x06
|
||||
#define HIDPP20_BUTTON_SPECIAL_SHIFT_DPI 0x07
|
||||
#define HIDPP20_BUTTON_SPECIAL_NEXT_PROFILE 0x08
|
||||
#define HIDPP20_BUTTON_SPECIAL_PREV_PROFILE 0x09
|
||||
#define HIDPP20_BUTTON_SPECIAL_CYCLE_PROFILE 0x0a
|
||||
#define HIDPP20_BUTTON_SPECIAL_GSHIFT 0x0b
|
||||
/* memory model >= 3 */
|
||||
#define HIDPP20_BUTTON_SPECIAL_BATTERY_INDICATOR 0x0c
|
||||
#define HIDPP20_BUTTON_SPECIAL_ENABLE_PROFILE 0x0d
|
||||
#define HIDPP20_BUTTON_SPECIAL_PERFORMANCE_SWITCH 0x0e
|
||||
#define HIDPP20_BUTTON_SPECIAL_HOST 0x0f
|
||||
#define HIDPP20_BUTTON_SPECIAL_SCROLL_DOWN 0x10
|
||||
#define HIDPP20_BUTTON_SPECIAL_SCROLL_UP 0x11
|
||||
|
||||
/* buttons */
|
||||
#define HIDPP20_BUTTON_MACRO 0x00
|
||||
#define HIDPP20_BUTTON_DISABLED 0xFF
|
||||
|
||||
/* modifiers */
|
||||
#define HIDPP20_MODIFIER_KEY_CTRL 0x01
|
||||
#define HIDPP20_MODIFIER_KEY_SHIFT 0x02
|
||||
|
||||
@@ -599,6 +646,8 @@ union hidpp20_button_binding {
|
||||
struct {
|
||||
uint8_t type; /* HIDPP20_BUTTON_SPECIAL */
|
||||
uint8_t special;
|
||||
uint8_t reserved;
|
||||
uint8_t profile;
|
||||
} __attribute__((packed)) special;
|
||||
struct {
|
||||
uint8_t type; /* HIDPP20_BUTTON_MACRO */
|
||||
@@ -698,7 +747,11 @@ enum hidpp20_led_mode {
|
||||
HIDPP20_LED_OFF = 0x00,
|
||||
HIDPP20_LED_ON = 0x01,
|
||||
HIDPP20_LED_CYCLE = 0x03,
|
||||
HIDPP20_LED_COLOR_WAVE = 0x04,
|
||||
HIDPP20_LED_STARLIGHT = 0x05,
|
||||
HIDPP20_LED_BREATHING = 0x0a,
|
||||
HIDPP20_LED_RIPPLE = 0x0b,
|
||||
HIDPP20_LED_CUSTOM = 0x0c,
|
||||
};
|
||||
|
||||
enum hidpp20_led_waveform {
|
||||
@@ -723,35 +776,76 @@ struct hidpp20_internal_led {
|
||||
uint16_t period_or_speed; /* period in ms, speed is device dependent */
|
||||
uint8_t intensity; /* 1 - 100 percent, 0 means 100 */
|
||||
} __attribute__((packed)) cycle;
|
||||
struct hidpp20_led_starlight {
|
||||
struct hidpp20_color color_sky;
|
||||
struct hidpp20_color color_star;
|
||||
} __attribute__((packed)) starlight;
|
||||
struct hidpp20_led_breath {
|
||||
struct hidpp20_color color;
|
||||
uint16_t period_or_speed; /* period in ms, speed is device dependent */
|
||||
uint8_t waveform; /* enum hidpp20_led_waveform */
|
||||
uint8_t intensity; /* 1 - 100 percent, 0 means 100 */
|
||||
} __attribute__((packed)) breath;
|
||||
struct hidpp20_led_ripple {
|
||||
struct hidpp20_color color;
|
||||
uint8_t reserved;
|
||||
uint16_t period;
|
||||
} __attribute__((packed)) ripple;
|
||||
struct hidpp20_led_custom {
|
||||
uint8_t slot;
|
||||
uint16_t init_frame;
|
||||
uint16_t lenght;
|
||||
uint16_t frame_period;
|
||||
uint8_t intensity;
|
||||
} __attribute__((packed)) custom;
|
||||
uint8_t padding[10];
|
||||
} __attribute__((packed)) effect;
|
||||
};
|
||||
_Static_assert(sizeof(struct hidpp20_led_fixed) == 4, "Invalid size");
|
||||
_Static_assert(sizeof(struct hidpp20_led_cycle) == 8, "Invalid size");
|
||||
_Static_assert(sizeof(struct hidpp20_led_starlight) == 6, "Invalid size");
|
||||
_Static_assert(sizeof(struct hidpp20_led_breath) == 7, "Invalid size");
|
||||
_Static_assert(sizeof(struct hidpp20_internal_led) == 11, "Invalid size");
|
||||
_Static_assert(sizeof(struct hidpp20_led_ripple) == 6, "Invalid size");
|
||||
_Static_assert(sizeof(struct hidpp20_led_custom) == 8, "Invalid size");
|
||||
|
||||
typedef uint8_t percent_t;
|
||||
|
||||
struct hidpp20_led {
|
||||
enum hidpp20_led_mode mode;
|
||||
struct hidpp20_color color;
|
||||
struct hidpp20_color extra_color;
|
||||
uint16_t period;
|
||||
percent_t brightness;
|
||||
uint8_t original[sizeof(struct hidpp20_internal_led)];
|
||||
};
|
||||
|
||||
#define HIDPP20_MACRO_NOOP 0x01
|
||||
/* macro opcodes */
|
||||
|
||||
/* control commands */
|
||||
#define HIDPP20_MACRO_WAIT_FOR_RELEASE 0x01
|
||||
#define HIDPP20_MACRO_REPEAT_WHILE_PRESSED 0x02
|
||||
#define HIDPP20_MACRO_REPEAT_UNTIL_CANCELED 0x03
|
||||
#define HIDPP20_MACRO_END 0xff
|
||||
|
||||
/* delay & jump commands */
|
||||
#define HIDPP20_MACRO_NOOP 0x00 /* wait the duration of a macro step */
|
||||
#define HIDPP20_MACRO_DELAY 0x40
|
||||
#define HIDPP20_MACRO_JUMP 0x60
|
||||
|
||||
/* button & key event generation */
|
||||
#define HIDPP20_MACRO_BUTTON_DOWN 0x41
|
||||
#define HIDPP20_MACRO_BUTTON_UP 0x42
|
||||
#define HIDPP20_MACRO_KEY_PRESS 0x43
|
||||
#define HIDPP20_MACRO_KEY_RELEASE 0x44
|
||||
#define HIDPP20_MACRO_JUMP 0x60
|
||||
#define HIDPP20_MACRO_END 0xff
|
||||
#define HIDPP20_MACRO_CONS_DOWN 0x45
|
||||
#define HIDPP20_MACRO_CONS_UP 0x46
|
||||
|
||||
/* analog commands */
|
||||
#define HIDPP20_MACRO_ROLLER 0x20
|
||||
#define HIDPP20_MACRO_ACPAN 0x21
|
||||
#define HIDPP20_MACRO_XY 0x61
|
||||
|
||||
|
||||
union hidpp20_macro_data {
|
||||
struct {
|
||||
@@ -821,6 +915,7 @@ struct hidpp20_profiles {
|
||||
uint8_t wireless;
|
||||
uint8_t sector_count;
|
||||
uint16_t sector_size;
|
||||
uint8_t active_profile_index;
|
||||
struct hidpp20_profile *profiles;
|
||||
};
|
||||
|
||||
@@ -919,6 +1014,14 @@ hidpp20_onboard_profiles_allocate_sector(struct hidpp20_profiles *profiles)
|
||||
return zalloc(profiles->sector_size);
|
||||
}
|
||||
|
||||
void
|
||||
hidpp20_onboard_profiles_read_led(struct hidpp20_led *led,
|
||||
struct hidpp20_internal_led internal_led);
|
||||
|
||||
void
|
||||
hidpp20_onboard_profiles_write_led(struct hidpp20_internal_led *internal_led,
|
||||
struct hidpp20_led *led);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 0x8110 - Mouse Button Spy */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
16
src/liblur.c
16
src/liblur.c
@@ -140,20 +140,21 @@ hidraw_is_receiver(int fd)
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct hidpp10_device *
|
||||
hidpp10_init(int fd)
|
||||
static int
|
||||
hidpp10_init(int fd, struct hidpp10_device **out)
|
||||
{
|
||||
struct hidpp_device base;
|
||||
|
||||
hidpp_device_init(&base, fd);
|
||||
|
||||
return hidpp10_device_new(&base, HIDPP_RECEIVER_IDX,
|
||||
HIDPP10_PROFILE_UNKNOWN, 1);
|
||||
HIDPP10_PROFILE_UNKNOWN, 1, out);
|
||||
}
|
||||
|
||||
_EXPORT_ int
|
||||
lur_receiver_new_from_hidraw(int fd, void *userdata, struct lur_receiver **out)
|
||||
{
|
||||
int rc;
|
||||
struct lur_receiver *receiver;
|
||||
|
||||
if (!hidraw_is_receiver(fd))
|
||||
@@ -165,8 +166,8 @@ lur_receiver_new_from_hidraw(int fd, void *userdata, struct lur_receiver **out)
|
||||
receiver->userdata = userdata;
|
||||
list_init(&receiver->devices);
|
||||
|
||||
receiver->hidppdev = hidpp10_init(fd);
|
||||
if (!receiver->hidppdev)
|
||||
rc = hidpp10_init(fd, &receiver->hidppdev);
|
||||
if (rc)
|
||||
goto error;
|
||||
|
||||
*out = receiver;
|
||||
@@ -174,8 +175,7 @@ lur_receiver_new_from_hidraw(int fd, void *userdata, struct lur_receiver **out)
|
||||
|
||||
error:
|
||||
free(receiver);
|
||||
return -errno;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
_EXPORT_ int
|
||||
@@ -203,7 +203,7 @@ lur_receiver_enumerate(struct lur_receiver *lur,
|
||||
uint32_t serial;
|
||||
bool is_new_device = true;
|
||||
|
||||
d = hidpp10_device_new(&base, i, HIDPP10_PROFILE_UNKNOWN, 1);
|
||||
rc = hidpp10_device_new(&base, i, HIDPP10_PROFILE_UNKNOWN, 1, &d);
|
||||
if (!d)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -30,10 +30,15 @@
|
||||
#include <glib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "asus.h"
|
||||
#include "driver-sinowealth.h"
|
||||
#include "driver-steelseries.h"
|
||||
#include "libratbag.h"
|
||||
#include "libratbag-private.h"
|
||||
#include "libratbag-data.h"
|
||||
#include "hidpp20.h"
|
||||
#include "shared-macro.h"
|
||||
#include "usb-ids.h"
|
||||
|
||||
#define GROUP_DEVICE "Device"
|
||||
|
||||
@@ -46,16 +51,25 @@ enum driver {
|
||||
HIDPP10,
|
||||
HIDPP20,
|
||||
ROCCAT,
|
||||
ROCCAT_KONE_PURE,
|
||||
ROCCAT_EMP,
|
||||
ETEKCITY,
|
||||
GSKILL,
|
||||
LOGITECH_G300,
|
||||
LOGITECH_G600,
|
||||
STEELSERIES,
|
||||
ASUS,
|
||||
SINOWEALTH,
|
||||
SINOWEALTH_NUBWO,
|
||||
OPENINPUT,
|
||||
};
|
||||
|
||||
struct data_hidpp20 {
|
||||
int index;
|
||||
enum hidpp20_quirk quirk;
|
||||
int led_count;
|
||||
int report_rate;
|
||||
int button_count;
|
||||
};
|
||||
|
||||
struct data_hidpp10 {
|
||||
@@ -68,6 +82,10 @@ struct data_hidpp10 {
|
||||
int led_count;
|
||||
};
|
||||
|
||||
struct data_sinowealth {
|
||||
struct list supported_devices;
|
||||
};
|
||||
|
||||
struct data_steelseries {
|
||||
int device_version;
|
||||
int button_count;
|
||||
@@ -75,8 +93,18 @@ struct data_steelseries {
|
||||
struct dpi_list *dpi_list;
|
||||
struct dpi_range *dpi_range;
|
||||
int macro_length;
|
||||
int mono_led;
|
||||
int short_button;
|
||||
enum steelseries_quirk quirk;
|
||||
};
|
||||
|
||||
struct data_asus {
|
||||
int profile_count;
|
||||
int button_count;
|
||||
int8_t button_mapping[ASUS_MAX_NUM_BUTTON];
|
||||
int led_count;
|
||||
int dpi_count;
|
||||
int is_wireless;
|
||||
struct dpi_range *dpi_range;
|
||||
uint32_t quirks;
|
||||
};
|
||||
|
||||
struct ratbag_device_data {
|
||||
@@ -89,7 +117,9 @@ struct ratbag_device_data {
|
||||
union {
|
||||
struct data_hidpp20 hidpp20;
|
||||
struct data_hidpp10 hidpp10;
|
||||
struct data_sinowealth sinowealth;
|
||||
struct data_steelseries steelseries;
|
||||
struct data_asus asus;
|
||||
};
|
||||
|
||||
enum ratbag_led_type led_types[20];
|
||||
@@ -156,14 +186,38 @@ init_data_hidpp20(struct ratbag *ratbag,
|
||||
int num;
|
||||
char *str;
|
||||
|
||||
data->hidpp20.button_count = -1;
|
||||
data->hidpp20.index = -1;
|
||||
data->hidpp20.led_count = -1;
|
||||
data->hidpp20.report_rate = -1;
|
||||
|
||||
num = g_key_file_get_integer(keyfile, group, "Buttons", &error);
|
||||
if (num > 0 || !error)
|
||||
data->hidpp20.button_count = num;
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
|
||||
error = NULL;
|
||||
num = g_key_file_get_integer(keyfile, group, "DeviceIndex", &error);
|
||||
if (num != 0 || !error)
|
||||
data->hidpp20.index = num;
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
|
||||
error = NULL;
|
||||
num = g_key_file_get_integer(keyfile, group, "Leds", &error);
|
||||
if (!error)
|
||||
data->hidpp20.led_count = num;
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
|
||||
error = NULL;
|
||||
num = g_key_file_get_integer(keyfile, group, "ReportRate", &error);
|
||||
if (num > 0 || !error)
|
||||
data->hidpp20.report_rate = num;
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
|
||||
str = g_key_file_get_string(keyfile, group, "Quirk", NULL);
|
||||
data->hidpp20.quirk = HIDPP20_QUIRK_NONE;
|
||||
if (str) {
|
||||
@@ -174,6 +228,56 @@ init_data_hidpp20(struct ratbag *ratbag,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_data_sinowealth(struct ratbag *ratbag,
|
||||
GKeyFile *keyfile,
|
||||
struct ratbag_device_data *data)
|
||||
{
|
||||
const char *devices_group = "Driver/sinowealth/devices/";
|
||||
|
||||
GError *error = NULL;
|
||||
|
||||
size_t group_count = 0;
|
||||
_cleanup_(g_strfreevp) char **groups = g_key_file_get_groups(keyfile, &group_count);
|
||||
|
||||
list_init(&data->sinowealth.supported_devices);
|
||||
|
||||
for (size_t i = 0; i < group_count; ++i) {
|
||||
const char *device_group = groups[i];
|
||||
if (startswith(device_group, devices_group) == NULL)
|
||||
continue;
|
||||
|
||||
struct sinowealth_device_data *device = zalloc(sizeof(struct sinowealth_device_data));
|
||||
|
||||
device->button_count = g_key_file_get_integer(keyfile, device_group, "ButtonCount", &error);
|
||||
g_clear_error(&error);
|
||||
|
||||
device->device_name = g_key_file_get_string(keyfile, device_group, "DeviceName", &error);
|
||||
g_clear_error(&error);
|
||||
|
||||
device->fw_version = g_key_file_get_string(keyfile, device_group, "FwVersion", &error);
|
||||
g_clear_error(&error);
|
||||
|
||||
_cleanup_free_ char *led_type_str = g_key_file_get_string(keyfile, device_group, "LedType", &error);
|
||||
if (led_type_str) {
|
||||
if (streq(led_type_str, "RGB")) {
|
||||
device->led_type = SINOWEALTH_LED_TYPE_RGB;
|
||||
} else if (streq(led_type_str, "RBG")) {
|
||||
device->led_type = SINOWEALTH_LED_TYPE_RBG;
|
||||
} else if (streq(led_type_str, "None")) {
|
||||
device->led_type = SINOWEALTH_LED_TYPE_NONE;
|
||||
} else {
|
||||
log_error(ratbag, "Unknown LED type '%s' in group '%s'\n", led_type_str, device_group);
|
||||
|
||||
device->led_type = SINOWEALTH_LED_TYPE_NONE;
|
||||
}
|
||||
}
|
||||
g_clear_error(&error);
|
||||
|
||||
list_insert(&data->sinowealth.supported_devices, &device->link);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_data_steelseries(struct ratbag *ratbag,
|
||||
GKeyFile *keyfile,
|
||||
@@ -181,7 +285,8 @@ init_data_steelseries(struct ratbag *ratbag,
|
||||
{
|
||||
const char *group = "Driver/steelseries";
|
||||
GError *error = NULL;
|
||||
_cleanup_(freep) char *str = NULL;
|
||||
_cleanup_(freep) char *dpi_range = NULL;
|
||||
_cleanup_(freep) char *quirk = NULL;
|
||||
int num;
|
||||
|
||||
data->steelseries.device_version = -1;
|
||||
@@ -189,8 +294,7 @@ init_data_steelseries(struct ratbag *ratbag,
|
||||
data->steelseries.led_count = -1;
|
||||
data->steelseries.dpi_list = NULL;
|
||||
data->steelseries.dpi_range = NULL;
|
||||
data->steelseries.mono_led = 0;
|
||||
data->steelseries.short_button = 0;
|
||||
data->steelseries.quirk = STEELSERIES_QURIK_NONE;
|
||||
|
||||
num = g_key_file_get_integer(keyfile, group, "Buttons", &error);
|
||||
if (num != 0 || !error)
|
||||
@@ -212,13 +316,13 @@ init_data_steelseries(struct ratbag *ratbag,
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
|
||||
str = g_key_file_get_string(keyfile, group, "DpiRange", NULL);
|
||||
if (str) {
|
||||
data->steelseries.dpi_range = dpi_range_from_string(str);
|
||||
dpi_range = g_key_file_get_string(keyfile, group, "DpiRange", NULL);
|
||||
if (dpi_range) {
|
||||
data->steelseries.dpi_range = dpi_range_from_string(dpi_range);
|
||||
} else {
|
||||
str = g_key_file_get_string(keyfile, group, "DpiList", NULL);
|
||||
if (str)
|
||||
data->steelseries.dpi_list = dpi_list_from_string(str);
|
||||
dpi_range = g_key_file_get_string(keyfile, group, "DpiList", NULL);
|
||||
if (dpi_range)
|
||||
data->steelseries.dpi_list = dpi_list_from_string(dpi_range);
|
||||
}
|
||||
|
||||
error = NULL;
|
||||
@@ -228,19 +332,86 @@ init_data_steelseries(struct ratbag *ratbag,
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
|
||||
error = NULL;
|
||||
num = g_key_file_get_integer(keyfile, group, "MonoLed", &error);
|
||||
if (num > 0 || !error)
|
||||
data->steelseries.mono_led = num;
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
quirk = g_key_file_get_string(keyfile, group, "Quirk", NULL);
|
||||
if (quirk) {
|
||||
if (streq(quirk, "Rival100"))
|
||||
data->steelseries.quirk = STEELSERIES_QUIRK_RIVAL100;
|
||||
if (streq(quirk, "SenseiRAW"))
|
||||
data->steelseries.quirk = STEELSERIES_QUIRK_SENSEIRAW;
|
||||
}
|
||||
}
|
||||
|
||||
error = NULL;
|
||||
num = g_key_file_get_integer(keyfile, group, "ShortButton", &error);
|
||||
if (num > 0 || !error)
|
||||
data->steelseries.short_button = num;
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
static void
|
||||
init_data_asus(struct ratbag *ratbag,
|
||||
GKeyFile *keyfile,
|
||||
struct ratbag_device_data *data)
|
||||
{
|
||||
const char *group = "Driver/asus";
|
||||
GError *error = NULL;
|
||||
|
||||
data->asus.profile_count = -1;
|
||||
data->asus.button_count = -1;
|
||||
data->asus.led_count = -1;
|
||||
data->asus.dpi_count = -1;
|
||||
data->asus.dpi_range = NULL;
|
||||
data->asus.is_wireless = -1;
|
||||
data->asus.quirks = 0;
|
||||
for (unsigned int i = 0; i < ASUS_MAX_NUM_BUTTON; i++)
|
||||
data->asus.button_mapping[i] = -1;
|
||||
|
||||
int profiles = g_key_file_get_integer(keyfile, group, "Profiles", &error);
|
||||
if (!error && profiles >= 0)
|
||||
data->asus.profile_count = profiles;
|
||||
g_clear_error(&error);
|
||||
|
||||
int buttons = g_key_file_get_integer(keyfile, group, "Buttons", &error);
|
||||
if (!error && buttons >= 0 && buttons <= ASUS_MAX_NUM_BUTTON)
|
||||
data->asus.button_count = buttons;
|
||||
g_clear_error(&error);
|
||||
|
||||
gsize button_mapping_count = 0;
|
||||
_cleanup_(g_strfreevp) char **button_mapping = g_key_file_get_string_list(keyfile, group, "ButtonMapping", &button_mapping_count, &error);
|
||||
if (!error && button_mapping) {
|
||||
for (unsigned int i = 0; i < button_mapping_count; i++) {
|
||||
data->asus.button_mapping[i] = (int8_t) strtoul(button_mapping[i], NULL, 10);
|
||||
}
|
||||
}
|
||||
g_clear_error(&error);
|
||||
|
||||
int leds = g_key_file_get_integer(keyfile, group, "Leds", &error);
|
||||
if (!error && leds >= 0 && leds <= ASUS_MAX_NUM_LED)
|
||||
data->asus.led_count = leds;
|
||||
g_clear_error(&error);
|
||||
|
||||
int dpis = g_key_file_get_integer(keyfile, group, "Dpis", &error);
|
||||
if (!error && dpis >= 2 && dpis <= ASUS_MAX_NUM_DPI)
|
||||
data->asus.dpi_count = dpis;
|
||||
g_clear_error(&error);
|
||||
|
||||
_cleanup_(freep) char *dpi_range = g_key_file_get_string(keyfile, group, "DpiRange", &error);
|
||||
if (!error && dpi_range)
|
||||
data->asus.dpi_range = dpi_range_from_string(dpi_range);
|
||||
g_clear_error(&error);
|
||||
|
||||
int wireless = g_key_file_get_integer(keyfile, group, "Wireless", &error);
|
||||
if (!error && (wireless == 0 || wireless == 1))
|
||||
data->asus.is_wireless = wireless;
|
||||
g_clear_error(&error);
|
||||
|
||||
gsize quirks_count = 0;
|
||||
_cleanup_(g_strfreevp) char **quirks = g_key_file_get_string_list(keyfile, group, "Quirks", &quirks_count, &error);
|
||||
if (!error && quirks) {
|
||||
for (unsigned int i = 0; i < quirks_count; i++) {
|
||||
if (streq(quirks[i], "DOUBLE_DPI")) {
|
||||
data->asus.quirks |= ASUS_QUIRK_DOUBLE_DPI;
|
||||
} else if (streq(quirks[i], "STRIX_PROFILE")) {
|
||||
data->asus.quirks |= ASUS_QUIRK_STRIX_PROFILE;
|
||||
} else {
|
||||
log_debug(ratbag, "%s is invalid quirk. Ignoring...\n", quirks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
g_clear_error(&error);
|
||||
}
|
||||
|
||||
static const struct driver_map {
|
||||
@@ -253,11 +424,17 @@ static const struct driver_map {
|
||||
{ HIDPP10, "hidpp10", init_data_hidpp10 },
|
||||
{ HIDPP20, "hidpp20", init_data_hidpp20 },
|
||||
{ ROCCAT, "roccat", NULL },
|
||||
{ ROCCAT_KONE_PURE, "roccat-kone-pure", NULL },
|
||||
{ ROCCAT_EMP, "roccat-kone-emp", NULL },
|
||||
{ ETEKCITY, "etekcity", NULL},
|
||||
{ GSKILL, "gskill", NULL },
|
||||
{ LOGITECH_G300, "logitech_g300", NULL},
|
||||
{ LOGITECH_G600, "logitech_g600", NULL},
|
||||
{ STEELSERIES, "steelseries", init_data_steelseries },
|
||||
{ ASUS, "asus", init_data_asus },
|
||||
{ SINOWEALTH, "sinowealth", init_data_sinowealth },
|
||||
{ SINOWEALTH_NUBWO, "sinowealth_nubwo", NULL},
|
||||
{ OPENINPUT, "openinput", NULL },
|
||||
};
|
||||
|
||||
const char *
|
||||
@@ -293,8 +470,34 @@ ratbag_device_data_destroy(struct ratbag_device_data *data)
|
||||
{
|
||||
switch (data->drivertype) {
|
||||
case HIDPP10:
|
||||
if (data->hidpp10.dpi_list) {
|
||||
free(data->hidpp10.dpi_list->entries);
|
||||
free(data->hidpp10.dpi_list);
|
||||
}
|
||||
|
||||
free(data->hidpp10.dpi_range);
|
||||
free(data->hidpp10.profile_type);
|
||||
break;
|
||||
case SINOWEALTH: {
|
||||
struct sinowealth_device_data *device_data = NULL;
|
||||
struct sinowealth_device_data *device_data_next = NULL;
|
||||
|
||||
list_for_each_safe(device_data, device_data_next, &data->sinowealth.supported_devices, link) {
|
||||
free(device_data->device_name);
|
||||
free(device_data->fw_version);
|
||||
free(device_data);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case STEELSERIES:
|
||||
if (data->steelseries.dpi_list) {
|
||||
free(data->steelseries.dpi_list->entries);
|
||||
free(data->steelseries.dpi_list);
|
||||
}
|
||||
|
||||
free(data->steelseries.dpi_range);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -346,6 +549,8 @@ parse_ledtypes(char **strv, enum ratbag_led_type *types, size_t ntypes)
|
||||
types[i] = RATBAG_LED_TYPE_SIDE;
|
||||
else if (streq(s, "wheel"))
|
||||
types[i] = RATBAG_LED_TYPE_WHEEL;
|
||||
else if (streq(s, "switches"))
|
||||
types[i] = RATBAG_LED_TYPE_SWITCHES;
|
||||
else
|
||||
return -1;
|
||||
|
||||
@@ -502,7 +707,9 @@ ratbag_device_data_new_for_id(struct ratbag *ratbag, const struct input_id *id)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!data)
|
||||
if (id->vendor == USB_VENDOR_ID_LOGITECH && (id->product & 0xff00) == 0xc500)
|
||||
log_debug(ratbag, "%04x:%04x is a Logitech receiver, not a device. Ignoring...\n", id->vendor, id->product);
|
||||
else if (!data)
|
||||
log_debug(ratbag, "No data file found for %04x:%04x\n", id->vendor, id->product);
|
||||
|
||||
out:
|
||||
@@ -574,6 +781,30 @@ ratbag_device_data_hidpp20_get_index(const struct ratbag_device_data *data)
|
||||
return data->hidpp20.index;
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_device_data_hidpp20_get_button_count(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == HIDPP20);
|
||||
|
||||
return data->hidpp20.button_count;
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_device_data_hidpp20_get_led_count(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == HIDPP20);
|
||||
|
||||
return data->hidpp20.led_count;
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_device_data_hidpp20_get_report_rate(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == HIDPP20);
|
||||
|
||||
return data->hidpp20.report_rate;
|
||||
}
|
||||
|
||||
enum hidpp20_quirk
|
||||
ratbag_device_data_hidpp20_get_quirk(const struct ratbag_device_data *data)
|
||||
{
|
||||
@@ -582,6 +813,16 @@ ratbag_device_data_hidpp20_get_quirk(const struct ratbag_device_data *data)
|
||||
return data->hidpp20.quirk;
|
||||
}
|
||||
|
||||
/* SinoWealth */
|
||||
|
||||
const struct list *
|
||||
ratbag_device_data_sinowealth_get_supported_devices(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == SINOWEALTH);
|
||||
|
||||
return &data->sinowealth.supported_devices;
|
||||
}
|
||||
|
||||
/* SteelSeries */
|
||||
|
||||
int
|
||||
@@ -632,18 +873,68 @@ ratbag_device_data_steelseries_get_macro_length(const struct ratbag_device_data
|
||||
return data->steelseries.macro_length;
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_device_data_steelseries_get_mono_led(const struct ratbag_device_data *data)
|
||||
enum steelseries_quirk
|
||||
ratbag_device_data_steelseries_get_quirk(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == STEELSERIES);
|
||||
|
||||
return data->steelseries.mono_led;
|
||||
return data->steelseries.quirk;
|
||||
}
|
||||
|
||||
/* ASUS */
|
||||
|
||||
int
|
||||
ratbag_device_data_asus_get_profile_count(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == ASUS);
|
||||
return data->asus.profile_count;
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_device_data_steelseries_get_short_button(const struct ratbag_device_data *data)
|
||||
ratbag_device_data_asus_get_button_count(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == STEELSERIES);
|
||||
|
||||
return data->steelseries.short_button;
|
||||
assert(data->drivertype == ASUS);
|
||||
return data->asus.button_count;
|
||||
}
|
||||
|
||||
const int8_t *
|
||||
ratbag_device_data_asus_get_button_mapping(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == ASUS);
|
||||
return data->asus.button_mapping;
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_device_data_asus_get_led_count(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == ASUS);
|
||||
return data->asus.led_count;
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_device_data_asus_get_dpi_count(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == ASUS);
|
||||
return data->asus.dpi_count;
|
||||
}
|
||||
|
||||
struct dpi_range *
|
||||
ratbag_device_data_asus_get_dpi_range(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == ASUS);
|
||||
return data->asus.dpi_range;
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_device_data_asus_is_wireless(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == ASUS);
|
||||
return data->asus.is_wireless;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
ratbag_device_data_asus_get_quirks(const struct ratbag_device_data *data)
|
||||
{
|
||||
assert(data->drivertype == ASUS);
|
||||
return data->asus.quirks;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "libratbag-private.h"
|
||||
|
||||
struct ratbag_device_data;
|
||||
|
||||
struct ratbag_device_data *
|
||||
@@ -80,9 +82,28 @@ ratbag_device_data_hidpp10_get_led_count(const struct ratbag_device_data *data);
|
||||
int
|
||||
ratbag_device_data_hidpp20_get_index(const struct ratbag_device_data *data);
|
||||
|
||||
int
|
||||
ratbag_device_data_hidpp20_get_button_count(const struct ratbag_device_data *data);
|
||||
|
||||
int
|
||||
ratbag_device_data_hidpp20_get_led_count(const struct ratbag_device_data *data);
|
||||
|
||||
int
|
||||
ratbag_device_data_hidpp20_get_report_rate(const struct ratbag_device_data *data);
|
||||
|
||||
enum hidpp20_quirk
|
||||
ratbag_device_data_hidpp20_get_quirk(const struct ratbag_device_data *data);
|
||||
|
||||
/* SinoWealth */
|
||||
|
||||
/*
|
||||
* NOTE: Don't forget to check for NULL in fields of each device data entry.
|
||||
*
|
||||
* @return List of data for supported devices.
|
||||
*/
|
||||
const struct list *
|
||||
ratbag_device_data_sinowealth_get_supported_devices(const struct ratbag_device_data *data);
|
||||
|
||||
/* SteelSeries */
|
||||
|
||||
/**
|
||||
@@ -112,8 +133,58 @@ ratbag_device_data_steelseries_get_dpi_range(const struct ratbag_device_data *da
|
||||
int
|
||||
ratbag_device_data_steelseries_get_macro_length(const struct ratbag_device_data *data);
|
||||
|
||||
int
|
||||
ratbag_device_data_steelseries_get_mono_led(const struct ratbag_device_data *data);
|
||||
/**
|
||||
* @return Quirk
|
||||
*/
|
||||
enum steelseries_quirk
|
||||
ratbag_device_data_steelseries_get_quirk(const struct ratbag_device_data *data);
|
||||
|
||||
/* ASUS */
|
||||
|
||||
/**
|
||||
* @return Number of profiles
|
||||
*/
|
||||
int
|
||||
ratbag_device_data_steelseries_get_short_button(const struct ratbag_device_data *data);
|
||||
ratbag_device_data_asus_get_profile_count(const struct ratbag_device_data *data);
|
||||
|
||||
/**
|
||||
* @return Number of buttons
|
||||
*/
|
||||
int
|
||||
ratbag_device_data_asus_get_button_count(const struct ratbag_device_data *data);
|
||||
|
||||
/**
|
||||
* @return Array of button indices, which are used for reading and writing button actions
|
||||
*/
|
||||
const int8_t *
|
||||
ratbag_device_data_asus_get_button_mapping(const struct ratbag_device_data *data);
|
||||
|
||||
/**
|
||||
* @return Number of LEDs
|
||||
*/
|
||||
int
|
||||
ratbag_device_data_asus_get_led_count(const struct ratbag_device_data *data);
|
||||
|
||||
/**
|
||||
* @return Number of DPI presets
|
||||
*/
|
||||
int
|
||||
ratbag_device_data_asus_get_dpi_count(const struct ratbag_device_data *data);
|
||||
|
||||
/**
|
||||
* @return NULL if not set
|
||||
*/
|
||||
struct dpi_range *
|
||||
ratbag_device_data_asus_get_dpi_range(const struct ratbag_device_data *data);
|
||||
|
||||
/**
|
||||
* @return 1 if wireless, 0 otherwise
|
||||
*/
|
||||
int
|
||||
ratbag_device_data_asus_is_wireless(const struct ratbag_device_data *data);
|
||||
|
||||
/**
|
||||
* @return Quirks bitmask
|
||||
*/
|
||||
uint32_t
|
||||
ratbag_device_data_asus_get_quirks(const struct ratbag_device_data *data);
|
||||
|
||||
@@ -293,6 +293,7 @@ enum ratbag_led_type {
|
||||
RATBAG_LED_TYPE_BATTERY,
|
||||
RATBAG_LED_TYPE_DPI,
|
||||
RATBAG_LED_TYPE_WHEEL,
|
||||
RATBAG_LED_TYPE_SWITCHES,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1520,6 +1520,21 @@ ratbag_hidraw_get_usage(struct ratbag_device *device, unsigned int report_id)
|
||||
return report->usage;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
ratbag_hidraw_has_vendor_page(struct ratbag_device *device)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (ratbag_hidraw_get_usage_page(device, 0) >= 0xff00)
|
||||
return 1;
|
||||
|
||||
for (i = 0; i < device->hidraw[0].num_reports; i++) {
|
||||
if (ratbag_hidraw_get_usage_page(device, device->hidraw[0].reports[i].report_id) >= 0xff00)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ratbag_close_hidraw(struct ratbag_device *device)
|
||||
{
|
||||
@@ -1627,16 +1642,19 @@ ratbag_hidraw_output_report(struct ratbag_device *device, uint8_t *buf, size_t l
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf, size_t len)
|
||||
ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf, size_t len,
|
||||
ratbagd_hidraw_filter_t filter)
|
||||
{
|
||||
return ratbag_hidraw_read_input_report_index(device, buf, len, 0);
|
||||
return ratbag_hidraw_read_input_report_index(device, buf, len, 0, filter);
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_hidraw_read_input_report_index(struct ratbag_device *device, uint8_t *buf, size_t len, int hidrawno)
|
||||
ratbag_hidraw_read_input_report_index(struct ratbag_device *device, uint8_t *buf, size_t len, int hidrawno,
|
||||
ratbagd_hidraw_filter_t filter)
|
||||
{
|
||||
int rc;
|
||||
int rc, nfds;
|
||||
struct pollfd fds;
|
||||
int ts, ts_end;
|
||||
|
||||
assert(hidrawno >= 0 && hidrawno < MAX_HIDRAW);
|
||||
|
||||
@@ -1646,17 +1664,32 @@ ratbag_hidraw_read_input_report_index(struct ratbag_device *device, uint8_t *buf
|
||||
fds.fd = device->hidraw[hidrawno].fd;
|
||||
fds.events = POLLIN;
|
||||
|
||||
rc = poll(&fds, 1, 1000);
|
||||
if (rc == -1)
|
||||
return -errno;
|
||||
/* convert to ms */
|
||||
ts = now(CLOCK_MONOTONIC_RAW) / 1000 / 1000;
|
||||
ts_end = ts + 1000; /* end in now + 1000ms */
|
||||
|
||||
if (rc == 0)
|
||||
return -ETIMEDOUT;
|
||||
while (ts < ts_end) {
|
||||
nfds = poll(&fds, 1, ts_end - ts); /* poll for the remainder of timeout */
|
||||
|
||||
rc = read(device->hidraw[hidrawno].fd, buf, len);
|
||||
if (nfds < 0)
|
||||
return -errno;
|
||||
|
||||
if (rc > 0)
|
||||
log_buf_raw(device->ratbag, "input report: ", buf, rc);
|
||||
if (nfds > 0) {
|
||||
rc = read(device->hidraw[hidrawno].fd, buf, len);
|
||||
|
||||
return rc >= 0 ? rc : -errno;
|
||||
if (rc < 0)
|
||||
return -errno;
|
||||
|
||||
if (rc > 0) {
|
||||
if(!filter || (filter && filter(buf, rc))) {
|
||||
log_buf_raw(device->ratbag, "input report: ", buf, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ts = now(CLOCK_MONOTONIC_RAW) / 1000 / 1000;
|
||||
}
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ struct ratbag_hidraw {
|
||||
char *sysname;
|
||||
};
|
||||
|
||||
typedef bool (*ratbagd_hidraw_filter_t)(uint8_t *buf, size_t len);
|
||||
|
||||
/**
|
||||
* Open the hidraw device associated with the device.
|
||||
*
|
||||
@@ -162,27 +164,32 @@ int ratbag_hidraw_output_report(struct ratbag_device *device, uint8_t *buf, size
|
||||
|
||||
/**
|
||||
* Read an input report from the device
|
||||
* Optional filter function can be provided, when the filter returns false the packet is ignored
|
||||
*
|
||||
* @param device the ratbag device
|
||||
* @param[out] buf resulting raw data
|
||||
* @param len length of buf
|
||||
* @param filter filter function
|
||||
*
|
||||
* @return count of data transfered, or a negative errno on error
|
||||
*/
|
||||
int ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf, size_t len);
|
||||
int ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf, size_t len,
|
||||
ratbagd_hidraw_filter_t filter);
|
||||
|
||||
/**
|
||||
* Read an input report from the device from a specific hidraw index
|
||||
* Optional filter function can be provided, when the filter returns false the packet is ignored
|
||||
*
|
||||
* @param device the ratbag device
|
||||
* @param[out] buf resulting raw data
|
||||
* @param len length of buf
|
||||
* @param interal index of hidraw array
|
||||
* @param hidrawno index of hidraw array
|
||||
* @param filter filter function
|
||||
*
|
||||
* @return count of data transfered, or a negative errno on error
|
||||
*/
|
||||
int ratbag_hidraw_read_input_report_index(struct ratbag_device *device, uint8_t *buf, size_t len, int hidrawno);
|
||||
|
||||
int ratbag_hidraw_read_input_report_index(struct ratbag_device *device, uint8_t *buf, size_t len, int hidrawno,
|
||||
ratbagd_hidraw_filter_t filter);
|
||||
|
||||
/**
|
||||
* Tells if a given device has the specified report ID.
|
||||
@@ -219,6 +226,16 @@ ratbag_hidraw_get_usage_page(struct ratbag_device *device, unsigned int report_i
|
||||
unsigned int
|
||||
ratbag_hidraw_get_usage(struct ratbag_device *device, unsigned int report_id);
|
||||
|
||||
/**
|
||||
* Tells if a given device has a vendor usage page
|
||||
*
|
||||
* @param device the ratbag device which hidraw node is opened
|
||||
*
|
||||
* @return 1 if the device has a vendor usage page, 0 otherwise
|
||||
*/
|
||||
unsigned int
|
||||
ratbag_hidraw_has_vendor_page(struct ratbag_device *device);
|
||||
|
||||
/**
|
||||
* Gives the input key code associated to the keyboard HID usage.
|
||||
*
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config.h"
|
||||
#include <linux/input.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -196,13 +197,6 @@ struct ratbag_driver {
|
||||
*/
|
||||
int (*commit)(struct ratbag_device *device);
|
||||
|
||||
/*
|
||||
* FIXME: This function is deprecated and should be removed. Once
|
||||
* we've updated all the device drivers to stop using it we'll remove
|
||||
* it. Look at commit() instead.
|
||||
*/
|
||||
int (*write_profile)(struct ratbag_profile *profile);
|
||||
|
||||
/**
|
||||
* Called to mark a previously writen profile as active.
|
||||
*
|
||||
@@ -211,31 +205,6 @@ struct ratbag_driver {
|
||||
*/
|
||||
int (*set_active_profile)(struct ratbag_device *device, unsigned int index);
|
||||
|
||||
/*
|
||||
* FIXME: This function is deprecated and should be removed. Once
|
||||
* we've updated all the device drivers to stop using it we'll remove
|
||||
* it. Look at commit() instead.
|
||||
*/
|
||||
int (*write_button)(struct ratbag_button *button,
|
||||
const struct ratbag_button_action *action);
|
||||
|
||||
/*
|
||||
* FIXME: This function is deprecated and should be removed. Once
|
||||
* we've updated all the device drivers to stop using it we'll remove
|
||||
* it. Look at commit() instead.
|
||||
*/
|
||||
int (*write_resolution_dpi)(struct ratbag_resolution *resolution,
|
||||
int dpi_x, int dpi_y);
|
||||
|
||||
/*
|
||||
* FIXME: This function is deprecated and should be removed. Once
|
||||
* we've updated all the device drivers to stop using it we'll remove
|
||||
* it. Look at commit() instead.
|
||||
*/
|
||||
int (*write_led)(struct ratbag_led *led, enum ratbag_led_mode mode,
|
||||
struct ratbag_color color, unsigned int ms,
|
||||
unsigned int brightness);
|
||||
|
||||
/* private */
|
||||
int (*test_probe)(struct ratbag_device *device, const void *data);
|
||||
|
||||
@@ -295,6 +264,7 @@ struct ratbag_profile {
|
||||
unsigned int hz; /**< report rate in Hz */
|
||||
unsigned int rates[8]; /**< report rates available */
|
||||
size_t nrates; /**< number of entries in rates */
|
||||
bool rate_dirty;
|
||||
|
||||
unsigned int num_resolutions;
|
||||
|
||||
@@ -460,6 +430,8 @@ ratbag_button_action_match(const struct ratbag_button_action *action,
|
||||
return 0;
|
||||
|
||||
switch (action->type) {
|
||||
case RATBAG_BUTTON_ACTION_TYPE_NONE:
|
||||
return 1;
|
||||
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
|
||||
return match->action.button == action->action.button;
|
||||
case RATBAG_BUTTON_ACTION_TYPE_KEY:
|
||||
@@ -467,6 +439,7 @@ ratbag_button_action_match(const struct ratbag_button_action *action,
|
||||
case RATBAG_BUTTON_ACTION_TYPE_SPECIAL:
|
||||
return match->action.special == action->action.special;
|
||||
case RATBAG_BUTTON_ACTION_TYPE_MACRO:
|
||||
/* TODO: check if events match. */
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
@@ -585,14 +558,20 @@ ratbag_led_set_mode_capability(struct ratbag_led *led,
|
||||
}
|
||||
|
||||
/* list of all supported drivers */
|
||||
struct ratbag_driver etekcity_driver;
|
||||
struct ratbag_driver hidpp20_driver;
|
||||
struct ratbag_driver hidpp10_driver;
|
||||
struct ratbag_driver logitech_g300_driver;
|
||||
struct ratbag_driver logitech_g600_driver;
|
||||
struct ratbag_driver roccat_driver;
|
||||
struct ratbag_driver gskill_driver;
|
||||
struct ratbag_driver steelseries_driver;
|
||||
extern struct ratbag_driver etekcity_driver;
|
||||
extern struct ratbag_driver hidpp20_driver;
|
||||
extern struct ratbag_driver hidpp10_driver;
|
||||
extern struct ratbag_driver logitech_g300_driver;
|
||||
extern struct ratbag_driver logitech_g600_driver;
|
||||
extern struct ratbag_driver roccat_driver;
|
||||
extern struct ratbag_driver roccat_kone_pure_driver;
|
||||
extern struct ratbag_driver roccat_emp_driver;
|
||||
extern struct ratbag_driver gskill_driver;
|
||||
extern struct ratbag_driver steelseries_driver;
|
||||
extern struct ratbag_driver asus_driver;
|
||||
extern struct ratbag_driver sinowealth_driver;
|
||||
extern struct ratbag_driver sinowealth_nubwo_driver;
|
||||
extern struct ratbag_driver openinput_driver;
|
||||
|
||||
struct ratbag_device*
|
||||
ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device,
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "libratbag-util.h"
|
||||
#include "libratbag-test.h"
|
||||
|
||||
struct ratbag_driver test_driver;
|
||||
extern struct ratbag_driver test_driver;
|
||||
|
||||
static inline void
|
||||
ratbag_register_test_drivers(struct ratbag *ratbag)
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <iconv.h>
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "libratbag-util.h"
|
||||
#include "libratbag-private.h"
|
||||
@@ -188,3 +190,18 @@ err:
|
||||
iconv_close(converter);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mkdir_p(char *dir, mode_t mode)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (!dir)
|
||||
return EINVAL;
|
||||
|
||||
if (!stat(dir, &sb))
|
||||
return 0;
|
||||
|
||||
mkdir_p(dirname(strdupa(dir)), mode);
|
||||
|
||||
return mkdir(dir, mode);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,8 @@ int list_empty(const struct list *list);
|
||||
pos = tmp, \
|
||||
tmp = container_of(pos->member.next, tmp, member))
|
||||
|
||||
int mkdir_p(char *dir, mode_t mode);
|
||||
|
||||
static inline char*
|
||||
strncpy_safe(char *dest, const char *src, size_t n)
|
||||
{
|
||||
@@ -280,7 +282,6 @@ dpi_list_from_string(const char *str)
|
||||
|
||||
if (!str || str[0] == '\0')
|
||||
return NULL;
|
||||
printf("%s: ", str);
|
||||
|
||||
/* first, count how many elements do we have in the table */
|
||||
count = 1;
|
||||
|
||||
@@ -268,7 +268,7 @@ ratbag_sanity_check_device(struct ratbag_device *device)
|
||||
}
|
||||
|
||||
nres = ratbag_profile_get_num_resolutions(profile);
|
||||
if (nres == 0 || nres > 16) {
|
||||
if (nres > 16) {
|
||||
log_bug_libratbag(ratbag,
|
||||
"%s: invalid number of resolutions (%d)\n",
|
||||
device->name,
|
||||
@@ -600,8 +600,14 @@ ratbag_create_context(const struct ratbag_interface *interface,
|
||||
ratbag_register_driver(ratbag, &logitech_g300_driver);
|
||||
ratbag_register_driver(ratbag, &logitech_g600_driver);
|
||||
ratbag_register_driver(ratbag, &roccat_driver);
|
||||
ratbag_register_driver(ratbag, &roccat_kone_pure_driver);
|
||||
ratbag_register_driver(ratbag, &roccat_emp_driver);
|
||||
ratbag_register_driver(ratbag, &gskill_driver);
|
||||
ratbag_register_driver(ratbag, &steelseries_driver);
|
||||
ratbag_register_driver(ratbag, &asus_driver);
|
||||
ratbag_register_driver(ratbag, &sinowealth_driver);
|
||||
ratbag_register_driver(ratbag, &sinowealth_nubwo_driver);
|
||||
ratbag_register_driver(ratbag, &openinput_driver);
|
||||
|
||||
return ratbag;
|
||||
}
|
||||
@@ -858,75 +864,6 @@ ratbag_device_get_num_leds(struct ratbag_device *device)
|
||||
return device->num_leds;
|
||||
}
|
||||
|
||||
static inline enum ratbag_error_code
|
||||
write_led_helper(struct ratbag_device *device, struct ratbag_led *led)
|
||||
{
|
||||
return device->driver->write_led(led, led->mode, led->color, led->ms, led->brightness);
|
||||
}
|
||||
|
||||
/* FIXME: This is a temporary fix for all of the drivers that have yet to be
|
||||
* converted to the new profile-oriented API. Once all of the drivers have been
|
||||
* converted, this code should be removed.
|
||||
*/
|
||||
static enum ratbag_error_code
|
||||
ratbag_old_write_profile(struct ratbag_device *device)
|
||||
{
|
||||
struct ratbag_profile *profile;
|
||||
struct ratbag_button *button;
|
||||
struct ratbag_led *led;
|
||||
struct ratbag_resolution *resolution;
|
||||
int rc;
|
||||
|
||||
assert(device->driver->write_profile);
|
||||
|
||||
list_for_each(profile, &device->profiles, link) {
|
||||
if (!profile->dirty)
|
||||
continue;
|
||||
|
||||
rc = device->driver->write_profile(profile);
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
|
||||
if (device->driver->write_resolution_dpi) {
|
||||
ratbag_profile_for_each_resolution(profile, resolution) {
|
||||
rc = device->driver->write_resolution_dpi(
|
||||
resolution, resolution->dpi_x,
|
||||
resolution->dpi_y);
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
if (device->driver->write_button) {
|
||||
list_for_each(button, &profile->buttons, link) {
|
||||
struct ratbag_button_action action =
|
||||
button->action;
|
||||
|
||||
if (!button->dirty)
|
||||
continue;
|
||||
|
||||
rc = device->driver->write_button(button,
|
||||
&action);
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
if (device->driver->write_led) {
|
||||
list_for_each(led, &profile->leds, link) {
|
||||
if (!led->dirty)
|
||||
continue;
|
||||
|
||||
rc = write_led_helper(device, led);
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return RATBAG_SUCCESS;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT enum ratbag_error_code
|
||||
ratbag_device_commit(struct ratbag_device *device)
|
||||
{
|
||||
@@ -936,19 +873,15 @@ ratbag_device_commit(struct ratbag_device *device)
|
||||
struct ratbag_resolution *resolution;
|
||||
int rc;
|
||||
|
||||
if (!device->driver->commit) {
|
||||
rc = ratbag_old_write_profile(device);
|
||||
if (rc != RATBAG_SUCCESS)
|
||||
return rc;
|
||||
} else {
|
||||
rc = device->driver->commit(device);
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
rc = device->driver->commit(device);
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
|
||||
list_for_each(profile, &device->profiles, link) {
|
||||
profile->dirty = false;
|
||||
|
||||
profile->rate_dirty = false;
|
||||
|
||||
list_for_each(button, &profile->buttons, link)
|
||||
button->dirty = false;
|
||||
|
||||
@@ -1117,6 +1050,7 @@ ratbag_profile_set_report_rate(struct ratbag_profile *profile,
|
||||
if (profile->hz != hz) {
|
||||
profile->hz = hz;
|
||||
profile->dirty = true;
|
||||
profile->rate_dirty = true;
|
||||
}
|
||||
|
||||
return RATBAG_SUCCESS;
|
||||
|
||||
@@ -52,6 +52,28 @@
|
||||
%typemap(freearg) (unsigned int *rates, size_t nrates) = (unsigned int *resolutions, size_t nres);
|
||||
/* END OF custom typemap for handling ratbag_resolution_get_report_rate_list */
|
||||
|
||||
/* uintXX_t mapping: Python -> C */
|
||||
%typemap(in) uint8_t {
|
||||
$1 = (uint8_t) PyInt_AsLong($input);
|
||||
}
|
||||
%typemap(in) uint16_t {
|
||||
$1 = (uint16_t) PyInt_AsLong($input);
|
||||
}
|
||||
%typemap(in) uint32_t {
|
||||
$1 = (uint32_t) PyInt_AsLong($input);
|
||||
}
|
||||
|
||||
/* uintXX_t mapping: C -> Python */
|
||||
%typemap(out) uint8_t {
|
||||
$result = PyInt_FromLong((long) $1);
|
||||
}
|
||||
%typemap(out) uint16_t {
|
||||
$result = PyInt_FromLong((long) $1);
|
||||
}
|
||||
%typemap(out) uint32_t {
|
||||
$result = PyInt_FromLong((long) $1);
|
||||
}
|
||||
|
||||
/* Parse the header file to generate wrappers */
|
||||
%include "libratbag.h"
|
||||
%include "libratbag-enums.h"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user