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-10-17 18:46:57 +00:00
|
|
|
|
2022-07-03 02:55:46 +00:00
|
|
|
#include "drashna.h"
|
|
|
|
#include "rgb_stuff.h"
|
|
|
|
#include "eeprom.h"
|
2018-06-01 05:11:06 +00:00
|
|
|
|
2021-02-23 18:57:24 +00:00
|
|
|
bool has_initialized;
|
2018-06-01 05:11:06 +00:00
|
|
|
|
2022-07-03 02:55:46 +00:00
|
|
|
void rgblight_sethsv_default_helper(uint8_t index) {
|
|
|
|
rgblight_sethsv_at(rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val(), index);
|
|
|
|
}
|
2021-08-21 20:34:44 +00:00
|
|
|
void rgblight_set_hsv_and_mode(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode) {
|
|
|
|
rgblight_sethsv_noeeprom(hue, sat, val);
|
|
|
|
// wait_us(175); // Add a slight delay between color and mode to ensure it's processed correctly
|
|
|
|
rgblight_mode_noeeprom(mode);
|
2018-06-01 05:11:06 +00:00
|
|
|
}
|
|
|
|
|
2022-07-03 02:55:46 +00:00
|
|
|
bool process_record_user_rgb_light(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-06-01 05:11:06 +00:00
|
|
|
|
2022-07-03 02:55:46 +00:00
|
|
|
#if defined(RGBLIGHT_STARTUP_ANIMATION)
|
|
|
|
static bool is_enabled;
|
|
|
|
static bool is_rgblight_startup;
|
|
|
|
static HSV old_hsv;
|
|
|
|
static uint8_t old_mode;
|
2022-01-30 21:20:33 +00:00
|
|
|
deferred_token rgb_startup_token;
|
2020-06-15 10:41:28 +00:00
|
|
|
|
2022-01-30 21:20:33 +00:00
|
|
|
uint32_t rgb_startup_animation(uint32_t triger_time, void *cb_arg) {
|
|
|
|
if (is_rgblight_startup && is_keyboard_master()) {
|
|
|
|
static uint8_t counter = 0;
|
|
|
|
counter++;
|
|
|
|
rgblight_sethsv_noeeprom((counter + old_hsv.h) % 255, 255, 255);
|
|
|
|
if (counter >= 255) {
|
|
|
|
is_rgblight_startup = false;
|
|
|
|
if (userspace_config.rgb_layer_change) {
|
|
|
|
layer_state_set_rgb_light(layer_state);
|
|
|
|
} else {
|
|
|
|
rgblight_set_hsv_and_mode(old_hsv.h, old_hsv.s, old_hsv.v, old_mode);
|
|
|
|
}
|
|
|
|
if (!is_enabled) {
|
|
|
|
rgblight_disable_noeeprom();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return is_rgblight_startup ? 10 : 0;
|
|
|
|
}
|
2022-07-03 02:55:46 +00:00
|
|
|
#endif
|
2022-01-30 21:20:33 +00:00
|
|
|
|
2020-03-31 23:26:43 +00:00
|
|
|
void keyboard_post_init_rgb_light(void) {
|
2022-07-03 02:55:46 +00:00
|
|
|
#if defined(RGBLIGHT_STARTUP_ANIMATION)
|
2020-06-15 10:41:28 +00:00
|
|
|
is_enabled = rgblight_is_enabled();
|
2021-07-27 00:59:49 +00:00
|
|
|
if (userspace_config.rgb_layer_change) {
|
2020-03-31 23:26:43 +00:00
|
|
|
layer_state_set_rgb_light(layer_state);
|
2019-04-22 18:55:55 +00:00
|
|
|
}
|
2021-08-21 20:34:44 +00:00
|
|
|
old_hsv = rgblight_get_hsv();
|
|
|
|
old_mode = rgblight_get_mode();
|
|
|
|
rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
|
|
|
|
is_rgblight_startup = true;
|
2022-07-03 02:55:46 +00:00
|
|
|
rgb_startup_token = defer_exec(300, rgb_startup_animation, NULL);
|
|
|
|
#endif
|
2021-08-21 20:34:44 +00:00
|
|
|
if (userspace_config.rgb_layer_change) {
|
|
|
|
layer_state_set_rgb_light(layer_state);
|
|
|
|
}
|
2018-06-01 05:11:06 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 23:26:43 +00:00
|
|
|
layer_state_t layer_state_set_rgb_light(layer_state_t state) {
|
2022-07-03 02:55:46 +00:00
|
|
|
#ifdef RGBLIGHT_ENABLE
|
2019-05-07 05:34:09 +00:00
|
|
|
if (userspace_config.rgb_layer_change) {
|
2022-07-03 02:55:46 +00:00
|
|
|
switch (get_highest_layer(state & ~((layer_state_t)1 << _MOUSE))) {
|
2021-07-27 00:59:49 +00:00
|
|
|
case _MEDIA:
|
|
|
|
rgblight_set_hsv_and_mode(HSV_CHARTREUSE, RGBLIGHT_MODE_KNIGHT + 1);
|
|
|
|
break;
|
|
|
|
case _GAMEPAD:
|
|
|
|
rgblight_set_hsv_and_mode(HSV_ORANGE, RGBLIGHT_MODE_SNAKE + 2);
|
|
|
|
break;
|
|
|
|
case _DIABLO:
|
2022-07-03 02:55:46 +00:00
|
|
|
case _DIABLOII:
|
2021-07-27 00:59:49 +00:00
|
|
|
rgblight_set_hsv_and_mode(HSV_RED, RGBLIGHT_MODE_BREATHING + 3);
|
|
|
|
break;
|
|
|
|
case _RAISE:
|
|
|
|
rgblight_set_hsv_and_mode(HSV_YELLOW, RGBLIGHT_MODE_BREATHING + 3);
|
|
|
|
break;
|
|
|
|
case _LOWER:
|
|
|
|
rgblight_set_hsv_and_mode(HSV_GREEN, RGBLIGHT_MODE_BREATHING + 3);
|
|
|
|
break;
|
|
|
|
case _ADJUST:
|
|
|
|
rgblight_set_hsv_and_mode(HSV_RED, RGBLIGHT_MODE_KNIGHT + 2);
|
|
|
|
break;
|
2022-07-03 02:55:46 +00:00
|
|
|
default:
|
|
|
|
if (layer_state_cmp(state, _MOUSE)) {
|
|
|
|
# if defined(RGBLIGHT_EFFECT_TWINKLE)
|
|
|
|
rgblight_set_hsv_and_mode(HSV_CHARTREUSE, RGBLIGHT_MODE_TWINKLE + 5);
|
|
|
|
# else
|
|
|
|
rgblight_set_hsv_and_mode(HSV_CHARTREUSE, RGBLIGHT_MODE_BREATHING + 3);
|
|
|
|
# endif
|
|
|
|
} else {
|
|
|
|
default_layer_state_set_rgb_light(default_layer_state);
|
|
|
|
}
|
2019-05-07 05:34:09 +00:00
|
|
|
}
|
2022-07-03 02:55:46 +00:00
|
|
|
#endif // RGBLIGHT_ENABLE
|
2018-06-01 05:11:06 +00:00
|
|
|
}
|
2019-05-07 05:34:09 +00:00
|
|
|
return state;
|
2018-11-27 00:45:24 +00:00
|
|
|
}
|
2021-02-23 18:57:24 +00:00
|
|
|
|
2022-07-03 02:55:46 +00:00
|
|
|
layer_state_t default_layer_state_set_rgb_light(layer_state_t state) {
|
|
|
|
switch (get_highest_layer(state)) {
|
|
|
|
case _DEFAULT_LAYER_1:
|
|
|
|
rgblight_set_hsv_and_mode(DEFAULT_LAYER_1_HSV, RGBLIGHT_MODE_STATIC_LIGHT);
|
|
|
|
break;
|
|
|
|
case _DEFAULT_LAYER_2:
|
|
|
|
rgblight_set_hsv_and_mode(DEFAULT_LAYER_2_HSV, RGBLIGHT_MODE_STATIC_LIGHT);
|
|
|
|
break;
|
|
|
|
case _DEFAULT_LAYER_3:
|
|
|
|
rgblight_set_hsv_and_mode(DEFAULT_LAYER_3_HSV, RGBLIGHT_MODE_STATIC_LIGHT);
|
|
|
|
break;
|
|
|
|
case _DEFAULT_LAYER_4:
|
|
|
|
rgblight_set_hsv_and_mode(DEFAULT_LAYER_4_HSV, RGBLIGHT_MODE_STATIC_LIGHT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|