Skip to content

Commit

Permalink
Allow for modification of output RGB values when using rgblight/rgb_m…
Browse files Browse the repository at this point in the history
…atrix.
  • Loading branch information
tzarc committed Oct 20, 2020
1 parent 2d468c4 commit 9f7342c
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions quantum/rgb_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const point_t k_rgb_matrix_center = {112, 32};
const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER;
#endif

__attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); }

// Generic effect runners
#include "rgb_matrix_runners/effect_runner_dx_dy_dist.h"
#include "rgb_matrix_runners/effect_runner_dx_dy.h"
Expand Down
4 changes: 2 additions & 2 deletions quantum/rgb_matrix_animations/alpha_mods_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ bool ALPHAS_MODS(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);

HSV hsv = rgb_matrix_config.hsv;
RGB rgb1 = hsv_to_rgb(hsv);
RGB rgb1 = rgb_matrix_hsv_to_rgb(hsv);
hsv.h += rgb_matrix_config.speed;
RGB rgb2 = hsv_to_rgb(hsv);
RGB rgb2 = rgb_matrix_hsv_to_rgb(hsv);

for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_animations/breathing_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bool BREATHING(effect_params_t* params) {
HSV hsv = rgb_matrix_config.hsv;
uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8);
hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
RGB rgb = hsv_to_rgb(hsv);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_animations/gradient_left_right_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bool GRADIENT_LEFT_RIGHT(effect_params_t* params) {
// The x range will be 0..224, map this to 0..7
// Relies on hue being 8-bit and wrapping
hsv.h = rgb_matrix_config.hsv.h + (scale * g_led_config.point[i].x >> 5);
RGB rgb = hsv_to_rgb(hsv);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_animations/gradient_up_down_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bool GRADIENT_UP_DOWN(effect_params_t* params) {
// The y range will be 0..64, map this to 0..4
// Relies on hue being 8-bit and wrapping
hsv.h = rgb_matrix_config.hsv.h + scale * (g_led_config.point[i].y >> 4);
RGB rgb = hsv_to_rgb(hsv);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_animations/jellybean_raindrops_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RGB_MATRIX_EFFECT(JELLYBEAN_RAINDROPS)
static void jellybean_raindrops_set_color(int i, effect_params_t* params) {
if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return;
HSV hsv = {rand() & 0xFF, rand() & 0xFF, rgb_matrix_config.hsv.v};
RGB rgb = hsv_to_rgb(hsv);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}

Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_animations/raindrops_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static void raindrops_set_color(int i, effect_params_t* params) {
}

hsv.h = rgb_matrix_config.hsv.h + (deltaH * (rand() & 0x03));
RGB rgb = hsv_to_rgb(hsv);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}

Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_animations/solid_color_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RGB_MATRIX_EFFECT(SOLID_COLOR)
bool SOLID_COLOR(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);

RGB rgb = hsv_to_rgb(rgb_matrix_config.hsv);
RGB rgb = rgb_matrix_hsv_to_rgb(rgb_matrix_config.hsv);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_animations/typing_heatmap_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool TYPING_HEATMAP(effect_params_t* params) {
if (!HAS_ANY_FLAGS(g_led_config.flags[led[j]], params->flags)) continue;

HSV hsv = {170 - qsub8(val, 85), rgb_matrix_config.hsv.s, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.hsv.v)};
RGB rgb = hsv_to_rgb(hsv);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(led[j], rgb.r, rgb.g, rgb.b);
}

Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_runners/effect_runner_dx_dy.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) {
RGB_MATRIX_TEST_LED_FLAGS();
int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x;
int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y;
RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, time));
RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, time));
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_runners/effect_runner_dx_dy_dist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func)
int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x;
int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y;
uint8_t dist = sqrt16(dx * dx + dy * dy);
RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, dist, time));
RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, dx, dy, dist, time));
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_runners/effect_runner_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bool effect_runner_i(effect_params_t* params, i_f effect_func) {
uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 4);
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_runners/effect_runner_reactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) {
}

uint16_t offset = scale16by8(tick, rgb_matrix_config.speed);
RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, offset));
RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, offset));
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_runners/effect_runner_reactive_splash.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, react
hsv = effect_func(hsv, dx, dy, dist, tick);
}
hsv.v = scale8(hsv.v, rgb_matrix_config.hsv.v);
RGB rgb = hsv_to_rgb(hsv);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_runners/effect_runner_sin_cos_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) {
int8_t sin_value = sin8(time) - 128;
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
RGB rgb = hsv_to_rgb(effect_func(rgb_matrix_config.hsv, cos_value, sin_value, i, time));
RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, cos_value, sin_value, i, time));
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < DRIVER_LED_TOTAL;
Expand Down
4 changes: 3 additions & 1 deletion quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) {
rgblight_ranges.effect_num_leds = num_leds;
}

__attribute__((weak)) RGB rgblight_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); }

void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
HSV hsv = {hue, sat, val};
RGB rgb = hsv_to_rgb(hsv);
RGB rgb = rgblight_hsv_to_rgb(hsv);
setrgb(rgb.r, rgb.g, rgb.b, led1);
}

Expand Down

0 comments on commit 9f7342c

Please sign in to comment.