diogotr7 / OpenRGB.NET

C# client for the OpenRGB SDK
MIT License
40 stars 16 forks source link

How to "poke" devices when Computer wake up from sleep #28

Open Kaitoukid93 opened 1 year ago

Kaitoukid93 commented 1 year ago

I have been digging around for this kind of behavior. When computer wake up from sleep, some (or all) device keep their "hardware lighting" effect and not receiving OpenRGB direct color I have to manually load a profile (with all device set to direct mode) and then all devices show the color from OpenRGB (which is sent from my app's client) The problem is Client.LoadProfile("string profileName"); seems to have effect sometimes but not when the computer wake up from sleep. I have checked the log file and see OpenRGB actually loaded the profile, but in the GUI, the parameters not change, I have to manually click the Load Profile button

Below is the log file and the specific task (recorded since computer wakeup and my app try to RefreshOpenRGBDeviceState() but has no effect, then I have to click the Load Profile Button

62403 |Info:    Found file: default.orp attempting to validate header
62404 |Info:    Valid v4 profile found for default
62404 |Info:    Found file: default2.orp attempting to validate header
62424 |Info:    Valid v4 profile found for default2
78720 |Info:    Found file: default.orp attempting to validate header
78720 |Info:    Valid v4 profile found for default
78720 |Info:    Found file: default2.orp attempting to validate header
78730 |Info:    Valid v4 profile found for default2
150032|Info:    Closing server connection: 127.0.0.1
150091|Info:    Profile loading: Succeeded for ENE DRAM @ I2C: Intel(R) SMBus - 06A3, address 0x70
150091|Info:    Profile loading: Succeeded for Logitech G903 Wired/Wireless Gaming Mouse @ HID: \\?\HID#VID_046D&PID_C539&MI_02&Col01#8&28218130&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} (Receiver) 
Wireless Index: 1
150091|Info:    Profile loading: Succeeded for MSI MEG Z490 ACE (MS-7C71) @ HID: \\?\HID#VID_1462&PID_7C71#6&1a58bd65&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
177429|Info:    Profile loading: Succeeded for ENE DRAM @ I2C: Intel(R) SMBus - 06A3, address 0x70
177429|Info:    Profile loading: Succeeded for Logitech G903 Wired/Wireless Gaming Mouse @ HID: \\?\HID#VID_046D&PID_C539&MI_02&Col01#8&28218130&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} (Receiver) 
Wireless Index: 1
177429|Info:    Profile loading: Succeeded for MSI MEG Z490 ACE (MS-7C71) @ HID: \\?\HID#VID_1462&PID_7C71#6&1a58bd65&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
 public async Task<bool> RefreshOpenRGBDeviceState()
 {

     if (Client != null)
         Client.Dispose();
     Client = new OpenRGBClient("127.0.0.1", 6742, name: "Ambinity", autoconnect: true, timeout: 1000, protocolVersion: 2);
     if (Client != null)
     {
         //check if we get any device from Openrgb
         //create default profile if not exist
         if (Client.GetControllerCount() > 0)
         {
             var devices = Client.GetAllControllerData();
             int index = 0;
             var profiles = Client.GetProfiles();
             if (!profiles.Any(p => p == "default"))
             {
                 foreach (var device in devices)
                 {
                     for (var i = 0; i < device.Modes.Length; i++)
                     {
                         Debug.WriteLine(device.Modes[i].Name.ToString());
                         if (device.Modes[i].Name == "Direct")
                         {
                             Client.SetMode(index, i);
                         }
                     }
                     index++;

                     Log.Information($"Device found : " + device.Name.ToString() + "At index: " + index);

                 }
                 Client.SaveProfile("default");
                 Log.Information("Saving OpenRGB Default Profile");
             }

             Client.LoadProfile("default");
             await Task.Delay(500);
             Log.Information("Loading OpenRGB Default Profile");
             return await Task.FromResult(true);
         }
         else // this could happen due to device scanning is in progress
         {
             //dispose the client
             Client.Dispose();
             throw (new Exception("ORGB busy"));
             // throw some type of exception , now retry policy will catch the exception and retry
         }
     }
     return await Task.FromResult(false);
 }
diogotr7 commented 1 year ago

Hey, I don't have any specific information to give as this client only sends commands. It's up to the server to handle reconnects properly. You could try adding a delay before the new profile is loaded, maybe that helps.