2020-10-17 20:46:57 +02:00
|
|
|
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-04-01 01:26:43 +02:00
|
|
|
|
2020-10-17 20:46:57 +02:00
|
|
|
#include "drashna.h"
|
|
|
|
#include "rgb_matrix.h"
|
2020-04-01 01:26:43 +02:00
|
|
|
#include "lib/lib8tion/lib8tion.h"
|
|
|
|
extern led_config_t g_led_config;
|
|
|
|
|
|
|
|
static uint32_t hypno_timer;
|
|
|
|
#if defined(SPLIT_KEYBOARD) || defined(KEYBOARD_ergodox_ez) || defined(KEYBOARD_crkbd)
|
|
|
|
# define RGB_MATRIX_REST_MODE RGB_MATRIX_CYCLE_OUT_IN_DUAL
|
|
|
|
#else
|
|
|
|
# define RGB_MATRIX_REST_MODE RGB_MATRIX_CYCLE_OUT_IN
|
|
|
|
#endif
|
|
|
|
|
2021-01-22 17:23:03 +01: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-04-01 01:26:43 +02:00
|
|
|
HSV hsv = {hue, sat, val};
|
2021-07-27 02:59:49 +02:00
|
|
|
if (hsv.v > rgb_matrix_get_val()) {
|
|
|
|
hsv.v = rgb_matrix_get_val();
|
|
|
|
}
|
2020-04-01 01:26:43 +02:00
|
|
|
|
|
|
|
switch (mode) {
|
2021-07-27 02:59:49 +02:00
|
|
|
case 1: // breathing
|
2021-07-01 09:42:32 +02: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);
|
|
|
|
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
|
2021-07-27 02:59:49 +02:00
|
|
|
if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
|
|
|
|
RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b);
|
|
|
|
}
|
2020-04-01 01:26:43 +02:00
|
|
|
}
|
2021-07-01 09:42:32 +02:00
|
|
|
break;
|
2020-04-01 01:26:43 +02:00
|
|
|
}
|
2021-07-27 02:59:49 +02:00
|
|
|
default: // Solid Color
|
2021-07-01 09:42:32 +02:00
|
|
|
{
|
|
|
|
RGB rgb = hsv_to_rgb(hsv);
|
|
|
|
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
|
2021-07-27 02:59:49 +02:00
|
|
|
if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
|
|
|
|
RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b);
|
|
|
|
}
|
2020-04-01 01:26:43 +02:00
|
|
|
}
|
2021-07-01 09:42:32 +02:00
|
|
|
break;
|
2020-04-01 01:26:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) void rgb_matrix_indicator_keymap(void) {}
|
|
|
|
|
|
|
|
void matrix_scan_rgb_matrix(void) {
|
|
|
|
#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
|
2021-07-27 02:59:49 +02: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-04-01 01:26:43 +02:00
|
|
|
#endif
|
|
|
|
rgb_matrix_indicator_keymap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void keyboard_post_init_rgb_matrix(void) {
|
|
|
|
#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
|
2021-07-27 02:59:49 +02:00
|
|
|
if (userspace_config.rgb_matrix_idle_anim) {
|
|
|
|
rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE);
|
|
|
|
}
|
2020-04-01 01:26:43 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
|
2021-05-25 18:24:01 +02:00
|
|
|
hypno_timer = sync_timer_read32();
|
2021-07-27 02:59:49 +02: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-04-01 01:26:43 +02:00
|
|
|
#endif
|
|
|
|
switch (keycode) {
|
2021-07-27 02:59:49 +02:00
|
|
|
case RGB_IDL: // This allows me to use underglow as layer indication, or as normal
|
2020-04-01 01:26:43 +02: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);
|
|
|
|
eeconfig_update_user(userspace_config.raw);
|
2021-07-27 02:59:49 +02:00
|
|
|
if (userspace_config.rgb_matrix_idle_anim) {
|
|
|
|
rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP);
|
|
|
|
}
|
2020-04-01 01:26:43 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|