This commit is contained in:
52
main.c
52
main.c
@ -3,20 +3,20 @@
|
||||
* ledcontroller-3bit
|
||||
*
|
||||
* This file is a fork of the LedController code. You will find
|
||||
* the original copyright notice below.
|
||||
* the original copyright notices below.
|
||||
*
|
||||
* @copyright
|
||||
* Copyright (C) 2013 andmarios - http://www.andmarios.com
|
||||
* Copyright (C) 2013 andmarios - http://www.andmarios.com \n
|
||||
*
|
||||
* 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.
|
||||
* (at your option) any later version. \n
|
||||
*
|
||||
* 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.
|
||||
* GNU General Public License for more details. \n
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
@ -26,17 +26,17 @@
|
||||
* Original Copyright Notice:
|
||||
*
|
||||
* LedController
|
||||
* Copyright (C) 2011 jmrobles - http://robleshermoso.wordpress.com
|
||||
* Copyright (C) 2011 jmrobles - http://robleshermoso.wordpress.com \n
|
||||
*
|
||||
* 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.
|
||||
* (at your option) any later version.\n
|
||||
*
|
||||
* 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.
|
||||
* GNU General Public License for more details.\n
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
@ -47,8 +47,9 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#define VID 0x1294 /**< USB Vendor ID */
|
||||
#define PID 0x1320 /**< USB Product ID */
|
||||
#define USB_VID 0x1294 /**< USB Vendor ID */
|
||||
#define USB_PID 0x1320 /**< USB Product ID */
|
||||
#define USB_EP 0x2 /**< USB EndPoint */
|
||||
|
||||
static struct libusb_device_handle *devh = NULL;
|
||||
/**
|
||||
@ -73,43 +74,47 @@ static struct libusb_device_handle *devh = NULL;
|
||||
*
|
||||
* @param argc POSIX number of parameters
|
||||
* @param argv Array of parameters
|
||||
* @return Error color_code (0 on success)
|
||||
*/
|
||||
int main(int argc, char **argv) {
|
||||
int ret;
|
||||
unsigned char code = 0;
|
||||
if (argc != 2)
|
||||
{
|
||||
printf("Syntax: %s blue | red | green | aqua | purple | yellow | white | off\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "blue") == 0)
|
||||
unsigned char color_code = 0;
|
||||
if (strcmp(argv[1], "off") == 0)
|
||||
{
|
||||
code = 1;
|
||||
color_code = 0;
|
||||
}
|
||||
else if (strcmp(argv[1], "blue") == 0)
|
||||
{
|
||||
color_code = 1;
|
||||
}
|
||||
else if (strcmp(argv[1], "red") == 0)
|
||||
{
|
||||
code = 2;
|
||||
color_code = 2;
|
||||
}
|
||||
else if (strcmp(argv[1], "green") == 0)
|
||||
{
|
||||
code = 3;
|
||||
color_code = 3;
|
||||
}
|
||||
else if (strcmp(argv[1], "aqua") == 0)
|
||||
{
|
||||
code = 4;
|
||||
color_code = 4;
|
||||
}
|
||||
else if (strcmp(argv[1], "purple") == 0)
|
||||
{
|
||||
code = 5;
|
||||
color_code = 5;
|
||||
}
|
||||
else if (strcmp(argv[1], "yellow") == 0)
|
||||
{
|
||||
code = 6;
|
||||
color_code = 6;
|
||||
}
|
||||
else if (strcmp(argv[1], "white") == 0)
|
||||
{
|
||||
code = 7;
|
||||
color_code = 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -118,7 +123,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
libusb_init(NULL);
|
||||
devh = libusb_open_device_with_vid_pid(NULL, VID, PID);
|
||||
devh = libusb_open_device_with_vid_pid(NULL, USB_VID, USB_PID);
|
||||
if (devh == NULL)
|
||||
{
|
||||
puts("Device not found");
|
||||
@ -128,7 +133,7 @@ int main(int argc, char **argv) {
|
||||
if (libusb_kernel_driver_active(devh, 0))
|
||||
{
|
||||
puts("Detach driver from kernel");
|
||||
ret = libusb_detach_kernel_driver(devh, 0);
|
||||
int ret = libusb_detach_kernel_driver(devh, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
puts("Could not detach driver");
|
||||
@ -137,15 +142,14 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
char data[5];
|
||||
data[0] = code;
|
||||
data[0] = color_code;
|
||||
data[1] = 0x4;
|
||||
data[2] = 0x4;
|
||||
data[3] = 0x4;
|
||||
data[4] = 0x4;
|
||||
|
||||
int dummy;
|
||||
libusb_claim_interface(devh, 0);
|
||||
ret = libusb_interrupt_transfer(devh, 0x2, data, 5, &dummy, 0);
|
||||
int ret = libusb_interrupt_transfer(devh, USB_EP, data, 5, NULL, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
perror("libusb error");
|
||||
|
Reference in New Issue
Block a user