From 736d9fa5384977159abf55b72251c93a5dba8356 Mon Sep 17 00:00:00 2001 From: just-another-jxliu Date: Fri, 29 Oct 2021 13:11:48 -0700 Subject: Stop-gap forward-port Drop LED features for CTRL and ALT (#14967) --- tmk_core/protocol/arm_atsam/md_rgb_matrix.c | 48 ++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'tmk_core/protocol/arm_atsam/md_rgb_matrix.c') diff --git a/tmk_core/protocol/arm_atsam/md_rgb_matrix.c b/tmk_core/protocol/arm_atsam/md_rgb_matrix.c index 98967aac88..43d9f2ee60 100644 --- a/tmk_core/protocol/arm_atsam/md_rgb_matrix.c +++ b/tmk_core/protocol/arm_atsam/md_rgb_matrix.c @@ -341,6 +341,10 @@ uint8_t led_lighting_mode = LED_MODE_NORMAL; uint8_t led_enabled = 1; uint8_t led_animation_breathe_cur = BREATHE_MIN_STEP; uint8_t breathe_dir = 1; +uint8_t led_animation_circular = 0; +float led_edge_brightness = 1.0f; +float led_ratio_brightness = 1.0f; +uint8_t led_edge_mode = LED_EDGE_MODE_ALL; static void led_run_pattern(led_setup_t* f, float* ro, float* go, float* bo, float pos) { float po; @@ -398,16 +402,32 @@ static void led_run_pattern(led_setup_t* f, float* ro, float* go, float* bo, flo } } +# define RGB_MAX_DISTANCE 232.9635f + static void md_rgb_matrix_config_override(int i) { float ro = 0; float go = 0; float bo = 0; - - float po = (led_animation_orientation) ? (float)g_led_config.point[i].y / 64.f * 100 : (float)g_led_config.point[i].x / 224.f * 100; + float po; uint8_t highest_active_layer = biton32(layer_state); - if (led_lighting_mode == LED_MODE_KEYS_ONLY && HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) { + if (led_animation_circular) { + // TODO: should use min/max values from LED configuration instead of + // hard-coded 224, 64 + // po = sqrtf((powf(fabsf((disp.width / 2) - (led_cur->x - disp.left)), 2) + powf(fabsf((disp.height / 2) - (led_cur->y - disp.bottom)), 2))) / disp.max_distance * 100; + po = sqrtf((powf(fabsf((224 / 2) - (float)g_led_config.point[i].x), 2) + powf(fabsf((64 / 2) - (float)g_led_config.point[i].y), 2))) / RGB_MAX_DISTANCE * 100; + } else { + if (led_animation_orientation) { + po = (float)g_led_config.point[i].y / 64.f * 100; + } else { + po = (float)g_led_config.point[i].x / 224.f * 100; + } + } + + if (led_edge_mode == LED_EDGE_MODE_ALTERNATE && LED_IS_EDGE_ALT(led_map[i].scan)) { + // Do not act on this LED (Edge alternate lighting mode) + } else if (led_lighting_mode == LED_MODE_KEYS_ONLY && HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) { // Do not act on this LED } else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && !HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) { // Do not act on this LED @@ -465,10 +485,30 @@ static void md_rgb_matrix_config_override(int i) { } } + // Adjust edge LED brightness + if (led_edge_brightness != 1 && LED_IS_EDGE(led_map[i].scan)) { + ro *= led_edge_brightness; + go *= led_edge_brightness; + bo *= led_edge_brightness; + } + + // Adjust ratio of key vs. underglow (edge) LED brightness + if (LED_IS_EDGE(led_map[i].scan) && led_ratio_brightness > 1.0) { + // Decrease edge (underglow) LEDs + ro *= (2.0 - led_ratio_brightness); + go *= (2.0 - led_ratio_brightness); + bo *= (2.0 - led_ratio_brightness); + } else if (LED_IS_KEY(led_map[i].scan) && led_ratio_brightness < 1.0) { + // Decrease KEY LEDs + ro *= led_ratio_brightness; + go *= led_ratio_brightness; + bo *= led_ratio_brightness; + } + led_buffer[i].r = (uint8_t)ro; led_buffer[i].g = (uint8_t)go; led_buffer[i].b = (uint8_t)bo; } # endif // USE_MASSDROP_CONFIGURATOR -#endif // RGB_MATRIX_ENABLE \ No newline at end of file +#endif // RGB_MATRIX_ENABLE -- cgit v1.2.1