This commit is contained in:
145
main.c
145
main.c
@ -51,16 +51,19 @@
|
|||||||
|
|
||||||
static struct libusb_device_handle *devh = NULL;
|
static struct libusb_device_handle *devh = NULL;
|
||||||
|
|
||||||
int main(int argc,char** argv)
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned char code = 0;
|
unsigned char code = 0;
|
||||||
if (argc != 2 )
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
printf("syntax: %s blue | red | green | aqua | purple | yellow | white | off\n",argv[0]);
|
printf
|
||||||
return -1;
|
("Syntax: %s blue | red | green | aqua | purple | yellow | white | off\n",
|
||||||
|
argv[0]);
|
||||||
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The device has a RGB LED, which has two states for each "sub-LED",
|
The device has a RGB LED, which has two states for each "sub-LED",
|
||||||
@ -81,72 +84,74 @@ int main(int argc,char** argv)
|
|||||||
1 1 0 yellow 0x6 (more of a mustard - green color)
|
1 1 0 yellow 0x6 (more of a mustard - green color)
|
||||||
1 1 1 white 0x7 (a very blue-ish white)
|
1 1 1 white 0x7 (a very blue-ish white)
|
||||||
*/
|
*/
|
||||||
if ( strcmp(argv[1],"blue") == 0 )
|
if (strcmp (argv[1], "blue") == 0)
|
||||||
{
|
{
|
||||||
code = 1;
|
code = 1;
|
||||||
}
|
}
|
||||||
else if ( strcmp(argv[1],"red") == 0 )
|
else if (strcmp (argv[1], "red") == 0)
|
||||||
{
|
{
|
||||||
code = 2;
|
code = 2;
|
||||||
}
|
}
|
||||||
else if ( strcmp(argv[1],"green") == 0 )
|
else if (strcmp (argv[1], "green") == 0)
|
||||||
{
|
{
|
||||||
code = 3;
|
code = 3;
|
||||||
}
|
}
|
||||||
else if ( strcmp(argv[1],"aqua") == 0 )
|
else if (strcmp (argv[1], "aqua") == 0)
|
||||||
{
|
{
|
||||||
code = 4;
|
code = 4;
|
||||||
}
|
}
|
||||||
else if ( strcmp(argv[1],"purple") == 0 )
|
else if (strcmp (argv[1], "purple") == 0)
|
||||||
{
|
{
|
||||||
code = 5;
|
code = 5;
|
||||||
}
|
}
|
||||||
else if ( strcmp(argv[1],"yellow") == 0 )
|
else if (strcmp (argv[1], "yellow") == 0)
|
||||||
{
|
{
|
||||||
code = 6;
|
code = 6;
|
||||||
}
|
}
|
||||||
else if ( strcmp(argv[1],"white") == 0 )
|
else if (strcmp (argv[1], "white") == 0)
|
||||||
{
|
{
|
||||||
code = 7;
|
code = 7;
|
||||||
} else {
|
}
|
||||||
printf("invalid color\n");
|
else
|
||||||
return -1;
|
{
|
||||||
}
|
printf ("invalid color\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
libusb_init(NULL);
|
libusb_init (NULL);
|
||||||
devh = libusb_open_device_with_vid_pid(NULL, VID, PID);
|
devh = libusb_open_device_with_vid_pid (NULL, VID, PID);
|
||||||
if (devh == NULL )
|
if (devh == NULL)
|
||||||
{
|
{
|
||||||
printf("not found\n");
|
printf ("not found\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( libusb_kernel_driver_active(devh,0) )
|
if (libusb_kernel_driver_active (devh, 0))
|
||||||
{
|
{
|
||||||
printf("detach from kernel\n");
|
printf ("detach from kernel\n");
|
||||||
ret = libusb_detach_kernel_driver(devh,0);
|
ret = libusb_detach_kernel_driver (devh, 0);
|
||||||
if (ret < 0 )
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
printf("can't detach\n");
|
printf ("can't detach\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char data[5];
|
char data[5];
|
||||||
data[0] = code;
|
data[0] = code;
|
||||||
data[1] = 0x4;
|
data[1] = 0x4;
|
||||||
data[2] = 0x4;
|
data[2] = 0x4;
|
||||||
data[3] = 0x4;
|
data[3] = 0x4;
|
||||||
data[4] = 0x4;
|
data[4] = 0x4;
|
||||||
|
|
||||||
int dummy;
|
int dummy;
|
||||||
libusb_claim_interface(devh,0);
|
libusb_claim_interface (devh, 0);
|
||||||
ret = libusb_interrupt_transfer(devh,0x2,data,5,&dummy,0);
|
ret = libusb_interrupt_transfer (devh, 0x2, data, 5, &dummy, 0);
|
||||||
if ( ret < 0 )
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
perror("error");
|
perror ("error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user