Added snap click, per-key/mixed rgb, custom debounce, wireless config feature

This commit is contained in:
lokher
2025-05-30 23:55:10 +08:00
parent b507ea2216
commit c9049679ac
81 changed files with 3696 additions and 251 deletions

View File

@@ -14,9 +14,9 @@ bool ALPHAS_MODS(effect_params_t* params) {
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_MODIFIER)) {
rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b);
rgb_matrix_region_set_color(params->region, i, rgb2.r, rgb2.g, rgb2.b);
} else {
rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b);
rgb_matrix_region_set_color(params->region, i, rgb1.r, rgb1.g, rgb1.b);
}
}
return rgb_matrix_check_finished_leds(led_max);

View File

@@ -11,7 +11,7 @@ bool BREATHING(effect_params_t* params) {
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);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -7,76 +7,108 @@ RGB_MATRIX_EFFECT(DIGITAL_RAIN)
# define RGB_DIGITAL_RAIN_DROPS 24
# endif
uint8_t rain_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}};
bool DIGITAL_RAIN(effect_params_t* params) {
// algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
const uint8_t drop_ticks = 28;
const uint8_t pure_green_intensity = (((uint16_t)rgb_matrix_config.hsv.v) * 3) >> 2;
const uint8_t max_brightness_boost = (((uint16_t)rgb_matrix_config.hsv.v) * 3) >> 2;
const uint8_t max_intensity = rgb_matrix_config.hsv.v;
static uint8_t max_intensity = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
const uint8_t decay_ticks = 0xff / max_intensity;
static uint8_t drop = 0;
static uint8_t decay = 0;
static bool render = true;
RGB_MATRIX_USE_LIMITS(led_min, led_max);
if (params->init) {
rgb_matrix_set_color_all(0, 0, 0);
memset(g_rgb_frame_buffer, 0, sizeof(g_rgb_frame_buffer));
rgb_matrix_region_set_color_all(params->region, 0, 0, 0);
memset(rain_rgb_frame_buffer, 0, sizeof(rain_rgb_frame_buffer));
drop = 0;
}
decay++;
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
// top row, pixels have just fallen and we're
// making a new rain drop in this column
g_rgb_frame_buffer[row][col] = max_intensity;
} else if (g_rgb_frame_buffer[row][col] > 0 && g_rgb_frame_buffer[row][col] < max_intensity) {
// neither fully bright nor dark, decay it
if (decay == decay_ticks) {
g_rgb_frame_buffer[row][col]--;
if (params->iter == 0) {
if (max_intensity != rgb_matrix_config.hsv.v) {
// Check if value is decreased
if (max_intensity > rgb_matrix_config.hsv.v) {
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
rain_rgb_frame_buffer[row][col] = rain_rgb_frame_buffer[row][col] * (uint16_t)rgb_matrix_config.hsv.v / max_intensity;
}
}
}
// set the pixel colour
uint8_t led[LED_HITS_TO_REMEMBER];
uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
// TODO: multiple leds are supported mapped to the same row/column
if (led_count > 0) {
if (g_rgb_frame_buffer[row][col] > pure_green_intensity) {
const uint8_t boost = (uint8_t)((uint16_t)max_brightness_boost * (g_rgb_frame_buffer[row][col] - pure_green_intensity) / (max_intensity - pure_green_intensity));
rgb_matrix_set_color(led[0], boost, max_intensity, boost);
} else {
const uint8_t green = (uint8_t)((uint16_t)max_intensity * g_rgb_frame_buffer[row][col] / pure_green_intensity);
rgb_matrix_set_color(led[0], 0, green, 0);
max_intensity = rgb_matrix_config.hsv.v;
}
if (render)
decay++;
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
if (render) {
if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
// top row, pixels have just fallen and we're
// making a new rain drop in this column
rain_rgb_frame_buffer[row][col] = max_intensity;
} else if (rain_rgb_frame_buffer[row][col] > 0 && rain_rgb_frame_buffer[row][col] < max_intensity) {
// neither fully bright nor dark, decay it
if (decay == decay_ticks) {
rain_rgb_frame_buffer[row][col]--;
}
}
}
// set the pixel colour
uint8_t led[LED_HITS_TO_REMEMBER];
uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
// TODO: multiple leds are supported mapped to the same row/column
if (led_count > 0) {
if (rain_rgb_frame_buffer[row][col] > pure_green_intensity) {
const uint8_t boost = (uint8_t)((uint16_t)max_brightness_boost * (rain_rgb_frame_buffer[row][col] - pure_green_intensity) / (max_intensity - pure_green_intensity));
rgb_matrix_region_set_color(params->region, led[0], boost, max_intensity, boost);
} else {
const uint8_t green = (uint8_t)((uint16_t)max_intensity * rain_rgb_frame_buffer[row][col] / pure_green_intensity);
rgb_matrix_region_set_color(params->region, led[0], 0, green, 0);
}
}
}
}
}
if (decay == decay_ticks) {
decay = 0;
}
if (++drop > drop_ticks) {
// reset drop timer
drop = 0;
for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
// if ths is on the bottom row and bright allow decay
if (row == MATRIX_ROWS - 1 && g_rgb_frame_buffer[row][col] == max_intensity) {
g_rgb_frame_buffer[row][col]--;
}
// check if the pixel above is bright
if (g_rgb_frame_buffer[row - 1][col] >= max_intensity) { // Note: can be larger than max_intensity if val was recently decreased
// allow old bright pixel to decay
g_rgb_frame_buffer[row - 1][col] = max_intensity - 1;
// make this pixel bright
g_rgb_frame_buffer[row][col] = max_intensity;
if (render) {
if (decay == decay_ticks) {
decay = 0;
}
if (++drop > drop_ticks) {
// reset drop timer
drop = 0;
for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
// if ths is on the bottom row and bright allow decay
if (row == MATRIX_ROWS - 1 && rain_rgb_frame_buffer[row][col] == max_intensity) {
rain_rgb_frame_buffer[row][col]--;
}
// check if the pixel above is bright
if (rain_rgb_frame_buffer[row - 1][col] >= max_intensity) { // Note: can be larger than max_intensity if val was recently decreased
// allow old bright pixel to decay
rain_rgb_frame_buffer[row - 1][col] = max_intensity - 1;
// make this pixel bright
rain_rgb_frame_buffer[row][col] = max_intensity;
}
}
}
}
}
render = false;
} else {
render = true;
}
return false;
return rgb_matrix_check_finished_leds(led_max);
}
# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS

View File

@@ -28,10 +28,10 @@ bool effect_runner_bloom(effect_params_t* params, flower_blooming_f effect_func)
RGB_MATRIX_TEST_LED_FLAGS();
if (g_led_config.point[i].y > k_rgb_matrix_center.y) {
RGB bgr = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
rgb_matrix_set_color(i, bgr.b, bgr.g, bgr.r);
rgb_matrix_region_set_color(params->region, i, bgr.b, bgr.g, bgr.r);
} else {
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);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
}
return rgb_matrix_check_finished_leds(led_max);

View File

@@ -13,7 +13,7 @@ bool GRADIENT_LEFT_RIGHT(effect_params_t* params) {
// 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 = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -13,7 +13,7 @@ bool GRADIENT_UP_DOWN(effect_params_t* params) {
// 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 = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -13,7 +13,7 @@ bool HUE_BREATHING(effect_params_t* params) {
RGB rgb = 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);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -6,7 +6,7 @@ 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 = {random8(), random8_min_max(127, 255), rgb_matrix_config.hsv.v};
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
bool JELLYBEAN_RAINDROPS(effect_params_t* params) {

View File

@@ -5,12 +5,17 @@
RGB_MATRIX_EFFECT(PIXEL_FLOW)
# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
static uint32_t flow_wait_timer = 0;
void PIXEL_FLOW_init(void) {
flow_wait_timer = 0;
}
static bool PIXEL_FLOW(effect_params_t* params) {
// LED state array
static RGB led[RGB_MATRIX_LED_COUNT];
static uint32_t wait_timer = 0;
if (wait_timer > g_rgb_timer) {
if (flow_wait_timer > g_rgb_timer) {
return false;
}
@@ -20,7 +25,7 @@ static bool PIXEL_FLOW(effect_params_t* params) {
if (params->init) {
// Clear LEDs and fill the state array
rgb_matrix_set_color_all(0, 0, 0);
rgb_matrix_region_set_color_all(params->region, 0, 0, 0);
for (uint8_t j = 0; j < RGB_MATRIX_LED_COUNT; ++j) {
led[j] = (random8() & 2) ? (RGB){0, 0, 0} : hsv_to_rgb((HSV){random8(), random8_min_max(127, 255), rgb_matrix_config.hsv.v});
}
@@ -30,7 +35,7 @@ static bool PIXEL_FLOW(effect_params_t* params) {
// Light LEDs based on state array
for (uint8_t i = led_min; i < led_max; ++i) {
RGB_MATRIX_TEST_LED_FLAGS();
rgb_matrix_set_color(i, led[i].r, led[i].g, led[i].b);
rgb_matrix_region_set_color(params->region, i, led[i].r, led[i].g, led[i].b);
}
if (!rgb_matrix_check_finished_leds(led_max)) {
@@ -41,7 +46,7 @@ static bool PIXEL_FLOW(effect_params_t* params) {
// Fill last LED
led[led_max - 1] = (random8() & 2) ? (RGB){0, 0, 0} : hsv_to_rgb((HSV){random8(), random8_min_max(127, 255), rgb_matrix_config.hsv.v});
// Set pulse timer
wait_timer = g_rgb_timer + interval();
flow_wait_timer = g_rgb_timer + interval();
}
return rgb_matrix_check_finished_leds(led_max);

View File

@@ -6,6 +6,13 @@
RGB_MATRIX_EFFECT(PIXEL_FRACTAL)
# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
static uint32_t fractal_wait_timer = 0;
void PIXEL_FRACTAL_init(void) {
fractal_wait_timer = 0;
}
static bool PIXEL_FRACTAL(effect_params_t* params) {
# if MATRIX_COLS < 2
# define MID_COL 1
@@ -13,47 +20,46 @@ static bool PIXEL_FRACTAL(effect_params_t* params) {
# define MID_COL MATRIX_COLS / 2
# endif
static bool led[MATRIX_ROWS][MID_COL];
static uint32_t wait_timer = 0;
inline uint32_t interval(void) {
return 3000 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16);
}
if (params->init) {
rgb_matrix_set_color_all(0, 0, 0);
rgb_matrix_region_set_color_all(params->region 0, 0, 0);
}
RGB_MATRIX_USE_LIMITS(led_min, led_max);
if (g_rgb_timer > wait_timer) {
if (g_rgb_timer > fractal_wait_timer) {
RGB rgb = rgb_matrix_hsv_to_rgb(rgb_matrix_config.hsv);
for (uint8_t h = 0; h < MATRIX_ROWS; ++h) {
// Light and copy columns outward
for (uint8_t l = 0; l < MID_COL - 1; ++l) {
if (led[h][l]) {
rgb_matrix_set_color(g_led_config.matrix_co[h][l], rgb.r, rgb.g, rgb.b);
rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - 1 - l], rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, g_led_config.matrix_co[h][l], rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, g_led_config.matrix_co[h][MATRIX_COLS - 1 - l], rgb.r, rgb.g, rgb.b);
} else {
rgb_matrix_set_color(g_led_config.matrix_co[h][l], 0, 0, 0);
rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - 1 - l], 0, 0, 0);
rgb_matrix_region_set_color(params->region, g_led_config.matrix_co[h][l], 0, 0, 0);
rgb_matrix_region_set_color(params->region, g_led_config.matrix_co[h][MATRIX_COLS - 1 - l], 0, 0, 0);
}
led[h][l] = led[h][l + 1];
}
// Light both middle columns
if (led[h][MID_COL - 1]) {
rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL - 1], rgb.r, rgb.g, rgb.b);
rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - MID_COL], rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, g_led_config.matrix_co[h][MID_COL - 1], rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, g_led_config.matrix_co[h][MATRIX_COLS - MID_COL], rgb.r, rgb.g, rgb.b);
} else {
rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL - 1], 0, 0, 0);
rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - MID_COL], 0, 0, 0);
rgb_matrix_region_set_color(params->region, g_led_config.matrix_co[h][MID_COL - 1], 0, 0, 0);
rgb_matrix_region_set_color(params->region, g_led_config.matrix_co[h][MATRIX_COLS - MID_COL], 0, 0, 0);
}
// Generate new random fractal column
led[h][MID_COL - 1] = (random8() & 3) ? false : true;
}
wait_timer = g_rgb_timer + interval();
fractal_wait_timer = g_rgb_timer + interval();
}
return rgb_matrix_check_finished_leds(led_max);

View File

@@ -5,8 +5,13 @@
RGB_MATRIX_EFFECT(PIXEL_RAIN)
# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
static bool PIXEL_RAIN(effect_params_t* params) {
static uint32_t wait_timer = 0;
static uint32_t rain_wait_timer = 0;
void PIXEL_RAIN_init(void) {
rain_wait_timer = 0;
}
bool PIXEL_RAIN(effect_params_t* params) {
inline uint32_t interval(void) {
return 500 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16);
@@ -18,12 +23,12 @@ static bool PIXEL_RAIN(effect_params_t* params) {
}
HSV hsv = (random8() & 2) ? (HSV){0, 0, 0} : (HSV){random8(), random8_min_max(127, 255), rgb_matrix_config.hsv.v};
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(led_index, rgb.r, rgb.g, rgb.b);
wait_timer = g_rgb_timer + interval();
rgb_matrix_region_set_color(params->region, led_index, rgb.r, rgb.g, rgb.b);
rain_wait_timer = g_rgb_timer + interval();
}
RGB_MATRIX_USE_LIMITS(led_min, led_max);
if (g_rgb_timer > wait_timer) {
if (g_rgb_timer > rain_wait_timer) {
rain_pixel(random8_max(RGB_MATRIX_LED_COUNT));
}
return rgb_matrix_check_finished_leds(led_max);

View File

@@ -16,7 +16,7 @@ static void raindrops_set_color(int i, effect_params_t* params) {
hsv.h = rgb_matrix_config.hsv.h + (deltaH * (random8() & 0x03));
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
bool RAINDROPS(effect_params_t* params) {

View File

@@ -12,7 +12,7 @@ bool RIVERFLOW(effect_params_t* params) {
hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
RGB_MATRIX_TEST_LED_FLAGS();
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);

View File

@@ -11,7 +11,7 @@ bool effect_runner_dx_dy(effect_params_t* params, dx_dy_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;
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);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -12,7 +12,7 @@ bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func)
int16_t dy = g_led_config.point[i].y - k_rgb_matrix_center.y;
uint8_t dist = sqrt16(dx * dx + dy * dy);
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);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -9,7 +9,7 @@ bool effect_runner_i(effect_params_t* params, i_f effect_func) {
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
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);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -21,7 +21,7 @@ bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) {
uint16_t offset = scale16by8(tick, qadd8(rgb_matrix_config.speed, 1));
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);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -21,7 +21,7 @@ bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, react
}
hsv.v = scale8(hsv.v, rgb_matrix_config.hsv.v);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -11,7 +11,7 @@ bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) {
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
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);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -7,7 +7,7 @@ bool SOLID_COLOR(effect_params_t* params) {
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);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
return rgb_matrix_check_finished_leds(led_max);
}

View File

@@ -7,7 +7,7 @@ void set_starlight_color(int i, effect_params_t* params) {
HSV hsv = rgb_matrix_config.hsv;
hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
bool STARLIGHT(effect_params_t* params) {
@@ -27,4 +27,4 @@ bool STARLIGHT(effect_params_t* params) {
}
# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // ENABLE_RGB_MATRIX_STARLIGHT
#endif // ENABLE_RGB_MATRIX_STARLIGHT

View File

@@ -8,7 +8,7 @@ void set_starlight_dual_hue_color(int i, effect_params_t* params) {
hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
hsv.h = hsv.h + (rand() % (30 + 1 - -30) + -30);
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
bool STARLIGHT_DUAL_HUE(effect_params_t* params) {
@@ -28,4 +28,4 @@ bool STARLIGHT_DUAL_HUE(effect_params_t* params) {
}
# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // ENABLE_RGB_MATRIX_STARLIGHT_DUAL_HUE
#endif // ENABLE_RGB_MATRIX_STARLIGHT_DUAL_HUE

View File

@@ -8,7 +8,7 @@ void set_starlight_dual_sat_color(int i, effect_params_t* params) {
hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
hsv.s = hsv.s + (rand() % (30 + 1 - -30) + -30);
RGB rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b);
}
bool STARLIGHT_DUAL_SAT(effect_params_t* params) {
@@ -28,4 +28,4 @@ bool STARLIGHT_DUAL_SAT(effect_params_t* params) {
}
# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // ENABLE_RGB_MATRIX_STARLIGHT_DUAL_SAT
#endif // ENABLE_RGB_MATRIX_STARLIGHT_DUAL_SAT

View File

@@ -52,25 +52,29 @@ void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) {
static uint16_t heatmap_decrease_timer;
// Whether we should decrement the heatmap values during the next update.
static bool decrease_heatmap_values;
static uint8_t loop = 0;
bool TYPING_HEATMAP(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
if (params->init) {
rgb_matrix_set_color_all(0, 0, 0);
rgb_matrix_region_set_color_all(params->region, 0, 0, 0);
memset(g_rgb_frame_buffer, 0, sizeof g_rgb_frame_buffer);
}
// The heatmap animation might run in several iterations depending on
// `RGB_MATRIX_LED_PROCESS_LIMIT`, therefore we only want to update the
// timer when the animation starts.
if (params->iter == 0) {
if (params->iter == 0 && loop == 0) {
loop |= 1 << params->region;
decrease_heatmap_values = timer_elapsed(heatmap_decrease_timer) >= RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS;
// Restart the timer if we are going to decrease the heatmap this frame.
if (decrease_heatmap_values) {
heatmap_decrease_timer = timer_read();
}
} else if (params->iter == 4) {
loop &= ~(1 << params->region);
}
// Render heatmap & decrease
@@ -84,7 +88,7 @@ bool TYPING_HEATMAP(effect_params_t* params) {
HSV hsv = {170 - qsub8(val, 85), rgb_matrix_config.hsv.s, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.hsv.v)};
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(g_led_config.matrix_co[row][col], rgb.r, rgb.g, rgb.b);
rgb_matrix_region_set_color(params->region, g_led_config.matrix_co[row][col], rgb.r, rgb.g, rgb.b);
if (decrease_heatmap_values) {
g_rgb_frame_buffer[row][col] = qsub8(val, 1);

View File

@@ -80,7 +80,7 @@ static bool driver_shutdown = false;
static bool suspend_state = false;
static uint8_t rgb_last_enable = UINT8_MAX;
static uint8_t rgb_last_effect = UINT8_MAX;
static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false};
static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false, 0};
static rgb_task_states rgb_task_state = SYNCING;
#if RGB_MATRIX_TIMEOUT > 0
static uint32_t rgb_anykey_timer;
@@ -98,6 +98,8 @@ static last_hit_t last_hit_buffer;
const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT;
#endif
uint8_t rgb_regions[RGB_MATRIX_LED_COUNT];
EECONFIG_DEBOUNCE_HELPER(rgb_matrix, EECONFIG_RGB_MATRIX, rgb_matrix_config);
void rgb_matrix_increase_val_helper(bool write_to_eeprom);
@@ -168,6 +170,20 @@ void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
#endif
}
void rgb_matrix_region_set_color(uint8_t region, int index, uint8_t red, uint8_t green, uint8_t blue) {
if (rgb_regions[index] == region) {
rgb_matrix_driver.set_color(index, red, green, blue);
}
}
void rgb_matrix_region_set_color_all(uint8_t region, uint8_t red, uint8_t green, uint8_t blue) {
for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++)
if (((g_led_config.flags[i] & 0xF0) >> 4) == region)
rgb_matrix_set_color(i, red, green, blue);
}
__attribute__((weak)) void process_rgb_matrix_kb(uint8_t row, uint8_t col, bool pressed) {}
void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) {
#ifndef RGB_MATRIX_SPLIT
if (!is_keyboard_master()) return;
@@ -219,6 +235,7 @@ void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) {
}
}
#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && defined(ENABLE_RGB_MATRIX_TYPING_HEATMAP)
process_rgb_matrix_kb(row, col, pressed);
}
void rgb_matrix_test(void) {
@@ -313,6 +330,14 @@ static void rgb_task_start(void) {
static void rgb_task_render(uint8_t effect) {
bool rendering = false;
rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
if (effect != rgb_last_effect) {
memset(rgb_regions, 0, RGB_MATRIX_LED_COUNT);
rgb_config_t rgb_cfg;
eeprom_read_block(&rgb_cfg, EECONFIG_RGB_MATRIX, sizeof(rgb_cfg));
rgb_matrix_config.hsv = rgb_cfg.hsv;
rgb_matrix_config.speed = rgb_cfg.speed;
}
if (rgb_effect_params.flags != rgb_matrix_config.flags) {
rgb_effect_params.flags = rgb_matrix_config.flags;
rgb_matrix_set_color_all(0, 0, 0);
@@ -537,7 +562,10 @@ bool rgb_matrix_get_suspend_state(void) {
void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
rgb_matrix_config.enable ^= 1;
rgb_task_state = STARTING;
eeconfig_flag_rgb_matrix(write_to_eeprom);
if (write_to_eeprom) {
uint8_t mode = (rgb_matrix_config.mode << 2) | rgb_matrix_config.enable;
eeprom_write_byte((uint8_t*)EECONFIG_RGB_MATRIX, mode);
}
dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable);
#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL
while (rgb_matrix_config.enable && rgb_matrix_config.hsv.v < RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
@@ -554,7 +582,8 @@ void rgb_matrix_toggle(void) {
void rgb_matrix_enable(void) {
rgb_matrix_enable_noeeprom();
eeconfig_flag_rgb_matrix(true);
uint8_t mode = (rgb_matrix_config.mode << 2) | rgb_matrix_config.enable;
eeprom_write_byte((uint8_t*)EECONFIG_RGB_MATRIX, mode);
#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL
while (rgb_matrix_config.hsv.v < RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) {
rgb_matrix_increase_val_helper(true);
@@ -574,7 +603,8 @@ void rgb_matrix_enable_noeeprom(void) {
void rgb_matrix_disable(void) {
rgb_matrix_disable_noeeprom();
eeconfig_flag_rgb_matrix(true);
uint8_t mode = (rgb_matrix_config.mode << 2) | rgb_matrix_config.enable;
eeprom_write_byte((uint8_t*)EECONFIG_RGB_MATRIX, mode);
}
void rgb_matrix_disable_noeeprom(void) {
@@ -598,7 +628,11 @@ void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
rgb_matrix_config.mode = mode;
}
rgb_task_state = STARTING;
eeconfig_flag_rgb_matrix(write_to_eeprom);
if (write_to_eeprom) {
uint8_t mode = (rgb_matrix_config.mode << 2) | rgb_matrix_config.enable;
eeprom_write_byte((uint8_t*)EECONFIG_RGB_MATRIX, mode);
}
dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode);
}
void rgb_matrix_mode_noeeprom(uint8_t mode) {
@@ -641,7 +675,10 @@ void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, boo
rgb_matrix_config.hsv.h = hue;
rgb_matrix_config.hsv.s = sat;
rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val;
eeconfig_flag_rgb_matrix(write_to_eeprom);
if (write_to_eeprom) {
uint8_t *addr = (uint8_t*)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, hsv);
eeprom_write_block(&rgb_matrix_config.hsv, addr, sizeof(rgb_matrix_config.hsv));
}
dprintf("rgb matrix set hsv [%s]: %u,%u,%u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v);
}
void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
@@ -737,7 +774,10 @@ void rgb_matrix_decrease_val(void) {
void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
rgb_matrix_config.speed = speed;
eeconfig_flag_rgb_matrix(write_to_eeprom);
if (write_to_eeprom) {
uint8_t *addr = (uint8_t*)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, speed);
eeprom_write_byte(addr, rgb_matrix_config.speed);
}
dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed);
}
void rgb_matrix_set_speed_noeeprom(uint8_t speed) {
@@ -773,7 +813,10 @@ void rgb_matrix_decrease_speed(void) {
void rgb_matrix_set_flags_eeprom_helper(led_flags_t flags, bool write_to_eeprom) {
rgb_matrix_config.flags = flags;
eeconfig_flag_rgb_matrix(write_to_eeprom);
if (write_to_eeprom) {
uint8_t *addr = (uint8_t*)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, flags);
eeprom_write_byte(addr, rgb_matrix_config.flags);
}
dprintf("rgb matrix set flags [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.flags);
}

View File

@@ -168,6 +168,8 @@ uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l
void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
void rgb_matrix_region_set_color(uint8_t region, int index, uint8_t red, uint8_t green, uint8_t blue);
void rgb_matrix_region_set_color_all(uint8_t region, uint8_t red, uint8_t green, uint8_t blue);
void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed);

View File

@@ -48,6 +48,7 @@ typedef struct PACKED {
uint8_t iter;
led_flags_t flags;
bool init;
uint8_t region;
} effect_params_t;
typedef struct PACKED {

View File

@@ -633,7 +633,7 @@ void via_qmk_rgblight_save(void) {
#endif // QMK_RGBLIGHT_ENABLE
#if defined(RGB_MATRIX_ENABLE)
static uint8_t rgb_matrix_value_id_mask;
void via_qmk_rgb_matrix_command(uint8_t *data, uint8_t length) {
// data = [ command_id, channel_id, value_id, value_data ]
uint8_t *command_id = &(data[0]);
@@ -689,6 +689,7 @@ void via_qmk_rgb_matrix_set_value(uint8_t *data) {
// data = [ value_id, value_data ]
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);
rgb_matrix_value_id_mask |= 0x01U << *value_id;
switch (*value_id) {
case id_qmk_rgb_matrix_brightness: {
rgb_matrix_sethsv_noeeprom(rgb_matrix_get_hue(), rgb_matrix_get_sat(), scale8(value_data[0], RGB_MATRIX_MAXIMUM_BRIGHTNESS));
@@ -715,7 +716,30 @@ void via_qmk_rgb_matrix_set_value(uint8_t *data) {
}
void via_qmk_rgb_matrix_save(void) {
eeconfig_update_rgb_matrix();
if (rgb_matrix_value_id_mask == (0x01U << id_qmk_rgb_matrix_brightness)) {
uint8_t *addr = (uint8_t*)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, hsv.v);
eeprom_write_byte(addr, rgb_matrix_config.hsv.v);
}
if (rgb_matrix_value_id_mask == (0x01U << id_qmk_rgb_matrix_effect)) {
uint8_t mode = (rgb_matrix_config.mode << 2) | rgb_matrix_config.enable;
eeprom_write_byte((uint8_t*)EECONFIG_RGB_MATRIX, mode);
}
if (rgb_matrix_value_id_mask == (0x01U << id_qmk_rgb_matrix_color)) {
uint8_t *addr = (uint8_t*)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, hsv.h);
eeprom_write_byte(addr, rgb_matrix_config.hsv.h);
addr = (uint8_t*)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, hsv.s);
eeprom_write_byte(addr, rgb_matrix_config.hsv.s);
}
if (rgb_matrix_value_id_mask == (0x01U << id_qmk_rgb_matrix_effect_speed)) {
uint8_t *addr = (uint8_t*)EECONFIG_RGB_MATRIX + offsetof(rgb_config_t, speed);
eeprom_write_byte(addr, rgb_matrix_config.speed);
}
rgb_matrix_value_id_mask = 0;
}
#endif // RGB_MATRIX_ENABLE