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

RGB Matrix not working on bm60rgb #5

Open
jjimenezlopez opened this issue Apr 28, 2021 · 2 comments
Open

RGB Matrix not working on bm60rgb #5

jjimenezlopez opened this issue Apr 28, 2021 · 2 comments

Comments

@jjimenezlopez
Copy link

Hi! first of all, thanks for this awesome tool, it's exactly what I was looking for :)

I updated my keyboard's firmware without issues. And I managed to run some commands correctly, for example, these commands are working fine:

$ curl 127.0.0.1:9916/command -XPOST \
  -H 'content-type: application/json' \
  -d '{"id":14,"data":[1]}'

$ curl 127.0.0.1:9916/command -XPOST \
  -H 'content-type: application/json' \
  -d '{"id":8}'

However, when I try to modify the led's color, nothing happens, here is an example:

 $ curl 127.0.0.1:9916/command -XPOST \
  -H 'content-type: application/json' \
  -d '{"id":10,"data":[50,75,90,1,4]}'
{"message":"Command sent","bytes":[0,10,5,0,0,0,50,75,90,10,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}%

I copied this command from your documentation, I just changed the command id.

Let me know if I can help with this, I'm not familiar with programming in C, but if you need some debug info or something, let me know!

Thanks!

@mkillewald
Copy link

mkillewald commented Oct 12, 2021

I've got the same issue using a Keychron Q1, and I think whats happening is the RGB matrix animation running on the board just updates the RGB LEDs too quickly to see the change made by qmkrc. Setting a static color doesn't help because I think the LEDs still get updated very quickly same as in an animation only with a solid color over and over.

Try this, if you have the "raindrop" animation, where it slowly sets random keys one at a time to random colors, select it as the active RGB mode and then try sending the RGB_MATRIX_SETRGB_RANGE command to qmkrc. You should be able to see the changes take effect until the LEDs get "over written" by the raindrop animation.

As far as how to fix this in the code, the setting of the color by qmkrc needs to be done after the animation frame is finished. The rgb_matrix_indicators_user callback in QMK seems like a good place to do this, but I'm not sure how best to modify qmkrc to make this happen.

@mkillewald
Copy link

mkillewald commented Oct 12, 2021

This may not be the most elegant solution, but as a proof of concept it does work for me on the Q1.

I made two custom commands. The first takes the the color and range data received from qmkrc and stores it into a struct, then later pulls the data from this struct within the rgb_matrix_indicators_user callback to actually light the LEDs. This works because rgb_matrix_indicators_user is called after the RGB effects frame has been rendered.

The second custom command clears the struct effectively turning off the range that was previously set.

The downside is you can only set one range at a time this way. If you set a new range, the old range is wiped out. However, this can be extended to handle multiple ranges if needed.

the relevant code from keymap.c

#ifdef RAW_ENABLE
#include "qmk_rc.h"
#define MY_RGB_MATRIX_SETRGB_RANGE 128
#define MY_RGB_MATRIX_CLEAR 129

typedef struct {
  uint8_t red;
  uint8_t green;
  uint8_t blue;
  uint8_t led_min;
  uint8_t led_max;
  bool is_set;
} my_rgb_range_t;
my_rgb_range_t my_rgb_range;

void qmk_rc_process_command_user(qmk_rc_command_t* command) {
  switch (command->id) {
    case MY_RGB_MATRIX_SETRGB_RANGE:
        my_rgb_range.red     = command->data[0];
        my_rgb_range.green   = command->data[1];
        my_rgb_range.blue    = command->data[2];
        my_rgb_range.led_min = command->data[3];
        my_rgb_range.led_max = command->data[4];
        my_rgb_range.is_set  = true;
        break;
    case MY_RGB_MATRIX_CLEAR:
        my_rgb_range.red     = 0;
        my_rgb_range.green   = 0;
        my_rgb_range.blue    = 0;
        my_rgb_range.led_min = 0;
        my_rgb_range.led_max = 0;
        my_rgb_range.is_set  = false;
        break;
  }
}

void rgb_matrix_indicators_user(void) {
    if (my_rgb_range.is_set) {
        for (int i = my_rgb_range.led_min; i <= my_rgb_range.led_max; i++) {
            rgb_matrix_set_color(i, my_rgb_range.red, my_rgb_range.green, my_rgb_range.blue);
        }
    }
}
#endif // RAW_ENABLE

Usage of the custom commands is very similar to the normal qmkrc commands, just substitute the id numbers of the custom commands like so:

 $ curl 127.0.0.1:9916/command -XPOST \
  -H 'content-type: application/json' \
  -d '{"id":128,"data":[50,75,90,1,4]}'

 $ curl 127.0.0.1:9916/command -XPOST \
  -H 'content-type: application/json' \
  -d '{"id":129}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants