Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] keybow2040: RGB causing infinite loop #859

Open
JimMadge opened this issue Aug 20, 2023 · 7 comments · Fixed by #862
Open

[BUG] keybow2040: RGB causing infinite loop #859

JimMadge opened this issue Aug 20, 2023 · 7 comments · Fixed by #862
Labels
bug Something isn't working

Comments

@JimMadge
Copy link

Describe the bug
When using the example keybow2040 configuration, current CircuitPython and current kmk library, button presses have no effect. After a while CircuitPython soft resets.

Disabling the RGB, or forcing an exit from the _process_timeouts loop is a workaround.

To Reproduce
Steps to reproduce the behavior:

Expected behavior
Keyboard responds to button presses.

Debug output

75001 kmk.keyboard: Unexpected error: cleaning up

Code stopped by auto-reload. Reloading soon.
soft reboot

repeatedly (different numbers)

Additional context

  • When using the unmodified keybow2040 configuration, the RGB cycles colours but key presses have no effect.
  • If you disable RGB (by commenting )
    keybow.extensions = [rgb_ext]

    key presses work as expected
  • Trying to find out what was happening, I found that _process_timouts() never returns.
    The loop does not end.
    def _process_timeouts(self) -> None:
    for task in get_due_task():
    task()

    If you force this loop to exit early (say, by calling return after 10 iterations), key presses again work, but the RGB stops cycling.

So, I suspect that calls to update the RGB LEDs are filling the task queue and preventing the HID functions in go from being called.

I'm not very familiar with async but I'm happy to help debug if you have any suggestions.

@JimMadge JimMadge added the bug Something isn't working label Aug 20, 2023
@JeffreyStocker
Copy link
Contributor

I am having the same issue. I just started to play with RGB module and noticed that the keypad would become unresponsive to key presses when one of the more intricate RGB sequences were selected.

Ones tried

  • KC.RGB_MODE_SWIRL
  • KC.RGB_MODE_BREATHE_RAINBOW
  • KC.RGB_MODE_RAINBOW

KC.RGB_MODE_PLAIN and KC.RGB_MODE_BREATHE don't appear to be affected.

One workaround is to throttle the RGB updates via the refresh_rate setting

#from [RGB Document](https://github.com/KMKfw/kmk_firmware/blob/master/docs/en/rgb.md)
from kmk.extensions.rgb import AnimationModes
rgb = RGB(pixel_pin=rgb_pixel_pin,
        num_pixels=27
        val_limit=100,
        hue_default=0,
        sat_default=100,
        rgb_order=(1, 0, 2),  # GRB WS2812
        val_default=100,
        hue_step=5,
        sat_step=5,
        val_step=5,
        animation_speed=1,
        breathe_center=1,  # 1.0-2.7
        knight_effect_length=3,
        animation_mode=AnimationModes.STATIC,
        reverse_animation=False,
        refresh_rate=60,  # <---------- set to a lower setting
        )

On mine I found that 35 appears to be the upper limit, but key press start to get unreliable. Lower is better but it makes the RGB update slowly

Hardware:
Adafruit MacroPad RP2040

@JimMadge
Copy link
Author

JimMadge commented Aug 22, 2023

#862 is an improvement but my board still isn't behaving quite as expected.

Keypress are now sometimes registered. However if it is, characters are repeated many times as if they HID signal is being repeatedly sent or the key is being held down. (e.g. "aaaaaaaaaa").

Thanks @xs5871 for proposing a fix so quickly 🎉.
I commented here because I didn't want to hold up that PR. It is an improvement but I don't think it fixes this problem completely.
Happy to help continue testing branches or with anything debugging I can do.

@xs5871
Copy link
Collaborator

xs5871 commented Aug 23, 2023

You're right that #862 only fixes the infinite loop.

Keypress are now sometimes registered. However if it is, characters are repeated many times as if they HID signal is being repeatedly sent or the key is being held down. (e.g. "aaaaaaaaaa").

That is the "expected" behaviour and unintuitively not a bug. Compounding factors are:

  • some RGB animations takes a long time to compute
  • writing to the pixelbuffer is a blocking operation
  • there are lots of LEDs
  • animation refresh rate is too high

@xs5871 xs5871 reopened this Aug 23, 2023
@JimMadge
Copy link
Author

That makes sense.

Would a sensible thing be to change the keybow2040 example to use a less expensive RGB animation?

Happy to play around with that to find something that makes the keyboard more responsive.

@JeffreyStocker
Copy link
Contributor

Funny you should say that. I was playing around with the RGB and found a way to increase the RGB update efficiency.
#864
I found that this allowed me to go from refresh_rate of 35ish to over 200 before issues started to appear
YMMV since I'm using a tiny macropad

@JimMadge
Copy link
Author

@JeffreyStocker #864 Doesn't seem to make much difference on my Keybow2040. It still isn't really usable with the more intense RGB animations.

@JeffreyStocker
Copy link
Contributor

@JimMadge Check your refresh_rate that your passing into the RGB module. See what happens when you lower the refresh_rate

One thing I'm seeing, looking at the spec page of the Keybow2040 is that it is using a LED matrix driver, (maybe a custom code to control it?)

The way Neopixels and many strip LED work is by a message to the first LED and then that LED pass the message to the next LED. So I'm the code is gaining a lot of performance I'm having only 1 message be sent per update cycle, rather than 12 messages (I have 12 LEDS).
I'm not sure how the Keybow2040 is sending LED updates. Could you show what your RGB initiation variables and what libraries you are importing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants