2021-12-30 04:17:34 +00:00
|
|
|
// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-03-31 23:26:43 +00:00
|
|
|
|
2020-10-17 18:46:57 +00:00
|
|
|
#include "drashna.h"
|
|
|
|
#include "rgb_matrix.h"
|
2020-03-31 23:26:43 +00:00
|
|
|
#include "lib/lib8tion/lib8tion.h"
|
|
|
|
extern led_config_t g_led_config;
|
|
|
|
|
|
|
|
static uint32_t hypno_timer;
|
|
|
|
|
2021-01-22 16:23:03 +00:00
|
|
|
void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type, uint8_t led_min, uint8_t led_max) {
|
2020-03-31 23:26:43 +00:00
|
|
|
HSV hsv = {hue, sat, val};
|
2021-07-27 00:59:49 +00:00
|
|
|
if (hsv.v > rgb_matrix_get_val()) {
|
|
|
|
hsv.v = rgb_matrix_get_val();
|
|
|
|
}
|
2020-03-31 23:26:43 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
2022-07-03 02:55:46 +00:00
|
|
|
case 1: // breathing
|
2021-12-30 04:17:34 +00:00
|
|
|
{
|
|
|
|
uint16_t time = scale16by8(g_rgb_timer, speed / 8);
|
|
|
|
hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
|
|
|
|
RGB rgb = hsv_to_rgb(hsv);
|
2022-09-23 12:46:23 +00:00
|
|
|
for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
|
2021-12-30 04:17:34 +00:00
|
|
|
if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
|
|
|
|
RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b);
|
2020-03-31 23:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-30 04:17:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-07-03 02:55:46 +00:00
|
|
|
default: // Solid Color
|
2021-12-30 04:17:34 +00:00
|
|
|
{
|
|
|
|
RGB rgb = hsv_to_rgb(hsv);
|
2022-09-23 12:46:23 +00:00
|
|
|
for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
|
2021-12-30 04:17:34 +00:00
|
|
|
if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
|
|
|
|
RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b);
|
2020-03-31 23:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-30 04:17:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-03-31 23:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 19:14:48 +00:00
|
|
|
void housekeeping_task_rgb_matrix(void) {
|
2020-03-31 23:26:43 +00:00
|
|
|
#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
|
2021-07-27 00:59:49 +00:00
|
|
|
if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_TYPING_HEATMAP && sync_timer_elapsed32(hypno_timer) > 15000) {
|
|
|
|
rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE);
|
|
|
|
}
|
2020-03-31 23:26:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void keyboard_post_init_rgb_matrix(void) {
|
|
|
|
#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
|
2021-07-27 00:59:49 +00:00
|
|
|
if (userspace_config.rgb_matrix_idle_anim) {
|
|
|
|
rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE);
|
|
|
|
}
|
2020-03-31 23:26:43 +00:00
|
|
|
#endif
|
2022-05-31 05:02:55 +00:00
|
|
|
if (userspace_config.rgb_layer_change) {
|
|
|
|
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW | LED_FLAG_KEYLIGHT | LED_FLAG_INDICATOR);
|
2022-07-03 02:55:46 +00:00
|
|
|
} else {
|
|
|
|
rgb_matrix_set_flags(LED_FLAG_ALL);
|
2022-05-31 05:02:55 +00:00
|
|
|
}
|
2020-03-31 23:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
|
2021-05-25 16:24:01 +00:00
|
|
|
hypno_timer = sync_timer_read32();
|
2021-07-27 00:59:49 +00:00
|
|
|
if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_REST_MODE) {
|
|
|
|
rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP);
|
|
|
|
}
|
2020-03-31 23:26:43 +00:00
|
|
|
#endif
|
|
|
|
switch (keycode) {
|
2022-07-03 02:55:46 +00:00
|
|
|
case RGB_IDL: // This allows me to use underglow as layer indication, or as normal
|
2020-03-31 23:26:43 +00:00
|
|
|
#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
|
|
|
|
if (record->event.pressed) {
|
|
|
|
userspace_config.rgb_matrix_idle_anim ^= 1;
|
|
|
|
dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim);
|
2023-05-31 18:44:06 +00:00
|
|
|
eeconfig_update_user_config(&userspace_config.raw);
|
2021-07-27 00:59:49 +00:00
|
|
|
if (userspace_config.rgb_matrix_idle_anim) {
|
|
|
|
rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP);
|
|
|
|
}
|
2020-03-31 23:26:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2021-12-30 04:17:34 +00:00
|
|
|
|
2022-07-03 02:55:46 +00:00
|
|
|
__attribute__((weak)) bool rgb_matrix_indicators_advanced_keymap(uint8_t led_min, uint8_t led_max) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-04 22:24:22 +00:00
|
|
|
bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
|
2022-07-03 02:55:46 +00:00
|
|
|
if (!rgb_matrix_indicators_advanced_keymap(led_min, led_max)) {
|
2022-10-04 22:24:22 +00:00
|
|
|
return false;
|
2022-07-03 02:55:46 +00:00
|
|
|
}
|
2021-12-30 04:17:34 +00:00
|
|
|
|
|
|
|
#if defined(RGBLIGHT_ENABLE)
|
|
|
|
if (!userspace_config.rgb_layer_change)
|
|
|
|
#else
|
|
|
|
if (userspace_config.rgb_layer_change)
|
|
|
|
#endif
|
|
|
|
{
|
2022-07-03 02:55:46 +00:00
|
|
|
switch (get_highest_layer(layer_state & ~((layer_state_t)1 << _MOUSE))) {
|
2021-12-30 04:17:34 +00:00
|
|
|
case _GAMEPAD:
|
|
|
|
rgb_matrix_layer_helper(HSV_ORANGE, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
break;
|
|
|
|
case _DIABLO:
|
|
|
|
rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed * 8, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
break;
|
|
|
|
case _RAISE:
|
|
|
|
rgb_matrix_layer_helper(HSV_YELLOW, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
break;
|
|
|
|
case _LOWER:
|
|
|
|
rgb_matrix_layer_helper(HSV_GREEN, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
break;
|
|
|
|
case _ADJUST:
|
|
|
|
rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
break;
|
2022-07-03 02:55:46 +00:00
|
|
|
default:
|
|
|
|
if (layer_state_is(_MOUSE)) {
|
|
|
|
rgb_matrix_layer_helper(HSV_PURPLE, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
} else {
|
|
|
|
switch (get_highest_layer(default_layer_state)) {
|
|
|
|
case _DEFAULT_LAYER_1:
|
|
|
|
rgb_matrix_layer_helper(DEFAULT_LAYER_1_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
break;
|
|
|
|
case _DEFAULT_LAYER_2:
|
|
|
|
rgb_matrix_layer_helper(DEFAULT_LAYER_2_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
break;
|
|
|
|
case _DEFAULT_LAYER_3:
|
|
|
|
rgb_matrix_layer_helper(DEFAULT_LAYER_3_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
break;
|
|
|
|
case _DEFAULT_LAYER_4:
|
|
|
|
rgb_matrix_layer_helper(DEFAULT_LAYER_4_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2021-12-30 04:17:34 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-04 22:24:22 +00:00
|
|
|
return false;
|
2021-12-30 04:17:34 +00:00
|
|
|
}
|
|
|
|
|
2022-07-03 02:55:46 +00:00
|
|
|
__attribute__((weak)) bool rgb_matrix_indicators_keymap(void) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-04 22:24:22 +00:00
|
|
|
bool rgb_matrix_indicators_user(void) {
|
|
|
|
return rgb_matrix_indicators_keymap();
|
2022-07-03 02:55:46 +00:00
|
|
|
}
|
2023-05-31 18:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
// RGB Matrix naming
|
|
|
|
#include <rgb_matrix.h>
|
|
|
|
|
|
|
|
#if defined(RGB_MATRIX_EFFECT)
|
|
|
|
# undef RGB_MATRIX_EFFECT
|
|
|
|
#endif // defined(RGB_MATRIX_EFFECT)
|
|
|
|
|
|
|
|
#define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x,
|
|
|
|
enum {
|
|
|
|
RGB_MATRIX_EFFECT_NONE,
|
|
|
|
#include "rgb_matrix_effects.inc"
|
|
|
|
#undef RGB_MATRIX_EFFECT
|
|
|
|
#ifdef RGB_MATRIX_CUSTOM_KB
|
|
|
|
# include "rgb_matrix_kb.inc"
|
|
|
|
#endif
|
|
|
|
#ifdef RGB_MATRIX_CUSTOM_USER
|
|
|
|
# include "rgb_matrix_user.inc"
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RGB_MATRIX_EFFECT(x) \
|
|
|
|
case RGB_MATRIX_EFFECT_##x: \
|
|
|
|
return #x;
|
|
|
|
const char* rgb_matrix_name(uint8_t effect) {
|
|
|
|
switch (effect) {
|
|
|
|
case RGB_MATRIX_EFFECT_NONE:
|
|
|
|
return "NONE";
|
|
|
|
#include "rgb_matrix_effects.inc"
|
|
|
|
#undef RGB_MATRIX_EFFECT
|
|
|
|
#ifdef RGB_MATRIX_CUSTOM_KB
|
|
|
|
# include "rgb_matrix_kb.inc"
|
|
|
|
#endif
|
|
|
|
#ifdef RGB_MATRIX_CUSTOM_USER
|
|
|
|
# include "rgb_matrix_user.inc"
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|