LoLei / razer-cli

CLI for configuring Razer devices
GNU General Public License v3.0
92 stars 11 forks source link

Effect option is very broken on mouse [Razer DeathAdder Elite] #46

Closed GM-Script-Writer-62850 closed 3 years ago

GM-Script-Writer-62850 commented 3 years ago
$ for i in logo_breath_single logo_reactive logo_static scroll_breath_single scroll_reactive scroll_static breath_single multicolor ripple starlight_random starlight_single reactive;do echo test $i;.local/bin/razer-cli -e $i;done
test logo_breath_single
Effect is supported by device but not yet implemented.
Consider opening a PR:
https://github.com/LoLei/razer-x-color/pulls
test logo_reactive
Effect is supported by device but not yet implemented.
Consider opening a PR:
https://github.com/LoLei/razer-x-color/pulls
test logo_static
Effect is supported by device but not yet implemented.
Consider opening a PR:
https://github.com/LoLei/razer-x-color/pulls
test scroll_breath_single
Effect is supported by device but not yet implemented.
Consider opening a PR:
https://github.com/LoLei/razer-x-color/pulls
test scroll_reactive
Effect is supported by device but not yet implemented.
Consider opening a PR:
https://github.com/LoLei/razer-x-color/pulls
test scroll_static
Effect is supported by device but not yet implemented.
Consider opening a PR:
https://github.com/LoLei/razer-x-color/pulls
test breath_single
Setting device: Razer DeathAdder Elite to effect static
test multicolor
Setting device: Razer DeathAdder Elite to effect multicolor
test ripple
Setting device: Razer DeathAdder Elite to effect static
test starlight_random
Setting device: Razer DeathAdder Elite to effect static
test starlight_single
Setting device: Razer DeathAdder Elite to effect static
test reactive
Setting device: Razer DeathAdder Elite to effect static

I went to try to work on this, but not really sure where to start, figure it will probably need a full re-write, maybe you have some thoughts on it before i tackle it for the fun

LoLei commented 3 years ago

As you can see in set_effect_to_device from line 241 onwards, I've only implemented the effects static, breath_single, reactive, ripple, starlight_random, starlight_single and multicolor (which is a custom effect). Those are mostly keyboard effects too. It's setting the static effect as a fallback if the supplied effect cannot be used. Maybe the normal log output should reflect that in addition to the verbose message that says that. If the supplied effect is in device.fx.has but is not implemented in the set_effect_to_device function the log with the link to opening a PR is done.

You're right that this may benefit from a rewrite. Ideally, openrazer would just take an effect string and some arguments, and set a device to that effect if it has the capability. But I had to use the effect functions like this:

# for example
device.fx.breath_single(r, g, b)
# and
device.fx.reactive(r, g, b, times[3])

If you can figure out a way to do this with a dict access, for example device.fx['<effect>']([<args>]) instead of fx.<effect>(<args>), then it'd be much easier to use, and we could reduce the number of lines greatly. Maybe you can find something in openrazer's pylib code, at e.g. line 51 of /usr/lib/python3.9/site-packages/openrazer/client/fx.py.

GM-Script-Writer-62850 commented 3 years ago

Just a heads up the way i am planning to change things will break exiting multicolor commands, there will be no functionally loss, but it will need the command to be altered

is there some way i can dump a array into a function? effectively doing this

arr=[r, g, b]
device.fx[effect](arr) == device.fx[effect](r,g,b)
LoLei commented 3 years ago

Yeah this can be done with the "splat" (*) operator:

arr=[r, g, b]
device.fx[effect](*arr) == device.fx[effect](r,g,b)

https://stackoverflow.com/a/7746043/4644044

GM-Script-Writer-62850 commented 3 years ago

are these always this way?

razer_constants.REACTIVE_500MS == 1
razer_constants.REACTIVE_1000MS == 2
razer_constants.REACTIVE_1500MS == 3
razer_constants.REACTIVE_2000MS == 4

if they are i may as well just use the integer instead

GM-Script-Writer-62850 commented 3 years ago

Can you give this a test run for bugs? razer_cli.zip some effects will take a parameter for example using multicolor,6 as effect would allocate 6 colors to multicolor from -c If you run out of colors random ones will be generated

you can use random just as you would use FF00FF for a color

the following effects take a int as a paramater: multicolor, starlight_*, reactive, wave

LoLei commented 3 years ago

Am I correct in assuming these changes are based on the ones you added here: https://github.com/LoLei/razer-cli/issues/48?

The effects I've tested so far seem to be working well with this dev copy. Wave looks especially cool on keyboard and mouse. If you could list a few more of the more complex settings you can use, I can try them all, and we could add that to the Readme as well.

Let's merge the open PR into master first, then you can sync master with your changes again, so we can get a clean patch for these new effect changes.

Also btw, since this razer_cli.py file is getting really long, some stuff could be split up into separate files. For example, the set_effect_to_device function. Maybe a class with member functions could work as well.

GM-Script-Writer-62850 commented 3 years ago

I made manual entries for it razer_cli.zip You should be able to go crazy with stuff now razer-cli -c random ffffff 12 250 125 -e static reactive spectrium -z generic logo,left scroll_wheel,right

LoLei commented 3 years ago

Do you mean you added comments for command examples by "manual entries"? Could you just paste them here please? Sifting through the entire code for new changes is getting a bit tedious.

GM-Script-Writer-62850 commented 3 years ago

no there is a --manual option was not asking you to look through that code, just try to break it with something silly crazy

LoLei commented 3 years ago

Ah I see, that is helpful as well.

LoLei commented 3 years ago

Anyway please bear with me while I look through these changes. I have very little time these days to maintain this project. If you want to keep on adding new content with the same speed as this I could just add you as a maintainer to the project, so you can add code directly, without me having to apply your changes. I'll still review and test them before a new version is released to PyPI of course.

GM-Script-Writer-62850 commented 3 years ago

I think i am done for a while, at least for large stuff, if it all seems to work i can try to touch up some code formatting to make a clean patch file for you may end up finding some typos or 1 or 2 line tweaks

GM-Script-Writer-62850 commented 3 years ago

You know what the silly thing is? All of this started from I wanted to set the dpi from a script, I have no personal need for any of the other upgrades I made to this project they were just for fun in the name of 'it is a cli tool how can be so week'

GM-Script-Writer-62850 commented 3 years ago

Patch Files: razer-cli.patch.zip Assuming everything is working as intended here are proper patch files only thing i that think of that should be checked for is off by one mistakes for inputs in the set_effect_to_device function, note that the call to reset_device_effect is commended out, you can decide what you want to do with that

Changes:

GM-Script-Writer-62850 commented 3 years ago

Made a bug in my last changes, here is the fix (simple find and replace) razer_cli.py: Replace 5 occurrences of "util.random.randint" with "util.randint". These are on lines 373, 399, 412, 421, and 433

GM-Script-Writer-62850 commented 3 years ago

I made a couple more small changes:

LoLei commented 3 years ago

I actually like the option to have -ll output everything in a single line instead of with these multiple newlines, so I don't have to scroll like mad. So having both options, like -ll and -llh would be the best.

Remove any other features you deem unnecessary at your discretion.

Also, I've merged the previous pull request into master. Can you please make a patch with the final version of your new changes off of master so I can create a clean new pull request?

GM-Script-Writer-62850 commented 3 years ago

should i make zone/effect a 1 line under -ll and expand it under -llh or leave it in -l

GM-Script-Writer-62850 commented 3 years ago

razer-cli.patch.zip Here is a updated patch based on the branch you merged today

You may feel like changing or telling me how you think it would be best to do it for -l, -ll, and -llh

GM-Script-Writer-62850 commented 3 years ago

**When a lighting zone supports a feature it only means it can call the functions without a error, it can still return false indicating it does not support it You could use this if you want to drop -llh (part of list_devices)

        capabilitity = {"supported":[], "unsupported":[]}
        device_effects = get_effects_of_device(device)
        for i in device.capabilities:
            if device.capabilities[i]:
                capabilitity['supported'].append(i)
            elif args.verbose:
                capabilitity['unsupported'].append(i)

        join_str=', '
        start_str=''
        if args.list_devices_long:
            join_str='\n      '
            start_str='\n     '
        print("   supported capabilities:"+start_str,join_str.join(capabilitity['supported']))
        if args.verbose:
            print("   unsupported capabilities:"+start_str,join_str.join(capabilitity['unsupported']))
        for i in device_effects:
            print('   lighting zone',i,'supports:'+start_str,join_str.join(device_effects[i]))
$ ~/.local/bin/razer-cli -l
Found 1 Razer devices
Razer DeathAdder Elite:
   type: mouse
   DPI: (1100, 1100)
   max DPI: 16000
   polling rate: 1000
   brightness (logo): 49.8
   brightness (wheel): 49.8
   serial: 321848H04401822
   firmware version: v1.6
   driver version: 2.9.0
   supported capabilities: name, type, firmware_version, serial, lighting, lighting_led_matrix, lighting_logo, lighting_logo_brightness, lighting_logo_spectrum, lighting_logo_static, lighting_logo_none, lighting_logo_reactive, lighting_logo_breath_single, lighting_logo_breath_dual, lighting_logo_breath_random, lighting_scroll, lighting_scroll_brightness, lighting_scroll_spectrum, lighting_scroll_static, lighting_scroll_none, lighting_scroll_reactive, lighting_scroll_breath_single, lighting_scroll_breath_dual, lighting_scroll_breath_random, poll_rate, dpi
   lighting zone generic supports: none, breath_single, breath_dual, breath_triple, breath_random, reactive, ripple, ripple_random, spectrum, starlight_single, starlight_dual, starlight_random, static, wave, multicolor
   lighting zone scroll_wheel supports: none, brightness, breath_single, breath_dual, breath_random, reactive, spectrum, static, wave
   lighting zone logo supports: none, brightness, breath_single, breath_dual, breath_random, reactive, spectrum, static, wave
$ ~/.local/bin/razer-cli -l -v
Found 1 Razer devices
Razer DeathAdder Elite:
   type: mouse
   DPI: (1100, 1100)
   max DPI: 16000
   polling rate: 1000
   brightness (logo): 49.8
   brightness (wheel): 49.8
   serial: 321848H04401822
   firmware version: v1.6
   driver version: 2.9.0
   supported capabilities: name, type, firmware_version, serial, lighting, lighting_led_matrix, lighting_logo, lighting_logo_brightness, lighting_logo_spectrum, lighting_logo_static, lighting_logo_none, lighting_logo_reactive, lighting_logo_breath_single, lighting_logo_breath_dual, lighting_logo_breath_random, lighting_scroll, lighting_scroll_brightness, lighting_scroll_spectrum, lighting_scroll_static, lighting_scroll_none, lighting_scroll_reactive, lighting_scroll_breath_single, lighting_scroll_breath_dual, lighting_scroll_breath_random, poll_rate, dpi
   unsupported capabilities: brightness, macro_logic, keyboard_layout, lighting_breath_single, lighting_breath_dual, lighting_breath_triple, lighting_breath_random, lighting_wave, lighting_reactive, lighting_none, lighting_spectrum, lighting_static, lighting_starlight_single, lighting_starlight_dual, lighting_starlight_random, lighting_ripple, lighting_ripple_random, lighting_pulsate, lighting_led_single, lighting_logo_active, lighting_logo_blinking, lighting_logo_pulsate, lighting_logo_wave, lighting_scroll_active, lighting_scroll_blinking, lighting_scroll_pulsate, lighting_scroll_wave, lighting_left, lighting_left_active, lighting_left_brightness, lighting_left_spectrum, lighting_left_static, lighting_left_none, lighting_left_reactive, lighting_left_wave, lighting_left_breath_single, lighting_left_breath_dual, lighting_left_breath_random, lighting_right, lighting_right_active, lighting_right_brightness, lighting_right_spectrum, lighting_right_static, lighting_right_none, lighting_right_reactive, lighting_right_wave, lighting_right_breath_single, lighting_right_breath_dual, lighting_right_breath_random, lighting_backlight, lighting_backlight_active, lighting_profile_led_red, lighting_profile_led_green, lighting_profile_led_blue, available_dpi, battery
   lighting zone generic supports: none, breath_single, breath_dual, breath_triple, breath_random, reactive, ripple, ripple_random, spectrum, starlight_single, starlight_dual, starlight_random, static, wave, multicolor
   lighting zone scroll_wheel supports: none, brightness, breath_single, breath_dual, breath_random, reactive, spectrum, static, wave
   lighting zone logo supports: none, brightness, breath_single, breath_dual, breath_random, reactive, spectrum, static, wave
$ ~/.local/bin/razer-cli -ll
Found 1 Razer devices
Razer DeathAdder Elite:
   type: mouse
   DPI: (1100, 1100)
   max DPI: 16000
   polling rate: 1000
   brightness (logo): 49.8
   brightness (wheel): 49.8
   serial: 321848H04401822
   firmware version: v1.6
   driver version: 2.9.0
   supported capabilities:
      name
      type
      firmware_version
      serial
      lighting
      lighting_led_matrix
      lighting_logo
      lighting_logo_brightness
      lighting_logo_spectrum
      lighting_logo_static
      lighting_logo_none
      lighting_logo_reactive
      lighting_logo_breath_single
      lighting_logo_breath_dual
      lighting_logo_breath_random
      lighting_scroll
      lighting_scroll_brightness
      lighting_scroll_spectrum
      lighting_scroll_static
      lighting_scroll_none
      lighting_scroll_reactive
      lighting_scroll_breath_single
      lighting_scroll_breath_dual
      lighting_scroll_breath_random
      poll_rate
      dpi
   lighting zone generic supports:
      none
      breath_single
      breath_dual
      breath_triple
      breath_random
      reactive
      ripple
      ripple_random
      spectrum
      starlight_single
      starlight_dual
      starlight_random
      static
      wave
      multicolor
   lighting zone scroll_wheel supports:
      none
      brightness
      breath_single
      breath_dual
      breath_random
      reactive
      spectrum
      static
      wave
   lighting zone logo supports:
      none
      brightness
      breath_single
      breath_dual
      breath_random
      reactive
      spectrum
      static
      wave
$ ~/.local/bin/razer-cli -ll -v
Found 1 Razer devices
Razer DeathAdder Elite:
   type: mouse
   DPI: (1100, 1100)
   max DPI: 16000
   polling rate: 1000
   brightness (logo): 49.8
   brightness (wheel): 49.8
   serial: 321848H04401822
   firmware version: v1.6
   driver version: 2.9.0
   supported capabilities:
      name
      type
      firmware_version
      serial
      lighting
      lighting_led_matrix
      lighting_logo
      lighting_logo_brightness
      lighting_logo_spectrum
      lighting_logo_static
      lighting_logo_none
      lighting_logo_reactive
      lighting_logo_breath_single
      lighting_logo_breath_dual
      lighting_logo_breath_random
      lighting_scroll
      lighting_scroll_brightness
      lighting_scroll_spectrum
      lighting_scroll_static
      lighting_scroll_none
      lighting_scroll_reactive
      lighting_scroll_breath_single
      lighting_scroll_breath_dual
      lighting_scroll_breath_random
      poll_rate
      dpi
   unsupported capabilities:
      brightness
      macro_logic
      keyboard_layout
      lighting_breath_single
      lighting_breath_dual
      lighting_breath_triple
      lighting_breath_random
      lighting_wave
      lighting_reactive
      lighting_none
      lighting_spectrum
      lighting_static
      lighting_starlight_single
      lighting_starlight_dual
      lighting_starlight_random
      lighting_ripple
      lighting_ripple_random
      lighting_pulsate
      lighting_led_single
      lighting_logo_active
      lighting_logo_blinking
      lighting_logo_pulsate
      lighting_logo_wave
      lighting_scroll_active
      lighting_scroll_blinking
      lighting_scroll_pulsate
      lighting_scroll_wave
      lighting_left
      lighting_left_active
      lighting_left_brightness
      lighting_left_spectrum
      lighting_left_static
      lighting_left_none
      lighting_left_reactive
      lighting_left_wave
      lighting_left_breath_single
      lighting_left_breath_dual
      lighting_left_breath_random
      lighting_right
      lighting_right_active
      lighting_right_brightness
      lighting_right_spectrum
      lighting_right_static
      lighting_right_none
      lighting_right_reactive
      lighting_right_wave
      lighting_right_breath_single
      lighting_right_breath_dual
      lighting_right_breath_random
      lighting_backlight
      lighting_backlight_active
      lighting_profile_led_red
      lighting_profile_led_green
      lighting_profile_led_blue
      available_dpi
      battery
   lighting zone generic supports:
      none
      breath_single
      breath_dual
      breath_triple
      breath_random
      reactive
      ripple
      ripple_random
      spectrum
      starlight_single
      starlight_dual
      starlight_random
      static
      wave
      multicolor
   lighting zone scroll_wheel supports:
      none
      brightness
      breath_single
      breath_dual
      breath_random
      reactive
      spectrum
      static
      wave
   lighting zone logo supports:
      none
      brightness
      breath_single
      breath_dual
      breath_random
      reactive
      spectrum
      static
      wave
GM-Script-Writer-62850 commented 3 years ago

razer-cli.patch.zip

If you like that more, here is the patch based on that also put zones into the settings file and fixed a bug i found that we would not see till you have more than 1 custom effect

LoLei commented 3 years ago

So, not a huge issue but I tested all the effects, and when I used ripple_random, and afterwards multicolor, the keyboard wouldn't switch from ripple_random (the mouse did), and I had to reset with razer-cli -a, only then did multicolor work for the keyboard again.

Steps to reproduce:

razer-cli -e ripple_random
razer-cli -e multicolor,3 -c ff0000 00ff00 0000ff # Only works for mouse, ripple remains on keyboard
razer-cli -a # Or razer-cli -c ffffff
razer-cli -e multicolor,3 -c ff0000 00ff00 0000ff # Now it works

If you can find a fix for that it'd be great, otherwise I don't really care.

I also made some minor fixes based on your changes in the PR I opened: https://github.com/LoLei/razer-cli/pull/50

GM-Script-Writer-62850 commented 3 years ago

That issue sounds like something I encountered, does it sound like this: https://github.com/openrazer/openrazer/issues/1421

GM-Script-Writer-62850 commented 3 years ago

Should we drop the commas in the features list for $ .local/bin/razer-cli -l?

LoLei commented 3 years ago

I think it's fine as it is.