diff --git a/src/argbColors.c b/src/argbColors.c index bfbcb46..beb92a9 100644 --- a/src/argbColors.c +++ b/src/argbColors.c @@ -26,7 +26,7 @@ int findDevice(libusb_device *dev){ } if (desc.idVendor == VID && desc.idProduct == PID){ - printf("Found VID:PID device: %04x:%04x\n", desc.idVendor, desc.idProduct); + printf("Device found: %04x:%04x\n", desc.idVendor, desc.idProduct); return 1; } @@ -76,8 +76,10 @@ int main(int argc, char *argv[]) { } // We will rule, not kernel modules :D - printf("libusb_set_auto_detach_kernel_driver - %d\n", libusb_set_auto_detach_kernel_driver(dev_handle, 1)); - + ret = libusb_set_auto_detach_kernel_driver(dev_handle, 1); +#ifdef DEBUG + printf("libusb_set_auto_detach_kernel_driver - %d\n", ret); + // Let's find out current CONFIGURATION int bConfigurationValue; ret = libusb_get_configuration(dev_handle, &bConfigurationValue); @@ -86,17 +88,19 @@ int main(int argc, char *argv[]) { printf("libusb_get_configuration failed: %d\n", ret); return ret; } + printf("Current bConfigurationValue: %d\n", bConfigurationValue); - - // if device used by kernel drivers already +#endif + // Check if device used by kernel drivers already ret = libusb_kernel_driver_active(dev_handle, 1); - printf("libusb_kernel_driver_active: %d\n", ret); - + printf("Kernel driver is%s", ret == 0?" not active\n":"active and "); + + // Active? Let's try to get control if(ret != LIBUSB_ERROR_NOT_SUPPORTED && ret < 0){ ret = libusb_detach_kernel_driver(dev_handle, 1); if (ret != LIBUSB_ERROR_NOT_SUPPORTED && ret < 0) { libusb_exit(NULL); - printf("libusb_detach_kernel_driver failed: %d\n", ret); + printf("detach kernel driver attempt failed: %d\n", ret); return ret; } } @@ -128,12 +132,19 @@ int main(int argc, char *argv[]) { return -1; } + if (impulse(0, 0xff, 0x2f, 0xff)){ + printf("Command transfer failure\n"); + libusb_close(dev_handle); + return -1; + } +/* + // 0xff, 0x2f, 0xff <3 if(staticColorSeparate(0xff, 0xff, 0x2b, 0x00)){ printf("Command transfer failure\n"); libusb_close(dev_handle); return -1; } - +//*/ if (terminate_sequence()){ printf("Termination sequence transfer failure\n"); libusb_close(dev_handle); diff --git a/src/commands.c b/src/commands.c index 050e6db..51569f6 100644 --- a/src/commands.c +++ b/src/commands.c @@ -61,17 +61,17 @@ int staticColorSeparate(unsigned char brightness, unsigned char red, unsigned ch counter = 0; limit = 7; - //cc 22 04 00 00 00 00 00 00 00 00 01__00______ + //cc 22 04 00 00 00 00 00 00 00 00 01 __ 00 __ __ __ unsigned char dir1[64] = { 0xcc, 0x22, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red, }; - //cc 24 10 00 00 00 00 00 00 00 00 01__00______ + //cc 24 10 00 00 00 00 00 00 00 00 01 __ 00 __ __ __ unsigned char dir2[64] = { 0xcc, 0x24, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red, }; - //cc 25 20 00 00 00 00 00 00 00 00 01__00______ + //cc 25 20 00 00 00 00 00 00 00 00 01 __ 00 __ __ __ unsigned char dir3[64] = { 0xcc, 0x25, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red, }; - //cc 26 40 00 00 00 00 00 00 00 00 01__00______ + //cc 26 40 00 00 00 00 00 00 00 00 01 __ 00 __ __ __ unsigned char dir4[64] = { 0xcc, 0x26, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red, }; - //cc 27 80 00 00 00 00 00 00 00 00 01__00______ + //cc 27 80 00 00 00 00 00 00 00 00 01 __ 00 __ __ __ unsigned char dir5[64] = { 0xcc, 0x27, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red, }; - //cc 91 00 02 00 00 00 00 00 00 00 01__00______ + //cc 91 00 02 00 00 00 00 00 00 00 01 __ 00 __ __ __ unsigned char dir6[64] = { 0xcc, 0x91, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red, }; if(64 != writeUsb(dir1)) @@ -213,4 +213,107 @@ int wave2(){ printf("\rWave 2 (Sync) sequence sent\n"); return 0; -} \ No newline at end of file +} + +int staticColorSync(unsigned char red, unsigned char green, unsigned char blue){ + if (prefix()) + return 1; + + counter = 0; + limit = 2; + + //cc 20 ff 07 00 00 00 00 00 00 00 01 ff 00 __ __ __ + unsigned char dir1[64] = { 0xcc, 0x20, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, blue, green, red, }; + + if(64 != writeUsb(dir1)) + return 1; + + if(64 != writeUsb(end_transaction)) + return 1; + + printf("\rStatic Color (Sync) sequence sent\n"); + + return 0; +} + +int impulse(int intensity, unsigned char red, unsigned char green, unsigned char blue){ + + unsigned char *I; + + switch (intensity){ + case 0: + I = (unsigned char [6]) { 0x40, 0x06, 0x40, 0x06, 0x20, 0x03 }; // 400640062003 + break; + case 1: + I = (unsigned char [6]) { 0xb0, 0x04, 0xb0, 0x04, 0xf4, 0x01 }; // b004b004f401 + break; + case 2: + I = (unsigned char [6]) { 0x84, 0x03, 0x84, 0x03, 0xc2, 0x01 }; // 84038403c201 + break; + case 3: + I = (unsigned char [6]) { 0xbc, 0x02, 0xbc, 0x02, 0x5e, 0x01 }; // bc02bc025e01 + break; + case 4: + I = (unsigned char [6]) { 0xf4, 0x01, 0xf4, 0x01, 0xfa, 0x00 }; // f401f401fa00 + break; + default: + printf("Intensity must be defined in range of 0..4\n"); + return 1; + } + + if (prefix()) + return 1; + + counter = 0; + limit = 7; + + //cc22040000000000000000026400______0000000000____________00000001 + unsigned char dir1[64] = { 0xcc, 0x22, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x64, 0x00, blue, green, + red, 0x00, 0x00, 0x00, 0x00, 0x00, I[0], I[1], I[2], I[3], I[4], I[5], 0x00, 0x00, 0x00, 0x01, }; + //cc24100000000000000000026400______0000000000____________00000001 + unsigned char dir2[64] = { 0xcc, 0x24, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x64, 0x00, blue, green, + red, 0x00, 0x00, 0x00, 0x00, 0x00, I[0], I[1], I[2], I[3], I[4], I[5], 0x00, 0x00, 0x00, 0x01, }; + //cc25200000000000000000026400______0000000000____________00000001 + unsigned char dir3[64] = { 0xcc, 0x25, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x64, 0x00, blue, green, + red, 0x00, 0x00, 0x00, 0x00, 0x00, I[0], I[1], I[2], I[3], I[4], I[5], 0x00, 0x00, 0x00, 0x01, }; + //cc26400000000000000000026400______0000000000____________00000001 + unsigned char dir4[64] = { 0xcc, 0x26, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x64, 0x00, blue, green, + red, 0x00, 0x00, 0x00, 0x00, 0x00, I[0], I[1], I[2], I[3], I[4], I[5], 0x00, 0x00, 0x00, 0x01, }; + //cc27800000000000000000026400______0000000000____________00000001 + unsigned char dir5[64] = { 0xcc, 0x27, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x64, 0x00, blue, green, + red, 0x00, 0x00, 0x00, 0x00, 0x00, I[0], I[1], I[2], I[3], I[4], I[5], 0x00, 0x00, 0x00, 0x01, }; + //cc91000200000000000000026400______0000000000____________00000001 + unsigned char dir6[64] = { 0xcc, 0x91, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x64, 0x00, blue, green, + red, 0x00, 0x00, 0x00, 0x00, 0x00, I[0], I[1], I[2], I[3], I[4], I[5], 0x00, 0x00, 0x00, 0x01, }; + + if(64 != writeUsb(dir1)) + return 1; + + if(64 != writeUsb(dir2)) + return 1; + + if(64 != writeUsb(dir3)) + return 1; + + if(64 != writeUsb(dir4)) + return 1; + + if(64 != writeUsb(dir5)) + return 1; + + if(64 != writeUsb(dir6)) + return 1; + + if(64 != writeUsb(end_transaction)) + return 1; + + printf("\rImpulse (Separate) sequence sent\n"); + + return 0; +} + + +// Impulse +// Flash +// 2xFlash +// Cycle \ No newline at end of file diff --git a/src/iousb.c b/src/iousb.c index 9497430..e8fee9d 100644 --- a/src/iousb.c +++ b/src/iousb.c @@ -26,7 +26,8 @@ int readUsb(){ } #ifdef DEBUG - printf("INPUT REQUEST\n"); + printf("INPUT RESPONSE:\n"); + print_array(buffer, 64); #endif return ret;