This commit is contained in:
parent
f33002f67e
commit
f9f79a4eeb
7 changed files with 355 additions and 244 deletions
|
@ -1,7 +1,7 @@
|
|||
# argb controls for 048d:5711 Integrated Technology Express, Inc. GIGABYTE Device
|
||||
|
||||
|
||||
 [](https://ci.redrise.ru/repos/13)
|
||||
 ](https://ci.redrise.ru/repos/13)
|
||||
|
||||
Reference hardware used: Z890 AORUS PRO ICE
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ cc38
|
|||
|
||||
### Commands / directives to apply changes
|
||||
|
||||
BRG abbreviation stands for Blue Red Green
|
||||
*BGR abbreviation stands for Blue Green Red*
|
||||
|
||||
There are two types of commands:
|
||||
* synchronized - applies same setting to everything
|
||||
|
|
211
src/argbColors.c
211
src/argbColors.c
|
@ -17,137 +17,130 @@
|
|||
|
||||
int findDevice(libusb_device *dev){
|
||||
|
||||
struct libusb_device_descriptor desc;
|
||||
struct libusb_device_descriptor desc;
|
||||
|
||||
int ret = libusb_get_device_descriptor(dev, &desc);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "failed to get device descriptor");
|
||||
return 0;
|
||||
}
|
||||
int ret = libusb_get_device_descriptor(dev, &desc);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "failed to get device descriptor");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (desc.idVendor == VID && desc.idProduct == PID){
|
||||
printf("Found VID:PID device: %04x:%04x\n", desc.idVendor, desc.idProduct);
|
||||
return 1;
|
||||
}
|
||||
if (desc.idVendor == VID && desc.idProduct == PID){
|
||||
printf("Found VID:PID device: %04x:%04x\n", desc.idVendor, desc.idProduct);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
libusb_context *context;
|
||||
int ret = libusb_init_context(&context, /*options=*/NULL, /*num_options=*/0);
|
||||
if (ret < 0){
|
||||
printf("libusb_init_context failure\n");
|
||||
return ret;
|
||||
}
|
||||
libusb_context *context;
|
||||
int ret = libusb_init_context(&context, /*options=*/NULL, /*num_options=*/0);
|
||||
if (ret < 0){
|
||||
printf("libusb_init_context failure\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
libusb_device **devs;
|
||||
ssize_t count = libusb_get_device_list(context, &devs);
|
||||
if (count < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_get_device_list failed\n");
|
||||
return 1;
|
||||
}
|
||||
libusb_device **devs;
|
||||
ssize_t count = libusb_get_device_list(context, &devs);
|
||||
if (count < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_get_device_list failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get deivce list
|
||||
libusb_device* device = NULL;
|
||||
for (int i = 0; devs[i]; i++){
|
||||
if (findDevice(devs[i])){
|
||||
device = devs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Get device list
|
||||
libusb_device* device = NULL;
|
||||
for (int i = 0; devs[i]; i++){
|
||||
if (findDevice(devs[i])){
|
||||
device = devs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (device == NULL){
|
||||
libusb_exit(NULL);
|
||||
printf("Device not found\n");
|
||||
return 1;
|
||||
}
|
||||
if (device == NULL){
|
||||
libusb_exit(NULL);
|
||||
printf("Device not found\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Free deivce list
|
||||
libusb_free_device_list(devs, 1);
|
||||
/*
|
||||
libusb_device_handle* device = libusb_open_device_with_vid_pid(context, VID, PID);
|
||||
// Free device list
|
||||
libusb_free_device_list(devs, 1);
|
||||
|
||||
if (device == NULL)
|
||||
printf("Device not found\n");
|
||||
*/
|
||||
ret = libusb_open(device, &dev_handle);
|
||||
if (ret < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_open failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = libusb_open(device, &dev_handle);
|
||||
if (ret < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_open failed\n");
|
||||
return ret;
|
||||
}
|
||||
// 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));
|
||||
|
||||
// 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));
|
||||
// Let's find out current CONFIGURATION
|
||||
int bConfigurationValue;
|
||||
ret = libusb_get_configuration(dev_handle, &bConfigurationValue);
|
||||
if (ret < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_get_configuration failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
printf("Current bConfigurationValue: %d\n", bConfigurationValue);
|
||||
|
||||
// Let's find out current CONFIGURATION
|
||||
int bConfigurationValue;
|
||||
ret = libusb_get_configuration(dev_handle, &bConfigurationValue);
|
||||
if (ret < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_get_configuration failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
printf("Current bConfigurationValue: %d\n", bConfigurationValue);
|
||||
// if device used by kernel drivers already
|
||||
ret = libusb_kernel_driver_active(dev_handle, 1);
|
||||
printf("libusb_kernel_driver_active: %d\n", ret);
|
||||
|
||||
// Set configuration (soft reset device)
|
||||
// if device used by kernel drivers already
|
||||
ret = libusb_kernel_driver_active(dev_handle, 1);
|
||||
printf("libusb_kernel_driver_active: %d\n", ret);
|
||||
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);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
/*
|
||||
// Now let's reset device
|
||||
// Or just comment it out, since it's always this kinda shit appears: [25465.608100] usb 3-13: usbfs: interface 0 claimed by usbhid while 'argbColors' sets config #1
|
||||
// Either way it works
|
||||
ret = libusb_set_configuration(dev_handle, 1);
|
||||
if (ret < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_set_configuration failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Now let's reset device
|
||||
// Or just comment it out, since it's always this kinda shit appears: [25465.608100] usb 3-13: usbfs: interface 0 claimed by usbhid while 'argbColors' sets config #1
|
||||
// Either way it works
|
||||
ret = libusb_set_configuration(dev_handle, 1);
|
||||
if (ret < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_set_configuration failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
|
||||
// Claim interface
|
||||
ret = libusb_claim_interface(dev_handle, 1);
|
||||
if (ret < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_claim_interface failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
// Claim interface
|
||||
ret = libusb_claim_interface(dev_handle, 1);
|
||||
if (ret < 0) {
|
||||
libusb_exit(NULL);
|
||||
printf("libusb_claim_interface failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
if (init_sequence()){
|
||||
printf("Initial sequence transfer failure\n");
|
||||
libusb_close(dev_handle);
|
||||
return -1;
|
||||
}
|
||||
if (init_sequence()){
|
||||
printf("Initial sequence transfer failure\n");
|
||||
libusb_close(dev_handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(staticColorSeparate(0xff, 0xff, 0x2b, 0x00)){
|
||||
printf("Command transfer failure\n");
|
||||
libusb_close(dev_handle);
|
||||
return -1;
|
||||
}
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
if (terminate_sequence()){
|
||||
printf("Termination sequence transfer failure\n");
|
||||
libusb_close(dev_handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
libusb_close(dev_handle);
|
||||
libusb_close(dev_handle);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
204
src/commands.c
204
src/commands.c
|
@ -1,55 +1,56 @@
|
|||
unsigned char end_transaction[64] = { 0xcc, 0x28, 0xff, 0x07, }; //cc28ff07
|
||||
unsigned char end_alt_transaction[64] = { 0xcc, 0x28, 0x04, }; //cc2804
|
||||
|
||||
int prefix(){
|
||||
counter = 0;
|
||||
limit = 12; // flow contains 12 I/O events
|
||||
limit = 12; // flow contains 12 I/O events
|
||||
|
||||
unsigned char message[64] = {0xcc, 0x20, };
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x21;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x22;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x23;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x24;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x25;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x26;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x27;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x90;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x91;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x92;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
if(64 != writeUsb(end_transaction))
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -59,42 +60,159 @@ int staticColorSeparate(unsigned char brightness, unsigned char red, unsigned ch
|
|||
return 1;
|
||||
|
||||
counter = 0;
|
||||
limit = 7;
|
||||
limit = 7;
|
||||
//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 };
|
||||
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______
|
||||
unsigned char dir2[64] = { 0xcc, 0x24, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red };
|
||||
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______
|
||||
unsigned char dir3[64] = { 0xcc, 0x25, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red };
|
||||
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______
|
||||
unsigned char dir4[64] = { 0xcc, 0x26, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red };
|
||||
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______
|
||||
unsigned char dir5[64] = { 0xcc, 0x27, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red };
|
||||
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______
|
||||
unsigned char dir6[64] = { 0xcc, 0x91, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, brightness, 0x00, blue, green, red };
|
||||
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))
|
||||
return 1;
|
||||
if(64 != writeUsb(dir1))
|
||||
return 1;
|
||||
|
||||
if(64 != writeUsb(dir2))
|
||||
return 1;
|
||||
if(64 != writeUsb(dir2))
|
||||
return 1;
|
||||
|
||||
if(64 != writeUsb(dir3))
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
if(64 != writeUsb(dir4))
|
||||
return 1;
|
||||
if(64 != writeUsb(dir4))
|
||||
return 1;
|
||||
|
||||
if(64 != writeUsb(dir5))
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
if(64 != writeUsb(dir6))
|
||||
return 1;
|
||||
if(64 != writeUsb(dir6))
|
||||
return 1;
|
||||
|
||||
if(64 != writeUsb(end_transaction))
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
printf("\rStatic Color (Separate) sequence sent\n");
|
||||
printf("\rStatic Color (Separate) sequence sent\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int turnOffBacklight(){
|
||||
if (prefix())
|
||||
return 0;
|
||||
|
||||
counter = 0;
|
||||
limit = 7;
|
||||
|
||||
//cc 22 04 00 00 00 00 00 00 00 00 01 ff
|
||||
unsigned char dir1[64] = { 0xcc, 0x22, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, };
|
||||
//cc 24 10 00 00 00 00 00 00 00 00 01 ff
|
||||
unsigned char dir2[64] = { 0xcc, 0x24, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, };
|
||||
//cc 25 20 00 00 00 00 00 00 00 00 01 ff
|
||||
unsigned char dir3[64] = { 0xcc, 0x25, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, };
|
||||
//cc 26 40 00 00 00 00 00 00 00 00 01 ff
|
||||
unsigned char dir4[64] = { 0xcc, 0x26, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, };
|
||||
//cc 27 80 00 00 00 00 00 00 00 00 01 ff
|
||||
unsigned char dir5[64] = { 0xcc, 0x27, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, };
|
||||
//cc 91 00 02 00 00 00 00 00 00 00 01 ff
|
||||
unsigned char dir6[64] = { 0xcc, 0x91, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, };
|
||||
|
||||
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("\rTurn off backlight (Separate) sequence sent\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int turnOffBacklightSync(){
|
||||
if (prefix())
|
||||
return 0;
|
||||
|
||||
counter = 0;
|
||||
limit = 2;
|
||||
|
||||
//cc 20 ff 07 00 00 00 00 00 00 00 01 ff
|
||||
unsigned char dir1[64] = { 0xcc, 0x20, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, };
|
||||
|
||||
if(64 != writeUsb(dir1))
|
||||
return 1;
|
||||
|
||||
if(64 != writeUsb(end_transaction))
|
||||
return 1;
|
||||
|
||||
printf("\rTurn off backlight (Sync) sequence sent\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wave1(){
|
||||
//cc 20 ff 07 00 00 00 00 00 00 00 01 ff ← turns off backlight
|
||||
//cc28ff07
|
||||
turnOffBacklightSync();
|
||||
|
||||
counter = 0;
|
||||
limit = 2;
|
||||
|
||||
//cc 22 00 00 00 00 00 00 00 00 00 09 64 00 00 00 00 00 00 00 00 00 26 02 00 00 00 00 00 00 07
|
||||
unsigned char dir1[64] = { 0xcc, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x64, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, };
|
||||
|
||||
if(64 != writeUsb(dir1))
|
||||
return 1;
|
||||
|
||||
//cc2804
|
||||
if(64 != writeUsb(end_alt_transaction))
|
||||
return 1;
|
||||
|
||||
unsigned char dir1[64] = { 0xcc, };
|
||||
|
||||
printf("\rWave 1 (Sync) sequence sent\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wave2(){
|
||||
//cc 20 ff 07 00 00 00 00 00 00 00 01 ff ← turns off backlight
|
||||
//cc28ff07
|
||||
turnOffBacklightSync();
|
||||
|
||||
counter = 0;
|
||||
limit = 2;
|
||||
|
||||
//cc 22 00 00 00 00 00 00 00 00 00 0a 64 00 00 00 00 00 00 00 00 00 7d 00 00 00 00 00 00 00 20
|
||||
unsigned char dir1[64] = { 0xcc, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x64, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, };
|
||||
|
||||
if(64 != writeUsb(dir1))
|
||||
return 1;
|
||||
|
||||
//cc2804
|
||||
if(64 != writeUsb(end_alt_transaction))
|
||||
return 1;
|
||||
|
||||
printf("\rWave 2 (Sync) sequence sent\n");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
void print_array(unsigned char* buf, int size){
|
||||
|
||||
int j = 0;
|
||||
for(int i = 0; i < size; i++) {
|
||||
printf("%02x ", buf[i]);
|
||||
for(int i = 0; i < size; i++) {
|
||||
printf("%02x ", buf[i]);
|
||||
|
||||
if (++j % 8 == 0)
|
||||
printf(" ");
|
||||
if (++j % 8 == 0)
|
||||
printf(" ");
|
||||
|
||||
if (j % 16 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
if (j % 16 == 0)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
|
@ -1,87 +1,87 @@
|
|||
int init_sequence(){
|
||||
counter = 0;
|
||||
limit = 18; // Initialization flow contains 18 I/O events
|
||||
counter = 0;
|
||||
limit = 18; // Initialization flow contains 18 I/O events
|
||||
|
||||
unsigned char message[64] = { 0xcc, 0x60, };
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
unsigned char message[64] = { 0xcc, 0x60, };
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
|
||||
message[1] = 0x60;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x60;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
|
||||
message[1] = 0x34;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x34;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x48;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x48;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
|
||||
message[1] = 0x61;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x61;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
|
||||
message[1] = 0x3c;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x3c;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x3e;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x3e;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
|
||||
message[1] = 0x34;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x34;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x3d;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x3d;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x3f;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x3f;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
if(64 != readUsb())
|
||||
return 1;
|
||||
|
||||
message[1] = 0x34;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x34;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
message[1] = 0x38;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
message[1] = 0x38;
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
printf("\rInitialization sequence sent\n");
|
||||
printf("\rInitialization sequence sent\n");
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int terminate_sequence(){
|
||||
counter = 0;
|
||||
limit = 1;
|
||||
counter = 0;
|
||||
limit = 1;
|
||||
|
||||
unsigned char message[64] = { 0xcc, 0x47, 0x01, }; //cc4701
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
unsigned char message[64] = { 0xcc, 0x47, 0x01, }; //cc4701
|
||||
if(64 != writeUsb(message))
|
||||
return 1;
|
||||
|
||||
printf("\rTermination sequence sent\n");
|
||||
printf("\rTermination sequence sent\n");
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
28
src/iousb.c
28
src/iousb.c
|
@ -1,33 +1,33 @@
|
|||
int writeUsb(unsigned char *message){
|
||||
#ifndef DEBUG
|
||||
#ifndef DEBUG
|
||||
printf("\r%02d / %02d (write)", ++counter, limit);
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
print_array(message, 64);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
print_array(message, 64);
|
||||
#endif
|
||||
int ret = libusb_control_transfer(dev_handle, 0x21, 9, 0x03cc, 1, message, 64, TIMEOUT);
|
||||
if(ret != 64){
|
||||
printf("\nFailure: %d\n", ret);
|
||||
printf("\nFailure: %d\n", ret);
|
||||
print_array(message, 64);
|
||||
}
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int readUsb(){
|
||||
#ifndef DEBUG
|
||||
#ifndef DEBUG
|
||||
printf("\r%02d / %02d (read)", ++counter, limit);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
unsigned char buffer[64] = {};
|
||||
int ret = libusb_control_transfer(dev_handle, 0xa1, 1, 0x03cc, 1, buffer, 64, TIMEOUT);
|
||||
unsigned char buffer[64] = {};
|
||||
int ret = libusb_control_transfer(dev_handle, 0xa1, 1, 0x03cc, 1, buffer, 64, TIMEOUT);
|
||||
if(ret != 64){
|
||||
printf("\nFailure: %d\n", ret);
|
||||
printf("\nFailure: %d\n", ret);
|
||||
print_array(buffer, 64);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
printf("INPUT REQUEST\n");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in a new issue