From 3fa592a4024a24a636fa0c562e6761667a94f565 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 14 Dec 2021 20:53:36 -0800 Subject: [Keymap] Unicode and Pointing Device and Autocorect for drashna keymaps (#15415) --- users/drashna/rgb/rgb_matrix_stuff.c | 97 +++++++++++++++++++++++++ users/drashna/rgb/rgb_matrix_stuff.h | 25 +++++++ users/drashna/rgb/rgb_stuff.c | 132 +++++++++++++++++++++++++++++++++++ users/drashna/rgb/rgb_stuff.h | 25 +++++++ 4 files changed, 279 insertions(+) create mode 100644 users/drashna/rgb/rgb_matrix_stuff.c create mode 100644 users/drashna/rgb/rgb_matrix_stuff.h create mode 100644 users/drashna/rgb/rgb_stuff.c create mode 100644 users/drashna/rgb/rgb_stuff.h (limited to 'users/drashna/rgb') diff --git a/users/drashna/rgb/rgb_matrix_stuff.c b/users/drashna/rgb/rgb_matrix_stuff.c new file mode 100644 index 0000000000..97811092c1 --- /dev/null +++ b/users/drashna/rgb/rgb_matrix_stuff.c @@ -0,0 +1,97 @@ +/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 . + */ + +#include "drashna.h" +#include "rgb_matrix.h" +#include "lib/lib8tion/lib8tion.h" +extern led_config_t g_led_config; + +static uint32_t hypno_timer; + +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) { + HSV hsv = {hue, sat, val}; + if (hsv.v > rgb_matrix_get_val()) { + hsv.v = rgb_matrix_get_val(); + } + + switch (mode) { + case 1: // breathing + { + 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++) { + if (HAS_FLAGS(g_led_config.flags[i], led_type)) { + RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); + } + } + break; + } + default: // Solid Color + { + RGB rgb = hsv_to_rgb(hsv); + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + if (HAS_FLAGS(g_led_config.flags[i], led_type)) { + RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b); + } + } + break; + } + } +} + +__attribute__((weak)) void rgb_matrix_indicator_keymap(void) {} + +void matrix_scan_rgb_matrix(void) { +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) + 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); + } +#endif + rgb_matrix_indicator_keymap(); +} + +void keyboard_post_init_rgb_matrix(void) { +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) + if (userspace_config.rgb_matrix_idle_anim) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE); + } +#endif +} + +bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record) { +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) + hypno_timer = sync_timer_read32(); + if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_REST_MODE) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP); + } +#endif + switch (keycode) { + case RGB_IDL: // This allows me to use underglow as layer indication, or as normal +#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); + if (userspace_config.rgb_matrix_idle_anim) { + rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP); + } + } +#endif + break; + } + return true; +} diff --git a/users/drashna/rgb/rgb_matrix_stuff.h b/users/drashna/rgb/rgb_matrix_stuff.h new file mode 100644 index 0000000000..b86f2f6514 --- /dev/null +++ b/users/drashna/rgb/rgb_matrix_stuff.h @@ -0,0 +1,25 @@ +/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 . + */ + +#pragma once +#include "quantum.h" + +bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record); +void keyboard_post_init_rgb_matrix(void); +void matrix_scan_rgb_matrix(void); + +void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +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); diff --git a/users/drashna/rgb/rgb_stuff.c b/users/drashna/rgb/rgb_stuff.c new file mode 100644 index 0000000000..15108bde04 --- /dev/null +++ b/users/drashna/rgb/rgb_stuff.c @@ -0,0 +1,132 @@ +/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 . + */ + +#ifdef RGBLIGHT_ENABLE + +# include "drashna.h" +# include "rgb_stuff.h" +# include "eeprom.h" + +bool has_initialized; + +void rgblight_sethsv_default_helper(uint8_t index) { rgblight_sethsv_at(rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val(), index); } +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); +} + +bool process_record_user_rgb_light(uint16_t keycode, keyrecord_t *record) { return true; } + +# if defined(RGBLIGHT_STARTUP_ANIMATION) +static bool is_enabled; +static bool is_rgblight_startup; +static HSV old_hsv; +static uint8_t old_mode; +static uint16_t rgblight_startup_loop_timer; +# endif + +void keyboard_post_init_rgb_light(void) { +# if defined(RGBLIGHT_STARTUP_ANIMATION) + is_enabled = rgblight_is_enabled(); + if (userspace_config.rgb_layer_change) { + layer_state_set_rgb_light(layer_state); + } + old_hsv = rgblight_get_hsv(); + old_mode = rgblight_get_mode(); + rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); + is_rgblight_startup = true; +# endif + if (userspace_config.rgb_layer_change) { + layer_state_set_rgb_light(layer_state); + } +} + +void matrix_scan_rgb_light(void) { +# if defined(RGBLIGHT_STARTUP_ANIMATION) + if (is_rgblight_startup && is_keyboard_master()) { + if (sync_timer_elapsed(rgblight_startup_loop_timer) > 10) { + static uint8_t counter; + counter++; + rgblight_sethsv_noeeprom((counter + old_hsv.h) % 255, 255, 255); + rgblight_startup_loop_timer = sync_timer_read(); + 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(); + } + } + } + } +# endif +} + +layer_state_t layer_state_set_rgb_light(layer_state_t state) { +# ifdef RGBLIGHT_ENABLE + if (userspace_config.rgb_layer_change) { + switch (get_highest_layer(state | default_layer_state)) { + case _MOUSE: // mouse + if (!layer_state_cmp(state, _GAMEPAD) && !layer_state_cmp(state, _DIABLO)) { +# 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 + } + break; + 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: + 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; + 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; + } + } +# endif // RGBLIGHT_ENABLE + + return state; +} + +#endif diff --git a/users/drashna/rgb/rgb_stuff.h b/users/drashna/rgb/rgb_stuff.h new file mode 100644 index 0000000000..af1acdde71 --- /dev/null +++ b/users/drashna/rgb/rgb_stuff.h @@ -0,0 +1,25 @@ +/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) + * + * 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 . + */ + +#pragma once +#include "quantum.h" + +bool process_record_user_rgb_light(uint16_t keycode, keyrecord_t *record); +void keyboard_post_init_rgb_light(void); +void matrix_scan_rgb_light(void); +layer_state_t layer_state_set_rgb_light(layer_state_t state); +layer_state_t default_layer_state_set_rgb_light(layer_state_t state); +void rgblight_sethsv_default_helper(uint8_t index); -- cgit v1.2.3