first commit

This commit is contained in:
Philipp Schmitt 2013-06-28 15:59:28 +02:00
commit bcfd6468ec
4 changed files with 152 additions and 0 deletions

17
.SRCINFO Normal file
View file

@ -0,0 +1,17 @@
pkgbase = g9xled
pkgdesc = Logitech G9X LED color control utility
pkgver = 1
pkgrel = 2
url = http://als.regnet.cz/logitech-g9-linux-led-color.html
install = g9xled.install
arch = i686
arch = x86_64
license = unknown
makedepends = gcc
depends = libusb
noextract = g9xled.c
source = http://lxl.io/aur/g9xled/g9xled.c
md5sums = 0a8ba5b00ca0663cd6dd6efa30597cbd
pkgname = g9xled

29
PKGBUILD Normal file
View file

@ -0,0 +1,29 @@
# Contributor: Philipp Schmitt (attentah@NOSPAM.gmail.com)
pkgname=g9xled
pkgver=1
pkgrel=2
pkgdesc="Logitech G9X LED color control utility"
arch=('i686' 'x86_64')
url="http://als.regnet.cz/logitech-g9-linux-led-color.html"
license=('unknown')
depends=('libusb')
makedepends=('gcc')
install="$pkgname.install"
source=(http://lxl.io/aur/g9xled/g9xled.c)
noextract=('g9xled.c')
md5sums=('0a8ba5b00ca0663cd6dd6efa30597cbd')
build() {
# Create destination directories
mkdir -p $pkgdir/usr/bin
# Build/Install
cd "$srcdir"
gcc g9xled.c -o g9xled -lusb
install -m755 g9xled $pkgdir/usr/bin
}

84
g9xled.c Normal file
View file

@ -0,0 +1,84 @@
#include <stdio.h>
#include <string.h>
#include <usb.h>
#define G9X_VENDOR_ID 0x046d
#define G9X_PRODUCT_ID 0xc066
unsigned int get_hex4(unsigned char *p)
{
return (*p > '9' ? *p - 'A' + 10 : *p - '0') & 15;
}
unsigned int get_hex8(unsigned char *p)
{
return (get_hex4(p) << 4) + get_hex4(p+1);
}
int is_hex(unsigned char *hex)
{
char buf[7] = {0};
return (strtok(strncpy(buf, hex, sizeof(buf)), "0123456789ABCDEFabcdef") == NULL);
}
static void change_color(struct usb_dev_handle *handle, unsigned char *color)
{
unsigned char usb_data[] = { 0x10, 0x00, 0x80, 0x57, 0x00, 0x00, 0x00 };
usb_data[4] = get_hex8(color);
usb_data[5] = get_hex8(color+2);
usb_data[6] = get_hex8(color+4);
usb_control_msg(handle, 0x34, 0x9, 0x210, 0x01, (char*)usb_data, 0x7, 5000);
}
static struct usb_device *device_init(void)
{
struct usb_bus *usb_bus;
struct usb_device *dev;
usb_init();
usb_find_busses();
usb_find_devices();
for (usb_bus = usb_busses; usb_bus; usb_bus = usb_bus->next) {
for (dev = usb_bus->devices; dev; dev = dev->next) {
if ((dev->descriptor.idVendor == G9X_VENDOR_ID) && (dev->descriptor.idProduct == G9X_PRODUCT_ID))
return dev;
}
}
return NULL;
}
int main(int argc, char **argv)
{
struct usb_device *usb_dev;
struct usb_dev_handle *usb_handle;
int retval = 1;
usb_dev = device_init();
if (usb_dev == NULL) {
fprintf(stderr, "Device not found!\n");
goto exit;
}
usb_handle = usb_open(usb_dev);
if (usb_handle == NULL) {
fprintf(stderr, "Unable to open USB device!\n");
goto exit;
}
if ((argc != 2) || (strlen(argv[1]) != 6) || !is_hex(argv[1])) {
fprintf(stderr, "Specify color in RRGGBB hexa form!\n");
goto exit;
}
change_color(usb_handle, argv[1]);
retval = 0;
exit:
usb_close(usb_handle);
return retval;
}

22
g9xled.install Normal file
View file

@ -0,0 +1,22 @@
post_install() {
cat <<-EoM
==> To set the Logitech G9X LED color, enter a hexadecimal value as root:
==>
==> g9xled RRGGBB
==>
==> g9xled attempts to round to the nearest subset color allowed by the G9X
==> mouse. Settings are temporary - profile color is restored on un-plugging
==> and re-plugging of the mouse, or upon reboot.
EoM
}
post_upgrade() {
post_install
}