[Keymap] Improve andrebrait keymap (#13985)

This commit is contained in:
Andre Brait 2021-08-13 20:33:04 +02:00 committed by GitHub
parent fa1ec32e39
commit 5711a3bac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,9 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef RGB_CONFIRMATION_BLINKING_TIME
#define RGB_CONFIRMATION_BLINKING_TIME 2000 // 2 seconds
#endif
#if RGB_CONFIRMATION_BLINKING_TIME > 0
#include <lib/lib8tion/lib8tion.h>
#endif // RGB_CONFIRMATION_BLINKING_TIME > 0
#endif // RGB_MATRIX_ENABLE
// clang-format off
@ -83,6 +80,10 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
#ifdef RGB_MATRIX_ENABLE
/* Renaming those to make the purpose on this keymap clearer */
#define LED_FLAG_CAPS LED_FLAG_NONE
#define LED_FLAG_EFFECTS LED_FLAG_INDICATOR
static void set_rgb_caps_leds(void);
#if RGB_CONFIRMATION_BLINKING_TIME > 0
@ -90,6 +91,13 @@ static uint16_t effect_started_time = 0;
static uint8_t r_effect = 0x0, g_effect = 0x0, b_effect = 0x0;
static void start_effects(void);
/* The higher this is, the slower the blinking will be */
#ifndef TIME_SELECTED_BIT
#define TIME_SELECTED_BIT 8
#endif
#if TIME_SELECTED_BIT < 0 || TIME_SELECTED_BIT >= 16
#error "TIME_SELECTED_BIT must be a positive integer smaller than 16"
#endif
#define effect_red() r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0
#define effect_green() r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0
#endif // RGB_CONFIRMATION_BLINKING_TIME > 0
@ -98,10 +106,10 @@ bool led_update_user(led_t led_state) {
if (led_state.caps_lock) {
if (!rgb_matrix_is_enabled()) {
/* Turn ON the RGB Matrix for CAPS LOCK */
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_set_flags(LED_FLAG_CAPS);
rgb_matrix_enable();
}
} else if (rgb_matrix_get_flags() == LED_FLAG_NONE) {
} else if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
/* RGB Matrix was only ON because of CAPS LOCK. Turn it OFF. */
rgb_matrix_set_flags(LED_FLAG_ALL);
rgb_matrix_disable();
@ -167,9 +175,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (rgb_matrix_is_enabled()) {
switch (rgb_matrix_get_flags()) {
#if RGB_CONFIRMATION_BLINKING_TIME > 0
case LED_FLAG_INDICATOR:
case LED_FLAG_EFFECTS:
#endif
case LED_FLAG_NONE:
case LED_FLAG_CAPS:
/* Turned ON because of EFFECTS or CAPS, is actually OFF */
/* Change to LED_FLAG_ALL to signal it's really ON */
rgb_matrix_set_flags(LED_FLAG_ALL);
@ -180,15 +188,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
/* Is actually ON */
#if RGB_CONFIRMATION_BLINKING_TIME > 0
if (effect_started_time > 0) {
/* Change to LED_FLAG_INDICATOR to signal EFFECTS */
rgb_matrix_set_flags(LED_FLAG_INDICATOR);
/* Signal EFFECTS */
rgb_matrix_set_flags(LED_FLAG_EFFECTS);
/* Will be re-enabled by the processing of the toggle */
rgb_matrix_disable_noeeprom();
} else
#endif
if (host_keyboard_led_state().caps_lock) {
/* Change to LED_FLAG_NONE to signal CAPS */
rgb_matrix_set_flags(LED_FLAG_NONE);
/* Signal CAPS */
rgb_matrix_set_flags(LED_FLAG_CAPS);
/* Will be re-enabled by the processing of the toggle */
rgb_matrix_disable_noeeprom();
}
@ -204,12 +212,11 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
void rgb_matrix_indicators_user() {
#if RGB_CONFIRMATION_BLINKING_TIME > 0
if (effect_started_time != 0) {
if (effect_started_time > 0) {
/* Render blinking EFFECTS */
uint16_t deltaTime = sync_timer_elapsed(effect_started_time);
if (deltaTime <= RGB_CONFIRMATION_BLINKING_TIME) {
uint16_t time = scale16by8(deltaTime, UINT8_MAX / 2);
uint8_t led_state = sin8(time) >> 7;
uint8_t led_state = ((~deltaTime) >> TIME_SELECTED_BIT) & 0x01;
uint8_t val_r = led_state * r_effect;
uint8_t val_g = led_state * g_effect;
uint8_t val_b = led_state * b_effect;
@ -221,11 +228,11 @@ void rgb_matrix_indicators_user() {
} else {
/* EFFECTS duration is finished */
effect_started_time = 0;
if (rgb_matrix_get_flags() == LED_FLAG_INDICATOR) {
if (rgb_matrix_get_flags() == LED_FLAG_EFFECTS) {
/* It was turned ON because of EFFECTS */
if (host_keyboard_led_state().caps_lock) {
/* CAPS is still ON. Demote to CAPS */
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_set_flags(LED_FLAG_CAPS);
} else {
/* There is nothing else keeping RGB enabled. Reset flags and turn if off. */
rgb_matrix_set_flags(LED_FLAG_ALL);
@ -235,7 +242,7 @@ void rgb_matrix_indicators_user() {
}
}
#endif // RGB_CONFIRMATION_BLINKING_TIME > 0
if (rgb_matrix_get_flags() == LED_FLAG_NONE) {
if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
rgb_matrix_set_color_all(0x0, 0x0, 0x0);
}
if (host_keyboard_led_state().caps_lock) {
@ -248,11 +255,11 @@ static void start_effects() {
effect_started_time = sync_timer_read();
if (!rgb_matrix_is_enabled()) {
/* Turn it ON, signal the cause (EFFECTS) */
rgb_matrix_set_flags(LED_FLAG_INDICATOR);
rgb_matrix_set_flags(LED_FLAG_EFFECTS);
rgb_matrix_enable_noeeprom();
} else if (rgb_matrix_get_flags() == LED_FLAG_NONE) {
} else if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
/* It's already ON, promote the cause from CAPS to EFFECTS */
rgb_matrix_set_flags(LED_FLAG_INDICATOR);
rgb_matrix_set_flags(LED_FLAG_EFFECTS);
}
}
#endif // RGB_CONFIRMATION_BLINKING_TIME > 0