jath03 / openrgb-python

A python client for the OpenRGB SDK
GNU General Public License v3.0
115 stars 22 forks source link

Finding the size of DRGB LEDs #15

Closed subterfugium closed 3 years ago

subterfugium commented 3 years ago

I'm trying to do something like this:

motherboard = client.get_devices_by_type(DeviceType.MOTHERBOARD)
for mobo in motherboard:
    for zone in mobo.zones:
        # Addressable RGBs
        if zone.type == ZoneType.LINEAR:
            # Check if direct mode is in use
            if mobo.active_mode != 0:
                for mode in mobo.modes:
                    if mode.name == 'Direct':
                        mobo.set_mode('Direct')
            find_led_count(zone)

And

def find_led_count(zone):
    for size in range(1, 100):
        zone.resize(size)
        zone.set_color(RGBColor(255, 255, 255), start=size, end=size, fast=False)

I was hoping that when resize is more than actual amount of leds in fan/led strip there would be exception that I could catch. At the moment python-openrgb seems to get stuck waiting for openrgb when I resize to 10 (avaialble leds is 9). All leds go black (I take this indication that led controller detected bad configuration) and:

^CTraceback (most recent call last):
  File "/usr/local/bin/rgb", line 135, in <module>
    find_led_count(zone)
  File "/usr/local/bin/rgb", line 78, in find_led_count
    zone.set_color(RGBColor(123, 123,0 ), start=size, end=size, fast=False)
  File "/usr/lib/python3.8/site-packages/openrgb/orgb.py", line 80, in set_color
    self.update()
  File "/usr/lib/python3.8/site-packages/openrgb/utils.py", line 549, in update
    self.comms.requestDeviceData(self.device_id)
  File "/usr/lib/python3.8/site-packages/openrgb/network.py", line 119, in requestDeviceData
    self.read()
  File "/usr/lib/python3.8/site-packages/openrgb/network.py", line 77, in read
    self.sock.recv_into(header)
KeyboardInterrupt

And openrgb outputs not and if you try to stop it then:

Attempting to connect to local OpenRGB server.
Connection attempt failed
Local OpenRGB server unavailable, running standalone.
Network connection thread started on port 6742
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
Network server started
Server connection closed
terminate called after throwing an instance of 'std::system_error'
  what():  Invalid argument
Aborted

Is this possible or is there just bug in python-openrgb (Version: 0.2.3) or openrgb (0.5)?

EDIT: upgraded python-openrgb to 0.2.5 but behaviour seems to be same.

jath03 commented 3 years ago

Unfortunately, OpenRGB has no idea how many ARGB LEDs are connected to the header (that's why there is a resize option at all), so there will never be any error for you catch. The error you are running into is probably caused by repeatedly calling resize and set_color without any delay. This warning from the docs actually applies to any operation that interacts with SDK server. I'll update the docs to reflect that. image Does resizing to 10 LEDs cause the error even when done outside of a loop? If so, does resizing to 10 LEDs cause the error if you do it with the resize button on OpenRGB itself?

subterfugium commented 3 years ago

Resizing to 10 with delay or from openrgb GUI does not cause this error. It just happened to happen when doing resizing in loop :) So I can forget trying to find correct LED size. Why I was asking this is that it seems that resize() does not seem to change zone.leds list at the first run.

If I turn on openrgb server and do this for every ZoneType.Linear device (ARGB_LEDS = 9, the amount of leds in my fans):

loop:
print('zone %s type %s' % (zone.name, zone.type))
if len(zone.leds) != ARGB_LEDS:
      print('resize to %s' % ARGB_LEDS)
      zone.resize(ARGB_LEDS)
      time.sleep(0.1)
      print('led count: %s' % len(zone.leds))

I get prints:

zone D_LED1 Bottom type ZoneType.LINEAR
resize to 9
led count: 10

zone D_LED2 Top type ZoneType.LINEAR
resize to 9
led count: 0

zone D_LED1 Bottom type ZoneType.LINEAR
resize to 9
led count: 0

zone D_LED2 Top type ZoneType.LINEAR
resize to 9
led count: 0

If I do the same with 3 second delay I get same result (run openrgb server and run script). I don't close openrgb between runs, then led count is correct at second run. If I run resize(), when it is expected to zone.leds list be populated?

Here is both runs with prints from my rgb script 3second delay after resize (script generates random colors and sets them to all devices):

subterfugium@pc:~$ rgb
B550 AORUS ELITE
zone D_LED1 Bottom type ZoneType.LINEAR
resize to 9
led count: 10

 - Set D_LED1 Bottom ARGB 10 leds to rosybrown greenyellow (gradient=False)
zone D_LED2 Top type ZoneType.LINEAR
resize to 9
led count: 0

 - Set D_LED2 Top ARGB 0 leds to rosybrown greenyellow (gradient=False)
zone Motherboard type ZoneType.SINGLE
 - Set Back I/O one of ['rosybrown', 'greenyellow'] colors
 - Set CPU Header one of ['rosybrown', 'greenyellow'] colors
 - Set PCIe one of ['rosybrown', 'greenyellow'] colors
 - Set LED C1/C2 one of ['rosybrown', 'greenyellow'] colors
B550 AORUS ELITE
zone D_LED1 Bottom type ZoneType.LINEAR
resize to 9
led count: 0

 - Set D_LED1 Bottom ARGB 0 leds to rosybrown greenyellow (gradient=False)
zone D_LED2 Top type ZoneType.LINEAR
resize to 9
led count: 0

 - Set D_LED2 Top ARGB 0 leds to rosybrown greenyellow (gradient=False)
zone Motherboard type ZoneType.SINGLE
 - Set Back I/O one of ['rosybrown', 'greenyellow'] colors
 - Set CPU Header one of ['rosybrown', 'greenyellow'] colors
 - Set PCIe one of ['rosybrown', 'greenyellow'] colors
 - Set LED C1/C2 one of ['rosybrown', 'greenyellow'] colors
ASUS Aura DRAM
 - Set ASUS Aura DRAM RAM 8 leds to rosybrown greenyellow (gradient=False)
ASUS Aura DRAM
 - Set ASUS Aura DRAM RAM 8 leds to rosybrown greenyellow (gradient=False)

subterfugium@pc:~$ rgb
B550 AORUS ELITE
zone D_LED1 Bottom type ZoneType.LINEAR
 - Set D_LED1 Bottom ARGB 9 leds to magenta yellow (gradient=True)
zone D_LED2 Top type ZoneType.LINEAR
 - Set D_LED2 Top ARGB 9 leds to magenta yellow (gradient=True)
zone Motherboard type ZoneType.SINGLE
 - Set Back I/O one of ['magenta', 'yellow'] colors
 - Set CPU Header one of ['magenta', 'yellow'] colors
 - Set PCIe one of ['magenta', 'yellow'] colors
 - Set LED C1/C2 one of ['magenta', 'yellow'] colors
B550 AORUS ELITE
zone D_LED1 Bottom type ZoneType.LINEAR
 - Set D_LED1 Bottom ARGB 9 leds to magenta yellow (gradient=True)
zone D_LED2 Top type ZoneType.LINEAR
 - Set D_LED2 Top ARGB 9 leds to magenta yellow (gradient=True)
zone Motherboard type ZoneType.SINGLE
 - Set Back I/O one of ['magenta', 'yellow'] colors
 - Set CPU Header one of ['magenta', 'yellow'] colors
 - Set PCIe one of ['magenta', 'yellow'] colors
 - Set LED C1/C2 one of ['magenta', 'yellow'] colors
ASUS Aura DRAM
 - Set ASUS Aura DRAM RAM 8 leds to magenta yellow (gradient=True)
ASUS Aura DRAM
 - Set ASUS Aura DRAM RAM 8 leds to magenta yellow (gradient=True)
jath03 commented 3 years ago

Ah, I see the problem. When openrgb-python gets the new information from the server (new LEDs), it isn't updating zones stored in separate variables. For you right now, a workaround is to not store zones in separate variables from the device. Like using device.zones[i] instead of assigning zone = device.zones[i] and using zone. I should get a fix for this in the next few days, but I'm not sure when the fix will make it into a pypi release.

subterfugium commented 3 years ago

Oh okay. I can can pull and do local pip install, just let me know!

jath03 commented 3 years ago

Can you test how it works on the latest commit and reopen the issue if there are any problems?

subterfugium commented 3 years ago

Yes, now leds count is updated after using resize

B550 AORUS ELITE
+ zone D_LED1 Bottom type ZoneType.LINEAR
resize to 9
led count: 9
 - Set D_LED1 Bottom ARGB 9 leds to lightsalmon orchid darkred (gradient=False)
+ zone D_LED2 Top type ZoneType.LINEAR
resize to 9
led count: 9
 - Set D_LED2 Top ARGB 9 leds to lightsalmon orchid darkred (gradient=False)
+ zone Motherboard type ZoneType.SINGLE
 - Set Back I/O one of ['lightsalmon', 'orchid', 'darkred'] colors
 - Set CPU Header one of ['lightsalmon', 'orchid', 'darkred'] colors
 - Set PCIe one of ['lightsalmon', 'orchid', 'darkred'] colors
 - Set LED C1/C2 one of ['lightsalmon', 'orchid', 'darkred'] colors

B550 AORUS ELITE
+ zone D_LED1 Bottom type ZoneType.LINEAR
resize to 9
led count: 9
 - Set D_LED1 Bottom ARGB 9 leds to lightsalmon orchid darkred (gradient=False)
+ zone D_LED2 Top type ZoneType.LINEAR
resize to 9
led count: 9
 - Set D_LED2 Top ARGB 9 leds to lightsalmon orchid darkred (gradient=False)
+ zone Motherboard type ZoneType.SINGLE
 - Set Back I/O one of ['lightsalmon', 'orchid', 'darkred'] colors
 - Set CPU Header one of ['lightsalmon', 'orchid', 'darkred'] colors
 - Set PCIe one of ['lightsalmon', 'orchid', 'darkred'] colors
 - Set LED C1/C2 one of ['lightsalmon', 'orchid', 'darkred'] colors

ASUS Aura DRAM
 - Set ASUS Aura DRAM RAM 8 leds to lightsalmon orchid darkred (gradient=False)
ASUS Aura DRAM
 - Set ASUS Aura DRAM RAM 8 leds to lightsalmon orchid darkred (gradient=False)

I run script second time then resize is not needed as leds count is already there. Perfect.

Just for some reason it's skipping 2nd ARGB header on my mobo. Probably something to to do with openrgb itself as it detects my mobo twice. Need to investigate more.

2: B550 AORUS ELITE
  Type:           Motherboard
  Description:    IT5702-GIGABYTE V2.0.8.0
  Version:        0x00080002
  Location:       HID: /dev/hidraw1
  Serial:         0x57020100
  Modes: [Direct] Static Breathing Blinking 'Color Cycle' Flashing
  Zones: 'D_LED1 Bottom' 'D_LED2 Top' Motherboard
  LEDs: 'D_LED1 Bottom LED 0' 'D_LED1 Bottom LED 1' 'D_LED1 Bottom LED 2' 'D_LED1 Bottom LED 3' 'D_LED1 Bottom LED 4' 'D_LED1 Bottom LED 5' 'D_LED1 Bottom LED 6' 'D_LED1 Bottom LED 7' 'D_LED1 Bottom LED 8' 'D_LED1 Bottom LED 9' 'Back I/O' 'CPU Header' PCIe 'LED C1/C2'

3: B550 AORUS ELITE
  Type:           Motherboard
  Description:    IT5702-GIGABYTE V2.0.8.0
  Version:        0x00080002
  Location:       HID: /dev/hidraw1
  Serial:         0x57020100
  Modes: [Direct] Static Breathing Blinking 'Color Cycle' Flashing
  Zones: 'D_LED1 Bottom' 'D_LED2 Top' Motherboard
  LEDs: 'Back I/O' 'CPU Header' PCIe 'LED C1/C2'