Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for G915 (libusb only) #267

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

yawor
Copy link

@yawor yawor commented Aug 23, 2021

I've added implementation for G915. It works only with libusb (I don't know how to make it work with hidraw).
Also it's only for wireless connection. It won't work if keyboard is also connected to PC via USB cable.

g810-led has a lot of assumptions regarding the communication with keyboards, like interface and endpoint numbers in libusb mode or HID++ 2.0 target id (the second byte in the data packet sent to the keyboard). Because of that I had to make some changes here and there to make the code compatible with G915.

G815 and G915 are actually quite similar. They use the same protocol, but third byte in the data (feature index) is different because of different number of API features available in both models, so the numbers are shifted. Also the target id (second byte) must be set to 0x01 in wireless mode to talk to the keyboard because target 0xFF means the receiver itself.

It should also be possible to support G915 in wired mode, but like in case of G815 vs G915, the feature indexes are also different for G915 over cable so it would require additional work.

@yawor yawor mentioned this pull request Aug 23, 2021
@MatMoul MatMoul added the review label Sep 1, 2021
@MatMoul
Copy link
Owner

MatMoul commented Sep 1, 2021

Thanks for the "PR", I'll test that ...

It's sure that libusb will be needed for the g915 ...

As the "g810-led" package is part of Debian main, I cannot validate the "PR" until I have run some tests.

But that would be too cool to have a solution for that damn G915.

@yawor
Copy link
Author

yawor commented Sep 1, 2021

@MatMoul I wonder why g810-led doesn't work with G915 when hidapi is used.
Other projects like keyleds (with some modifications) and OpenRGB (my merge request is pending for now) are able to communicate with G915 over hidapi.
Also the python script I've posted few comments earlier (the one to retrieve list of features from G915 TKL) is also using hidapi.

@yawor
Copy link
Author

yawor commented Sep 2, 2021

@MatMoul I see where the hidapi issue may be coming from. You're using hid_open, which opens the first interface on the device. This probably works on some models, but for others you'd need to open non-first interface. For example, to control G915 you need to open 3rd interface (interface_number = 2). To do this, you'd need to first find correct device path by checking the interface number and use the hid_open_path function instead.

@yawor
Copy link
Author

yawor commented Sep 2, 2021

@MatMoul I've added support for G915 in hidapi mode. Unfortunately I don't have any way to test if this breaks support for other keyboards, but from the information I've gathered from different projects, everything should still work.
I've also added extra argument -di which works with -tuk and is able to override the interface number. The argument itself is not required, as it has a default value for each tuk value.

@MatMoul
Copy link
Owner

MatMoul commented Sep 5, 2021

The code look fine but I am having some problems.

FYI, I tested with HIDAPI and LIBUSB.

I started by testing with the USB cable without success ...
Then I tested with the USB dongle and it worked (better with LIBUSB).
But after 60s, the keyboard is reset.

I have also tested old keyboards and some key is no longer defined in a single call of g810-led.

It's a good start but there is still some work to do for this damn G915.

@yawor
Copy link
Author

yawor commented Sep 5, 2021

@MatMoul I've mentioned it in the PR that only wireless mode is implemented. It can be done for wired mode too, but without Logitech feature detection it'll add even mode switch cases.

Regarding the profile resets, it's the on board node interfering. To get rid of it first switch the keyboard in the software mode. You should have then the full control of the keyboard without resets.

I've also noticed that not always all the keys are set on the first run. I don't know why but I thought that this is G915 specific. Have you compared the behaviour with and without my changes on these older keyboards? Also for me this issue goes away when keyboard is in software mode.

@bkw777
Copy link

bkw777 commented Oct 10, 2021

This is almost working for me. I just got a new g915tkl and I had to edit c541 to c545 in the udev rule and Keyboard.h and then built with libusb, installed, re-plugged the lightspeed dongle to invoke the udev rule.

When I ran g915-led --list-keyboards it recognized the keyboard and changed all the keys to a color pattern I never saw before, so something worked, which is good, however it also modified the keyboard without being asked, which is bad.

And, nothing else seems to work. For instance g915-led -a 888800 has no effect.

This current color pattern is none of the 13 built-ins (light+0 - light+9, Fn+M1 - Fn+M3), and I've never used the windows ghub software yet (no windows partition on this machine), so this pattern definitely came from g915-led somehow. And it was un-expected but not unwelcome just to be clear. It's mercifully static which is a huge improvement over the unstoppable flashing/breathing circus it was doing before. Even if I never get it to do anythijng else, this is good enough to live with! So thank you for that at least.

Whoa, I just noticed dmesg/syslog is continuously spamming:

root@fw:~# tail -50 /var/log/syslog
Oct 10 15:06:22 fw kernel: [83667.507924] hid-generic 0003:046D:C545.87C8: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw systemd-udevd[28438]: hiddev0: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw kernel: [83667.626651] hid-generic 0003:046D:C545.87C9: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw kernel: [83667.670777] hid-generic 0003:046D:C545.87CA: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw systemd-udevd[28439]: 0003:046D:C545.5CBE: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw kernel: [83667.791879] hid-generic 0003:046D:C545.87CB: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw systemd-udevd[28439]: 0003:046D:C545.5CBF: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw kernel: [83667.908229] hid-generic 0003:046D:C545.87CC: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw systemd-udevd[28439]: 0003:046D:C545.5CC0: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw kernel: [83668.014755] hid-generic 0003:046D:C545.87CD: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw systemd-udevd[28439]: 0003:046D:C545.5CC1: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw kernel: [83668.121873] hid-generic 0003:046D:C545.87CE: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw systemd-udevd[28438]: hiddev0: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw kernel: [83668.227792] hid-generic 0003:046D:C545.87CF: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw kernel: [83668.273884] hid-generic 0003:046D:C545.87D0: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw systemd-udevd[28439]: 0003:046D:C545.5CC3: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw kernel: [83668.400869] hid-generic 0003:046D:C545.87D1: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:23 fw systemd-udevd[28439]: 0003:046D:C545.5CC4: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:23 fw kernel: [83668.516982] hid-generic 0003:046D:C545.87D2: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw systemd-udevd[28439]: 0003:046D:C545.5CC5: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw kernel: [83668.622707] hid-generic 0003:046D:C545.87D3: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw systemd-udevd[28439]: 0003:046D:C545.5CC6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw kernel: [83668.729893] hid-generic 0003:046D:C545.87D4: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw systemd-udevd[28439]: 0003:046D:C545.5CC7: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw kernel: [83668.841851] hid-generic 0003:046D:C545.87D5: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw systemd-udevd[28438]: hiddev0: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw kernel: [83668.945729] hid-generic 0003:046D:C545.87D6: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw kernel: [83668.989018] hid-generic 0003:046D:C545.87D7: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw systemd-udevd[28439]: 0003:046D:C545.5CC9: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw kernel: [83669.108233] hid-generic 0003:046D:C545.87D8: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw systemd-udevd[28439]: 0003:046D:C545.5CCA: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw systemd-udevd[28439]: hidraw6: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw kernel: [83669.217893] hid-generic 0003:046D:C545.87D9: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw systemd-udevd[28438]: hiddev0: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:24 fw kernel: [83669.322865] hid-generic 0003:046D:C545.87DA: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw kernel: [83669.365847] hid-generic 0003:046D:C545.87DB: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw kernel: [83669.483726] hid-generic 0003:046D:C545.87DC: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw kernel: [83669.529925] hid-generic 0003:046D:C545.87DD: hiddev0,hidraw6: USB HID v1.11 Device [Logitech USB Receiver] on usb-0000:00:14.0-6/input2
Oct 10 15:06:24 fw systemd-udevd[28438]: hiddev0: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
Oct 10 15:06:25 fw systemd-udevd[28439]: 0003:046D:C545.5CCD: Process '/usr/bin/g915-led -p /etc/g810-led/profile' failed with exit code 2.
root@fw:~# 

Watching tail -f /var/log/syslog, it stops as soon as I remove the dongle, and resumes flooding as soon as I reinsert the dongle.

@bkw777
Copy link

bkw777 commented Oct 10, 2021

I guess what's going on is, the udev rule is successfully applying /etc/g810-led/profile many times per second forever, which would explain both why my lights changed on their own, and why I can't seem to change them with other commands ?

@bkw777
Copy link

bkw777 commented Oct 10, 2021

I removed the RUN action from the udev rules and re-plugged the receiver, and udev is not spamming syslog, it just reacted to the plug event, set the permissions, and stopped like normal.

And now g915-led commands work as documented, except as already noted, the action is unreliable. "-a 888800" for instance changed most keys yellow, but left a random scattering of keys turned off. So, that's already been noted, just saying me too on that one.

@bkw777
Copy link

bkw777 commented Oct 10, 2021

Not a random scattering. Repeated re-running of the same -a 888800 command always leaves the same set of keys dark:
left-shift, F1-F5, Home, End, PgUp, Pg Dn, all 4 arrow keys, all 4 media keys.
That means specifically and curiously, right-shift, F6-F12, INS, DEL are lit.
I have a while loop re-running the command every second while writing this and no lights changed the whole time.

@bkw777
Copy link

bkw777 commented Oct 10, 2021

When I run g915-led -p /etc/g810-led/profile manually (it's removed from udev now remember), the profile is applied and all key are set according to that profile, but 60 seconds later the keyboard reverts to the default circus act (or the selected preset if I select Fn+M1 , M2, or M3. For instance, Fn + M2 results in all keys cyan, breathing. That pattern remains through idleness. When idle, it gradually dims to all off, and then when woken up, resumes that M2 setting, not the power-on default rainbow waves.)

But the profile applied by -p filename only lasts until 60 seconds after being left idle.

@bkw777
Copy link

bkw777 commented Oct 10, 2021

The same command in the udev rule does not exit with 2, at least not from the normal user's interactive environment, which is not the same as the environment that the udev command runs in.

bkw@fw:~$ g915-led -p /etc/g810-led/profile ;echo $?
0
bkw@fw:~$ 

I thought maybe it was because the sample profile includes key groups that this keyboard doesn't have, but that doesn't seem to hurt anything.

@bkw777
Copy link

bkw777 commented Oct 10, 2021

I think now I have this working as well as promised.
I wrote a custom profile that sets the key colors in groups instead of all, and it reliably sets all keys.
I can run g915-led --on-board-mode software to stop the keyboard from reverting to the default rainbow cycling.
The -fx commands do not work, but they aren't promised to on this model.

I think that disabling on-board-mode must be disabling idle timeout altogether, which means the battery will die in a number of hours instead of months, but it is what it is. Since the g915-led commands are working, maybe I can insert commands into the desktop environment or systemd to restore on-board mode so that the on-board power management resumes, which probably puts the mcu and radio to sleep more than just shutting off the lights. And then issue other commands to disable on-board mode again when waking from sleep or lock screen etc.

Anyway, aside from the udev rule and the different usb device id number for my dongle, this is working for me more or less as documented by yawor.

Thank you.

@no-more-secrets
Copy link

Hi, I built this branch (in libusb mode) and I can control the colors nicely on my G915, however it seems that I cannot put the keyboard into software mode. It tried running:

$ sudo g915-led -dv 046d -dp c545 -tuk 5 --on-board-mode software

and the command appears to succeed, but my keyboard shortly thereafter reverts to the color cycling. Am I doing something wrong? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants