audiohacked / OpenCorsairLink

Linux and Mac OS support for the CorsairLink Devices
GNU General Public License v2.0
706 stars 125 forks source link

New CPU/Motherbord, H110i is no longer changing settings. #189

Closed cbacott closed 5 years ago

cbacott commented 5 years ago

Describe the bug Since upgrading to a Ryzen 3700 and Prime X370-pro, cannot control my Corsair H110i. Command says it detects the device, and dmesg shows the scan successfully, however pump and fan speed do not change. Dump is showing something weird at the end:

$ sudo ./OpenCorsairLink.elf --dump
Checking USB device 0 (05e3:0616)...
Checking USB device 1 (1d6b:0003)...
Checking USB device 2 (05e3:0610)...
Checking USB device 3 (1d6b:0002)...
Checking USB device 4 (1d6b:0003)...
Checking USB device 5 (046d:c338)...
Checking USB device 6 (046d:c069)...
Checking USB device 7 (1d6b:0002)...
Checking USB device 8 (1d6b:0003)...
Checking USB device 9 (0a12:0001)...
Checking USB device 10 (1b1c:0c04)...
Corsair product detected. Checking if device is H80... No (device_id 0x42)
Corsair product detected. Checking if device is Cooling Node... No (device_id 0x42)
Corsair product detected. Checking if device is Lighting Node... No (device_id 0x42)
Corsair product detected. Checking if device is H100... No (device_id 0x42)
Corsair product detected. Checking if device is H80i... No (device_id 0x42)
Corsair product detected. Checking if device is H100i... No (device_id 0x42)
Corsair product detected. Checking if device is Commander Mini... No (device_id 0x42)
Corsair product detected. Checking if device is H100i GT... No (device_id 0x42)
Corsair product detected. Checking if device is H110i GT... No (device_id 0x42)
Corsair product detected. Checking if device is H110i... Dev=0, CorsairLink Device Found: H110i!
Checking USB device 11 (1d6b:0002)...

DEBUG: scan done, start routines
DEBUG: device_number = -1

The following command used to set the first fan into full bore loud mode, it doesn't seem to do anything anymore.

$ sudo ./OpenCorsairLink.elf --fan channel=1,mode=5
Dev=0, CorsairLink Device Found: H110i!

Desktop (please complete the following information):

mazunki commented 5 years ago

I also need to add the --device 0 option. I'm not being allowed to use fan mode 0 or 1. My fans were at 500rpm, now I got them up to 1000, unintentionally. Can't seem to lower them again.

cbacott commented 5 years ago

Yeah, something changed for me. I'm now not able to run it with --device=0. I was looking at the code and decided to start fresh, so I rm'd the whole thing and re-cloned the git. Now, it won't do anything, if I set device=0 it says it's out of range. Not sure what changed here. I'm poking around the code.

EDIT: Dammit, nvm. I wasn't running it with sudo while debugging, and forgot that I needed to. It's working still with sudo. Still messing around in the code.

EDIT2: Temporary fix for me, you can try this and recompile. Open main.c, change line 67 from -1 to 0. That's setting the initial value of device_number to 0 rather than -1. I don't know what the author was trying to do by making that -1, so it's a hack at this point. But, it seems to work for me.

Basically, device_number is initialized to -1 normally, the scan happens and the scan returns the number of devices found. After that, it checks if device_number is >= 0, though I think they meant to check scanlist_count? Doing that causes a seg-fault, so I'm only guessing at their intentions. Anyway, since device_number is still -1 from initialization, it never goes into that block to actually do anything. That's why it worked for me to set device=0 manually. I don't see what harm there is in initializing that value to 0 rather than -1. The next bit after checking that device_number >= 0 compares it to scanlist_count, and since a normal user couldn't open any of the devs, the value is 0 and it just does nothing, with an error message that might need tweaking. Then, it exits. However, if one runs it with sudo, scanlist_count is 1, thus the code continues and it all works.

I'm not sure what issue you're having exactly, mazunki, but this quick hack has made this app work for me.

EDIT3: Final edit. I figured they really did mean to check scanlist_count, just needed to have device_number >= 0 afterwards, as the seg fault comes from trying to set an array to -1. I switched back to -1 initialization, but tweaked the whole if block starting at line 90 to properly handle detecting no detected devices, and if devices detected then properly set it. Again, not sure what the author was attempting to do so I can't comment on how this would handle multiple devices. I'm setting device_number = scanlist_count-1 which I know is only going to by default access the last device found. Maybe there was supposed to be some other logic in there to loop through them?

Anyway, until author checks on this, if anyone is interested in that quick hack patch here it is.

--- main.c.orig 2019-08-11 11:14:42.255704603 -0500
+++ main.c  2019-08-11 11:36:30.379459920 -0500
@@ -87,7 +87,7 @@
     msg_debug( "DEBUG: scan done, start routines\n" );
     msg_debug( "DEBUG: selected device_number = %d\n", device_number );

-    if ( device_number >= 0 )
+    if ( scanlist_count > 0 )
     {
         if ( device_number >= scanlist_count )
         {
@@ -97,6 +97,7 @@
         }
         else
         {
+            device_number = scanlist_count-1;
             if ( scanlist[device_number].device->driver == &corsairlink_driver_rmi )
             {
                 psu_settings( scanlist[device_number], flags, settings );
@@ -119,6 +121,10 @@
             }
         }
     }
+    else
+    {
+        msg_info("No devices detected. You may not have permissions to access the device.\n");
+    }

 exit:
     corsairlink_close( context );
audiohacked commented 5 years ago

device_number is set to -1 so that it forces the user to select the intended device. What this hack does is always select the last detected device which breaks usability for myself (since I have several devices that uses this utility).

cbacott commented 5 years ago

That is a bit embarrassing, I didn't consider that. This patch will allow selecting of another device, while also providing a default selection like before, and also spits out a good error message to notify the user that they need permission to access the devices.

--- main.c.orig 2019-08-11 11:14:42.255704603 -0500
+++ main.c  2019-08-13 21:30:08.147805494 -0500
@@ -64,7 +64,7 @@
 {
     int rr; // result from libusb functions

-    int8_t device_number = -1;
+    int8_t device_number = 0;

     int scanlist_count = 0;

@@ -87,7 +87,7 @@
     msg_debug( "DEBUG: scan done, start routines\n" );
     msg_debug( "DEBUG: selected device_number = %d\n", device_number );

-    if ( device_number >= 0 )
+    if ( scanlist_count > 0 )
     {
         if ( device_number >= scanlist_count )
         {
@@ -119,6 +119,10 @@
             }
         }
     }
+    else
+    {
+        msg_info("No devices detected. You may not have permissions to access the device.\n");
+    }

 exit:
     corsairlink_close( context );
mazunki commented 5 years ago

@cbacott

My error is different. I made an issue for it at #195 .

mazunki commented 5 years ago

Changing

-    int8_t device_number = -1;
+    int8_t device_number = 0;

followed by sudo make install does the trick for me, having only one device to care about.

I still need to use channel=0, though, followed by the same command with channel=1.