Git Product home page Git Product logo

g213colors's Introduction

G213Colors

A script to change the key colors on a Logitech G213 Prodigy Gaming Keyboard.

Please also check out these awesome forks:

G213Colors GUI - A cool grafical GUI you can use from the main menu

G213Colors GUI + installation script - The GUI plus an easy installation script

Thanks to derEisele and JeroenED for creating this!

What it does

G213Colors lets you set the color(s) and certain effects of the illuminated keys on a G213 keyboard under Linux.

The original Software and Hardware has the following downsides:

  • There is no Linux software
  • The keyboard does not save the last setting, one has to re-set it every bootup / disconnect
  • The keyboard starts up with an annoying color cycle animation
  • The original software is unusable with KVM switches

So i decided to reverse engineer their USB protocol and to write my own script to control the keyboard.

G213Colors was built and tested under Linux for the G213 keyboard specifically, but after some adaptation it could potentially be run under other OS'es and used for other Logitech keyboards as well. Please understand that i do not support any such adaptation, if you want to do it you are on your own.

The "Wave" color effect that is available with the Logitech software could not be replicated since it is completely generated in the software by updating the colors every x ms (In contrast to the other effects which run on the keyboard itself). You could generate this effect with a script, but since G213Colors has to detach the kernel driver from one of the G213's interfaces to send data out the multimedia keys would most likely stop working. Unfortunately this is a side effect of the linux driver structure.

Installation

Either download the G213Colors.py file to a directory of your choosing or clone this project with git.

Prerequisites

If you run the script as Root (Which is likely) please install the libraries also as root (E.g.: sudo pip3 install pyusb, sudo pip3 install randomcolor, use only "pip" for Python 2).

Please ignore the pcap directory, i added the pcap files i used for reverse engineering just in case someone wants to work with them. They can be opened with Wireshark.

Usage

For help on how to use G213Colors call the script without any arguments:

sudo python G213Colors.py

G213Colors needs to run as root as long as your user doesn't have access privileges for that USB device (How to do this, please use "046d" as idVendor and "c336" as idProduct).

If you want to run the script when the keyboard is plugged in (For instance if you use a USB switch or KVM switch) use this udev rule (In this case the script is run by root):

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c336", RUN+="/usr/bin/python /usr/local/bin/G213Colors.py -c 4F7F9F"

Changelog

Changelog v0.3:

  • Added feature: Assign random colors to keyboard by using -ra or -rs flag

Changelog v0.2:

  • Fixed bug preventing setting all 5 color fields correctly, thanks to @oncecreated for finding this solution!
  • Added propper validation of user inputs
  • Complete refactoring

Changelog v0.1:

  • Initial checkin

g213colors's People

Contributors

dush1729 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

g213colors's Issues

Just stopping by

Apologies for the non-issue issue...

Just popping by to say thanks a bunch for this, and @JeroenED as well for the GUI and service. Saved me a bunch of time digging through documentation to achieve this myself.

I do dual boot with Windows but as you noticed changing the colour doesn't stick without the apps. I use Ubuntu 99% of the time anyway though, so this has been fantastic!

Cheers :)

Matt

Some issues in g213colors-gui

Hi,
I'm a newbie in programming, and i try to set your project for set led light of logitech mouse G203 Prodigy without success.

when i've compiled and install G213Colors, if i launch it from terminal, i get these issues



1-
File "/usr/bin/g213colors-gui", line 50
myG.saveData(myG.cycleCommand.format(str(format(self.sbGetValue(self.sbCycle), '04x'))))
^
TabError: inconsistent use of tabs and spaces in indentation

***>>> i've edited "g213colors-gui" line 50, deleting Tab space and do spaces.



2-
File "/usr/bin/g213colors-gui", line 150
print command
^
SyntaxError: Missing parentheses in call to 'print'

***>>> i've edited line 150 as this -->> print (command)

Pipe error when ctrl_transfer is called

Hi, I found this project now that I am working on something very similar for my G510 keyboard.
After .detach_kernel_driver, like you, I also send a .ctrl_transfer, but I always get "Pipe error".
It happens the same when I use your script (duly modified). Have you ever encountered this error? How did you manage to solve it?

Thank you

Adaptation for Windows

Not a real issue, but I wanted to let you know that your code can perfectly used under Windows. The user just also needs to install libusb via Zadig, but then magic.
I made small adaptations since I just wanted to set my color at the start without starting GHub.
I made it realy simply. I know not the best coding style. But definitely the fastest.

import sys
import usb.core

device = usb.core.find(idVendor=0x046d, idProduct=0xc336)
if device is None:
sys.exit(1)

device.ctrl_transfer(0x21, 0x09, 0x0211, 0x0001, b'\x11\xff\x0c:\x00\x01\xff\xa1\xf6\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
device.read(0x82, 20)

No module named usb.core

$ sudo python G213Colors.py
Traceback (most recent call last):
  File "G213Colors.py", line 27, in <module>
    import usb.core
ImportError: No module named usb.core

Reset?

How could I go back to the initial G213 setting ?

No module named randomcolor

cagcak@xps:~$ sudo python G213Colors.py 
Traceback (most recent call last):
  File "G213Colors.py", line 30, in <module>
    import randomcolor
ImportError: No module named randomcolor

Related to #6

Not lighting up

I have followed your instructions, however my G213 Keyboard is still not lighting up. Please help.

Individual key colors?

Is there a way to set individual keys to specific colors? Example "Windows Flag" key, and some letters? As so to indicate short cut keys if pressed together.

udev rule tip

Hi,

I couldn't make udev rule working properly because my multimedia keys would stop working after colors were set. By adding just idVendor and idProduct to udev rule, it gets hit three times (device and keyboard+multimedia interfaces). Setting colors takes multimedia interface off, sets colors and then attaches it back. This triggers udev again for attaching multimedia interface and ends up in infinite loop.

I had to limit the rule so that only root device triggers the script

ACTION=="add",        KERNEL=="event[0-9]*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c336", RUN+="/usr/local/bin/G213Colors.sh 4F7F9F"

However, I couldn't make it work with ATTRS, so I moved the necessary check to the script itself:

#!/bin/sh

[ "${ID_USB_INTERFACE_NUM}" == "00" ] || exit
exec /usr/bin/python /usr/local/bin/G213Colors.py -c $1

Maybe somebody can create a more elegant solution but this one works and I believe it should be documented as it took me several hours to figure out.

How can I make the profile persistent?

Hi there,

I am on the following system:
Operating System: Kubuntu 20.04
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8
Kernel Version: 5.11.0-41-generic
OS Type: 64-bit
Processors: 8 × Intel® Core™ i5-10210U CPU @ 1.60GHz
Memory: 14,9 GiB

and have just installed the script and it works up until a reboot.
I have tried added the service as suggested here. However, I do not get the pre-reboot-status that I want.

Do u have any idea on how to get this to work?

all the best,
K

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.