Files

219 lines
9.5 KiB
C
Raw Permalink Normal View History

2019-12-16 20:27:53 +00:00
/* Copyright 2019
*
* 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/>.
*/
#include "process_rgb.h"
typedef void (*rgb_func_pointer)(void);
/**
* Wrapper for inc/dec rgb keycode
*
* noinline to optimise for firmware size not speed (not in hot path)
2019-12-16 20:27:53 +00:00
*/
2020-10-07 11:30:43 +09:00
#if (defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)) || (defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES))
2019-12-16 20:27:53 +00:00
static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) {
if (is_shifted) {
dec_func();
} else {
inc_func();
}
}
#endif
2019-12-16 20:27:53 +00:00
/**
* Wrapper for animation mode
* - if not in animation family -> jump to that animation
* - otherwise -> wrap round animation speed
*
* noinline to optimise for firmware size not speed (not in hot path)
2019-12-16 20:27:53 +00:00
*/
static void __attribute__((noinline, unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) {
2019-12-16 20:27:53 +00:00
if ((start <= rgblight_get_mode()) && (rgblight_get_mode() < end)) {
rgblight_step();
} else {
rgblight_mode(start);
}
}
/**
* Handle keycodes for both rgblight and rgbmatrix
*/
bool process_rgb(const uint16_t keycode, const keyrecord_t *record) {
// need to trigger on key-up for edge-case issue
#ifndef RGB_TRIGGER_ON_KEYDOWN
2019-12-16 20:27:53 +00:00
if (!record->event.pressed) {
#else
if (record->event.pressed) {
#endif
2020-10-07 11:30:43 +09:00
#if (defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)) || (defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES))
uint8_t shifted = get_mods() & MOD_MASK_SHIFT;
#endif
2019-12-16 20:27:53 +00:00
switch (keycode) {
case RGB_TOG:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
rgblight_toggle();
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
rgb_matrix_toggle();
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_MODE_FORWARD:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_step, rgblight_step_reverse);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_step, rgb_matrix_step_reverse);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_MODE_REVERSE:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_step_reverse, rgblight_step);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_step_reverse, rgb_matrix_step);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_HUI:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_increase_hue, rgblight_decrease_hue);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_increase_hue, rgb_matrix_decrease_hue);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_HUD:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_decrease_hue, rgblight_increase_hue);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_decrease_hue, rgb_matrix_increase_hue);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_SAI:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_increase_sat, rgblight_decrease_sat);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_increase_sat, rgb_matrix_decrease_sat);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_SAD:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_decrease_sat, rgblight_increase_sat);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_decrease_sat, rgb_matrix_increase_sat);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_VAI:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_increase_val, rgblight_decrease_val);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_increase_val, rgb_matrix_decrease_val);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_VAD:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_decrease_val, rgblight_increase_val);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_decrease_val, rgb_matrix_increase_val);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_SPI:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_increase_speed, rgblight_decrease_speed);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_increase_speed, rgb_matrix_decrease_speed);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_SPD:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
handleKeycodeRGB(shifted, rgblight_decrease_speed, rgblight_increase_speed);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
handleKeycodeRGB(shifted, rgb_matrix_decrease_speed, rgb_matrix_increase_speed);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_MODE_PLAIN:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES)
2019-12-16 20:27:53 +00:00
rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
2020-06-22 01:38:58 -07:00
#endif
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES)
rgb_matrix_mode(RGB_MATRIX_SOLID_COLOR);
#endif
2019-12-16 20:27:53 +00:00
return false;
case RGB_MODE_BREATHE:
2020-06-22 01:38:58 -07:00
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_BREATHING)
2019-12-16 20:27:53 +00:00
handleKeycodeRGBMode(RGBLIGHT_MODE_BREATHING, RGBLIGHT_MODE_BREATHING_end);
2020-06-22 01:38:58 -07:00
#endif
2021-08-17 11:19:00 -07:00
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && defined(ENABLE_RGB_MATRIX_BREATHING)
2020-06-22 01:38:58 -07:00
rgb_matrix_mode(RGB_MATRIX_BREATHING);
2019-12-16 20:27:53 +00:00
#endif
return false;
case RGB_MODE_RAINBOW:
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_RAINBOW_MOOD)
2019-12-16 20:27:53 +00:00
handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_MOOD, RGBLIGHT_MODE_RAINBOW_MOOD_end);
2020-06-22 01:38:58 -07:00
#endif
2021-08-17 11:19:00 -07:00
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && defined(ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT)
2020-06-22 01:38:58 -07:00
rgb_matrix_mode(RGB_MATRIX_CYCLE_LEFT_RIGHT);
2019-12-16 20:27:53 +00:00
#endif
return false;
case RGB_MODE_SWIRL:
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL)
2019-12-16 20:27:53 +00:00
handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_SWIRL, RGBLIGHT_MODE_RAINBOW_SWIRL_end);
2020-06-22 01:38:58 -07:00
#endif
2021-08-17 11:19:00 -07:00
#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_DISABLE_KEYCODES) && defined(ENABLE_RGB_MATRIX_CYCLE_PINWHEEL)
2020-06-22 01:38:58 -07:00
rgb_matrix_mode(RGB_MATRIX_CYCLE_PINWHEEL);
2019-12-16 20:27:53 +00:00
#endif
return false;
case RGB_MODE_SNAKE:
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_SNAKE)
2019-12-16 20:27:53 +00:00
handleKeycodeRGBMode(RGBLIGHT_MODE_SNAKE, RGBLIGHT_MODE_SNAKE_end);
#endif
return false;
case RGB_MODE_KNIGHT:
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_KNIGHT)
2019-12-16 20:27:53 +00:00
handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end);
#endif
return false;
case RGB_MODE_XMAS:
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_CHRISTMAS)
2019-12-16 20:27:53 +00:00
rgblight_mode(RGBLIGHT_MODE_CHRISTMAS);
#endif
return false;
case RGB_MODE_GRADIENT:
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_STATIC_GRADIENT)
2019-12-16 20:27:53 +00:00
handleKeycodeRGBMode(RGBLIGHT_MODE_STATIC_GRADIENT, RGBLIGHT_MODE_STATIC_GRADIENT_end);
#endif
return false;
case RGB_MODE_RGBTEST:
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_RGB_TEST)
2019-12-16 20:27:53 +00:00
rgblight_mode(RGBLIGHT_MODE_RGB_TEST);
#endif
return false;
case RGB_MODE_TWINKLE:
#if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_DISABLE_KEYCODES) && defined(RGBLIGHT_EFFECT_TWINKLE)
handleKeycodeRGBMode(RGBLIGHT_MODE_TWINKLE, RGBLIGHT_MODE_TWINKLE_end);
2019-12-16 20:27:53 +00:00
#endif
return false;
}
}
return true;
}