From bc8945b4fcb48badd1007246da955fabb23f68c5 Mon Sep 17 00:00:00 2001 From: Marios Andreopoulos Date: Tue, 19 Feb 2013 00:05:11 +0200 Subject: [PATCH] Import of jmrobles' source code. --- Makefile | 9 ++++++ main.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 Makefile create mode 100644 main.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e474ab9 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ + + +all: ledcontroller + +ledcontroller: main.c + gcc -o $@ $^ `pkg-config libusb-1.0 --cflags --libs` + +clean: + rm ledcontroller diff --git a/main.c b/main.c new file mode 100644 index 0000000..85abab2 --- /dev/null +++ b/main.c @@ -0,0 +1,89 @@ +/* + LedController + Copyright (C) 2011 jmrobles - http://robleshermoso.wordpress.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#include +#include +#include + + +#define VID 0x1294 +#define PID 0x1320 + + +static struct libusb_device_handle *devh = NULL; + +int main(int argc,char** argv) +{ + int ret; + unsigned char code = 0; + if (argc != 2 ) + { + printf("syntax: %s red | green | blue | off\n",argv[0]); + return -1; + + } + if ( strcmp(argv[1],"red") == 0 ) + { + code = 2; + } + else if ( strcmp(argv[1],"green") == 0 ) + { + code = 3; + } + else if ( strcmp(argv[1],"blue") == 0 ) + { + code = 1; + } + + libusb_init(NULL); + devh = libusb_open_device_with_vid_pid(NULL, VID, PID); + if (devh == NULL ) + { + printf("not found\n"); + return -1; + } + + if ( libusb_kernel_driver_active(devh,0) ) + { + printf("detach from kernel\n"); + ret = libusb_detach_kernel_driver(devh,0); + if (ret < 0 ) + { + printf("can't detach\n"); + return -1; + } + } + + char data[5]; + data[0] = code; + data[1] = 0x4; + data[2] = 0x4; + data[3] = 0x4; + data[4] = 0x4; + + int dummy; + ret = libusb_interrupt_transfer(devh,0x2,data,5,&dummy,0); + if ( ret < 0 ) + { + perror("error"); + } + + +return 0; +}